Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart 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 file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class WorkItem { | 5 class WorkItem { |
| 6 final Element element; | 6 final Element element; |
| 7 TreeElements resolutionTree; | 7 TreeElements resolutionTree; |
| 8 Function run; | 8 Function run; |
| 9 bool allowSpeculativeOptimization = true; | 9 bool allowSpeculativeOptimization = true; |
| 10 List<HTypeGuard> guards = const <HTypeGuard>[]; | 10 List<HTypeGuard> guards = const <HTypeGuard>[]; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 } | 26 } |
| 27 | 27 |
| 28 String codegen(Compiler compiler) { | 28 String codegen(Compiler compiler) { |
| 29 return compiler.codegen(this); | 29 return compiler.codegen(this); |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 | 32 |
| 33 class Compiler implements DiagnosticListener { | 33 class Compiler implements DiagnosticListener { |
| 34 Queue<WorkItem> worklist; | 34 Queue<WorkItem> worklist; |
| 35 Universe universe; | 35 Universe universe; |
| 36 World world; | |
| 36 String assembledCode; | 37 String assembledCode; |
| 37 Namer namer; | 38 Namer namer; |
| 38 Types types; | 39 Types types; |
| 39 bool enableTypeAssertions = false; | 40 bool enableTypeAssertions = false; |
| 40 | 41 |
| 41 final Tracer tracer; | 42 final Tracer tracer; |
| 42 | 43 |
| 43 CompilerTask measuredTask; | 44 CompilerTask measuredTask; |
| 44 Element _currentElement; | 45 Element _currentElement; |
| 45 LibraryElement coreLibrary; | 46 LibraryElement coreLibrary; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 static final SourceString START_ROOT_ISOLATE = | 94 static final SourceString START_ROOT_ISOLATE = |
| 94 const SourceString('startRootIsolate'); | 95 const SourceString('startRootIsolate'); |
| 95 bool enabledNoSuchMethod = false; | 96 bool enabledNoSuchMethod = false; |
| 96 | 97 |
| 97 bool workListIsClosed = false; | 98 bool workListIsClosed = false; |
| 98 | 99 |
| 99 Stopwatch codegenProgress; | 100 Stopwatch codegenProgress; |
| 100 | 101 |
| 101 Compiler([this.tracer = const Tracer()]) | 102 Compiler([this.tracer = const Tracer()]) |
| 102 : universe = new Universe(), | 103 : universe = new Universe(), |
| 104 world = new World(), | |
| 103 worklist = new Queue<WorkItem>(), | 105 worklist = new Queue<WorkItem>(), |
| 104 codegenProgress = new Stopwatch.start() { | 106 codegenProgress = new Stopwatch.start() { |
| 105 namer = new Namer(this); | 107 namer = new Namer(this); |
| 106 constantHandler = new ConstantHandler(this); | 108 constantHandler = new ConstantHandler(this); |
| 107 scanner = new ScannerTask(this); | 109 scanner = new ScannerTask(this); |
| 108 dietParser = new DietParserTask(this); | 110 dietParser = new DietParserTask(this); |
| 109 parser = new ParserTask(this); | 111 parser = new ParserTask(this); |
| 110 validator = new TreeValidatorTask(this); | 112 validator = new TreeValidatorTask(this); |
| 111 resolver = new ResolverTask(this); | 113 resolver = new ResolverTask(this); |
| 112 checker = new TypeCheckerTask(this); | 114 checker = new TypeCheckerTask(this); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 cancel('main is not a function', element: main); | 295 cancel('main is not a function', element: main); |
| 294 } | 296 } |
| 295 FunctionElement mainMethod = main; | 297 FunctionElement mainMethod = main; |
| 296 FunctionSignature parameters = mainMethod.computeSignature(this); | 298 FunctionSignature parameters = mainMethod.computeSignature(this); |
| 297 if (parameters.parameterCount > 0) { | 299 if (parameters.parameterCount > 0) { |
| 298 cancel('main cannot have parameters', element: mainMethod); | 300 cancel('main cannot have parameters', element: mainMethod); |
| 299 } | 301 } |
| 300 }); | 302 }); |
| 301 } | 303 } |
| 302 native.processNativeClasses(this, universe.libraries.getValues()); | 304 native.processNativeClasses(this, universe.libraries.getValues()); |
| 305 computeSubclasses(); | |
|
kasperl
2012/05/09 11:13:03
Could we move this code to world? That would seem
ngeoffray
2012/05/09 11:34:22
Done.
| |
| 303 enqueue(new WorkItem.toCompile(main)); | 306 enqueue(new WorkItem.toCompile(main)); |
| 304 codegenProgress.reset(); | 307 codegenProgress.reset(); |
| 305 while (!worklist.isEmpty()) { | 308 while (!worklist.isEmpty()) { |
| 306 WorkItem work = worklist.removeLast(); | 309 WorkItem work = worklist.removeLast(); |
| 307 withCurrentElement(work.element, () => (work.run)(this)); | 310 withCurrentElement(work.element, () => (work.run)(this)); |
| 308 } | 311 } |
| 309 workListIsClosed = true; | 312 workListIsClosed = true; |
| 310 assert(enqueuer.checkNoEnqueuedInvokedInstanceMethods()); | 313 assert(enqueuer.checkNoEnqueuedInvokedInstanceMethods()); |
| 311 enqueuer.registerFieldClosureInvocations(); | 314 enqueuer.registerFieldClosureInvocations(); |
| 312 emitter.assembleProgram(); | 315 emitter.assembleProgram(); |
| 313 if (!worklist.isEmpty()) { | 316 if (!worklist.isEmpty()) { |
| 314 internalErrorOnElement(worklist.first().element, | 317 internalErrorOnElement(worklist.first().element, |
| 315 "work list is not empty"); | 318 "work list is not empty"); |
| 316 } | 319 } |
| 317 } | 320 } |
| 318 | 321 |
| 322 void addSubtypes(ClassElement cls) { | |
| 323 for (Type type in cls.allSupertypes) { | |
| 324 List<Element> subtypes = world.subtypes.putIfAbsent( | |
| 325 type.element, | |
| 326 () => <ClassElement>[]); | |
| 327 subtypes.add(cls); | |
| 328 } | |
| 329 } | |
| 330 | |
| 331 void computeSubclasses() { | |
| 332 universe.libraries.getValues().forEach((LibraryElement library) { | |
| 333 for (Link<Element> link = library.topLevelElements; | |
| 334 !link.isEmpty(); | |
| 335 link = link.tail) { | |
| 336 Element element = link.head; | |
| 337 if (!element.isClass()) continue; | |
| 338 ClassElement cls = element; | |
| 339 resolveClass(cls); | |
| 340 addSubtypes(cls); | |
| 341 } | |
| 342 }); | |
| 343 } | |
| 344 | |
| 319 TreeElements analyzeElement(Element element) { | 345 TreeElements analyzeElement(Element element) { |
| 320 assert(parser !== null); | 346 assert(parser !== null); |
| 321 Node tree = parser.parse(element); | 347 Node tree = parser.parse(element); |
| 322 validator.validate(tree); | 348 validator.validate(tree); |
| 323 TreeElements elements = resolver.resolve(element); | 349 TreeElements elements = resolver.resolve(element); |
| 324 checker.check(tree, elements); | 350 checker.check(tree, elements); |
| 325 return elements; | 351 return elements; |
| 326 } | 352 } |
| 327 | 353 |
| 328 TreeElements analyze(WorkItem work) { | 354 TreeElements analyze(WorkItem work) { |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 568 } | 594 } |
| 569 } | 595 } |
| 570 | 596 |
| 571 class SourceSpan { | 597 class SourceSpan { |
| 572 final Uri uri; | 598 final Uri uri; |
| 573 final int begin; | 599 final int begin; |
| 574 final int end; | 600 final int end; |
| 575 | 601 |
| 576 const SourceSpan(this.uri, this.begin, this.end); | 602 const SourceSpan(this.uri, this.begin, this.end); |
| 577 } | 603 } |
| OLD | NEW |