| 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 dart2js.compiler_base; | 5 library dart2js.compiler_base; |
| 6 | 6 |
| 7 import 'dart:async' show | 7 import 'dart:async' show |
| 8 EventSink, | 8 EventSink, |
| 9 Future; | 9 Future; |
| 10 | 10 |
| 11 import '../compiler_new.dart' as api; | 11 import '../compiler_new.dart' as api; |
| 12 import 'cache_strategy.dart' show | 12 import 'cache_strategy.dart' show |
| 13 CacheStrategy; | 13 CacheStrategy; |
| 14 import 'closure.dart' as closureMapping show | 14 import 'closure.dart' as closureMapping show |
| 15 ClosureTask; | 15 ClosureTask; |
| 16 import 'common/backend_api.dart' show | 16 import 'common/backend_api.dart' show |
| 17 Backend; | 17 Backend; |
| 18 import 'common/codegen.dart' show | 18 import 'common/codegen.dart' show |
| 19 CodegenRegistry, | 19 CodegenRegistry, |
| 20 CodegenWorkItem; | 20 CodegenWorkItem; |
| 21 import 'common/names.dart' show |
| 22 Identifiers; |
| 21 import 'common/registry.dart' show | 23 import 'common/registry.dart' show |
| 22 Registry; | 24 Registry; |
| 23 import 'common/resolution.dart' show | 25 import 'common/resolution.dart' show |
| 24 ResolutionWorkItem; | 26 ResolutionWorkItem; |
| 25 import 'common/tasks.dart' show | 27 import 'common/tasks.dart' show |
| 26 CompilerTask, | 28 CompilerTask, |
| 27 GenericTask; | 29 GenericTask; |
| 28 import 'common/work.dart' show | 30 import 'common/work.dart' show |
| 29 WorkItem; | 31 WorkItem; |
| 30 import 'compile_time_constants.dart'; | 32 import 'compile_time_constants.dart'; |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 | 432 |
| 431 EnqueueTask enqueuer; | 433 EnqueueTask enqueuer; |
| 432 DeferredLoadTask deferredLoadTask; | 434 DeferredLoadTask deferredLoadTask; |
| 433 MirrorUsageAnalyzerTask mirrorUsageAnalyzerTask; | 435 MirrorUsageAnalyzerTask mirrorUsageAnalyzerTask; |
| 434 DumpInfoTask dumpInfoTask; | 436 DumpInfoTask dumpInfoTask; |
| 435 String buildId; | 437 String buildId; |
| 436 | 438 |
| 437 /// A customizable filter that is applied to enqueued work items. | 439 /// A customizable filter that is applied to enqueued work items. |
| 438 QueueFilter enqueuerFilter = new QueueFilter(); | 440 QueueFilter enqueuerFilter = new QueueFilter(); |
| 439 | 441 |
| 440 static const String MAIN = 'main'; | 442 final Selector symbolValidatedConstructorSelector = new Selector.call( |
| 441 static const String CALL_OPERATOR_NAME = 'call'; | 443 const PublicName('validated'), 1); |
| 442 static const String NO_SUCH_METHOD = 'noSuchMethod'; | 444 |
| 443 static const int NO_SUCH_METHOD_ARG_COUNT = 1; | |
| 444 static const String CREATE_INVOCATION_MIRROR = | 445 static const String CREATE_INVOCATION_MIRROR = |
| 445 'createInvocationMirror'; | 446 'createInvocationMirror'; |
| 446 static const String FROM_ENVIRONMENT = 'fromEnvironment'; | |
| 447 | |
| 448 static const String RUNTIME_TYPE = 'runtimeType'; | |
| 449 | 447 |
| 450 static const String UNDETERMINED_BUILD_ID = | 448 static const String UNDETERMINED_BUILD_ID = |
| 451 "build number could not be determined"; | 449 "build number could not be determined"; |
| 452 | 450 |
| 453 final Selector iteratorSelector = | |
| 454 new Selector.getter('iterator', null); | |
| 455 final Selector currentSelector = | |
| 456 new Selector.getter('current', null); | |
| 457 final Selector moveNextSelector = | |
| 458 new Selector.call('moveNext', null, 0); | |
| 459 final Selector noSuchMethodSelector = new Selector.call( | |
| 460 Compiler.NO_SUCH_METHOD, null, Compiler.NO_SUCH_METHOD_ARG_COUNT); | |
| 461 final Selector symbolValidatedConstructorSelector = new Selector.call( | |
| 462 'validated', null, 1); | |
| 463 | |
| 464 bool enabledRuntimeType = false; | 451 bool enabledRuntimeType = false; |
| 465 bool enabledFunctionApply = false; | 452 bool enabledFunctionApply = false; |
| 466 bool enabledInvokeOn = false; | 453 bool enabledInvokeOn = false; |
| 467 bool hasIsolateSupport = false; | 454 bool hasIsolateSupport = false; |
| 468 | 455 |
| 469 Stopwatch progress; | 456 Stopwatch progress; |
| 470 | 457 |
| 471 bool get shouldPrintProgress { | 458 bool get shouldPrintProgress { |
| 472 return verbose && progress.elapsedMilliseconds > 500; | 459 return verbose && progress.elapsedMilliseconds > 500; |
| 473 } | 460 } |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 mirrorSystemGetNameFunction = | 880 mirrorSystemGetNameFunction = |
| 894 cls.lookupLocalMember('getName'); | 881 cls.lookupLocalMember('getName'); |
| 895 } else if (symbolClass == cls) { | 882 } else if (symbolClass == cls) { |
| 896 symbolConstructor = cls.constructors.head; | 883 symbolConstructor = cls.constructors.head; |
| 897 } else if (symbolImplementationClass == cls) { | 884 } else if (symbolImplementationClass == cls) { |
| 898 symbolValidatedConstructor = symbolImplementationClass.lookupConstructor( | 885 symbolValidatedConstructor = symbolImplementationClass.lookupConstructor( |
| 899 symbolValidatedConstructorSelector.name); | 886 symbolValidatedConstructorSelector.name); |
| 900 } else if (mirrorsUsedClass == cls) { | 887 } else if (mirrorsUsedClass == cls) { |
| 901 mirrorsUsedConstructor = cls.constructors.head; | 888 mirrorsUsedConstructor = cls.constructors.head; |
| 902 } else if (intClass == cls) { | 889 } else if (intClass == cls) { |
| 903 intEnvironment = intClass.lookupConstructor(FROM_ENVIRONMENT); | 890 intEnvironment = intClass.lookupConstructor(Identifiers.fromEnvironment); |
| 904 } else if (stringClass == cls) { | 891 } else if (stringClass == cls) { |
| 905 stringEnvironment = | 892 stringEnvironment = |
| 906 stringClass.lookupConstructor(FROM_ENVIRONMENT); | 893 stringClass.lookupConstructor(Identifiers.fromEnvironment); |
| 907 } else if (boolClass == cls) { | 894 } else if (boolClass == cls) { |
| 908 boolEnvironment = | 895 boolEnvironment = |
| 909 boolClass.lookupConstructor(FROM_ENVIRONMENT); | 896 boolClass.lookupConstructor(Identifiers.fromEnvironment); |
| 910 } | 897 } |
| 911 } | 898 } |
| 912 | 899 |
| 913 void initializeCoreClasses() { | 900 void initializeCoreClasses() { |
| 914 final List missingCoreClasses = []; | 901 final List missingCoreClasses = []; |
| 915 ClassElement lookupCoreClass(String name) { | 902 ClassElement lookupCoreClass(String name) { |
| 916 ClassElement result = coreLibrary.find(name); | 903 ClassElement result = coreLibrary.find(name); |
| 917 if (result == null) { | 904 if (result == null) { |
| 918 missingCoreClasses.add(name); | 905 missingCoreClasses.add(name); |
| 919 } | 906 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 }); | 974 }); |
| 988 } | 975 } |
| 989 }).then((_) { | 976 }).then((_) { |
| 990 compileLoadedLibraries(); | 977 compileLoadedLibraries(); |
| 991 }); | 978 }); |
| 992 } | 979 } |
| 993 | 980 |
| 994 void computeMain() { | 981 void computeMain() { |
| 995 if (mainApp == null) return; | 982 if (mainApp == null) return; |
| 996 | 983 |
| 997 Element main = mainApp.findExported(MAIN); | 984 Element main = mainApp.findExported(Identifiers.main); |
| 998 ErroneousElement errorElement = null; | 985 ErroneousElement errorElement = null; |
| 999 if (main == null) { | 986 if (main == null) { |
| 1000 if (analyzeOnly) { | 987 if (analyzeOnly) { |
| 1001 if (!analyzeAll) { | 988 if (!analyzeAll) { |
| 1002 errorElement = new ErroneousElementX( | 989 errorElement = new ErroneousElementX( |
| 1003 MessageKind.CONSIDER_ANALYZE_ALL, {'main': MAIN}, MAIN, mainApp); | 990 MessageKind.CONSIDER_ANALYZE_ALL, {'main': Identifiers.main}, |
| 991 Identifiers.main, mainApp); |
| 1004 } | 992 } |
| 1005 } else { | 993 } else { |
| 1006 // Compilation requires a main method. | 994 // Compilation requires a main method. |
| 1007 errorElement = new ErroneousElementX( | 995 errorElement = new ErroneousElementX( |
| 1008 MessageKind.MISSING_MAIN, {'main': MAIN}, MAIN, mainApp); | 996 MessageKind.MISSING_MAIN, {'main': Identifiers.main}, |
| 997 Identifiers.main, mainApp); |
| 1009 } | 998 } |
| 1010 mainFunction = backend.helperForMissingMain(); | 999 mainFunction = backend.helperForMissingMain(); |
| 1011 } else if (main.isErroneous && main.isSynthesized) { | 1000 } else if (main.isErroneous && main.isSynthesized) { |
| 1012 if (main is ErroneousElement) { | 1001 if (main is ErroneousElement) { |
| 1013 errorElement = main; | 1002 errorElement = main; |
| 1014 } else { | 1003 } else { |
| 1015 internalError(main, 'Problem with $MAIN.'); | 1004 internalError(main, 'Problem with ${Identifiers.main}.'); |
| 1016 } | 1005 } |
| 1017 mainFunction = backend.helperForBadMain(); | 1006 mainFunction = backend.helperForBadMain(); |
| 1018 } else if (!main.isFunction) { | 1007 } else if (!main.isFunction) { |
| 1019 errorElement = new ErroneousElementX( | 1008 errorElement = new ErroneousElementX( |
| 1020 MessageKind.MAIN_NOT_A_FUNCTION, {'main': MAIN}, MAIN, main); | 1009 MessageKind.MAIN_NOT_A_FUNCTION, {'main': Identifiers.main}, |
| 1010 Identifiers.main, main); |
| 1021 mainFunction = backend.helperForBadMain(); | 1011 mainFunction = backend.helperForBadMain(); |
| 1022 } else { | 1012 } else { |
| 1023 mainFunction = main; | 1013 mainFunction = main; |
| 1024 mainFunction.computeType(this); | 1014 mainFunction.computeType(this); |
| 1025 FunctionSignature parameters = mainFunction.functionSignature; | 1015 FunctionSignature parameters = mainFunction.functionSignature; |
| 1026 if (parameters.requiredParameterCount > 2) { | 1016 if (parameters.requiredParameterCount > 2) { |
| 1027 int index = 0; | 1017 int index = 0; |
| 1028 parameters.orderedForEachParameter((Element parameter) { | 1018 parameters.orderedForEachParameter((Element parameter) { |
| 1029 if (index++ < 2) return; | 1019 if (index++ < 2) return; |
| 1030 errorElement = new ErroneousElementX( | 1020 errorElement = new ErroneousElementX( |
| 1031 MessageKind.MAIN_WITH_EXTRA_PARAMETER, {'main': MAIN}, MAIN, | 1021 MessageKind.MAIN_WITH_EXTRA_PARAMETER, {'main': Identifiers.main}, |
| 1022 Identifiers.main, |
| 1032 parameter); | 1023 parameter); |
| 1033 mainFunction = backend.helperForMainArity(); | 1024 mainFunction = backend.helperForMainArity(); |
| 1034 // Don't warn about main not being used: | 1025 // Don't warn about main not being used: |
| 1035 enqueuer.resolution.registerStaticUse(main); | 1026 enqueuer.resolution.registerStaticUse(main); |
| 1036 }); | 1027 }); |
| 1037 } | 1028 } |
| 1038 } | 1029 } |
| 1039 if (mainFunction == null) { | 1030 if (mainFunction == null) { |
| 1040 if (errorElement == null && !analyzeOnly && !analyzeAll) { | 1031 if (errorElement == null && !analyzeOnly && !analyzeAll) { |
| 1041 internalError(mainApp, "Problem with '$MAIN'."); | 1032 internalError(mainApp, "Problem with '${Identifiers.main}'."); |
| 1042 } else { | 1033 } else { |
| 1043 mainFunction = errorElement; | 1034 mainFunction = errorElement; |
| 1044 } | 1035 } |
| 1045 } | 1036 } |
| 1046 if (errorElement != null && | 1037 if (errorElement != null && |
| 1047 errorElement.isSynthesized && | 1038 errorElement.isSynthesized && |
| 1048 !mainApp.isSynthesized) { | 1039 !mainApp.isSynthesized) { |
| 1049 reportWarning( | 1040 reportWarning( |
| 1050 errorElement, errorElement.messageKind, | 1041 errorElement, errorElement.messageKind, |
| 1051 errorElement.messageArguments); | 1042 errorElement.messageArguments); |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1762 | 1753 |
| 1763 @override | 1754 @override |
| 1764 InterfaceType streamType([DartType elementType]) { | 1755 InterfaceType streamType([DartType elementType]) { |
| 1765 InterfaceType type = streamClass.computeType(compiler); | 1756 InterfaceType type = streamClass.computeType(compiler); |
| 1766 if (elementType == null) { | 1757 if (elementType == null) { |
| 1767 return streamClass.rawType; | 1758 return streamClass.rawType; |
| 1768 } | 1759 } |
| 1769 return type.createInstantiation([elementType]); | 1760 return type.createInstantiation([elementType]); |
| 1770 } | 1761 } |
| 1771 } | 1762 } |
| OLD | NEW |