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

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

Issue 11367007: Tests owed. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « no previous file | dart/tests/compiler/dart2js/parser_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "dart:uri"; 7 import "dart:uri";
8 8
9 import "../../../lib/compiler/implementation/elements/elements.dart"; 9 import "../../../lib/compiler/implementation/elements/elements.dart";
10 import "../../../lib/compiler/implementation/tree/tree.dart"; 10 import "../../../lib/compiler/implementation/tree/tree.dart";
11 import '../../../lib/compiler/implementation/scanner/scannerlib.dart'; 11 import "../../../lib/compiler/implementation/scanner/scannerlib.dart";
12 import "../../../lib/compiler/implementation/dart2jslib.dart" hide SourceString; 12 import "../../../lib/compiler/implementation/dart2jslib.dart" hide SourceString;
13 import "../../../lib/compiler/implementation/source_file.dart"; 13 import "../../../lib/compiler/implementation/source_file.dart";
14 import "../../../lib/compiler/implementation/util/util.dart"; 14 import "../../../lib/compiler/implementation/util/util.dart";
15 15
16 export "../../../lib/compiler/implementation/dart2jslib.dart"
17 show DiagnosticListener;
18 // TODO(ahe): We should have token library to export instead.
19 export "../../../lib/compiler/implementation/scanner/scannerlib.dart";
20
16 class LoggerCanceler implements DiagnosticListener { 21 class LoggerCanceler implements DiagnosticListener {
17 void cancel(String reason, {node, token, instruction, element}) { 22 void cancel(String reason, {node, token, instruction, element}) {
18 throw new CompilerCancelledException(reason); 23 throw new CompilerCancelledException(reason);
19 } 24 }
20 25
21 void log(message) { 26 void log(message) {
22 print(message); 27 print(message);
23 } 28 }
24 } 29 }
25 30
26 Token scan(String text) => new StringScanner(text).tokenize(); 31 Token scan(String text) => new StringScanner(text).tokenize();
27 32
28 Node parseBodyCode(String text, Function parseMethod) { 33 Node parseBodyCode(String text, Function parseMethod, {DiagnosticListener lc}) {
Johnni Winther 2012/10/31 12:24:22 Bad name. I can see from the code that it is an ab
ahe 2012/10/31 14:00:09 Done.
29 Token tokens = scan(text); 34 Token tokens = scan(text);
30 LoggerCanceler lc = new LoggerCanceler(); 35 if (lc == null) lc = new LoggerCanceler();
31 Script script = 36 Script script =
32 new Script( 37 new Script(
33 new Uri.fromComponents(scheme: "source"), 38 new Uri.fromComponents(scheme: "source"),
34 new MockFile(text)); 39 new MockFile(text));
35 LibraryElement library = new LibraryElement(script); 40 LibraryElement library = new LibraryElement(script);
36 library.canUseNative = true; 41 library.canUseNative = true;
37 NodeListener listener = new NodeListener(lc, library.entryCompilationUnit); 42 NodeListener listener = new NodeListener(lc, library.entryCompilationUnit);
38 Parser parser = new Parser(listener); 43 Parser parser = new Parser(listener);
39 Token endToken = parseMethod(parser, tokens); 44 Token endToken = parseMethod(parser, tokens);
40 assert(endToken.kind == EOF_TOKEN); 45 assert(endToken.kind == EOF_TOKEN);
41 Node node = listener.popNode(); 46 Node node = listener.popNode();
42 Expect.isNotNull(node); 47 Expect.isNotNull(node);
43 Expect.isTrue(listener.nodes.isEmpty, 'Not empty: ${listener.nodes}'); 48 Expect.isTrue(listener.nodes.isEmpty, 'Not empty: ${listener.nodes}');
44 return node; 49 return node;
45 } 50 }
46 51
47 Node parseStatement(String text) => 52 Node parseStatement(String text) =>
48 parseBodyCode(text, (parser, tokens) => parser.parseStatement(tokens)); 53 parseBodyCode(text, (parser, tokens) => parser.parseStatement(tokens));
49 54
50 Node parseFunction(String text, Compiler compiler) { 55 Node parseFunction(String text, Compiler compiler) {
51 Element element = parseUnit(text, compiler, compiler.mainApp).head; 56 Element element = parseUnit(text, compiler, compiler.mainApp).head;
52 Expect.isNotNull(element); 57 Expect.isNotNull(element);
53 Expect.equals(ElementKind.FUNCTION, element.kind); 58 Expect.equals(ElementKind.FUNCTION, element.kind);
54 return element.parseNode(compiler); 59 return element.parseNode(compiler);
55 } 60 }
56 61
57 Node parseMember(String text) => 62 Node parseMember(String text, {DiagnosticListener lc}) =>
Johnni Winther 2012/10/31 12:24:22 Also bad name here.
ahe 2012/10/31 14:00:09 Done.
58 parseBodyCode(text, (parser, tokens) => parser.parseMember(tokens)); 63 parseBodyCode(text, (parser, tokens) => parser.parseMember(tokens), lc: lc);
59 64
60 class MockFile extends SourceFile { 65 class MockFile extends SourceFile {
61 MockFile(text) 66 MockFile(text)
62 : super('<string>', text); 67 : super('<string>', text);
63 } 68 }
64 69
65 Link<Element> parseUnit(String text, Compiler compiler, 70 Link<Element> parseUnit(String text, Compiler compiler,
66 LibraryElement library) { 71 LibraryElement library) {
67 Token tokens = scan(text); 72 Token tokens = scan(text);
68 Uri uri = new Uri.fromComponents(scheme: "source"); 73 Uri uri = new Uri.fromComponents(scheme: "source");
69 var script = new Script(uri, new MockFile(text)); 74 var script = new Script(uri, new MockFile(text));
70 var unit = new CompilationUnitElement(script, library); 75 var unit = new CompilationUnitElement(script, library);
71 int id = 0; 76 int id = 0;
72 ElementListener listener = new ElementListener(compiler, unit, () => id++); 77 ElementListener listener = new ElementListener(compiler, unit, () => id++);
73 PartialParser parser = new PartialParser(listener); 78 PartialParser parser = new PartialParser(listener);
74 compiler.withCurrentElement(unit, () => parser.parseUnit(tokens)); 79 compiler.withCurrentElement(unit, () => parser.parseUnit(tokens));
75 return unit.localMembers; 80 return unit.localMembers;
76 } 81 }
77 82
78 NodeList fullParseUnit(String source) { 83 NodeList fullParseUnit(String source) {
79 return parseBodyCode(source, (parser, tokens) => parser.parseUnit(tokens)); 84 return parseBodyCode(source, (parser, tokens) => parser.parseUnit(tokens));
80 } 85 }
81 86
82 // TODO(ahe): We define this method to avoid having to import 87 // TODO(ahe): We define this method to avoid having to import
83 // the scanner in the tests. We should move SourceString to another 88 // the scanner in the tests. We should move SourceString to another
84 // location instead. 89 // location instead.
85 SourceString buildSourceString(String name) { 90 SourceString buildSourceString(String name) {
86 return new SourceString(name); 91 return new SourceString(name);
87 } 92 }
OLDNEW
« no previous file with comments | « no previous file | dart/tests/compiler/dart2js/parser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698