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

Side by Side Diff: pkg/front_end/lib/src/incremental_kernel_generator_impl.dart

Issue 2624193003: Work in progress: front end hot reload API (Closed)
Patch Set: First steel thread of functionality. 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2017, 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 import 'dart:async';
6
7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/error/error.dart';
11 import 'package:analyzer/src/generated/engine.dart';
12 import 'package:analyzer/src/generated/source.dart';
13 import 'package:front_end/incremental_kernel_generator.dart';
14 import 'package:front_end/incremental_resolved_ast_generator.dart';
15 import 'package:front_end/src/base/processed_options.dart';
16 import 'package:front_end/src/base/source.dart';
17 import 'package:front_end/src/incremental_resolved_ast_generator_impl.dart';
18 import 'package:kernel/analyzer/loader.dart';
19 import 'package:kernel/kernel.dart' hide Source;
20 import 'package:kernel/repository.dart';
21
22 dynamic unimplemented() {
23 // TODO(paulberry): get rid of this.
24 throw new UnimplementedError();
25 }
26
27 DartOptions _convertOptions(ProcessedOptions options) {
28 // TODO(paulberry): make sure options.compileSdk is handled correctly.
29 return new DartOptions(
30 strongMode: true, // TODO(paulberry): options.strongMode,
31 sdk: null, // TODO(paulberry): _uriToPath(options.sdkRoot, options),
32 sdkSummary:
33 null, // TODO(paulberry): options.compileSdk ? null : _uriToPath(optio ns.sdkSummary, options),
34 packagePath:
35 null, // TODO(paulberry): _uriToPath(options.packagesFileUri, options) ,
36 declaredVariables: null // TODO(paulberry): options.declaredVariables
37 );
38 }
39
40 /// Implementation of [IncrementalKernelGenerator].
41 ///
42 /// Theory of operation: an instance of [IncrementalResolvedAstGenerator] is
43 /// used to obtain resolved ASTs, and these are fed into kernel code generation
44 /// logic.
45 ///
46 /// Note that the kernel doesn't expect to take resolved ASTs as a direct input;
47 /// it expects to request resolved ASTs from an [AnalysisContext]. To deal with
48 /// this, we create [_AnalysisContextProxy] which returns the resolved ASTs when
49 /// requested. TODO(paulberry): Make this unnecessary.
50 class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
51 final IncrementalResolvedAstGenerator _resolvedAstGenerator;
52 final ProcessedOptions _options;
53
54 IncrementalKernelGeneratorImpl(Uri source, ProcessedOptions options)
55 : _resolvedAstGenerator =
56 new IncrementalResolvedAstGeneratorImpl(source, options),
57 _options = options;
58
59 @override
60 Future<DeltaProgram> computeDelta() async {
61 var deltaLibraries = await _resolvedAstGenerator.computeDelta();
62 var kernelOptions = _convertOptions(_options);
63 var packages = null; // TODO(paulberry)
64 var kernels = <Uri, Program>{};
65 deltaLibraries.newState.forEach((uri, resolvedLibrary) {
66 // The kernel generation code doesn't currently support building a kernel
67 // directly from resolved ASTs--it wants to query an analysis context. So
68 // we provide it with a proxy analysis context that feeds it the resolved
69 // ASTs.
70 var strongMode = true; // TODO(paulberry): set this correctly
71 var analysisOptions = new _AnalysisOptionsProxy(strongMode);
72 var context =
73 new _AnalysisContextProxy(deltaLibraries.newState, analysisOptions);
74 var repository = new Repository();
75 var loader =
76 new DartLoader(repository, kernelOptions, packages, context: context);
77 loader.loadLibrary(uri);
78 kernels[uri] = new Program(repository.libraries);
79 });
80 return new DeltaProgram(kernels);
81 }
82
83 @override
84 void invalidate(String path) => _resolvedAstGenerator.invalidate(path);
85
86 @override
87 void invalidateAll() => _resolvedAstGenerator.invalidateAll();
88 }
89
90 class _AnalysisContextProxy implements AnalysisContext {
91 final Map<Uri, ResolvedLibrary> _resolvedLibraries;
92
93 @override
94 final _SourceFactoryProxy sourceFactory = new _SourceFactoryProxy();
95
96 @override
97 final AnalysisOptions analysisOptions;
98
99 _AnalysisContextProxy(this._resolvedLibraries, this.analysisOptions);
100
101 List<AnalysisError> computeErrors(Source source) {
102 // TODO(paulberry): do we need to return errors sometimes?
103 return [];
104 }
105
106 LibraryElement computeLibraryElement(Source source) {
107 assert(_resolvedLibraries.containsKey(source.uri));
108 return resolutionMap
109 .elementDeclaredByCompilationUnit(
110 _resolvedLibraries[source.uri].definingCompilationUnit)
111 .library;
112 }
113
114 noSuchMethod(Invocation invocation) => unimplemented();
115
116 CompilationUnit resolveCompilationUnit(
117 Source unitSource, LibraryElement library) {
118 assert(_resolvedLibraries.containsKey(library.source.uri));
119 // TODO(paulberry): support parts.
120 assert(unitSource == library.source);
121 return _resolvedLibraries[library.source.uri].definingCompilationUnit;
122 }
123 }
124
125 class _AnalysisOptionsProxy implements AnalysisOptions {
126 final bool strongMode;
127
128 _AnalysisOptionsProxy(this.strongMode);
129
130 noSuchMethod(Invocation invocation) => unimplemented();
131 }
132
133 class _SourceFactoryProxy implements SourceFactory {
134 Source forUri2(Uri absoluteUri) => new _SourceProxy(absoluteUri);
135
136 noSuchMethod(Invocation invocation) => unimplemented();
137 }
138
139 class _SourceProxy extends BasicSource {
140 _SourceProxy(Uri uri) : super(uri);
141
142 noSuchMethod(Invocation invocation) => unimplemented();
143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698