| 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 abstract class TreeElements { | 5 abstract class TreeElements { |
| 6 Element operator[](Node node); | 6 Element operator[](Node node); |
| 7 Selector getSelector(Send send); | 7 Selector getSelector(Send send); |
| 8 DartType getType(TypeAnnotation annotation); | 8 DartType getType(TypeAnnotation annotation); |
| 9 bool isParameterChecked(Element element); | 9 bool isParameterChecked(Element element); |
| 10 } | 10 } |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 * Warning: do not call this method directly. It should only be | 388 * Warning: do not call this method directly. It should only be |
| 389 * called by [resolveClass] and [ClassSupertypeResolver]. | 389 * called by [resolveClass] and [ClassSupertypeResolver]. |
| 390 */ | 390 */ |
| 391 void loadSupertypes(ClassElement cls, Node from) { | 391 void loadSupertypes(ClassElement cls, Node from) { |
| 392 compiler.withCurrentElement(cls, () => measure(() { | 392 compiler.withCurrentElement(cls, () => measure(() { |
| 393 if (cls.supertypeLoadState == STATE_DONE) return; | 393 if (cls.supertypeLoadState == STATE_DONE) return; |
| 394 if (cls.supertypeLoadState == STATE_STARTED) { | 394 if (cls.supertypeLoadState == STATE_STARTED) { |
| 395 compiler.reportMessage( | 395 compiler.reportMessage( |
| 396 compiler.spanFromNode(from), | 396 compiler.spanFromNode(from), |
| 397 MessageKind.CYCLIC_CLASS_HIERARCHY.error([cls.name]), | 397 MessageKind.CYCLIC_CLASS_HIERARCHY.error([cls.name]), |
| 398 api.Diagnostic.ERROR); | 398 Diagnostic.ERROR); |
| 399 cls.supertypeLoadState = STATE_DONE; | 399 cls.supertypeLoadState = STATE_DONE; |
| 400 cls.allSupertypes = const Link<DartType>().prepend( | 400 cls.allSupertypes = const Link<DartType>().prepend( |
| 401 compiler.objectClass.computeType(compiler)); | 401 compiler.objectClass.computeType(compiler)); |
| 402 // TODO(ahe): We should also set cls.supertype here to avoid | 402 // TODO(ahe): We should also set cls.supertype here to avoid |
| 403 // creating a malformed class hierarchy. | 403 // creating a malformed class hierarchy. |
| 404 return; | 404 return; |
| 405 } | 405 } |
| 406 cls.supertypeLoadState = STATE_STARTED; | 406 cls.supertypeLoadState = STATE_STARTED; |
| 407 compiler.withCurrentElement(cls, () { | 407 compiler.withCurrentElement(cls, () { |
| 408 // TODO(ahe): Cache the node in cls. | 408 // TODO(ahe): Cache the node in cls. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 // well? | 470 // well? |
| 471 cls.forEachMember((holder, member) { | 471 cls.forEachMember((holder, member) { |
| 472 // Perform various checks as side effect of "computing" the type. | 472 // Perform various checks as side effect of "computing" the type. |
| 473 member.computeType(compiler); | 473 member.computeType(compiler); |
| 474 | 474 |
| 475 // Check modifiers. | 475 // Check modifiers. |
| 476 if (member.isFunction() && member.modifiers.isFinal()) { | 476 if (member.isFunction() && member.modifiers.isFinal()) { |
| 477 compiler.reportMessage( | 477 compiler.reportMessage( |
| 478 compiler.spanFromElement(member), | 478 compiler.spanFromElement(member), |
| 479 MessageKind.ILLEGAL_FINAL_METHOD_MODIFIER.error(), | 479 MessageKind.ILLEGAL_FINAL_METHOD_MODIFIER.error(), |
| 480 api.Diagnostic.ERROR); | 480 Diagnostic.ERROR); |
| 481 } | 481 } |
| 482 if (member.isConstructor()) { | 482 if (member.isConstructor()) { |
| 483 final mismatchedFlagsBits = | 483 final mismatchedFlagsBits = |
| 484 member.modifiers.flags & | 484 member.modifiers.flags & |
| 485 (Modifiers.FLAG_STATIC | Modifiers.FLAG_ABSTRACT); | 485 (Modifiers.FLAG_STATIC | Modifiers.FLAG_ABSTRACT); |
| 486 if (mismatchedFlagsBits != 0) { | 486 if (mismatchedFlagsBits != 0) { |
| 487 final mismatchedFlags = | 487 final mismatchedFlags = |
| 488 new Modifiers.withFlags(null, mismatchedFlagsBits); | 488 new Modifiers.withFlags(null, mismatchedFlagsBits); |
| 489 compiler.reportMessage( | 489 compiler.reportMessage( |
| 490 compiler.spanFromElement(member), | 490 compiler.spanFromElement(member), |
| 491 MessageKind.ILLEGAL_CONSTRUCTOR_MODIFIERS.error([mismatchedFlags]), | 491 MessageKind.ILLEGAL_CONSTRUCTOR_MODIFIERS.error([mismatchedFlags]), |
| 492 api.Diagnostic.ERROR); | 492 Diagnostic.ERROR); |
| 493 } | 493 } |
| 494 } | 494 } |
| 495 checkAbstractField(member); | 495 checkAbstractField(member); |
| 496 checkValidOverride(member, cls.lookupSuperMember(member.name)); | 496 checkValidOverride(member, cls.lookupSuperMember(member.name)); |
| 497 }); | 497 }); |
| 498 } | 498 } |
| 499 | 499 |
| 500 void checkAbstractField(Element member) { | 500 void checkAbstractField(Element member) { |
| 501 // Only check for getters. The test can only fail if there is both a setter | 501 // Only check for getters. The test can only fail if there is both a setter |
| 502 // and a getter with the same name, and we only need to check each abstract | 502 // and a getter with the same name, and we only need to check each abstract |
| (...skipping 15 matching lines...) Expand all Loading... |
| 518 if (field.getter == null) return; | 518 if (field.getter == null) return; |
| 519 if (field.setter == null) return; | 519 if (field.setter == null) return; |
| 520 int getterFlags = field.getter.modifiers.flags | Modifiers.FLAG_ABSTRACT; | 520 int getterFlags = field.getter.modifiers.flags | Modifiers.FLAG_ABSTRACT; |
| 521 int setterFlags = field.setter.modifiers.flags | Modifiers.FLAG_ABSTRACT; | 521 int setterFlags = field.setter.modifiers.flags | Modifiers.FLAG_ABSTRACT; |
| 522 if (!identical(getterFlags, setterFlags)) { | 522 if (!identical(getterFlags, setterFlags)) { |
| 523 final mismatchedFlags = | 523 final mismatchedFlags = |
| 524 new Modifiers.withFlags(null, getterFlags ^ setterFlags); | 524 new Modifiers.withFlags(null, getterFlags ^ setterFlags); |
| 525 compiler.reportMessage( | 525 compiler.reportMessage( |
| 526 compiler.spanFromElement(field.getter), | 526 compiler.spanFromElement(field.getter), |
| 527 MessageKind.GETTER_MISMATCH.error([mismatchedFlags]), | 527 MessageKind.GETTER_MISMATCH.error([mismatchedFlags]), |
| 528 api.Diagnostic.ERROR); | 528 Diagnostic.ERROR); |
| 529 compiler.reportMessage( | 529 compiler.reportMessage( |
| 530 compiler.spanFromElement(field.setter), | 530 compiler.spanFromElement(field.setter), |
| 531 MessageKind.SETTER_MISMATCH.error([mismatchedFlags]), | 531 MessageKind.SETTER_MISMATCH.error([mismatchedFlags]), |
| 532 api.Diagnostic.ERROR); | 532 Diagnostic.ERROR); |
| 533 } | 533 } |
| 534 } | 534 } |
| 535 | 535 |
| 536 reportErrorWithContext(Element errorneousElement, | 536 reportErrorWithContext(Element errorneousElement, |
| 537 MessageKind errorMessage, | 537 MessageKind errorMessage, |
| 538 Element contextElement, | 538 Element contextElement, |
| 539 MessageKind contextMessage) { | 539 MessageKind contextMessage) { |
| 540 compiler.reportMessage( | 540 compiler.reportMessage( |
| 541 compiler.spanFromElement(errorneousElement), | 541 compiler.spanFromElement(errorneousElement), |
| 542 errorMessage.error([contextElement.name, | 542 errorMessage.error([contextElement.name, |
| 543 contextElement.getEnclosingClass().name]), | 543 contextElement.getEnclosingClass().name]), |
| 544 api.Diagnostic.ERROR); | 544 Diagnostic.ERROR); |
| 545 compiler.reportMessage( | 545 compiler.reportMessage( |
| 546 compiler.spanFromElement(contextElement), | 546 compiler.spanFromElement(contextElement), |
| 547 contextMessage.error(), | 547 contextMessage.error(), |
| 548 api.Diagnostic.INFO); | 548 Diagnostic.INFO); |
| 549 } | 549 } |
| 550 | 550 |
| 551 void checkValidOverride(Element member, Element superMember) { | 551 void checkValidOverride(Element member, Element superMember) { |
| 552 if (superMember == null) return; | 552 if (superMember == null) return; |
| 553 if (member.modifiers.isStatic()) { | 553 if (member.modifiers.isStatic()) { |
| 554 reportErrorWithContext( | 554 reportErrorWithContext( |
| 555 member, MessageKind.NO_STATIC_OVERRIDE, | 555 member, MessageKind.NO_STATIC_OVERRIDE, |
| 556 superMember, MessageKind.NO_STATIC_OVERRIDE_CONT); | 556 superMember, MessageKind.NO_STATIC_OVERRIDE_CONT); |
| 557 } else { | 557 } else { |
| 558 FunctionElement superFunction = superMember.asFunctionElement(); | 558 FunctionElement superFunction = superMember.asFunctionElement(); |
| (...skipping 2022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2581 error(node, MessageKind.CANNOT_RESOLVE_TYPE, [node]); | 2581 error(node, MessageKind.CANNOT_RESOLVE_TYPE, [node]); |
| 2582 } else if (!element.impliesType()) { | 2582 } else if (!element.impliesType()) { |
| 2583 error(node, MessageKind.NOT_A_TYPE, [node]); | 2583 error(node, MessageKind.NOT_A_TYPE, [node]); |
| 2584 } else { | 2584 } else { |
| 2585 if (element.isClass()) { | 2585 if (element.isClass()) { |
| 2586 loadSupertype(element, node); | 2586 loadSupertype(element, node); |
| 2587 } else { | 2587 } else { |
| 2588 compiler.reportMessage( | 2588 compiler.reportMessage( |
| 2589 compiler.spanFromNode(node), | 2589 compiler.spanFromNode(node), |
| 2590 MessageKind.TYPE_NAME_EXPECTED.error([]), | 2590 MessageKind.TYPE_NAME_EXPECTED.error([]), |
| 2591 api.Diagnostic.ERROR); | 2591 Diagnostic.ERROR); |
| 2592 } | 2592 } |
| 2593 } | 2593 } |
| 2594 } | 2594 } |
| 2595 | 2595 |
| 2596 void visitSend(Send node) { | 2596 void visitSend(Send node) { |
| 2597 Identifier prefix = node.receiver.asIdentifier(); | 2597 Identifier prefix = node.receiver.asIdentifier(); |
| 2598 if (prefix == null) { | 2598 if (prefix == null) { |
| 2599 error(node.receiver, MessageKind.NOT_A_PREFIX, [node.receiver]); | 2599 error(node.receiver, MessageKind.NOT_A_PREFIX, [node.receiver]); |
| 2600 return; | 2600 return; |
| 2601 } | 2601 } |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2792 NodeList formalParameters, | 2792 NodeList formalParameters, |
| 2793 Node returnNode, | 2793 Node returnNode, |
| 2794 Element element) { | 2794 Element element) { |
| 2795 SignatureResolver visitor = new SignatureResolver(compiler, element); | 2795 SignatureResolver visitor = new SignatureResolver(compiler, element); |
| 2796 Link<Element> parameters = const Link<Element>(); | 2796 Link<Element> parameters = const Link<Element>(); |
| 2797 int requiredParameterCount = 0; | 2797 int requiredParameterCount = 0; |
| 2798 if (formalParameters == null) { | 2798 if (formalParameters == null) { |
| 2799 if (!element.isGetter()) { | 2799 if (!element.isGetter()) { |
| 2800 compiler.reportMessage(compiler.spanFromElement(element), | 2800 compiler.reportMessage(compiler.spanFromElement(element), |
| 2801 MessageKind.MISSING_FORMALS.error([]), | 2801 MessageKind.MISSING_FORMALS.error([]), |
| 2802 api.Diagnostic.ERROR); | 2802 Diagnostic.ERROR); |
| 2803 } | 2803 } |
| 2804 } else { | 2804 } else { |
| 2805 if (element.isGetter()) { | 2805 if (element.isGetter()) { |
| 2806 if (!element.getLibrary().isPlatformLibrary) { | 2806 if (!element.getLibrary().isPlatformLibrary) { |
| 2807 // TODO(ahe): Remove the isPlatformLibrary check. | 2807 // TODO(ahe): Remove the isPlatformLibrary check. |
| 2808 if (!identical(formalParameters.getEndToken().next.stringValue, 'nativ
e')) { | 2808 if (!identical(formalParameters.getEndToken().next.stringValue, 'nativ
e')) { |
| 2809 // TODO(ahe): Remove the check for native keyword. | 2809 // TODO(ahe): Remove the check for native keyword. |
| 2810 compiler.reportMessage(compiler.spanFromNode(formalParameters), | 2810 compiler.reportMessage(compiler.spanFromNode(formalParameters), |
| 2811 MessageKind.EXTRA_FORMALS.error([]), | 2811 MessageKind.EXTRA_FORMALS.error([]), |
| 2812 api.Diagnostic.WARNING); | 2812 Diagnostic.WARNING); |
| 2813 } | 2813 } |
| 2814 } | 2814 } |
| 2815 } | 2815 } |
| 2816 LinkBuilder<Element> parametersBuilder = | 2816 LinkBuilder<Element> parametersBuilder = |
| 2817 visitor.analyzeNodes(formalParameters.nodes); | 2817 visitor.analyzeNodes(formalParameters.nodes); |
| 2818 requiredParameterCount = parametersBuilder.length; | 2818 requiredParameterCount = parametersBuilder.length; |
| 2819 parameters = parametersBuilder.toLink(); | 2819 parameters = parametersBuilder.toLink(); |
| 2820 } | 2820 } |
| 2821 DartType returnType = compiler.resolveReturnType(element, returnNode); | 2821 DartType returnType = compiler.resolveReturnType(element, returnNode); |
| 2822 return new FunctionSignature(parameters, | 2822 return new FunctionSignature(parameters, |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3222 return result; | 3222 return result; |
| 3223 } | 3223 } |
| 3224 Element lookup(SourceString name) => localLookup(name); | 3224 Element lookup(SourceString name) => localLookup(name); |
| 3225 Element lexicalLookup(SourceString name) => localLookup(name); | 3225 Element lexicalLookup(SourceString name) => localLookup(name); |
| 3226 | 3226 |
| 3227 Element add(Element newElement) { | 3227 Element add(Element newElement) { |
| 3228 throw "Cannot add an element in a patch library scope"; | 3228 throw "Cannot add an element in a patch library scope"; |
| 3229 } | 3229 } |
| 3230 String toString() => 'PatchLibraryScope($origin,$patch)'; | 3230 String toString() => 'PatchLibraryScope($origin,$patch)'; |
| 3231 } | 3231 } |
| OLD | NEW |