OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library fasta.body_builder; | 5 library fasta.body_builder; |
6 | 6 |
7 import '../fasta_codes.dart' | 7 import '../fasta_codes.dart' |
8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; | 8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; |
9 | 9 |
10 import '../parser/parser.dart' show FormalParameterType, optional; | 10 import '../parser/parser.dart' show FormalParameterType, optional; |
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 {int equalsCharOffset: TreeNode.noOffset}) { | 950 {int equalsCharOffset: TreeNode.noOffset}) { |
951 Identifier identifier = pop(); | 951 Identifier identifier = pop(); |
952 assert(currentLocalVariableModifiers != -1); | 952 assert(currentLocalVariableModifiers != -1); |
953 bool isConst = (currentLocalVariableModifiers & constMask) != 0; | 953 bool isConst = (currentLocalVariableModifiers & constMask) != 0; |
954 bool isFinal = (currentLocalVariableModifiers & finalMask) != 0; | 954 bool isFinal = (currentLocalVariableModifiers & finalMask) != 0; |
955 assert(isConst == constantExpressionRequired); | 955 assert(isConst == constantExpressionRequired); |
956 push(new VariableDeclaration(identifier.name, | 956 push(new VariableDeclaration(identifier.name, |
957 initializer: initializer, | 957 initializer: initializer, |
958 type: currentLocalVariableType ?? const DynamicType(), | 958 type: currentLocalVariableType ?? const DynamicType(), |
959 isFinal: isFinal, | 959 isFinal: isFinal, |
960 isConst: isConst)..fileEqualsOffset = equalsCharOffset); | 960 isConst: isConst) |
| 961 ..fileEqualsOffset = equalsCharOffset); |
961 } | 962 } |
962 | 963 |
963 @override | 964 @override |
964 void endFieldInitializer(Token assignmentOperator) { | 965 void endFieldInitializer(Token assignmentOperator) { |
965 debugEvent("FieldInitializer"); | 966 debugEvent("FieldInitializer"); |
966 assert(assignmentOperator.stringValue == "="); | 967 assert(assignmentOperator.stringValue == "="); |
967 push(popForValue()); | 968 push(popForValue()); |
968 } | 969 } |
969 | 970 |
970 @override | 971 @override |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 constantExpressionRequired = (modifiers & constMask) != 0; | 1005 constantExpressionRequired = (modifiers & constMask) != 0; |
1005 } | 1006 } |
1006 | 1007 |
1007 @override | 1008 @override |
1008 void endVariablesDeclaration(int count, Token endToken) { | 1009 void endVariablesDeclaration(int count, Token endToken) { |
1009 debugEvent("VariablesDeclaration"); | 1010 debugEvent("VariablesDeclaration"); |
1010 List<VariableDeclaration> variables = popList(count); | 1011 List<VariableDeclaration> variables = popList(count); |
1011 constantExpressionRequired = pop(); | 1012 constantExpressionRequired = pop(); |
1012 currentLocalVariableType = pop(); | 1013 currentLocalVariableType = pop(); |
1013 currentLocalVariableModifiers = pop(); | 1014 currentLocalVariableModifiers = pop(); |
| 1015 pop(); // Metadata. |
1014 if (variables.length != 1) { | 1016 if (variables.length != 1) { |
1015 push(variables); | 1017 push(variables); |
1016 } else { | 1018 } else { |
1017 push(variables.single); | 1019 push(variables.single); |
1018 } | 1020 } |
1019 } | 1021 } |
1020 | 1022 |
1021 @override | 1023 @override |
1022 void endBlock(int count, Token beginToken, Token endToken) { | 1024 void endBlock(int count, Token beginToken, Token endToken) { |
1023 debugEvent("Block"); | 1025 debugEvent("Block"); |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 FieldBuilder field = builder; | 1408 FieldBuilder field = builder; |
1407 if (type != null) { | 1409 if (type != null) { |
1408 nit("Ignoring type on 'this' parameter '${name.name}'.", | 1410 nit("Ignoring type on 'this' parameter '${name.name}'.", |
1409 thisKeyword.charOffset); | 1411 thisKeyword.charOffset); |
1410 } | 1412 } |
1411 type = field.target.type ?? const DynamicType(); | 1413 type = field.target.type ?? const DynamicType(); |
1412 variable = new VariableDeclaration(name.name, | 1414 variable = new VariableDeclaration(name.name, |
1413 type: type, | 1415 type: type, |
1414 initializer: name.initializer, | 1416 initializer: name.initializer, |
1415 isFinal: isFinal, | 1417 isFinal: isFinal, |
1416 isConst: isConst)..fileOffset = name.fileOffset; | 1418 isConst: isConst) |
| 1419 ..fileOffset = name.fileOffset; |
1417 } else { | 1420 } else { |
1418 addCompileTimeError( | 1421 addCompileTimeError( |
1419 name.fileOffset, "'${name.name}' isn't a field in this class."); | 1422 name.fileOffset, "'${name.name}' isn't a field in this class."); |
1420 } | 1423 } |
1421 } | 1424 } |
1422 variable ??= new VariableDeclaration(name.name, | 1425 variable ??= new VariableDeclaration(name.name, |
1423 type: type ?? const DynamicType(), | 1426 type: type ?? const DynamicType(), |
1424 initializer: name.initializer, | 1427 initializer: name.initializer, |
1425 isFinal: isFinal, | 1428 isFinal: isFinal, |
1426 isConst: isConst)..fileOffset = name.fileOffset; | 1429 isConst: isConst) |
| 1430 ..fileOffset = name.fileOffset; |
1427 push(variable); | 1431 push(variable); |
1428 } | 1432 } |
1429 | 1433 |
1430 @override | 1434 @override |
1431 void endOptionalFormalParameters( | 1435 void endOptionalFormalParameters( |
1432 int count, Token beginToken, Token endToken) { | 1436 int count, Token beginToken, Token endToken) { |
1433 debugEvent("OptionalFormalParameters"); | 1437 debugEvent("OptionalFormalParameters"); |
1434 FormalParameterType kind = optional("{", beginToken) | 1438 FormalParameterType kind = optional("{", beginToken) |
1435 ? FormalParameterType.NAMED | 1439 ? FormalParameterType.NAMED |
1436 : FormalParameterType.POSITIONAL; | 1440 : FormalParameterType.POSITIONAL; |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2009 variable = new VariableDeclaration.forValue(null); | 2013 variable = new VariableDeclaration.forValue(null); |
2010 body = combineStatements( | 2014 body = combineStatements( |
2011 new ExpressionStatement(lvalue | 2015 new ExpressionStatement(lvalue |
2012 .buildAssignment(new VariableGet(variable), voidContext: true)), | 2016 .buildAssignment(new VariableGet(variable), voidContext: true)), |
2013 body); | 2017 body); |
2014 } else { | 2018 } else { |
2015 variable = new VariableDeclaration.forValue(buildCompileTimeError( | 2019 variable = new VariableDeclaration.forValue(buildCompileTimeError( |
2016 "Expected lvalue, but got ${lvalue}", forToken.next.next.charOffset)); | 2020 "Expected lvalue, but got ${lvalue}", forToken.next.next.charOffset)); |
2017 } | 2021 } |
2018 Statement result = new ForInStatement(variable, expression, body, | 2022 Statement result = new ForInStatement(variable, expression, body, |
2019 isAsync: awaitToken != null)..fileOffset = body.fileOffset; | 2023 isAsync: awaitToken != null) |
| 2024 ..fileOffset = body.fileOffset; |
2020 if (breakTarget.hasUsers) { | 2025 if (breakTarget.hasUsers) { |
2021 result = new LabeledStatement(result); | 2026 result = new LabeledStatement(result); |
2022 breakTarget.resolveBreaks(result); | 2027 breakTarget.resolveBreaks(result); |
2023 } | 2028 } |
2024 exitLoopOrSwitch(result); | 2029 exitLoopOrSwitch(result); |
2025 } | 2030 } |
2026 | 2031 |
2027 @override | 2032 @override |
2028 void handleLabel(Token token) { | 2033 void handleLabel(Token token) { |
2029 debugEvent("Label"); | 2034 debugEvent("Label"); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2167 debugEvent("SwitchCase"); | 2172 debugEvent("SwitchCase"); |
2168 Block block = popBlock(statementCount, firstToken.charOffset); | 2173 Block block = popBlock(statementCount, firstToken.charOffset); |
2169 exitLocalScope(); | 2174 exitLocalScope(); |
2170 List<Label> labels = pop(); | 2175 List<Label> labels = pop(); |
2171 List<Expression> expressions = pop(); | 2176 List<Expression> expressions = pop(); |
2172 List<int> expressionOffsets = <int>[]; | 2177 List<int> expressionOffsets = <int>[]; |
2173 for (Expression expression in expressions) { | 2178 for (Expression expression in expressions) { |
2174 expressionOffsets.add(expression.fileOffset); | 2179 expressionOffsets.add(expression.fileOffset); |
2175 } | 2180 } |
2176 push(new SwitchCase(expressions, expressionOffsets, block, | 2181 push(new SwitchCase(expressions, expressionOffsets, block, |
2177 isDefault: defaultKeyword != null)..fileOffset = firstToken.charOffset); | 2182 isDefault: defaultKeyword != null) |
| 2183 ..fileOffset = firstToken.charOffset); |
2178 push(labels); | 2184 push(labels); |
2179 } | 2185 } |
2180 | 2186 |
2181 @override | 2187 @override |
2182 void endSwitchStatement(Token switchKeyword, Token endToken) { | 2188 void endSwitchStatement(Token switchKeyword, Token endToken) { |
2183 debugEvent("SwitchStatement"); | 2189 debugEvent("SwitchStatement"); |
2184 // Do nothing. Handled by [endSwitchBlock]. | 2190 // Do nothing. Handled by [endSwitchBlock]. |
2185 } | 2191 } |
2186 | 2192 |
2187 @override | 2193 @override |
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2899 } else if (node is PrefixBuilder) { | 2905 } else if (node is PrefixBuilder) { |
2900 return node.name; | 2906 return node.name; |
2901 } else if (node is ThisAccessor) { | 2907 } else if (node is ThisAccessor) { |
2902 return node.isSuper ? "super" : "this"; | 2908 return node.isSuper ? "super" : "this"; |
2903 } else if (node is FastaAccessor) { | 2909 } else if (node is FastaAccessor) { |
2904 return node.plainNameForRead; | 2910 return node.plainNameForRead; |
2905 } else { | 2911 } else { |
2906 return internalError("Unhandled: ${node.runtimeType}"); | 2912 return internalError("Unhandled: ${node.runtimeType}"); |
2907 } | 2913 } |
2908 } | 2914 } |
OLD | NEW |