Merge changes from topic \\'parser\\' am: c30f10e390
am: 749d12c3b9
Change-Id: I0ab3b6c306e57df5ab1b92cf099868075c0f624e
This commit is contained in:
@@ -16,7 +16,7 @@ import (
|
|||||||
// TODO: non-expanded variables with expressions
|
// TODO: non-expanded variables with expressions
|
||||||
|
|
||||||
type bpFile struct {
|
type bpFile struct {
|
||||||
comments []bpparser.Comment
|
comments []*bpparser.CommentGroup
|
||||||
defs []bpparser.Definition
|
defs []bpparser.Definition
|
||||||
localAssignments map[string]*bpparser.Property
|
localAssignments map[string]*bpparser.Property
|
||||||
globalAssignments map[string]*bpparser.Expression
|
globalAssignments map[string]*bpparser.Expression
|
||||||
@@ -29,21 +29,32 @@ type bpFile struct {
|
|||||||
inModule bool
|
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{}) {
|
func (f *bpFile) errorf(node mkparser.Node, s string, args ...interface{}) {
|
||||||
orig := node.Dump()
|
orig := node.Dump()
|
||||||
s = fmt.Sprintf(s, args...)
|
s = fmt.Sprintf(s, args...)
|
||||||
c := bpparser.Comment{
|
f.insertExtraComment(fmt.Sprintf("// ANDROIDMK TRANSLATION ERROR: %s", s))
|
||||||
Comment: []string{fmt.Sprintf("// ANDROIDMK TRANSLATION ERROR: %s", s)},
|
|
||||||
Slash: f.bpPos,
|
|
||||||
}
|
|
||||||
|
|
||||||
lines := strings.Split(orig, "\n")
|
lines := strings.Split(orig, "\n")
|
||||||
for _, l := range lines {
|
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) {
|
func (f *bpFile) setMkPos(pos, end scanner.Position) {
|
||||||
@@ -54,11 +65,6 @@ func (f *bpFile) setMkPos(pos, end scanner.Position) {
|
|||||||
f.mkPos = end
|
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 {
|
type conditional struct {
|
||||||
cond string
|
cond string
|
||||||
eq bool
|
eq bool
|
||||||
@@ -104,10 +110,7 @@ func convertFile(filename string, buffer *bytes.Buffer) (string, []error) {
|
|||||||
|
|
||||||
switch x := node.(type) {
|
switch x := node.(type) {
|
||||||
case *mkparser.Comment:
|
case *mkparser.Comment:
|
||||||
file.comments = append(file.comments, bpparser.Comment{
|
file.insertComment("//" + x.Comment)
|
||||||
Slash: file.bpPos,
|
|
||||||
Comment: []string{"//" + x.Comment},
|
|
||||||
})
|
|
||||||
case *mkparser.Assignment:
|
case *mkparser.Assignment:
|
||||||
handleAssignment(file, x, assignmentCond)
|
handleAssignment(file, x, assignmentCond)
|
||||||
case *mkparser.Directive:
|
case *mkparser.Directive:
|
||||||
@@ -290,10 +293,8 @@ func handleModuleConditionals(file *bpFile, directive *mkparser.Directive, conds
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeModule(file *bpFile, t string) {
|
func makeModule(file *bpFile, t string) {
|
||||||
file.module.Type = bpparser.Ident{
|
file.module.Type = t
|
||||||
Name: t,
|
file.module.TypePos = file.module.LBracePos
|
||||||
Pos: file.module.LBracePos,
|
|
||||||
}
|
|
||||||
file.module.RBracePos = file.bpPos
|
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
|
||||||
@@ -364,8 +365,8 @@ func setVariable(file *bpFile, plusequals bool, prefix, name string, value bppar
|
|||||||
prop := file.localAssignments[fqn]
|
prop := file.localAssignments[fqn]
|
||||||
if prop == nil {
|
if prop == nil {
|
||||||
prop = &bpparser.Property{
|
prop = &bpparser.Property{
|
||||||
Name: bpparser.Ident{Name: n, Pos: pos},
|
Name: n,
|
||||||
Pos: pos,
|
NamePos: pos,
|
||||||
Value: &bpparser.Map{
|
Value: &bpparser.Map{
|
||||||
Properties: []*bpparser.Property{},
|
Properties: []*bpparser.Property{},
|
||||||
},
|
},
|
||||||
@@ -377,9 +378,9 @@ func setVariable(file *bpFile, plusequals bool, prefix, name string, value bppar
|
|||||||
}
|
}
|
||||||
|
|
||||||
prop := &bpparser.Property{
|
prop := &bpparser.Property{
|
||||||
Name: bpparser.Ident{Name: names[len(names)-1], Pos: pos},
|
Name: names[len(names)-1],
|
||||||
Pos: pos,
|
NamePos: pos,
|
||||||
Value: value,
|
Value: value,
|
||||||
}
|
}
|
||||||
file.localAssignments[name] = prop
|
file.localAssignments[name] = prop
|
||||||
*container = append(*container, prop)
|
*container = append(*container, prop)
|
||||||
@@ -387,31 +388,26 @@ func setVariable(file *bpFile, plusequals bool, prefix, name string, value bppar
|
|||||||
} else {
|
} else {
|
||||||
if oldValue != nil && plusequals {
|
if oldValue != nil && plusequals {
|
||||||
a := &bpparser.Assignment{
|
a := &bpparser.Assignment{
|
||||||
Name: bpparser.Ident{
|
Name: name,
|
||||||
Name: name,
|
NamePos: pos,
|
||||||
Pos: pos,
|
|
||||||
},
|
|
||||||
Value: value,
|
Value: value,
|
||||||
OrigValue: value,
|
OrigValue: value,
|
||||||
Pos: pos,
|
EqualsPos: pos,
|
||||||
Assigner: "+=",
|
Assigner: "+=",
|
||||||
}
|
}
|
||||||
file.defs = append(file.defs, a)
|
file.defs = append(file.defs, a)
|
||||||
} else {
|
} else {
|
||||||
a := &bpparser.Assignment{
|
a := &bpparser.Assignment{
|
||||||
Name: bpparser.Ident{
|
Name: name,
|
||||||
Name: name,
|
NamePos: pos,
|
||||||
Pos: pos,
|
|
||||||
},
|
|
||||||
Value: value,
|
Value: value,
|
||||||
OrigValue: value,
|
OrigValue: value,
|
||||||
Pos: pos,
|
EqualsPos: pos,
|
||||||
Assigner: "=",
|
Assigner: "=",
|
||||||
}
|
}
|
||||||
file.globalAssignments[name] = &a.Value
|
file.globalAssignments[name] = &a.Value
|
||||||
file.defs = append(file.defs, a)
|
file.defs = append(file.defs, a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user