Describes a resolved reference to a declaration.
| 745 | |
| 746 | // Describes a resolved reference to a declaration. |
| 747 | class Reference { |
| 748 | public: |
| 749 | Reference() = default; |
| 750 | |
| 751 | Reference(std::string name, std::vector<std::string> overload_id, |
| 752 | Constant value) |
| 753 | : name_(std::move(name)), |
| 754 | overload_id_(std::move(overload_id)), |
| 755 | value_(std::move(value)) {} |
| 756 | |
| 757 | Reference(const Reference& other) = default; |
| 758 | Reference& operator=(const Reference& other) = default; |
| 759 | Reference(Reference&&) = default; |
| 760 | Reference& operator=(Reference&&) = default; |
| 761 | |
| 762 | void set_name(std::string name) { name_ = std::move(name); } |
| 763 | |
| 764 | void set_overload_id(std::vector<std::string> overload_id) { |
| 765 | overload_id_ = std::move(overload_id); |
| 766 | } |
| 767 | |
| 768 | void set_value(Constant value) { value_ = std::move(value); } |
| 769 | |
| 770 | const std::string& name() const { return name_; } |
| 771 | |
| 772 | const std::vector<std::string>& overload_id() const { return overload_id_; } |
| 773 | |
| 774 | const Constant& value() const { |
| 775 | if (value_.has_value()) { |
| 776 | return value_.value(); |
| 777 | } |
| 778 | static const Constant* default_constant = new Constant; |
| 779 | return *default_constant; |
| 780 | } |
| 781 | |
| 782 | std::vector<std::string>& mutable_overload_id() { return overload_id_; } |
| 783 | |
| 784 | Constant& mutable_value() { |
| 785 | if (!value_.has_value()) { |
| 786 | value_.emplace(); |
| 787 | } |
| 788 | return *value_; |
| 789 | } |
| 790 | |
| 791 | bool has_value() const { return value_.has_value(); } |
| 792 | |
| 793 | bool operator==(const Reference& other) const { |
| 794 | return name_ == other.name_ && overload_id_ == other.overload_id_ && |
| 795 | value() == other.value(); |
| 796 | } |
| 797 | |
| 798 | private: |
| 799 | // The fully qualified name of the declaration. |
| 800 | std::string name_; |
| 801 | // For references to functions, this is a list of `Overload.overload_id` |
| 802 | // values which match according to typing rules. |
| 803 | // |
| 804 | // If the list has more than one element, overload resolution among the |