member.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include "executable_semantics/ast/pattern.h"
  10. #include "llvm/Support/Compiler.h"
  11. namespace Carbon {
  12. enum class MemberKind { FieldMember };
  13. struct FieldMember {
  14. static constexpr MemberKind Kind = MemberKind::FieldMember;
  15. // TODO: split this into a non-optional name and a type, initialized by
  16. // a constructor that takes a BindingPattern and handles errors like a
  17. // missing name.
  18. const BindingPattern* binding;
  19. };
  20. struct Member {
  21. static auto MakeFieldMember(int line_num, const BindingPattern* binding)
  22. -> Member*;
  23. auto GetFieldMember() const -> const FieldMember&;
  24. void Print(llvm::raw_ostream& out) const;
  25. LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
  26. inline auto tag() const -> MemberKind {
  27. return std::visit([](const auto& t) { return t.Kind; }, value);
  28. }
  29. int line_num;
  30. private:
  31. std::variant<FieldMember> value;
  32. };
  33. } // namespace Carbon
  34. #endif // EXECUTABLE_SEMANTICS_AST_MEMBER_H_