member.h 1009 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef EXECUTABLE_SEMANTICS_AST_MEMBER_H_
  5. #define EXECUTABLE_SEMANTICS_AST_MEMBER_H_
  6. #include <string>
  7. #include "executable_semantics/ast/expression.h"
  8. namespace Carbon {
  9. enum class MemberKind { FieldMember };
  10. struct FieldMember {
  11. static constexpr MemberKind Kind = MemberKind::FieldMember;
  12. std::string name;
  13. const Expression* type;
  14. };
  15. struct Member {
  16. static auto MakeFieldMember(int line_num, std::string name,
  17. const Expression* type) -> Member*;
  18. auto GetFieldMember() const -> const FieldMember&;
  19. void Print();
  20. inline auto tag() const -> MemberKind {
  21. return std::visit([](const auto& t) { return t.Kind; }, value);
  22. }
  23. int line_num;
  24. private:
  25. std::variant<FieldMember> value;
  26. };
  27. } // namespace Carbon
  28. #endif // EXECUTABLE_SEMANTICS_AST_MEMBER_H_