| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 78 |
| 79 final CoreTypes coreTypes; | 79 final CoreTypes coreTypes; |
| 80 | 80 |
| 81 final bool isInstanceMember; | 81 final bool isInstanceMember; |
| 82 | 82 |
| 83 final Map<String, FieldInitializer> fieldInitializers = | 83 final Map<String, FieldInitializer> fieldInitializers = |
| 84 <String, FieldInitializer>{}; | 84 <String, FieldInitializer>{}; |
| 85 | 85 |
| 86 final Scope enclosingScope; | 86 final Scope enclosingScope; |
| 87 | 87 |
| 88 final bool isDartLibrary; | 88 final bool enableNative; |
| 89 | 89 |
| 90 @override | 90 @override |
| 91 final Uri uri; | 91 final Uri uri; |
| 92 | 92 |
| 93 final TypeInferrer _typeInferrer; | 93 final TypeInferrer _typeInferrer; |
| 94 | 94 |
| 95 @override | 95 @override |
| 96 final TypePromoter<Expression, VariableDeclaration> typePromoter; | 96 final TypePromoter<Expression, VariableDeclaration> typePromoter; |
| 97 | 97 |
| 98 /// If not `null`, dependencies on fields are accumulated into this list. | 98 /// If not `null`, dependencies on fields are accumulated into this list. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 this.formalParameterScope, | 145 this.formalParameterScope, |
| 146 this.hierarchy, | 146 this.hierarchy, |
| 147 this.coreTypes, | 147 this.coreTypes, |
| 148 this.classBuilder, | 148 this.classBuilder, |
| 149 this.isInstanceMember, | 149 this.isInstanceMember, |
| 150 this.uri, | 150 this.uri, |
| 151 this._typeInferrer, | 151 this._typeInferrer, |
| 152 {this.fieldDependencies}) | 152 {this.fieldDependencies}) |
| 153 : enclosingScope = scope, | 153 : enclosingScope = scope, |
| 154 library = library, | 154 library = library, |
| 155 isDartLibrary = library.uri.scheme == "dart", | 155 enableNative = (library.uri.scheme == "dart" || library.isPatch), |
| 156 needsImplicitSuperInitializer = | 156 needsImplicitSuperInitializer = |
| 157 coreTypes.objectClass != classBuilder?.cls, | 157 coreTypes.objectClass != classBuilder?.cls, |
| 158 typePromoter = _typeInferrer.typePromoter, | 158 typePromoter = _typeInferrer.typePromoter, |
| 159 super(scope); | 159 super(scope); |
| 160 | 160 |
| 161 bool get hasParserError => recoverableErrors.isNotEmpty; | 161 bool get hasParserError => recoverableErrors.isNotEmpty; |
| 162 | 162 |
| 163 bool get inConstructor { | 163 bool get inConstructor { |
| 164 return functionNestingLevel == 0 && member is KernelConstructorBuilder; | 164 return functionNestingLevel == 0 && member is KernelConstructorBuilder; |
| 165 } | 165 } |
| (...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 builder == null && | 868 builder == null && |
| 869 "loadLibrary" == name) { | 869 "loadLibrary" == name) { |
| 870 return buildCompileTimeError( | 870 return buildCompileTimeError( |
| 871 "Deferred loading isn't implemented yet.", offsetForToken(token)); | 871 "Deferred loading isn't implemented yet.", offsetForToken(token)); |
| 872 } else if (!isQualified && isInstanceContext) { | 872 } else if (!isQualified && isInstanceContext) { |
| 873 assert(builder == null); | 873 assert(builder == null); |
| 874 if (constantExpressionRequired) { | 874 if (constantExpressionRequired) { |
| 875 return new UnresolvedAccessor(this, n, token); | 875 return new UnresolvedAccessor(this, n, token); |
| 876 } | 876 } |
| 877 return new ThisPropertyAccessor(this, token, n, null, null); | 877 return new ThisPropertyAccessor(this, token, n, null, null); |
| 878 } else if (isDartLibrary && | 878 } else if ( |
| 879 name == "main" && | 879 // Optimization, if [enableNative] is false, this can't be |
| 880 library.uri.path == "_builtin" && | 880 // dart:_builtin. |
| 881 member?.name == "_getMainClosure") { | 881 enableNative && |
| 882 name == "main" && |
| 883 library.uri.scheme == "dart" && |
| 884 library.uri.path == "_builtin" && |
| 885 member?.name == "_getMainClosure") { |
| 882 // TODO(ahe): https://github.com/dart-lang/sdk/issues/28989 | 886 // TODO(ahe): https://github.com/dart-lang/sdk/issues/28989 |
| 883 return new KernelNullLiteral()..fileOffset = offsetForToken(token); | 887 return new KernelNullLiteral()..fileOffset = offsetForToken(token); |
| 884 } else { | 888 } else { |
| 885 return new UnresolvedAccessor(this, n, token); | 889 return new UnresolvedAccessor(this, n, token); |
| 886 } | 890 } |
| 887 } else if (builder.isTypeDeclaration) { | 891 } else if (builder.isTypeDeclaration) { |
| 888 if (constantExpressionRequired && | 892 if (constantExpressionRequired && |
| 889 builder.isTypeVariable && | 893 builder.isTypeVariable && |
| 890 !member.isConstructor) { | 894 !member.isConstructor) { |
| 891 addCompileTimeError( | 895 addCompileTimeError( |
| (...skipping 1668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2560 } | 2564 } |
| 2561 | 2565 |
| 2562 @override | 2566 @override |
| 2563 void handleRecoverableError(Token token, FastaMessage message) { | 2567 void handleRecoverableError(Token token, FastaMessage message) { |
| 2564 bool silent = hasParserError; | 2568 bool silent = hasParserError; |
| 2565 addCompileTimeError(message.charOffset, message.message, silent: silent); | 2569 addCompileTimeError(message.charOffset, message.message, silent: silent); |
| 2566 } | 2570 } |
| 2567 | 2571 |
| 2568 @override | 2572 @override |
| 2569 Token handleUnrecoverableError(Token token, FastaMessage message) { | 2573 Token handleUnrecoverableError(Token token, FastaMessage message) { |
| 2570 if (isDartLibrary && message.code == codeExpectedFunctionBody) { | 2574 if (enableNative && message.code == codeExpectedFunctionBody) { |
| 2571 Token recover = library.loader.target.skipNativeClause(token); | 2575 Token recover = library.loader.target.skipNativeClause(token); |
| 2572 if (recover != null) return recover; | 2576 if (recover != null) return recover; |
| 2573 } else if (message.code == codeExpectedButGot) { | 2577 } else if (message.code == codeExpectedButGot) { |
| 2574 String expected = message.arguments["string"]; | 2578 String expected = message.arguments["string"]; |
| 2575 const List<String> trailing = const <String>[")", "}", ";", ","]; | 2579 const List<String> trailing = const <String>[")", "}", ";", ","]; |
| 2576 if (trailing.contains(token.stringValue) && trailing.contains(expected)) { | 2580 if (trailing.contains(token.stringValue) && trailing.contains(expected)) { |
| 2577 handleRecoverableError(token, message); | 2581 handleRecoverableError(token, message); |
| 2578 return newSyntheticToken(token); | 2582 return newSyntheticToken(token); |
| 2579 } | 2583 } |
| 2580 } | 2584 } |
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3198 if (starToken == null) { | 3202 if (starToken == null) { |
| 3199 return AsyncMarker.Async; | 3203 return AsyncMarker.Async; |
| 3200 } else { | 3204 } else { |
| 3201 assert(identical(starToken.stringValue, "*")); | 3205 assert(identical(starToken.stringValue, "*")); |
| 3202 return AsyncMarker.AsyncStar; | 3206 return AsyncMarker.AsyncStar; |
| 3203 } | 3207 } |
| 3204 } else { | 3208 } else { |
| 3205 return internalError("Unknown async modifier: $asyncToken"); | 3209 return internalError("Unknown async modifier: $asyncToken"); |
| 3206 } | 3210 } |
| 3207 } | 3211 } |
| OLD | NEW |