OLD | NEW |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 library fletchc_incremental.fletch_reuser; | 5 library dartino_compiler_incremental.dartino_reuser; |
6 | 6 |
7 import 'package:compiler/compiler_new.dart' show | 7 import 'package:compiler/compiler_new.dart' show |
8 CompilerDiagnostics, | 8 CompilerDiagnostics, |
9 Diagnostic; | 9 Diagnostic; |
10 | 10 |
11 import 'package:compiler/compiler.dart' as api; | 11 import 'package:compiler/compiler.dart' as api; |
12 | 12 |
13 import 'package:compiler/src/compiler.dart' show | 13 import 'package:compiler/src/compiler.dart' show |
14 Compiler; | 14 Compiler; |
15 | 15 |
(...skipping 14 matching lines...) Expand all Loading... |
30 | 30 |
31 import 'package:compiler/src/elements/modelx.dart' show | 31 import 'package:compiler/src/elements/modelx.dart' show |
32 ClassElementX, | 32 ClassElementX, |
33 FieldElementX, | 33 FieldElementX, |
34 LibraryElementX; | 34 LibraryElementX; |
35 | 35 |
36 import 'package:compiler/src/constants/values.dart' show | 36 import 'package:compiler/src/constants/values.dart' show |
37 ConstantValue; | 37 ConstantValue; |
38 | 38 |
39 import '../incremental_backend.dart' show | 39 import '../incremental_backend.dart' show |
40 IncrementalFletchBackend; | 40 IncrementalDartinoBackend; |
41 | 41 |
42 import '../src/fletch_class_builder.dart' show | 42 import '../src/dartino_class_builder.dart' show |
43 FletchClassBuilder; | 43 DartinoClassBuilder; |
44 | 44 |
45 import '../src/fletch_context.dart' show | 45 import '../src/dartino_context.dart' show |
46 FletchContext; | 46 DartinoContext; |
47 | 47 |
48 import '../src/fletch_compiler_implementation.dart' show | 48 import '../src/dartino_compiler_implementation.dart' show |
49 FletchCompilerImplementation; | 49 DartinoCompilerImplementation; |
50 | 50 |
51 import '../src/fletch_function_builder.dart' show | 51 import '../src/dartino_function_builder.dart' show |
52 FletchFunctionBuilder; | 52 DartinoFunctionBuilder; |
53 | 53 |
54 import '../vm_commands.dart' show | 54 import '../vm_commands.dart' show |
55 PrepareForChanges, | 55 PrepareForChanges, |
56 VmCommand; | 56 VmCommand; |
57 | 57 |
58 import '../fletch_system.dart' show | 58 import '../dartino_system.dart' show |
59 FletchDelta, | 59 DartinoDelta, |
60 FletchSystem; | 60 DartinoSystem; |
61 | 61 |
62 import 'fletchc_incremental.dart' show | 62 import 'dartino_compiler_incremental.dart' show |
63 IncrementalCompilationFailed, | 63 IncrementalCompilationFailed, |
64 IncrementalCompiler; | 64 IncrementalCompiler; |
65 | 65 |
66 import 'reuser.dart' show | 66 import 'reuser.dart' show |
67 AddedClassUpdate, | 67 AddedClassUpdate, |
68 AddedFieldUpdate, | 68 AddedFieldUpdate, |
69 AddedFunctionUpdate, | 69 AddedFunctionUpdate, |
70 ClassUpdate, | 70 ClassUpdate, |
71 Logger, | 71 Logger, |
72 RemovedClassUpdate, | 72 RemovedClassUpdate, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 if (kind == Diagnostic.WARNING) { | 120 if (kind == Diagnostic.WARNING) { |
121 warningCount++; | 121 warningCount++; |
122 } | 122 } |
123 if (kind == Diagnostic.HINT) { | 123 if (kind == Diagnostic.HINT) { |
124 hintCount++; | 124 hintCount++; |
125 } | 125 } |
126 diagnostics.report(code, uri, begin, end, text, kind); | 126 diagnostics.report(code, uri, begin, end, text, kind); |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 class FletchReuser extends Reuser with FletchFeatures { | 130 class DartinoReuser extends Reuser with DartinoFeatures { |
131 final IncrementalCompilerContext _context; | 131 final IncrementalCompilerContext _context; |
132 | 132 |
133 FletchReuser( | 133 DartinoReuser( |
134 FletchCompilerImplementation compiler, | 134 DartinoCompilerImplementation compiler, |
135 api.CompilerInputProvider inputProvider, | 135 api.CompilerInputProvider inputProvider, |
136 Logger logTime, | 136 Logger logTime, |
137 Logger logVerbose, | 137 Logger logVerbose, |
138 this._context) | 138 this._context) |
139 : super(compiler, inputProvider, logTime, logVerbose); | 139 : super(compiler, inputProvider, logTime, logVerbose); |
140 | 140 |
141 FletchDelta computeUpdateFletch(FletchSystem currentSystem) { | 141 DartinoDelta computeUpdateDartino(DartinoSystem currentSystem) { |
142 // TODO(ahe): Remove this when we support adding static fields. | 142 // TODO(ahe): Remove this when we support adding static fields. |
143 Set<Element> existingStaticFields = | 143 Set<Element> existingStaticFields = |
144 new Set<Element>.from(fletchContext.staticIndices.keys); | 144 new Set<Element>.from(dartinoContext.staticIndices.keys); |
145 | 145 |
146 backend.newSystemBuilder(currentSystem); | 146 backend.newSystemBuilder(currentSystem); |
147 | 147 |
148 List<Element> updatedElements = applyUpdates(); | 148 List<Element> updatedElements = applyUpdates(); |
149 | 149 |
150 if (compiler.progress != null) { | 150 if (compiler.progress != null) { |
151 compiler.progress.reset(); | 151 compiler.progress.reset(); |
152 } | 152 } |
153 | 153 |
154 for (Element element in updatedElements) { | 154 for (Element element in updatedElements) { |
(...skipping 11 matching lines...) Expand all Loading... |
166 // already instantiated. | 166 // already instantiated. |
167 enqueuer.codegen.registerInstantiatedType(cls.rawType); | 167 enqueuer.codegen.registerInstantiatedType(cls.rawType); |
168 } | 168 } |
169 } | 169 } |
170 compiler.processQueue(enqueuer.resolution, null); | 170 compiler.processQueue(enqueuer.resolution, null); |
171 | 171 |
172 compiler.phase = Compiler.PHASE_DONE_RESOLVING; | 172 compiler.phase = Compiler.PHASE_DONE_RESOLVING; |
173 | 173 |
174 // TODO(ahe): Clean this up. Don't call this method in analyze-only mode. | 174 // TODO(ahe): Clean this up. Don't call this method in analyze-only mode. |
175 if (compiler.analyzeOnly) { | 175 if (compiler.analyzeOnly) { |
176 return new FletchDelta(currentSystem, currentSystem, <VmCommand>[]); | 176 return new DartinoDelta(currentSystem, currentSystem, <VmCommand>[]); |
177 } | 177 } |
178 | 178 |
179 for (AstElement element in updatedElements) { | 179 for (AstElement element in updatedElements) { |
180 if (element.node.isErroneous) { | 180 if (element.node.isErroneous) { |
181 throw new IncrementalCompilationFailed( | 181 throw new IncrementalCompilationFailed( |
182 "Unable to incrementally compile $element with syntax error"); | 182 "Unable to incrementally compile $element with syntax error"); |
183 } | 183 } |
184 if (element.isField) { | 184 if (element.isField) { |
185 backend.newElement(element); | 185 backend.newElement(element); |
186 } else if (!element.isClass) { | 186 } else if (!element.isClass) { |
187 enqueuer.codegen.addToWorkList(element); | 187 enqueuer.codegen.addToWorkList(element); |
188 } | 188 } |
189 } | 189 } |
190 compiler.processQueue(enqueuer.codegen, null); | 190 compiler.processQueue(enqueuer.codegen, null); |
191 | 191 |
192 // TODO(ahe): Remove this when we support adding static fields. | 192 // TODO(ahe): Remove this when we support adding static fields. |
193 Set<Element> newStaticFields = | 193 Set<Element> newStaticFields = |
194 new Set<Element>.from(fletchContext.staticIndices.keys).difference( | 194 new Set<Element>.from(dartinoContext.staticIndices.keys).difference( |
195 existingStaticFields); | 195 existingStaticFields); |
196 if (newStaticFields.isNotEmpty) { | 196 if (newStaticFields.isNotEmpty) { |
197 throw new IncrementalCompilationFailed( | 197 throw new IncrementalCompilationFailed( |
198 "Unable to add static fields:\n ${newStaticFields.join(',\n ')}"); | 198 "Unable to add static fields:\n ${newStaticFields.join(',\n ')}"); |
199 } | 199 } |
200 | 200 |
201 List<VmCommand> commands = <VmCommand>[const PrepareForChanges()]; | 201 List<VmCommand> commands = <VmCommand>[const PrepareForChanges()]; |
202 FletchSystem system = | 202 DartinoSystem system = |
203 backend.systemBuilder.computeSystem(fletchContext, commands); | 203 backend.systemBuilder.computeSystem(dartinoContext, commands); |
204 return new FletchDelta(system, currentSystem, commands); | 204 return new DartinoDelta(system, currentSystem, commands); |
205 } | 205 } |
206 | 206 |
207 void addClassUpdate( | 207 void addClassUpdate( |
208 Compiler compiler, | 208 Compiler compiler, |
209 PartialClassElement before, | 209 PartialClassElement before, |
210 PartialClassElement after) { | 210 PartialClassElement after) { |
211 updates.add(new FletchClassUpdate(compiler, before, after)); | 211 updates.add(new DartinoClassUpdate(compiler, before, after)); |
212 } | 212 } |
213 | 213 |
214 void addAddedFunctionUpdate( | 214 void addAddedFunctionUpdate( |
215 Compiler compiler, | 215 Compiler compiler, |
216 PartialFunctionElement element, | 216 PartialFunctionElement element, |
217 /* ScopeContainerElement */ container) { | 217 /* ScopeContainerElement */ container) { |
218 updates.add(new FletchAddedFunctionUpdate(compiler, element, container)); | 218 updates.add(new DartinoAddedFunctionUpdate(compiler, element, container)); |
219 } | 219 } |
220 | 220 |
221 void addRemovedFunctionUpdate( | 221 void addRemovedFunctionUpdate( |
222 Compiler compiler, | 222 Compiler compiler, |
223 PartialFunctionElement element) { | 223 PartialFunctionElement element) { |
224 updates.add(new FletchRemovedFunctionUpdate(compiler, element)); | 224 updates.add(new DartinoRemovedFunctionUpdate(compiler, element)); |
225 } | 225 } |
226 | 226 |
227 void addRemovedFieldUpdate( | 227 void addRemovedFieldUpdate( |
228 Compiler compiler, | 228 Compiler compiler, |
229 FieldElementX element) { | 229 FieldElementX element) { |
230 updates.add(new FletchRemovedFieldUpdate(compiler, element)); | 230 updates.add(new DartinoRemovedFieldUpdate(compiler, element)); |
231 } | 231 } |
232 | 232 |
233 void addRemovedClassUpdate( | 233 void addRemovedClassUpdate( |
234 Compiler compiler, | 234 Compiler compiler, |
235 PartialClassElement element) { | 235 PartialClassElement element) { |
236 updates.add(new FletchRemovedClassUpdate(compiler, element)); | 236 updates.add(new DartinoRemovedClassUpdate(compiler, element)); |
237 } | 237 } |
238 | 238 |
239 void addAddedFieldUpdate( | 239 void addAddedFieldUpdate( |
240 Compiler compiler, | 240 Compiler compiler, |
241 FieldElementX element, | 241 FieldElementX element, |
242 /* ScopeContainerElement */ container) { | 242 /* ScopeContainerElement */ container) { |
243 updates.add(new FletchAddedFieldUpdate(compiler, element, container)); | 243 updates.add(new DartinoAddedFieldUpdate(compiler, element, container)); |
244 } | 244 } |
245 | 245 |
246 void addAddedClassUpdate( | 246 void addAddedClassUpdate( |
247 Compiler compiler, | 247 Compiler compiler, |
248 PartialClassElement element, | 248 PartialClassElement element, |
249 LibraryElementX library) { | 249 LibraryElementX library) { |
250 updates.add(new FletchAddedClassUpdate(compiler, element, library)); | 250 updates.add(new DartinoAddedClassUpdate(compiler, element, library)); |
251 } | 251 } |
252 | 252 |
253 static void forEachField(ClassElement c, void action(FieldElement field)) { | 253 static void forEachField(ClassElement c, void action(FieldElement field)) { |
254 List classes = []; | 254 List classes = []; |
255 while (c != null) { | 255 while (c != null) { |
256 if (!c.isResolved) { | 256 if (!c.isResolved) { |
257 throw new IncrementalCompilationFailed("Class not resolved: $c"); | 257 throw new IncrementalCompilationFailed("Class not resolved: $c"); |
258 } | 258 } |
259 classes.add(c); | 259 classes.add(c); |
260 c = c.superclass; | 260 c = c.superclass; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 | 305 |
306 bool allowAddedElement(PartialElement element) { | 306 bool allowAddedElement(PartialElement element) { |
307 if (!_context.incrementalCompiler.isExperimentalModeEnabled) { | 307 if (!_context.incrementalCompiler.isExperimentalModeEnabled) { |
308 return cannotReuse( | 308 return cannotReuse( |
309 element, "Adding elements requires 'experimental' mode"); | 309 element, "Adding elements requires 'experimental' mode"); |
310 } | 310 } |
311 return true; | 311 return true; |
312 } | 312 } |
313 } | 313 } |
314 | 314 |
315 class FletchRemovedFunctionUpdate extends RemovedFunctionUpdate | 315 class DartinoRemovedFunctionUpdate extends RemovedFunctionUpdate |
316 with FletchFeatures { | 316 with DartinoFeatures { |
317 FletchRemovedFunctionUpdate(Compiler compiler, PartialFunctionElement element) | 317 DartinoRemovedFunctionUpdate(Compiler compiler, PartialFunctionElement element
) |
318 : super(compiler, element); | 318 : super(compiler, element); |
319 } | 319 } |
320 | 320 |
321 class FletchRemovedClassUpdate extends RemovedClassUpdate with FletchFeatures { | 321 class DartinoRemovedClassUpdate extends RemovedClassUpdate with DartinoFeatures
{ |
322 FletchRemovedClassUpdate(Compiler compiler, PartialClassElement element) | 322 DartinoRemovedClassUpdate(Compiler compiler, PartialClassElement element) |
323 : super(compiler, element); | 323 : super(compiler, element); |
324 } | 324 } |
325 | 325 |
326 class FletchRemovedFieldUpdate extends RemovedFieldUpdate with FletchFeatures { | 326 class DartinoRemovedFieldUpdate extends RemovedFieldUpdate with DartinoFeatures
{ |
327 // TODO(ahe): Remove? | 327 // TODO(ahe): Remove? |
328 FletchClassBuilder beforeFletchClassBuilder; | 328 DartinoClassBuilder beforeDartinoClassBuilder; |
329 | 329 |
330 FletchRemovedFieldUpdate(Compiler compiler, FieldElementX element) | 330 DartinoRemovedFieldUpdate(Compiler compiler, FieldElementX element) |
331 : super(compiler, element); | 331 : super(compiler, element); |
332 } | 332 } |
333 | 333 |
334 class FletchAddedFunctionUpdate extends AddedFunctionUpdate | 334 class DartinoAddedFunctionUpdate extends AddedFunctionUpdate |
335 with FletchFeatures { | 335 with DartinoFeatures { |
336 FletchAddedFunctionUpdate( | 336 DartinoAddedFunctionUpdate( |
337 Compiler compiler, | 337 Compiler compiler, |
338 PartialFunctionElement element, | 338 PartialFunctionElement element, |
339 /* ScopeContainerElement */ container) | 339 /* ScopeContainerElement */ container) |
340 : super(compiler, element, container); | 340 : super(compiler, element, container); |
341 } | 341 } |
342 | 342 |
343 class FletchAddedClassUpdate extends AddedClassUpdate with FletchFeatures { | 343 class DartinoAddedClassUpdate extends AddedClassUpdate with DartinoFeatures { |
344 FletchAddedClassUpdate( | 344 DartinoAddedClassUpdate( |
345 Compiler compiler, | 345 Compiler compiler, |
346 PartialClassElement element, | 346 PartialClassElement element, |
347 LibraryElementX library) | 347 LibraryElementX library) |
348 : super(compiler, element, library); | 348 : super(compiler, element, library); |
349 } | 349 } |
350 | 350 |
351 class FletchAddedFieldUpdate extends AddedFieldUpdate with FletchFeatures { | 351 class DartinoAddedFieldUpdate extends AddedFieldUpdate with DartinoFeatures { |
352 FletchAddedFieldUpdate( | 352 DartinoAddedFieldUpdate( |
353 Compiler compiler, | 353 Compiler compiler, |
354 FieldElementX element, | 354 FieldElementX element, |
355 /* ScopeContainerElement */ container) | 355 /* ScopeContainerElement */ container) |
356 : super(compiler, element, container); | 356 : super(compiler, element, container); |
357 } | 357 } |
358 | 358 |
359 class FletchClassUpdate extends ClassUpdate with FletchFeatures { | 359 class DartinoClassUpdate extends ClassUpdate with DartinoFeatures { |
360 FletchClassUpdate( | 360 DartinoClassUpdate( |
361 Compiler compiler, | 361 Compiler compiler, |
362 PartialClassElement before, | 362 PartialClassElement before, |
363 PartialClassElement after) | 363 PartialClassElement after) |
364 : super(compiler, before, after); | 364 : super(compiler, before, after); |
365 } | 365 } |
366 | 366 |
367 abstract class FletchFeatures { | 367 abstract class DartinoFeatures { |
368 FletchCompilerImplementation get compiler; | 368 DartinoCompilerImplementation get compiler; |
369 | 369 |
370 IncrementalFletchBackend get backend { | 370 IncrementalDartinoBackend get backend { |
371 return compiler.backend as IncrementalFletchBackend; | 371 return compiler.backend as IncrementalDartinoBackend; |
372 } | 372 } |
373 | 373 |
374 EnqueueTask get enqueuer => compiler.enqueuer; | 374 EnqueueTask get enqueuer => compiler.enqueuer; |
375 | 375 |
376 FletchContext get fletchContext => compiler.context; | 376 DartinoContext get dartinoContext => compiler.context; |
377 | 377 |
378 FletchFunctionBuilder lookupFletchFunctionBuilder(FunctionElement function) { | 378 DartinoFunctionBuilder lookupDartinoFunctionBuilder(FunctionElement function)
{ |
379 return backend.systemBuilder.lookupFunctionBuilderByElement(function); | 379 return backend.systemBuilder.lookupFunctionBuilderByElement(function); |
380 } | 380 } |
381 } | 381 } |
OLD | NEW |