| 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, MemberKind, optional; | 10 import '../parser/parser.dart' show FormalParameterType, MemberKind, optional; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 import 'package:kernel/core_types.dart' show CoreTypes; | 43 import 'package:kernel/core_types.dart' show CoreTypes; |
| 44 | 44 |
| 45 import 'frontend_accessors.dart' show buildIsNull, makeBinary, makeLet; | 45 import 'frontend_accessors.dart' show buildIsNull, makeBinary, makeLet; |
| 46 | 46 |
| 47 import '../../scanner/token.dart' show Token; | 47 import '../../scanner/token.dart' show Token; |
| 48 | 48 |
| 49 import '../scanner/token.dart' | 49 import '../scanner/token.dart' |
| 50 show BeginGroupToken, isBinaryOperator, isMinusOperator; | 50 show BeginGroupToken, isBinaryOperator, isMinusOperator; |
| 51 | 51 |
| 52 import '../errors.dart' show formatUnexpected, internalError; | 52 import '../errors.dart' show InputError, formatUnexpected, internalError; |
| 53 | 53 |
| 54 import '../source/scope_listener.dart' | 54 import '../source/scope_listener.dart' |
| 55 show JumpTargetKind, NullValue, ScopeListener; | 55 show JumpTargetKind, NullValue, ScopeListener; |
| 56 | 56 |
| 57 import '../scope.dart' show ProblemBuilder; | 57 import '../scope.dart' show ProblemBuilder; |
| 58 | 58 |
| 59 import 'fasta_accessors.dart'; | 59 import 'fasta_accessors.dart'; |
| 60 | 60 |
| 61 import '../quote.dart' | 61 import '../quote.dart' |
| 62 show | 62 show |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 if (outerSwitchScope == null) { | 298 if (outerSwitchScope == null) { |
| 299 addCompileTimeError(-1, "Label not found: '$name'."); | 299 addCompileTimeError(-1, "Label not found: '$name'."); |
| 300 } else { | 300 } else { |
| 301 outerSwitchScope.forwardDeclareLabel(name, builder); | 301 outerSwitchScope.forwardDeclareLabel(name, builder); |
| 302 } | 302 } |
| 303 }); | 303 }); |
| 304 } | 304 } |
| 305 switchScope = outerSwitchScope; | 305 switchScope = outerSwitchScope; |
| 306 } | 306 } |
| 307 | 307 |
| 308 void declareVariable(VariableDeclaration variable) { |
| 309 InputError error = scope.declare( |
| 310 variable.name, |
| 311 new KernelVariableBuilder( |
| 312 variable, member ?? classBuilder ?? library, uri), |
| 313 variable.fileOffset, |
| 314 uri); |
| 315 if (error != null) { |
| 316 addCompileTimeError( |
| 317 variable.fileOffset, |
| 318 "Can't declare '${variable.name}' because it was already used in " |
| 319 "this scope."); |
| 320 library.addCompileTimeError(error.charOffset, error.error, |
| 321 fileUri: error.uri); |
| 322 } |
| 323 } |
| 324 |
| 308 @override | 325 @override |
| 309 JumpTarget createJumpTarget(JumpTargetKind kind, int charOffset) { | 326 JumpTarget createJumpTarget(JumpTargetKind kind, int charOffset) { |
| 310 return new JumpTarget(kind, functionNestingLevel, member, charOffset); | 327 return new JumpTarget(kind, functionNestingLevel, member, charOffset); |
| 311 } | 328 } |
| 312 | 329 |
| 313 @override | 330 @override |
| 314 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { | 331 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { |
| 315 debugEvent("Metadata"); | 332 debugEvent("Metadata"); |
| 316 pop(); // Arguments. | 333 pop(); // Arguments. |
| 317 popIfNotNull(periodBeforeName); // Postfix. | 334 popIfNotNull(periodBeforeName); // Postfix. |
| (...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 } | 1153 } |
| 1137 } | 1154 } |
| 1138 | 1155 |
| 1139 @override | 1156 @override |
| 1140 void endInitializedIdentifier(Token nameToken) { | 1157 void endInitializedIdentifier(Token nameToken) { |
| 1141 // TODO(ahe): Use [InitializedIdentifier] here? | 1158 // TODO(ahe): Use [InitializedIdentifier] here? |
| 1142 debugEvent("InitializedIdentifier"); | 1159 debugEvent("InitializedIdentifier"); |
| 1143 VariableDeclaration variable = pop(); | 1160 VariableDeclaration variable = pop(); |
| 1144 variable.fileOffset = nameToken.charOffset; | 1161 variable.fileOffset = nameToken.charOffset; |
| 1145 push(variable); | 1162 push(variable); |
| 1146 scope[variable.name] = new KernelVariableBuilder( | 1163 declareVariable(variable); |
| 1147 variable, member ?? classBuilder ?? library, uri); | |
| 1148 } | 1164 } |
| 1149 | 1165 |
| 1150 @override | 1166 @override |
| 1151 void beginVariablesDeclaration(Token token) { | 1167 void beginVariablesDeclaration(Token token) { |
| 1152 debugEvent("beginVariablesDeclaration"); | 1168 debugEvent("beginVariablesDeclaration"); |
| 1153 DartType type = pop(); | 1169 DartType type = pop(); |
| 1154 int modifiers = Modifier.validate(pop()); | 1170 int modifiers = Modifier.validate(pop()); |
| 1155 super.push(currentLocalVariableModifiers); | 1171 super.push(currentLocalVariableModifiers); |
| 1156 super.push(currentLocalVariableType ?? NullValue.Type); | 1172 super.push(currentLocalVariableType ?? NullValue.Type); |
| 1157 currentLocalVariableType = type; | 1173 currentLocalVariableType = type; |
| (...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2055 @override | 2071 @override |
| 2056 void endFunctionName(Token beginToken, Token token) { | 2072 void endFunctionName(Token beginToken, Token token) { |
| 2057 debugEvent("FunctionName"); | 2073 debugEvent("FunctionName"); |
| 2058 Identifier name = pop(); | 2074 Identifier name = pop(); |
| 2059 VariableDeclaration variable = astFactory.variableDeclaration( | 2075 VariableDeclaration variable = astFactory.variableDeclaration( |
| 2060 name.name, name.token, functionNestingLevel, | 2076 name.name, name.token, functionNestingLevel, |
| 2061 isFinal: true, isLocalFunction: true); | 2077 isFinal: true, isLocalFunction: true); |
| 2062 push(new KernelFunctionDeclaration( | 2078 push(new KernelFunctionDeclaration( |
| 2063 variable, new FunctionNode(new InvalidStatement())) | 2079 variable, new FunctionNode(new InvalidStatement())) |
| 2064 ..fileOffset = beginToken.charOffset); | 2080 ..fileOffset = beginToken.charOffset); |
| 2065 scope[variable.name] = new KernelVariableBuilder( | 2081 declareVariable(variable); |
| 2066 variable, member ?? classBuilder ?? library, uri); | |
| 2067 enterLocalScope(); | 2082 enterLocalScope(); |
| 2068 } | 2083 } |
| 2069 | 2084 |
| 2070 void enterFunction() { | 2085 void enterFunction() { |
| 2071 debugEvent("enterFunction"); | 2086 debugEvent("enterFunction"); |
| 2072 functionNestingLevel++; | 2087 functionNestingLevel++; |
| 2073 push(switchScope ?? NullValue.SwitchScope); | 2088 push(switchScope ?? NullValue.SwitchScope); |
| 2074 switchScope = null; | 2089 switchScope = null; |
| 2075 push(inCatchBlock); | 2090 push(inCatchBlock); |
| 2076 inCatchBlock = false; | 2091 inCatchBlock = false; |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2661 } | 2676 } |
| 2662 for (Expression argument in expressions.reversed) { | 2677 for (Expression argument in expressions.reversed) { |
| 2663 expression = new Let( | 2678 expression = new Let( |
| 2664 new VariableDeclaration.forValue(argument, isFinal: true), | 2679 new VariableDeclaration.forValue(argument, isFinal: true), |
| 2665 expression); | 2680 expression); |
| 2666 } | 2681 } |
| 2667 return expression; | 2682 return expression; |
| 2668 } | 2683 } |
| 2669 | 2684 |
| 2670 @override | 2685 @override |
| 2686 void addCompileTimeErrorFromMessage(FastaMessage message) { |
| 2687 library.addCompileTimeError(message.charOffset, message.message, |
| 2688 fileUri: message.uri); |
| 2689 } |
| 2690 |
| 2691 @override |
| 2671 void debugEvent(String name) { | 2692 void debugEvent(String name) { |
| 2672 // printEvent(name); | 2693 // printEvent(name); |
| 2673 } | 2694 } |
| 2674 | 2695 |
| 2675 @override | 2696 @override |
| 2676 StaticGet makeStaticGet(Member readTarget, Token token) { | 2697 StaticGet makeStaticGet(Member readTarget, Token token) { |
| 2677 // TODO(paulberry): only record the dependencies mandated by the top level | 2698 // TODO(paulberry): only record the dependencies mandated by the top level |
| 2678 // type inference spec. | 2699 // type inference spec. |
| 2679 if (fieldDependencies != null && readTarget is KernelField) { | 2700 if (fieldDependencies != null && readTarget is KernelField) { |
| 2680 var fieldNode = _typeInferrer.getFieldNodeForReadTarget(readTarget); | 2701 var fieldNode = _typeInferrer.getFieldNodeForReadTarget(readTarget); |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3167 if (starToken == null) { | 3188 if (starToken == null) { |
| 3168 return AsyncMarker.Async; | 3189 return AsyncMarker.Async; |
| 3169 } else { | 3190 } else { |
| 3170 assert(identical(starToken.stringValue, "*")); | 3191 assert(identical(starToken.stringValue, "*")); |
| 3171 return AsyncMarker.AsyncStar; | 3192 return AsyncMarker.AsyncStar; |
| 3172 } | 3193 } |
| 3173 } else { | 3194 } else { |
| 3174 return internalError("Unknown async modifier: $asyncToken"); | 3195 return internalError("Unknown async modifier: $asyncToken"); |
| 3175 } | 3196 } |
| 3176 } | 3197 } |
| OLD | NEW |