associated_constant.h 1.5 KB

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