| 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 operator[](Node node); | 8 Element operator[](Node node); |
| 9 Selector getSelector(Send send); | 9 Selector getSelector(Send send); |
| 10 DartType getType(Node node); | 10 DartType getType(Node node); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 class ResolverTask extends CompilerTask { | 72 class ResolverTask extends CompilerTask { |
| 73 ResolverTask(Compiler compiler) : super(compiler); | 73 ResolverTask(Compiler compiler) : super(compiler); |
| 74 | 74 |
| 75 String get name => 'Resolver'; | 75 String get name => 'Resolver'; |
| 76 | 76 |
| 77 TreeElements resolve(Element element) { | 77 TreeElements resolve(Element element) { |
| 78 return measure(() { | 78 return measure(() { |
| 79 if (Elements.isErroneousElement(element)) return null; |
| 80 |
| 81 for (MetadataAnnotation metadata in element.metadata) { |
| 82 metadata.ensureResolved(compiler); |
| 83 } |
| 84 |
| 79 ElementKind kind = element.kind; | 85 ElementKind kind = element.kind; |
| 80 if (identical(kind, ElementKind.GENERATIVE_CONSTRUCTOR) || | 86 if (identical(kind, ElementKind.GENERATIVE_CONSTRUCTOR) || |
| 81 identical(kind, ElementKind.FUNCTION) || | 87 identical(kind, ElementKind.FUNCTION) || |
| 82 identical(kind, ElementKind.GETTER) || | 88 identical(kind, ElementKind.GETTER) || |
| 83 identical(kind, ElementKind.SETTER)) { | 89 identical(kind, ElementKind.SETTER)) { |
| 84 return resolveMethodElement(element); | 90 return resolveMethodElement(element); |
| 85 } | 91 } |
| 86 | 92 |
| 87 if (identical(kind, ElementKind.FIELD)) return resolveField(element); | 93 if (identical(kind, ElementKind.FIELD)) return resolveField(element); |
| 88 | 94 |
| 89 if (identical(kind, ElementKind.PARAMETER) || | 95 if (identical(kind, ElementKind.PARAMETER) || |
| 90 identical(kind, ElementKind.FIELD_PARAMETER)) { | 96 identical(kind, ElementKind.FIELD_PARAMETER)) { |
| 91 return resolveParameter(element); | 97 return resolveParameter(element); |
| 92 } | 98 } |
| 99 if (element.isClass()) { |
| 100 ClassElement cls = element; |
| 101 cls.ensureResolved(compiler); |
| 102 return null; |
| 103 } else if (element.isTypedef() || element.isTypeVariable()) { |
| 104 element.computeType(compiler); |
| 105 return null; |
| 106 } |
| 93 | 107 |
| 94 compiler.unimplemented("resolve($element)", | 108 compiler.unimplemented("resolve($element)", |
| 95 node: element.parseNode(compiler)); | 109 node: element.parseNode(compiler)); |
| 96 }); | 110 }); |
| 97 } | 111 } |
| 98 | 112 |
| 99 String constructorNameForDiagnostics(SourceString className, | 113 String constructorNameForDiagnostics(SourceString className, |
| 100 SourceString constructorName) { | 114 SourceString constructorName) { |
| 101 String classNameString = className.slowToString(); | 115 String classNameString = className.slowToString(); |
| 102 String constructorNameString = constructorName.slowToString(); | 116 String constructorNameString = constructorName.slowToString(); |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 element.defaultClass = element.origin.defaultClass; | 452 element.defaultClass = element.origin.defaultClass; |
| 439 element.interfaces = element.origin.interfaces; | 453 element.interfaces = element.origin.interfaces; |
| 440 element.allSupertypes = element.origin.allSupertypes; | 454 element.allSupertypes = element.origin.allSupertypes; |
| 441 // Stepwise assignment to ensure invariant. | 455 // Stepwise assignment to ensure invariant. |
| 442 element.supertypeLoadState = STATE_STARTED; | 456 element.supertypeLoadState = STATE_STARTED; |
| 443 element.supertypeLoadState = STATE_DONE; | 457 element.supertypeLoadState = STATE_DONE; |
| 444 element.resolutionState = STATE_DONE; | 458 element.resolutionState = STATE_DONE; |
| 445 // TODO(johnniwinther): Check matching type variables and | 459 // TODO(johnniwinther): Check matching type variables and |
| 446 // empty extends/implements clauses. | 460 // empty extends/implements clauses. |
| 447 } | 461 } |
| 462 for (MetadataAnnotation metadata in element.metadata) { |
| 463 metadata.ensureResolved(compiler); |
| 464 } |
| 448 } | 465 } |
| 449 | 466 |
| 450 void checkMembers(ClassElement cls) { | 467 void checkMembers(ClassElement cls) { |
| 451 assert(invariant(cls, cls.isDeclaration)); | 468 assert(invariant(cls, cls.isDeclaration)); |
| 452 if (cls.isObject(compiler)) return; | 469 if (cls.isObject(compiler)) return; |
| 453 // TODO(johnniwinther): Should this be done on the implementation element as | 470 // TODO(johnniwinther): Should this be done on the implementation element as |
| 454 // well? | 471 // well? |
| 455 cls.forEachMember((holder, member) { | 472 cls.forEachMember((holder, member) { |
| 456 // Perform various checks as side effect of "computing" the type. | 473 // Perform various checks as side effect of "computing" the type. |
| 457 member.computeType(compiler); | 474 member.computeType(compiler); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 void resolveMetadataAnnotation(PartialMetadataAnnotation annotation) { | 638 void resolveMetadataAnnotation(PartialMetadataAnnotation annotation) { |
| 622 compiler.withCurrentElement(annotation.annotatedElement, () => measure(() { | 639 compiler.withCurrentElement(annotation.annotatedElement, () => measure(() { |
| 623 assert(annotation.resolutionState == STATE_NOT_STARTED); | 640 assert(annotation.resolutionState == STATE_NOT_STARTED); |
| 624 annotation.resolutionState = STATE_STARTED; | 641 annotation.resolutionState = STATE_STARTED; |
| 625 | 642 |
| 626 Node node = annotation.parseNode(compiler); | 643 Node node = annotation.parseNode(compiler); |
| 627 ResolverVisitor visitor = | 644 ResolverVisitor visitor = |
| 628 visitorFor(annotation.annotatedElement.enclosingElement); | 645 visitorFor(annotation.annotatedElement.enclosingElement); |
| 629 node.accept(visitor); | 646 node.accept(visitor); |
| 630 annotation.value = compiler.constantHandler.compileNodeWithDefinitions( | 647 annotation.value = compiler.constantHandler.compileNodeWithDefinitions( |
| 631 node, visitor.mapping); | 648 node, visitor.mapping, isConst: true); |
| 632 | 649 |
| 633 annotation.resolutionState = STATE_DONE; | 650 annotation.resolutionState = STATE_DONE; |
| 634 })); | 651 })); |
| 635 } | 652 } |
| 636 | 653 |
| 637 error(Node node, MessageKind kind, [arguments = const []]) { | 654 error(Node node, MessageKind kind, [arguments = const []]) { |
| 638 ResolutionError message = new ResolutionError(kind, arguments); | 655 ResolutionError message = new ResolutionError(kind, arguments); |
| 639 compiler.reportError(node, message); | 656 compiler.reportError(node, message); |
| 640 } | 657 } |
| 641 } | 658 } |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1194 inCheckContext = compiler.enableTypeAssertions, | 1211 inCheckContext = compiler.enableTypeAssertions, |
| 1195 inCatchBlock = false, | 1212 inCatchBlock = false, |
| 1196 super(compiler); | 1213 super(compiler); |
| 1197 | 1214 |
| 1198 Enqueuer get world => compiler.enqueuer.resolution; | 1215 Enqueuer get world => compiler.enqueuer.resolution; |
| 1199 | 1216 |
| 1200 Element lookup(Node node, SourceString name) { | 1217 Element lookup(Node node, SourceString name) { |
| 1201 Element result = scope.lookup(name); | 1218 Element result = scope.lookup(name); |
| 1202 if (!Elements.isUnresolved(result)) { | 1219 if (!Elements.isUnresolved(result)) { |
| 1203 if (!inInstanceContext && result.isInstanceMember()) { | 1220 if (!inInstanceContext && result.isInstanceMember()) { |
| 1204 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]); | 1221 compiler.reportMessage(compiler.spanFromNode(node), |
| 1205 // TODO(johnniwinther): Create an ErroneousElement. | 1222 MessageKind.NO_INSTANCE_AVAILABLE.error([name]), |
| 1223 Diagnostic.ERROR); |
| 1224 return new ErroneousElement(MessageKind.NO_INSTANCE_AVAILABLE, |
| 1225 [name], |
| 1226 name, enclosingElement); |
| 1206 } else if (result.isAmbiguous()) { | 1227 } else if (result.isAmbiguous()) { |
| 1207 AmbiguousElement ambiguous = result; | 1228 AmbiguousElement ambiguous = result; |
| 1208 compiler.reportMessage(compiler.spanFromNode(node), | 1229 compiler.reportMessage(compiler.spanFromNode(node), |
| 1209 ambiguous.messageKind.error(ambiguous.messageArguments), | 1230 ambiguous.messageKind.error(ambiguous.messageArguments), |
| 1210 Diagnostic.ERROR); | 1231 Diagnostic.ERROR); |
| 1211 return new ErroneousElement(ambiguous.messageKind, | 1232 return new ErroneousElement(ambiguous.messageKind, |
| 1212 ambiguous.messageArguments, | 1233 ambiguous.messageArguments, |
| 1213 name, enclosingElement); | 1234 name, enclosingElement); |
| 1214 } | 1235 } |
| 1215 } | 1236 } |
| (...skipping 1857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3073 return e; | 3094 return e; |
| 3074 } | 3095 } |
| 3075 | 3096 |
| 3076 /// Assumed to be called by [resolveRedirectingFactory]. | 3097 /// Assumed to be called by [resolveRedirectingFactory]. |
| 3077 Element visitReturn(Return node) { | 3098 Element visitReturn(Return node) { |
| 3078 Node expression = node.expression; | 3099 Node expression = node.expression; |
| 3079 return finishConstructorReference(visit(expression), | 3100 return finishConstructorReference(visit(expression), |
| 3080 expression, expression); | 3101 expression, expression); |
| 3081 } | 3102 } |
| 3082 } | 3103 } |
| OLD | NEW |