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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 final Tracer tracer; | 409 final Tracer tracer; |
410 | 410 |
411 CompilerTask measuredTask; | 411 CompilerTask measuredTask; |
412 Element _currentElement; | 412 Element _currentElement; |
413 LibraryElement coreLibrary; | 413 LibraryElement coreLibrary; |
414 LibraryElement isolateLibrary; | 414 LibraryElement isolateLibrary; |
415 LibraryElement isolateHelperLibrary; | 415 LibraryElement isolateHelperLibrary; |
416 LibraryElement jsHelperLibrary; | 416 LibraryElement jsHelperLibrary; |
417 LibraryElement interceptorsLibrary; | 417 LibraryElement interceptorsLibrary; |
418 LibraryElement foreignLibrary; | 418 LibraryElement foreignLibrary; |
| 419 |
419 LibraryElement mainApp; | 420 LibraryElement mainApp; |
| 421 FunctionElement mainFunction; |
420 | 422 |
421 /// Initialized when dart:mirrors is loaded. | 423 /// Initialized when dart:mirrors is loaded. |
422 LibraryElement mirrorsLibrary; | 424 LibraryElement mirrorsLibrary; |
423 | 425 |
424 /// Initialized when dart:typed_data is loaded. | 426 /// Initialized when dart:typed_data is loaded. |
425 LibraryElement typedDataLibrary; | 427 LibraryElement typedDataLibrary; |
426 | 428 |
427 ClassElement objectClass; | 429 ClassElement objectClass; |
428 ClassElement closureClass; | 430 ClassElement closureClass; |
429 ClassElement boundClosureClass; | 431 ClassElement boundClosureClass; |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 } | 1020 } |
1019 }).then((_) { | 1021 }).then((_) { |
1020 compileLoadedLibraries(); | 1022 compileLoadedLibraries(); |
1021 }); | 1023 }); |
1022 } | 1024 } |
1023 | 1025 |
1024 /// Performs the compilation when all libraries have been loaded. | 1026 /// Performs the compilation when all libraries have been loaded. |
1025 void compileLoadedLibraries() { | 1027 void compileLoadedLibraries() { |
1026 Element main = null; | 1028 Element main = null; |
1027 if (mainApp != null) { | 1029 if (mainApp != null) { |
1028 main = mainApp.find(MAIN); | 1030 main = mainApp.findExported(MAIN); |
1029 if (main == null) { | 1031 if (main == null) { |
1030 if (!analyzeOnly) { | 1032 if (!analyzeOnly) { |
1031 // Allow analyze only of libraries with no main. | 1033 // Allow analyze only of libraries with no main. |
1032 reportFatalError( | 1034 reportFatalError( |
1033 mainApp, | 1035 mainApp, |
1034 MessageKind.GENERIC, | 1036 MessageKind.GENERIC, |
1035 {'text': "Error: Could not find '$MAIN'."}); | 1037 {'text': "Error: Could not find '$MAIN'."}); |
1036 } else if (!analyzeAll) { | 1038 } else if (!analyzeAll) { |
1037 reportFatalError( | 1039 reportFatalError( |
1038 mainApp, | 1040 mainApp, |
1039 MessageKind.GENERIC, | 1041 MessageKind.GENERIC, |
1040 {'text': "Error: Could not find '$MAIN'. " | 1042 {'text': "Error: Could not find '$MAIN'. " |
1041 "No source will be analyzed. " | 1043 "No source will be analyzed. " |
1042 "Use '--analyze-all' to analyze all code in the library."}); | 1044 "Use '--analyze-all' to analyze all code in the library."}); |
1043 } | 1045 } |
1044 } else { | 1046 } else { |
1045 if (!main.isFunction()) { | 1047 if (main.isErroneous()) { |
| 1048 reportFatalError( |
| 1049 main, |
| 1050 MessageKind.GENERIC, |
| 1051 {'text': "Error: Cannot determine which '$MAIN' to use."}); |
| 1052 } else if (!main.isFunction()) { |
1046 reportFatalError( | 1053 reportFatalError( |
1047 main, | 1054 main, |
1048 MessageKind.GENERIC, | 1055 MessageKind.GENERIC, |
1049 {'text': "Error: '$MAIN' is not a function."}); | 1056 {'text': "Error: '$MAIN' is not a function."}); |
1050 } | 1057 } |
1051 FunctionElement mainMethod = main; | 1058 mainFunction = main; |
1052 FunctionSignature parameters = mainMethod.computeSignature(this); | 1059 FunctionSignature parameters = mainFunction.computeSignature(this); |
1053 if (parameters.parameterCount > 2) { | 1060 if (parameters.parameterCount > 2) { |
1054 int index = 0; | 1061 int index = 0; |
1055 parameters.forEachParameter((Element parameter) { | 1062 parameters.forEachParameter((Element parameter) { |
1056 if (index++ < 2) return; | 1063 if (index++ < 2) return; |
1057 reportError( | 1064 reportError( |
1058 parameter, | 1065 parameter, |
1059 MessageKind.GENERIC, | 1066 MessageKind.GENERIC, |
1060 {'text': | 1067 {'text': |
1061 "Error: '$MAIN' cannot have more than two parameters."}); | 1068 "Error: '$MAIN' cannot have more than two parameters."}); |
1062 }); | 1069 }); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 | 1110 |
1104 log('Inferring types...'); | 1111 log('Inferring types...'); |
1105 typesTask.onResolutionComplete(main); | 1112 typesTask.onResolutionComplete(main); |
1106 | 1113 |
1107 log('Compiling...'); | 1114 log('Compiling...'); |
1108 phase = PHASE_COMPILING; | 1115 phase = PHASE_COMPILING; |
1109 // TODO(johnniwinther): Move these to [CodegenEnqueuer]. | 1116 // TODO(johnniwinther): Move these to [CodegenEnqueuer]. |
1110 if (hasIsolateSupport()) { | 1117 if (hasIsolateSupport()) { |
1111 enqueuer.codegen.addToWorkList( | 1118 enqueuer.codegen.addToWorkList( |
1112 isolateHelperLibrary.find(Compiler.START_ROOT_ISOLATE)); | 1119 isolateHelperLibrary.find(Compiler.START_ROOT_ISOLATE)); |
1113 enqueuer.codegen.registerGetOfStaticFunction(mainApp.find(MAIN)); | 1120 enqueuer.codegen.registerGetOfStaticFunction(main); |
1114 } | 1121 } |
1115 if (enabledNoSuchMethod) { | 1122 if (enabledNoSuchMethod) { |
1116 backend.enableNoSuchMethod(enqueuer.codegen); | 1123 backend.enableNoSuchMethod(enqueuer.codegen); |
1117 } | 1124 } |
1118 if (compileAll) { | 1125 if (compileAll) { |
1119 libraries.forEach((_, lib) => fullyEnqueueLibrary(lib, | 1126 libraries.forEach((_, lib) => fullyEnqueueLibrary(lib, |
1120 enqueuer.codegen)); | 1127 enqueuer.codegen)); |
1121 } | 1128 } |
1122 processQueue(enqueuer.codegen, main); | 1129 processQueue(enqueuer.codegen, main); |
1123 enqueuer.codegen.logSummary(log); | 1130 enqueuer.codegen.logSummary(log); |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1645 | 1652 |
1646 void close() {} | 1653 void close() {} |
1647 | 1654 |
1648 toString() => name; | 1655 toString() => name; |
1649 | 1656 |
1650 /// Convenience method for getting an [api.CompilerOutputProvider]. | 1657 /// Convenience method for getting an [api.CompilerOutputProvider]. |
1651 static NullSink outputProvider(String name, String extension) { | 1658 static NullSink outputProvider(String name, String extension) { |
1652 return new NullSink('$name.$extension'); | 1659 return new NullSink('$name.$extension'); |
1653 } | 1660 } |
1654 } | 1661 } |
OLD | NEW |