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

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

Issue 10996062: Use static final empty Modifier instead of null. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Missing uses fixed. Created 8 years, 2 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');
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 class Element implements Spannable { 110 class Element implements Spannable {
111 final SourceString name; 111 final SourceString name;
112 final ElementKind kind; 112 final ElementKind kind;
113 final Element enclosingElement; 113 final Element enclosingElement;
114 Link<MetadataAnnotation> metadata = const EmptyLink<MetadataAnnotation>(); 114 Link<MetadataAnnotation> metadata = const EmptyLink<MetadataAnnotation>();
115 115
116 Element(this.name, this.kind, this.enclosingElement) { 116 Element(this.name, this.kind, this.enclosingElement) {
117 assert(getLibrary() !== null); 117 assert(getLibrary() !== null);
118 } 118 }
119 119
120 Modifiers get modifiers => null; 120 Modifiers get modifiers => Modifiers.EMPTY;
121 121
122 Node parseNode(DiagnosticListener listener) { 122 Node parseNode(DiagnosticListener listener) {
123 listener.cancel("Internal Error: $this.parseNode", token: position()); 123 listener.cancel("Internal Error: $this.parseNode", token: position());
124 } 124 }
125 125
126 DartType computeType(Compiler compiler) { 126 DartType computeType(Compiler compiler) {
127 compiler.internalError("$this.computeType.", token: position()); 127 compiler.internalError("$this.computeType.", token: position());
128 } 128 }
129 129
130 void addMetadata(MetadataAnnotation annotation) { 130 void addMetadata(MetadataAnnotation annotation) {
131 assert(annotation.annotatedElement === null); 131 assert(annotation.annotatedElement === null);
132 annotation.annotatedElement = this; 132 annotation.annotatedElement = this;
133 metadata = metadata.prepend(annotation); 133 metadata = metadata.prepend(annotation);
134 } 134 }
135 135
136 bool isFunction() => kind === ElementKind.FUNCTION; 136 bool isFunction() => kind === ElementKind.FUNCTION;
137 bool isConstructor() => isFactoryConstructor() || isGenerativeConstructor(); 137 bool isConstructor() => isFactoryConstructor() || isGenerativeConstructor();
138 bool isClosure() => false; 138 bool isClosure() => false;
139 bool isMember() { 139 bool isMember() {
140 // Check that this element is defined in the scope of a Class. 140 // Check that this element is defined in the scope of a Class.
141 Element enclosing = enclosingElement; 141 Element enclosing = enclosingElement;
142 if (enclosing !== null && 142 if (enclosing !== null &&
143 enclosing.kind === ElementKind.COMPILATION_UNIT_OVERRIDE) { 143 enclosing.kind === ElementKind.COMPILATION_UNIT_OVERRIDE) {
144 enclosing = enclosing.enclosingElement; 144 enclosing = enclosing.enclosingElement;
145 } 145 }
146 return enclosing !== null && enclosing.isClass(); 146 return enclosing !== null && enclosing.isClass();
147 } 147 }
148 bool isInstanceMember() => false; 148 bool isInstanceMember() => false;
149 bool isFactoryConstructor() => modifiers !== null && modifiers.isFactory(); 149 bool isFactoryConstructor() => modifiers.isFactory();
150 bool isGenerativeConstructor() => kind === ElementKind.GENERATIVE_CONSTRUCTOR; 150 bool isGenerativeConstructor() => kind === ElementKind.GENERATIVE_CONSTRUCTOR;
151 bool isGenerativeConstructorBody() => 151 bool isGenerativeConstructorBody() =>
152 kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY; 152 kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY;
153 bool isCompilationUnit() => kind === ElementKind.COMPILATION_UNIT; 153 bool isCompilationUnit() => kind === ElementKind.COMPILATION_UNIT;
154 bool isClass() => kind === ElementKind.CLASS; 154 bool isClass() => kind === ElementKind.CLASS;
155 bool isPrefix() => kind === ElementKind.PREFIX; 155 bool isPrefix() => kind === ElementKind.PREFIX;
156 bool isVariable() => kind === ElementKind.VARIABLE; 156 bool isVariable() => kind === ElementKind.VARIABLE;
157 bool isParameter() => kind === ElementKind.PARAMETER; 157 bool isParameter() => kind === ElementKind.PARAMETER;
158 bool isStatement() => kind === ElementKind.STATEMENT; 158 bool isStatement() => kind === ElementKind.STATEMENT;
159 bool isTypedef() => kind === ElementKind.TYPEDEF; 159 bool isTypedef() => kind === ElementKind.TYPEDEF;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 222
223 // TODO(johnniwinther): This breaks for libraries (for which enclosing 223 // TODO(johnniwinther): This breaks for libraries (for which enclosing
224 // elements are null) and is invalid for top level variable declarations for 224 // elements are null) and is invalid for top level variable declarations for
225 // which the enclosing element is a VariableDeclarations and not a compilation 225 // which the enclosing element is a VariableDeclarations and not a compilation
226 // unit. 226 // unit.
227 bool isTopLevel() { 227 bool isTopLevel() {
228 return enclosingElement !== null && enclosingElement.isCompilationUnit(); 228 return enclosingElement !== null && enclosingElement.isCompilationUnit();
229 } 229 }
230 230
231 bool isAssignable() { 231 bool isAssignable() {
232 if (modifiers != null && modifiers.isFinalOrConst()) return false; 232 if (modifiers.isFinalOrConst()) return false;
233 if (isFunction() || isGenerativeConstructor()) return false; 233 if (isFunction() || isGenerativeConstructor()) return false;
234 return true; 234 return true;
235 } 235 }
236 236
237 Token position() => null; 237 Token position() => null;
238 238
239 Token findMyName(Token token) { 239 Token findMyName(Token token) {
240 for (Token t = token; t.kind !== EOF_TOKEN; t = t.next) { 240 for (Token t = token; t.kind !== EOF_TOKEN; t = t.next) {
241 if (t.value == name) return t; 241 if (t.value == name) return t;
242 } 242 }
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 FunctionSignature functionSignature; 798 FunctionSignature functionSignature;
799 799
800 VariableListElement(ElementKind kind, 800 VariableListElement(ElementKind kind,
801 Modifiers this.modifiers, 801 Modifiers this.modifiers,
802 Element enclosing) 802 Element enclosing)
803 : super(null, kind, enclosing); 803 : super(null, kind, enclosing);
804 804
805 VariableListElement.node(VariableDefinitions node, 805 VariableListElement.node(VariableDefinitions node,
806 ElementKind kind, 806 ElementKind kind,
807 Element enclosing) 807 Element enclosing)
808 : super(null, kind, enclosing), 808 : super(null, kind, enclosing),
809 this.cachedNode = node, 809 this.cachedNode = node,
810 this.modifiers = node.modifiers; 810 this.modifiers = node.modifiers {
811 assert(modifiers !== null);
812 }
811 813
812 VariableDefinitions parseNode(DiagnosticListener listener) { 814 VariableDefinitions parseNode(DiagnosticListener listener) {
813 return cachedNode; 815 return cachedNode;
814 } 816 }
815 817
816 DartType computeType(Compiler compiler) { 818 DartType computeType(Compiler compiler) {
817 if (type != null) return type; 819 if (type != null) return type;
818 compiler.withCurrentElement(this, () { 820 compiler.withCurrentElement(this, () {
819 VariableDefinitions node = parseNode(compiler); 821 VariableDefinitions node = parseNode(compiler);
820 if (node.type !== null) { 822 if (node.type !== null) {
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 other.modifiers, enclosing, 1040 other.modifiers, enclosing,
1039 other.functionSignature); 1041 other.functionSignature);
1040 1042
1041 FunctionElement.tooMuchOverloading(SourceString name, 1043 FunctionElement.tooMuchOverloading(SourceString name,
1042 FunctionExpression this.cachedNode, 1044 FunctionExpression this.cachedNode,
1043 ElementKind kind, 1045 ElementKind kind,
1044 Modifiers this.modifiers, 1046 Modifiers this.modifiers,
1045 Element enclosing, 1047 Element enclosing,
1046 FunctionSignature this.functionSignature) 1048 FunctionSignature this.functionSignature)
1047 : super(name, kind, enclosing) { 1049 : super(name, kind, enclosing) {
1050 assert(modifiers !== null);
1048 defaultImplementation = this; 1051 defaultImplementation = this;
1049 } 1052 }
1050 1053
1051 bool get isPatched => patch !== null; 1054 bool get isPatched => patch !== null;
1052 1055
1053 /** 1056 /**
1054 * Applies a patch function to this function. The patch function's body 1057 * Applies a patch function to this function. The patch function's body
1055 * is used as replacement when parsing this function's body. 1058 * is used as replacement when parsing this function's body.
1056 * This method must not be called after the function has been parsed, 1059 * This method must not be called after the function has been parsed,
1057 * and it must be called at most once. 1060 * and it must be called at most once.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 FunctionType computeType(Compiler compiler) { 1096 FunctionType computeType(Compiler compiler) {
1094 if (type != null) return type; 1097 if (type != null) return type;
1095 type = compiler.computeFunctionType(declaration, 1098 type = compiler.computeFunctionType(declaration,
1096 computeSignature(compiler)); 1099 computeSignature(compiler));
1097 return type; 1100 return type;
1098 } 1101 }
1099 1102
1100 Node parseNode(DiagnosticListener listener) { 1103 Node parseNode(DiagnosticListener listener) {
1101 if (cachedNode !== null) return cachedNode; 1104 if (cachedNode !== null) return cachedNode;
1102 if (patch === null) { 1105 if (patch === null) {
1103 if (modifiers != null && modifiers.isExternal()) { 1106 if (modifiers.isExternal()) {
1104 listener.cancel("Compiling external function with no implementation.", 1107 listener.cancel("Compiling external function with no implementation.",
1105 element: this); 1108 element: this);
1106 } 1109 }
1107 return null; 1110 return null;
1108 } 1111 }
1109 cachedNode = patch.parseNode(listener); 1112 cachedNode = patch.parseNode(listener);
1110 return cachedNode; 1113 return cachedNode;
1111 } 1114 }
1112 1115
1113 Token position() => cachedNode.getBeginToken(); 1116 Token position() => cachedNode.getBeginToken();
(...skipping 21 matching lines...) Expand all
1135 } 1138 }
1136 } 1139 }
1137 1140
1138 class ConstructorBodyElement extends FunctionElement { 1141 class ConstructorBodyElement extends FunctionElement {
1139 FunctionElement constructor; 1142 FunctionElement constructor;
1140 1143
1141 ConstructorBodyElement(FunctionElement constructor) 1144 ConstructorBodyElement(FunctionElement constructor)
1142 : this.constructor = constructor, 1145 : this.constructor = constructor,
1143 super(constructor.name, 1146 super(constructor.name,
1144 ElementKind.GENERATIVE_CONSTRUCTOR_BODY, 1147 ElementKind.GENERATIVE_CONSTRUCTOR_BODY,
1145 null, 1148 Modifiers.EMPTY,
1146 constructor.enclosingElement) { 1149 constructor.enclosingElement) {
1147 functionSignature = constructor.functionSignature; 1150 functionSignature = constructor.functionSignature;
1148 } 1151 }
1149 1152
1150 bool isInstanceMember() => true; 1153 bool isInstanceMember() => true;
1151 1154
1152 FunctionType computeType(Compiler compiler) { 1155 FunctionType computeType(Compiler compiler) {
1153 compiler.reportFatalError('Internal error: $this.computeType', this); 1156 compiler.reportFatalError('Internal error: $this.computeType', this);
1154 } 1157 }
1155 1158
(...skipping 10 matching lines...) Expand all
1166 DiagnosticListener listener) { 1169 DiagnosticListener listener) {
1167 ConstructorBodyElement result = 1170 ConstructorBodyElement result =
1168 new ConstructorBodyElement(constructor.cloneTo(enclosing, listener)); 1171 new ConstructorBodyElement(constructor.cloneTo(enclosing, listener));
1169 return result; 1172 return result;
1170 } 1173 }
1171 } 1174 }
1172 1175
1173 class SynthesizedConstructorElement extends FunctionElement { 1176 class SynthesizedConstructorElement extends FunctionElement {
1174 SynthesizedConstructorElement(Element enclosing) 1177 SynthesizedConstructorElement(Element enclosing)
1175 : super(enclosing.name, ElementKind.GENERATIVE_CONSTRUCTOR, 1178 : super(enclosing.name, ElementKind.GENERATIVE_CONSTRUCTOR,
1176 null, enclosing); 1179 Modifiers.EMPTY, enclosing);
1177 1180
1178 Token position() => enclosingElement.position(); 1181 Token position() => enclosingElement.position();
1179 1182
1180 SynthesizedConstructorElement cloneTo(Element enclosing, 1183 SynthesizedConstructorElement cloneTo(Element enclosing,
1181 DiagnosticListener listener) { 1184 DiagnosticListener listener) {
1182 return new SynthesizedConstructorElement(enclosing); 1185 return new SynthesizedConstructorElement(enclosing);
1183 } 1186 }
1184 } 1187 }
1185 1188
1186 class VoidElement extends Element { 1189 class VoidElement extends Element {
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1556 && element.isInstanceMember() 1559 && element.isInstanceMember()
1557 && (element.kind === ElementKind.FIELD 1560 && (element.kind === ElementKind.FIELD
1558 || element.kind === ElementKind.GETTER 1561 || element.kind === ElementKind.GETTER
1559 || element.kind === ElementKind.SETTER); 1562 || element.kind === ElementKind.SETTER);
1560 } 1563 }
1561 1564
1562 static bool isStaticOrTopLevel(Element element) { 1565 static bool isStaticOrTopLevel(Element element) {
1563 // TODO(ager): This should not be necessary when patch support has 1566 // TODO(ager): This should not be necessary when patch support has
1564 // been reworked. 1567 // been reworked.
1565 if (!Elements.isUnresolved(element) 1568 if (!Elements.isUnresolved(element)
1566 && element.modifiers != null
1567 && element.modifiers.isStatic()) { 1569 && element.modifiers.isStatic()) {
1568 return true; 1570 return true;
1569 } 1571 }
1570 return !Elements.isUnresolved(element) 1572 return !Elements.isUnresolved(element)
1571 && !element.isInstanceMember() 1573 && !element.isInstanceMember()
1572 && !element.isPrefix() 1574 && !element.isPrefix()
1573 && element.enclosingElement !== null 1575 && element.enclosingElement !== null
1574 && (element.enclosingElement.kind == ElementKind.CLASS || 1576 && (element.enclosingElement.kind == ElementKind.CLASS ||
1575 element.enclosingElement.kind == ElementKind.COMPILATION_UNIT || 1577 element.enclosingElement.kind == ElementKind.COMPILATION_UNIT ||
1576 element.enclosingElement.kind == ElementKind.LIBRARY); 1578 element.enclosingElement.kind == ElementKind.LIBRARY);
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 1832
1831 MetadataAnnotation ensureResolved(Compiler compiler) { 1833 MetadataAnnotation ensureResolved(Compiler compiler) {
1832 if (resolutionState == STATE_NOT_STARTED) { 1834 if (resolutionState == STATE_NOT_STARTED) {
1833 compiler.resolver.resolveMetadataAnnotation(this); 1835 compiler.resolver.resolveMetadataAnnotation(this);
1834 } 1836 }
1835 return this; 1837 return this;
1836 } 1838 }
1837 1839
1838 String toString() => 'MetadataAnnotation($value, $resolutionState)'; 1840 String toString() => 'MetadataAnnotation($value, $resolutionState)';
1839 } 1841 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698