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 | 8 show |
9 FastaMessage, | 9 FastaMessage, |
10 codeConstFieldWithoutInitializer, | 10 codeConstFieldWithoutInitializer, |
11 codeExpectedButGot, | 11 codeExpectedButGot, |
12 codeExpectedFunctionBody, | 12 codeExpectedFunctionBody, |
13 codeFinalFieldWithoutInitializer; | 13 codeFinalFieldWithoutInitializer; |
14 | 14 |
15 import '../parser/parser.dart' | 15 import '../parser/parser.dart' |
16 show Assert, FormalParameterType, MemberKind, optional; | 16 show Assert, FormalParameterType, MemberKind, optional; |
17 | 17 |
18 import '../parser/identifier_context.dart' show IdentifierContext; | 18 import '../parser/identifier_context.dart' show IdentifierContext; |
19 | 19 |
| 20 import '../parser/native_support.dart' show skipNativeClause; |
| 21 |
20 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart'; | 22 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart'; |
21 | 23 |
22 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken; | 24 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken; |
23 | 25 |
24 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart' | 26 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart' |
25 show TypeInferrer; | 27 show TypeInferrer; |
26 | 28 |
27 import 'package:front_end/src/fasta/type_inference/type_promotion.dart' | 29 import 'package:front_end/src/fasta/type_inference/type_promotion.dart' |
28 show TypePromoter; | 30 show TypePromoter; |
29 | 31 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 88 |
87 final ClassHierarchy hierarchy; | 89 final ClassHierarchy hierarchy; |
88 | 90 |
89 final CoreTypes coreTypes; | 91 final CoreTypes coreTypes; |
90 | 92 |
91 final bool isInstanceMember; | 93 final bool isInstanceMember; |
92 | 94 |
93 final Scope enclosingScope; | 95 final Scope enclosingScope; |
94 | 96 |
95 final bool enableNative; | 97 final bool enableNative; |
| 98 final bool stringExpectedAfterNative; |
96 | 99 |
97 /// Whether to ignore an unresolved reference to `main` within the body of | 100 /// Whether to ignore an unresolved reference to `main` within the body of |
98 /// `_getMainClosure` when compiling the current library. | 101 /// `_getMainClosure` when compiling the current library. |
99 /// | 102 /// |
100 /// This as a temporary workaround. The standalone VM and flutter have | 103 /// This as a temporary workaround. The standalone VM and flutter have |
101 /// special logic to resolve `main` in `_getMainClosure`, this flag is used to | 104 /// special logic to resolve `main` in `_getMainClosure`, this flag is used to |
102 /// ignore that reference to `main`, but only on libraries where we expect to | 105 /// ignore that reference to `main`, but only on libraries where we expect to |
103 /// see it (today that is dart:_builtin and dart:ui). | 106 /// see it (today that is dart:_builtin and dart:ui). |
104 /// | 107 /// |
105 // TODO(ahe,sigmund): remove when the VM gets rid of the special rule, see | 108 // TODO(ahe,sigmund): remove when the VM gets rid of the special rule, see |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 Scope scope, | 176 Scope scope, |
174 this.formalParameterScope, | 177 this.formalParameterScope, |
175 this.hierarchy, | 178 this.hierarchy, |
176 this.coreTypes, | 179 this.coreTypes, |
177 this.classBuilder, | 180 this.classBuilder, |
178 this.isInstanceMember, | 181 this.isInstanceMember, |
179 this.uri, | 182 this.uri, |
180 this._typeInferrer) | 183 this._typeInferrer) |
181 : enclosingScope = scope, | 184 : enclosingScope = scope, |
182 library = library, | 185 library = library, |
183 enableNative = library.loader.target.enableNative(library), | 186 enableNative = |
| 187 library.loader.target.backendTarget.enableNative(library.uri), |
| 188 stringExpectedAfterNative = |
| 189 library.loader.target.backendTarget.nativeExtensionExpectsString, |
184 ignoreMainInGetMainClosure = library.uri.scheme == 'dart' && | 190 ignoreMainInGetMainClosure = library.uri.scheme == 'dart' && |
185 (library.uri.path == "_builtin" || library.uri.path == "ui"), | 191 (library.uri.path == "_builtin" || library.uri.path == "ui"), |
186 needsImplicitSuperInitializer = | 192 needsImplicitSuperInitializer = |
187 coreTypes.objectClass != classBuilder?.cls, | 193 coreTypes.objectClass != classBuilder?.cls, |
188 typePromoter = _typeInferrer.typePromoter, | 194 typePromoter = _typeInferrer.typePromoter, |
189 super(scope); | 195 super(scope); |
190 | 196 |
191 bool get hasParserError => recoverableErrors.isNotEmpty; | 197 bool get hasParserError => recoverableErrors.isNotEmpty; |
192 | 198 |
193 bool get inConstructor { | 199 bool get inConstructor { |
(...skipping 2773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2967 void handleRecoverableError(Token token, FastaMessage message) { | 2973 void handleRecoverableError(Token token, FastaMessage message) { |
2968 bool silent = hasParserError || | 2974 bool silent = hasParserError || |
2969 message.code == codeFinalFieldWithoutInitializer || | 2975 message.code == codeFinalFieldWithoutInitializer || |
2970 message.code == codeConstFieldWithoutInitializer; | 2976 message.code == codeConstFieldWithoutInitializer; |
2971 addCompileTimeError(message.charOffset, message.message, silent: silent); | 2977 addCompileTimeError(message.charOffset, message.message, silent: silent); |
2972 } | 2978 } |
2973 | 2979 |
2974 @override | 2980 @override |
2975 Token handleUnrecoverableError(Token token, FastaMessage message) { | 2981 Token handleUnrecoverableError(Token token, FastaMessage message) { |
2976 if (enableNative && message.code == codeExpectedFunctionBody) { | 2982 if (enableNative && message.code == codeExpectedFunctionBody) { |
2977 Token recover = library.loader.target.skipNativeClause(token); | 2983 Token recover = skipNativeClause(token, stringExpectedAfterNative); |
2978 if (recover != null) return recover; | 2984 if (recover != null) return recover; |
2979 } else if (message.code == codeExpectedButGot) { | 2985 } else if (message.code == codeExpectedButGot) { |
2980 String expected = message.arguments["string"]; | 2986 String expected = message.arguments["string"]; |
2981 const List<String> trailing = const <String>[")", "}", ";", ","]; | 2987 const List<String> trailing = const <String>[")", "}", ";", ","]; |
2982 if (trailing.contains(token.stringValue) && trailing.contains(expected)) { | 2988 if (trailing.contains(token.stringValue) && trailing.contains(expected)) { |
2983 handleRecoverableError(token, message); | 2989 handleRecoverableError(token, message); |
2984 return newSyntheticToken(token); | 2990 return newSyntheticToken(token); |
2985 } | 2991 } |
2986 } | 2992 } |
2987 return super.handleUnrecoverableError(token, message); | 2993 return super.handleUnrecoverableError(token, message); |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3692 if (starToken == null) { | 3698 if (starToken == null) { |
3693 return AsyncMarker.Async; | 3699 return AsyncMarker.Async; |
3694 } else { | 3700 } else { |
3695 assert(identical(starToken.stringValue, "*")); | 3701 assert(identical(starToken.stringValue, "*")); |
3696 return AsyncMarker.AsyncStar; | 3702 return AsyncMarker.AsyncStar; |
3697 } | 3703 } |
3698 } else { | 3704 } else { |
3699 return internalError("Unknown async modifier: $asyncToken"); | 3705 return internalError("Unknown async modifier: $asyncToken"); |
3700 } | 3706 } |
3701 } | 3707 } |
OLD | NEW |