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

Side by Side Diff: dart/lib/compiler/implementation/elements/elements.dart

Issue 10870010: Evaluate compile-time constants of metadata. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased and use const instead of final Created 8 years, 4 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 #library('elements'); 5 #library('elements');
6 6
7 #import('dart:uri'); 7 #import('dart:uri');
8 8
9 #import('../tree/tree.dart'); 9 #import('../tree/tree.dart');
10 #import('../scanner/scannerlib.dart'); 10 #import('../scanner/scannerlib.dart');
11 #import('../leg.dart'); // TODO(karlklose): we only need type. 11 #import('../leg.dart'); // TODO(karlklose): we only need type.
12 #import('../util/util.dart'); 12 #import('../util/util.dart');
13 13
14 const int STATE_NOT_STARTED = 0;
15 const int STATE_STARTED = 1;
16 const int STATE_DONE = 2;
17
14 class ElementCategory { 18 class ElementCategory {
15 /** 19 /**
16 * Represents things that we don't expect to find when looking in a 20 * Represents things that we don't expect to find when looking in a
17 * scope. 21 * scope.
18 */ 22 */
19 static final int NONE = 0; 23 static final int NONE = 0;
20 24
21 /** Field, parameter, or variable. */ 25 /** Field, parameter, or variable. */
22 static final int VARIABLE = 1; 26 static final int VARIABLE = 1;
23 27
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 120
117 Node parseNode(DiagnosticListener listener) { 121 Node parseNode(DiagnosticListener listener) {
118 listener.cancel("Internal Error: $this.parseNode", token: position()); 122 listener.cancel("Internal Error: $this.parseNode", token: position());
119 } 123 }
120 124
121 Type computeType(Compiler compiler) { 125 Type computeType(Compiler compiler) {
122 compiler.internalError("$this.computeType.", token: position()); 126 compiler.internalError("$this.computeType.", token: position());
123 } 127 }
124 128
125 void addMetadata(MetadataAnnotation annotation) { 129 void addMetadata(MetadataAnnotation annotation) {
130 assert(annotation.annotatedElement === null);
131 annotation.annotatedElement = this;
126 metadata = metadata.prepend(annotation); 132 metadata = metadata.prepend(annotation);
127 } 133 }
128 134
129 bool isFunction() => kind === ElementKind.FUNCTION; 135 bool isFunction() => kind === ElementKind.FUNCTION;
130 bool isConstructor() => isFactoryConstructor() || isGenerativeConstructor(); 136 bool isConstructor() => isFactoryConstructor() || isGenerativeConstructor();
131 bool isClosure() => false; 137 bool isClosure() => false;
132 bool isMember() { 138 bool isMember() {
133 // Check that this element is defined in the scope of a Class. 139 // Check that this element is defined in the scope of a Class.
134 Element enclosing = enclosingElement; 140 Element enclosing = enclosingElement;
135 if (enclosing !== null && 141 if (enclosing !== null &&
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 TypeVariableType variableType = new TypeVariableType(variableElement); 1080 TypeVariableType variableType = new TypeVariableType(variableElement);
1075 variableElement.type = variableType; 1081 variableElement.type = variableType;
1076 arguments.addLast(variableType); 1082 arguments.addLast(variableType);
1077 } 1083 }
1078 return arguments.toLink(); 1084 return arguments.toLink();
1079 } 1085 }
1080 } 1086 }
1081 1087
1082 class ClassElement extends ScopeContainerElement 1088 class ClassElement extends ScopeContainerElement
1083 implements TypeDeclarationElement { 1089 implements TypeDeclarationElement {
1084 static final int STATE_NOT_STARTED = 0;
1085 static final int STATE_STARTED = 1;
1086 static final int STATE_DONE = 2;
1087
1088 final int id; 1090 final int id;
1089 InterfaceType type; 1091 InterfaceType type;
1090 Type supertype; 1092 Type supertype;
1091 Type defaultClass; 1093 Type defaultClass;
1092 Link<Type> interfaces; 1094 Link<Type> interfaces;
1093 SourceString nativeName; 1095 SourceString nativeName;
1094 int supertypeLoadState; 1096 int supertypeLoadState;
1095 int resolutionState; 1097 int resolutionState;
1096 1098
1097 // backendMembers are members that have been added by the backend to simplify 1099 // backendMembers are members that have been added by the backend to simplify
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
1606 * are the same compile-time constant, [: const Data() :]. 1608 * are the same compile-time constant, [: const Data() :].
1607 * 1609 *
1608 * The mirror system does not have a concept matching this class. 1610 * The mirror system does not have a concept matching this class.
1609 */ 1611 */
1610 class MetadataAnnotation { 1612 class MetadataAnnotation {
1611 /** 1613 /**
1612 * The compile-time constant which this annotation resolves to. 1614 * The compile-time constant which this annotation resolves to.
1613 * In the mirror system, this would be an object mirror. 1615 * In the mirror system, this would be an object mirror.
1614 */ 1616 */
1615 abstract Constant get value(); 1617 abstract Constant get value();
1618 Element annotatedElement;
1619 int resolutionState;
1616 1620
1617 // TODO(ahe): Add more functionality as needed. 1621 MetadataAnnotation([this.resolutionState = STATE_NOT_STARTED]);
1622
1623 abstract Node parseNode(DiagnosticListener listener);
1624
1625 MetadataAnnotation ensureResolved(Compiler compiler) {
1626 if (resolutionState == STATE_NOT_STARTED) {
1627 compiler.resolver.resolveMetadataAnnotation(this);
1628 }
1629 return this;
1630 }
1631
1632 String toString() => 'MetadataAnnotation($value, $resolutionState)';
1618 } 1633 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698