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 'package:kernel/ast.dart' | 7 import 'package:kernel/ast.dart' |
8 hide InvalidExpression, InvalidInitializer, InvalidStatement; | 8 hide InvalidExpression, InvalidInitializer, InvalidStatement; |
9 | 9 |
10 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; | 10 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; |
11 | 11 |
12 import 'package:kernel/clone.dart' show CloneVisitor; | 12 import 'package:kernel/clone.dart' show CloneVisitor; |
13 | 13 |
14 import 'package:kernel/core_types.dart' show CoreTypes; | 14 import 'package:kernel/core_types.dart' show CoreTypes; |
15 | 15 |
16 import 'package:kernel/transformations/flags.dart' show TransformerFlag; | 16 import 'package:kernel/transformations/flags.dart' show TransformerFlag; |
17 | 17 |
| 18 import 'package:kernel/type_algebra.dart' show Substitution; |
| 19 |
18 import '../fasta_codes.dart' as fasta; | 20 import '../fasta_codes.dart' as fasta; |
19 | 21 |
20 import '../fasta_codes.dart' show LocatedMessage, Message; | 22 import '../fasta_codes.dart' show LocatedMessage, Message; |
21 | 23 |
22 import '../messages.dart' as messages show getLocationFromUri; | 24 import '../messages.dart' as messages show getLocationFromUri; |
23 | 25 |
24 import '../modifier.dart' show Modifier, constMask, finalMask; | 26 import '../modifier.dart' show Modifier, constMask, finalMask; |
25 | 27 |
26 import '../parser/native_support.dart' show skipNativeClause; | 28 import '../parser/native_support.dart' show skipNativeClause; |
27 | 29 |
(...skipping 29 matching lines...) Expand all Loading... |
57 | 59 |
58 import '../source/scope_listener.dart' | 60 import '../source/scope_listener.dart' |
59 show JumpTargetKind, NullValue, ScopeListener; | 61 show JumpTargetKind, NullValue, ScopeListener; |
60 | 62 |
61 import '../type_inference/type_inferrer.dart' show TypeInferrer; | 63 import '../type_inference/type_inferrer.dart' show TypeInferrer; |
62 | 64 |
63 import '../type_inference/type_promotion.dart' show TypePromoter; | 65 import '../type_inference/type_promotion.dart' show TypePromoter; |
64 | 66 |
65 import 'frontend_accessors.dart' show buildIsNull, makeBinary; | 67 import 'frontend_accessors.dart' show buildIsNull, makeBinary; |
66 | 68 |
67 import 'redirecting_factory_body.dart' | 69 import 'redirecting_factory_body.dart' show RedirectingFactoryBody; |
68 show | |
69 RedirectingFactoryBody, | |
70 getRedirectingFactoryBody, | |
71 getRedirectionTarget; | |
72 | 70 |
73 import 'utils.dart' show offsetForToken; | 71 import 'utils.dart' show offsetForToken; |
74 | 72 |
75 import '../names.dart'; | 73 import '../names.dart'; |
76 | 74 |
77 import 'fasta_accessors.dart'; | 75 import 'fasta_accessors.dart'; |
78 | 76 |
79 import 'kernel_builder.dart'; | 77 import 'kernel_builder.dart'; |
80 | 78 |
81 import 'kernel_shadow_ast.dart'; | 79 import 'kernel_shadow_ast.dart'; |
(...skipping 2238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2320 push(new KernelSyntheticExpression(evaluateArgumentsBefore( | 2318 push(new KernelSyntheticExpression(evaluateArgumentsBefore( |
2321 arguments, | 2319 arguments, |
2322 buildAbstractClassInstantiationError( | 2320 buildAbstractClassInstantiationError( |
2323 type.name, nameToken.charOffset)))); | 2321 type.name, nameToken.charOffset)))); |
2324 return; | 2322 return; |
2325 } else { | 2323 } else { |
2326 target = initialTarget; | 2324 target = initialTarget; |
2327 } | 2325 } |
2328 } else if (b.isFactory) { | 2326 } else if (b.isFactory) { |
2329 initialTarget = b.target; | 2327 initialTarget = b.target; |
2330 target = getRedirectionTarget(initialTarget); | 2328 RedirectingFactoryBody body = |
2331 if (target == null) { | 2329 RedirectingFactoryBody.getRedirectingFactoryBody(initialTarget); |
2332 push(deprecated_buildCompileTimeError( | |
2333 "Cyclic definition of factory '${name}'.", | |
2334 nameToken.charOffset)); | |
2335 return; | |
2336 } | |
2337 RedirectingFactoryBody body = getRedirectingFactoryBody(target); | |
2338 if (body != null) { | 2330 if (body != null) { |
2339 // If the redirection target is itself a redirecting factory, it | 2331 target = body.target; |
2340 // means that it is unresolved. So we set target to null so we | 2332 if (target == null) { |
2341 // can generate a no-such-method error below. | 2333 push(deprecated_buildCompileTimeError( |
2342 assert(body.isUnresolved); | 2334 "Cyclic definition of factory" |
2343 target = null; | 2335 " '${debugName(type.name, name)}'.", |
2344 errorName = body.unresolvedName; | 2336 nameToken.charOffset)); |
| 2337 return; |
| 2338 } |
| 2339 DartType targetType = body.returnType; |
| 2340 if (arguments.types.isNotEmpty) { |
| 2341 if (initialTarget.function.typeParameters.length != |
| 2342 arguments.types.length) { |
| 2343 // TODO(ahe): Report a problem here, try to unify with |
| 2344 // [buildStaticInvocation]. |
| 2345 arguments.types.clear(); |
| 2346 } else { |
| 2347 Substitution substitution = Substitution.fromPairs( |
| 2348 initialTarget.function.typeParameters, arguments.types); |
| 2349 targetType = substitution.substituteType(targetType); |
| 2350 if (targetType is InterfaceType) { |
| 2351 arguments = new KernelArguments(arguments.positional, |
| 2352 types: targetType.typeArguments, named: arguments.named) |
| 2353 ..fileOffset = arguments.fileOffset; |
| 2354 } else { |
| 2355 arguments.types.clear(); |
| 2356 } |
| 2357 } |
| 2358 } |
| 2359 body = RedirectingFactoryBody.getRedirectingFactoryBody(target); |
| 2360 if (body != null) { |
| 2361 // If the redirection target is itself a redirecting factory, it |
| 2362 // means that it is unresolved. So we set target to null so we |
| 2363 // can generate a no-such-method error below. |
| 2364 assert(body.isUnresolved); |
| 2365 target = null; |
| 2366 errorName = body.unresolvedName; |
| 2367 } |
| 2368 } else { |
| 2369 target = initialTarget; |
2345 } | 2370 } |
2346 } | 2371 } |
2347 if (target is Constructor || | 2372 if (target is Constructor || |
2348 (target is Procedure && target.kind == ProcedureKind.Factory)) { | 2373 (target is Procedure && target.kind == ProcedureKind.Factory)) { |
2349 push(buildStaticInvocation(target, arguments, | 2374 push(buildStaticInvocation(target, arguments, |
2350 isConst: optional("const", token) || optional("@", token), | 2375 isConst: optional("const", token) || optional("@", token), |
2351 charOffset: nameToken.charOffset, | 2376 charOffset: nameToken.charOffset, |
2352 initialTarget: initialTarget)); | 2377 initialTarget: initialTarget)); |
2353 return; | 2378 return; |
2354 } else { | 2379 } else { |
(...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3827 return AsyncMarker.Async; | 3852 return AsyncMarker.Async; |
3828 } else { | 3853 } else { |
3829 assert(identical(starToken.stringValue, "*")); | 3854 assert(identical(starToken.stringValue, "*")); |
3830 return AsyncMarker.AsyncStar; | 3855 return AsyncMarker.AsyncStar; |
3831 } | 3856 } |
3832 } else { | 3857 } else { |
3833 return unhandled(asyncToken.lexeme, "asyncMarkerFromTokens", | 3858 return unhandled(asyncToken.lexeme, "asyncMarkerFromTokens", |
3834 asyncToken.charOffset, null); | 3859 asyncToken.charOffset, null); |
3835 } | 3860 } |
3836 } | 3861 } |
OLD | NEW |