member.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 "common/ostream.h"
  8. #include "executable_semantics/ast/expression.h"
  9. namespace Carbon {
  10. enum class MemberKind { FieldMember };
  11. struct FieldMember {
  12. static constexpr MemberKind Kind = MemberKind::FieldMember;
  13. std::string name;
  14. const Expression* type;
  15. };
  16. struct Member {
  17. static auto MakeFieldMember(int line_num, std::string name,
  18. const Expression* type) -> Member*;
  19. auto GetFieldMember() const -> const FieldMember&;
  20. void Print(llvm::raw_ostream& out) const;
  21. inline auto tag() const -> MemberKind {
  22. return std::visit([](const auto& t) { return t.Kind; }, value);
  23. }
  24. int line_num;
  25. private:
  26. std::variant<FieldMember> value;
  27. };
  28. } // namespace Carbon
  29. #endif // EXECUTABLE_SEMANTICS_AST_MEMBER_H_