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

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

Issue 10836355: Make sure that libraries loaded from dart:core gets dart:core implicitly loaded. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix mock compiler Created 8 years, 4 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 | « tests/compiler/dart2js/compiler_helper.dart ('k') | no next file » | 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("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/leg.dart"); 10 #import("../../../lib/compiler/implementation/leg.dart");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 add$1(receiver, value) {} 44 add$1(receiver, value) {}
45 get$length(receiver) {} 45 get$length(receiver) {}
46 filter(receiver, predicate) {} 46 filter(receiver, predicate) {}
47 removeLast(receiver) {} 47 removeLast(receiver) {}
48 iterator(receiver) {} 48 iterator(receiver) {}
49 next(receiver) {} 49 next(receiver) {}
50 hasNext(receiver) {}'''; 50 hasNext(receiver) {}''';
51 51
52 final String DEFAULT_CORELIB = @''' 52 final String DEFAULT_CORELIB = @'''
53 print(var obj) {} 53 print(var obj) {}
54 assert(x) {}
54 interface int extends num {} 55 interface int extends num {}
55 interface double extends num {} 56 interface double extends num {}
56 class bool {} 57 class bool {}
57 class String {} 58 class String {}
58 class Object {} 59 class Object {}
59 interface num {} 60 interface num {}
60 class Function {} 61 class Function {}
61 class List {} 62 class List {}
62 class Closure {} 63 class Closure {}
63 class Null {} 64 class Null {}
64 class Dynamic {}'''; 65 class Dynamic {}''';
65 66
66 class MockCompiler extends Compiler { 67 class MockCompiler extends Compiler {
67 List<WarningMessage> warnings; 68 List<WarningMessage> warnings;
68 List<WarningMessage> errors; 69 List<WarningMessage> errors;
69 final Map<String, SourceFile> sourceFiles; 70 final Map<String, SourceFile> sourceFiles;
70 Node parsedTree; 71 Node parsedTree;
71 72
72 MockCompiler([String coreSource = DEFAULT_CORELIB, 73 MockCompiler([String coreSource = DEFAULT_CORELIB,
73 String helperSource = DEFAULT_HELPERLIB, 74 String helperSource = DEFAULT_HELPERLIB,
74 String interceptorsSource = DEFAULT_INTERCEPTORSLIB]) 75 String interceptorsSource = DEFAULT_INTERCEPTORSLIB])
75 : warnings = [], errors = [], 76 : warnings = [], errors = [],
76 sourceFiles = new Map<String, SourceFile>(), 77 sourceFiles = new Map<String, SourceFile>(),
77 super() { 78 super() {
78 Uri uri = new Uri.fromComponents(scheme: "source"); 79 Uri uri = new Uri.fromComponents(scheme: "source");
79 var script = new Script(uri, new MockFile(coreSource)); 80 var script = new Script(uri, new MockFile(coreSource));
80 coreLibrary = new LibraryElement(script); 81 coreLibrary = new LibraryElement(script);
81 parseScript(coreSource, coreLibrary); 82 parseScript(coreSource, coreLibrary);
83 // We need to set the assert method to avoid calls with a 'null'
84 // target being interpreted as a call to assert.
85 assertMethod = coreLibrary.find(buildSourceString('assert'));
82 86
83 script = new Script(uri, new MockFile(helperSource)); 87 script = new Script(uri, new MockFile(helperSource));
84 jsHelperLibrary = new LibraryElement(script); 88 jsHelperLibrary = new LibraryElement(script);
85 parseScript(helperSource, jsHelperLibrary); 89 parseScript(helperSource, jsHelperLibrary);
86 90
87 script = new Script(uri, new MockFile(interceptorsSource)); 91 script = new Script(uri, new MockFile(interceptorsSource));
88 interceptorsLibrary = new LibraryElement(script); 92 interceptorsLibrary = new LibraryElement(script);
89 parseScript(interceptorsSource, interceptorsLibrary); 93 parseScript(interceptorsSource, interceptorsLibrary);
90 94
91 scanner.importLibrary(jsHelperLibrary, coreLibrary, null);
92 scanner.importLibrary(interceptorsLibrary, coreLibrary, null);
93 mainApp = mockLibrary(this, ""); 95 mainApp = mockLibrary(this, "");
94 initializeSpecialClasses(); 96 initializeSpecialClasses();
95 } 97 }
96 98
97 void reportWarning(Node node, var message) { 99 void reportWarning(Node node, var message) {
98 warnings.add(new WarningMessage(node, message.message)); 100 warnings.add(new WarningMessage(node, message.message));
99 } 101 }
100 102
101 void reportError(Node node, var message) { 103 void reportError(Node node, var message) {
102 if (message is String && message.startsWith("no #library tag found in")) { 104 if (message is String && message.startsWith("no #library tag found in")) {
103 // TODO(ahe): Fix the MockCompiler to not have this problem. 105 // TODO(ahe): Fix the MockCompiler to not have this problem.
104 return; 106 return;
105 } 107 }
106 errors.add(new WarningMessage(node, message.message)); 108 errors.add(new WarningMessage(node, message.message));
107 } 109 }
108 110
109 void reportMessage(SourceSpan span, var message, api.Diagnostic kind) { 111 void reportMessage(SourceSpan span, var message, api.Diagnostic kind) {
110 var diagnostic = new WarningMessage(null, message.message); 112 var diagnostic = new WarningMessage(null, message.message);
111 if (kind === api.Diagnostic.ERROR) { 113 if (kind === api.Diagnostic.ERROR) {
112 errors.add(diagnostic); 114 errors.add(diagnostic);
113 } else { 115 } else {
114 warnings.add(diagnostic); 116 warnings.add(diagnostic);
115 } 117 }
116 } 118 }
117 119
118 void reportDiagnostic(SourceSpan span, String message, var kind) { 120 void reportDiagnostic(SourceSpan span, String message, var kind) {
119 print(message); 121 print(message);
120 } 122 }
121 123
124 bool get compilationFailed => !errors.isEmpty();
125
122 void clearWarnings() { 126 void clearWarnings() {
123 warnings = []; 127 warnings = [];
124 } 128 }
125 129
126 void clearErrors() { 130 void clearErrors() {
127 errors = []; 131 errors = [];
128 } 132 }
129 133
130 TreeElementMapping resolveStatement(String text) { 134 TreeElementMapping resolveStatement(String text) {
131 parsedTree = parseStatement(text); 135 parsedTree = parseStatement(text);
(...skipping 24 matching lines...) Expand all
156 } 160 }
157 161
158 void scanBuiltinLibraries() { 162 void scanBuiltinLibraries() {
159 // Do nothing. The mock core library is already handled in the constructor. 163 // Do nothing. The mock core library is already handled in the constructor.
160 } 164 }
161 165
162 LibraryElement scanBuiltinLibrary(String name) { 166 LibraryElement scanBuiltinLibrary(String name) {
163 // Do nothing. The mock core library is already handled in the constructor. 167 // Do nothing. The mock core library is already handled in the constructor.
164 } 168 }
165 169
170 void importCoreLibrary(LibraryElement library) {
171 scanner.importLibrary(library, coreLibrary, null);
172 }
173
166 // The mock library doesn't need any patches. 174 // The mock library doesn't need any patches.
167 Uri resolvePatchUri(String dartLibraryName) => null; 175 Uri resolvePatchUri(String dartLibraryName) => null;
168 176
169 Script readScript(Uri uri, [ScriptTag node]) { 177 Script readScript(Uri uri, [ScriptTag node]) {
170 SourceFile sourceFile = sourceFiles[uri.toString()]; 178 SourceFile sourceFile = sourceFiles[uri.toString()];
171 if (sourceFile === null) throw new IllegalArgumentException(uri); 179 if (sourceFile === null) throw new IllegalArgumentException(uri);
172 return new Script(uri, sourceFile); 180 return new Script(uri, sourceFile);
173 } 181 }
174 } 182 }
175 183
(...skipping 26 matching lines...) Expand all
202 }); 210 });
203 } 211 }
204 } 212 }
205 213
206 LibraryElement mockLibrary(Compiler compiler, String source) { 214 LibraryElement mockLibrary(Compiler compiler, String source) {
207 Uri uri = new Uri.fromComponents(scheme: "source"); 215 Uri uri = new Uri.fromComponents(scheme: "source");
208 var library = new LibraryElement(new Script(uri, new MockFile(source))); 216 var library = new LibraryElement(new Script(uri, new MockFile(source)));
209 importLibrary(library, compiler.coreLibrary, compiler); 217 importLibrary(library, compiler.coreLibrary, compiler);
210 return library; 218 return library;
211 } 219 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/compiler_helper.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698