| 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 #library('elements'); | 5 #library('elements'); |
| 6 | 6 |
| 7 #import('../tree/tree.dart'); | 7 #import('../tree/tree.dart'); |
| 8 #import('../scanner/scannerlib.dart'); | 8 #import('../scanner/scannerlib.dart'); |
| 9 #import('../leg.dart'); // TODO(karlklose): we only need type. | 9 #import('../leg.dart'); // TODO(karlklose): we only need type. |
| 10 #import('../util/util.dart'); | 10 #import('../util/util.dart'); |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 } | 617 } |
| 618 | 618 |
| 619 static bool isInstanceField(Element element) { | 619 static bool isInstanceField(Element element) { |
| 620 return (element !== null) | 620 return (element !== null) |
| 621 && element.isInstanceMember() | 621 && element.isInstanceMember() |
| 622 && (element.kind === ElementKind.FIELD | 622 && (element.kind === ElementKind.FIELD |
| 623 || element.kind === ElementKind.GETTER | 623 || element.kind === ElementKind.GETTER |
| 624 || element.kind === ElementKind.SETTER); | 624 || element.kind === ElementKind.SETTER); |
| 625 } | 625 } |
| 626 | 626 |
| 627 static bool isStaticOrTopLevelField(Element element) { | 627 static bool isStaticOrTopLevel(Element element) { |
| 628 return (element != null) | 628 return (element != null) |
| 629 && !element.isInstanceMember() | 629 && !element.isInstanceMember() |
| 630 && element.enclosingElement !== null |
| 631 && (element.enclosingElement.kind == ElementKind.CLASS || |
| 632 element.enclosingElement.kind == ElementKind.COMPILATION_UNIT || |
| 633 element.enclosingElement.kind == ElementKind.LIBRARY); |
| 634 } |
| 635 |
| 636 static bool isStaticOrTopLevelField(Element element) { |
| 637 return isStaticOrTopLevel(element) |
| 630 && (element.kind === ElementKind.FIELD | 638 && (element.kind === ElementKind.FIELD |
| 631 || element.kind === ElementKind.GETTER | 639 || element.kind === ElementKind.GETTER |
| 632 || element.kind === ElementKind.SETTER); | 640 || element.kind === ElementKind.SETTER); |
| 633 } | 641 } |
| 634 | 642 |
| 635 static bool isStaticOrTopLevelFunction(Element element) { | 643 static bool isStaticOrTopLevelFunction(Element element) { |
| 636 return (element != null) | 644 return isStaticOrTopLevel(element) |
| 637 && !element.isInstanceMember() | 645 && (element.kind === ElementKind.FUNCTION); |
| 638 && (element.kind === ElementKind.FUNCTION); | |
| 639 } | 646 } |
| 640 | 647 |
| 641 static bool isInstanceMethod(Element element) { | 648 static bool isInstanceMethod(Element element) { |
| 642 return (element != null) | 649 return (element != null) |
| 643 && element.isInstanceMember() | 650 && element.isInstanceMember() |
| 644 && (element.kind === ElementKind.FUNCTION); | 651 && (element.kind === ElementKind.FUNCTION); |
| 645 } | 652 } |
| 646 | 653 |
| 647 static bool isInstanceSend(Send send, TreeElements elements) { | 654 static bool isInstanceSend(Send send, TreeElements elements) { |
| 648 Element element = elements[send]; | 655 Element element = elements[send]; |
| 649 if (element === null) return !isClosureSend(send, elements); | 656 if (element === null) return !isClosureSend(send, elements); |
| 650 return isInstanceMethod(element) || isInstanceField(element); | 657 return isInstanceMethod(element) || isInstanceField(element); |
| 651 } | 658 } |
| 652 | 659 |
| 653 static bool isClosureSend(Send send, TreeElements elements) { | 660 static bool isClosureSend(Send send, TreeElements elements) { |
| 654 if (send.isPropertyAccess) return false; | 661 if (send.isPropertyAccess) return false; |
| 655 if (send.receiver !== null) return false; | 662 if (send.receiver !== null) return false; |
| 656 Element element = elements[send]; | 663 Element element = elements[send]; |
| 657 // (o)() or foo()(). | 664 // (o)() or foo()(). |
| 658 if (element === null && send.selector.asIdentifier() === null) return true; | 665 if (element === null && send.selector.asIdentifier() === null) return true; |
| 659 if (element === null) return false; | 666 if (element === null) return false; |
| 660 // foo() with foo a local or a parameter. | 667 // foo() with foo a local or a parameter. |
| 661 return element.isVariable() || element.isParameter(); | 668 return isLocal(element); |
| 662 } | 669 } |
| 663 | 670 |
| 664 static SourceString constructConstructorName(SourceString receiver, | 671 static SourceString constructConstructorName(SourceString receiver, |
| 665 SourceString selector) { | 672 SourceString selector) { |
| 666 return new SourceString('$receiver\$$selector'); | 673 return new SourceString('$receiver\$$selector'); |
| 667 } | 674 } |
| 668 | 675 |
| 669 static SourceString constructOperatorName(SourceString receiver, | 676 static SourceString constructOperatorName(SourceString receiver, |
| 670 SourceString selector, | 677 SourceString selector, |
| 671 [bool isPrefix = false]) { | 678 [bool isPrefix = false]) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 687 else if (str === '>=') str = 'ge'; | 694 else if (str === '>=') str = 'ge'; |
| 688 else if (str === '>') str = 'gt'; | 695 else if (str === '>') str = 'gt'; |
| 689 else if (str === '<=') str = 'le'; | 696 else if (str === '<=') str = 'le'; |
| 690 else if (str === '<') str = 'lt'; | 697 else if (str === '<') str = 'lt'; |
| 691 else if (str === '&' || str === '&=') str = 'and'; | 698 else if (str === '&' || str === '&=') str = 'and'; |
| 692 else if (str === '^' || str === '^=') str = 'xor'; | 699 else if (str === '^' || str === '^=') str = 'xor'; |
| 693 else if (str === '|' || str === '|=') str = 'or'; | 700 else if (str === '|' || str === '|=') str = 'or'; |
| 694 return new SourceString('$receiver\$$str'); | 701 return new SourceString('$receiver\$$str'); |
| 695 } | 702 } |
| 696 } | 703 } |
| OLD | NEW |