associated_constant.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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_ASSOCIATED_CONSTANT_H_
  5. #define CARBON_TOOLCHAIN_SEM_IR_ASSOCIATED_CONSTANT_H_
  6. #include "common/ostream.h"
  7. #include "toolchain/base/value_store.h"
  8. #include "toolchain/sem_ir/ids.h"
  9. namespace Carbon::SemIR {
  10. // An associated constant entity. For example:
  11. //
  12. // interface I {
  13. // let AssocConst:! type;
  14. // }
  15. //
  16. // TODO: This overlaps a lot with EntityName and EntityWithParamsBase.
  17. // Investigate ways of factoring out the common parts.
  18. struct AssociatedConstant : public Printable<AssociatedConstant> {
  19. auto Print(llvm::raw_ostream& out) const -> void {
  20. out << "{"
  21. << "name: " << name_id << ", parent_scope: " << parent_scope_id << "}";
  22. }
  23. // The following fields are set at the `:!` binding, when the
  24. // `AssociatedConstant` is created.
  25. // The entity's name.
  26. NameId name_id;
  27. // The parent scope.
  28. NameScopeId parent_scope_id;
  29. // The declaration of this associated constant.
  30. InstId decl_id;
  31. // The following fields are set at the `=` or `;`.
  32. // Information about the generic. An associated constant is always
  33. // parameterized by `Self`, so this is always present.
  34. GenericId generic_id;
  35. // The following fields are set at the `;`.
  36. // The default value of the constant.
  37. InstId default_value_id = InstId::None;
  38. };
  39. using AssociatedConstantStore =
  40. ValueStore<AssociatedConstantId, AssociatedConstant, Tag<CheckIRId>>;
  41. } // namespace Carbon::SemIR
  42. #endif // CARBON_TOOLCHAIN_SEM_IR_ASSOCIATED_CONSTANT_H_