Chromium Code Reviews| 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 #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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 bool isSetter() => kind === ElementKind.SETTER; | 164 bool isSetter() => kind === ElementKind.SETTER; |
| 165 bool isAccessor() => isGetter() || isSetter(); | 165 bool isAccessor() => isGetter() || isSetter(); |
| 166 bool isForeign() => kind === ElementKind.FOREIGN; | 166 bool isForeign() => kind === ElementKind.FOREIGN; |
| 167 bool isLibrary() => kind === ElementKind.LIBRARY; | 167 bool isLibrary() => kind === ElementKind.LIBRARY; |
| 168 bool impliesType() => (kind.category & ElementCategory.IMPLIES_TYPE) != 0; | 168 bool impliesType() => (kind.category & ElementCategory.IMPLIES_TYPE) != 0; |
| 169 bool isExtendable() => (kind.category & ElementCategory.IS_EXTENDABLE) != 0; | 169 bool isExtendable() => (kind.category & ElementCategory.IS_EXTENDABLE) != 0; |
| 170 | 170 |
| 171 /** See [ErroneousElement] for documentation. */ | 171 /** See [ErroneousElement] for documentation. */ |
| 172 bool isErroneous() => false; | 172 bool isErroneous() => false; |
| 173 | 173 |
| 174 //---------------------------------------------------------------------------- | |
|
ahe
2012/09/18 11:25:54
What does this comment apply to? I think this is d
Johnni Winther
2012/09/20 08:12:23
Done.
| |
| 175 // Patch related getters. See [:patch_parser.dart:] for a description of the | |
| 176 // terminology. | |
| 177 //---------------------------------------------------------------------------- | |
| 178 bool get isPatched => false; | |
| 179 bool get isPatch => false; | |
| 180 | |
| 181 bool get isImplementation => implementation === this; | |
| 182 bool get isDeclaration => declaration === this; | |
| 183 | |
| 184 Element get implementation => this; | |
| 185 Element get declaration => this; | |
| 186 | |
| 174 // TODO(johnniwinther): This breaks for libraries (for which enclosing | 187 // TODO(johnniwinther): This breaks for libraries (for which enclosing |
| 175 // elements are null) and is invalid for top level variable declarations for | 188 // elements are null) and is invalid for top level variable declarations for |
| 176 // which the enclosing element is a VariableDeclarations and not a compilation | 189 // which the enclosing element is a VariableDeclarations and not a compilation |
| 177 // unit. | 190 // unit. |
| 178 bool isTopLevel() { | 191 bool isTopLevel() { |
| 179 return enclosingElement !== null && enclosingElement.isCompilationUnit(); | 192 return enclosingElement !== null && enclosingElement.isCompilationUnit(); |
| 180 } | 193 } |
| 181 | 194 |
| 182 bool isAssignable() { | 195 bool isAssignable() { |
| 183 if (modifiers != null && modifiers.isFinalOrConst()) return false; | 196 if (modifiers != null && modifiers.isFinalOrConst()) return false; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 } | 235 } |
| 223 | 236 |
| 224 LibraryElement getLibrary() { | 237 LibraryElement getLibrary() { |
| 225 Element element = this; | 238 Element element = this; |
| 226 while (element.kind !== ElementKind.LIBRARY) { | 239 while (element.kind !== ElementKind.LIBRARY) { |
| 227 element = element.enclosingElement; | 240 element = element.enclosingElement; |
| 228 } | 241 } |
| 229 return element; | 242 return element; |
| 230 } | 243 } |
| 231 | 244 |
| 245 LibraryElement getImplementationLibrary() => getLibrary(); | |
| 246 | |
| 232 ClassElement getEnclosingClass() { | 247 ClassElement getEnclosingClass() { |
| 233 for (Element e = this; e !== null; e = e.enclosingElement) { | 248 for (Element e = this; e !== null; e = e.enclosingElement) { |
| 234 if (e.isClass()) return e; | 249 if (e.isClass()) return e; |
| 235 } | 250 } |
| 236 return null; | 251 return null; |
| 237 } | 252 } |
| 238 | 253 |
| 239 Element getEnclosingClassOrCompilationUnit() { | 254 Element getEnclosingClassOrCompilationUnit() { |
| 240 for (Element e = this; e !== null; e = e.enclosingElement) { | 255 for (Element e = this; e !== null; e = e.enclosingElement) { |
| 241 if (e.isClass() || e.isCompilationUnit()) return e; | 256 if (e.isClass() || e.isCompilationUnit()) return e; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 | 302 |
| 288 bool _isNative = false; | 303 bool _isNative = false; |
| 289 void setNative() { _isNative = true; } | 304 void setNative() { _isNative = true; } |
| 290 bool isNative() => _isNative; | 305 bool isNative() => _isNative; |
| 291 | 306 |
| 292 FunctionElement asFunctionElement() => null; | 307 FunctionElement asFunctionElement() => null; |
| 293 | 308 |
| 294 Element cloneTo(Element enclosing, DiagnosticListener listener) { | 309 Element cloneTo(Element enclosing, DiagnosticListener listener) { |
| 295 listener.cancel("Unimplemented cloneTo", element: this); | 310 listener.cancel("Unimplemented cloneTo", element: this); |
| 296 } | 311 } |
| 297 | |
| 298 bool get isPatched => false; | |
| 299 } | 312 } |
| 300 | 313 |
| 301 /** | 314 /** |
| 302 * Represents an unresolvable or duplicated element. | 315 * Represents an unresolvable or duplicated element. |
| 303 * | 316 * |
| 304 * An [ErroneousElement] is used instead of [null] to provide additional | 317 * An [ErroneousElement] is used instead of [null] to provide additional |
| 305 * information about the error that caused the element to be unresolvable | 318 * information about the error that caused the element to be unresolvable |
| 306 * or otherwise invalid. | 319 * or otherwise invalid. |
| 307 * | 320 * |
| 308 * Accessing any field or calling any method defined on [ErroneousElement] | 321 * Accessing any field or calling any method defined on [ErroneousElement] |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 338 class ErroneousFunctionElement extends ErroneousElement | 351 class ErroneousFunctionElement extends ErroneousElement |
| 339 implements FunctionElement { | 352 implements FunctionElement { |
| 340 ErroneousFunctionElement(Message errorMessage, SourceString targetName, | 353 ErroneousFunctionElement(Message errorMessage, SourceString targetName, |
| 341 Element enclosing) | 354 Element enclosing) |
| 342 : super(errorMessage, targetName, enclosing); | 355 : super(errorMessage, targetName, enclosing); |
| 343 | 356 |
| 344 get type => unsupported(); | 357 get type => unsupported(); |
| 345 get cachedNode => unsupported(); | 358 get cachedNode => unsupported(); |
| 346 get functionSignature => unsupported(); | 359 get functionSignature => unsupported(); |
| 347 get patch => unsupported(); | 360 get patch => unsupported(); |
| 361 get origin => unsupported(); | |
| 348 get defaultImplementation => unsupported(); | 362 get defaultImplementation => unsupported(); |
| 349 bool get isPatched => unsupported(); | 363 bool get isPatched => unsupported(); |
| 364 bool get isPatch => unsupported(); | |
| 350 setPatch(patch) => unsupported(); | 365 setPatch(patch) => unsupported(); |
| 351 computeSignature(compiler) => unsupported(); | 366 computeSignature(compiler) => unsupported(); |
| 352 requiredParameterCount(compiler) => unsupported(); | 367 requiredParameterCount(compiler) => unsupported(); |
| 353 optionalParameterCount(compiler) => unsupported(); | 368 optionalParameterCount(compiler) => unsupported(); |
| 354 parameterCount(copmiler) => unsupported(); | 369 parameterCount(copmiler) => unsupported(); |
| 355 } | 370 } |
| 356 | 371 |
| 357 class ContainerElement extends Element { | 372 class ContainerElement extends Element { |
| 358 Link<Element> localMembers = const EmptyLink<Element>(); | 373 Link<Element> localMembers = const EmptyLink<Element>(); |
| 359 | 374 |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 973 int optionalParameterCount(Compiler compiler) { | 988 int optionalParameterCount(Compiler compiler) { |
| 974 return computeSignature(compiler).optionalParameterCount; | 989 return computeSignature(compiler).optionalParameterCount; |
| 975 } | 990 } |
| 976 | 991 |
| 977 int parameterCount(Compiler compiler) { | 992 int parameterCount(Compiler compiler) { |
| 978 return computeSignature(compiler).parameterCount; | 993 return computeSignature(compiler).parameterCount; |
| 979 } | 994 } |
| 980 | 995 |
| 981 FunctionType computeType(Compiler compiler) { | 996 FunctionType computeType(Compiler compiler) { |
| 982 if (type != null) return type; | 997 if (type != null) return type; |
| 983 type = compiler.computeFunctionType(this, computeSignature(compiler)); | 998 type = compiler.computeFunctionType(declaration, |
|
ngeoffray
2012/09/17 12:46:24
Why this change?
Johnni Winther
2012/09/20 08:12:23
To enforce the invariant that DartType.element is
| |
| 999 computeSignature(compiler)); | |
| 984 return type; | 1000 return type; |
| 985 } | 1001 } |
| 986 | 1002 |
| 987 Node parseNode(DiagnosticListener listener) { | 1003 Node parseNode(DiagnosticListener listener) { |
| 988 if (cachedNode !== null) return cachedNode; | |
| 989 if (patch === null) { | 1004 if (patch === null) { |
| 990 if (modifiers.isExternal()) { | 1005 if (modifiers != null && modifiers.isExternal()) { |
| 991 listener.cancel("Compiling external function with no implementation.", | 1006 listener.cancel("Compiling external function with no implementation.", |
| 992 element: this); | 1007 element: this); |
| 993 } | 1008 } |
| 994 return null; | |
| 995 } | 1009 } |
| 996 cachedNode = patch.parseNode(listener); | |
| 997 return cachedNode; | 1010 return cachedNode; |
| 998 } | 1011 } |
| 999 | 1012 |
| 1000 Token position() => cachedNode.getBeginToken(); | 1013 Token position() => cachedNode.getBeginToken(); |
| 1001 | 1014 |
| 1002 FunctionElement asFunctionElement() => this; | 1015 FunctionElement asFunctionElement() => this; |
| 1003 | 1016 |
| 1004 FunctionElement cloneTo(Element enclosing, DiagnosticListener listener) { | 1017 String toString() { |
| 1005 FunctionElement result = new FunctionElement.tooMuchOverloading( | 1018 if (isPatch) { |
| 1006 name, cachedNode, kind, modifiers, enclosing, functionSignature); | 1019 return 'patch ${super.toString()}'; |
| 1007 result.defaultImplementation = defaultImplementation; | 1020 } else if (isPatched) { |
| 1008 result.type = type; | 1021 return 'origin ${super.toString()}'; |
| 1009 return result; | 1022 } else { |
| 1023 return super.toString(); | |
| 1024 } | |
| 1010 } | 1025 } |
| 1011 | 1026 |
| 1012 Scope buildScope() { | 1027 Scope buildScope() { |
| 1013 Scope result = new MethodScope(enclosingElement.buildScope(), this); | 1028 Scope result = |
| 1029 new MethodScope(enclosingElement.buildScope(), this); | |
| 1014 if (enclosingElement.isClass()) { | 1030 if (enclosingElement.isClass()) { |
| 1015 ClassScope clsScope = result.parent; | 1031 Scope clsScope = result.parent; |
| 1016 clsScope.inStaticContext = !isInstanceMember() && !isConstructor(); | 1032 clsScope.inStaticContext = !isInstanceMember() && !isConstructor(); |
| 1017 } | 1033 } |
| 1018 return result; | 1034 return result; |
| 1019 } | 1035 } |
| 1020 } | 1036 } |
| 1021 | 1037 |
| 1022 | |
| 1023 class ConstructorBodyElement extends FunctionElement { | 1038 class ConstructorBodyElement extends FunctionElement { |
| 1024 FunctionElement constructor; | 1039 FunctionElement constructor; |
| 1025 | 1040 |
| 1026 ConstructorBodyElement(FunctionElement constructor) | 1041 ConstructorBodyElement(FunctionElement constructor) |
| 1027 : this.constructor = constructor, | 1042 : this.constructor = constructor, |
| 1028 super(constructor.name, | 1043 super(constructor.name, |
| 1029 ElementKind.GENERATIVE_CONSTRUCTOR_BODY, | 1044 ElementKind.GENERATIVE_CONSTRUCTOR_BODY, |
| 1030 null, | 1045 null, |
| 1031 constructor.enclosingElement) { | 1046 constructor.enclosingElement) { |
| 1032 functionSignature = constructor.functionSignature; | 1047 functionSignature = constructor.functionSignature; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1148 ClassNode node = parseNode(compiler); | 1163 ClassNode node = parseNode(compiler); |
| 1149 Link<DartType> parameters = | 1164 Link<DartType> parameters = |
| 1150 TypeDeclarationElement.createTypeVariables(this, node.typeParameters); | 1165 TypeDeclarationElement.createTypeVariables(this, node.typeParameters); |
| 1151 type = new InterfaceType(this, parameters); | 1166 type = new InterfaceType(this, parameters); |
| 1152 } | 1167 } |
| 1153 return type; | 1168 return type; |
| 1154 } | 1169 } |
| 1155 | 1170 |
| 1156 bool get isPatched => patch != null; | 1171 bool get isPatched => patch != null; |
| 1157 | 1172 |
| 1173 bool get isObject => supertype === null; | |
|
ngeoffray
2012/09/17 12:46:24
This is fragile: the class may not have been resol
Johnni Winther
2012/09/20 08:12:23
Changed to a less fragile method call.
| |
| 1174 | |
| 1158 Link<DartType> get typeVariables => type.arguments; | 1175 Link<DartType> get typeVariables => type.arguments; |
| 1159 | 1176 |
| 1160 ClassElement ensureResolved(Compiler compiler) { | 1177 ClassElement ensureResolved(Compiler compiler) { |
| 1161 if (resolutionState == STATE_NOT_STARTED) { | 1178 if (resolutionState == STATE_NOT_STARTED) { |
| 1162 compiler.resolver.resolveClass(this); | 1179 compiler.resolver.resolveClass(this); |
| 1163 } | 1180 } |
| 1164 return this; | 1181 return this; |
| 1165 } | 1182 } |
| 1166 | 1183 |
| 1167 /** | 1184 /** |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1691 | 1708 |
| 1692 MetadataAnnotation ensureResolved(Compiler compiler) { | 1709 MetadataAnnotation ensureResolved(Compiler compiler) { |
| 1693 if (resolutionState == STATE_NOT_STARTED) { | 1710 if (resolutionState == STATE_NOT_STARTED) { |
| 1694 compiler.resolver.resolveMetadataAnnotation(this); | 1711 compiler.resolver.resolveMetadataAnnotation(this); |
| 1695 } | 1712 } |
| 1696 return this; | 1713 return this; |
| 1697 } | 1714 } |
| 1698 | 1715 |
| 1699 String toString() => 'MetadataAnnotation($value, $resolutionState)'; | 1716 String toString() => 'MetadataAnnotation($value, $resolutionState)'; |
| 1700 } | 1717 } |
| OLD | NEW |