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: dart/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart

Issue 16101007: Implement LibraryMirror.metadata. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix issues found during testing. Created 7 years, 6 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 dart2js; 5 part of dart2js;
6 6
7 /** 7 /**
8 * The [ConstantHandler] keeps track of compile-time constants, 8 * The [ConstantHandler] keeps track of compile-time constants,
9 * initializations of global and static fields, and default values of 9 * initializations of global and static fields, and default values of
10 * optional parameters. 10 * optional parameters.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 compiledConstants.add(constant); 55 compiledConstants.add(constant);
56 } 56 }
57 57
58 void registerInstantiatedClass(ClassElement element, TreeElements elements) { 58 void registerInstantiatedClass(ClassElement element, TreeElements elements) {
59 if (isMetadata) return; 59 if (isMetadata) return;
60 compiler.enqueuer.codegen.registerInstantiatedClass(element, elements); 60 compiler.enqueuer.codegen.registerInstantiatedClass(element, elements);
61 } 61 }
62 62
63 void registerStaticUse(Element element) { 63 void registerStaticUse(Element element) {
64 if (isMetadata) return; 64 if (isMetadata) return;
65 compiler.analyzeElement(element.declaration);
65 compiler.enqueuer.codegen.registerStaticUse(element); 66 compiler.enqueuer.codegen.registerStaticUse(element);
66 } 67 }
67 68
68 void registerGetOfStaticFunction(FunctionElement element) { 69 void registerGetOfStaticFunction(FunctionElement element) {
69 if (isMetadata) return; 70 if (isMetadata) return;
71 compiler.analyzeElement(element.declaration);
70 compiler.enqueuer.codegen.registerGetOfStaticFunction(element); 72 compiler.enqueuer.codegen.registerGetOfStaticFunction(element);
71 } 73 }
72 74
73 void registerStringInstance(TreeElements elements) { 75 void registerStringInstance(TreeElements elements) {
74 registerInstantiatedClass(compiler.stringClass, elements); 76 registerInstantiatedClass(compiler.stringClass, elements);
75 } 77 }
76 78
77 void registerCreateRuntimeTypeFunction() { 79 void registerCreateRuntimeTypeFunction() {
78 if (createRuntimeTypeFunction != null) return; 80 if (createRuntimeTypeFunction != null) return;
79 SourceString helperName = const SourceString('createRuntimeType'); 81 SourceString helperName = const SourceString('createRuntimeType');
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 * Returns the a compile-time constant if the variable could be compiled 119 * Returns the a compile-time constant if the variable could be compiled
118 * eagerly. Otherwise returns `null`. 120 * eagerly. Otherwise returns `null`.
119 */ 121 */
120 Constant compileVariable(VariableElement element, {bool isConst: false}) { 122 Constant compileVariable(VariableElement element, {bool isConst: false}) {
121 return measure(() { 123 return measure(() {
122 if (initialVariableValues.containsKey(element)) { 124 if (initialVariableValues.containsKey(element)) {
123 Constant result = initialVariableValues[element]; 125 Constant result = initialVariableValues[element];
124 return result; 126 return result;
125 } 127 }
126 return compiler.withCurrentElement(element, () { 128 return compiler.withCurrentElement(element, () {
127 TreeElements definitions = compiler.analyzeElement(element); 129 TreeElements definitions = compiler.analyzeElement(element.declaration);
128 Constant constant = compileVariableWithDefinitions( 130 Constant constant = compileVariableWithDefinitions(
129 element, definitions, isConst: isConst); 131 element, definitions, isConst: isConst);
130 return constant; 132 return constant;
131 }); 133 });
132 }); 134 });
133 } 135 }
134 136
135 /** 137 /**
136 * Returns the a compile-time constant if the variable could be compiled 138 * Returns the a compile-time constant if the variable could be compiled
137 * eagerly. If the variable needs to be initialized lazily returns `null`. 139 * eagerly. If the variable needs to be initialized lazily returns `null`.
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 return compiledArguments; 640 return compiledArguments;
639 } 641 }
640 642
641 Constant visitNewExpression(NewExpression node) { 643 Constant visitNewExpression(NewExpression node) {
642 if (!node.isConst()) { 644 if (!node.isConst()) {
643 return signalNotCompileTimeConstant(node); 645 return signalNotCompileTimeConstant(node);
644 } 646 }
645 647
646 Send send = node.send; 648 Send send = node.send;
647 FunctionElement constructor = elements[send]; 649 FunctionElement constructor = elements[send];
650 // TODO(ahe): This is nasty: we must eagerly analyze the
651 // constructor to ensure the redirectionTarget has been computed
652 // correctly. Find a way to avoid this.
653 compiler.analyzeElement(constructor.declaration);
648 constructor = constructor.redirectionTarget; 654 constructor = constructor.redirectionTarget;
649 ClassElement classElement = constructor.getEnclosingClass(); 655 ClassElement classElement = constructor.getEnclosingClass();
650 // The constructor must be an implementation to ensure that field 656 // The constructor must be an implementation to ensure that field
651 // initializers are handled correctly. 657 // initializers are handled correctly.
652 constructor = constructor.implementation; 658 constructor = constructor.implementation;
653 assert(invariant(node, constructor.isImplementation)); 659 assert(invariant(node, constructor.isImplementation));
654 660
655 Selector selector = elements.getSelector(send); 661 Selector selector = elements.getSelector(send);
656 List<Constant> arguments = evaluateArgumentsToConstructor( 662 List<Constant> arguments = evaluateArgumentsToConstructor(
657 node, selector, send.arguments, constructor); 663 node, selector, send.arguments, constructor);
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 if (fieldValue == null) { 887 if (fieldValue == null) {
882 // Use the default value. 888 // Use the default value.
883 fieldValue = handler.compileConstant(field); 889 fieldValue = handler.compileConstant(field);
884 } 890 }
885 jsNewArguments.add(fieldValue); 891 jsNewArguments.add(fieldValue);
886 }, 892 },
887 includeSuperAndInjectedMembers: true); 893 includeSuperAndInjectedMembers: true);
888 return jsNewArguments; 894 return jsNewArguments;
889 } 895 }
890 } 896 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698