| 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 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Categorizes `noSuchMethod` implementations. | 8 * Categorizes `noSuchMethod` implementations. |
| 9 * | 9 * |
| 10 * If user code includes `noSuchMethod` implementations, type inference is | 10 * If user code includes `noSuchMethod` implementations, type inference is |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 _compiler.reportHint(e, | 97 _compiler.reportHint(e, |
| 98 MessageKind.COMPLEX_RETURNING_NSM); | 98 MessageKind.COMPLEX_RETURNING_NSM); |
| 99 } | 99 } |
| 100 }); | 100 }); |
| 101 } | 101 } |
| 102 | 102 |
| 103 /// Returns [true] if the given element is a complex [noSuchMethod] | 103 /// Returns [true] if the given element is a complex [noSuchMethod] |
| 104 /// implementation. An implementation is complex if it falls into | 104 /// implementation. An implementation is complex if it falls into |
| 105 /// category C, as described above. | 105 /// category C, as described above. |
| 106 bool isComplex(FunctionElement element) { | 106 bool isComplex(FunctionElement element) { |
| 107 assert(element.name == Compiler.NO_SUCH_METHOD); | 107 assert(element.name == Identifiers.noSuchMethod_); |
| 108 return otherImpls.contains(element); | 108 return otherImpls.contains(element); |
| 109 } | 109 } |
| 110 | 110 |
| 111 _subcategorizeOther(FunctionElement element) { | 111 _subcategorizeOther(FunctionElement element) { |
| 112 TypeMask returnType = | 112 TypeMask returnType = |
| 113 _compiler.typesTask.getGuaranteedReturnTypeOfElement(element); | 113 _compiler.typesTask.getGuaranteedReturnTypeOfElement(element); |
| 114 if (returnType == const TypeMask.nonNullEmpty()) { | 114 if (returnType == const TypeMask.nonNullEmpty()) { |
| 115 complexNoReturnImpls.add(element); | 115 complexNoReturnImpls.add(element); |
| 116 } else { | 116 } else { |
| 117 complexReturningImpls.add(element); | 117 complexReturningImpls.add(element); |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| 121 NsmCategory _categorizeImpl(FunctionElement element) { | 121 NsmCategory _categorizeImpl(FunctionElement element) { |
| 122 assert(element.name == Compiler.NO_SUCH_METHOD); | 122 assert(element.name == Identifiers.noSuchMethod_); |
| 123 if (defaultImpls.contains(element)) { | 123 if (defaultImpls.contains(element)) { |
| 124 return NsmCategory.DEFAULT; | 124 return NsmCategory.DEFAULT; |
| 125 } | 125 } |
| 126 if (throwingImpls.contains(element)) { | 126 if (throwingImpls.contains(element)) { |
| 127 return NsmCategory.THROWING; | 127 return NsmCategory.THROWING; |
| 128 } | 128 } |
| 129 if (otherImpls.contains(element)) { | 129 if (otherImpls.contains(element)) { |
| 130 return NsmCategory.OTHER; | 130 return NsmCategory.OTHER; |
| 131 } | 131 } |
| 132 if (!_compiler.noSuchMethodSelector.signatureApplies(element)) { | 132 if (!Selectors.noSuchMethod_.signatureApplies(element)) { |
| 133 otherImpls.add(element); | 133 otherImpls.add(element); |
| 134 return NsmCategory.OTHER; | 134 return NsmCategory.OTHER; |
| 135 } | 135 } |
| 136 if (_isDefaultNoSuchMethodImplementation(element)) { | 136 if (_isDefaultNoSuchMethodImplementation(element)) { |
| 137 defaultImpls.add(element); | 137 defaultImpls.add(element); |
| 138 return NsmCategory.DEFAULT; | 138 return NsmCategory.DEFAULT; |
| 139 } else if (_hasForwardingSyntax(element)) { | 139 } else if (_hasForwardingSyntax(element)) { |
| 140 // If the implementation is 'noSuchMethod(x) => super.noSuchMethod(x);' | 140 // If the implementation is 'noSuchMethod(x) => super.noSuchMethod(x);' |
| 141 // then it is in the same category as the super call. | 141 // then it is in the same category as the super call. |
| 142 Element superCall = element.enclosingClass | 142 Element superCall = element.enclosingClass |
| 143 .lookupSuperByName(_compiler.noSuchMethodSelector.memberName); | 143 .lookupSuperByName(Selectors.noSuchMethod_.memberName); |
| 144 NsmCategory category = _categorizeImpl(superCall); | 144 NsmCategory category = _categorizeImpl(superCall); |
| 145 switch(category) { | 145 switch(category) { |
| 146 case NsmCategory.DEFAULT: | 146 case NsmCategory.DEFAULT: |
| 147 defaultImpls.add(element); | 147 defaultImpls.add(element); |
| 148 break; | 148 break; |
| 149 case NsmCategory.THROWING: | 149 case NsmCategory.THROWING: |
| 150 throwingImpls.add(element); | 150 throwingImpls.add(element); |
| 151 break; | 151 break; |
| 152 case NsmCategory.OTHER: | 152 case NsmCategory.OTHER: |
| 153 otherImpls.add(element); | 153 otherImpls.add(element); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 183 !body.statements.isEmpty && | 183 !body.statements.isEmpty && |
| 184 body.statements.nodes.tail.isEmpty) { | 184 body.statements.nodes.tail.isEmpty) { |
| 185 Statement stmt = body.statements.nodes.head; | 185 Statement stmt = body.statements.nodes.head; |
| 186 if (stmt is Return && stmt.hasExpression) { | 186 if (stmt is Return && stmt.hasExpression) { |
| 187 expr = stmt.expression; | 187 expr = stmt.expression; |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 if (expr is Send && | 190 if (expr is Send && |
| 191 expr.isSuperCall && | 191 expr.isSuperCall && |
| 192 expr.selector is Identifier && | 192 expr.selector is Identifier && |
| 193 (expr.selector as Identifier).source == Compiler.NO_SUCH_METHOD) { | 193 (expr.selector as Identifier).source == Identifiers.noSuchMethod_) { |
| 194 var arg = expr.arguments.head; | 194 var arg = expr.arguments.head; |
| 195 if (expr.arguments.tail.isEmpty && | 195 if (expr.arguments.tail.isEmpty && |
| 196 arg is Send && | 196 arg is Send && |
| 197 arg.argumentsNode == null && | 197 arg.argumentsNode == null && |
| 198 arg.receiver == null && | 198 arg.receiver == null && |
| 199 arg.selector is Identifier && | 199 arg.selector is Identifier && |
| 200 arg.selector.source == param) { | 200 arg.selector.source == param) { |
| 201 return true; | 201 return true; |
| 202 } | 202 } |
| 203 } | 203 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 216 if (body.statements.nodes.head is ExpressionStatement) { | 216 if (body.statements.nodes.head is ExpressionStatement) { |
| 217 ExpressionStatement stmt = body.statements.nodes.head; | 217 ExpressionStatement stmt = body.statements.nodes.head; |
| 218 return stmt.expression is Throw; | 218 return stmt.expression is Throw; |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 return false; | 221 return false; |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 | 224 |
| 225 enum NsmCategory { DEFAULT, THROWING, OTHER } | 225 enum NsmCategory { DEFAULT, THROWING, OTHER } |
| OLD | NEW |