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 '../common.dart'; | 7 import '../common.dart'; |
8 import '../common/resolution.dart' show | 8 import '../common/resolution.dart' show Resolution; |
9 Resolution; | 9 import '../compiler.dart' show Compiler; |
10 import '../compiler.dart' show | |
11 Compiler; | |
12 import '../constants/constructors.dart'; | 10 import '../constants/constructors.dart'; |
13 import '../constants/expressions.dart'; | 11 import '../constants/expressions.dart'; |
14 import '../core_types.dart' show | 12 import '../core_types.dart' show CoreClasses; |
15 CoreClasses; | |
16 import '../dart_types.dart'; | 13 import '../dart_types.dart'; |
17 import '../resolution/scope.dart' show | 14 import '../resolution/scope.dart' show Scope; |
18 Scope; | 15 import '../resolution/tree_elements.dart' show TreeElements; |
19 import '../resolution/tree_elements.dart' show | |
20 TreeElements; | |
21 import '../ordered_typeset.dart' show OrderedTypeSet; | 16 import '../ordered_typeset.dart' show OrderedTypeSet; |
22 import '../script.dart'; | 17 import '../script.dart'; |
23 import '../tokens/token.dart' show | 18 import '../tokens/token.dart' |
24 Token, | 19 show Token, isUserDefinableOperator, isMinusOperator; |
25 isUserDefinableOperator, | |
26 isMinusOperator; | |
27 import '../tree/tree.dart'; | 20 import '../tree/tree.dart'; |
28 import '../util/characters.dart' show $_; | 21 import '../util/characters.dart' show $_; |
29 import '../util/util.dart'; | 22 import '../util/util.dart'; |
30 | 23 |
31 import 'visitor.dart' show ElementVisitor; | 24 import 'visitor.dart' show ElementVisitor; |
32 | 25 |
33 part 'names.dart'; | 26 part 'names.dart'; |
34 | 27 |
35 const int STATE_NOT_STARTED = 0; | 28 const int STATE_NOT_STARTED = 0; |
36 const int STATE_STARTED = 1; | 29 const int STATE_STARTED = 1; |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 | 416 |
424 static bool isError(Element e) { | 417 static bool isError(Element e) { |
425 return e != null && e.isError; | 418 return e != null && e.isError; |
426 } | 419 } |
427 | 420 |
428 static bool isMalformed(Element e) { | 421 static bool isMalformed(Element e) { |
429 return e != null && e.isMalformed; | 422 return e != null && e.isMalformed; |
430 } | 423 } |
431 | 424 |
432 /// Unwraps [element] reporting any warnings attached to it, if any. | 425 /// Unwraps [element] reporting any warnings attached to it, if any. |
433 static Element unwrap(Element element, | 426 static Element unwrap( |
434 DiagnosticReporter listener, | 427 Element element, DiagnosticReporter listener, Spannable spannable) { |
435 Spannable spannable) { | |
436 if (element != null && element.isWarnOnUse) { | 428 if (element != null && element.isWarnOnUse) { |
437 WarnOnUseElement wrappedElement = element; | 429 WarnOnUseElement wrappedElement = element; |
438 element = wrappedElement.unwrap(listener, spannable); | 430 element = wrappedElement.unwrap(listener, spannable); |
439 } | 431 } |
440 return element; | 432 return element; |
441 } | 433 } |
442 | 434 |
443 static bool isClass(Element e) => e != null && e.kind == ElementKind.CLASS; | 435 static bool isClass(Element e) => e != null && e.kind == ElementKind.CLASS; |
444 static bool isTypedef(Element e) { | 436 static bool isTypedef(Element e) { |
445 return e != null && e.kind == ElementKind.TYPEDEF; | 437 return e != null && e.kind == ElementKind.TYPEDEF; |
446 } | 438 } |
447 | 439 |
448 static bool isLocal(Element element) { | 440 static bool isLocal(Element element) { |
449 return !Elements.isUnresolved(element) && element.isLocal; | 441 return !Elements.isUnresolved(element) && element.isLocal; |
450 } | 442 } |
451 | 443 |
452 static bool isInstanceField(Element element) { | 444 static bool isInstanceField(Element element) { |
453 return !Elements.isUnresolved(element) | 445 return !Elements.isUnresolved(element) && |
454 && element.isInstanceMember | 446 element.isInstanceMember && |
455 && (identical(element.kind, ElementKind.FIELD) | 447 (identical(element.kind, ElementKind.FIELD) || |
456 || identical(element.kind, ElementKind.GETTER) | 448 identical(element.kind, ElementKind.GETTER) || |
457 || identical(element.kind, ElementKind.SETTER)); | 449 identical(element.kind, ElementKind.SETTER)); |
458 } | 450 } |
459 | 451 |
460 static bool isStaticOrTopLevel(Element element) { | 452 static bool isStaticOrTopLevel(Element element) { |
461 // TODO(johnniwinther): Clean this up. This currently returns true for a | 453 // TODO(johnniwinther): Clean this up. This currently returns true for a |
462 // PartialConstructorElement, SynthesizedConstructorElementX, and | 454 // PartialConstructorElement, SynthesizedConstructorElementX, and |
463 // TypeVariableElementX though neither `element.isStatic` nor | 455 // TypeVariableElementX though neither `element.isStatic` nor |
464 // `element.isTopLevel` is true. | 456 // `element.isTopLevel` is true. |
465 if (Elements.isUnresolved(element)) return false; | 457 if (Elements.isUnresolved(element)) return false; |
466 if (element.isStatic || element.isTopLevel) return true; | 458 if (element.isStatic || element.isTopLevel) return true; |
467 return !element.isAmbiguous | 459 return !element.isAmbiguous && |
468 && !element.isInstanceMember | 460 !element.isInstanceMember && |
469 && !element.isPrefix | 461 !element.isPrefix && |
470 && element.enclosingElement != null | 462 element.enclosingElement != null && |
471 && (element.enclosingElement.kind == ElementKind.CLASS || | 463 (element.enclosingElement.kind == ElementKind.CLASS || |
472 element.enclosingElement.kind == ElementKind.COMPILATION_UNIT || | 464 element.enclosingElement.kind == ElementKind.COMPILATION_UNIT || |
473 element.enclosingElement.kind == ElementKind.LIBRARY || | 465 element.enclosingElement.kind == ElementKind.LIBRARY || |
474 element.enclosingElement.kind == ElementKind.PREFIX); | 466 element.enclosingElement.kind == ElementKind.PREFIX); |
475 } | 467 } |
476 | 468 |
477 static bool isInStaticContext(Element element) { | 469 static bool isInStaticContext(Element element) { |
478 if (isUnresolved(element)) return true; | 470 if (isUnresolved(element)) return true; |
479 if (element.enclosingElement.isClosure) { | 471 if (element.enclosingElement.isClosure) { |
480 var closureClass = element.enclosingElement; | 472 var closureClass = element.enclosingElement; |
481 element = closureClass.methodElement; | 473 element = closureClass.methodElement; |
482 } | 474 } |
483 Element outer = element.outermostEnclosingMemberOrTopLevel; | 475 Element outer = element.outermostEnclosingMemberOrTopLevel; |
484 if (isUnresolved(outer)) return true; | 476 if (isUnresolved(outer)) return true; |
485 if (outer.isTopLevel) return true; | 477 if (outer.isTopLevel) return true; |
486 if (outer.isGenerativeConstructor) return false; | 478 if (outer.isGenerativeConstructor) return false; |
487 if (outer.isInstanceMember) return false; | 479 if (outer.isInstanceMember) return false; |
488 return true; | 480 return true; |
489 } | 481 } |
490 | 482 |
491 static bool hasAccessToTypeVariables(Element element) { | 483 static bool hasAccessToTypeVariables(Element element) { |
492 Element outer = element.outermostEnclosingMemberOrTopLevel; | 484 Element outer = element.outermostEnclosingMemberOrTopLevel; |
493 return (outer != null && outer.isFactoryConstructor) || | 485 return (outer != null && outer.isFactoryConstructor) || |
494 !isInStaticContext(element); | 486 !isInStaticContext(element); |
495 } | 487 } |
496 | 488 |
497 static bool isStaticOrTopLevelField(Element element) { | 489 static bool isStaticOrTopLevelField(Element element) { |
498 return isStaticOrTopLevel(element) | 490 return isStaticOrTopLevel(element) && |
499 && (identical(element.kind, ElementKind.FIELD) | 491 (identical(element.kind, ElementKind.FIELD) || |
500 || identical(element.kind, ElementKind.GETTER) | 492 identical(element.kind, ElementKind.GETTER) || |
501 || identical(element.kind, ElementKind.SETTER)); | 493 identical(element.kind, ElementKind.SETTER)); |
502 } | 494 } |
503 | 495 |
504 static bool isStaticOrTopLevelFunction(Element element) { | 496 static bool isStaticOrTopLevelFunction(Element element) { |
505 return isStaticOrTopLevel(element) && element.isFunction; | 497 return isStaticOrTopLevel(element) && element.isFunction; |
506 } | 498 } |
507 | 499 |
508 static bool isInstanceMethod(Element element) { | 500 static bool isInstanceMethod(Element element) { |
509 return !Elements.isUnresolved(element) | 501 return !Elements.isUnresolved(element) && |
510 && element.isInstanceMember | 502 element.isInstanceMember && |
511 && (identical(element.kind, ElementKind.FUNCTION)); | 503 (identical(element.kind, ElementKind.FUNCTION)); |
512 } | 504 } |
513 | 505 |
514 /// Also returns true for [ConstructorBodyElement]s and getters/setters. | 506 /// Also returns true for [ConstructorBodyElement]s and getters/setters. |
515 static bool isNonAbstractInstanceMember(Element element) { | 507 static bool isNonAbstractInstanceMember(Element element) { |
516 // The generative constructor body is not a function. We therefore treat | 508 // The generative constructor body is not a function. We therefore treat |
517 // it specially. | 509 // it specially. |
518 if (element.isGenerativeConstructorBody) return true; | 510 if (element.isGenerativeConstructorBody) return true; |
519 return !Elements.isUnresolved(element) && | 511 return !Elements.isUnresolved(element) && |
520 !element.isAbstract && | 512 !element.isAbstract && |
521 element.isInstanceMember && | 513 element.isInstanceMember && |
522 (element.isFunction || element.isAccessor); | 514 (element.isFunction || element.isAccessor); |
523 } | 515 } |
524 | 516 |
525 static bool isInstanceSend(Send send, TreeElements elements) { | 517 static bool isInstanceSend(Send send, TreeElements elements) { |
526 Element element = elements[send]; | 518 Element element = elements[send]; |
527 if (element == null) return !isClosureSend(send, element); | 519 if (element == null) return !isClosureSend(send, element); |
528 return isInstanceMethod(element) || | 520 return isInstanceMethod(element) || |
529 isInstanceField(element) || | 521 isInstanceField(element) || |
530 (send.isConditional && !element.isStatic); | 522 (send.isConditional && !element.isStatic); |
531 } | 523 } |
532 | 524 |
533 static bool isClosureSend(Send send, Element element) { | 525 static bool isClosureSend(Send send, Element element) { |
534 if (send.isPropertyAccess) return false; | 526 if (send.isPropertyAccess) return false; |
535 if (send.receiver != null) return false; | 527 if (send.receiver != null) return false; |
536 Node selector = send.selector; | 528 Node selector = send.selector; |
537 // this(). | 529 // this(). |
538 if (selector.isThis()) return true; | 530 if (selector.isThis()) return true; |
539 // (o)() or foo()(). | 531 // (o)() or foo()(). |
540 if (element == null && selector.asIdentifier() == null) return true; | 532 if (element == null && selector.asIdentifier() == null) return true; |
(...skipping 13 matching lines...) Expand all Loading... |
554 // TODO(johnniwinther): Remove this method. | 546 // TODO(johnniwinther): Remove this method. |
555 static String reconstructConstructorName(Element element) { | 547 static String reconstructConstructorName(Element element) { |
556 String className = element.enclosingClass.name; | 548 String className = element.enclosingClass.name; |
557 if (element.name == '') { | 549 if (element.name == '') { |
558 return className; | 550 return className; |
559 } else { | 551 } else { |
560 return '$className\$${element.name}'; | 552 return '$className\$${element.name}'; |
561 } | 553 } |
562 } | 554 } |
563 | 555 |
564 static String constructorNameForDiagnostics(String className, | 556 static String constructorNameForDiagnostics( |
565 String constructorName) { | 557 String className, String constructorName) { |
566 String classNameString = className; | 558 String classNameString = className; |
567 String constructorNameString = constructorName; | 559 String constructorNameString = constructorName; |
568 return (constructorName == '') | 560 return (constructorName == '') |
569 ? classNameString | 561 ? classNameString |
570 : "$classNameString.$constructorNameString"; | 562 : "$classNameString.$constructorNameString"; |
571 } | 563 } |
572 | 564 |
573 /// Returns `true` if [name] is the name of an operator method. | 565 /// Returns `true` if [name] is the name of an operator method. |
574 static bool isOperatorName(String name) { | 566 static bool isOperatorName(String name) { |
575 return name == 'unary-' || isUserDefinableOperator(name); | 567 return name == 'unary-' || isUserDefinableOperator(name); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 return isUnary ? 'unary-' : op; | 629 return isUnary ? 'unary-' : op; |
638 } else if (isUserDefinableOperator(op) || op == '??') { | 630 } else if (isUserDefinableOperator(op) || op == '??') { |
639 return op; | 631 return op; |
640 } else { | 632 } else { |
641 return null; | 633 return null; |
642 } | 634 } |
643 } | 635 } |
644 | 636 |
645 static String constructOperatorName(String op, bool isUnary) { | 637 static String constructOperatorName(String op, bool isUnary) { |
646 String operatorName = constructOperatorNameOrNull(op, isUnary); | 638 String operatorName = constructOperatorNameOrNull(op, isUnary); |
647 if (operatorName == null) throw 'Unhandled operator: $op'; | 639 if (operatorName == null) |
648 else return operatorName; | 640 throw 'Unhandled operator: $op'; |
| 641 else |
| 642 return operatorName; |
649 } | 643 } |
650 | 644 |
651 static String mapToUserOperatorOrNull(String op) { | 645 static String mapToUserOperatorOrNull(String op) { |
652 if (identical(op, '!=')) return '=='; | 646 if (identical(op, '!=')) return '=='; |
653 if (identical(op, '*=')) return '*'; | 647 if (identical(op, '*=')) return '*'; |
654 if (identical(op, '/=')) return '/'; | 648 if (identical(op, '/=')) return '/'; |
655 if (identical(op, '%=')) return '%'; | 649 if (identical(op, '%=')) return '%'; |
656 if (identical(op, '~/=')) return '~/'; | 650 if (identical(op, '~/=')) return '~/'; |
657 if (identical(op, '+=')) return '+'; | 651 if (identical(op, '+=')) return '+'; |
658 if (identical(op, '-=')) return '-'; | 652 if (identical(op, '-=')) return '-'; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 if (r != 0) return r; | 693 if (r != 0) return r; |
700 // Same file, position and name. If this happens, we should find out why | 694 // Same file, position and name. If this happens, we should find out why |
701 // and make the order total and independent of hashCode. | 695 // and make the order total and independent of hashCode. |
702 return a.hashCode.compareTo(b.hashCode); | 696 return a.hashCode.compareTo(b.hashCode); |
703 } | 697 } |
704 | 698 |
705 static List<Element> sortedByPosition(Iterable<Element> elements) { | 699 static List<Element> sortedByPosition(Iterable<Element> elements) { |
706 return elements.toList()..sort(compareByPosition); | 700 return elements.toList()..sort(compareByPosition); |
707 } | 701 } |
708 | 702 |
709 static bool isFixedListConstructorCall(Element element, | 703 static bool isFixedListConstructorCall( |
710 Send node, | 704 Element element, Send node, Compiler compiler) { |
711 Compiler compiler) { | 705 return element == compiler.unnamedListConstructor && |
712 return element == compiler.unnamedListConstructor | 706 node.isCall && |
713 && node.isCall | 707 !node.arguments.isEmpty && |
714 && !node.arguments.isEmpty | 708 node.arguments.tail.isEmpty; |
715 && node.arguments.tail.isEmpty; | |
716 } | 709 } |
717 | 710 |
718 static bool isGrowableListConstructorCall(Element element, | 711 static bool isGrowableListConstructorCall( |
719 Send node, | 712 Element element, Send node, Compiler compiler) { |
720 Compiler compiler) { | 713 return element == compiler.unnamedListConstructor && |
721 return element == compiler.unnamedListConstructor | 714 node.isCall && |
722 && node.isCall | 715 node.arguments.isEmpty; |
723 && node.arguments.isEmpty; | |
724 } | 716 } |
725 | 717 |
726 static bool isFilledListConstructorCall(Element element, | 718 static bool isFilledListConstructorCall( |
727 Send node, | 719 Element element, Send node, Compiler compiler) { |
728 Compiler compiler) { | 720 return element == compiler.filledListConstructor && |
729 return element == compiler.filledListConstructor | 721 node.isCall && |
730 && node.isCall | 722 !node.arguments.isEmpty && |
731 && !node.arguments.isEmpty | 723 !node.arguments.tail.isEmpty && |
732 && !node.arguments.tail.isEmpty | 724 node.arguments.tail.tail.isEmpty; |
733 && node.arguments.tail.tail.isEmpty; | |
734 } | 725 } |
735 | 726 |
736 static bool isConstructorOfTypedArraySubclass(Element element, | 727 static bool isConstructorOfTypedArraySubclass( |
737 Compiler compiler) { | 728 Element element, Compiler compiler) { |
738 if (compiler.typedDataLibrary == null) return false; | 729 if (compiler.typedDataLibrary == null) return false; |
739 if (!element.isConstructor) return false; | 730 if (!element.isConstructor) return false; |
740 ConstructorElement constructor = element.implementation; | 731 ConstructorElement constructor = element.implementation; |
741 constructor = constructor.effectiveTarget; | 732 constructor = constructor.effectiveTarget; |
742 ClassElement cls = constructor.enclosingClass; | 733 ClassElement cls = constructor.enclosingClass; |
743 return cls.library == compiler.typedDataLibrary | 734 return cls.library == compiler.typedDataLibrary && |
744 && compiler.backend.isNative(cls) | 735 compiler.backend.isNative(cls) && |
745 && compiler.world.isSubtypeOf(cls, compiler.typedDataClass) | 736 compiler.world.isSubtypeOf(cls, compiler.typedDataClass) && |
746 && compiler.world.isSubtypeOf(cls, compiler.coreClasses.listClass) | 737 compiler.world.isSubtypeOf(cls, compiler.coreClasses.listClass) && |
747 && constructor.name == ''; | 738 constructor.name == ''; |
748 } | 739 } |
749 | 740 |
750 static bool switchStatementHasContinue(SwitchStatement node, | 741 static bool switchStatementHasContinue( |
751 TreeElements elements) { | 742 SwitchStatement node, TreeElements elements) { |
752 for (SwitchCase switchCase in node.cases) { | 743 for (SwitchCase switchCase in node.cases) { |
753 for (Node labelOrCase in switchCase.labelsAndCases) { | 744 for (Node labelOrCase in switchCase.labelsAndCases) { |
754 Node label = labelOrCase.asLabel(); | 745 Node label = labelOrCase.asLabel(); |
755 if (label != null) { | 746 if (label != null) { |
756 LabelDefinition labelElement = elements.getLabelDefinition(label); | 747 LabelDefinition labelElement = elements.getLabelDefinition(label); |
757 if (labelElement != null && labelElement.isContinueTarget) { | 748 if (labelElement != null && labelElement.isContinueTarget) { |
758 return true; | 749 return true; |
759 } | 750 } |
760 } | 751 } |
761 } | 752 } |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 /// Is true if this prefix belongs to a deferred import. | 930 /// Is true if this prefix belongs to a deferred import. |
940 bool get isDeferred; | 931 bool get isDeferred; |
941 | 932 |
942 /// Import that declared this deferred prefix. | 933 /// Import that declared this deferred prefix. |
943 ImportElement get deferredImport; | 934 ImportElement get deferredImport; |
944 } | 935 } |
945 | 936 |
946 /// A type alias definition. | 937 /// A type alias definition. |
947 abstract class TypedefElement extends Element | 938 abstract class TypedefElement extends Element |
948 implements AstElement, TypeDeclarationElement, FunctionTypedElement { | 939 implements AstElement, TypeDeclarationElement, FunctionTypedElement { |
949 | |
950 /// The type defined by this typedef with the type variables as its type | 940 /// The type defined by this typedef with the type variables as its type |
951 /// arguments. | 941 /// arguments. |
952 /// | 942 /// |
953 /// For instance `F<T>` for `typedef void F<T>(T t)`. | 943 /// For instance `F<T>` for `typedef void F<T>(T t)`. |
954 TypedefType get thisType; | 944 TypedefType get thisType; |
955 | 945 |
956 /// The type defined by this typedef with `dynamic` as its type arguments. | 946 /// The type defined by this typedef with `dynamic` as its type arguments. |
957 /// | 947 /// |
958 /// For instance `F<dynamic>` for `typedef void F<T>(T t)`. | 948 /// For instance `F<dynamic>` for `typedef void F<T>(T t)`. |
959 TypedefType get rawType; | 949 TypedefType get rawType; |
(...skipping 30 matching lines...) Expand all Loading... |
990 abstract class MemberElement extends Element implements ExecutableElement { | 980 abstract class MemberElement extends Element implements ExecutableElement { |
991 /// The local functions defined within this member. | 981 /// The local functions defined within this member. |
992 List<FunctionElement> get nestedClosures; | 982 List<FunctionElement> get nestedClosures; |
993 | 983 |
994 /// The name of this member, taking privacy into account. | 984 /// The name of this member, taking privacy into account. |
995 Name get memberName; | 985 Name get memberName; |
996 } | 986 } |
997 | 987 |
998 /// A function, variable or parameter defined in an executable context. | 988 /// A function, variable or parameter defined in an executable context. |
999 abstract class LocalElement extends Element | 989 abstract class LocalElement extends Element |
1000 implements AstElement, TypedElement, Local { | 990 implements AstElement, TypedElement, Local {} |
1001 } | |
1002 | 991 |
1003 /// A top level, static or instance field, a formal parameter or local variable. | 992 /// A top level, static or instance field, a formal parameter or local variable. |
1004 abstract class VariableElement extends ExecutableElement { | 993 abstract class VariableElement extends ExecutableElement { |
1005 @override | 994 @override |
1006 VariableDefinitions get node; | 995 VariableDefinitions get node; |
1007 | 996 |
1008 Expression get initializer; | 997 Expression get initializer; |
1009 | 998 |
1010 /// The constant expression defining the value of the variable if `const`, | 999 /// The constant expression defining the value of the variable if `const`, |
1011 /// `null` otherwise. | 1000 /// `null` otherwise. |
(...skipping 14 matching lines...) Expand all Loading... |
1026 abstract class Local extends Entity { | 1015 abstract class Local extends Entity { |
1027 /// The context in which this local is defined. | 1016 /// The context in which this local is defined. |
1028 ExecutableElement get executableContext; | 1017 ExecutableElement get executableContext; |
1029 } | 1018 } |
1030 | 1019 |
1031 /// A variable or parameter that is local to an executable context. | 1020 /// A variable or parameter that is local to an executable context. |
1032 /// | 1021 /// |
1033 /// The executable context is the [ExecutableElement] in which this variable | 1022 /// The executable context is the [ExecutableElement] in which this variable |
1034 /// is defined. | 1023 /// is defined. |
1035 abstract class LocalVariableElement extends VariableElement | 1024 abstract class LocalVariableElement extends VariableElement |
1036 implements LocalElement { | 1025 implements LocalElement {} |
1037 } | |
1038 | 1026 |
1039 /// A top-level, static or instance field. | 1027 /// A top-level, static or instance field. |
1040 abstract class FieldElement extends VariableElement implements MemberElement { | 1028 abstract class FieldElement extends VariableElement implements MemberElement {} |
1041 } | |
1042 | 1029 |
1043 /// A parameter-like element of a function signature. | 1030 /// A parameter-like element of a function signature. |
1044 /// | 1031 /// |
1045 /// If the function signature comes from a typedef or an inline function-typed | 1032 /// If the function signature comes from a typedef or an inline function-typed |
1046 /// parameter (e.g. the parameter 'f' in `method(void f())`), then its | 1033 /// parameter (e.g. the parameter 'f' in `method(void f())`), then its |
1047 /// parameters are not real parameters in that they can take no argument and | 1034 /// parameters are not real parameters in that they can take no argument and |
1048 /// hold no value. Such parameter-like elements are modeled by [FormalElement]. | 1035 /// hold no value. Such parameter-like elements are modeled by [FormalElement]. |
1049 /// | 1036 /// |
1050 /// If the function signature comes from a function or constructor, its | 1037 /// If the function signature comes from a function or constructor, its |
1051 /// parameters are real parameters and are modeled by [ParameterElement]. | 1038 /// parameters are real parameters and are modeled by [ParameterElement]. |
(...skipping 27 matching lines...) Expand all Loading... |
1079 /// `true` if this parameter is named. | 1066 /// `true` if this parameter is named. |
1080 bool get isNamed; | 1067 bool get isNamed; |
1081 | 1068 |
1082 /// `true` if this parameter is optional. | 1069 /// `true` if this parameter is optional. |
1083 bool get isOptional; | 1070 bool get isOptional; |
1084 } | 1071 } |
1085 | 1072 |
1086 /// A formal parameter on a function or constructor that introduces a local | 1073 /// A formal parameter on a function or constructor that introduces a local |
1087 /// variable in the scope of the function or constructor. | 1074 /// variable in the scope of the function or constructor. |
1088 abstract class LocalParameterElement extends ParameterElement | 1075 abstract class LocalParameterElement extends ParameterElement |
1089 implements LocalVariableElement { | 1076 implements LocalVariableElement {} |
1090 } | |
1091 | 1077 |
1092 /// A formal parameter in a constructor that directly initializes a field. | 1078 /// A formal parameter in a constructor that directly initializes a field. |
1093 /// | 1079 /// |
1094 /// For example: `A(this.field)`. | 1080 /// For example: `A(this.field)`. |
1095 abstract class InitializingFormalElement extends ParameterElement { | 1081 abstract class InitializingFormalElement extends ParameterElement { |
1096 /// The field initialized by this initializing formal. | 1082 /// The field initialized by this initializing formal. |
1097 FieldElement get fieldElement; | 1083 FieldElement get fieldElement; |
1098 | 1084 |
1099 /// The function on which this parameter is declared. | 1085 /// The function on which this parameter is declared. |
1100 ConstructorElement get functionDeclaration; | 1086 ConstructorElement get functionDeclaration; |
(...skipping 30 matching lines...) Expand all Loading... |
1131 void forEachOptionalParameter(void function(FormalElement parameter)); | 1117 void forEachOptionalParameter(void function(FormalElement parameter)); |
1132 | 1118 |
1133 void orderedForEachParameter(void function(FormalElement parameter)); | 1119 void orderedForEachParameter(void function(FormalElement parameter)); |
1134 | 1120 |
1135 bool isCompatibleWith(FunctionSignature constructorSignature); | 1121 bool isCompatibleWith(FunctionSignature constructorSignature); |
1136 } | 1122 } |
1137 | 1123 |
1138 /// A top level, static or instance method, constructor, local function, or | 1124 /// A top level, static or instance method, constructor, local function, or |
1139 /// closure (anonymous local function). | 1125 /// closure (anonymous local function). |
1140 abstract class FunctionElement extends Element | 1126 abstract class FunctionElement extends Element |
1141 implements AstElement, | 1127 implements |
1142 TypedElement, | 1128 AstElement, |
1143 FunctionTypedElement, | 1129 TypedElement, |
1144 ExecutableElement { | 1130 FunctionTypedElement, |
| 1131 ExecutableElement { |
1145 FunctionExpression get node; | 1132 FunctionExpression get node; |
1146 | 1133 |
1147 FunctionElement get patch; | 1134 FunctionElement get patch; |
1148 FunctionElement get origin; | 1135 FunctionElement get origin; |
1149 | 1136 |
1150 bool get hasFunctionSignature; | 1137 bool get hasFunctionSignature; |
1151 | 1138 |
1152 /// The parameters of this functions. | 1139 /// The parameters of this functions. |
1153 List<ParameterElement> get parameters; | 1140 List<ParameterElement> get parameters; |
1154 | 1141 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 final bool isYielding; | 1192 final bool isYielding; |
1206 | 1193 |
1207 const AsyncMarker._({this.isAsync: false, this.isYielding: false}); | 1194 const AsyncMarker._({this.isAsync: false, this.isYielding: false}); |
1208 | 1195 |
1209 String toString() { | 1196 String toString() { |
1210 return '${isAsync ? 'async' : 'sync'}${isYielding ? '*' : ''}'; | 1197 return '${isAsync ? 'async' : 'sync'}${isYielding ? '*' : ''}'; |
1211 } | 1198 } |
1212 } | 1199 } |
1213 | 1200 |
1214 /// A top level, static or instance function. | 1201 /// A top level, static or instance function. |
1215 abstract class MethodElement extends FunctionElement | 1202 abstract class MethodElement extends FunctionElement implements MemberElement {} |
1216 implements MemberElement { | |
1217 } | |
1218 | 1203 |
1219 /// A local function or closure (anonymous local function). | 1204 /// A local function or closure (anonymous local function). |
1220 abstract class LocalFunctionElement extends FunctionElement | 1205 abstract class LocalFunctionElement extends FunctionElement |
1221 implements LocalElement { | 1206 implements LocalElement {} |
1222 } | |
1223 | 1207 |
1224 /// A constructor. | 1208 /// A constructor. |
1225 abstract class ConstructorElement extends FunctionElement | 1209 abstract class ConstructorElement extends FunctionElement |
1226 implements MemberElement { | 1210 implements MemberElement { |
1227 /// The effective target of this constructor, that is the non-redirecting | 1211 /// The effective target of this constructor, that is the non-redirecting |
1228 /// constructor that is called on invocation of this constructor. | 1212 /// constructor that is called on invocation of this constructor. |
1229 /// | 1213 /// |
1230 /// Consider for instance this hierachy: | 1214 /// Consider for instance this hierachy: |
1231 /// | 1215 /// |
1232 /// class C { factory C.c() = D.d; } | 1216 /// class C { factory C.c() = D.d; } |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 void reverseBackendMembers(); | 1443 void reverseBackendMembers(); |
1460 | 1444 |
1461 Element lookupMember(String memberName); | 1445 Element lookupMember(String memberName); |
1462 Element lookupByName(Name memberName); | 1446 Element lookupByName(Name memberName); |
1463 Element lookupSuperByName(Name memberName); | 1447 Element lookupSuperByName(Name memberName); |
1464 | 1448 |
1465 Element lookupLocalMember(String memberName); | 1449 Element lookupLocalMember(String memberName); |
1466 Element lookupBackendMember(String memberName); | 1450 Element lookupBackendMember(String memberName); |
1467 Element lookupSuperMember(String memberName); | 1451 Element lookupSuperMember(String memberName); |
1468 | 1452 |
1469 Element lookupSuperMemberInLibrary(String memberName, | 1453 Element lookupSuperMemberInLibrary(String memberName, LibraryElement library); |
1470 LibraryElement library); | |
1471 | 1454 |
1472 ConstructorElement lookupDefaultConstructor(); | 1455 ConstructorElement lookupDefaultConstructor(); |
1473 ConstructorElement lookupConstructor(String name); | 1456 ConstructorElement lookupConstructor(String name); |
1474 | 1457 |
1475 void forEachMember(void f(ClassElement enclosingClass, Element member), | 1458 void forEachMember(void f(ClassElement enclosingClass, Element member), |
1476 {bool includeBackendMembers: false, | 1459 {bool includeBackendMembers: false, |
1477 bool includeSuperAndInjectedMembers: false}); | 1460 bool includeSuperAndInjectedMembers: false}); |
1478 | 1461 |
1479 void forEachInstanceField(void f(ClassElement enclosingClass, | 1462 void forEachInstanceField( |
1480 FieldElement field), | 1463 void f(ClassElement enclosingClass, FieldElement field), |
1481 {bool includeSuperAndInjectedMembers: false}); | 1464 {bool includeSuperAndInjectedMembers: false}); |
1482 | 1465 |
1483 /// Similar to [forEachInstanceField] but visits static fields. | 1466 /// Similar to [forEachInstanceField] but visits static fields. |
1484 void forEachStaticField(void f(ClassElement enclosingClass, Element field)); | 1467 void forEachStaticField(void f(ClassElement enclosingClass, Element field)); |
1485 | 1468 |
1486 void forEachBackendMember(void f(Element member)); | 1469 void forEachBackendMember(void f(Element member)); |
1487 | 1470 |
1488 /// Looks up the member [name] in this class. | 1471 /// Looks up the member [name] in this class. |
1489 Member lookupClassMember(Name name); | 1472 Member lookupClassMember(Name name); |
1490 | 1473 |
1491 /// Calls [f] with each member of this class. | 1474 /// Calls [f] with each member of this class. |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1716 /// by a field. | 1699 /// by a field. |
1717 bool get isDeclaredByField; | 1700 bool get isDeclaredByField; |
1718 | 1701 |
1719 /// Returns `true` if this member is abstract. | 1702 /// Returns `true` if this member is abstract. |
1720 bool get isAbstract; | 1703 bool get isAbstract; |
1721 | 1704 |
1722 /// If abstract, [implementation] points to the overridden concrete member, | 1705 /// If abstract, [implementation] points to the overridden concrete member, |
1723 /// if any. Otherwise [implementation] points to the member itself. | 1706 /// if any. Otherwise [implementation] points to the member itself. |
1724 Member get implementation; | 1707 Member get implementation; |
1725 } | 1708 } |
1726 | |
OLD | NEW |