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

Side by Side Diff: dart/frog/tests/leg/src/mock_compiler.dart

Issue 9373043: Move helpers and interceptors to own library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add TODO Created 8 years, 10 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
« no previous file with comments | « dart/frog/leg/typechecker.dart ('k') | dart/tests/language/language-leg.status » ('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('mock_compiler'); 5 #library('mock_compiler');
6 6
7 #import("../../../../lib/uri/uri.dart"); 7 #import("../../../../lib/uri/uri.dart");
8 8
9 #import("../../../leg/leg.dart"); 9 #import("../../../leg/leg.dart");
10 #import("../../../leg/elements/elements.dart"); 10 #import("../../../leg/elements/elements.dart");
11 #import("../../../leg/tree/tree.dart"); 11 #import("../../../leg/tree/tree.dart");
12 #import("../../../leg/util/util.dart"); 12 #import("../../../leg/util/util.dart");
13 #import("parser_helper.dart"); 13 #import("parser_helper.dart");
14 14
15 class WarningMessage { 15 class WarningMessage {
16 Node node; 16 Node node;
17 Message message; 17 Message message;
18 WarningMessage(this.node, this.message); 18 WarningMessage(this.node, this.message);
19 19
20 toString() => message.toString(); 20 toString() => message.toString();
21 } 21 }
22 22
23 final String DEFAULT_CORELIB = @''' 23 final String DEFAULT_HELPERLIB = @'''
24 lt() {} add(var a, var b) {} sub() {} mul() {} div() {} tdiv() {} mod() {} 24 lt() {} add(var a, var b) {} sub() {} mul() {} div() {} tdiv() {} mod() {}
25 neg() {} shl() {} shr() {} eq() {} le() {} gt() {} ge() {} 25 neg() {} shl() {} shr() {} eq() {} le() {} gt() {} ge() {}
26 or() {} and() {} not() {} print(var obj) {} eqNull(a) {} eqq() {} 26 or() {} and() {} not() {} eqNull(a) {} eqq() {}
27 guard$array(x) { return x; } 27 guard$array(x) { return x; }
28 guard$num(x) { return x; } 28 guard$num(x) { return x; }
29 guard$string(x) { return x; } 29 guard$string(x) { return x; }
30 guard$stringOrArray(x) { return x; } 30 guard$stringOrArray(x) { return x; }
31 builtin$add$1(receiver, value) {} 31 builtin$add$1(receiver, value) {}
32 builtin$get$length(var receiver) {} 32 builtin$get$length(var receiver) {}
33 builtin$filter$1(receiver, predicate) {} 33 builtin$filter$1(receiver, predicate) {}
34 builtin$removeLast$0(receiver) {} 34 builtin$removeLast$0(receiver) {}
35 index(a, index) {} 35 index(a, index) {}
36 indexSet(a, index, value) {} 36 indexSet(a, index, value) {}''';
37
38 final String DEFAULT_CORELIB = @'''
39 print(var obj) {}
37 class int {} 40 class int {}
38 class double {} 41 class double {}
39 class bool {} 42 class bool {}
40 class String {} 43 class String {}
41 class Object {}'''; 44 class Object {}''';
42 45
43 class MockCompiler extends Compiler { 46 class MockCompiler extends Compiler {
44 List<WarningMessage> warnings; 47 List<WarningMessage> warnings;
45 List<WarningMessage> errors; 48 List<WarningMessage> errors;
46 Node parsedTree; 49 Node parsedTree;
47 WorkItem lastBailoutWork; 50 WorkItem lastBailoutWork;
48 51
49 MockCompiler([String coreSource = DEFAULT_CORELIB]) 52 MockCompiler([String coreSource = DEFAULT_CORELIB,
53 String helperSource = DEFAULT_HELPERLIB])
50 : warnings = [], errors = [], super() { 54 : warnings = [], errors = [], super() {
51 Uri uri = new Uri(scheme: "source"); 55 Uri uri = new Uri(scheme: "source");
52 var script = new Script(uri, new MockFile(coreSource)); 56 var script = new Script(uri, new MockFile(coreSource));
53 coreLibrary = new LibraryElement(script); 57 coreLibrary = new LibraryElement(script);
54 parseScript(coreSource, coreLibrary); 58 parseScript(coreSource, coreLibrary);
59 script = new Script(uri, new MockFile(helperSource));
60 jsHelperLibrary = new LibraryElement(script);
61 parseScript(helperSource, jsHelperLibrary);
55 mainApp = mockLibrary(this, ""); 62 mainApp = mockLibrary(this, "");
56 } 63 }
57 64
58 void reportWarning(Node node, var message) { 65 void reportWarning(Node node, var message) {
59 warnings.add(new WarningMessage(node, message.message)); 66 warnings.add(new WarningMessage(node, message.message));
60 } 67 }
61 68
62 void reportError(Node node, var message) { 69 void reportError(Node node, var message) {
63 errors.add(new WarningMessage(node, message.message)); 70 errors.add(new WarningMessage(node, message.message));
64 } 71 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 112
106 void enqueue(WorkItem work) { 113 void enqueue(WorkItem work) {
107 if (work.isBailoutVersion()) lastBailoutWork = work; 114 if (work.isBailoutVersion()) lastBailoutWork = work;
108 super.enqueue(work); 115 super.enqueue(work);
109 } 116 }
110 117
111 resolve(ClassElement element) { 118 resolve(ClassElement element) {
112 return resolver.resolveType(element); 119 return resolver.resolveType(element);
113 } 120 }
114 121
115 void scanCoreLibrary() { 122 void scanBuiltinLibraries() {
116 // Do nothing. The mock core library is already handled in the constructor. 123 // Do nothing. The mock core library is already handled in the constructor.
117 } 124 }
118 } 125 }
119 126
120 void compareWarningKinds(String text, expectedWarnings, foundWarnings) { 127 void compareWarningKinds(String text, expectedWarnings, foundWarnings) {
121 var fail = (message) => Expect.fail('$text: $message'); 128 var fail = (message) => Expect.fail('$text: $message');
122 Iterator<MessageKind> expected = expectedWarnings.iterator(); 129 Iterator<MessageKind> expected = expectedWarnings.iterator();
123 Iterator<WarningMessage> found = foundWarnings.iterator(); 130 Iterator<WarningMessage> found = foundWarnings.iterator();
124 while (expected.hasNext() && found.hasNext()) { 131 while (expected.hasNext() && found.hasNext()) {
125 Expect.equals(expected.next(), found.next().message.kind); 132 Expect.equals(expected.next(), found.next().message.kind);
(...skipping 21 matching lines...) Expand all
147 }); 154 });
148 } 155 }
149 } 156 }
150 157
151 LibraryElement mockLibrary(Compiler compiler, String source) { 158 LibraryElement mockLibrary(Compiler compiler, String source) {
152 Uri uri = new Uri(scheme: "source"); 159 Uri uri = new Uri(scheme: "source");
153 var library = new LibraryElement(new Script(uri, new MockFile(source))); 160 var library = new LibraryElement(new Script(uri, new MockFile(source)));
154 importLibrary(library, compiler.coreLibrary, compiler); 161 importLibrary(library, compiler.coreLibrary, compiler);
155 return library; 162 return library;
156 } 163 }
OLDNEW
« no previous file with comments | « dart/frog/leg/typechecker.dart ('k') | dart/tests/language/language-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698