Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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.test.message_kind_helper; | 5 library dart2js.test.message_kind_helper; |
| 6 | 6 |
| 7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 | 9 |
| 10 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' show | 10 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' show |
| 11 Compiler, | 11 Compiler, |
| 12 MessageKind; | 12 MessageKind; |
| 13 | 13 |
| 14 import 'memory_compiler.dart'; | 14 import 'memory_compiler.dart'; |
| 15 | 15 |
| 16 const String ESCAPE_REGEXP = r'[[\]{}()*+?.\\^$|]'; | 16 const String ESCAPE_REGEXP = r'[[\]{}()*+?.\\^$|]'; |
| 17 | 17 |
| 18 /// Most examples generate a single diagnostic. | 18 /// Most examples generate a single diagnostic. |
| 19 /// Add an exception here if a single diagnostic cannot be produced. | 19 /// Add an exception here if a single diagnostic cannot be produced. |
| 20 /// However, consider that a single concise diagnostic is easier to understand, | 20 /// However, consider that a single concise diagnostic is easier to understand, |
| 21 /// so try to change error reporting logic before adding an exception. | 21 /// so try to change error reporting logic before adding an exception. |
| 22 final Set<MessageKind> kindsWithExtraMessages = new Set<MessageKind>.from([ | 22 final Set<MessageKind> kindsWithExtraMessages = new Set<MessageKind>.from([ |
| 23 // See http://dartbug.com/18361. | 23 // See http://dartbug.com/18361. |
|
Johnni Winther
2014/04/25 09:57:55
Replace . by : to indicated that the bug has to do
ahe
2014/04/25 12:51:17
Done.
| |
| 24 // If you add something here, please file a *new* bug report. | |
|
Johnni Winther
2014/04/25 09:57:55
Move above the previous line.
ahe
2014/04/25 12:51:17
Done.
| |
| 24 MessageKind.CANNOT_EXTEND_MALFORMED, | 25 MessageKind.CANNOT_EXTEND_MALFORMED, |
| 25 MessageKind.CANNOT_IMPLEMENT_MALFORMED, | 26 MessageKind.CANNOT_IMPLEMENT_MALFORMED, |
| 26 MessageKind.CANNOT_MIXIN, | 27 MessageKind.CANNOT_MIXIN, |
| 27 MessageKind.CANNOT_MIXIN_MALFORMED, | 28 MessageKind.CANNOT_MIXIN_MALFORMED, |
| 28 MessageKind.CYCLIC_TYPEDEF_ONE, | 29 MessageKind.CYCLIC_TYPEDEF_ONE, |
| 29 MessageKind.EQUAL_MAP_ENTRY_KEY, | 30 MessageKind.EQUAL_MAP_ENTRY_KEY, |
| 30 MessageKind.FINAL_FUNCTION_TYPE_PARAMETER, | 31 MessageKind.FINAL_FUNCTION_TYPE_PARAMETER, |
| 31 MessageKind.FORMAL_DECLARED_CONST, | 32 MessageKind.FORMAL_DECLARED_CONST, |
| 32 MessageKind.FORMAL_DECLARED_STATIC, | 33 MessageKind.FORMAL_DECLARED_STATIC, |
| 34 MessageKind.FUNCTION_TYPE_FORMAL_WITH_DEFAULT, | |
| 33 MessageKind.HEX_DIGIT_EXPECTED, | 35 MessageKind.HEX_DIGIT_EXPECTED, |
| 34 MessageKind.HIDDEN_IMPLICIT_IMPORT, | 36 MessageKind.HIDDEN_IMPLICIT_IMPORT, |
| 35 MessageKind.HIDDEN_IMPORT, | 37 MessageKind.HIDDEN_IMPORT, |
| 36 MessageKind.INHERIT_GETTER_AND_METHOD, | 38 MessageKind.INHERIT_GETTER_AND_METHOD, |
| 37 MessageKind.UNIMPLEMENTED_METHOD, | 39 MessageKind.UNIMPLEMENTED_METHOD, |
| 38 MessageKind.UNIMPLEMENTED_METHOD_ONE, | 40 MessageKind.UNIMPLEMENTED_METHOD_ONE, |
| 41 MessageKind.UNMATCHED_TOKEN, | |
| 39 MessageKind.UNTERMINATED_STRING, | 42 MessageKind.UNTERMINATED_STRING, |
| 40 MessageKind.VAR_FUNCTION_TYPE_PARAMETER, | 43 MessageKind.VAR_FUNCTION_TYPE_PARAMETER, |
| 41 MessageKind.VOID_NOT_ALLOWED, | 44 MessageKind.VOID_NOT_ALLOWED, |
| 42 MessageKind.UNMATCHED_TOKEN, | |
| 43 ]); | 45 ]); |
| 44 | 46 |
| 45 /// Most messages can be tested without causing a fatal error. Add an exception | 47 /// Most messages can be tested without causing a fatal error. Add an exception |
| 46 /// here if a fatal error is unavoidable and leads to pending classes. | 48 /// here if a fatal error is unavoidable and leads to pending classes. |
| 47 /// Try to avoid adding exceptions here; a fatal error causes the compiler to | 49 /// Try to avoid adding exceptions here; a fatal error causes the compiler to |
| 48 /// stop before analyzing all input, and it isn't safe to reuse it. | 50 /// stop before analyzing all input, and it isn't safe to reuse it. |
| 49 final Set<MessageKind> kindsWithPendingClasses = new Set<MessageKind>.from([ | 51 final Set<MessageKind> kindsWithPendingClasses = new Set<MessageKind>.from([ |
| 50 MessageKind.TYPEDEF_FORMAL_WITH_DEFAULT, | 52 // If you add something here, please file a new bug report. |
|
Johnni Winther
2014/04/25 09:57:55
new -> *new*
ahe
2014/04/25 12:51:17
Done.
| |
| 51 ]); | 53 ]); |
| 52 | 54 |
| 53 /// Most messages can be tested without causing a fatal error. Add an exception | 55 /// Most messages can be tested without causing a fatal error. Add an exception |
| 54 /// here if a fatal error is unavoidable. | 56 /// here if a fatal error is unavoidable. |
| 55 /// Try to avoid adding exceptions here; a fatal error causes the compiler to | 57 /// Try to avoid adding exceptions here; a fatal error causes the compiler to |
| 56 /// stop before analyzing all input, and it isn't safe to reuse it. | 58 /// stop before analyzing all input, and it isn't safe to reuse it. |
| 57 final Set<MessageKind> kindsWithFatalErrors = new Set<MessageKind>.from([ | 59 final Set<MessageKind> kindsWithFatalErrors = new Set<MessageKind>.from([ |
| 58 MessageKind.FUNCTION_TYPE_FORMAL_WITH_DEFAULT, | 60 // If you add something here, please file a *new* bug report. |
| 59 MessageKind.HEX_DIGIT_EXPECTED, | 61 MessageKind.HEX_DIGIT_EXPECTED, |
| 60 MessageKind.REDIRECTING_FACTORY_WITH_DEFAULT, | |
| 61 MessageKind.REFERENCE_IN_INITIALIZATION, | |
| 62 MessageKind.TYPEDEF_FORMAL_WITH_DEFAULT, | |
| 63 MessageKind.UNMATCHED_TOKEN, | 62 MessageKind.UNMATCHED_TOKEN, |
| 64 MessageKind.UNTERMINATED_STRING, | 63 MessageKind.UNTERMINATED_STRING, |
| 65 ]); | 64 ]); |
| 66 | 65 |
| 67 Future<Compiler> check(MessageKind kind, Compiler cachedCompiler) { | 66 Future<Compiler> check(MessageKind kind, Compiler cachedCompiler) { |
| 68 Expect.isNotNull(kind.howToFix); | 67 Expect.isNotNull(kind.howToFix); |
| 69 Expect.isFalse(kind.examples.isEmpty); | 68 Expect.isFalse(kind.examples.isEmpty); |
| 70 | 69 |
| 71 return Future.forEach(kind.examples, (example) { | 70 return Future.forEach(kind.examples, (example) { |
| 72 if (example is String) { | 71 if (example is String) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 if (!unexpectedMessages.isEmpty) { | 116 if (!unexpectedMessages.isEmpty) { |
| 118 for (String message in unexpectedMessages) { | 117 for (String message in unexpectedMessages) { |
| 119 print("Unexpected message: $message"); | 118 print("Unexpected message: $message"); |
| 120 } | 119 } |
| 121 if (!kindsWithExtraMessages.contains(kind)) { | 120 if (!kindsWithExtraMessages.contains(kind)) { |
| 122 // Try changing the error reporting logic before adding an exception | 121 // Try changing the error reporting logic before adding an exception |
| 123 // to [kindsWithExtraMessages]. | 122 // to [kindsWithExtraMessages]. |
| 124 throw 'Unexpected messages found.'; | 123 throw 'Unexpected messages found.'; |
| 125 } | 124 } |
| 126 } | 125 } |
| 127 cachedCompiler = compiler; | 126 Expect.isTrue(!compiler.compilerWasCancelled || |
| 128 Expect.isTrue(kindsWithFatalErrors.contains(kind) || | 127 kindsWithFatalErrors.contains(kind)); |
| 129 !compiler.compilerWasCancelled); | |
| 130 | 128 |
| 131 bool pendingStuff = false; | 129 bool pendingStuff = false; |
| 132 for (var e in compiler.resolver.pendingClassesToBePostProcessed) { | 130 for (var e in compiler.resolver.pendingClassesToBePostProcessed) { |
| 133 pendingStuff = true; | 131 pendingStuff = true; |
| 134 compiler.reportInfo( | 132 compiler.reportInfo( |
| 135 e, MessageKind.GENERIC, | 133 e, MessageKind.GENERIC, |
| 136 {'text': 'Pending class to be post-processed.'}); | 134 {'text': 'Pending class to be post-processed.'}); |
| 137 } | 135 } |
| 138 for (var e in compiler.resolver.pendingClassesToBeResolved) { | 136 for (var e in compiler.resolver.pendingClassesToBeResolved) { |
| 139 pendingStuff = true; | 137 pendingStuff = true; |
| 140 compiler.reportInfo( | 138 compiler.reportInfo( |
| 141 e, MessageKind.GENERIC, | 139 e, MessageKind.GENERIC, |
| 142 {'text': 'Pending class to be resolved.'}); | 140 {'text': 'Pending class to be resolved.'}); |
| 143 } | 141 } |
| 144 if (pendingStuff) { | 142 Expect.isTrue(!pendingStuff || kindsWithPendingClasses.contains(kind)); |
| 145 if (!kindsWithPendingClasses.contains(kind)) { | 143 |
| 146 throw 'Stuff was pending'; | 144 if (!pendingStuff && !compiler.compilerWasCancelled) { |
| 147 } | 145 // If there is pending stuff, or the compiler was cancelled, we |
| 148 cachedCompiler = null; | 146 // shouldn't reuse the compiler. |
| 149 } else if (compiler.compilerWasCancelled) { | |
| 150 cachedCompiler = null; | |
| 151 } else { | |
| 152 cachedCompiler = compiler; | 147 cachedCompiler = compiler; |
| 153 } | 148 } |
| 154 }); | 149 }); |
| 155 }).then((_) => cachedCompiler); | 150 }).then((_) => cachedCompiler); |
| 156 } | 151 } |
| OLD | NEW |