class.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 CARBON_TOOLCHAIN_SEM_IR_CLASS_H_
  5. #define CARBON_TOOLCHAIN_SEM_IR_CLASS_H_
  6. #include "toolchain/sem_ir/ids.h"
  7. namespace Carbon::SemIR {
  8. // A class.
  9. struct Class : public Printable<Class> {
  10. enum InheritanceKind : int8_t {
  11. // `abstract class`
  12. Abstract,
  13. // `base class`
  14. Base,
  15. // `class`
  16. Final,
  17. };
  18. auto Print(llvm::raw_ostream& out) const -> void {
  19. out << "{name: " << name_id << ", enclosing_scope: " << enclosing_scope_id
  20. << "}";
  21. }
  22. // Determines whether this class has been fully defined. This is false until
  23. // we reach the `}` of the class definition.
  24. auto is_defined() const -> bool { return object_repr_id.is_valid(); }
  25. // The following members always have values, and do not change throughout the
  26. // lifetime of the class.
  27. // The class name.
  28. NameId name_id;
  29. // The enclosing scope.
  30. NameScopeId enclosing_scope_id;
  31. // The class type, which is the type of `Self` in the class definition.
  32. TypeId self_type_id;
  33. // The first declaration of the class. This is a ClassDecl.
  34. InstId decl_id = InstId::Invalid;
  35. // The kind of inheritance that this class supports.
  36. // TODO: The rules here are not yet decided. See #3384.
  37. InheritanceKind inheritance_kind;
  38. // The following members are set at the `{` of the class definition.
  39. // The definition of the class. This is a ClassDecl.
  40. InstId definition_id = InstId::Invalid;
  41. // The class scope.
  42. NameScopeId scope_id = NameScopeId::Invalid;
  43. // The first block of the class body.
  44. // TODO: Handle control flow in the class body, such as if-expressions.
  45. InstBlockId body_block_id = InstBlockId::Invalid;
  46. // The following members are accumulated throughout the class definition.
  47. // The base class declaration. Invalid if the class has no base class. This is
  48. // a BaseDecl instruction.
  49. InstId base_id = InstId::Invalid;
  50. // The following members are set at the `}` of the class definition.
  51. // The object representation type to use for this class. This is valid once
  52. // the class is defined.
  53. TypeId object_repr_id = TypeId::Invalid;
  54. };
  55. } // namespace Carbon::SemIR
  56. #endif // CARBON_TOOLCHAIN_SEM_IR_CLASS_H_