| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 dart2js.resolution.send_structure; | 5 library dart2js.resolution.send_structure; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../constants/expressions.dart'; | 8 import '../constants/expressions.dart'; |
| 9 import '../elements/resolution_types.dart'; | 9 import '../elements/resolution_types.dart'; |
| 10 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 105 |
| 106 @override | 106 @override |
| 107 SendStructureKind get kind => SendStructureKind.LOGICAL_OR; | 107 SendStructureKind get kind => SendStructureKind.LOGICAL_OR; |
| 108 | 108 |
| 109 String toString() => '||'; | 109 String toString() => '||'; |
| 110 } | 110 } |
| 111 | 111 |
| 112 /// The structure for a [Send] of the form `a is T`. | 112 /// The structure for a [Send] of the form `a is T`. |
| 113 class IsStructure<R, A> implements SendStructure<R, A> { | 113 class IsStructure<R, A> implements SendStructure<R, A> { |
| 114 /// The type that the expression is tested against. | 114 /// The type that the expression is tested against. |
| 115 final DartType type; | 115 final ResolutionDartType type; |
| 116 | 116 |
| 117 IsStructure(this.type); | 117 IsStructure(this.type); |
| 118 | 118 |
| 119 R dispatch(SemanticSendVisitor<R, A> visitor, Send node, A arg) { | 119 R dispatch(SemanticSendVisitor<R, A> visitor, Send node, A arg) { |
| 120 return visitor.visitIs(node, node.receiver, type, arg); | 120 return visitor.visitIs(node, node.receiver, type, arg); |
| 121 } | 121 } |
| 122 | 122 |
| 123 @override | 123 @override |
| 124 SendStructureKind get kind => SendStructureKind.IS; | 124 SendStructureKind get kind => SendStructureKind.IS; |
| 125 | 125 |
| 126 String toString() => 'is $type'; | 126 String toString() => 'is $type'; |
| 127 } | 127 } |
| 128 | 128 |
| 129 /// The structure for a [Send] of the form `a is! T`. | 129 /// The structure for a [Send] of the form `a is! T`. |
| 130 class IsNotStructure<R, A> implements SendStructure<R, A> { | 130 class IsNotStructure<R, A> implements SendStructure<R, A> { |
| 131 /// The type that the expression is tested against. | 131 /// The type that the expression is tested against. |
| 132 final DartType type; | 132 final ResolutionDartType type; |
| 133 | 133 |
| 134 IsNotStructure(this.type); | 134 IsNotStructure(this.type); |
| 135 | 135 |
| 136 R dispatch(SemanticSendVisitor<R, A> visitor, Send node, A arg) { | 136 R dispatch(SemanticSendVisitor<R, A> visitor, Send node, A arg) { |
| 137 return visitor.visitIsNot(node, node.receiver, type, arg); | 137 return visitor.visitIsNot(node, node.receiver, type, arg); |
| 138 } | 138 } |
| 139 | 139 |
| 140 @override | 140 @override |
| 141 SendStructureKind get kind => SendStructureKind.IS_NOT; | 141 SendStructureKind get kind => SendStructureKind.IS_NOT; |
| 142 | 142 |
| 143 String toString() => 'is! $type'; | 143 String toString() => 'is! $type'; |
| 144 } | 144 } |
| 145 | 145 |
| 146 /// The structure for a [Send] of the form `a as T`. | 146 /// The structure for a [Send] of the form `a as T`. |
| 147 class AsStructure<R, A> implements SendStructure<R, A> { | 147 class AsStructure<R, A> implements SendStructure<R, A> { |
| 148 /// The type that the expression is cast to. | 148 /// The type that the expression is cast to. |
| 149 final DartType type; | 149 final ResolutionDartType type; |
| 150 | 150 |
| 151 AsStructure(this.type); | 151 AsStructure(this.type); |
| 152 | 152 |
| 153 R dispatch(SemanticSendVisitor<R, A> visitor, Send node, A arg) { | 153 R dispatch(SemanticSendVisitor<R, A> visitor, Send node, A arg) { |
| 154 return visitor.visitAs(node, node.receiver, type, arg); | 154 return visitor.visitAs(node, node.receiver, type, arg); |
| 155 } | 155 } |
| 156 | 156 |
| 157 @override | 157 @override |
| 158 SendStructureKind get kind => SendStructureKind.AS; | 158 SendStructureKind get kind => SendStructureKind.AS; |
| 159 | 159 |
| (...skipping 1947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2107 if (constructor.isEffectiveTargetMalformed) { | 2107 if (constructor.isEffectiveTargetMalformed) { |
| 2108 return visitor.visitUnresolvedRedirectingFactoryConstructorInvoke( | 2108 return visitor.visitUnresolvedRedirectingFactoryConstructorInvoke( |
| 2109 node, | 2109 node, |
| 2110 semantics.element, | 2110 semantics.element, |
| 2111 semantics.type, | 2111 semantics.type, |
| 2112 node.send.argumentsNode, | 2112 node.send.argumentsNode, |
| 2113 callStructure, | 2113 callStructure, |
| 2114 arg); | 2114 arg); |
| 2115 } | 2115 } |
| 2116 ConstructorElement effectiveTarget = constructor.effectiveTarget; | 2116 ConstructorElement effectiveTarget = constructor.effectiveTarget; |
| 2117 InterfaceType effectiveTargetType = | 2117 ResolutionInterfaceType effectiveTargetType = |
| 2118 constructor.computeEffectiveTargetType(semantics.type); | 2118 constructor.computeEffectiveTargetType(semantics.type); |
| 2119 if (callStructure | 2119 if (callStructure |
| 2120 .signatureApplies(effectiveTarget.functionSignature)) { | 2120 .signatureApplies(effectiveTarget.functionSignature)) { |
| 2121 return visitor.visitRedirectingFactoryConstructorInvoke( | 2121 return visitor.visitRedirectingFactoryConstructorInvoke( |
| 2122 node, | 2122 node, |
| 2123 semantics.element, | 2123 semantics.element, |
| 2124 semantics.type, | 2124 semantics.type, |
| 2125 effectiveTarget, | 2125 effectiveTarget, |
| 2126 effectiveTargetType, | 2126 effectiveTargetType, |
| 2127 node.send.argumentsNode, | 2127 node.send.argumentsNode, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2231 LateConstInvokeStructure(this.elements); | 2231 LateConstInvokeStructure(this.elements); |
| 2232 | 2232 |
| 2233 @override | 2233 @override |
| 2234 NewStructureKind get kind => NewStructureKind.LATE_CONST; | 2234 NewStructureKind get kind => NewStructureKind.LATE_CONST; |
| 2235 | 2235 |
| 2236 /// Convert this new structure into a regular new structure using the data | 2236 /// Convert this new structure into a regular new structure using the data |
| 2237 /// available in [elements]. | 2237 /// available in [elements]. |
| 2238 NewStructure resolve(NewExpression node) { | 2238 NewStructure resolve(NewExpression node) { |
| 2239 Element element = elements[node.send]; | 2239 Element element = elements[node.send]; |
| 2240 Selector selector = elements.getSelector(node.send); | 2240 Selector selector = elements.getSelector(node.send); |
| 2241 DartType type = elements.getType(node); | 2241 ResolutionDartType type = elements.getType(node); |
| 2242 ConstantExpression constant = elements.getConstant(node); | 2242 ConstantExpression constant = elements.getConstant(node); |
| 2243 if (element.isMalformed || | 2243 if (element.isMalformed || |
| 2244 constant == null || | 2244 constant == null || |
| 2245 constant.kind == ConstantExpressionKind.ERRONEOUS) { | 2245 constant.kind == ConstantExpressionKind.ERRONEOUS) { |
| 2246 // This is a non-constant constant constructor invocation, like | 2246 // This is a non-constant constant constructor invocation, like |
| 2247 // `const Const(method())`. | 2247 // `const Const(method())`. |
| 2248 return new NewInvokeStructure( | 2248 return new NewInvokeStructure( |
| 2249 new ConstructorAccessSemantics( | 2249 new ConstructorAccessSemantics( |
| 2250 ConstructorAccessKind.NON_CONSTANT_CONSTRUCTOR, element, type), | 2250 ConstructorAccessKind.NON_CONSTANT_CONSTRUCTOR, element, type), |
| 2251 selector); | 2251 selector); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2268 throw new SpannableAssertionFailure( | 2268 throw new SpannableAssertionFailure( |
| 2269 node, "Unexpected constant kind $kind: ${constant.toDartText()}"); | 2269 node, "Unexpected constant kind $kind: ${constant.toDartText()}"); |
| 2270 } | 2270 } |
| 2271 return new ConstInvokeStructure(kind, constant); | 2271 return new ConstInvokeStructure(kind, constant); |
| 2272 } | 2272 } |
| 2273 } | 2273 } |
| 2274 | 2274 |
| 2275 R dispatch(SemanticSendVisitor<R, A> visitor, NewExpression node, A arg) { | 2275 R dispatch(SemanticSendVisitor<R, A> visitor, NewExpression node, A arg) { |
| 2276 Element element = elements[node.send]; | 2276 Element element = elements[node.send]; |
| 2277 Selector selector = elements.getSelector(node.send); | 2277 Selector selector = elements.getSelector(node.send); |
| 2278 DartType type = elements.getType(node); | 2278 ResolutionDartType type = elements.getType(node); |
| 2279 ConstantExpression constant = elements.getConstant(node); | 2279 ConstantExpression constant = elements.getConstant(node); |
| 2280 if (element.isMalformed || | 2280 if (element.isMalformed || |
| 2281 constant == null || | 2281 constant == null || |
| 2282 constant.kind == ConstantExpressionKind.ERRONEOUS) { | 2282 constant.kind == ConstantExpressionKind.ERRONEOUS) { |
| 2283 // This is a non-constant constant constructor invocation, like | 2283 // This is a non-constant constant constructor invocation, like |
| 2284 // `const Const(method())`. | 2284 // `const Const(method())`. |
| 2285 return visitor.errorNonConstantConstructorInvoke(node, element, type, | 2285 return visitor.errorNonConstantConstructorInvoke(node, element, type, |
| 2286 node.send.argumentsNode, selector.callStructure, arg); | 2286 node.send.argumentsNode, selector.callStructure, arg); |
| 2287 } else { | 2287 } else { |
| 2288 ConstantInvokeKind kind; | 2288 ConstantInvokeKind kind; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2467 | 2467 |
| 2468 R dispatch(SemanticDeclarationVisitor<R, A> visitor, A arg) { | 2468 R dispatch(SemanticDeclarationVisitor<R, A> visitor, A arg) { |
| 2469 return visitor.visitFieldInitializer( | 2469 return visitor.visitFieldInitializer( |
| 2470 node, field, node.arguments.single, arg); | 2470 node, field, node.arguments.single, arg); |
| 2471 } | 2471 } |
| 2472 } | 2472 } |
| 2473 | 2473 |
| 2474 class SuperConstructorInvokeStructure<R, A> extends InitializerStructure<R, A> { | 2474 class SuperConstructorInvokeStructure<R, A> extends InitializerStructure<R, A> { |
| 2475 final Send node; | 2475 final Send node; |
| 2476 final ConstructorElement constructor; | 2476 final ConstructorElement constructor; |
| 2477 final InterfaceType type; | 2477 final ResolutionInterfaceType type; |
| 2478 final CallStructure callStructure; | 2478 final CallStructure callStructure; |
| 2479 | 2479 |
| 2480 SuperConstructorInvokeStructure( | 2480 SuperConstructorInvokeStructure( |
| 2481 this.node, this.constructor, this.type, this.callStructure); | 2481 this.node, this.constructor, this.type, this.callStructure); |
| 2482 | 2482 |
| 2483 R dispatch(SemanticDeclarationVisitor<R, A> visitor, A arg) { | 2483 R dispatch(SemanticDeclarationVisitor<R, A> visitor, A arg) { |
| 2484 return visitor.visitSuperConstructorInvoke( | 2484 return visitor.visitSuperConstructorInvoke( |
| 2485 node, constructor, type, node.argumentsNode, callStructure, arg); | 2485 node, constructor, type, node.argumentsNode, callStructure, arg); |
| 2486 } | 2486 } |
| 2487 | 2487 |
| 2488 bool get isConstructorInvoke => true; | 2488 bool get isConstructorInvoke => true; |
| 2489 } | 2489 } |
| 2490 | 2490 |
| 2491 class ImplicitSuperConstructorInvokeStructure<R, A> | 2491 class ImplicitSuperConstructorInvokeStructure<R, A> |
| 2492 extends InitializerStructure<R, A> { | 2492 extends InitializerStructure<R, A> { |
| 2493 final FunctionExpression node; | 2493 final FunctionExpression node; |
| 2494 final ConstructorElement constructor; | 2494 final ConstructorElement constructor; |
| 2495 final InterfaceType type; | 2495 final ResolutionInterfaceType type; |
| 2496 | 2496 |
| 2497 ImplicitSuperConstructorInvokeStructure( | 2497 ImplicitSuperConstructorInvokeStructure( |
| 2498 this.node, this.constructor, this.type); | 2498 this.node, this.constructor, this.type); |
| 2499 | 2499 |
| 2500 R dispatch(SemanticDeclarationVisitor<R, A> visitor, A arg) { | 2500 R dispatch(SemanticDeclarationVisitor<R, A> visitor, A arg) { |
| 2501 return visitor.visitImplicitSuperConstructorInvoke( | 2501 return visitor.visitImplicitSuperConstructorInvoke( |
| 2502 node, constructor, type, arg); | 2502 node, constructor, type, arg); |
| 2503 } | 2503 } |
| 2504 | 2504 |
| 2505 bool get isConstructorInvoke => true; | 2505 bool get isConstructorInvoke => true; |
| 2506 } | 2506 } |
| 2507 | 2507 |
| 2508 class ThisConstructorInvokeStructure<R, A> extends InitializerStructure<R, A> { | 2508 class ThisConstructorInvokeStructure<R, A> extends InitializerStructure<R, A> { |
| 2509 final Send node; | 2509 final Send node; |
| 2510 final ConstructorElement constructor; | 2510 final ConstructorElement constructor; |
| 2511 final CallStructure callStructure; | 2511 final CallStructure callStructure; |
| 2512 | 2512 |
| 2513 ThisConstructorInvokeStructure( | 2513 ThisConstructorInvokeStructure( |
| 2514 this.node, this.constructor, this.callStructure); | 2514 this.node, this.constructor, this.callStructure); |
| 2515 | 2515 |
| 2516 R dispatch(SemanticDeclarationVisitor<R, A> visitor, A arg) { | 2516 R dispatch(SemanticDeclarationVisitor<R, A> visitor, A arg) { |
| 2517 return visitor.visitThisConstructorInvoke( | 2517 return visitor.visitThisConstructorInvoke( |
| 2518 node, constructor, node.argumentsNode, callStructure, arg); | 2518 node, constructor, node.argumentsNode, callStructure, arg); |
| 2519 } | 2519 } |
| 2520 | 2520 |
| 2521 bool get isConstructorInvoke => true; | 2521 bool get isConstructorInvoke => true; |
| 2522 } | 2522 } |
| OLD | NEW |