From 28672962039aa241d144b87e6cfad2dc38f3779f Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 9 Jun 2016 16:24:44 -0700 Subject: [PATCH 1/3] Remove blueprint/parser.Ident Follows blueprint change https://github.com/google/blueprint/pull/104/commits/c32c47938f2a04cd62aed8691add85049c6a6625 Change-Id: I8f479704504f7bbefed3ed63bd0d040f65a2fdd5 --- androidmk/cmd/androidmk/androidmk.go | 29 +++++++++++----------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/androidmk/cmd/androidmk/androidmk.go b/androidmk/cmd/androidmk/androidmk.go index 67d110150..8b4e51aca 100644 --- a/androidmk/cmd/androidmk/androidmk.go +++ b/androidmk/cmd/androidmk/androidmk.go @@ -290,10 +290,8 @@ func handleModuleConditionals(file *bpFile, directive *mkparser.Directive, conds } func makeModule(file *bpFile, t string) { - file.module.Type = bpparser.Ident{ - Name: t, - Pos: file.module.LBracePos, - } + file.module.Type = t + file.module.TypePos = file.module.LBracePos file.module.RBracePos = file.bpPos file.defs = append(file.defs, file.module) file.inModule = false @@ -364,8 +362,8 @@ func setVariable(file *bpFile, plusequals bool, prefix, name string, value bppar prop := file.localAssignments[fqn] if prop == nil { prop = &bpparser.Property{ - Name: bpparser.Ident{Name: n, Pos: pos}, - Pos: pos, + Name: n, + NamePos: pos, Value: &bpparser.Map{ Properties: []*bpparser.Property{}, }, @@ -377,9 +375,9 @@ func setVariable(file *bpFile, plusequals bool, prefix, name string, value bppar } prop := &bpparser.Property{ - Name: bpparser.Ident{Name: names[len(names)-1], Pos: pos}, - Pos: pos, - Value: value, + Name: names[len(names)-1], + NamePos: pos, + Value: value, } file.localAssignments[name] = prop *container = append(*container, prop) @@ -387,10 +385,8 @@ func setVariable(file *bpFile, plusequals bool, prefix, name string, value bppar } else { if oldValue != nil && plusequals { a := &bpparser.Assignment{ - Name: bpparser.Ident{ - Name: name, - Pos: pos, - }, + Name: name, + NamePos: pos, Value: value, OrigValue: value, Pos: pos, @@ -399,10 +395,8 @@ func setVariable(file *bpFile, plusequals bool, prefix, name string, value bppar file.defs = append(file.defs, a) } else { a := &bpparser.Assignment{ - Name: bpparser.Ident{ - Name: name, - Pos: pos, - }, + Name: name, + NamePos: pos, Value: value, OrigValue: value, Pos: pos, @@ -412,6 +406,5 @@ func setVariable(file *bpFile, plusequals bool, prefix, name string, value bppar file.defs = append(file.defs, a) } } - return nil } From e538e410cb8931628d210b022513c4368bae49f0 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 9 Jun 2016 17:06:08 -0700 Subject: [PATCH 2/3] Rename Pos members Follows blueprint change https://github.com/google/blueprint/pull/104/commits/b3d0b8dab43776e5391eeebe8a9a0de7600ba219 Change-Id: I10f53498557325d26c6b690583596ac4f9206c79 --- androidmk/cmd/androidmk/androidmk.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/androidmk/cmd/androidmk/androidmk.go b/androidmk/cmd/androidmk/androidmk.go index 8b4e51aca..75a53815b 100644 --- a/androidmk/cmd/androidmk/androidmk.go +++ b/androidmk/cmd/androidmk/androidmk.go @@ -389,7 +389,7 @@ func setVariable(file *bpFile, plusequals bool, prefix, name string, value bppar NamePos: pos, Value: value, OrigValue: value, - Pos: pos, + EqualsPos: pos, Assigner: "+=", } file.defs = append(file.defs, a) @@ -399,7 +399,7 @@ func setVariable(file *bpFile, plusequals bool, prefix, name string, value bppar NamePos: pos, Value: value, OrigValue: value, - Pos: pos, + EqualsPos: pos, Assigner: "=", } file.globalAssignments[name] = &a.Value From 7b6ba5c7fac1f420ae68cee1ab51d85e73e5900e Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 10 Jun 2016 17:34:07 -0700 Subject: [PATCH 3/3] Add CommentGroups Follows blueprint change https://github.com/google/blueprint/pull/104/commits/1e73794d421a8017dbbc1d80913d93571d46d1b6 Change-Id: If3539e2d9370a0224a2364608c496a1e4385dbbf --- androidmk/cmd/androidmk/androidmk.go | 39 +++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/androidmk/cmd/androidmk/androidmk.go b/androidmk/cmd/androidmk/androidmk.go index 75a53815b..bc3295a05 100644 --- a/androidmk/cmd/androidmk/androidmk.go +++ b/androidmk/cmd/androidmk/androidmk.go @@ -16,7 +16,7 @@ import ( // TODO: non-expanded variables with expressions type bpFile struct { - comments []bpparser.Comment + comments []*bpparser.CommentGroup defs []bpparser.Definition localAssignments map[string]*bpparser.Property globalAssignments map[string]*bpparser.Expression @@ -29,21 +29,32 @@ type bpFile struct { inModule bool } +func (f *bpFile) insertComment(s string) { + f.comments = append(f.comments, &bpparser.CommentGroup{ + Comments: []*bpparser.Comment{ + &bpparser.Comment{ + Comment: []string{s}, + Slash: f.bpPos, + }, + }, + }) + f.bpPos.Offset += len(s) +} + +func (f *bpFile) insertExtraComment(s string) { + f.insertComment(s) + f.bpPos.Line++ +} + func (f *bpFile) errorf(node mkparser.Node, s string, args ...interface{}) { orig := node.Dump() s = fmt.Sprintf(s, args...) - c := bpparser.Comment{ - Comment: []string{fmt.Sprintf("// ANDROIDMK TRANSLATION ERROR: %s", s)}, - Slash: f.bpPos, - } + f.insertExtraComment(fmt.Sprintf("// ANDROIDMK TRANSLATION ERROR: %s", s)) lines := strings.Split(orig, "\n") for _, l := range lines { - c.Comment = append(c.Comment, "// "+l) + f.insertExtraComment("// " + l) } - f.incBpPos(len(lines)) - - f.comments = append(f.comments, c) } func (f *bpFile) setMkPos(pos, end scanner.Position) { @@ -54,11 +65,6 @@ func (f *bpFile) setMkPos(pos, end scanner.Position) { f.mkPos = end } -// Called when inserting extra lines into the blueprint file -func (f *bpFile) incBpPos(lines int) { - f.bpPos.Line += lines -} - type conditional struct { cond string eq bool @@ -104,10 +110,7 @@ func convertFile(filename string, buffer *bytes.Buffer) (string, []error) { switch x := node.(type) { case *mkparser.Comment: - file.comments = append(file.comments, bpparser.Comment{ - Slash: file.bpPos, - Comment: []string{"//" + x.Comment}, - }) + file.insertComment("//" + x.Comment) case *mkparser.Assignment: handleAssignment(file, x, assignmentCond) case *mkparser.Directive: