Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(720)

Side by Side Diff: tests/compiler/dart2js/parser_helper.dart

Issue 27510003: Scanner for UTF-8 byte arrays (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fixes compiler tests Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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";
11 import "../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.da rt"; 11 import "../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.da rt";
12 import "../../../sdk/lib/_internal/compiler/implementation/source_file.dart"; 12 import "../../../sdk/lib/_internal/compiler/implementation/source_file.dart";
13 import "../../../sdk/lib/_internal/compiler/implementation/util/util.dart"; 13 import "../../../sdk/lib/_internal/compiler/implementation/util/util.dart";
14 14
15 import "../../../sdk/lib/_internal/compiler/implementation/elements/modelx.dart" 15 import "../../../sdk/lib/_internal/compiler/implementation/elements/modelx.dart"
16 show CompilationUnitElementX, 16 show CompilationUnitElementX,
17 LibraryElementX; 17 LibraryElementX;
18 18
19 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart" 19 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart";
20 hide SourceString;
21 20
22 export "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart" 21 export "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart"
23 show DiagnosticListener; 22 show DiagnosticListener;
24 // TODO(ahe): We should have token library to export instead. 23 // TODO(ahe): We should have token library to export instead.
25 export "../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.da rt"; 24 export "../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.da rt";
26 25
27 class LoggerCanceler implements DiagnosticListener { 26 class LoggerCanceler implements DiagnosticListener {
28 void cancel(String reason, {node, token, instruction, element}) { 27 void cancel(String reason, {node, token, instruction, element}) {
29 throw new CompilerCancelledException(reason); 28 throw new CompilerCancelledException(reason);
30 } 29 }
(...skipping 22 matching lines...) Expand all
53 log(new Message(errorCode, arguments, false)); 52 log(new Message(errorCode, arguments, false));
54 } 53 }
55 54
56 void reportInfo(Spannable node, MessageKind errorCode, [Map arguments]) { 55 void reportInfo(Spannable node, MessageKind errorCode, [Map arguments]) {
57 log(new Message(errorCode, arguments, false)); 56 log(new Message(errorCode, arguments, false));
58 } 57 }
59 58
60 withCurrentElement(Element element, f()) => f(); 59 withCurrentElement(Element element, f()) => f();
61 } 60 }
62 61
63 Token scan(String text) => new StringScanner(text).tokenize(); 62 Token scan(String text) => new StringScanner.fromString(text).tokenize();
64 63
65 Node parseBodyCode(String text, Function parseMethod, 64 Node parseBodyCode(String text, Function parseMethod,
66 {DiagnosticListener diagnosticHandler}) { 65 {DiagnosticListener diagnosticHandler}) {
67 Token tokens = scan(text); 66 Token tokens = scan(text);
68 if (diagnosticHandler == null) diagnosticHandler = new LoggerCanceler(); 67 if (diagnosticHandler == null) diagnosticHandler = new LoggerCanceler();
69 Script script = 68 Script script =
70 new Script( 69 new Script(
71 new Uri(scheme: "source"), 70 new Uri(scheme: "source"),
72 new MockFile(text)); 71 new MockFile(text));
73 LibraryElement library = new LibraryElementX(script); 72 LibraryElement library = new LibraryElementX(script);
(...skipping 17 matching lines...) Expand all
91 Expect.isNotNull(element); 90 Expect.isNotNull(element);
92 Expect.equals(ElementKind.FUNCTION, element.kind); 91 Expect.equals(ElementKind.FUNCTION, element.kind);
93 return element.parseNode(compiler); 92 return element.parseNode(compiler);
94 } 93 }
95 94
96 Node parseMember(String text, {DiagnosticListener diagnosticHandler}) { 95 Node parseMember(String text, {DiagnosticListener diagnosticHandler}) {
97 return parseBodyCode(text, (parser, tokens) => parser.parseMember(tokens), 96 return parseBodyCode(text, (parser, tokens) => parser.parseMember(tokens),
98 diagnosticHandler: diagnosticHandler); 97 diagnosticHandler: diagnosticHandler);
99 } 98 }
100 99
101 class MockFile extends SourceFile { 100 class MockFile extends StringSourceFile {
102 MockFile(text) 101 MockFile(text)
103 : super('<string>', text); 102 : super('<string>', text);
104 } 103 }
105 104
106 var sourceCounter = 0; 105 var sourceCounter = 0;
107 106
108 Link<Element> parseUnit(String text, Compiler compiler, 107 Link<Element> parseUnit(String text, Compiler compiler,
109 LibraryElement library, 108 LibraryElement library,
110 [void registerSource(Uri uri, String source)]) { 109 [void registerSource(Uri uri, String source)]) {
111 Token tokens = scan(text); 110 Token tokens = scan(text);
112 Uri uri = new Uri(scheme: "source", path: '${++sourceCounter}'); 111 Uri uri = new Uri(scheme: "source", path: '${++sourceCounter}');
113 if (registerSource != null) { 112 if (registerSource != null) {
114 registerSource(uri, text); 113 registerSource(uri, text);
115 } 114 }
116 var script = new Script(uri, new MockFile(text)); 115 var script = new Script(uri, new MockFile(text));
117 var unit = new CompilationUnitElementX(script, library); 116 var unit = new CompilationUnitElementX(script, library);
118 int id = 0; 117 int id = 0;
119 ElementListener listener = new ElementListener(compiler, unit, () => id++); 118 ElementListener listener = new ElementListener(compiler, unit, () => id++);
120 PartialParser parser = new PartialParser(listener); 119 PartialParser parser = new PartialParser(listener);
121 compiler.withCurrentElement(unit, () => parser.parseUnit(tokens)); 120 compiler.withCurrentElement(unit, () => parser.parseUnit(tokens));
122 return unit.localMembers; 121 return unit.localMembers;
123 } 122 }
124 123
125 NodeList fullParseUnit(String source, {DiagnosticListener diagnosticHandler}) { 124 NodeList fullParseUnit(String source, {DiagnosticListener diagnosticHandler}) {
126 return parseBodyCode(source, (parser, tokens) => parser.parseUnit(tokens), 125 return parseBodyCode(source, (parser, tokens) => parser.parseUnit(tokens),
127 diagnosticHandler: diagnosticHandler); 126 diagnosticHandler: diagnosticHandler);
128 } 127 }
129
130 // TODO(ahe): We define this method to avoid having to import
131 // the scanner in the tests. We should move SourceString to another
132 // location instead.
133 SourceString buildSourceString(String name) {
134 return new SourceString(name);
135 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698