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

Side by Side Diff: pkg/analyzer2dart/lib/src/driver.dart

Issue 2037123002: Cleanup: remove package "analyzer2dart". (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5 library analyzer2dart.driver;
6
7 import 'package:analyzer/file_system/file_system.dart';
8 import 'package:analyzer/src/generated/element.dart';
9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/sdk.dart';
11 import 'package:analyzer/src/generated/source_io.dart';
12
13 import 'package:compiler/compiler.dart';
14
15 import 'closed_world.dart';
16 import 'tree_shaker.dart';
17
18 /**
19 * Top level driver for Analyzer2Dart.
20 */
21 class Driver {
22 final ResourceProvider resourceProvider;
23 final AnalysisContext context;
24 final CompilerOutputProvider outputProvider;
25
26 Driver(this.resourceProvider, DartSdk sdk, this.outputProvider)
27 : context = AnalysisEngine.instance.createAnalysisContext() {
28 // Set up the source factory.
29 // TODO(paulberry): do we want to use ExplicitPackageUriResolver?
30 List<UriResolver> uriResolvers = [
31 new FileUriResolver(),
32 new DartUriResolver(sdk) /* ,
33 new PackageUriResolver(packagesDirectories) */
34 ];
35 context.sourceFactory = new SourceFactory(uriResolvers);
36 }
37
38 /**
39 * Compute the closed world that is reachable from an entry point.
40 */
41 ClosedWorld computeWorld(FunctionElement entryPointElement) {
42 InternalAnalysisContext analysisContext = context;
43 TreeShaker treeShaker =
44 new TreeShaker(analysisContext.typeProvider, entryPointElement);
45 return treeShaker.shake();
46 }
47
48 /**
49 * Given a source, resolve it and return its entry point.
50 */
51 FunctionElement resolveEntryPoint(Source source) {
52 // Get the library element associated with the source.
53 LibraryElement libraryElement = context.computeLibraryElement(source);
54
55 // Get the resolved AST for main
56 FunctionElement entryPointElement = libraryElement.entryPoint;
57 if (entryPointElement == null) {
58 throw new Exception('No main()!');
59 }
60 return entryPointElement;
61 }
62
63 /**
64 * Add the given file as the root of analysis, and return the corresponding
65 * source.
66 */
67 Source setRoot(String path) {
68 File file = resourceProvider.getResource(path);
69 Source source = file.createSource();
70 // add the Source
71 ChangeSet changeSet = new ChangeSet();
72 changeSet.addedSource(source);
73 context.applyChanges(changeSet);
74 // return the Source
75 return source;
76 }
77 }
OLDNEW
« no previous file with comments | « pkg/analyzer2dart/lib/src/dart_backend.dart ('k') | pkg/analyzer2dart/lib/src/element_converter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698