Simplify and correct variable assignments

- Remove asgnMaybeAppend, it was only used to indicate
  that the asignment needs a setDefault. But really, all
  types of variable assignments need setDefault if they're
  self-referential.
- Remove local_append/local_set_default because there was
  no implementation for them written in product_config.rbc
  anyways.
- Correct productConfigVariable.emitDefined using the global
  variables instead of the product config variables.
- Emit setDefaults for all types of assignments if they're
  self referential.

Bug: 222737841
Test: go test
Change-Id: I06a0f90f16d5900049d473281e6d5ef5e93e67da
This commit is contained in:
Cole Faust
2022-03-09 16:00:17 -08:00
parent ce73506a85
commit e2a37988ff
4 changed files with 88 additions and 45 deletions

View File

@@ -184,10 +184,9 @@ type assignmentFlavor int
const (
// Assignment flavors
asgnSet assignmentFlavor = iota // := or =
asgnMaybeSet assignmentFlavor = iota // ?= and variable may be unset
asgnAppend assignmentFlavor = iota // += and variable has been set before
asgnMaybeAppend assignmentFlavor = iota // += and variable may be unset
asgnSet assignmentFlavor = iota // := or =
asgnMaybeSet assignmentFlavor = iota // ?=
asgnAppend assignmentFlavor = iota // +=
)
type assignmentNode struct {
@@ -215,6 +214,20 @@ func (asgn *assignmentNode) emit(gctx *generationContext) {
}
}
func (asgn *assignmentNode) isSelfReferential() bool {
if asgn.flavor == asgnAppend {
return true
}
isSelfReferential := false
asgn.value.transform(func(expr starlarkExpr) starlarkExpr {
if ref, ok := expr.(*variableRefExpr); ok && ref.ref.name() == asgn.lhs.name() {
isSelfReferential = true
}
return nil
})
return isSelfReferential
}
type exprNode struct {
expr starlarkExpr
}