Make handleSimpleStatement also handle if statements
This simplifies its usage, as it can now handle virtually any Make node. Bug: 201700692 Test: go test Change-Id: I1786a441a706304673ea4a2973a21f93b95b945a
This commit is contained in:
@@ -965,25 +965,16 @@ func (ctx *parseContext) processBranch(check *mkparser.Directive) {
|
|||||||
ctx.pushReceiver(&block)
|
ctx.pushReceiver(&block)
|
||||||
for ctx.hasNodes() {
|
for ctx.hasNodes() {
|
||||||
node := ctx.getNode()
|
node := ctx.getNode()
|
||||||
if ctx.handleSimpleStatement(node) {
|
if d, ok := node.(*mkparser.Directive); ok {
|
||||||
continue
|
|
||||||
}
|
|
||||||
switch d := node.(type) {
|
|
||||||
case *mkparser.Directive:
|
|
||||||
switch d.Name {
|
switch d.Name {
|
||||||
case "else", "elifdef", "elifndef", "elifeq", "elifneq", "endif":
|
case "else", "elifdef", "elifndef", "elifeq", "elifneq", "endif":
|
||||||
ctx.popReceiver()
|
ctx.popReceiver()
|
||||||
ctx.receiver.newNode(&block)
|
ctx.receiver.newNode(&block)
|
||||||
ctx.backNode()
|
ctx.backNode()
|
||||||
return
|
return
|
||||||
case "ifdef", "ifndef", "ifeq", "ifneq":
|
|
||||||
ctx.handleIfBlock(d)
|
|
||||||
default:
|
|
||||||
ctx.errorf(d, "unexpected directive %s", d.Name)
|
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
ctx.errorf(node, "unexpected statement")
|
|
||||||
}
|
}
|
||||||
|
ctx.handleSimpleStatement(node)
|
||||||
}
|
}
|
||||||
ctx.fatalError = fmt.Errorf("no matching endif for %s", check.Dump())
|
ctx.fatalError = fmt.Errorf("no matching endif for %s", check.Dump())
|
||||||
ctx.popReceiver()
|
ctx.popReceiver()
|
||||||
@@ -1485,9 +1476,7 @@ func (ctx *parseContext) parseMakeString(node mkparser.Node, mk *mkparser.MakeSt
|
|||||||
// Handles the statements whose treatment is the same in all contexts: comment,
|
// Handles the statements whose treatment is the same in all contexts: comment,
|
||||||
// assignment, variable (which is a macro call in reality) and all constructs that
|
// assignment, variable (which is a macro call in reality) and all constructs that
|
||||||
// do not handle in any context ('define directive and any unrecognized stuff).
|
// do not handle in any context ('define directive and any unrecognized stuff).
|
||||||
// Return true if we handled it.
|
func (ctx *parseContext) handleSimpleStatement(node mkparser.Node) {
|
||||||
func (ctx *parseContext) handleSimpleStatement(node mkparser.Node) bool {
|
|
||||||
handled := true
|
|
||||||
switch x := node.(type) {
|
switch x := node.(type) {
|
||||||
case *mkparser.Comment:
|
case *mkparser.Comment:
|
||||||
ctx.maybeHandleAnnotation(x)
|
ctx.maybeHandleAnnotation(x)
|
||||||
@@ -1502,13 +1491,14 @@ func (ctx *parseContext) handleSimpleStatement(node mkparser.Node) bool {
|
|||||||
ctx.handleDefine(x)
|
ctx.handleDefine(x)
|
||||||
case "include", "-include":
|
case "include", "-include":
|
||||||
ctx.handleInclude(node, ctx.parseMakeString(node, x.Args), x.Name[0] != '-')
|
ctx.handleInclude(node, ctx.parseMakeString(node, x.Args), x.Name[0] != '-')
|
||||||
|
case "ifeq", "ifneq", "ifdef", "ifndef":
|
||||||
|
ctx.handleIfBlock(x)
|
||||||
default:
|
default:
|
||||||
handled = false
|
ctx.errorf(x, "unexpected directive %s", x.Name)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
ctx.errorf(x, "unsupported line %s", strings.ReplaceAll(x.Dump(), "\n", "\n#"))
|
ctx.errorf(x, "unsupported line %s", strings.ReplaceAll(x.Dump(), "\n", "\n#"))
|
||||||
}
|
}
|
||||||
return handled
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Processes annotation. An annotation is a comment that starts with #RBC# and provides
|
// Processes annotation. An annotation is a comment that starts with #RBC# and provides
|
||||||
@@ -1680,21 +1670,7 @@ func Convert(req Request) (*StarlarkScript, error) {
|
|||||||
}
|
}
|
||||||
ctx.pushReceiver(starScript)
|
ctx.pushReceiver(starScript)
|
||||||
for ctx.hasNodes() && ctx.fatalError == nil {
|
for ctx.hasNodes() && ctx.fatalError == nil {
|
||||||
node := ctx.getNode()
|
ctx.handleSimpleStatement(ctx.getNode())
|
||||||
if ctx.handleSimpleStatement(node) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
switch x := node.(type) {
|
|
||||||
case *mkparser.Directive:
|
|
||||||
switch x.Name {
|
|
||||||
case "ifeq", "ifneq", "ifdef", "ifndef":
|
|
||||||
ctx.handleIfBlock(x)
|
|
||||||
default:
|
|
||||||
ctx.errorf(x, "unexpected directive %s", x.Name)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
ctx.errorf(x, "unsupported line")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ctx.fatalError != nil {
|
if ctx.fatalError != nil {
|
||||||
return nil, ctx.fatalError
|
return nil, ctx.fatalError
|
||||||
|
Reference in New Issue
Block a user