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 mock_compiler; | 5 library mock_compiler; |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:collection'; | 9 import 'dart:collection'; |
| 10 | 10 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 interceptorsLibrary = createLibrary("interceptors", interceptorsSource); | 249 interceptorsLibrary = createLibrary("interceptors", interceptorsSource); |
| 250 isolateHelperLibrary = createLibrary("isolate_helper", isolateHelperSource); | 250 isolateHelperLibrary = createLibrary("isolate_helper", isolateHelperSource); |
| 251 | 251 |
| 252 // Set up the library imports. | 252 // Set up the library imports. |
| 253 importHelperLibrary(coreLibrary); | 253 importHelperLibrary(coreLibrary); |
| 254 libraryLoader.importLibrary(jsHelperLibrary, coreLibrary, null); | 254 libraryLoader.importLibrary(jsHelperLibrary, coreLibrary, null); |
| 255 libraryLoader.importLibrary(foreignLibrary, coreLibrary, null); | 255 libraryLoader.importLibrary(foreignLibrary, coreLibrary, null); |
| 256 libraryLoader.importLibrary(interceptorsLibrary, coreLibrary, null); | 256 libraryLoader.importLibrary(interceptorsLibrary, coreLibrary, null); |
| 257 libraryLoader.importLibrary(isolateHelperLibrary, coreLibrary, null); | 257 libraryLoader.importLibrary(isolateHelperLibrary, coreLibrary, null); |
| 258 | 258 |
| 259 assertMethod = jsHelperLibrary.find(buildSourceString('assertHelper')); | 259 assertMethod = jsHelperLibrary.find('assertHelper'); |
| 260 identicalFunction = coreLibrary.find(buildSourceString('identical')); | 260 identicalFunction = coreLibrary.find('identical'); |
| 261 | 261 |
| 262 mainApp = mockLibrary(this, ""); | 262 mainApp = mockLibrary(this, ""); |
| 263 initializeSpecialClasses(); | 263 initializeSpecialClasses(); |
| 264 // We need to make sure the Object class is resolved. When registering a | 264 // We need to make sure the Object class is resolved. When registering a |
| 265 // dynamic invocation the ArgumentTypesRegistry eventually iterates over | 265 // dynamic invocation the ArgumentTypesRegistry eventually iterates over |
| 266 // the interfaces of the Object class which would be 'null' if the class | 266 // the interfaces of the Object class which would be 'null' if the class |
| 267 // wasn't resolved. | 267 // wasn't resolved. |
| 268 objectClass.ensureResolved(this); | 268 objectClass.ensureResolved(this); |
| 269 | 269 |
| 270 // Our unit tests check code generation output that is affected by | 270 // Our unit tests check code generation output that is affected by |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 if (visitor.scope is LibraryScope) { | 379 if (visitor.scope is LibraryScope) { |
| 380 visitor.scope = new MethodScope(visitor.scope, element); | 380 visitor.scope = new MethodScope(visitor.scope, element); |
| 381 } | 381 } |
| 382 visitor.visit(tree); | 382 visitor.visit(tree); |
| 383 visitor.scope = new LibraryScope(element.getLibrary()); | 383 visitor.scope = new LibraryScope(element.getLibrary()); |
| 384 return visitor.mapping; | 384 return visitor.mapping; |
| 385 } | 385 } |
| 386 | 386 |
| 387 resolverVisitor() { | 387 resolverVisitor() { |
| 388 Element mockElement = | 388 Element mockElement = |
| 389 new ElementX(buildSourceString(''), ElementKind.FUNCTION, | 389 new ElementX('', ElementKind.FUNCTION, |
| 390 mainApp.entryCompilationUnit); | 390 mainApp.entryCompilationUnit); |
|
ngeoffray
2013/10/18 10:19:37
Fits in one line?
lukas
2013/10/24 16:48:36
Done.
| |
| 391 ResolverVisitor visitor = | 391 ResolverVisitor visitor = |
| 392 new ResolverVisitor(this, mockElement, | 392 new ResolverVisitor(this, mockElement, |
| 393 new CollectingTreeElements(mockElement)); | 393 new CollectingTreeElements(mockElement)); |
| 394 visitor.scope = new MethodScope(visitor.scope, mockElement); | 394 visitor.scope = new MethodScope(visitor.scope, mockElement); |
| 395 return visitor; | 395 return visitor; |
| 396 } | 396 } |
| 397 | 397 |
| 398 parseScript(String text, [LibraryElement library]) { | 398 parseScript(String text, [LibraryElement library]) { |
| 399 if (library == null) library = mainApp; | 399 if (library == null) library = mainApp; |
| 400 parseUnit(text, this, library, registerSource); | 400 parseUnit(text, this, library, registerSource); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 490 | 490 |
| 491 void registerMainApp(LibraryElement mainApp) { | 491 void registerMainApp(LibraryElement mainApp) { |
| 492 // Do nothing. | 492 // Do nothing. |
| 493 } | 493 } |
| 494 } | 494 } |
| 495 | 495 |
| 496 api.DiagnosticHandler createHandler(MockCompiler compiler, String text) { | 496 api.DiagnosticHandler createHandler(MockCompiler compiler, String text) { |
| 497 return (uri, int begin, int end, String message, kind) { | 497 return (uri, int begin, int end, String message, kind) { |
| 498 SourceFile sourceFile; | 498 SourceFile sourceFile; |
| 499 if (uri == null) { | 499 if (uri == null) { |
| 500 sourceFile = new SourceFile('analysis', text); | 500 sourceFile = new StringSourceFile('analysis', text); |
| 501 } else { | 501 } else { |
| 502 sourceFile = compiler.sourceFiles[uri.toString()]; | 502 sourceFile = compiler.sourceFiles[uri.toString()]; |
| 503 } | 503 } |
| 504 if (sourceFile != null && begin != null && end != null) { | 504 if (sourceFile != null && begin != null && end != null) { |
| 505 print(sourceFile.getLocationMessage(message, begin, end, true, (x) => x)); | 505 print(sourceFile.getLocationMessage(message, begin, end, true, (x) => x)); |
| 506 } else { | 506 } else { |
| 507 print(message); | 507 print(message); |
| 508 } | 508 } |
| 509 }; | 509 }; |
| 510 } | 510 } |
| OLD | NEW |