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 compiler_helper; | 5 library compiler_helper; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
9 | 9 |
10 import 'package:compiler/compiler_new.dart'; | 10 import 'package:compiler/compiler_new.dart'; |
11 | 11 |
| 12 import 'package:compiler/src/common_elements.dart'; |
| 13 |
12 import 'package:compiler/src/elements/elements.dart'; | 14 import 'package:compiler/src/elements/elements.dart'; |
13 export 'package:compiler/src/elements/elements.dart'; | 15 export 'package:compiler/src/elements/elements.dart'; |
14 | 16 |
15 import 'package:compiler/src/js_backend/js_backend.dart' as js; | 17 import 'package:compiler/src/js_backend/js_backend.dart' as js; |
16 import 'package:compiler/src/js_backend/element_strategy.dart' | 18 import 'package:compiler/src/js_backend/element_strategy.dart' |
17 show ElementCodegenWorkItem; | 19 show ElementCodegenWorkItem; |
18 | 20 |
19 import 'package:compiler/src/commandline_options.dart'; | 21 import 'package:compiler/src/commandline_options.dart'; |
20 import 'package:compiler/src/common/codegen.dart'; | 22 import 'package:compiler/src/common/codegen.dart'; |
21 import 'package:compiler/src/common/resolution.dart'; | 23 import 'package:compiler/src/common/resolution.dart'; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 enableTypeAssertions: enableTypeAssertions, | 69 enableTypeAssertions: enableTypeAssertions, |
68 // Type inference does not run when manually | 70 // Type inference does not run when manually |
69 // compiling a method. | 71 // compiling a method. |
70 disableTypeInference: true, | 72 disableTypeInference: true, |
71 enableMinification: minify, | 73 enableMinification: minify, |
72 disableInlining: disableInlining, | 74 disableInlining: disableInlining, |
73 trustJSInteropTypeAnnotations: trustJSInteropTypeAnnotations, | 75 trustJSInteropTypeAnnotations: trustJSInteropTypeAnnotations, |
74 outputProvider: outputCollector); | 76 outputProvider: outputCollector); |
75 await compiler.init(); | 77 await compiler.init(); |
76 compiler.parseScript(code); | 78 compiler.parseScript(code); |
77 LibraryElement mainApp = compiler.mainApp; | 79 ElementEnvironment elementEnvironment = |
78 MethodElement element = mainApp.find(entry); | 80 compiler.frontendStrategy.elementEnvironment; |
| 81 MethodElement element = compiler.mainApp.find(entry); |
79 if (element == null) return null; | 82 if (element == null) return null; |
80 compiler.phase = Compiler.PHASE_RESOLVING; | 83 compiler.phase = Compiler.PHASE_RESOLVING; |
81 compiler.processQueue( | 84 compiler.processQueue(elementEnvironment, compiler.enqueuer.resolution, |
82 compiler.frontendStrategy.elementEnvironment, | 85 element, compiler.libraryLoader.libraries); |
83 compiler.enqueuer.resolution, | |
84 element, | |
85 compiler.libraryLoader.libraries); | |
86 ResolutionWorkItem resolutionWork = | 86 ResolutionWorkItem resolutionWork = |
87 new ResolutionWorkItem(compiler.resolution, element); | 87 new ResolutionWorkItem(compiler.resolution, element); |
88 resolutionWork.run(); | 88 resolutionWork.run(); |
89 ClosedWorld closedWorld = compiler.closeResolution().closedWorld; | 89 ClosedWorld closedWorld = compiler.closeResolution(element).closedWorld; |
90 CodegenWorkItem work = | 90 CodegenWorkItem work = |
91 new ElementCodegenWorkItem(compiler.backend, closedWorld, element); | 91 new ElementCodegenWorkItem(compiler.backend, closedWorld, element); |
92 compiler.phase = Compiler.PHASE_COMPILING; | 92 compiler.phase = Compiler.PHASE_COMPILING; |
93 work.run(); | 93 work.run(); |
94 js.JavaScriptBackend backend = compiler.backend; | 94 js.JavaScriptBackend backend = compiler.backend; |
95 String generated = backend.getGeneratedCode(element); | 95 String generated = backend.getGeneratedCode(element); |
96 if (check != null) { | 96 if (check != null) { |
97 check(generated); | 97 check(generated); |
98 } | 98 } |
99 return returnAll ? outputCollector.getOutput('', OutputType.js) : generated; | 99 return returnAll ? outputCollector.getOutput('', OutputType.js) : generated; |
(...skipping 22 matching lines...) Expand all Loading... |
122 } else { | 122 } else { |
123 source = {'main.dart': code}; | 123 source = {'main.dart': code}; |
124 } | 124 } |
125 | 125 |
126 CompilationResult result = await runCompiler( | 126 CompilationResult result = await runCompiler( |
127 memorySourceFiles: source, | 127 memorySourceFiles: source, |
128 options: options, | 128 options: options, |
129 outputProvider: outputCollector); | 129 outputProvider: outputCollector); |
130 Expect.isTrue(result.isSuccess); | 130 Expect.isTrue(result.isSuccess); |
131 Compiler compiler = result.compiler; | 131 Compiler compiler = result.compiler; |
132 LibraryElement mainApp = compiler.mainApp; | 132 LibraryElement mainApp = |
| 133 compiler.frontendStrategy.elementEnvironment.mainLibrary; |
133 Element element = mainApp.find(entry); | 134 Element element = mainApp.find(entry); |
134 js.JavaScriptBackend backend = compiler.backend; | 135 js.JavaScriptBackend backend = compiler.backend; |
135 String generated = backend.getGeneratedCode(element); | 136 String generated = backend.getGeneratedCode(element); |
136 if (check != null) { | 137 if (check != null) { |
137 check(generated); | 138 check(generated); |
138 } | 139 } |
139 return returnAll ? outputCollector.getOutput('', OutputType.js) : generated; | 140 return returnAll ? outputCollector.getOutput('', OutputType.js) : generated; |
140 } | 141 } |
141 } | 142 } |
142 | 143 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 if (path == 'main.dart') return; | 193 if (path == 'main.dart') return; |
193 compiler.registerSource(base.resolve(path), code); | 194 compiler.registerSource(base.resolve(path), code); |
194 }); | 195 }); |
195 | 196 |
196 return compiler.run(mainUri).then((_) { | 197 return compiler.run(mainUri).then((_) { |
197 return check(compiler); | 198 return check(compiler); |
198 }); | 199 }); |
199 } | 200 } |
200 | 201 |
201 Element findElement(compiler, String name, [Uri library]) { | 202 Element findElement(compiler, String name, [Uri library]) { |
202 LibraryElement lib = compiler.mainApp; | 203 LibraryElement lib = compiler.frontendStrategy.elementEnvironment.mainLibrary; |
203 if (library != null) { | 204 if (library != null) { |
204 lib = compiler.libraryLoader.lookupLibrary(library); | 205 lib = compiler.libraryLoader.lookupLibrary(library); |
205 Expect.isNotNull(lib, 'Could not locate library $library.'); | 206 Expect.isNotNull(lib, 'Could not locate library $library.'); |
206 } | 207 } |
207 var element = lib.find(name); | 208 var element = lib.find(name); |
208 Expect.isNotNull(element, 'Could not locate $name.'); | 209 Expect.isNotNull(element, 'Could not locate $name.'); |
209 return element; | 210 return element; |
210 } | 211 } |
211 | 212 |
212 String anyIdentifier = "[a-zA-Z][a-zA-Z0-9]*"; | 213 String anyIdentifier = "[a-zA-Z][a-zA-Z0-9]*"; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 } | 302 } |
302 } | 303 } |
303 | 304 |
304 return checker; | 305 return checker; |
305 } | 306 } |
306 | 307 |
307 RegExp _directivePattern = new RegExp( | 308 RegExp _directivePattern = new RegExp( |
308 // \1 \2 \3 | 309 // \1 \2 \3 |
309 r'''// *(present|absent): *(?:"([^"]*)"|'([^'']*)')''', | 310 r'''// *(present|absent): *(?:"([^"]*)"|'([^'']*)')''', |
310 multiLine: true); | 311 multiLine: true); |
OLD | NEW |