mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 12:13:01 +00:00
Re-land "Search for main in the exported names of the main library, not in the library itself."
BUG= Review URL: https://codereview.chromium.org//57433004 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@29812 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
59f34542e2
commit
7cd5977b62
|
@ -416,7 +416,9 @@ abstract class Compiler implements DiagnosticListener {
|
|||
LibraryElement jsHelperLibrary;
|
||||
LibraryElement interceptorsLibrary;
|
||||
LibraryElement foreignLibrary;
|
||||
|
||||
LibraryElement mainApp;
|
||||
FunctionElement mainFunction;
|
||||
|
||||
/// Initialized when dart:mirrors is loaded.
|
||||
LibraryElement mirrorsLibrary;
|
||||
|
@ -1025,7 +1027,7 @@ abstract class Compiler implements DiagnosticListener {
|
|||
void compileLoadedLibraries() {
|
||||
Element main = null;
|
||||
if (mainApp != null) {
|
||||
main = mainApp.find(MAIN);
|
||||
main = mainApp.findExported(MAIN);
|
||||
if (main == null) {
|
||||
if (!analyzeOnly) {
|
||||
// Allow analyze only of libraries with no main.
|
||||
|
@ -1042,14 +1044,19 @@ abstract class Compiler implements DiagnosticListener {
|
|||
"Use '--analyze-all' to analyze all code in the library."});
|
||||
}
|
||||
} else {
|
||||
if (!main.isFunction()) {
|
||||
if (main.isErroneous()) {
|
||||
reportFatalError(
|
||||
main,
|
||||
MessageKind.GENERIC,
|
||||
{'text': "Error: Cannot determine which '$MAIN' to use."});
|
||||
} else if (!main.isFunction()) {
|
||||
reportFatalError(
|
||||
main,
|
||||
MessageKind.GENERIC,
|
||||
{'text': "Error: '$MAIN' is not a function."});
|
||||
}
|
||||
FunctionElement mainMethod = main;
|
||||
FunctionSignature parameters = mainMethod.computeSignature(this);
|
||||
mainFunction = main;
|
||||
FunctionSignature parameters = mainFunction.computeSignature(this);
|
||||
if (parameters.parameterCount > 2) {
|
||||
int index = 0;
|
||||
parameters.forEachParameter((Element parameter) {
|
||||
|
@ -1110,7 +1117,7 @@ abstract class Compiler implements DiagnosticListener {
|
|||
if (hasIsolateSupport()) {
|
||||
enqueuer.codegen.addToWorkList(
|
||||
isolateHelperLibrary.find(Compiler.START_ROOT_ISOLATE));
|
||||
enqueuer.codegen.registerGetOfStaticFunction(mainApp.find(MAIN));
|
||||
enqueuer.codegen.registerGetOfStaticFunction(main);
|
||||
}
|
||||
if (enabledNoSuchMethod) {
|
||||
backend.enableNoSuchMethod(enqueuer.codegen);
|
||||
|
|
|
@ -163,7 +163,7 @@ class PlaceholderCollector extends Visitor {
|
|||
TreeElements treeElements;
|
||||
|
||||
LibraryElement get coreLibrary => compiler.coreLibrary;
|
||||
FunctionElement get entryFunction => compiler.mainApp.find(Compiler.MAIN);
|
||||
FunctionElement get entryFunction => compiler.mainFunction;
|
||||
DartBackend get backend => compiler.backend;
|
||||
|
||||
get currentFunctionScope => functionScopes.putIfAbsent(
|
||||
|
|
|
@ -694,6 +694,7 @@ abstract class LibraryElement extends Element implements ScopeContainerElement {
|
|||
|
||||
Element find(String elementName);
|
||||
Element findLocal(String elementName);
|
||||
Element findExported(String elementName);
|
||||
void forEachExport(f(Element element));
|
||||
|
||||
bool hasLibraryName();
|
||||
|
|
|
@ -902,6 +902,14 @@ class LibraryElementX extends ElementX implements LibraryElement {
|
|||
return result;
|
||||
}
|
||||
|
||||
Element findExported(String elementName) {
|
||||
for (Link link = exports; !link.isEmpty; link = link.tail) {
|
||||
Element element = link.head;
|
||||
if (element.name == elementName) return element;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void forEachExport(f(Element element)) {
|
||||
exports.forEach((Element e) => f(e));
|
||||
}
|
||||
|
|
|
@ -959,7 +959,7 @@ class CodeEmitterTask extends CompilerTask {
|
|||
|
||||
emitMain(CodeBuffer buffer) {
|
||||
if (compiler.isMockCompilation) return;
|
||||
Element main = compiler.mainApp.find(Compiler.MAIN);
|
||||
Element main = compiler.mainFunction;
|
||||
String mainCall = null;
|
||||
if (compiler.hasIsolateSupport()) {
|
||||
Element isolateMain =
|
||||
|
|
|
@ -73,6 +73,8 @@ LibTest/typed_data/Float32x4/withZWInXY_A01_t01: Fail # co19 issue 650
|
|||
LibTest/typed_data/Float32x4/interleaveXY_A01_t01: Fail # co19 issue 650
|
||||
LibTest/typed_data/Float32x4/interleaveXYPairs_A01_t01: Fail # co19 issue 650
|
||||
|
||||
Language/14_Libraries_and_Scripts/4_Scripts_A03_t02: Fail # co19 issue 654
|
||||
|
||||
|
||||
[ $compiler == dart2dart && $system == windows ]
|
||||
LibTest/core/double/operator_remainder_A01_t04: Fail # Result is NaN
|
||||
|
|
|
@ -238,6 +238,7 @@ LibTest/typed_data/ByteData/setUint8_A02_t02: fail # Issue 12989
|
|||
LibTest/typed_data/ByteData/setUint8_A02_t02: fail # Issue 12989
|
||||
|
||||
Language/14_Libraries_and_Scripts/1_Imports_A04_t01: Fail # co19 Issue 603
|
||||
Language/14_Libraries_and_Scripts/4_Scripts_A03_t02: Fail # co19 issue 654
|
||||
|
||||
[ $compiler == dart2js && $jscl ]
|
||||
LibTest/core/RegExp/Pattern_semantics/firstMatch_CharacterClassEscape_A03_t01: Fail, Pass # issue 3333
|
||||
|
|
|
@ -467,6 +467,7 @@ LibraryElement mockLibrary(Compiler compiler, String source) {
|
|||
Uri uri = new Uri(scheme: "source");
|
||||
var library = new LibraryElementX(new Script(uri, new MockFile(source)));
|
||||
importLibrary(library, compiler.coreLibrary, compiler);
|
||||
library.setExports(<Element>[]);
|
||||
return library;
|
||||
}
|
||||
|
||||
|
|
9
tests/language/export_ambiguous_main_a.dart
Normal file
9
tests/language/export_ambiguous_main_a.dart
Normal file
|
@ -0,0 +1,9 @@
|
|||
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
library export_ambiguous_main_a;
|
||||
|
||||
main() {
|
||||
print('export_ambiguous_main_a');
|
||||
}
|
9
tests/language/export_ambiguous_main_b.dart
Normal file
9
tests/language/export_ambiguous_main_b.dart
Normal file
|
@ -0,0 +1,9 @@
|
|||
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
library export_ambiguous_main_b;
|
||||
|
||||
main() {
|
||||
print('export_ambiguous_main_b');
|
||||
}
|
6
tests/language/export_ambiguous_main_negative_test.dart
Normal file
6
tests/language/export_ambiguous_main_negative_test.dart
Normal file
|
@ -0,0 +1,6 @@
|
|||
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
export 'export_ambiguous_main_a.dart';
|
||||
export 'export_ambiguous_main_b.dart';
|
6
tests/language/export_double_same_main_test.dart
Normal file
6
tests/language/export_double_same_main_test.dart
Normal file
|
@ -0,0 +1,6 @@
|
|||
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
export 'top_level_entry_test.dart';
|
||||
export 'export_main_test.dart' show main;
|
9
tests/language/export_main_override_test.dart
Normal file
9
tests/language/export_main_override_test.dart
Normal file
|
@ -0,0 +1,9 @@
|
|||
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
export 'top_level_entry_test.dart';
|
||||
|
||||
main() {
|
||||
print('export_main_override');
|
||||
}
|
5
tests/language/export_main_test.dart
Normal file
5
tests/language/export_main_test.dart
Normal file
|
@ -0,0 +1,5 @@
|
|||
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
export 'top_level_entry_test.dart';
|
|
@ -47,6 +47,8 @@ compile_time_constant_checked3_test/06: Fail, OK
|
|||
[ $runtime == vm || (($runtime == drt || $runtime == dartium) && $compiler == none) ]
|
||||
call_test: Fail # Issue 12602
|
||||
dynamic_prefix_core_test: Fail # Issue 12478
|
||||
export_main_test: Fail # Issue 14763
|
||||
export_double_same_main_test: Fail # Issue 14763
|
||||
|
||||
[ $compiler == none && $runtime == drt ]
|
||||
mixin_illegal_object_test/01: pass # Issue 10952.
|
||||
|
|
|
@ -22,6 +22,8 @@ method_override7_test/03: Fail # Issue 11496
|
|||
|
||||
built_in_identifier_test/none: Fail # Issue 13023
|
||||
|
||||
export_double_same_main_test: Fail # Issue 14772
|
||||
|
||||
# Please add new failing tests before this line.
|
||||
# Section below is for invalid tests.
|
||||
#
|
||||
|
@ -218,6 +220,7 @@ dynamic_field_test: StaticWarning
|
|||
dynamic_prefix_core_test: StaticWarning
|
||||
empty_block_case_test: StaticWarning
|
||||
error_stacktrace_test: StaticWarning
|
||||
export_ambiguous_main_negative_test: CompileTimeError
|
||||
extend_type_parameter2_negative_test: CompileTimeError
|
||||
extend_type_parameter_negative_test: CompileTimeError
|
||||
external_test/20: StaticWarning
|
||||
|
|
|
@ -23,6 +23,8 @@ method_override8_test/03: Fail # Issue 11496
|
|||
|
||||
built_in_identifier_test/none: Fail # Issue 13023
|
||||
|
||||
export_double_same_main_test: Fail # Issue 14772
|
||||
|
||||
# Please add new failing tests before this line.
|
||||
# Section below is for invalid tests.
|
||||
#
|
||||
|
@ -214,6 +216,7 @@ dynamic_field_test: StaticWarning
|
|||
dynamic_prefix_core_test: StaticWarning
|
||||
empty_block_case_test: StaticWarning
|
||||
error_stacktrace_test: StaticWarning
|
||||
export_ambiguous_main_negative_test: CompileTimeError
|
||||
extend_type_parameter2_negative_test: CompileTimeError
|
||||
extend_type_parameter_negative_test: CompileTimeError
|
||||
external_test/20: StaticWarning
|
||||
|
|
|
@ -5,4 +5,8 @@
|
|||
// PackageRoot=none
|
||||
|
||||
library package1_test;
|
||||
import 'package:package1.dart';
|
||||
import 'package:package1.dart' as p1;
|
||||
|
||||
main() {
|
||||
p1.main();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue