Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 parser_helper; | 5 library parser_helper; |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 | 8 |
| 9 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t"; | 9 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t"; |
| 10 import "../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart"; | 10 import "../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart"; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 | 25 |
| 26 class LoggerCanceler implements DiagnosticListener { | 26 class LoggerCanceler implements DiagnosticListener { |
| 27 void cancel(String reason, {node, token, instruction, element}) { | 27 void cancel(String reason, {node, token, instruction, element}) { |
| 28 throw new CompilerCancelledException(reason); | 28 throw new CompilerCancelledException(reason); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void log(message) { | 31 void log(message) { |
| 32 print(message); | 32 print(message); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void internalErrorOnElement(element, String message) { | 35 void internalError(node, String message) { |
| 36 log(message); | 36 log(message); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void internalError(String message, {node, token, instruction, element}) { | |
| 40 log(message); | |
| 41 } | |
| 42 | |
| 43 SourceSpan spanFromSpannable(node) { | 39 SourceSpan spanFromSpannable(node) { |
| 44 throw 'unsupported operation'; | 40 throw 'unsupported operation'; |
| 45 } | 41 } |
| 46 | 42 |
| 47 void reportMessage(SourceSpan span, Message message, kind) { | 43 void reportMessage(SourceSpan span, Message message, kind) { |
| 48 log(message); | 44 log(message); |
| 49 } | 45 } |
| 50 | 46 |
| 47 void reportFatalError(Spannable node, | |
|
karlklose
2014/03/21 08:39:39
Could you add a comment describing what a fatal er
Johnni Winther
2014/03/21 09:39:23
Done.
| |
| 48 MessageKind errorCode, | |
| 49 [Map arguments]) { | |
| 50 log(new Message(errorCode, arguments, false)); | |
| 51 } | |
| 52 | |
| 51 void reportError(Spannable node, MessageKind errorCode, [Map arguments]) { | 53 void reportError(Spannable node, MessageKind errorCode, [Map arguments]) { |
| 52 log(new Message(errorCode, arguments, false)); | 54 log(new Message(errorCode, arguments, false)); |
| 53 } | 55 } |
| 54 | 56 |
| 55 void reportWarning(Spannable node, MessageKind errorCode, [Map arguments]) { | 57 void reportWarning(Spannable node, MessageKind errorCode, [Map arguments]) { |
| 56 log(new Message(errorCode, arguments, false)); | 58 log(new Message(errorCode, arguments, false)); |
| 57 } | 59 } |
| 58 | 60 |
| 59 void reportInfo(Spannable node, MessageKind errorCode, [Map arguments]) { | 61 void reportInfo(Spannable node, MessageKind errorCode, [Map arguments]) { |
| 60 log(new Message(errorCode, arguments, false)); | 62 log(new Message(errorCode, arguments, false)); |
| 61 } | 63 } |
| 62 | 64 |
| 65 void reportHint(Spannable node, MessageKind errorCode, [Map arguments]) { | |
| 66 log(new Message(errorCode, arguments, false)); | |
| 67 } | |
| 68 | |
| 63 withCurrentElement(Element element, f()) => f(); | 69 withCurrentElement(Element element, f()) => f(); |
| 64 } | 70 } |
| 65 | 71 |
| 66 Token scan(String text) => new StringScanner.fromString(text).tokenize(); | 72 Token scan(String text) => new StringScanner.fromString(text).tokenize(); |
| 67 | 73 |
| 68 Node parseBodyCode(String text, Function parseMethod, | 74 Node parseBodyCode(String text, Function parseMethod, |
| 69 {DiagnosticListener diagnosticHandler}) { | 75 {DiagnosticListener diagnosticHandler}) { |
| 70 Token tokens = scan(text); | 76 Token tokens = scan(text); |
| 71 if (diagnosticHandler == null) diagnosticHandler = new LoggerCanceler(); | 77 if (diagnosticHandler == null) diagnosticHandler = new LoggerCanceler(); |
| 72 Uri uri = new Uri(scheme: "source"); | 78 Uri uri = new Uri(scheme: "source"); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 ElementListener listener = new ElementListener(compiler, unit, () => id++); | 126 ElementListener listener = new ElementListener(compiler, unit, () => id++); |
| 121 PartialParser parser = new PartialParser(listener); | 127 PartialParser parser = new PartialParser(listener); |
| 122 compiler.withCurrentElement(unit, () => parser.parseUnit(tokens)); | 128 compiler.withCurrentElement(unit, () => parser.parseUnit(tokens)); |
| 123 return unit.localMembers; | 129 return unit.localMembers; |
| 124 } | 130 } |
| 125 | 131 |
| 126 NodeList fullParseUnit(String source, {DiagnosticListener diagnosticHandler}) { | 132 NodeList fullParseUnit(String source, {DiagnosticListener diagnosticHandler}) { |
| 127 return parseBodyCode(source, (parser, tokens) => parser.parseUnit(tokens), | 133 return parseBodyCode(source, (parser, tokens) => parser.parseUnit(tokens), |
| 128 diagnosticHandler: diagnosticHandler); | 134 diagnosticHandler: diagnosticHandler); |
| 129 } | 135 } |
| OLD | NEW |