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 part of resolution; | 5 part of resolution; |
| 6 | 6 |
| 7 abstract class TreeElements { | 7 abstract class TreeElements { |
| 8 Element get currentElement; | 8 Element get currentElement; |
| 9 Setlet<Node> get superUses; | 9 Setlet<Node> get superUses; |
| 10 | 10 |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 final ConstantCompiler constantCompiler; | 252 final ConstantCompiler constantCompiler; |
| 253 | 253 |
| 254 ResolverTask(Compiler compiler, this.constantCompiler) : super(compiler); | 254 ResolverTask(Compiler compiler, this.constantCompiler) : super(compiler); |
| 255 | 255 |
| 256 String get name => 'Resolver'; | 256 String get name => 'Resolver'; |
| 257 | 257 |
| 258 TreeElements resolve(Element element) { | 258 TreeElements resolve(Element element) { |
| 259 return measure(() { | 259 return measure(() { |
| 260 if (Elements.isErroneousElement(element)) return null; | 260 if (Elements.isErroneousElement(element)) return null; |
| 261 | 261 |
| 262 for (MetadataAnnotation metadata in element.metadata) { | 262 processMetadata([result]) { |
| 263 metadata.ensureResolved(compiler); | 263 for (MetadataAnnotation metadata in element.metadata) { |
| 264 metadata.ensureResolved(compiler); | |
| 265 } | |
| 266 return result; | |
| 264 } | 267 } |
| 265 | 268 |
| 266 ElementKind kind = element.kind; | 269 ElementKind kind = element.kind; |
| 267 if (identical(kind, ElementKind.GENERATIVE_CONSTRUCTOR) || | 270 if (identical(kind, ElementKind.GENERATIVE_CONSTRUCTOR) || |
| 268 identical(kind, ElementKind.FUNCTION) || | 271 identical(kind, ElementKind.FUNCTION) || |
| 269 identical(kind, ElementKind.GETTER) || | 272 identical(kind, ElementKind.GETTER) || |
| 270 identical(kind, ElementKind.SETTER)) { | 273 identical(kind, ElementKind.SETTER)) { |
| 271 return resolveMethodElement(element); | 274 return processMetadata(resolveMethodElement(element)); |
| 272 } | 275 } |
| 273 | 276 |
| 274 if (identical(kind, ElementKind.FIELD)) return resolveField(element); | 277 if (identical(kind, ElementKind.FIELD)) { |
| 275 | 278 return processMetadata(resolveField(element)); |
| 279 } | |
| 276 if (element.isClass) { | 280 if (element.isClass) { |
| 277 ClassElement cls = element; | 281 ClassElement cls = element; |
| 278 cls.ensureResolved(compiler); | 282 cls.ensureResolved(compiler); |
| 279 return null; | 283 return processMetadata(); |
| 280 } else if (element.isTypedef) { | 284 } else if (element.isTypedef) { |
| 281 TypedefElement typdef = element; | 285 TypedefElement typdef = element; |
| 282 return resolveTypedef(typdef); | 286 return processMetadata(resolveTypedef(typdef)); |
| 283 } | 287 } |
| 284 | 288 |
| 285 compiler.unimplemented(element, "resolve($element)"); | 289 compiler.unimplemented(element, "resolve($element)"); |
| 286 }); | 290 }); |
| 287 } | 291 } |
| 288 | 292 |
| 289 String constructorNameForDiagnostics(String className, | 293 String constructorNameForDiagnostics(String className, |
| 290 String constructorName) { | 294 String constructorName) { |
| 291 String classNameString = className; | 295 String classNameString = className; |
| 292 String constructorNameString = constructorName; | 296 String constructorNameString = constructorName; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 for (MixinApplicationElement mixinApplication in mixinUses) { | 539 for (MixinApplicationElement mixinApplication in mixinUses) { |
| 536 checkMixinSuperUses(resolutionTree, mixinApplication, mixin); | 540 checkMixinSuperUses(resolutionTree, mixinApplication, mixin); |
| 537 } | 541 } |
| 538 } | 542 } |
| 539 } | 543 } |
| 540 return resolutionTree; | 544 return resolutionTree; |
| 541 }); | 545 }); |
| 542 }); | 546 }); |
| 543 } | 547 } |
| 544 | 548 |
| 549 /// Creates a [ResolverVisitor] for resolving an AST in context of [element]. | |
| 550 /// If [useEnclosingScope] is `true` then the initial scope of the visitor | |
| 551 /// does not include inner scope of [element]. | |
| 552 /// | |
| 545 /// This method should only be used by this library (or tests of | 553 /// This method should only be used by this library (or tests of |
| 546 /// this library). | 554 /// this library). |
| 547 ResolverVisitor visitorFor(Element element) { | 555 ResolverVisitor visitorFor(Element element, {bool useEnclosingScope: false}) { |
| 548 return new ResolverVisitor(compiler, element, _ensureTreeElements(element)); | 556 return new ResolverVisitor(compiler, element, |
| 557 _ensureTreeElements(element), useEnclosingScope: useEnclosingScope); | |
| 549 } | 558 } |
| 550 | 559 |
| 551 TreeElements resolveField(VariableElementX element) { | 560 TreeElements resolveField(VariableElementX element) { |
| 552 VariableDefinitions tree = element.parseNode(compiler); | 561 VariableDefinitions tree = element.parseNode(compiler); |
| 553 if(element.modifiers.isStatic && element.isTopLevel) { | 562 if(element.modifiers.isStatic && element.isTopLevel) { |
| 554 error(element.modifiers.getStatic(), | 563 error(element.modifiers.getStatic(), |
| 555 MessageKind.TOP_LEVEL_VARIABLE_DECLARED_STATIC); | 564 MessageKind.TOP_LEVEL_VARIABLE_DECLARED_STATIC); |
| 556 } | 565 } |
| 557 ResolverVisitor visitor = visitorFor(element); | 566 ResolverVisitor visitor = visitorFor(element); |
| 558 // TODO(johnniwinther): Share the resolved type between all variables | 567 // TODO(johnniwinther): Share the resolved type between all variables |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1177 }); | 1186 }); |
| 1178 }); | 1187 }); |
| 1179 } | 1188 } |
| 1180 | 1189 |
| 1181 void resolveMetadataAnnotation(MetadataAnnotationX annotation) { | 1190 void resolveMetadataAnnotation(MetadataAnnotationX annotation) { |
| 1182 compiler.withCurrentElement(annotation.annotatedElement, () => measure(() { | 1191 compiler.withCurrentElement(annotation.annotatedElement, () => measure(() { |
| 1183 assert(annotation.resolutionState == STATE_NOT_STARTED); | 1192 assert(annotation.resolutionState == STATE_NOT_STARTED); |
| 1184 annotation.resolutionState = STATE_STARTED; | 1193 annotation.resolutionState = STATE_STARTED; |
| 1185 | 1194 |
| 1186 Node node = annotation.parseNode(compiler); | 1195 Node node = annotation.parseNode(compiler); |
| 1187 // TODO(johnniwinther): Find the right analyzable element to hold the | |
| 1188 // [TreeElements] for the annotation. | |
| 1189 Element annotatedElement = annotation.annotatedElement; | 1196 Element annotatedElement = annotation.annotatedElement; |
| 1190 Element context = annotatedElement.enclosingElement; | 1197 Element context = annotatedElement.analyzableElement; |
| 1191 if (context == null) { | 1198 assert(invariant(node, context != null, |
| 1192 context = annotatedElement; | 1199 message: "No context found for metadata annotation " |
| 1193 } | 1200 "on $annotatedElement.")); |
| 1194 ResolverVisitor visitor = visitorFor(context); | 1201 assert(invariant(node, context is AnalyzableElement, |
|
karlklose
2014/05/22 06:27:29
You could remove this, if the getter was typed ()
Johnni Winther
2014/05/22 10:09:09
Done.
| |
| 1202 message: "Unanalyzable context, $context, found for metadata " | |
| 1203 "annotation on $annotatedElement.")); | |
| 1204 ResolverVisitor visitor = visitorFor(context, useEnclosingScope: true); | |
| 1195 node.accept(visitor); | 1205 node.accept(visitor); |
| 1196 annotation.value = | 1206 annotation.value = |
| 1197 constantCompiler.compileMetadata(annotation, node, visitor.mapping); | 1207 constantCompiler.compileMetadata(annotation, node, visitor.mapping); |
| 1198 // TODO(johnniwinther): Register the relation between the annotation | 1208 // TODO(johnniwinther): Register the relation between the annotation |
| 1199 // and the annotated element instead. This will allow the backed to | 1209 // and the annotated element instead. This will allow the backend to |
| 1200 // retrieve the backend constant and only registered metadata on the | 1210 // retrieve the backend constant and only register metadata on the |
| 1201 // elements for which it is needed. (Issue 17732). | 1211 // elements for which it is needed. (Issue 17732). |
| 1202 compiler.backend.registerMetadataConstant( | 1212 compiler.backend.registerMetadataConstant( |
| 1203 annotation.value, visitor.mapping); | 1213 annotation.value, visitor.mapping); |
| 1204 annotation.resolutionState = STATE_DONE; | 1214 annotation.resolutionState = STATE_DONE; |
| 1205 })); | 1215 })); |
| 1206 } | 1216 } |
| 1207 | 1217 |
| 1208 error(Spannable node, MessageKind kind, [arguments = const {}]) { | 1218 error(Spannable node, MessageKind kind, [arguments = const {}]) { |
| 1209 // TODO(ahe): Make non-fatal. | 1219 // TODO(ahe): Make non-fatal. |
| 1210 compiler.reportFatalError(node, kind, arguments); | 1220 compiler.reportFatalError(node, kind, arguments); |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1995 r'>|' | 2005 r'>|' |
| 1996 r'<=|' | 2006 r'<=|' |
| 1997 r'<|' | 2007 r'<|' |
| 1998 r'&|' | 2008 r'&|' |
| 1999 r'\^|' | 2009 r'\^|' |
| 2000 r'\|' | 2010 r'\|' |
| 2001 r')$'); | 2011 r')$'); |
| 2002 | 2012 |
| 2003 ResolverVisitor(Compiler compiler, | 2013 ResolverVisitor(Compiler compiler, |
| 2004 Element element, | 2014 Element element, |
| 2005 TreeElementMapping mapping) | 2015 TreeElementMapping mapping, |
| 2016 {bool useEnclosingScope: false}) | |
| 2006 : this.enclosingElement = element, | 2017 : this.enclosingElement = element, |
| 2007 // When the element is a field, we are actually resolving its | 2018 // When the element is a field, we are actually resolving its |
| 2008 // initial value, which should not have access to instance | 2019 // initial value, which should not have access to instance |
| 2009 // fields. | 2020 // fields. |
| 2010 inInstanceContext = (element.isInstanceMember && !element.isField) | 2021 inInstanceContext = (element.isInstanceMember && !element.isField) |
| 2011 || element.isGenerativeConstructor, | 2022 || element.isGenerativeConstructor, |
| 2012 this.currentClass = element.isMember ? element.enclosingClass | 2023 this.currentClass = element.isMember ? element.enclosingClass |
| 2013 : null, | 2024 : null, |
| 2014 this.statementScope = new StatementScope(), | 2025 this.statementScope = new StatementScope(), |
| 2015 scope = element.buildScope(), | 2026 scope = useEnclosingScope |
| 2027 ? Scope.buildEnclosingScope(element) : element.buildScope(), | |
| 2016 // The type annotations on a typedef do not imply type checks. | 2028 // The type annotations on a typedef do not imply type checks. |
| 2017 // TODO(karlklose): clean this up (dartbug.com/8870). | 2029 // TODO(karlklose): clean this up (dartbug.com/8870). |
| 2018 inCheckContext = compiler.enableTypeAssertions && | 2030 inCheckContext = compiler.enableTypeAssertions && |
| 2019 !element.isLibrary && | 2031 !element.isLibrary && |
| 2020 !element.isTypedef && | 2032 !element.isTypedef && |
| 2021 !element.enclosingElement.isTypedef, | 2033 !element.enclosingElement.isTypedef, |
| 2022 inCatchBlock = false, | 2034 inCatchBlock = false, |
| 2023 super(compiler, mapping); | 2035 super(compiler, mapping); |
| 2024 | 2036 |
| 2025 ResolutionEnqueuer get world => compiler.enqueuer.resolution; | 2037 ResolutionEnqueuer get world => compiler.enqueuer.resolution; |
| (...skipping 2641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4667 TreeElements _treeElements; | 4679 TreeElements _treeElements; |
| 4668 | 4680 |
| 4669 bool get hasTreeElements => _treeElements != null; | 4681 bool get hasTreeElements => _treeElements != null; |
| 4670 | 4682 |
| 4671 TreeElements get treeElements { | 4683 TreeElements get treeElements { |
| 4672 assert(invariant(this, _treeElements !=null, | 4684 assert(invariant(this, _treeElements !=null, |
| 4673 message: "TreeElements have not been computed for $this.")); | 4685 message: "TreeElements have not been computed for $this.")); |
| 4674 return _treeElements; | 4686 return _treeElements; |
| 4675 } | 4687 } |
| 4676 } | 4688 } |
| OLD | NEW |