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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * If true, print a warning for each method that was resolved, but not | 8 * If true, print a warning for each method that was resolved, but not |
| 9 * compiled. | 9 * compiled. |
| 10 */ | 10 */ |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 622 static final Uri DART_NATIVE_TYPED_DATA = | 622 static final Uri DART_NATIVE_TYPED_DATA = |
| 623 new Uri(scheme: 'dart', path: '_native_typed_data'); | 623 new Uri(scheme: 'dart', path: '_native_typed_data'); |
| 624 static final Uri DART_INTERNAL = new Uri(scheme: 'dart', path: '_internal'); | 624 static final Uri DART_INTERNAL = new Uri(scheme: 'dart', path: '_internal'); |
| 625 static final Uri DART_ASYNC = new Uri(scheme: 'dart', path: 'async'); | 625 static final Uri DART_ASYNC = new Uri(scheme: 'dart', path: 'async'); |
| 626 | 626 |
| 627 final Stopwatch totalCompileTime = new Stopwatch(); | 627 final Stopwatch totalCompileTime = new Stopwatch(); |
| 628 int nextFreeClassId = 0; | 628 int nextFreeClassId = 0; |
| 629 World world; | 629 World world; |
| 630 String assembledCode; | 630 String assembledCode; |
| 631 Types types; | 631 Types types; |
| 632 _CompilerCoreTypes _coreTypes; | |
| 632 | 633 |
| 633 final CacheStrategy cacheStrategy; | 634 final CacheStrategy cacheStrategy; |
| 634 | 635 |
| 635 /** | 636 /** |
| 636 * Map from token to the first preceeding comment token. | 637 * Map from token to the first preceeding comment token. |
| 637 */ | 638 */ |
| 638 final TokenMap commentMap = new TokenMap(); | 639 final TokenMap commentMap = new TokenMap(); |
| 639 | 640 |
| 640 /** | 641 /** |
| 641 * Records global dependencies, that is, dependencies that don't | 642 * Records global dependencies, that is, dependencies that don't |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 763 | 764 |
| 764 LibraryElement mainApp; | 765 LibraryElement mainApp; |
| 765 FunctionElement mainFunction; | 766 FunctionElement mainFunction; |
| 766 | 767 |
| 767 /// Initialized when dart:mirrors is loaded. | 768 /// Initialized when dart:mirrors is loaded. |
| 768 LibraryElement mirrorsLibrary; | 769 LibraryElement mirrorsLibrary; |
| 769 | 770 |
| 770 /// Initialized when dart:typed_data is loaded. | 771 /// Initialized when dart:typed_data is loaded. |
| 771 LibraryElement typedDataLibrary; | 772 LibraryElement typedDataLibrary; |
| 772 | 773 |
| 773 ClassElement objectClass; | 774 ClassElement get objectClass => _coreTypes.objectClass; |
| 774 ClassElement boolClass; | 775 ClassElement get boolClass => _coreTypes.boolClass; |
| 775 ClassElement numClass; | 776 ClassElement get numClass => _coreTypes.numClass; |
| 776 ClassElement intClass; | 777 ClassElement get intClass => _coreTypes.intClass; |
| 777 ClassElement doubleClass; | 778 ClassElement get doubleClass => _coreTypes.doubleClass; |
| 778 ClassElement stringClass; | 779 ClassElement get stringClass => _coreTypes.stringClass; |
| 779 ClassElement functionClass; | 780 ClassElement get functionClass => _coreTypes.functionClass; |
| 780 ClassElement nullClass; | 781 ClassElement get nullClass => _coreTypes.nullClass; |
| 781 ClassElement listClass; | 782 ClassElement get listClass => _coreTypes.listClass; |
| 782 ClassElement typeClass; | 783 ClassElement get typeClass => _coreTypes.typeClass; |
| 783 ClassElement mapClass; | 784 ClassElement get mapClass => _coreTypes.mapClass; |
| 784 ClassElement symbolClass; | 785 ClassElement get symbolClass => _coreTypes.symbolClass; |
| 785 ClassElement stackTraceClass; | 786 ClassElement get stackTraceClass => _coreTypes.stackTraceClass; |
| 787 ClassElement get futureClass => _coreTypes.futureClass; | |
| 788 ClassElement get iterableClass => _coreTypes.iterableClass; | |
| 789 ClassElement get streamClass => _coreTypes.streamClass; | |
| 790 | |
| 791 CoreTypes get coreTypes => _coreTypes; | |
| 792 | |
| 786 ClassElement typedDataClass; | 793 ClassElement typedDataClass; |
| 787 ClassElement futureClass; | |
| 788 ClassElement iterableClass; | |
| 789 ClassElement streamClass; | |
| 790 | 794 |
| 791 /// The constant for the [proxy] variable defined in dart:core. | 795 /// The constant for the [proxy] variable defined in dart:core. |
| 792 ConstantValue proxyConstant; | 796 ConstantValue proxyConstant; |
| 793 | 797 |
| 794 // TODO(johnniwinther): Move this to the JavaScriptBackend. | 798 // TODO(johnniwinther): Move this to the JavaScriptBackend. |
| 795 /// The constant for the [patch] variable defined in dart:_js_helper. | 799 /// The constant for the [patch] variable defined in dart:_js_helper. |
| 796 ConstantValue patchConstant; | 800 ConstantValue patchConstant; |
| 797 | 801 |
| 798 // TODO(johnniwinther): Move this to the JavaScriptBackend. | 802 // TODO(johnniwinther): Move this to the JavaScriptBackend. |
| 799 ClassElement nativeAnnotationClass; | 803 ClassElement nativeAnnotationClass; |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1001 cacheStrategy = new CacheStrategy(hasIncrementalSupport), | 1005 cacheStrategy = new CacheStrategy(hasIncrementalSupport), |
| 1002 this.outputProvider = (outputProvider == null) | 1006 this.outputProvider = (outputProvider == null) |
| 1003 ? NullSink.outputProvider | 1007 ? NullSink.outputProvider |
| 1004 : outputProvider { | 1008 : outputProvider { |
| 1005 if (hasIncrementalSupport) { | 1009 if (hasIncrementalSupport) { |
| 1006 // TODO(ahe): This is too much. Any method from platform and package | 1010 // TODO(ahe): This is too much. Any method from platform and package |
| 1007 // libraries can be inlined. | 1011 // libraries can be inlined. |
| 1008 disableInlining = true; | 1012 disableInlining = true; |
| 1009 } | 1013 } |
| 1010 world = new World(this); | 1014 world = new World(this); |
| 1015 _coreTypes = new _CompilerCoreTypes(this); | |
| 1011 types = new Types(this); | 1016 types = new Types(this); |
| 1012 tracer = new Tracer(this, this.outputProvider); | 1017 tracer = new Tracer(this, this.outputProvider); |
| 1013 | 1018 |
| 1014 if (verbose) { | 1019 if (verbose) { |
| 1015 progress = new Stopwatch()..start(); | 1020 progress = new Stopwatch()..start(); |
| 1016 } | 1021 } |
| 1017 | 1022 |
| 1018 // TODO(johnniwinther): Separate the dependency tracking from the enqueueing | 1023 // TODO(johnniwinther): Separate the dependency tracking from the enqueueing |
| 1019 // for global dependencies. | 1024 // for global dependencies. |
| 1020 globalDependencies = | 1025 globalDependencies = |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1216 if (uri == DART_CORE) { | 1221 if (uri == DART_CORE) { |
| 1217 initializeCoreClasses(); | 1222 initializeCoreClasses(); |
| 1218 identicalFunction = coreLibrary.find('identical'); | 1223 identicalFunction = coreLibrary.find('identical'); |
| 1219 } else if (uri == DART_INTERNAL) { | 1224 } else if (uri == DART_INTERNAL) { |
| 1220 symbolImplementationClass = findRequiredElement(library, 'Symbol'); | 1225 symbolImplementationClass = findRequiredElement(library, 'Symbol'); |
| 1221 } else if (uri == DART_MIRRORS) { | 1226 } else if (uri == DART_MIRRORS) { |
| 1222 mirrorSystemClass = findRequiredElement(library, 'MirrorSystem'); | 1227 mirrorSystemClass = findRequiredElement(library, 'MirrorSystem'); |
| 1223 mirrorsUsedClass = findRequiredElement(library, 'MirrorsUsed'); | 1228 mirrorsUsedClass = findRequiredElement(library, 'MirrorsUsed'); |
| 1224 } else if (uri == DART_ASYNC) { | 1229 } else if (uri == DART_ASYNC) { |
| 1225 deferredLibraryClass = findRequiredElement(library, 'DeferredLibrary'); | 1230 deferredLibraryClass = findRequiredElement(library, 'DeferredLibrary'); |
| 1226 futureClass = findRequiredElement(library, 'Future'); | 1231 _coreTypes.futureClass = findRequiredElement(library, 'Future'); |
| 1227 streamClass = findRequiredElement(library, 'Stream'); | 1232 _coreTypes.streamClass = findRequiredElement(library, 'Stream'); |
| 1228 } else if (uri == DART_NATIVE_TYPED_DATA) { | 1233 } else if (uri == DART_NATIVE_TYPED_DATA) { |
| 1229 typedDataClass = findRequiredElement(library, 'NativeTypedData'); | 1234 typedDataClass = findRequiredElement(library, 'NativeTypedData'); |
| 1230 } else if (uri == js_backend.JavaScriptBackend.DART_JS_HELPER) { | 1235 } else if (uri == js_backend.JavaScriptBackend.DART_JS_HELPER) { |
| 1231 nativeAnnotationClass = findRequiredElement(library, 'Native'); | 1236 nativeAnnotationClass = findRequiredElement(library, 'Native'); |
| 1232 } | 1237 } |
| 1233 return backend.onLibraryScanned(library, loader); | 1238 return backend.onLibraryScanned(library, loader); |
| 1234 } | 1239 } |
| 1235 | 1240 |
| 1236 /// This method is called when all new libraries loaded through | 1241 /// This method is called when all new libraries loaded through |
| 1237 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports | 1242 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1360 | 1365 |
| 1361 void initializeCoreClasses() { | 1366 void initializeCoreClasses() { |
| 1362 final List missingCoreClasses = []; | 1367 final List missingCoreClasses = []; |
| 1363 ClassElement lookupCoreClass(String name) { | 1368 ClassElement lookupCoreClass(String name) { |
| 1364 ClassElement result = coreLibrary.find(name); | 1369 ClassElement result = coreLibrary.find(name); |
| 1365 if (result == null) { | 1370 if (result == null) { |
| 1366 missingCoreClasses.add(name); | 1371 missingCoreClasses.add(name); |
| 1367 } | 1372 } |
| 1368 return result; | 1373 return result; |
| 1369 } | 1374 } |
| 1370 objectClass = lookupCoreClass('Object'); | 1375 _coreTypes.objectClass = lookupCoreClass('Object'); |
|
karlklose
2014/12/16 09:04:38
Would it be possible to construct the whole CoreTy
Johnni Winther
2014/12/16 10:21:01
Adding a TODO.
| |
| 1371 boolClass = lookupCoreClass('bool'); | 1376 _coreTypes.boolClass = lookupCoreClass('bool'); |
| 1372 numClass = lookupCoreClass('num'); | 1377 _coreTypes.numClass = lookupCoreClass('num'); |
| 1373 intClass = lookupCoreClass('int'); | 1378 _coreTypes.intClass = lookupCoreClass('int'); |
| 1374 doubleClass = lookupCoreClass('double'); | 1379 _coreTypes.doubleClass = lookupCoreClass('double'); |
| 1375 stringClass = lookupCoreClass('String'); | 1380 _coreTypes.stringClass = lookupCoreClass('String'); |
| 1376 functionClass = lookupCoreClass('Function'); | 1381 _coreTypes.functionClass = lookupCoreClass('Function'); |
| 1377 listClass = lookupCoreClass('List'); | 1382 _coreTypes.listClass = lookupCoreClass('List'); |
| 1378 typeClass = lookupCoreClass('Type'); | 1383 _coreTypes.typeClass = lookupCoreClass('Type'); |
| 1379 mapClass = lookupCoreClass('Map'); | 1384 _coreTypes.mapClass = lookupCoreClass('Map'); |
| 1380 nullClass = lookupCoreClass('Null'); | 1385 _coreTypes.nullClass = lookupCoreClass('Null'); |
| 1381 stackTraceClass = lookupCoreClass('StackTrace'); | 1386 _coreTypes.stackTraceClass = lookupCoreClass('StackTrace'); |
| 1382 iterableClass = lookupCoreClass('Iterable'); | 1387 _coreTypes.iterableClass = lookupCoreClass('Iterable'); |
| 1383 symbolClass = lookupCoreClass('Symbol'); | 1388 _coreTypes.symbolClass = lookupCoreClass('Symbol'); |
| 1384 if (!missingCoreClasses.isEmpty) { | 1389 if (!missingCoreClasses.isEmpty) { |
| 1385 internalError(coreLibrary, | 1390 internalError(coreLibrary, |
| 1386 'dart:core library does not contain required classes: ' | 1391 'dart:core library does not contain required classes: ' |
| 1387 '$missingCoreClasses'); | 1392 '$missingCoreClasses'); |
| 1388 } | 1393 } |
| 1389 } | 1394 } |
| 1390 | 1395 |
| 1391 Element _unnamedListConstructor; | 1396 Element _unnamedListConstructor; |
| 1392 Element get unnamedListConstructor { | 1397 Element get unnamedListConstructor { |
| 1393 if (_unnamedListConstructor != null) return _unnamedListConstructor; | 1398 if (_unnamedListConstructor != null) return _unnamedListConstructor; |
| (...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2340 } | 2345 } |
| 2341 | 2346 |
| 2342 /// A code location that contains any uri. | 2347 /// A code location that contains any uri. |
| 2343 class AnyLocation implements CodeLocation { | 2348 class AnyLocation implements CodeLocation { |
| 2344 const AnyLocation(); | 2349 const AnyLocation(); |
| 2345 | 2350 |
| 2346 bool inSameLocation(Uri uri) => true; | 2351 bool inSameLocation(Uri uri) => true; |
| 2347 | 2352 |
| 2348 String relativize(Uri baseUri) => '$baseUri'; | 2353 String relativize(Uri baseUri) => '$baseUri'; |
| 2349 } | 2354 } |
| 2355 | |
| 2356 class _CompilerCoreTypes implements CoreTypes { | |
| 2357 final Compiler compiler; | |
| 2358 | |
| 2359 ClassElementX objectClass; | |
| 2360 ClassElementX boolClass; | |
| 2361 ClassElementX numClass; | |
| 2362 ClassElementX intClass; | |
| 2363 ClassElementX doubleClass; | |
| 2364 ClassElementX stringClass; | |
| 2365 ClassElementX functionClass; | |
| 2366 ClassElementX nullClass; | |
| 2367 ClassElementX listClass; | |
| 2368 ClassElementX typeClass; | |
| 2369 ClassElementX mapClass; | |
| 2370 ClassElementX symbolClass; | |
| 2371 ClassElementX stackTraceClass; | |
| 2372 ClassElementX futureClass; | |
| 2373 ClassElementX iterableClass; | |
| 2374 ClassElementX streamClass; | |
| 2375 | |
| 2376 _CompilerCoreTypes(this.compiler); | |
| 2377 | |
| 2378 @override | |
| 2379 InterfaceType get boolType => boolClass.computeType(compiler); | |
| 2380 | |
| 2381 @override | |
| 2382 InterfaceType get doubleType => doubleClass.computeType(compiler); | |
| 2383 | |
| 2384 @override | |
| 2385 InterfaceType get functionType => functionClass.computeType(compiler); | |
| 2386 | |
| 2387 @override | |
| 2388 InterfaceType get intType => intClass.computeType(compiler); | |
| 2389 | |
| 2390 @override | |
| 2391 InterfaceType listType([DartType elementType = const DynamicType()]) { | |
| 2392 return listClass.computeType(compiler).createInstantiation([elementType]); | |
| 2393 } | |
| 2394 | |
| 2395 @override | |
| 2396 InterfaceType mapType([DartType keyType = const DynamicType(), | |
| 2397 DartType valueType = const DynamicType()]) { | |
| 2398 return mapClass.computeType(compiler) | |
| 2399 .createInstantiation([keyType, valueType]); | |
| 2400 } | |
| 2401 | |
| 2402 @override | |
| 2403 InterfaceType get nullType => nullClass.computeType(compiler); | |
| 2404 | |
| 2405 @override | |
| 2406 InterfaceType get numType => numClass.computeType(compiler); | |
| 2407 | |
| 2408 @override | |
| 2409 InterfaceType get stringType => stringClass.computeType(compiler); | |
| 2410 } | |
| OLD | NEW |