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 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 _typeInferrer.inferStatement(body); | 467 _typeInferrer.inferStatement(body); |
468 KernelFunctionBuilder builder = member; | 468 KernelFunctionBuilder builder = member; |
469 builder.body = body; | 469 builder.body = body; |
470 if (formals?.optional != null) { | 470 if (formals?.optional != null) { |
471 Iterator<FormalParameterBuilder> formalBuilders = | 471 Iterator<FormalParameterBuilder> formalBuilders = |
472 builder.formals.skip(formals.required.length).iterator; | 472 builder.formals.skip(formals.required.length).iterator; |
473 for (VariableDeclaration parameter in formals.optional.formals) { | 473 for (VariableDeclaration parameter in formals.optional.formals) { |
474 bool hasMore = formalBuilders.moveNext(); | 474 bool hasMore = formalBuilders.moveNext(); |
475 assert(hasMore); | 475 assert(hasMore); |
476 VariableDeclaration realParameter = formalBuilders.current.target; | 476 VariableDeclaration realParameter = formalBuilders.current.target; |
477 Expression initializer = parameter.initializer ?? new NullLiteral(); | 477 Expression initializer = |
| 478 parameter.initializer ?? astFactory.nullLiteral(null); |
478 realParameter.initializer = initializer..parent = realParameter; | 479 realParameter.initializer = initializer..parent = realParameter; |
479 } | 480 } |
480 } | 481 } |
481 if (builder is KernelConstructorBuilder) { | 482 if (builder is KernelConstructorBuilder) { |
482 finishConstructor(builder, asyncModifier); | 483 finishConstructor(builder, asyncModifier); |
483 } else if (builder is KernelProcedureBuilder) { | 484 } else if (builder is KernelProcedureBuilder) { |
484 builder.asyncModifier = asyncModifier; | 485 builder.asyncModifier = asyncModifier; |
485 } else { | 486 } else { |
486 internalError("Unhandled: ${builder.runtimeType}"); | 487 internalError("Unhandled: ${builder.runtimeType}"); |
487 } | 488 } |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 } | 771 } |
771 if (constantExpressionRequired) { | 772 if (constantExpressionRequired) { |
772 return buildCompileTimeError(message, charOffset); | 773 return buildCompileTimeError(message, charOffset); |
773 } | 774 } |
774 warning(message, charOffset); | 775 warning(message, charOffset); |
775 Constructor constructor = | 776 Constructor constructor = |
776 coreTypes.getClass("dart:core", "NoSuchMethodError").constructors.first; | 777 coreTypes.getClass("dart:core", "NoSuchMethodError").constructors.first; |
777 return new Throw(new ConstructorInvocation( | 778 return new Throw(new ConstructorInvocation( |
778 constructor, | 779 constructor, |
779 new Arguments(<Expression>[ | 780 new Arguments(<Expression>[ |
780 new NullLiteral(), | 781 astFactory.nullLiteral(null), |
781 new SymbolLiteral(name), | 782 new SymbolLiteral(name), |
782 new ListLiteral(arguments.positional), | 783 new ListLiteral(arguments.positional), |
783 new MapLiteral(arguments.named.map((arg) { | 784 new MapLiteral(arguments.named.map((arg) { |
784 return new MapEntry(new SymbolLiteral(arg.name), arg.value); | 785 return new MapEntry(new SymbolLiteral(arg.name), arg.value); |
785 }).toList()), | 786 }).toList()), |
786 new NullLiteral() | 787 astFactory.nullLiteral(null) |
787 ]))); | 788 ]))); |
788 } | 789 } |
789 | 790 |
790 @override | 791 @override |
791 Member lookupSuperMember(Name name, {bool isSetter: false}) { | 792 Member lookupSuperMember(Name name, {bool isSetter: false}) { |
792 Class superclass = classBuilder.cls.superclass; | 793 Class superclass = classBuilder.cls.superclass; |
793 return superclass == null | 794 return superclass == null |
794 ? null | 795 ? null |
795 : hierarchy.getDispatchTarget(superclass, name, setter: isSetter); | 796 : hierarchy.getDispatchTarget(superclass, name, setter: isSetter); |
796 } | 797 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 assert(builder == null); | 859 assert(builder == null); |
859 if (constantExpressionRequired) { | 860 if (constantExpressionRequired) { |
860 return new UnresolvedAccessor(this, n, token); | 861 return new UnresolvedAccessor(this, n, token); |
861 } | 862 } |
862 return new ThisPropertyAccessor(this, token, n, null, null); | 863 return new ThisPropertyAccessor(this, token, n, null, null); |
863 } else if (isDartLibrary && | 864 } else if (isDartLibrary && |
864 name == "main" && | 865 name == "main" && |
865 library.uri.path == "_builtin" && | 866 library.uri.path == "_builtin" && |
866 member?.name == "_getMainClosure") { | 867 member?.name == "_getMainClosure") { |
867 // TODO(ahe): https://github.com/dart-lang/sdk/issues/28989 | 868 // TODO(ahe): https://github.com/dart-lang/sdk/issues/28989 |
868 return new NullLiteral()..fileOffset = offsetForToken(token); | 869 return astFactory.nullLiteral(token); |
869 } else { | 870 } else { |
870 return new UnresolvedAccessor(this, n, token); | 871 return new UnresolvedAccessor(this, n, token); |
871 } | 872 } |
872 } else if (builder.isTypeDeclaration) { | 873 } else if (builder.isTypeDeclaration) { |
873 if (constantExpressionRequired && | 874 if (constantExpressionRequired && |
874 builder.isTypeVariable && | 875 builder.isTypeVariable && |
875 !member.isConstructor) { | 876 !member.isConstructor) { |
876 addCompileTimeError( | 877 addCompileTimeError( |
877 offsetForToken(token), "Not a constant expression."); | 878 offsetForToken(token), "Not a constant expression."); |
878 } | 879 } |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1111 push(popForValue()); | 1112 push(popForValue()); |
1112 } | 1113 } |
1113 | 1114 |
1114 @override | 1115 @override |
1115 void handleNoFieldInitializer(Token token) { | 1116 void handleNoFieldInitializer(Token token) { |
1116 debugEvent("NoFieldInitializer"); | 1117 debugEvent("NoFieldInitializer"); |
1117 if (constantExpressionRequired) { | 1118 if (constantExpressionRequired) { |
1118 addCompileTimeError( | 1119 addCompileTimeError( |
1119 token.charOffset, "const field must have initializer."); | 1120 token.charOffset, "const field must have initializer."); |
1120 // Creating a null value to prevent the Dart VM from crashing. | 1121 // Creating a null value to prevent the Dart VM from crashing. |
1121 push(new NullLiteral()..fileOffset = token.charOffset); | 1122 push(astFactory.nullLiteral(token)); |
1122 } else { | 1123 } else { |
1123 push(NullValue.FieldInitializer); | 1124 push(NullValue.FieldInitializer); |
1124 } | 1125 } |
1125 } | 1126 } |
1126 | 1127 |
1127 @override | 1128 @override |
1128 void endInitializedIdentifier(Token nameToken) { | 1129 void endInitializedIdentifier(Token nameToken) { |
1129 // TODO(ahe): Use [InitializedIdentifier] here? | 1130 // TODO(ahe): Use [InitializedIdentifier] here? |
1130 debugEvent("InitializedIdentifier"); | 1131 debugEvent("InitializedIdentifier"); |
1131 VariableDeclaration variable = pop(); | 1132 VariableDeclaration variable = pop(); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1301 | 1302 |
1302 @override | 1303 @override |
1303 void handleLiteralDouble(Token token) { | 1304 void handleLiteralDouble(Token token) { |
1304 debugEvent("LiteralDouble"); | 1305 debugEvent("LiteralDouble"); |
1305 push(astFactory.doubleLiteral(double.parse(token.lexeme), token)); | 1306 push(astFactory.doubleLiteral(double.parse(token.lexeme), token)); |
1306 } | 1307 } |
1307 | 1308 |
1308 @override | 1309 @override |
1309 void handleLiteralNull(Token token) { | 1310 void handleLiteralNull(Token token) { |
1310 debugEvent("LiteralNull"); | 1311 debugEvent("LiteralNull"); |
1311 push(new NullLiteral()..fileOffset = token.charOffset); | 1312 push(astFactory.nullLiteral(token)); |
1312 } | 1313 } |
1313 | 1314 |
1314 @override | 1315 @override |
1315 void handleLiteralMap( | 1316 void handleLiteralMap( |
1316 int count, Token beginToken, Token constKeyword, Token endToken) { | 1317 int count, Token beginToken, Token constKeyword, Token endToken) { |
1317 debugEvent("LiteralMap"); | 1318 debugEvent("LiteralMap"); |
1318 List<MapEntry> entries = popList(count) ?? <MapEntry>[]; | 1319 List<MapEntry> entries = popList(count) ?? <MapEntry>[]; |
1319 List<DartType> typeArguments = pop(); | 1320 List<DartType> typeArguments = pop(); |
1320 DartType keyType = const DynamicType(); | 1321 DartType keyType = const DynamicType(); |
1321 DartType valueType = const DynamicType(); | 1322 DartType valueType = const DynamicType(); |
(...skipping 1804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3126 } else if (node is PrefixBuilder) { | 3127 } else if (node is PrefixBuilder) { |
3127 return node.name; | 3128 return node.name; |
3128 } else if (node is ThisAccessor) { | 3129 } else if (node is ThisAccessor) { |
3129 return node.isSuper ? "super" : "this"; | 3130 return node.isSuper ? "super" : "this"; |
3130 } else if (node is FastaAccessor) { | 3131 } else if (node is FastaAccessor) { |
3131 return node.plainNameForRead; | 3132 return node.plainNameForRead; |
3132 } else { | 3133 } else { |
3133 return internalError("Unhandled: ${node.runtimeType}"); | 3134 return internalError("Unhandled: ${node.runtimeType}"); |
3134 } | 3135 } |
3135 } | 3136 } |
OLD | NEW |