| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 final CoreTypes coreTypes; | 87 final CoreTypes coreTypes; |
| 88 | 88 |
| 89 final bool isInstanceMember; | 89 final bool isInstanceMember; |
| 90 | 90 |
| 91 final Map<String, FieldInitializer> fieldInitializers = | 91 final Map<String, FieldInitializer> fieldInitializers = |
| 92 <String, FieldInitializer>{}; | 92 <String, FieldInitializer>{}; |
| 93 | 93 |
| 94 final Scope enclosingScope; | 94 final Scope enclosingScope; |
| 95 | 95 |
| 96 final bool isDartLibrary; | 96 final bool enableNative; |
| 97 | 97 |
| 98 @override | 98 @override |
| 99 final Uri uri; | 99 final Uri uri; |
| 100 | 100 |
| 101 final TypeInferrer _typeInferrer; | 101 final TypeInferrer _typeInferrer; |
| 102 | 102 |
| 103 @override | 103 @override |
| 104 final AstFactory astFactory; | 104 final AstFactory astFactory; |
| 105 | 105 |
| 106 @override | 106 @override |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 this.hierarchy, | 157 this.hierarchy, |
| 158 this.coreTypes, | 158 this.coreTypes, |
| 159 this.classBuilder, | 159 this.classBuilder, |
| 160 this.isInstanceMember, | 160 this.isInstanceMember, |
| 161 this.uri, | 161 this.uri, |
| 162 this._typeInferrer, | 162 this._typeInferrer, |
| 163 this.astFactory, | 163 this.astFactory, |
| 164 {this.fieldDependencies}) | 164 {this.fieldDependencies}) |
| 165 : enclosingScope = scope, | 165 : enclosingScope = scope, |
| 166 library = library, | 166 library = library, |
| 167 isDartLibrary = library.uri.scheme == "dart", | 167 enableNative = (library.uri.scheme == "dart" || library.isPatch), |
| 168 needsImplicitSuperInitializer = | 168 needsImplicitSuperInitializer = |
| 169 coreTypes.objectClass != classBuilder?.cls, | 169 coreTypes.objectClass != classBuilder?.cls, |
| 170 typePromoter = _typeInferrer.typePromoter, | 170 typePromoter = _typeInferrer.typePromoter, |
| 171 super(scope); | 171 super(scope); |
| 172 | 172 |
| 173 bool get hasParserError => recoverableErrors.isNotEmpty; | 173 bool get hasParserError => recoverableErrors.isNotEmpty; |
| 174 | 174 |
| 175 bool get inConstructor { | 175 bool get inConstructor { |
| 176 return functionNestingLevel == 0 && member is KernelConstructorBuilder; | 176 return functionNestingLevel == 0 && member is KernelConstructorBuilder; |
| 177 } | 177 } |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 builder == null && | 881 builder == null && |
| 882 "loadLibrary" == name) { | 882 "loadLibrary" == name) { |
| 883 return buildCompileTimeError( | 883 return buildCompileTimeError( |
| 884 "Deferred loading isn't implemented yet.", offsetForToken(token)); | 884 "Deferred loading isn't implemented yet.", offsetForToken(token)); |
| 885 } else if (!isQualified && isInstanceContext) { | 885 } else if (!isQualified && isInstanceContext) { |
| 886 assert(builder == null); | 886 assert(builder == null); |
| 887 if (constantExpressionRequired) { | 887 if (constantExpressionRequired) { |
| 888 return new UnresolvedAccessor(this, n, token); | 888 return new UnresolvedAccessor(this, n, token); |
| 889 } | 889 } |
| 890 return new ThisPropertyAccessor(this, token, n, null, null); | 890 return new ThisPropertyAccessor(this, token, n, null, null); |
| 891 } else if (isDartLibrary && | 891 } else if ( |
| 892 name == "main" && | 892 // Optimization, if [enableNative] is false, this can't be |
| 893 library.uri.path == "_builtin" && | 893 // dart:_builtin. |
| 894 member?.name == "_getMainClosure") { | 894 enableNative && |
| 895 name == "main" && |
| 896 library.uri.scheme == "dart" && |
| 897 library.uri.path == "_builtin" && |
| 898 member?.name == "_getMainClosure") { |
| 895 // TODO(ahe): https://github.com/dart-lang/sdk/issues/28989 | 899 // TODO(ahe): https://github.com/dart-lang/sdk/issues/28989 |
| 896 return astFactory.nullLiteral(token); | 900 return astFactory.nullLiteral(token); |
| 897 } else { | 901 } else { |
| 898 return new UnresolvedAccessor(this, n, token); | 902 return new UnresolvedAccessor(this, n, token); |
| 899 } | 903 } |
| 900 } else if (builder.isTypeDeclaration) { | 904 } else if (builder.isTypeDeclaration) { |
| 901 if (constantExpressionRequired && | 905 if (constantExpressionRequired && |
| 902 builder.isTypeVariable && | 906 builder.isTypeVariable && |
| 903 !member.isConstructor) { | 907 !member.isConstructor) { |
| 904 addCompileTimeError( | 908 addCompileTimeError( |
| (...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2550 } | 2554 } |
| 2551 | 2555 |
| 2552 @override | 2556 @override |
| 2553 void handleRecoverableError(Token token, FastaMessage message) { | 2557 void handleRecoverableError(Token token, FastaMessage message) { |
| 2554 bool silent = hasParserError; | 2558 bool silent = hasParserError; |
| 2555 addCompileTimeError(message.charOffset, message.message, silent: silent); | 2559 addCompileTimeError(message.charOffset, message.message, silent: silent); |
| 2556 } | 2560 } |
| 2557 | 2561 |
| 2558 @override | 2562 @override |
| 2559 Token handleUnrecoverableError(Token token, FastaMessage message) { | 2563 Token handleUnrecoverableError(Token token, FastaMessage message) { |
| 2560 if (isDartLibrary && message.code == codeExpectedFunctionBody) { | 2564 if (enableNative && message.code == codeExpectedFunctionBody) { |
| 2561 Token recover = library.loader.target.skipNativeClause(token); | 2565 Token recover = library.loader.target.skipNativeClause(token); |
| 2562 if (recover != null) return recover; | 2566 if (recover != null) return recover; |
| 2563 } else if (message.code == codeExpectedButGot) { | 2567 } else if (message.code == codeExpectedButGot) { |
| 2564 String expected = message.arguments["string"]; | 2568 String expected = message.arguments["string"]; |
| 2565 const List<String> trailing = const <String>[")", "}", ";", ","]; | 2569 const List<String> trailing = const <String>[")", "}", ";", ","]; |
| 2566 if (trailing.contains(token.stringValue) && trailing.contains(expected)) { | 2570 if (trailing.contains(token.stringValue) && trailing.contains(expected)) { |
| 2567 handleRecoverableError(token, message); | 2571 handleRecoverableError(token, message); |
| 2568 return newSyntheticToken(token); | 2572 return newSyntheticToken(token); |
| 2569 } | 2573 } |
| 2570 } | 2574 } |
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3188 if (starToken == null) { | 3192 if (starToken == null) { |
| 3189 return AsyncMarker.Async; | 3193 return AsyncMarker.Async; |
| 3190 } else { | 3194 } else { |
| 3191 assert(identical(starToken.stringValue, "*")); | 3195 assert(identical(starToken.stringValue, "*")); |
| 3192 return AsyncMarker.AsyncStar; | 3196 return AsyncMarker.AsyncStar; |
| 3193 } | 3197 } |
| 3194 } else { | 3198 } else { |
| 3195 return internalError("Unknown async modifier: $asyncToken"); | 3199 return internalError("Unknown async modifier: $asyncToken"); |
| 3196 } | 3200 } |
| 3197 } | 3201 } |
| OLD | NEW |