Fix blank line translation once and for all

am: 7fd911f713

* commit '7fd911f713937029ec9a61602b2086c05a672b96':
  Fix blank line translation once and for all

Change-Id: Ie7188b30447830bda3b7a496a6519e60b2a4ca50
This commit is contained in:
Colin Cross
2016-05-26 16:49:59 +00:00
committed by android-build-merger

View File

@@ -23,8 +23,8 @@ type bpFile struct {
scope mkparser.Scope scope mkparser.Scope
module *bpparser.Module module *bpparser.Module
pos scanner.Position mkPos scanner.Position // Position of the last handled line in the makefile
prevLine, line int bpPos scanner.Position // Position of the last emitted line to the blueprint file
inModule bool inModule bool
} }
@@ -32,36 +32,31 @@ type bpFile struct {
func (f *bpFile) errorf(thing mkparser.MakeThing, s string, args ...interface{}) { func (f *bpFile) errorf(thing mkparser.MakeThing, s string, args ...interface{}) {
orig := thing.Dump() orig := thing.Dump()
s = fmt.Sprintf(s, args...) s = fmt.Sprintf(s, args...)
f.comments = append(f.comments, bpparser.Comment{ c := bpparser.Comment{
Comment: []string{fmt.Sprintf("// ANDROIDMK TRANSLATION ERROR: %s", s)}, Comment: []string{fmt.Sprintf("// ANDROIDMK TRANSLATION ERROR: %s", s)},
Pos: f.pos, Pos: f.bpPos,
}) }
lines := strings.Split(orig, "\n") lines := strings.Split(orig, "\n")
for _, l := range lines { for _, l := range lines {
f.incPos() c.Comment = append(c.Comment, "// "+l)
f.comments = append(f.comments, bpparser.Comment{
Comment: []string{"// " + l},
Pos: f.pos,
})
} }
f.incBpPos(len(lines))
f.comments = append(f.comments, c)
} }
func (f *bpFile) setPos(pos, endPos scanner.Position) { func (f *bpFile) setMkPos(pos, end scanner.Position) {
f.pos = pos if pos.Line < f.mkPos.Line {
panic(fmt.Errorf("out of order lines, %q after %q", pos, f.mkPos))
f.line++
if f.pos.Line > f.prevLine+1 {
f.line++
} }
f.bpPos.Line += (pos.Line - f.mkPos.Line)
f.pos.Line = f.line f.mkPos = end
f.prevLine = endPos.Line
} }
func (f *bpFile) incPos() { // Called when inserting extra lines into the blueprint file
f.pos.Line++ func (f *bpFile) incBpPos(lines int) {
f.line++ f.bpPos.Line += lines
f.prevLine++
} }
type conditional struct { type conditional struct {
@@ -96,12 +91,12 @@ func main() {
var assignmentCond *conditional var assignmentCond *conditional
for _, t := range things { for _, t := range things {
file.setPos(t.Pos(), t.EndPos()) file.setMkPos(t.Pos(), t.EndPos())
if comment, ok := t.AsComment(); ok { if comment, ok := t.AsComment(); ok {
file.comments = append(file.comments, bpparser.Comment{ file.comments = append(file.comments, bpparser.Comment{
Pos: file.pos,
Comment: []string{"//" + comment.Comment}, Comment: []string{"//" + comment.Comment},
Pos: file.bpPos,
}) })
} else if assignment, ok := t.AsAssignment(); ok { } else if assignment, ok := t.AsAssignment(); ok {
handleAssignment(file, assignment, assignmentCond) handleAssignment(file, assignment, assignmentCond)
@@ -275,7 +270,7 @@ func handleModuleConditionals(file *bpFile, directive mkparser.Directive, conds
disabledPrefix := conditionalTranslations[c.cond][!c.eq] disabledPrefix := conditionalTranslations[c.cond][!c.eq]
// Create a fake assignment with enabled = false // Create a fake assignment with enabled = false
val, err := makeVariableToBlueprint(file, mkparser.SimpleMakeString("false", file.pos), bpparser.Bool) val, err := makeVariableToBlueprint(file, mkparser.SimpleMakeString("false", file.bpPos), bpparser.Bool)
if err == nil { if err == nil {
err = setVariable(file, false, disabledPrefix, "enabled", val, true) err = setVariable(file, false, disabledPrefix, "enabled", val, true)
} }
@@ -290,14 +285,14 @@ func makeModule(file *bpFile, t string) {
Name: t, Name: t,
Pos: file.module.LbracePos, Pos: file.module.LbracePos,
} }
file.module.RbracePos = file.pos file.module.RbracePos = file.bpPos
file.defs = append(file.defs, file.module) file.defs = append(file.defs, file.module)
file.inModule = false file.inModule = false
} }
func resetModule(file *bpFile) { func resetModule(file *bpFile) {
file.module = &bpparser.Module{} file.module = &bpparser.Module{}
file.module.LbracePos = file.pos file.module.LbracePos = file.bpPos
file.localAssignments = make(map[string]*bpparser.Property) file.localAssignments = make(map[string]*bpparser.Property)
file.inModule = true file.inModule = true
} }
@@ -331,7 +326,7 @@ func setVariable(file *bpFile, plusequals bool, prefix, name string, value *bppa
name = prefix + "." + name name = prefix + "." + name
} }
pos := file.pos pos := file.bpPos
var oldValue *bpparser.Value var oldValue *bpparser.Value
if local { if local {