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, |
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 if (builder != null && member.isField && builder.isInstanceMember) { | 1004 if (builder != null && member.isField && builder.isInstanceMember) { |
1005 return new IncompleteError(this, token, | 1005 return new IncompleteError(this, token, |
1006 "Can't access 'this' in a field initializer to read '$name'."); | 1006 "Can't access 'this' in a field initializer to read '$name'."); |
1007 } | 1007 } |
1008 if (builder == null || (!isInstanceContext && builder.isInstanceMember)) { | 1008 if (builder == null || (!isInstanceContext && builder.isInstanceMember)) { |
1009 Name n = new Name(name, library.library); | 1009 Name n = new Name(name, library.library); |
1010 if (prefix != null && | 1010 if (prefix != null && |
1011 prefix.deferred && | 1011 prefix.deferred && |
1012 builder == null && | 1012 builder == null && |
1013 "loadLibrary" == name) { | 1013 "loadLibrary" == name) { |
1014 return buildCompileTimeError( | 1014 int offset = offsetForToken(token); |
1015 "Deferred loading isn't implemented yet.", offsetForToken(token)); | 1015 const String message = "Deferred loading isn't implemented yet."; |
| 1016 // We report the error twice, the first time silently and marking it as |
| 1017 // unhandled. This ensures that the compile-time error is reported |
| 1018 // eagerly by kernel-service, thus preventing any attempts from running |
| 1019 // a program that uses deferred loading. Obviously, this is a temporary |
| 1020 // solution until we can fully implement deferred loading. |
| 1021 addCompileTimeError(offset, message, wasHandled: false, silent: true); |
| 1022 return buildCompileTimeError(message, offset); |
1016 } else if (!isQualified && isInstanceContext) { | 1023 } else if (!isQualified && isInstanceContext) { |
1017 assert(builder == null); | 1024 assert(builder == null); |
1018 if (constantExpressionRequired || member.isField) { | 1025 if (constantExpressionRequired || member.isField) { |
1019 return new UnresolvedAccessor(this, n, token); | 1026 return new UnresolvedAccessor(this, n, token); |
1020 } | 1027 } |
1021 return new ThisPropertyAccessor(this, token, n, null, null); | 1028 return new ThisPropertyAccessor(this, token, n, null, null); |
1022 } else if (isBuiltinLibrary && | 1029 } else if (isBuiltinLibrary && |
1023 name == "main" && | 1030 name == "main" && |
1024 member?.name == "_getMainClosure") { | 1031 member?.name == "_getMainClosure") { |
1025 // TODO(ahe): https://github.com/dart-lang/sdk/issues/28989 | 1032 // TODO(ahe): https://github.com/dart-lang/sdk/issues/28989 |
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2029 name = ""; | 2036 name = ""; |
2030 } | 2037 } |
2031 push(type); | 2038 push(type); |
2032 push(typeArguments ?? NullValue.TypeArguments); | 2039 push(typeArguments ?? NullValue.TypeArguments); |
2033 push(name); | 2040 push(name); |
2034 } | 2041 } |
2035 | 2042 |
2036 @override | 2043 @override |
2037 Expression buildStaticInvocation(Member target, Arguments arguments, | 2044 Expression buildStaticInvocation(Member target, Arguments arguments, |
2038 {bool isConst: false, int charOffset: -1, Member initialTarget}) { | 2045 {bool isConst: false, int charOffset: -1, Member initialTarget}) { |
| 2046 initialTarget ??= target; |
2039 List<TypeParameter> typeParameters = target.function.typeParameters; | 2047 List<TypeParameter> typeParameters = target.function.typeParameters; |
2040 if (target is Constructor) { | 2048 if (target is Constructor) { |
2041 assert(!target.enclosingClass.isAbstract); | 2049 assert(!target.enclosingClass.isAbstract); |
2042 typeParameters = target.enclosingClass.typeParameters; | 2050 typeParameters = target.enclosingClass.typeParameters; |
2043 } | 2051 } |
2044 if (!checkArguments(target.function, arguments, typeParameters)) { | 2052 if (!checkArguments(target.function, arguments, typeParameters)) { |
2045 return throwNoSuchMethodError(new NullLiteral()..fileOffset = charOffset, | 2053 return throwNoSuchMethodError(new NullLiteral()..fileOffset = charOffset, |
2046 target.name.name, arguments, charOffset); | 2054 target.name.name, arguments, charOffset); |
2047 } | 2055 } |
2048 if (target is Constructor) { | 2056 if (target is Constructor) { |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2346 function.returnType = returnType; | 2354 function.returnType = returnType; |
2347 declaration.variable.type = function.functionType; | 2355 declaration.variable.type = function.functionType; |
2348 declaration.function = function; | 2356 declaration.function = function; |
2349 function.parent = declaration; | 2357 function.parent = declaration; |
2350 } else { | 2358 } else { |
2351 // If [declaration] isn't a [FunctionDeclaration], it must be because | 2359 // If [declaration] isn't a [FunctionDeclaration], it must be because |
2352 // there was a compile-time error. | 2360 // there was a compile-time error. |
2353 | 2361 |
2354 // TODO(paulberry): ensure that when integrating with analyzer, type | 2362 // TODO(paulberry): ensure that when integrating with analyzer, type |
2355 // inference is still performed for the dropped declaration. | 2363 // inference is still performed for the dropped declaration. |
2356 assert(library.compileTimeErrors.isNotEmpty); | 2364 assert(library.hasCompileTimeErrors); |
2357 } | 2365 } |
2358 push(declaration); | 2366 push(declaration); |
2359 } | 2367 } |
2360 | 2368 |
2361 @override | 2369 @override |
2362 void endUnnamedFunction(Token beginToken, Token token) { | 2370 void endUnnamedFunction(Token beginToken, Token token) { |
2363 debugEvent("UnnamedFunction"); | 2371 debugEvent("UnnamedFunction"); |
2364 Statement body = popStatement(); | 2372 Statement body = popStatement(); |
2365 AsyncMarker asyncModifier = pop(); | 2373 AsyncMarker asyncModifier = pop(); |
2366 exitLocalScope(); | 2374 exitLocalScope(); |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2880 } | 2888 } |
2881 return super.handleUnrecoverableError(token, message); | 2889 return super.handleUnrecoverableError(token, message); |
2882 } | 2890 } |
2883 | 2891 |
2884 @override | 2892 @override |
2885 Expression buildCompileTimeError(error, [int charOffset = -1]) { | 2893 Expression buildCompileTimeError(error, [int charOffset = -1]) { |
2886 // TODO(ahe): This method should be passed the erroneous expression, wrap | 2894 // TODO(ahe): This method should be passed the erroneous expression, wrap |
2887 // it in a class (TBD) from which the erroneous expression can be easily | 2895 // it in a class (TBD) from which the erroneous expression can be easily |
2888 // extracted. Similar for statements and initializers. See also [issue | 2896 // extracted. Similar for statements and initializers. See also [issue |
2889 // 29717](https://github.com/dart-lang/sdk/issues/29717) | 2897 // 29717](https://github.com/dart-lang/sdk/issues/29717) |
2890 addCompileTimeError(charOffset, error); | 2898 addCompileTimeError(charOffset, error, wasHandled: true); |
2891 return library.loader.throwCompileConstantError(library.loader | 2899 return library.loader.throwCompileConstantError(library.loader |
2892 .buildCompileTimeError( | 2900 .buildCompileTimeError( |
2893 formatUnexpected(uri, charOffset, error), charOffset)); | 2901 formatUnexpected(uri, charOffset, error), charOffset)); |
2894 } | 2902 } |
2895 | 2903 |
2896 Expression wrapInCompileTimeError(Expression expression, String message) { | 2904 Expression wrapInCompileTimeError(Expression expression, String message) { |
2897 return new Let( | 2905 return new Let( |
2898 new VariableDeclaration.forValue(expression) | 2906 new VariableDeclaration.forValue(expression) |
2899 ..fileOffset = expression.fileOffset, | 2907 ..fileOffset = expression.fileOffset, |
2900 buildCompileTimeError(message, expression.fileOffset)) | 2908 buildCompileTimeError(message, expression.fileOffset)) |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3014 } | 3022 } |
3015 | 3023 |
3016 @override | 3024 @override |
3017 void handleSymbolVoid(Token token) { | 3025 void handleSymbolVoid(Token token) { |
3018 debugEvent("SymbolVoid"); | 3026 debugEvent("SymbolVoid"); |
3019 push(new Identifier(token)); | 3027 push(new Identifier(token)); |
3020 } | 3028 } |
3021 | 3029 |
3022 @override | 3030 @override |
3023 dynamic addCompileTimeError(int charOffset, String message, | 3031 dynamic addCompileTimeError(int charOffset, String message, |
3024 {bool silent: false}) { | 3032 {bool silent: false, bool wasHandled: false}) { |
3025 // TODO(ahe): If constantExpressionRequired is set, set it to false to | 3033 // TODO(ahe): If constantExpressionRequired is set, set it to false to |
3026 // avoid a long list of errors. | 3034 // avoid a long list of errors. |
3027 return library.addCompileTimeError(charOffset, message, | 3035 return library.addCompileTimeError(charOffset, message, |
3028 fileUri: uri, silent: silent); | 3036 fileUri: uri, silent: silent, wasHandled: wasHandled); |
3029 } | 3037 } |
3030 | 3038 |
3031 @override | 3039 @override |
3032 void handleInvalidFunctionBody(Token token) { | 3040 void handleInvalidFunctionBody(Token token) { |
3033 if (member.isNative) { | 3041 if (member.isNative) { |
3034 push(NullValue.FunctionBody); | 3042 push(NullValue.FunctionBody); |
3035 } else { | 3043 } else { |
3036 push(new Block(<Statement>[ | 3044 push(new Block(<Statement>[ |
3037 buildCompileTimeErrorStatement("Expected '{'.", token.charOffset) | 3045 buildCompileTimeErrorStatement("Expected '{'.", token.charOffset) |
3038 ])); | 3046 ])); |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3577 if (starToken == null) { | 3585 if (starToken == null) { |
3578 return AsyncMarker.Async; | 3586 return AsyncMarker.Async; |
3579 } else { | 3587 } else { |
3580 assert(identical(starToken.stringValue, "*")); | 3588 assert(identical(starToken.stringValue, "*")); |
3581 return AsyncMarker.AsyncStar; | 3589 return AsyncMarker.AsyncStar; |
3582 } | 3590 } |
3583 } else { | 3591 } else { |
3584 return internalError("Unknown async modifier: $asyncToken"); | 3592 return internalError("Unknown async modifier: $asyncToken"); |
3585 } | 3593 } |
3586 } | 3594 } |
OLD | NEW |