| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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.modelx; | 5 library elements.modelx; |
| 6 | 6 |
| 7 import '../compiler.dart' show | 7 import '../compiler.dart' show |
| 8 Compiler; | 8 Compiler; |
| 9 import '../constants/constant_constructors.dart'; | 9 import '../constants/constant_constructors.dart'; |
| 10 import '../constants/constructors.dart'; | 10 import '../constants/constructors.dart'; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 abstract class DeclarationSite { | 52 abstract class DeclarationSite { |
| 53 } | 53 } |
| 54 | 54 |
| 55 abstract class ElementX extends Element with ElementCommon { | 55 abstract class ElementX extends Element with ElementCommon { |
| 56 static int elementHashCode = 0; | 56 static int elementHashCode = 0; |
| 57 | 57 |
| 58 final String name; | 58 final String name; |
| 59 final ElementKind kind; | 59 final ElementKind kind; |
| 60 final Element enclosingElement; | 60 final Element enclosingElement; |
| 61 final int hashCode = ++elementHashCode; | 61 final int hashCode = ++elementHashCode; |
| 62 Link<MetadataAnnotation> metadata = const Link<MetadataAnnotation>(); | 62 List<MetadataAnnotation> metadataInternal; |
| 63 | 63 |
| 64 ElementX(this.name, this.kind, this.enclosingElement) { | 64 ElementX(this.name, this.kind, this.enclosingElement) { |
| 65 assert(isErroneous || implementationLibrary != null); | 65 assert(isErroneous || implementationLibrary != null); |
| 66 } | 66 } |
| 67 | 67 |
| 68 Modifiers get modifiers => Modifiers.EMPTY; | 68 Modifiers get modifiers => Modifiers.EMPTY; |
| 69 | 69 |
| 70 Node parseNode(DiagnosticListener listener) { | 70 Node parseNode(DiagnosticListener listener) { |
| 71 listener.internalError(this, | 71 listener.internalError(this, |
| 72 'parseNode not implemented on $this.'); | 72 'parseNode not implemented on $this.'); |
| 73 return null; | 73 return null; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void addMetadata(MetadataAnnotationX annotation) { | 76 void set metadata(List<MetadataAnnotation> metadata) { |
| 77 assert(annotation.annotatedElement == null); | 77 assert(metadataInternal == null); |
| 78 annotation.annotatedElement = this; | 78 for (MetadataAnnotationX annotation in metadata) { |
| 79 addMetadataInternal(annotation); | 79 assert(annotation.annotatedElement == null); |
| 80 annotation.annotatedElement = this; |
| 81 } |
| 82 metadataInternal = metadata; |
| 80 } | 83 } |
| 81 | 84 |
| 82 void addMetadataInternal(MetadataAnnotation annotation) { | 85 Iterable<MetadataAnnotation> get metadata { |
| 83 metadata = metadata.prepend(annotation); | 86 if (isPatch && metadataInternal != null) { |
| 87 if (origin.metadata.isEmpty) { |
| 88 return metadataInternal; |
| 89 } else { |
| 90 return <MetadataAnnotation>[] |
| 91 ..addAll(origin.metadata) |
| 92 ..addAll(metadataInternal); |
| 93 } |
| 94 } |
| 95 return metadataInternal != null |
| 96 ? metadataInternal : const <MetadataAnnotation>[]; |
| 84 } | 97 } |
| 85 | 98 |
| 86 bool get isClosure => false; | 99 bool get isClosure => false; |
| 87 bool get isClassMember { | 100 bool get isClassMember { |
| 88 // Check that this element is defined in the scope of a Class. | 101 // Check that this element is defined in the scope of a Class. |
| 89 return enclosingElement != null && enclosingElement.isClass; | 102 return enclosingElement != null && enclosingElement.isClass; |
| 90 } | 103 } |
| 91 bool get isInstanceMember => false; | 104 bool get isInstanceMember => false; |
| 92 bool get isDeferredLoaderGetter => false; | 105 bool get isDeferredLoaderGetter => false; |
| 93 | 106 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 286 |
| 274 PrefixElement get redirectionDeferredPrefix => null; | 287 PrefixElement get redirectionDeferredPrefix => null; |
| 275 | 288 |
| 276 AbstractFieldElement abstractField; | 289 AbstractFieldElement abstractField; |
| 277 | 290 |
| 278 unsupported() { | 291 unsupported() { |
| 279 throw 'unsupported operation on erroneous element'; | 292 throw 'unsupported operation on erroneous element'; |
| 280 } | 293 } |
| 281 | 294 |
| 282 get asyncMarker => AsyncMarker.SYNC; | 295 get asyncMarker => AsyncMarker.SYNC; |
| 283 Link<MetadataAnnotation> get metadata => unsupported(); | 296 Iterable<MetadataAnnotation> get metadata => unsupported(); |
| 284 bool get hasNode => false; | 297 bool get hasNode => false; |
| 285 get node => unsupported(); | 298 get node => unsupported(); |
| 286 get hasResolvedAst => false; | 299 get hasResolvedAst => false; |
| 287 get resolvedAst => unsupported(); | 300 get resolvedAst => unsupported(); |
| 288 get type => unsupported(); | 301 get type => unsupported(); |
| 289 get cachedNode => unsupported(); | 302 get cachedNode => unsupported(); |
| 290 get functionSignature => unsupported(); | 303 get functionSignature => unsupported(); |
| 291 get parameters => unsupported(); | 304 get parameters => unsupported(); |
| 292 get patch => null; | 305 get patch => null; |
| 293 get origin => this; | 306 get origin => this; |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 : this.script = script, | 684 : this.script = script, |
| 672 super(script.name, | 685 super(script.name, |
| 673 ElementKind.COMPILATION_UNIT, | 686 ElementKind.COMPILATION_UNIT, |
| 674 library) { | 687 library) { |
| 675 library.addCompilationUnit(this); | 688 library.addCompilationUnit(this); |
| 676 } | 689 } |
| 677 | 690 |
| 678 @override | 691 @override |
| 679 LibraryElementX get library => enclosingElement.declaration; | 692 LibraryElementX get library => enclosingElement.declaration; |
| 680 | 693 |
| 694 void set metadata(List<MetadataAnnotation> metadata) { |
| 695 for (MetadataAnnotationX annotation in metadata) { |
| 696 assert(annotation.annotatedElement == null); |
| 697 annotation.annotatedElement = this; |
| 698 } |
| 699 // TODO(johnniwinther): Remove this work-around when import, export, |
| 700 // part, and part-of declarations are elements. |
| 701 if (metadataInternal == null) { |
| 702 metadataInternal = <MetadataAnnotation>[]; |
| 703 } |
| 704 metadataInternal.addAll(metadata); |
| 705 } |
| 706 |
| 681 void forEachLocalMember(f(Element element)) { | 707 void forEachLocalMember(f(Element element)) { |
| 682 localMembers.forEach(f); | 708 localMembers.forEach(f); |
| 683 } | 709 } |
| 684 | 710 |
| 685 void addMember(Element element, DiagnosticListener listener) { | 711 void addMember(Element element, DiagnosticListener listener) { |
| 686 // Keep a list of top level members. | 712 // Keep a list of top level members. |
| 687 localMembers = localMembers.prepend(element); | 713 localMembers = localMembers.prepend(element); |
| 688 // Provide the member to the library to build scope. | 714 // Provide the member to the library to build scope. |
| 689 if (enclosingElement.isPatch) { | 715 if (enclosingElement.isPatch) { |
| 690 implementationLibrary.addMember(element, listener); | 716 implementationLibrary.addMember(element, listener); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 : this.canonicalUri = | 911 : this.canonicalUri = |
| 886 ((canonicalUri == null) ? script.readableUri : canonicalUri), | 912 ((canonicalUri == null) ? script.readableUri : canonicalUri), |
| 887 this.isSynthesized = script.isSynthesized, | 913 this.isSynthesized = script.isSynthesized, |
| 888 super(script.name, ElementKind.LIBRARY, null) { | 914 super(script.name, ElementKind.LIBRARY, null) { |
| 889 entryCompilationUnit = new CompilationUnitElementX(script, this); | 915 entryCompilationUnit = new CompilationUnitElementX(script, this); |
| 890 if (origin != null) { | 916 if (origin != null) { |
| 891 origin.applyPatch(this); | 917 origin.applyPatch(this); |
| 892 } | 918 } |
| 893 } | 919 } |
| 894 | 920 |
| 895 Link<MetadataAnnotation> get metadata { | 921 Iterable<MetadataAnnotation> get metadata { |
| 896 return (libraryTag == null) ? super.metadata : libraryTag.metadata; | 922 if (libraryTag != null) { |
| 923 return libraryTag.metadata; |
| 924 } |
| 925 return const <MetadataAnnotation>[]; |
| 897 } | 926 } |
| 898 | 927 |
| 899 set metadata(value) { | 928 void set metadata(value) { |
| 900 // The metadata is stored on [libraryTag]. | 929 // The metadata is stored on [libraryTag]. |
| 901 throw new SpannableAssertionFailure(this, 'Cannot set metadata on Library'); | 930 throw new SpannableAssertionFailure(this, 'Cannot set metadata on Library'); |
| 902 } | 931 } |
| 903 | 932 |
| 904 CompilationUnitElement get compilationUnit => entryCompilationUnit; | 933 CompilationUnitElement get compilationUnit => entryCompilationUnit; |
| 905 | 934 |
| 906 Element get analyzableElement => this; | 935 Element get analyzableElement => this; |
| 907 | 936 |
| 908 void addCompilationUnit(CompilationUnitElement element) { | 937 void addCompilationUnit(CompilationUnitElement element) { |
| 909 compilationUnits = compilationUnits.prepend(element); | 938 compilationUnits = compilationUnits.prepend(element); |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 AstElement get definingElement => this; | 1240 AstElement get definingElement => this; |
| 1212 } | 1241 } |
| 1213 | 1242 |
| 1214 // This class holds common information for a list of variable or field | 1243 // This class holds common information for a list of variable or field |
| 1215 // declarations. It contains the node, and the type. A [VariableElementX] | 1244 // declarations. It contains the node, and the type. A [VariableElementX] |
| 1216 // forwards its [computeType] and [parseNode] methods to this class. | 1245 // forwards its [computeType] and [parseNode] methods to this class. |
| 1217 class VariableList implements DeclarationSite { | 1246 class VariableList implements DeclarationSite { |
| 1218 VariableDefinitions definitions; | 1247 VariableDefinitions definitions; |
| 1219 DartType type; | 1248 DartType type; |
| 1220 final Modifiers modifiers; | 1249 final Modifiers modifiers; |
| 1221 Link<MetadataAnnotation> metadata = const Link<MetadataAnnotation>(); | 1250 List<MetadataAnnotation> metadataInternal; |
| 1222 | 1251 |
| 1223 VariableList(Modifiers this.modifiers); | 1252 VariableList(Modifiers this.modifiers); |
| 1224 | 1253 |
| 1225 VariableList.node(VariableDefinitions node, this.type) | 1254 VariableList.node(VariableDefinitions node, this.type) |
| 1226 : this.definitions = node, | 1255 : this.definitions = node, |
| 1227 this.modifiers = node.modifiers { | 1256 this.modifiers = node.modifiers { |
| 1228 assert(modifiers != null); | 1257 assert(modifiers != null); |
| 1229 } | 1258 } |
| 1230 | 1259 |
| 1260 Iterable<MetadataAnnotation> get metadata { |
| 1261 return metadataInternal != null |
| 1262 ? metadataInternal : const <MetadataAnnotation>[]; |
| 1263 } |
| 1264 |
| 1265 void set metadata(List<MetadataAnnotation> metadata) { |
| 1266 if (metadata.isEmpty) { |
| 1267 // For a multi declaration like: |
| 1268 // |
| 1269 // @foo @bar var a, b, c |
| 1270 // |
| 1271 // the metadata list is reported through the declaration of `a`, and `b` |
| 1272 // and `c` report an empty list of metadata. |
| 1273 return; |
| 1274 } |
| 1275 assert(metadataInternal == null); |
| 1276 metadataInternal = metadata; |
| 1277 } |
| 1278 |
| 1231 VariableDefinitions parseNode(Element element, DiagnosticListener listener) { | 1279 VariableDefinitions parseNode(Element element, DiagnosticListener listener) { |
| 1232 return definitions; | 1280 return definitions; |
| 1233 } | 1281 } |
| 1234 | 1282 |
| 1235 DartType computeType(Element element, Compiler compiler) => type; | 1283 DartType computeType(Element element, Compiler compiler) => type; |
| 1236 } | 1284 } |
| 1237 | 1285 |
| 1238 abstract class ConstantVariableMixin implements VariableElement { | 1286 abstract class ConstantVariableMixin implements VariableElement { |
| 1239 ConstantExpression constantCache; | 1287 ConstantExpression constantCache; |
| 1240 | 1288 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1277 VariableElementX(String name, | 1325 VariableElementX(String name, |
| 1278 ElementKind kind, | 1326 ElementKind kind, |
| 1279 Element enclosingElement, | 1327 Element enclosingElement, |
| 1280 VariableList variables, | 1328 VariableList variables, |
| 1281 this.token) | 1329 this.token) |
| 1282 : this.variables = variables, | 1330 : this.variables = variables, |
| 1283 super(name, kind, enclosingElement); | 1331 super(name, kind, enclosingElement); |
| 1284 | 1332 |
| 1285 // TODO(johnniwinther): Ensure that the [TreeElements] for this variable hold | 1333 // TODO(johnniwinther): Ensure that the [TreeElements] for this variable hold |
| 1286 // the mappings for all its metadata. | 1334 // the mappings for all its metadata. |
| 1287 Link<MetadataAnnotation> get metadata => variables.metadata; | 1335 Iterable<MetadataAnnotation> get metadata => variables.metadata; |
| 1288 | 1336 |
| 1289 void addMetadataInternal(MetadataAnnotation annotation) { | 1337 void set metadata(List<MetadataAnnotation> metadata) { |
| 1290 variables.metadata = variables.metadata.prepend(annotation); | 1338 for (MetadataAnnotationX annotation in metadata) { |
| 1339 assert(annotation.annotatedElement == null); |
| 1340 annotation.annotatedElement = this; |
| 1341 } |
| 1342 variables.metadata = metadata; |
| 1291 } | 1343 } |
| 1292 | 1344 |
| 1293 // A variable cannot be patched therefore defines itself. | 1345 // A variable cannot be patched therefore defines itself. |
| 1294 AstElement get definingElement => this; | 1346 AstElement get definingElement => this; |
| 1295 | 1347 |
| 1296 bool get hasNode => definitionsCache != null; | 1348 bool get hasNode => definitionsCache != null; |
| 1297 | 1349 |
| 1298 VariableDefinitions get node { | 1350 VariableDefinitions get node { |
| 1299 assert(invariant(this, definitionsCache != null, | 1351 assert(invariant(this, definitionsCache != null, |
| 1300 message: "Node has not been computed for $this.")); | 1352 message: "Node has not been computed for $this.")); |
| (...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2090 ElementKind.GENERATIVE_CONSTRUCTOR_BODY, | 2142 ElementKind.GENERATIVE_CONSTRUCTOR_BODY, |
| 2091 Modifiers.EMPTY, | 2143 Modifiers.EMPTY, |
| 2092 constructor.enclosingElement) { | 2144 constructor.enclosingElement) { |
| 2093 functionSignatureCache = constructor.functionSignature; | 2145 functionSignatureCache = constructor.functionSignature; |
| 2094 } | 2146 } |
| 2095 | 2147 |
| 2096 bool get hasNode => constructor.hasNode; | 2148 bool get hasNode => constructor.hasNode; |
| 2097 | 2149 |
| 2098 FunctionExpression get node => constructor.node; | 2150 FunctionExpression get node => constructor.node; |
| 2099 | 2151 |
| 2100 Link<MetadataAnnotation> get metadata => constructor.metadata; | 2152 List<MetadataAnnotation> get metadata => constructor.metadata; |
| 2101 | 2153 |
| 2102 bool get isInstanceMember => true; | 2154 bool get isInstanceMember => true; |
| 2103 | 2155 |
| 2104 FunctionType computeType(Compiler compiler) { | 2156 FunctionType computeType(Compiler compiler) { |
| 2105 compiler.internalError(this, '$this.computeType.'); | 2157 compiler.internalError(this, '$this.computeType.'); |
| 2106 return null; | 2158 return null; |
| 2107 } | 2159 } |
| 2108 | 2160 |
| 2109 Token get position => constructor.position; | 2161 Token get position => constructor.position; |
| 2110 | 2162 |
| (...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2914 AstElement get definingElement; | 2966 AstElement get definingElement; |
| 2915 | 2967 |
| 2916 bool get hasResolvedAst => definingElement.hasTreeElements; | 2968 bool get hasResolvedAst => definingElement.hasTreeElements; |
| 2917 | 2969 |
| 2918 ResolvedAst get resolvedAst { | 2970 ResolvedAst get resolvedAst { |
| 2919 return new ResolvedAst(declaration, | 2971 return new ResolvedAst(declaration, |
| 2920 definingElement.node, definingElement.treeElements); | 2972 definingElement.node, definingElement.treeElements); |
| 2921 } | 2973 } |
| 2922 | 2974 |
| 2923 } | 2975 } |
| OLD | NEW |