Chromium Code Reviews| Index: pkg/front_end/lib/src/fasta/kernel/body_builder.dart |
| diff --git a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart |
| index 97e7af17d8020cc2b7ec5a0481a724cbc67e6da4..14f21a21d86d667e04693831fd62ae42470241e4 100644 |
| --- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart |
| +++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart |
| @@ -126,6 +126,10 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper { |
| bool constantExpressionRequired = false; |
| + DartType currentLocalVariableType = const DynamicType(); |
| + |
| + int currentLocalVariableModifiers = -1; |
| + |
| BodyBuilder( |
| KernelLibraryBuilder library, |
| this.member, |
| @@ -899,15 +903,27 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper { |
| void endVariableInitializer(Token assignmentOperator) { |
| debugEvent("VariableInitializer"); |
| assert(assignmentOperator.stringValue == "="); |
| - Expression initializer = popForValue(); |
| - Identifier identifier = pop(); |
| - push(new VariableDeclaration(identifier.name, initializer: initializer) |
| - ..fileEqualsOffset = assignmentOperator.charOffset); |
| + pushNewLocalVariable(popForValue(), |
| + equalsCharOffset: assignmentOperator.charOffset); |
| } |
| @override |
| void handleNoVariableInitializer(Token token) { |
| debugEvent("NoVariableInitializer"); |
| + pushNewLocalVariable(null); |
| + } |
| + |
| + void pushNewLocalVariable(Expression initializer, |
| + {int equalsCharOffset: TreeNode.noOffset}) { |
| + Identifier identifier = pop(); |
| + bool isConst = (currentLocalVariableModifiers & constMask) != 0; |
|
karlklose
2017/03/23 09:52:15
assert(currentLocalVariableModifiers != -1) here?
ahe
2017/03/23 11:17:54
Done.
|
| + bool isFinal = (currentLocalVariableModifiers & finalMask) != 0; |
| + assert(isConst == constantExpressionRequired); |
| + push(new VariableDeclaration(identifier.name, |
| + initializer: initializer, |
| + type: currentLocalVariableType, |
| + isFinal: isFinal, |
| + isConst: isConst)..fileEqualsOffset = equalsCharOffset); |
| } |
| @override |
| @@ -927,15 +943,7 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper { |
| void endInitializedIdentifier(Token nameToken) { |
| // TODO(ahe): Use [InitializedIdentifier] here? |
| debugEvent("InitializedIdentifier"); |
| - TreeNode node = pop(); |
| - VariableDeclaration variable; |
| - if (node is VariableDeclaration) { |
| - variable = node; |
| - } else if (node is Identifier) { |
| - variable = new VariableDeclaration(node.name); |
| - } else { |
| - internalError("unhandled identifier: ${node.runtimeType}"); |
| - } |
| + VariableDeclaration variable = pop(); |
| variable.fileOffset = nameToken.charOffset; |
| push(variable); |
| scope[variable.name] = new KernelVariableBuilder( |
| @@ -943,22 +951,25 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper { |
| } |
| @override |
| + void beginVariablesDeclaration(Token token) { |
| + debugEvent("beginVariablesDeclaration"); |
| + DartType type = pop(); |
| + int modifiers = Modifier.validate(pop()); |
| + super.push(currentLocalVariableModifiers); |
|
Paul Berry
2017/03/23 10:50:52
Why not:
push(currentLocalVariableModifiers ?? Nu
ahe
2017/03/23 11:17:55
I need to use super.push to avoid changing inIniti
|
| + super.push(currentLocalVariableType); |
|
Paul Berry
2017/03/23 10:50:52
Similar question here.
ahe
2017/03/23 11:17:55
I'll change it to ?? NullValue.Type.
|
| + currentLocalVariableType = type ?? const DynamicType(); |
|
Paul Berry
2017/03/23 10:50:52
FYI, for type inference we will need to keep track
ahe
2017/03/23 11:17:54
Done.
|
| + currentLocalVariableModifiers = modifiers; |
| + super.push(constantExpressionRequired); |
|
Paul Berry
2017/03/23 10:50:52
AFAICT, `constantExpressionRequired` is never null
ahe
2017/03/23 11:17:54
As mentioned above, super.push is used to avoid in
|
| + constantExpressionRequired = (modifiers & constMask) != 0; |
| + } |
| + |
| + @override |
| void endVariablesDeclaration(int count, Token endToken) { |
| debugEvent("VariablesDeclaration"); |
| List<VariableDeclaration> variables = popList(count); |
| - DartType type = pop(); |
| - int modifiers = Modifier.validate(pop()); |
| - bool isConst = (modifiers & constMask) != 0; |
| - bool isFinal = (modifiers & finalMask) != 0; |
| - if (type != null || isConst || isFinal) { |
| - type ??= const DynamicType(); |
| - for (VariableDeclaration variable in variables) { |
| - variable |
| - ..type = type |
| - ..isConst = isConst |
| - ..isFinal = isFinal; |
| - } |
| - } |
| + constantExpressionRequired = pop(); |
| + currentLocalVariableType = pop(); |
| + currentLocalVariableModifiers = pop(); |
| if (variables.length != 1) { |
| push(variables); |
| } else { |