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

Unified Diff: pkg/analyzer2dart/bin/analyzer2dart.dart

Issue 511193002: Split analyzer2dart code into multiple source files (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 | « no previous file | pkg/analyzer2dart/lib/src/closed_world.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer2dart/bin/analyzer2dart.dart
diff --git a/pkg/analyzer2dart/bin/analyzer2dart.dart b/pkg/analyzer2dart/bin/analyzer2dart.dart
index 3f85ef7afd4b82cfb2ceab2a4a2eddaef0ec6d23..3f618f81e48c9b7476398185c703d75e384658c7 100644
--- a/pkg/analyzer2dart/bin/analyzer2dart.dart
+++ b/pkg/analyzer2dart/bin/analyzer2dart.dart
@@ -6,116 +6,27 @@
library analyzer2dart.cmdline;
import 'package:analyzer/analyzer.dart';
-import 'package:analyzer/src/generated/engine.dart';
-import 'package:analyzer/src/generated/sdk_io.dart';
-import 'package:analyzer/src/generated/source_io.dart';
-import 'package:analyzer/src/generated/java_io.dart';
import 'package:analyzer/src/generated/element.dart';
+import 'package:analyzer/src/generated/source_io.dart';
-class TreeShakingVisitor extends RecursiveAstVisitor {
- final TreeShaker treeShaker;
-
- TreeShakingVisitor(this.treeShaker);
-
- @override
- void visitFunctionDeclaration(FunctionDeclaration node) {
- print('Visiting function ${node.name.name}');
- super.visitFunctionDeclaration(node);
- }
-
- @override
- void visitMethodInvocation(MethodInvocation node) {
- print('Visiting invocation of ${node.methodName.name}');
- Element staticElement = node.methodName.staticElement;
- if (staticElement != null) {
- // TODO(paulberry): deal with the case where staticElement is
- // not necessarily the exact target. (Dart2js calls this a
- // "dynamic invocation"). We need a notion of "selector". Maybe
- // we can use Dart2js selectors.
- treeShaker.add(staticElement);
- } else {
- // TODO(paulberry): deal with this case.
- }
- super.visitMethodInvocation(node);
- }
-
-}
-
-class CpsGeneratingVisitor extends RecursiveAstVisitor {
- // TODO(johnniwinther)
-}
-
-class ClosedWorld {
- // TODO(paulberry): is it a problem to hold on to all the AST's for the
- // duration of tree shaking & CPS generation?
- Map<Element, AstNode> elements = <Element, AstNode>{};
- ClosedWorld();
-}
-
-class TreeShaker {
- List<Element> _queue = <Element>[];
- Set<Element> _alreadyEnqueued = new Set<Element>();
- ClosedWorld _world = new ClosedWorld();
-
- void add(Element e) {
- if (!_alreadyEnqueued.contains(e)) {
- _queue.add(e);
- _alreadyEnqueued.add(e);
- }
- }
-
- ClosedWorld shake(AnalysisContext context) {
- while (_queue.isNotEmpty) {
- Element e = _queue.removeAt(0);
- print('Tree shaker handling $e');
- CompilationUnit compilationUnit =
- context.getResolvedCompilationUnit(e.source, e.library);
- AstNode identifier =
- new NodeLocator.con1(e.nameOffset).searchWithin(compilationUnit);
- FunctionDeclaration declaration =
- identifier.getAncestor((node) => node is FunctionDeclaration);
- _world.elements[e] = declaration;
- declaration.accept(new TreeShakingVisitor(this));
- }
- print('Tree shaking done');
- return _world;
- }
-}
+import '../lib/src/closed_world.dart';
+import '../lib/src/driver.dart';
void main(List<String> args) {
- // Create the analysis context
- AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
+ // TODO(paulberry): hacky
+ String path = args[0];
- // Set up the source factory.
- // TODO(paulberry): do we want to use ExplicitPackageUriResolver?
- List<UriResolver> uriResolvers = [
- new FileUriResolver(),
- new DartUriResolver(DirectoryBasedDartSdk.defaultSdk) /* ,
- new PackageUriResolver(packagesDirectories) */
- ];
- context.sourceFactory = new SourceFactory(uriResolvers);
+ Driver analyzer2Dart = new Driver();
// Tell the analysis server about the root
- JavaFile javaFile = new JavaFile(args[0]); // TODO(paulberry): hacky
- Source source = new FileBasedSource.con1(javaFile);
- ChangeSet changeSet = new ChangeSet();
- changeSet.addedSources.add(source);
- context.applyChanges(changeSet);
+ Source source = analyzer2Dart.setRealRoot(path);
// Get the library element associated with the source.
- LibraryElement libraryElement = context.computeLibraryElement(source);
-
- // Get the resolved AST for main
- FunctionElement entryPointElement = libraryElement.entryPoint;
- if (entryPointElement == null) {
- throw new Exception('No main()!');
- }
+ FunctionElement entryPointElement = analyzer2Dart.resolveEntryPoint(source);
// TODO(brianwilkerson,paulberry,johnniwinther): Perform tree-growing by
// visiting the ast and feeding the dependencies into a work queue (enqueuer).
- TreeShaker treeShaker = new TreeShaker();
- treeShaker.add(entryPointElement);
- ClosedWorld world = treeShaker.shake(context);
+ ClosedWorld world = analyzer2Dart.computeWorld(entryPointElement);
// TODO(brianwilkerson,paulberry,johnniwinther): Convert the ast into cps by
// visiting the ast and invoking the ir builder.
@@ -127,3 +38,7 @@ void main(List<String> args) {
// TODO(johnniwinther): Feed the cps ir into the new dart2dart backend to
// generate dart file(s).
}
+
+class CpsGeneratingVisitor extends RecursiveAstVisitor {
+ // TODO(johnniwinther)
+}
« no previous file with comments | « no previous file | pkg/analyzer2dart/lib/src/closed_world.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698