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 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 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 new Modifiers.withFlags(null, mismatchedFlagsBits); | 514 new Modifiers.withFlags(null, mismatchedFlagsBits); |
| 515 compiler.reportMessage( | 515 compiler.reportMessage( |
| 516 compiler.spanFromElement(member), | 516 compiler.spanFromElement(member), |
| 517 MessageKind.ILLEGAL_CONSTRUCTOR_MODIFIERS.error([mismatchedFlags]), | 517 MessageKind.ILLEGAL_CONSTRUCTOR_MODIFIERS.error([mismatchedFlags]), |
| 518 Diagnostic.ERROR); | 518 Diagnostic.ERROR); |
| 519 } | 519 } |
| 520 checkConstructorNameHack(holder, member); | 520 checkConstructorNameHack(holder, member); |
| 521 } | 521 } |
| 522 checkAbstractField(member); | 522 checkAbstractField(member); |
| 523 checkValidOverride(member, cls.lookupSuperMember(member.name)); | 523 checkValidOverride(member, cls.lookupSuperMember(member.name)); |
| 524 checkUserDefinableOperator(member); | |
| 524 }); | 525 }); |
| 525 } | 526 } |
| 526 | 527 |
| 527 // TODO(ahe): Remove this method. It is only needed while we store | 528 // TODO(ahe): Remove this method. It is only needed while we store |
| 528 // constructor names as ClassName$id. Once we start storing | 529 // constructor names as ClassName$id. Once we start storing |
| 529 // constructors as just id, this will be caught by the general | 530 // constructors as just id, this will be caught by the general |
| 530 // mechanism for duplicate members. | 531 // mechanism for duplicate members. |
| 531 /// Check that a constructor name does not conflict with a member. | 532 /// Check that a constructor name does not conflict with a member. |
| 532 void checkConstructorNameHack(ClassElement holder, FunctionElement member) { | 533 void checkConstructorNameHack(ClassElement holder, FunctionElement member) { |
| 533 // If the name of the constructor is the same as the name of the | 534 // If the name of the constructor is the same as the name of the |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 compiler.spanFromElement(field.getter), | 583 compiler.spanFromElement(field.getter), |
| 583 MessageKind.GETTER_MISMATCH.error([mismatchedFlags]), | 584 MessageKind.GETTER_MISMATCH.error([mismatchedFlags]), |
| 584 Diagnostic.ERROR); | 585 Diagnostic.ERROR); |
| 585 compiler.reportMessage( | 586 compiler.reportMessage( |
| 586 compiler.spanFromElement(field.setter), | 587 compiler.spanFromElement(field.setter), |
| 587 MessageKind.SETTER_MISMATCH.error([mismatchedFlags]), | 588 MessageKind.SETTER_MISMATCH.error([mismatchedFlags]), |
| 588 Diagnostic.ERROR); | 589 Diagnostic.ERROR); |
| 589 } | 590 } |
| 590 } | 591 } |
| 591 | 592 |
| 593 void checkUserDefinableOperator(Element member) { | |
| 594 FunctionElement function = member.asFunctionElement(); | |
| 595 if (function == null) return; | |
| 596 String value = member.name.stringValue; | |
| 597 if (value == null) return; | |
| 598 if (!(isUserDefinableOperator(value) || identical(value, 'unary-'))) return; | |
| 599 | |
| 600 FunctionSignature signature = function.computeSignature(compiler); | |
| 601 if (identical(value, 'unary-')) { | |
|
ahe
2013/01/09 10:17:52
Consider this approach:
int requiredParameterCoun
Johnni Winther
2013/01/09 13:00:47
Done.
| |
| 602 if (signature.requiredParameterCount != 0) { | |
|
ahe
2013/01/09 10:17:52
You should be able to assert this.
| |
| 603 compiler.reportMessage( | |
| 604 compiler.spanFromElement(function), | |
| 605 MessageKind.MINUS_OPERATOR_BAD_ARITY.error(), | |
| 606 Diagnostic.ERROR); | |
| 607 } | |
| 608 } else if (isMinusOperator(value)) { | |
| 609 if (signature.requiredParameterCount != 1) { | |
| 610 compiler.reportMessage( | |
| 611 compiler.spanFromElement(function), | |
| 612 MessageKind.MINUS_OPERATOR_BAD_ARITY.error(), | |
| 613 Diagnostic.ERROR); | |
| 614 } | |
| 615 } else if (isUnaryOperator(value)) { | |
| 616 if (signature.requiredParameterCount != 0) { | |
| 617 compiler.reportMessage( | |
| 618 compiler.spanFromElement(function), | |
| 619 MessageKind.UNARY_OPERATOR_BAD_ARITY.error([function.name]), | |
| 620 Diagnostic.ERROR); | |
| 621 } | |
| 622 } else if (isBinaryOperator(value)) { | |
| 623 if (signature.requiredParameterCount != 1) { | |
| 624 compiler.reportMessage( | |
| 625 compiler.spanFromElement(function), | |
| 626 MessageKind.BINARY_OPERATOR_BAD_ARITY.error([function.name]), | |
| 627 Diagnostic.ERROR); | |
| 628 } | |
| 629 } else if (isTernaryOperator(value)) { | |
| 630 if (signature.requiredParameterCount != 2) { | |
| 631 compiler.reportMessage( | |
| 632 compiler.spanFromElement(function), | |
| 633 MessageKind.TERNARY_OPERATOR_BAD_ARITY.error([function.name]), | |
| 634 Diagnostic.ERROR); | |
| 635 } | |
| 636 } | |
|
ahe
2013/01/09 10:17:52
else {
// Internal error.
}
Johnni Winther
2013/01/09 13:00:47
Done.
| |
| 637 if (signature.optionalParameterCount != 0) { | |
| 638 if (signature.optionalParametersAreNamed) { | |
| 639 compiler.reportMessage( | |
| 640 compiler.spanFromElement(function), | |
|
ahe
2013/01/09 10:17:52
There is a more accurate position for the optional
Johnni Winther
2013/01/09 13:00:47
Done.
| |
| 641 MessageKind.OPERATOR_NAMED_ARGUMENTS.error([function.name]), | |
| 642 Diagnostic.ERROR); | |
| 643 } else { | |
| 644 compiler.reportMessage( | |
| 645 compiler.spanFromElement(function), | |
|
ahe
2013/01/09 10:17:52
Ditto.
Johnni Winther
2013/01/09 13:00:47
Done.
| |
| 646 MessageKind.OPERATOR_OPTIONAL_ARGUMENTS.error([function.name]), | |
| 647 Diagnostic.ERROR); | |
| 648 } | |
| 649 } | |
| 650 } | |
| 651 | |
| 592 reportErrorWithContext(Element errorneousElement, | 652 reportErrorWithContext(Element errorneousElement, |
| 593 MessageKind errorMessage, | 653 MessageKind errorMessage, |
| 594 Element contextElement, | 654 Element contextElement, |
| 595 MessageKind contextMessage) { | 655 MessageKind contextMessage) { |
| 596 compiler.reportMessage( | 656 compiler.reportMessage( |
| 597 compiler.spanFromElement(errorneousElement), | 657 compiler.spanFromElement(errorneousElement), |
| 598 errorMessage.error([contextElement.name, | 658 errorMessage.error([contextElement.name, |
| 599 contextElement.getEnclosingClass().name]), | 659 contextElement.getEnclosingClass().name]), |
| 600 Diagnostic.ERROR); | 660 Diagnostic.ERROR); |
| 601 compiler.reportMessage( | 661 compiler.reportMessage( |
| (...skipping 2716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3318 return e; | 3378 return e; |
| 3319 } | 3379 } |
| 3320 | 3380 |
| 3321 /// Assumed to be called by [resolveRedirectingFactory]. | 3381 /// Assumed to be called by [resolveRedirectingFactory]. |
| 3322 Element visitReturn(Return node) { | 3382 Element visitReturn(Return node) { |
| 3323 Node expression = node.expression; | 3383 Node expression = node.expression; |
| 3324 return finishConstructorReference(visit(expression), | 3384 return finishConstructorReference(visit(expression), |
| 3325 expression, expression); | 3385 expression, expression); |
| 3326 } | 3386 } |
| 3327 } | 3387 } |
| OLD | NEW |