| 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 '../parser/parser.dart' show FormalParameterType, optional; | 7 import '../parser/parser.dart' show FormalParameterType, optional; |
| 8 | 8 |
| 9 import '../parser/error_kind.dart' show ErrorKind; | 9 import '../parser/error_kind.dart' show ErrorKind; |
| 10 | 10 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 168 |
| 169 @override | 169 @override |
| 170 Expression toValue(Object node) { | 170 Expression toValue(Object node) { |
| 171 if (node is UnresolvedIdentifier) { | 171 if (node is UnresolvedIdentifier) { |
| 172 return throwNoSuchMethodError( | 172 return throwNoSuchMethodError( |
| 173 node.name.name, new Arguments.empty(), node.fileOffset, | 173 node.name.name, new Arguments.empty(), node.fileOffset, |
| 174 isGetter: true); | 174 isGetter: true); |
| 175 } else if (node is BuilderAccessor) { | 175 } else if (node is BuilderAccessor) { |
| 176 return node.buildSimpleRead(); | 176 return node.buildSimpleRead(); |
| 177 } else if (node is TypeVariableBuilder) { | 177 } else if (node is TypeVariableBuilder) { |
| 178 TypeParameterType type = node.buildTypesWithBuiltArguments(null); | 178 TypeParameterType type = node.buildTypesWithBuiltArguments(library, null); |
| 179 if (!isInstanceContext && type.parameter.parent is Class) { | 179 if (!isInstanceContext && type.parameter.parent is Class) { |
| 180 return buildCompileTimeError( | 180 return buildCompileTimeError( |
| 181 "Type variables can only be used in instance methods."); | 181 "Type variables can only be used in instance methods."); |
| 182 } else { | 182 } else { |
| 183 return new TypeLiteral(type); | 183 return new TypeLiteral(type); |
| 184 } | 184 } |
| 185 } else if (node is TypeDeclarationBuilder) { | 185 } else if (node is TypeDeclarationBuilder) { |
| 186 return new TypeLiteral(node.buildTypesWithBuiltArguments(null)); | 186 return new TypeLiteral(node.buildTypesWithBuiltArguments(library, null)); |
| 187 } else if (node is KernelTypeBuilder) { | 187 } else if (node is KernelTypeBuilder) { |
| 188 return new TypeLiteral(node.build()); | 188 return new TypeLiteral(node.build(library)); |
| 189 } else if (node is Expression) { | 189 } else if (node is Expression) { |
| 190 return node; | 190 return node; |
| 191 } else if (node is PrefixBuilder) { | 191 } else if (node is PrefixBuilder) { |
| 192 return buildCompileTimeError("A library can't be used as an expression."); | 192 return buildCompileTimeError("A library can't be used as an expression."); |
| 193 } else { | 193 } else { |
| 194 return internalError("Unhandled: ${node.runtimeType}"); | 194 return internalError("Unhandled: ${node.runtimeType}"); |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 | 197 |
| 198 Expression toEffect(Object node) { | 198 Expression toEffect(Object node) { |
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 exitLocalScope(); | 942 exitLocalScope(); |
| 943 push(block); | 943 push(block); |
| 944 } | 944 } |
| 945 | 945 |
| 946 @override | 946 @override |
| 947 void handleAssignmentExpression(Token token) { | 947 void handleAssignmentExpression(Token token) { |
| 948 debugEvent("AssignmentExpression"); | 948 debugEvent("AssignmentExpression"); |
| 949 Expression value = popForValue(); | 949 Expression value = popForValue(); |
| 950 var accessor = pop(); | 950 var accessor = pop(); |
| 951 if (accessor is TypeDeclarationBuilder) { | 951 if (accessor is TypeDeclarationBuilder) { |
| 952 push(wrapInvalid( | 952 push(wrapInvalid(new TypeLiteral( |
| 953 new TypeLiteral(accessor.buildTypesWithBuiltArguments(null)))); | 953 accessor.buildTypesWithBuiltArguments(library, null)))); |
| 954 } else if (accessor is! BuilderAccessor) { | 954 } else if (accessor is! BuilderAccessor) { |
| 955 push(buildCompileTimeError("Can't assign to this.", token.charOffset)); | 955 push(buildCompileTimeError("Can't assign to this.", token.charOffset)); |
| 956 } else { | 956 } else { |
| 957 push(new DelayedAssignment( | 957 push(new DelayedAssignment( |
| 958 this, token.charOffset, accessor, value, token.stringValue)); | 958 this, token.charOffset, accessor, value, token.stringValue)); |
| 959 } | 959 } |
| 960 } | 960 } |
| 961 | 961 |
| 962 @override | 962 @override |
| 963 void enterLoop(int charOffset) { | 963 void enterLoop(int charOffset) { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 } | 1141 } |
| 1142 } | 1142 } |
| 1143 push(new SymbolLiteral(value)); | 1143 push(new SymbolLiteral(value)); |
| 1144 } | 1144 } |
| 1145 | 1145 |
| 1146 DartType toKernelType(String name, List<DartType> arguments, int charOffset) { | 1146 DartType toKernelType(String name, List<DartType> arguments, int charOffset) { |
| 1147 if (identical(name, "void")) return const VoidType(); | 1147 if (identical(name, "void")) return const VoidType(); |
| 1148 if (identical(name, "dynamic")) return const DynamicType(); | 1148 if (identical(name, "dynamic")) return const DynamicType(); |
| 1149 Builder builder = scope.lookup(name, charOffset, uri); | 1149 Builder builder = scope.lookup(name, charOffset, uri); |
| 1150 if (builder is TypeDeclarationBuilder) { | 1150 if (builder is TypeDeclarationBuilder) { |
| 1151 return builder.buildTypesWithBuiltArguments(arguments); | 1151 return builder.buildTypesWithBuiltArguments(library, arguments); |
| 1152 } | 1152 } |
| 1153 if (builder == null) { | 1153 if (builder == null) { |
| 1154 warning("Type not found: '$name'.", charOffset); | 1154 warning("Type not found: '$name'.", charOffset); |
| 1155 } else { | 1155 } else { |
| 1156 warning("Not a type: '$name'.", charOffset); | 1156 warning("Not a type: '$name'.", charOffset); |
| 1157 } | 1157 } |
| 1158 // TODO(ahe): Create an error somehow. | 1158 // TODO(ahe): Create an error somehow. |
| 1159 return const DynamicType(); | 1159 return const DynamicType(); |
| 1160 } | 1160 } |
| 1161 | 1161 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 if (name is Identifier) { | 1195 if (name is Identifier) { |
| 1196 name = name.name; | 1196 name = name.name; |
| 1197 } | 1197 } |
| 1198 if (name is BuilderAccessor) { | 1198 if (name is BuilderAccessor) { |
| 1199 warning("'${beginToken.value}' isn't a type.", beginToken.charOffset); | 1199 warning("'${beginToken.value}' isn't a type.", beginToken.charOffset); |
| 1200 push(const DynamicType()); | 1200 push(const DynamicType()); |
| 1201 } else if (name is UnresolvedIdentifier) { | 1201 } else if (name is UnresolvedIdentifier) { |
| 1202 warning("'${name.name}' isn't a type.", beginToken.charOffset); | 1202 warning("'${name.name}' isn't a type.", beginToken.charOffset); |
| 1203 push(const DynamicType()); | 1203 push(const DynamicType()); |
| 1204 } else if (name is TypeVariableBuilder) { | 1204 } else if (name is TypeVariableBuilder) { |
| 1205 push(name.buildTypesWithBuiltArguments(arguments)); | 1205 push(name.buildTypesWithBuiltArguments(library, arguments)); |
| 1206 } else if (name is TypeDeclarationBuilder) { | 1206 } else if (name is TypeDeclarationBuilder) { |
| 1207 push(name.buildTypesWithBuiltArguments(arguments)); | 1207 push(name.buildTypesWithBuiltArguments(library, arguments)); |
| 1208 } else if (name is TypeBuilder) { | 1208 } else if (name is TypeBuilder) { |
| 1209 push(name.build()); | 1209 push(name.build(library)); |
| 1210 } else { | 1210 } else { |
| 1211 push(toKernelType(name, arguments, beginToken.charOffset)); | 1211 push(toKernelType(name, arguments, beginToken.charOffset)); |
| 1212 } | 1212 } |
| 1213 if (peek() is TypeParameterType) { | 1213 if (peek() is TypeParameterType) { |
| 1214 TypeParameterType type = peek(); | 1214 TypeParameterType type = peek(); |
| 1215 if (!isInstanceContext && type.parameter.parent is Class) { | 1215 if (!isInstanceContext && type.parameter.parent is Class) { |
| 1216 pop(); | 1216 pop(); |
| 1217 warning("Type variables can only be used in instance methods.", | 1217 warning("Type variables can only be used in instance methods.", |
| 1218 beginToken.charOffset); | 1218 beginToken.charOffset); |
| 1219 push(const DynamicType()); | 1219 push(const DynamicType()); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1286 dynamic builder = formalParameterScope.lookup(name.name, charOffset, uri); | 1286 dynamic builder = formalParameterScope.lookup(name.name, charOffset, uri); |
| 1287 if (builder == null) { | 1287 if (builder == null) { |
| 1288 if (thisKeyword == null) { | 1288 if (thisKeyword == null) { |
| 1289 internalError("Internal error: formal missing for '${name.name}'"); | 1289 internalError("Internal error: formal missing for '${name.name}'"); |
| 1290 } else { | 1290 } else { |
| 1291 addCompileTimeError(thisKeyword.charOffset, | 1291 addCompileTimeError(thisKeyword.charOffset, |
| 1292 "'${name.name}' isn't a field in this class."); | 1292 "'${name.name}' isn't a field in this class."); |
| 1293 thisKeyword = null; | 1293 thisKeyword = null; |
| 1294 } | 1294 } |
| 1295 } else if (thisKeyword == null) { | 1295 } else if (thisKeyword == null) { |
| 1296 variable = builder.build(); | 1296 variable = builder.build(library); |
| 1297 variable.initializer = name.initializer; | 1297 variable.initializer = name.initializer; |
| 1298 } else if (builder.isField && builder.parent == classBuilder) { | 1298 } else if (builder.isField && builder.parent == classBuilder) { |
| 1299 FieldBuilder field = builder; | 1299 FieldBuilder field = builder; |
| 1300 if (type != null) { | 1300 if (type != null) { |
| 1301 nit("Ignoring type on 'this' parameter '${name.name}'.", | 1301 nit("Ignoring type on 'this' parameter '${name.name}'.", |
| 1302 thisKeyword.charOffset); | 1302 thisKeyword.charOffset); |
| 1303 } | 1303 } |
| 1304 type = field.target.type ?? const DynamicType(); | 1304 type = field.target.type ?? const DynamicType(); |
| 1305 variable = new VariableDeclaration(name.name, | 1305 variable = new VariableDeclaration(name.name, |
| 1306 type: type, initializer: name.initializer); | 1306 type: type, initializer: name.initializer); |
| (...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2682 } else if (node is TypeDeclarationBuilder) { | 2682 } else if (node is TypeDeclarationBuilder) { |
| 2683 return node.name; | 2683 return node.name; |
| 2684 } else if (node is PrefixBuilder) { | 2684 } else if (node is PrefixBuilder) { |
| 2685 return node.name; | 2685 return node.name; |
| 2686 } else if (node is ThisPropertyAccessor) { | 2686 } else if (node is ThisPropertyAccessor) { |
| 2687 return node.name.name; | 2687 return node.name.name; |
| 2688 } else { | 2688 } else { |
| 2689 return internalError("Unhandled: ${node.runtimeType}"); | 2689 return internalError("Unhandled: ${node.runtimeType}"); |
| 2690 } | 2690 } |
| 2691 } | 2691 } |
| OLD | NEW |