Merge "Remove variableDefinedExpr" am: 6a21d959e5 am: 88720b9807

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1963693

Change-Id: Ia8ae5164509f94e7bc4e1c6cd780e8e765b3ddc2
This commit is contained in:
Treehugger Robot 2022-02-01 04:42:12 +00:00 committed by Automerger Merge Worker
commit f59ea3c29a
3 changed files with 15 additions and 46 deletions

View file

@ -378,32 +378,6 @@ func (eq *eqExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) st
}
}
// variableDefinedExpr corresponds to Make's ifdef VAR
type variableDefinedExpr struct {
v variable
}
func (v *variableDefinedExpr) emit(gctx *generationContext) {
if v.v != nil {
v.v.emitDefined(gctx)
return
}
gctx.writef("%s(%q)", cfnWarning, "TODO(VAR)")
}
func (_ *variableDefinedExpr) typ() starlarkType {
return starlarkTypeBool
}
func (v *variableDefinedExpr) emitListVarCopy(gctx *generationContext) {
v.emit(gctx)
}
func (v *variableDefinedExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr {
// TODO: VariableDefinedExpr isn't really an expression?
return v
}
type listExpr struct {
items []starlarkExpr
}

View file

@ -1003,19 +1003,14 @@ func (ctx *parseContext) processBranch(check *mkparser.Directive) {
ctx.popReceiver()
}
func (ctx *parseContext) newIfDefinedNode(check *mkparser.Directive) (starlarkExpr, bool) {
if !check.Args.Const() {
return ctx.newBadExpr(check, "ifdef variable ref too complex: %s", check.Args.Dump()), false
}
v := ctx.addVariable(check.Args.Strings[0])
return &variableDefinedExpr{v}, true
}
func (ctx *parseContext) parseCondition(check *mkparser.Directive) starlarkNode {
switch check.Name {
case "ifdef", "ifndef", "elifdef", "elifndef":
v, ok := ctx.newIfDefinedNode(check)
if ok && strings.HasSuffix(check.Name, "ndef") {
if !check.Args.Const() {
return &exprNode{expr: ctx.newBadExpr(check, "ifdef variable ref too complex: %s", check.Args.Dump())}
}
v := NewVariableRefExpr(ctx.addVariable(check.Args.Strings[0]), false)
if strings.HasSuffix(check.Name, "ndef") {
v = &notExpr{v}
}
return &ifNode{

View file

@ -131,7 +131,7 @@ load(":part1.star|init", _part1_init = "init")
def init(g, handle):
cfg = rblf.cfg(handle)
rblf.inherit(handle, "part", _part_init)
if g.get("PRODUCT_NAME") != None:
if cfg.get("PRODUCT_NAME", ""):
if not _part1_init:
rblf.mkerror("product.mk", "Cannot find %s" % (":part1.star"))
rblf.inherit(handle, "part1", _part1_init)
@ -174,7 +174,7 @@ load(":part1.star|init", _part1_init = "init")
def init(g, handle):
cfg = rblf.cfg(handle)
_part_init(g, handle)
if g.get("PRODUCT_NAME") != None:
if cfg.get("PRODUCT_NAME", ""):
if not _part1_init:
rblf.mkerror("product.mk", "Cannot find %s" % (":part1.star"))
_part1_init(g, handle)
@ -231,7 +231,7 @@ endif
def init(g, handle):
cfg = rblf.cfg(handle)
if g.get("PRODUCT_NAME") != None:
if cfg.get("PRODUCT_NAME", ""):
cfg["PRODUCT_NAME"] = "gizmo"
else:
pass
@ -275,7 +275,7 @@ endif
def init(g, handle):
cfg = rblf.cfg(handle)
if g.get("PRODUCT_NAME") != None:
if cfg.get("PRODUCT_NAME", ""):
# Comment
pass
else:
@ -296,7 +296,7 @@ endif
def init(g, handle):
cfg = rblf.cfg(handle)
if not g.get("PRODUCT_NAME") != None:
if not cfg.get("PRODUCT_NAME", ""):
cfg["PRODUCT_NAME"] = "gizmo1"
else:
cfg["PRODUCT_NAME"] = "gizmo2"
@ -315,9 +315,9 @@ endif
def init(g, handle):
cfg = rblf.cfg(handle)
if g.get("PRODUCT_NAME") != None:
if cfg.get("PRODUCT_NAME", ""):
cfg["PRODUCT_NAME"] = "gizmo"
elif not g.get("PRODUCT_PACKAGES") != None:
elif not cfg.get("PRODUCT_PACKAGES", []):
# Comment
pass
`,
@ -509,11 +509,11 @@ endif
def init(g, handle):
cfg = rblf.cfg(handle)
if g.get("PRODUCT_NAME") != None:
if cfg.get("PRODUCT_NAME", ""):
cfg["PRODUCT_PACKAGES"] = ["pack-if0"]
if g.get("PRODUCT_MODEL") != None:
if cfg.get("PRODUCT_MODEL", ""):
cfg["PRODUCT_PACKAGES"] = ["pack-if-if"]
elif g.get("PRODUCT_NAME") != None:
elif cfg.get("PRODUCT_NAME", ""):
cfg["PRODUCT_PACKAGES"] = ["pack-if-elif"]
else:
cfg["PRODUCT_PACKAGES"] = ["pack-if-else"]