named_constraint.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_NAMED_CONSTRAINT_H_
  5. #define CARBON_TOOLCHAIN_SEM_IR_NAMED_CONSTRAINT_H_
  6. #include "toolchain/base/value_store.h"
  7. #include "toolchain/sem_ir/entity_with_params_base.h"
  8. #include "toolchain/sem_ir/ids.h"
  9. namespace Carbon::SemIR {
  10. // Named constraint-specific fields.
  11. struct NamedConstraintFields {
  12. // The following members are set at the `{` of the constraint definition.
  13. // The constraint scope.
  14. NameScopeId scope_id = NameScopeId::None;
  15. // The first block of the constraint body.
  16. InstBlockId body_block_id = InstBlockId::None;
  17. // The implicit `Self` parameter. This is a BindSymbolicName instruction.
  18. InstId self_param_id = InstId::None;
  19. // The following members are set at the `}` of the constraint definition.
  20. bool complete = false;
  21. };
  22. // A named constraint. See EntityWithParamsBase regarding the inheritance here.
  23. struct NamedConstraint : public EntityWithParamsBase,
  24. public NamedConstraintFields,
  25. public Printable<NamedConstraint> {
  26. auto Print(llvm::raw_ostream& out) const -> void {
  27. out << "{";
  28. PrintBaseFields(out);
  29. out << "}";
  30. }
  31. // This is false until we reach the `}` of the constraint definition.
  32. auto is_complete() const -> bool { return complete; }
  33. // Determines whether we're currently defining the constraint. This is true
  34. // between the braces of the constraint.
  35. auto is_being_defined() const -> bool {
  36. return has_definition_started() && !is_complete();
  37. }
  38. };
  39. using NamedConstraintStore = ValueStore<NamedConstraintId, NamedConstraint>;
  40. } // namespace Carbon::SemIR
  41. #endif // CARBON_TOOLCHAIN_SEM_IR_NAMED_CONSTRAINT_H_