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 // TODO(ahe): Rename prefix to 'api' when VM bug is fixed. | 9 // TODO(ahe): Rename prefix to 'api' when VM bug is fixed. |
10 #import('../../compiler.dart', prefix: 'api_e'); | 10 #import('../../compiler.dart', prefix: 'api_e'); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 const ElementKind('prefix', ElementCategory.PREFIX); | 96 const ElementKind('prefix', ElementCategory.PREFIX); |
97 static const ElementKind TYPEDEF = | 97 static const ElementKind TYPEDEF = |
98 const ElementKind('typedef', ElementCategory.ALIAS); | 98 const ElementKind('typedef', ElementCategory.ALIAS); |
99 | 99 |
100 static const ElementKind STATEMENT = | 100 static const ElementKind STATEMENT = |
101 const ElementKind('statement', ElementCategory.NONE); | 101 const ElementKind('statement', ElementCategory.NONE); |
102 static const ElementKind LABEL = | 102 static const ElementKind LABEL = |
103 const ElementKind('label', ElementCategory.NONE); | 103 const ElementKind('label', ElementCategory.NONE); |
104 static const ElementKind VOID = | 104 static const ElementKind VOID = |
105 const ElementKind('void', ElementCategory.NONE); | 105 const ElementKind('void', ElementCategory.NONE); |
| 106 static const ElementKind MALFORMED_TYPE = |
| 107 const ElementKind('malformed', ElementCategory.NONE); |
106 | 108 |
107 toString() => id; | 109 toString() => id; |
108 } | 110 } |
109 | 111 |
110 class Element implements Spannable { | 112 class Element implements Spannable { |
111 final SourceString name; | 113 final SourceString name; |
112 final ElementKind kind; | 114 final ElementKind kind; |
113 final Element enclosingElement; | 115 final Element enclosingElement; |
114 Link<MetadataAnnotation> metadata = const EmptyLink<MetadataAnnotation>(); | 116 Link<MetadataAnnotation> metadata = const EmptyLink<MetadataAnnotation>(); |
115 | 117 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 } | 327 } |
326 } | 328 } |
327 | 329 |
328 bool _isNative = false; | 330 bool _isNative = false; |
329 void setNative() { _isNative = true; } | 331 void setNative() { _isNative = true; } |
330 bool isNative() => _isNative; | 332 bool isNative() => _isNative; |
331 | 333 |
332 FunctionElement asFunctionElement() => null; | 334 FunctionElement asFunctionElement() => null; |
333 | 335 |
334 static bool isInvalid(Element e) => e == null || e.isErroneous(); | 336 static bool isInvalid(Element e) => e == null || e.isErroneous(); |
| 337 |
| 338 bool inStaticContext() { |
| 339 return modifiers.isStatic(); |
| 340 } |
335 } | 341 } |
336 | 342 |
337 /** | 343 /** |
338 * Represents an unresolvable or duplicated element. | 344 * Represents an unresolvable or duplicated element. |
339 * | 345 * |
340 * An [ErroneousElement] is used instead of [null] to provide additional | 346 * An [ErroneousElement] is used instead of [null] to provide additional |
341 * information about the error that caused the element to be unresolvable | 347 * information about the error that caused the element to be unresolvable |
342 * or otherwise invalid. | 348 * or otherwise invalid. |
343 * | 349 * |
344 * Accessing any field or calling any method defined on [ErroneousElement] | 350 * Accessing any field or calling any method defined on [ErroneousElement] |
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 class VoidElement extends Element { | 1220 class VoidElement extends Element { |
1215 VoidElement(Element enclosing) | 1221 VoidElement(Element enclosing) |
1216 : super(const SourceString('void'), ElementKind.VOID, enclosing); | 1222 : super(const SourceString('void'), ElementKind.VOID, enclosing); |
1217 DartType computeType(compiler) => compiler.types.voidType; | 1223 DartType computeType(compiler) => compiler.types.voidType; |
1218 Node parseNode(_) { | 1224 Node parseNode(_) { |
1219 throw 'internal error: parseNode on void'; | 1225 throw 'internal error: parseNode on void'; |
1220 } | 1226 } |
1221 bool impliesType() => true; | 1227 bool impliesType() => true; |
1222 } | 1228 } |
1223 | 1229 |
| 1230 class MalformedTypeElement extends Element { |
| 1231 final TypeAnnotation type; |
| 1232 MalformedTypeElement(this.type, Element enclosing) |
| 1233 : super(const SourceString('malformed'), |
| 1234 ElementKind.MALFORMED_TYPE, |
| 1235 enclosing); |
| 1236 DartType computeType(compiler) => compiler.types.malformedType; |
| 1237 Node parseNode(DiagnosticListener dl) => type; |
| 1238 bool impliesType() => true; |
| 1239 } |
| 1240 |
1224 /** | 1241 /** |
1225 * [TypeDeclarationElement] defines the common interface for class/interface | 1242 * [TypeDeclarationElement] defines the common interface for class/interface |
1226 * declarations and typedefs. | 1243 * declarations and typedefs. |
1227 */ | 1244 */ |
1228 abstract class TypeDeclarationElement implements Element { | 1245 abstract class TypeDeclarationElement implements Element { |
1229 // TODO(johnniwinther): This class should eventually be a mixin. | 1246 // TODO(johnniwinther): This class should eventually be a mixin. |
1230 | 1247 |
1231 /** | 1248 /** |
1232 * The type variables declared on this declaration. The type variables are not | 1249 * The type variables declared on this declaration. The type variables are not |
1233 * available until the type of the element has been computed through | 1250 * available until the type of the element has been computed through |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1913 | 1930 |
1914 MetadataAnnotation ensureResolved(Compiler compiler) { | 1931 MetadataAnnotation ensureResolved(Compiler compiler) { |
1915 if (resolutionState == STATE_NOT_STARTED) { | 1932 if (resolutionState == STATE_NOT_STARTED) { |
1916 compiler.resolver.resolveMetadataAnnotation(this); | 1933 compiler.resolver.resolveMetadataAnnotation(this); |
1917 } | 1934 } |
1918 return this; | 1935 return this; |
1919 } | 1936 } |
1920 | 1937 |
1921 String toString() => 'MetadataAnnotation($value, $resolutionState)'; | 1938 String toString() => 'MetadataAnnotation($value, $resolutionState)'; |
1922 } | 1939 } |
OLD | NEW |