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 #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 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 isStaticOrTopLevelField(Element element) { |
| 628 return (element != null) | 628 return (element != null) |
| 629 && !element.isInstanceMember() | 629 && !element.isInstanceMember() |
| 630 && (element.enclosingElement.kind == ElementKind.CLASS || | |
| 631 element.enclosingElement.kind == ElementKind.COMPILATION_UNIT || | |
| 632 element.enclosingElement.kind == ElementKind.LIBRARY) | |
|
ngeoffray
2012/02/13 10:13:38
I believe element.enclosing is null for library el
floitsch
2012/02/13 12:03:42
done (null check).
refactored into a isStaticOrTop
| |
| 630 && (element.kind === ElementKind.FIELD | 633 && (element.kind === ElementKind.FIELD |
| 631 || element.kind === ElementKind.GETTER | 634 || element.kind === ElementKind.GETTER |
| 632 || element.kind === ElementKind.SETTER); | 635 || element.kind === ElementKind.SETTER); |
|
ngeoffray
2012/02/13 10:13:38
Which of these kinds do not have an enclosing as c
floitsch
2012/02/13 12:03:42
refactored.
| |
| 633 } | 636 } |
| 634 | 637 |
| 635 static bool isStaticOrTopLevelFunction(Element element) { | 638 static bool isStaticOrTopLevelFunction(Element element) { |
| 636 return (element != null) | 639 return (element != null) |
| 637 && !element.isInstanceMember() | 640 && !element.isInstanceMember() |
| 641 && (element.enclosingElement.kind == ElementKind.CLASS || | |
| 642 element.enclosingElement.kind == ElementKind.COMPILATION_UNIT || | |
| 643 element.enclosingElement.kind == ElementKind.LIBRARY) | |
|
ngeoffray
2012/02/13 10:13:38
Same comments as above.
floitsch
2012/02/13 12:03:42
the enclosing element of JS is LIBRARY.
| |
| 638 && (element.kind === ElementKind.FUNCTION); | 644 && (element.kind === ElementKind.FUNCTION); |
| 639 } | 645 } |
| 640 | 646 |
| 641 static bool isInstanceMethod(Element element) { | 647 static bool isInstanceMethod(Element element) { |
| 642 return (element != null) | 648 return (element != null) |
| 643 && element.isInstanceMember() | 649 && element.isInstanceMember() |
| 644 && (element.kind === ElementKind.FUNCTION); | 650 && (element.kind === ElementKind.FUNCTION); |
| 645 } | 651 } |
| 646 | 652 |
| 647 static bool isInstanceSend(Send send, TreeElements elements) { | 653 static bool isInstanceSend(Send send, TreeElements elements) { |
| 648 Element element = elements[send]; | 654 Element element = elements[send]; |
| 649 if (element === null) return !isClosureSend(send, elements); | 655 if (element === null) return !isClosureSend(send, elements); |
| 650 return isInstanceMethod(element) || isInstanceField(element); | 656 return isInstanceMethod(element) || isInstanceField(element); |
| 651 } | 657 } |
| 652 | 658 |
| 653 static bool isClosureSend(Send send, TreeElements elements) { | 659 static bool isClosureSend(Send send, TreeElements elements) { |
| 654 if (send.isPropertyAccess) return false; | 660 if (send.isPropertyAccess) return false; |
| 655 if (send.receiver !== null) return false; | 661 if (send.receiver !== null) return false; |
| 656 Element element = elements[send]; | 662 Element element = elements[send]; |
| 657 // (o)() or foo()(). | 663 // (o)() or foo()(). |
| 658 if (element === null && send.selector.asIdentifier() === null) return true; | 664 if (element === null && send.selector.asIdentifier() === null) return true; |
| 659 if (element === null) return false; | 665 if (element === null) return false; |
| 660 // foo() with foo a local or a parameter. | 666 // foo() with foo a local or a parameter. |
| 661 return element.isVariable() || element.isParameter(); | 667 if (element.isVariable() || element.isParameter()) return true; |
|
ngeoffray
2012/02/13 10:13:38
Could that just be return element.isLocal()?
floitsch
2012/02/13 12:03:42
Done.
| |
| 668 if (element.kind == ElementKind.FUNCTION && isLocal(element)) return true; | |
| 669 return false; | |
| 662 } | 670 } |
| 663 | 671 |
| 664 static SourceString constructConstructorName(SourceString receiver, | 672 static SourceString constructConstructorName(SourceString receiver, |
| 665 SourceString selector) { | 673 SourceString selector) { |
| 666 return new SourceString('$receiver\$$selector'); | 674 return new SourceString('$receiver\$$selector'); |
| 667 } | 675 } |
| 668 | 676 |
| 669 static SourceString constructOperatorName(SourceString receiver, | 677 static SourceString constructOperatorName(SourceString receiver, |
| 670 SourceString selector, | 678 SourceString selector, |
| 671 [bool isPrefix = false]) { | 679 [bool isPrefix = false]) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 687 else if (str === '>=') str = 'ge'; | 695 else if (str === '>=') str = 'ge'; |
| 688 else if (str === '>') str = 'gt'; | 696 else if (str === '>') str = 'gt'; |
| 689 else if (str === '<=') str = 'le'; | 697 else if (str === '<=') str = 'le'; |
| 690 else if (str === '<') str = 'lt'; | 698 else if (str === '<') str = 'lt'; |
| 691 else if (str === '&' || str === '&=') str = 'and'; | 699 else if (str === '&' || str === '&=') str = 'and'; |
| 692 else if (str === '^' || str === '^=') str = 'xor'; | 700 else if (str === '^' || str === '^=') str = 'xor'; |
| 693 else if (str === '|' || str === '|=') str = 'or'; | 701 else if (str === '|' || str === '|=') str = 'or'; |
| 694 return new SourceString('$receiver\$$str'); | 702 return new SourceString('$receiver\$$str'); |
| 695 } | 703 } |
| 696 } | 704 } |
| OLD | NEW |