| 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 class WorkItem { | 5 class WorkItem { |
| 6 final Element element; | 6 final Element element; |
| 7 TreeElements resolutionTree; | 7 TreeElements resolutionTree; |
| 8 Function run; | 8 Function run; |
| 9 Map<int, BailoutInfo> bailouts = null; | 9 Map<int, BailoutInfo> bailouts = null; |
| 10 bool allowSpeculativeOptimization = true; | 10 bool allowSpeculativeOptimization = true; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 CompilerTask measuredTask; | 49 CompilerTask measuredTask; |
| 50 Element _currentElement; | 50 Element _currentElement; |
| 51 LibraryElement coreLibrary; | 51 LibraryElement coreLibrary; |
| 52 LibraryElement coreImplLibrary; | 52 LibraryElement coreImplLibrary; |
| 53 LibraryElement isolateLibrary; | 53 LibraryElement isolateLibrary; |
| 54 LibraryElement jsHelperLibrary; | 54 LibraryElement jsHelperLibrary; |
| 55 LibraryElement mainApp; | 55 LibraryElement mainApp; |
| 56 ClassElement objectClass; | 56 ClassElement objectClass; |
| 57 ClassElement closureClass; | 57 ClassElement closureClass; |
| 58 ClassElement dynamicClass; |
| 59 ClassElement boolClass; |
| 60 ClassElement numClass; |
| 61 ClassElement intClass; |
| 62 ClassElement doubleClass; |
| 63 ClassElement stringClass; |
| 64 ClassElement functionClass; |
| 65 ClassElement nullClass; |
| 58 | 66 |
| 59 Element get currentElement() => _currentElement; | 67 Element get currentElement() => _currentElement; |
| 60 withCurrentElement(Element element, f()) { | 68 withCurrentElement(Element element, f()) { |
| 61 Element old = currentElement; | 69 Element old = currentElement; |
| 62 _currentElement = element; | 70 _currentElement = element; |
| 63 try { | 71 try { |
| 64 return f(); | 72 return f(); |
| 65 } finally { | 73 } finally { |
| 66 _currentElement = old; | 74 _currentElement = old; |
| 67 } | 75 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 78 SsaOptimizerTask optimizer; | 86 SsaOptimizerTask optimizer; |
| 79 SsaCodeGeneratorTask generator; | 87 SsaCodeGeneratorTask generator; |
| 80 CodeEmitterTask emitter; | 88 CodeEmitterTask emitter; |
| 81 ConstantHandler constantHandler; | 89 ConstantHandler constantHandler; |
| 82 EnqueueTask enqueuer; | 90 EnqueueTask enqueuer; |
| 83 | 91 |
| 84 static final SourceString MAIN = const SourceString('main'); | 92 static final SourceString MAIN = const SourceString('main'); |
| 85 static final SourceString NO_SUCH_METHOD = const SourceString('noSuchMethod'); | 93 static final SourceString NO_SUCH_METHOD = const SourceString('noSuchMethod'); |
| 86 static final SourceString NO_SUCH_METHOD_EXCEPTION = | 94 static final SourceString NO_SUCH_METHOD_EXCEPTION = |
| 87 const SourceString('NoSuchMethodException'); | 95 const SourceString('NoSuchMethodException'); |
| 88 static final SourceString OBJECT = const SourceString('Object'); | |
| 89 static final SourceString START_ROOT_ISOLATE = | 96 static final SourceString START_ROOT_ISOLATE = |
| 90 const SourceString('startRootIsolate'); | 97 const SourceString('startRootIsolate'); |
| 91 static final SourceString CLOSURE = const SourceString('Closure'); | |
| 92 bool enabledNoSuchMethod = false; | 98 bool enabledNoSuchMethod = false; |
| 93 | 99 |
| 94 Compiler.withCurrentDirectory(String this.currentDirectory, | 100 Compiler.withCurrentDirectory(String this.currentDirectory, |
| 95 [this.tracer = const Tracer()]) | 101 [this.tracer = const Tracer()]) |
| 96 : types = new Types(), | 102 : types = new Types(), |
| 97 universe = new Universe(), | 103 universe = new Universe(), |
| 98 worklist = new Queue<WorkItem>() { | 104 worklist = new Queue<WorkItem>() { |
| 99 namer = new Namer(this); | 105 namer = new Namer(this); |
| 100 constantHandler = new ConstantHandler(this); | 106 constantHandler = new ConstantHandler(this); |
| 101 scanner = new ScannerTask(this); | 107 scanner = new ScannerTask(this); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 186 |
| 181 void enableIsolateSupport(LibraryElement element) { | 187 void enableIsolateSupport(LibraryElement element) { |
| 182 isolateLibrary = element; | 188 isolateLibrary = element; |
| 183 addToWorkList(element.find(START_ROOT_ISOLATE)); | 189 addToWorkList(element.find(START_ROOT_ISOLATE)); |
| 184 } | 190 } |
| 185 | 191 |
| 186 void onLibraryLoaded(LibraryElement library, Uri uri) { | 192 void onLibraryLoaded(LibraryElement library, Uri uri) { |
| 187 if (uri.toString() == 'dart:isolate') { | 193 if (uri.toString() == 'dart:isolate') { |
| 188 enableIsolateSupport(library); | 194 enableIsolateSupport(library); |
| 189 } | 195 } |
| 196 if (dynamicClass !== null) { |
| 197 // When loading the built-in libraries, dynamicClass is null. We |
| 198 // take advantage of this as core and coreimpl import js_helper |
| 199 // and see Dynamic this way. |
| 200 withCurrentElement(dynamicClass, () { |
| 201 library.define(dynamicClass, this); |
| 202 }); |
| 203 } |
| 190 } | 204 } |
| 191 | 205 |
| 192 abstract LibraryElement scanBuiltinLibrary(String filename); | 206 abstract LibraryElement scanBuiltinLibrary(String filename); |
| 193 | 207 |
| 208 void initializeSpecialClasses() { |
| 209 objectClass = coreLibrary.find(const SourceString('Object')); |
| 210 boolClass = coreLibrary.find(const SourceString('bool')); |
| 211 numClass = coreLibrary.find(const SourceString('num')); |
| 212 intClass = coreLibrary.find(const SourceString('int')); |
| 213 doubleClass = coreLibrary.find(const SourceString('double')); |
| 214 stringClass = coreLibrary.find(const SourceString('String')); |
| 215 functionClass = coreLibrary.find(const SourceString('Function')); |
| 216 closureClass = jsHelperLibrary.find(const SourceString('Closure')); |
| 217 dynamicClass = jsHelperLibrary.find(const SourceString('Dynamic')); |
| 218 nullClass = jsHelperLibrary.find(const SourceString('Null')); |
| 219 } |
| 220 |
| 194 void scanBuiltinLibraries() { | 221 void scanBuiltinLibraries() { |
| 195 coreImplLibrary = scanBuiltinLibrary('coreimpl.dart'); | 222 coreImplLibrary = scanBuiltinLibrary('coreimpl.dart'); |
| 196 jsHelperLibrary = scanBuiltinLibrary('js_helper.dart'); | 223 jsHelperLibrary = scanBuiltinLibrary('js_helper.dart'); |
| 197 coreLibrary = scanBuiltinLibrary('core.dart'); | 224 coreLibrary = scanBuiltinLibrary('core.dart'); |
| 198 objectClass = coreLibrary.find(OBJECT); | 225 |
| 199 closureClass = jsHelperLibrary.find(CLOSURE); | |
| 200 // Since coreLibrary import the libraries "coreimpl", and | 226 // Since coreLibrary import the libraries "coreimpl", and |
| 201 // "js_helper", coreLibrary is null when they are being built. So | 227 // "js_helper", coreLibrary is null when they are being built. So |
| 202 // we add the implicit import of coreLibrary now. This can be | 228 // we add the implicit import of coreLibrary now. This can be |
| 203 // cleaned up when we have proper support for "dart:core" and | 229 // cleaned up when we have proper support for "dart:core" and |
| 204 // don't need to access it through the field "coreLibrary". | 230 // don't need to access it through the field "coreLibrary". |
| 205 // TODO(ahe): Clean this up as described above. | 231 // TODO(ahe): Clean this up as described above. |
| 206 scanner.importLibrary(coreImplLibrary, coreLibrary, null); | 232 scanner.importLibrary(coreImplLibrary, coreLibrary, null); |
| 207 scanner.importLibrary(jsHelperLibrary, coreLibrary, null); | 233 scanner.importLibrary(jsHelperLibrary, coreLibrary, null); |
| 208 addForeignFunctions(jsHelperLibrary); | 234 addForeignFunctions(jsHelperLibrary); |
| 209 | 235 |
| 210 universe.libraries['dart:core'] = coreLibrary; | 236 universe.libraries['dart:core'] = coreLibrary; |
| 211 universe.libraries['dart:coreimpl'] = coreImplLibrary; | 237 universe.libraries['dart:coreimpl'] = coreImplLibrary; |
| 238 |
| 239 initializeSpecialClasses(); |
| 212 } | 240 } |
| 213 | 241 |
| 214 /** Define the JS helper functions in the given library. */ | 242 /** Define the JS helper functions in the given library. */ |
| 215 void addForeignFunctions(LibraryElement library) { | 243 void addForeignFunctions(LibraryElement library) { |
| 216 library.define(new ForeignElement( | 244 library.define(new ForeignElement( |
| 217 const SourceString('JS'), library), this); | 245 const SourceString('JS'), library), this); |
| 218 library.define(new ForeignElement( | 246 library.define(new ForeignElement( |
| 219 const SourceString('UNINTERCEPTED'), library), this); | 247 const SourceString('UNINTERCEPTED'), library), this); |
| 220 library.define(new ForeignElement( | 248 library.define(new ForeignElement( |
| 221 const SourceString('JS_HAS_EQUALS'), library), this); | 249 const SourceString('JS_HAS_EQUALS'), library), this); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 } | 502 } |
| 475 } | 503 } |
| 476 | 504 |
| 477 class SourceSpan { | 505 class SourceSpan { |
| 478 final Uri uri; | 506 final Uri uri; |
| 479 final int begin; | 507 final int begin; |
| 480 final int end; | 508 final int end; |
| 481 | 509 |
| 482 const SourceSpan(this.uri, this.begin, this.end); | 510 const SourceSpan(this.uri, this.begin, this.end); |
| 483 } | 511 } |
| OLD | NEW |