associated_constant.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. << ", decl_id: " << decl_id << ", generic_id: " << generic_id
  23. << ", default_value_id: " << default_value_id << "}";
  24. }
  25. // The following fields are set at the `:!` binding, when the
  26. // `AssociatedConstant` is created.
  27. // The entity's name.
  28. NameId name_id;
  29. // The parent scope.
  30. NameScopeId parent_scope_id;
  31. // The declaration of this associated constant.
  32. InstId decl_id;
  33. // The following fields are set at the `=` or `;`.
  34. // Information about the generic. An associated constant is always
  35. // parameterized by `Self`, so this is always present.
  36. GenericId generic_id;
  37. // The following fields are set at the `;`.
  38. // The default value of the constant.
  39. InstId default_value_id = InstId::None;
  40. };
  41. using AssociatedConstantStore =
  42. ValueStore<AssociatedConstantId, AssociatedConstant, Tag<CheckIRId>>;
  43. } // namespace Carbon::SemIR
  44. #endif // CARBON_TOOLCHAIN_SEM_IR_ASSOCIATED_CONSTANT_H_