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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/dart_backend/backend.dart

Issue 221873002: Compute frontend/backend specific constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Classes renamed and comments added. Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
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
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 /** 56 /**
49 * Tells whether it is safe to remove type declarations from variables, 57 * Tells whether it is safe to remove type declarations from variables,
50 * functions parameters. It becomes not safe if: 58 * functions parameters. It becomes not safe if:
51 * 1) TypeError is used somewhere in the code, 59 * 1) TypeError is used somewhere in the code,
52 * 2) The code has typedefs in right hand side of IS checks, 60 * 2) The code has typedefs in right hand side of IS checks,
53 * 3) The code has classes which extend typedefs, have type arguments typedefs 61 * 3) The code has classes which extend typedefs, have type arguments typedefs
54 * or type variable bounds typedefs. 62 * or type variable bounds typedefs.
55 * These restrictions can be less strict. 63 * These restrictions can be less strict.
56 */ 64 */
57 bool isSafeToRemoveTypeDeclarations( 65 bool isSafeToRemoveTypeDeclarations(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 97 }
90 98
91 DartBackend(Compiler compiler, List<String> strips) 99 DartBackend(Compiler compiler, List<String> strips)
92 : tasks = <CompilerTask>[], 100 : tasks = <CompilerTask>[],
93 renames = new Map<Node, String>(), 101 renames = new Map<Node, String>(),
94 imports = new Map<LibraryElement, String>(), 102 imports = new Map<LibraryElement, String>(),
95 memberNodes = new Map<ClassNode, List<Node>>(), 103 memberNodes = new Map<ClassNode, List<Node>>(),
96 reexportingLibraries = <Element, LibraryElement>{}, 104 reexportingLibraries = <Element, LibraryElement>{},
97 forceStripTypes = strips.indexOf('types') != -1, 105 forceStripTypes = strips.indexOf('types') != -1,
98 stripAsserts = strips.indexOf('asserts') != -1, 106 stripAsserts = strips.indexOf('asserts') != -1,
107 constantCompilerTask = new DartConstantTask(compiler),
99 super(compiler); 108 super(compiler);
100 109
101 bool classNeedsRti(ClassElement cls) => false; 110 bool classNeedsRti(ClassElement cls) => false;
102 bool methodNeedsRti(FunctionElement function) => false; 111 bool methodNeedsRti(FunctionElement function) => false;
103 112
104 void enqueueHelpers(ResolutionEnqueuer world, TreeElements elements) { 113 void enqueueHelpers(ResolutionEnqueuer world, TreeElements elements) {
105 // Right now resolver doesn't always resolve interfaces needed 114 // Right now resolver doesn't always resolve interfaces needed
106 // for literals, so force them. TODO(antonm): fix in the resolver. 115 // for literals, so force them. TODO(antonm): fix in the resolver.
107 final LITERAL_TYPE_NAMES = const [ 116 final LITERAL_TYPE_NAMES = const [
108 'Map', 'List', 'num', 'int', 'double', 'bool' 117 'Map', 'List', 'num', 'int', 'double', 'bool'
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 } 558 }
550 559
551 compareElements(e0, e1) { 560 compareElements(e0, e1) {
552 int result = compareBy((e) => e.getLibrary().canonicalUri.toString())(e0, e1); 561 int result = compareBy((e) => e.getLibrary().canonicalUri.toString())(e0, e1);
553 if (result != 0) return result; 562 if (result != 0) return result;
554 return compareBy((e) => e.position().charOffset)(e0, e1); 563 return compareBy((e) => e.position().charOffset)(e0, e1);
555 } 564 }
556 565
557 List<Element> sortElements(Iterable<Element> elements) => 566 List<Element> sortElements(Iterable<Element> elements) =>
558 sorted(elements, compareElements); 567 sorted(elements, compareElements);
568
569 /// [ConstantCompilerTask] for compilation of constants for the Dart backend.
570 ///
571 /// Since this task needs no distinction between frontend and backend constants
572 /// it also serves as the [BackendConstantEnvironment].
573 class DartConstantTask extends ConstantCompilerTask
574 implements BackendConstantEnvironment {
575 final DartConstantCompiler constantCompiler;
576
577 DartConstantTask(Compiler compiler)
578 : this.constantCompiler = new DartConstantCompiler(compiler),
579 super(compiler);
580
581 String get name => 'ConstantHandler';
582
583 Constant getConstantForVariable(VariableElement element) {
584 return constantCompiler.getConstantForVariable(element);
585 }
586
587 Constant getConstantForNode(Node node, TreeElements elements) {
588 return constantCompiler.getConstantForNode(node, elements);
589 }
590
591 Constant getConstantForMetadata(MetadataAnnotation metadata) {
592 return metadata.value;
593 }
594
595 Constant compileConstant(VariableElement element) {
596 return measure(() {
597 return constantCompiler.compileConstant(element);
598 });
599 }
600
601 void compileVariable(VariableElement element) {
602 measure(() {
603 constantCompiler.compileVariable(element);
604 });
605 }
606
607 Constant compileNode(Node node, TreeElements elements) {
608 return measure(() {
609 return constantCompiler.compileNodeWithDefinitions(node, elements);
610 });
611 }
612
613 Constant compileMetadata(MetadataAnnotation metadata,
614 Node node,
615 TreeElements elements) {
616 return measure(() {
617 return constantCompiler.compileMetadata(metadata, node, elements);
618 });
619 }
620 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698