| 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("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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 final Map<String, SourceFile> sourceFiles; | 74 final Map<String, SourceFile> sourceFiles; |
| 75 Node parsedTree; | 75 Node parsedTree; |
| 76 | 76 |
| 77 MockCompiler([String coreSource = DEFAULT_CORELIB, | 77 MockCompiler([String coreSource = DEFAULT_CORELIB, |
| 78 String helperSource = DEFAULT_HELPERLIB, | 78 String helperSource = DEFAULT_HELPERLIB, |
| 79 String interceptorsSource = DEFAULT_INTERCEPTORSLIB, | 79 String interceptorsSource = DEFAULT_INTERCEPTORSLIB, |
| 80 bool enableTypeAssertions = false]) | 80 bool enableTypeAssertions = false]) |
| 81 : warnings = [], errors = [], | 81 : warnings = [], errors = [], |
| 82 sourceFiles = new Map<String, SourceFile>(), | 82 sourceFiles = new Map<String, SourceFile>(), |
| 83 super(enableTypeAssertions: enableTypeAssertions) { | 83 super(enableTypeAssertions: enableTypeAssertions) { |
| 84 Uri uri = new Uri.fromComponents(scheme: "source"); | 84 coreLibrary = createLibrary("core", coreSource); |
| 85 var script = new Script(uri, new MockFile(coreSource)); | |
| 86 coreLibrary = new LibraryElement(script); | |
| 87 parseScript(coreSource, coreLibrary); | |
| 88 // We need to set the assert method to avoid calls with a 'null' | 85 // We need to set the assert method to avoid calls with a 'null' |
| 89 // target being interpreted as a call to assert. | 86 // target being interpreted as a call to assert. |
| 90 | 87 jsHelperLibrary = createLibrary("helper", helperSource); |
| 91 script = new Script(uri, new MockFile(helperSource)); | |
| 92 jsHelperLibrary = new LibraryElement(script); | |
| 93 parseScript(helperSource, jsHelperLibrary); | |
| 94 assertMethod = jsHelperLibrary.find(buildSourceString('assert')); | 88 assertMethod = jsHelperLibrary.find(buildSourceString('assert')); |
| 95 | 89 interceptorsLibrary = createLibrary("interceptors", interceptorsSource); |
| 96 script = new Script(uri, new MockFile(interceptorsSource)); | |
| 97 interceptorsLibrary = new LibraryElement(script); | |
| 98 parseScript(interceptorsSource, interceptorsLibrary); | |
| 99 | 90 |
| 100 mainApp = mockLibrary(this, ""); | 91 mainApp = mockLibrary(this, ""); |
| 101 initializeSpecialClasses(); | 92 initializeSpecialClasses(); |
| 102 } | 93 } |
| 103 | 94 |
| 95 /** |
| 96 * Used internally to create a library from a source text. The created library |
| 97 * is fixed to export its top-level declarations. |
| 98 */ |
| 99 LibraryElement createLibrary(String name, String source) { |
| 100 Uri uri = new Uri.fromComponents(scheme: "source", path: name); |
| 101 var script = new Script(uri, new MockFile(source)); |
| 102 var library = new LibraryElement(script); |
| 103 parseScript(source, library); |
| 104 library.setExports(library.localScope.getValues()); |
| 105 return library; |
| 106 } |
| 107 |
| 104 void reportWarning(Node node, var message) { | 108 void reportWarning(Node node, var message) { |
| 105 warnings.add(new WarningMessage(node, message.message)); | 109 warnings.add(new WarningMessage(node, message.message)); |
| 106 } | 110 } |
| 107 | 111 |
| 108 void reportError(Node node, var message) { | 112 void reportError(Node node, var message) { |
| 109 if (message is String && message.startsWith("no #library tag found in")) { | 113 if (message is String && message.startsWith("no #library tag found in")) { |
| 110 // TODO(ahe): Fix the MockCompiler to not have this problem. | 114 // TODO(ahe): Fix the MockCompiler to not have this problem. |
| 111 return; | 115 return; |
| 112 } | 116 } |
| 113 errors.add(new WarningMessage(node, message.message)); | 117 errors.add(new WarningMessage(node, message.message)); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 }); | 219 }); |
| 216 } | 220 } |
| 217 } | 221 } |
| 218 | 222 |
| 219 LibraryElement mockLibrary(Compiler compiler, String source) { | 223 LibraryElement mockLibrary(Compiler compiler, String source) { |
| 220 Uri uri = new Uri.fromComponents(scheme: "source"); | 224 Uri uri = new Uri.fromComponents(scheme: "source"); |
| 221 var library = new LibraryElement(new Script(uri, new MockFile(source))); | 225 var library = new LibraryElement(new Script(uri, new MockFile(source))); |
| 222 importLibrary(library, compiler.coreLibrary, compiler); | 226 importLibrary(library, compiler.coreLibrary, compiler); |
| 223 return library; | 227 return library; |
| 224 } | 228 } |
| OLD | NEW |