Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Unified Diff: pkg/kernel/lib/analyzer/loader.dart

Issue 2638353003: Revert "Fix some crashes in dartk." (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/kernel/lib/analyzer/ast_from_analyzer.dart ('k') | tests/co19/co19-kernel.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/lib/analyzer/loader.dart
diff --git a/pkg/kernel/lib/analyzer/loader.dart b/pkg/kernel/lib/analyzer/loader.dart
index 4d8de48b6409e9a480b1f9cb053d6030550465fc..cb5c9c6d3ec1f82d393179d6c9ee9fa68c016178 100644
--- a/pkg/kernel/lib/analyzer/loader.dart
+++ b/pkg/kernel/lib/analyzer/loader.dart
@@ -109,8 +109,7 @@ class DartLoader implements ReferenceLevelLoader {
DartLoader(this.repository, DartOptions options, Packages packages,
{DartSdk dartSdk, AnalysisContext context})
- : this.context =
- context ?? createContext(options, packages, dartSdk: dartSdk),
+ : this.context = context ?? createContext(options, packages, dartSdk: dartSdk),
this.applicationRoot = options.applicationRoot;
String getLibraryName(LibraryElement element) {
@@ -402,13 +401,11 @@ class DartLoader implements ReferenceLevelLoader {
}
ast.Member getMemberReference(Element element) {
- assert(element != null);
assert(element is! Member); // Use the "base element".
return _members[element] ??= _buildMemberReference(element);
}
ast.Member _buildMemberReference(Element element) {
- assert(element != null);
var node = _buildOrphanedMemberReference(element);
// Set the parent pointer and store it in the enclosing class or library.
// If the enclosing library is being built from the AST, do not add the
@@ -431,7 +428,6 @@ class DartLoader implements ReferenceLevelLoader {
}
ast.Member _buildOrphanedMemberReference(Element element) {
- assert(element != null);
ClassElement classElement = element.enclosingElement is ClassElement
? element.enclosingElement
: null;
@@ -689,41 +685,15 @@ class DartLoader implements ReferenceLevelLoader {
}
}
- ast.Procedure _getMainMethod(Uri uri) {
- Source source = context.sourceFactory.forUri2(uri);
- LibraryElement library = context.computeLibraryElement(source);
- var mainElement = library.entryPoint;
- if (mainElement == null) return null;
- var mainMember = getMemberReference(mainElement);
- if (mainMember is ast.Procedure && !mainMember.isAccessor) {
- return mainMember;
- }
- // Top-level 'main' getters are not supported at the moment.
- return null;
- }
-
- ast.Procedure _makeMissingMainMethod(ast.Library library) {
- var main = new ast.Procedure(
- new ast.Name('main'),
- ast.ProcedureKind.Method,
- new ast.FunctionNode(new ast.ExpressionStatement(new ast.Throw(
- new ast.StringLiteral('Program has no main method')))))
- ..fileUri = library.fileUri;
- library.addMember(main);
- return main;
- }
-
ast.Program loadProgram(Uri mainLibrary, {Target target, bool compileSdk}) {
- Uri uri = applicationRoot.relativeUri(mainLibrary);
- ast.Library library = repository.getLibraryReference(uri);
+ ast.Library library = repository
+ .getLibraryReference(applicationRoot.relativeUri(mainLibrary));
ensureLibraryIsLoaded(library);
- var mainMethod = _getMainMethod(mainLibrary);
loadEverything(target: target, compileSdk: compileSdk);
var program = new ast.Program(repository.libraries);
- if (mainMethod == null) {
- mainMethod = _makeMissingMainMethod(library);
- }
- program.mainMethod = mainMethod;
+ program.mainMethod = library.procedures.firstWhere(
+ (member) => member.name?.name == 'main',
+ orElse: () => null);
for (LibraryElement libraryElement in libraryElements) {
for (CompilationUnitElement compilationUnitElement
in libraryElement.units) {
« no previous file with comments | « pkg/kernel/lib/analyzer/ast_from_analyzer.dart ('k') | tests/co19/co19-kernel.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698