| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 /// The implementations that have not yet been categorized. | 52 /// The implementations that have not yet been categorized. |
| 53 final Set<FunctionElement> _uncategorizedImpls = new Set<FunctionElement>(); | 53 final Set<FunctionElement> _uncategorizedImpls = new Set<FunctionElement>(); |
| 54 | 54 |
| 55 final JavaScriptBackend _backend; | 55 final JavaScriptBackend _backend; |
| 56 final Compiler _compiler; | 56 final Compiler _compiler; |
| 57 | 57 |
| 58 NoSuchMethodRegistry(JavaScriptBackend backend) | 58 NoSuchMethodRegistry(JavaScriptBackend backend) |
| 59 : this._backend = backend, | 59 : this._backend = backend, |
| 60 this._compiler = backend.compiler; | 60 this._compiler = backend.compiler; |
| 61 | 61 |
| 62 DiagnosticReporter get reporter => _compiler.reporter; |
| 63 |
| 62 bool get hasThrowingNoSuchMethod => throwingImpls.isNotEmpty; | 64 bool get hasThrowingNoSuchMethod => throwingImpls.isNotEmpty; |
| 63 bool get hasComplexNoSuchMethod => otherImpls.isNotEmpty; | 65 bool get hasComplexNoSuchMethod => otherImpls.isNotEmpty; |
| 64 | 66 |
| 65 void registerNoSuchMethod(FunctionElement noSuchMethodElement) { | 67 void registerNoSuchMethod(FunctionElement noSuchMethodElement) { |
| 66 _uncategorizedImpls.add(noSuchMethodElement); | 68 _uncategorizedImpls.add(noSuchMethodElement); |
| 67 } | 69 } |
| 68 | 70 |
| 69 void onQueueEmpty() { | 71 void onQueueEmpty() { |
| 70 _uncategorizedImpls.forEach(_categorizeImpl); | 72 _uncategorizedImpls.forEach(_categorizeImpl); |
| 71 _uncategorizedImpls.clear(); | 73 _uncategorizedImpls.clear(); |
| 72 } | 74 } |
| 73 | 75 |
| 74 /// Now that type inference is complete, split category C into two | 76 /// Now that type inference is complete, split category C into two |
| 75 /// subcategories: C1, those that have no return type, and C2, those | 77 /// subcategories: C1, those that have no return type, and C2, those |
| 76 /// that have a return type. | 78 /// that have a return type. |
| 77 void onTypeInferenceComplete() { | 79 void onTypeInferenceComplete() { |
| 78 otherImpls.forEach(_subcategorizeOther); | 80 otherImpls.forEach(_subcategorizeOther); |
| 79 } | 81 } |
| 80 | 82 |
| 81 /// Emits a diagnostic | 83 /// Emits a diagnostic |
| 82 void emitDiagnostic() { | 84 void emitDiagnostic() { |
| 83 throwingImpls.forEach((e) { | 85 throwingImpls.forEach((e) { |
| 84 if (!_hasForwardingSyntax(e)) { | 86 if (!_hasForwardingSyntax(e)) { |
| 85 _compiler.reportHintMessage( | 87 reporter.reportHintMessage( |
| 86 e, MessageKind.DIRECTLY_THROWING_NSM); | 88 e, MessageKind.DIRECTLY_THROWING_NSM); |
| 87 } | 89 } |
| 88 }); | 90 }); |
| 89 complexNoReturnImpls.forEach((e) { | 91 complexNoReturnImpls.forEach((e) { |
| 90 if (!_hasForwardingSyntax(e)) { | 92 if (!_hasForwardingSyntax(e)) { |
| 91 _compiler.reportHintMessage( | 93 reporter.reportHintMessage( |
| 92 e, MessageKind.COMPLEX_THROWING_NSM); | 94 e, MessageKind.COMPLEX_THROWING_NSM); |
| 93 } | 95 } |
| 94 }); | 96 }); |
| 95 complexReturningImpls.forEach((e) { | 97 complexReturningImpls.forEach((e) { |
| 96 if (!_hasForwardingSyntax(e)) { | 98 if (!_hasForwardingSyntax(e)) { |
| 97 _compiler.reportHintMessage( | 99 reporter.reportHintMessage( |
| 98 e, MessageKind.COMPLEX_RETURNING_NSM); | 100 e, MessageKind.COMPLEX_RETURNING_NSM); |
| 99 } | 101 } |
| 100 }); | 102 }); |
| 101 } | 103 } |
| 102 | 104 |
| 103 /// Returns [true] if the given element is a complex [noSuchMethod] | 105 /// Returns [true] if the given element is a complex [noSuchMethod] |
| 104 /// implementation. An implementation is complex if it falls into | 106 /// implementation. An implementation is complex if it falls into |
| 105 /// category C, as described above. | 107 /// category C, as described above. |
| 106 bool isComplex(FunctionElement element) { | 108 bool isComplex(FunctionElement element) { |
| 107 assert(element.name == Identifiers.noSuchMethod_); | 109 assert(element.name == Identifiers.noSuchMethod_); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 if (body.statements.nodes.head is ExpressionStatement) { | 218 if (body.statements.nodes.head is ExpressionStatement) { |
| 217 ExpressionStatement stmt = body.statements.nodes.head; | 219 ExpressionStatement stmt = body.statements.nodes.head; |
| 218 return stmt.expression is Throw; | 220 return stmt.expression is Throw; |
| 219 } | 221 } |
| 220 } | 222 } |
| 221 return false; | 223 return false; |
| 222 } | 224 } |
| 223 } | 225 } |
| 224 | 226 |
| 225 enum NsmCategory { DEFAULT, THROWING, OTHER } | 227 enum NsmCategory { DEFAULT, THROWING, OTHER } |
| OLD | NEW |