| 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 part of dart_backend; | 5 part of dart_backend; |
| 6 | 6 |
| 7 // TODO(ahe): This class is simply wrong. This backend should use | 7 // TODO(ahe): This class is simply wrong. This backend should use |
| 8 // elements when it can, not AST nodes. Perhaps a [Map<Element, | 8 // elements when it can, not AST nodes. Perhaps a [Map<Element, |
| 9 // TreeElements>] is what is needed. | 9 // TreeElements>] is what is needed. |
| 10 class ElementAst { | 10 class ElementAst { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 /// Initialized when dart:mirrors is loaded if the useMirrorHelperLibrary | 38 /// Initialized when dart:mirrors is loaded if the useMirrorHelperLibrary |
| 39 /// field is set. | 39 /// field is set. |
| 40 FunctionElement mirrorHelperGetNameFunction; | 40 FunctionElement mirrorHelperGetNameFunction; |
| 41 /// Initialized when dart:mirrors is loaded if the useMirrorHelperLibrary | 41 /// Initialized when dart:mirrors is loaded if the useMirrorHelperLibrary |
| 42 /// field is set. | 42 /// field is set. |
| 43 Element mirrorHelperSymbolsMap; | 43 Element mirrorHelperSymbolsMap; |
| 44 | 44 |
| 45 Map<Element, TreeElements> get resolvedElements => | 45 Map<Element, TreeElements> get resolvedElements => |
| 46 compiler.enqueuer.resolution.resolvedElements; | 46 compiler.enqueuer.resolution.resolvedElements; |
| 47 | 47 |
| 48 ConstantSystem get constantSystem { |
| 49 return constantCompilerTask.constantCompiler.constantSystem; |
| 50 } |
| 51 |
| 52 BackendConstantEnvironment get constants => constantCompilerTask; |
| 53 |
| 54 DartConstantTask constantCompilerTask; |
| 55 |
| 48 final Set<ClassElement> usedTypeLiterals = new Set<ClassElement>(); | 56 final Set<ClassElement> usedTypeLiterals = new Set<ClassElement>(); |
| 49 | 57 |
| 50 /** | 58 /** |
| 51 * Tells whether it is safe to remove type declarations from variables, | 59 * Tells whether it is safe to remove type declarations from variables, |
| 52 * functions parameters. It becomes not safe if: | 60 * functions parameters. It becomes not safe if: |
| 53 * 1) TypeError is used somewhere in the code, | 61 * 1) TypeError is used somewhere in the code, |
| 54 * 2) The code has typedefs in right hand side of IS checks, | 62 * 2) The code has typedefs in right hand side of IS checks, |
| 55 * 3) The code has classes which extend typedefs, have type arguments typedefs | 63 * 3) The code has classes which extend typedefs, have type arguments typedefs |
| 56 * or type variable bounds typedefs. | 64 * or type variable bounds typedefs. |
| 57 * These restrictions can be less strict. | 65 * These restrictions can be less strict. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 } | 99 } |
| 92 | 100 |
| 93 DartBackend(Compiler compiler, List<String> strips) | 101 DartBackend(Compiler compiler, List<String> strips) |
| 94 : tasks = <CompilerTask>[], | 102 : tasks = <CompilerTask>[], |
| 95 renames = new Map<Node, String>(), | 103 renames = new Map<Node, String>(), |
| 96 imports = new Map<LibraryElement, String>(), | 104 imports = new Map<LibraryElement, String>(), |
| 97 memberNodes = new Map<ClassNode, List<Node>>(), | 105 memberNodes = new Map<ClassNode, List<Node>>(), |
| 98 reexportingLibraries = <Element, LibraryElement>{}, | 106 reexportingLibraries = <Element, LibraryElement>{}, |
| 99 forceStripTypes = strips.indexOf('types') != -1, | 107 forceStripTypes = strips.indexOf('types') != -1, |
| 100 stripAsserts = strips.indexOf('asserts') != -1, | 108 stripAsserts = strips.indexOf('asserts') != -1, |
| 109 constantCompilerTask = new DartConstantTask(compiler), |
| 101 super(compiler); | 110 super(compiler); |
| 102 | 111 |
| 103 bool classNeedsRti(ClassElement cls) => false; | 112 bool classNeedsRti(ClassElement cls) => false; |
| 104 bool methodNeedsRti(FunctionElement function) => false; | 113 bool methodNeedsRti(FunctionElement function) => false; |
| 105 | 114 |
| 106 void enqueueHelpers(ResolutionEnqueuer world, TreeElements elements) { | 115 void enqueueHelpers(ResolutionEnqueuer world, TreeElements elements) { |
| 107 // Right now resolver doesn't always resolve interfaces needed | 116 // Right now resolver doesn't always resolve interfaces needed |
| 108 // for literals, so force them. TODO(antonm): fix in the resolver. | 117 // for literals, so force them. TODO(antonm): fix in the resolver. |
| 109 final LITERAL_TYPE_NAMES = const [ | 118 final LITERAL_TYPE_NAMES = const [ |
| 110 'Map', 'List', 'num', 'int', 'double', 'bool' | 119 'Map', 'List', 'num', 'int', 'double', 'bool' |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 } | 583 } |
| 575 | 584 |
| 576 compareElements(e0, e1) { | 585 compareElements(e0, e1) { |
| 577 int result = compareBy((e) => e.getLibrary().canonicalUri.toString())(e0, e1); | 586 int result = compareBy((e) => e.getLibrary().canonicalUri.toString())(e0, e1); |
| 578 if (result != 0) return result; | 587 if (result != 0) return result; |
| 579 return compareBy((e) => e.position().charOffset)(e0, e1); | 588 return compareBy((e) => e.position().charOffset)(e0, e1); |
| 580 } | 589 } |
| 581 | 590 |
| 582 List<Element> sortElements(Iterable<Element> elements) => | 591 List<Element> sortElements(Iterable<Element> elements) => |
| 583 sorted(elements, compareElements); | 592 sorted(elements, compareElements); |
| 593 |
| 594 /// [ConstantCompilerTask] for compilation of constants for the Dart backend. |
| 595 /// |
| 596 /// Since this task needs no distinction between frontend and backend constants |
| 597 /// it also serves as the [BackendConstantEnvironment]. |
| 598 class DartConstantTask extends ConstantCompilerTask |
| 599 implements BackendConstantEnvironment { |
| 600 final DartConstantCompiler constantCompiler; |
| 601 |
| 602 DartConstantTask(Compiler compiler) |
| 603 : this.constantCompiler = new DartConstantCompiler(compiler), |
| 604 super(compiler); |
| 605 |
| 606 String get name => 'ConstantHandler'; |
| 607 |
| 608 Constant getConstantForVariable(VariableElement element) { |
| 609 return constantCompiler.getConstantForVariable(element); |
| 610 } |
| 611 |
| 612 Constant getConstantForNode(Node node, TreeElements elements) { |
| 613 return constantCompiler.getConstantForNode(node, elements); |
| 614 } |
| 615 |
| 616 Constant getConstantForMetadata(MetadataAnnotation metadata) { |
| 617 return metadata.value; |
| 618 } |
| 619 |
| 620 Constant compileConstant(VariableElement element) { |
| 621 return measure(() { |
| 622 return constantCompiler.compileConstant(element); |
| 623 }); |
| 624 } |
| 625 |
| 626 void compileVariable(VariableElement element) { |
| 627 measure(() { |
| 628 constantCompiler.compileVariable(element); |
| 629 }); |
| 630 } |
| 631 |
| 632 Constant compileNode(Node node, TreeElements elements) { |
| 633 return measure(() { |
| 634 return constantCompiler.compileNodeWithDefinitions(node, elements); |
| 635 }); |
| 636 } |
| 637 |
| 638 Constant compileMetadata(MetadataAnnotation metadata, |
| 639 Node node, |
| 640 TreeElements elements) { |
| 641 return measure(() { |
| 642 return constantCompiler.compileMetadata(metadata, node, elements); |
| 643 }); |
| 644 } |
| 645 } |
| OLD | NEW |