named_constraint.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 SymbolicBinding instruction.
  18. InstId self_param_id = InstId::None;
  19. // The following members are set at the `}` of the constraint definition.
  20. RequireImplsBlockId require_impls_block_id = RequireImplsBlockId::None;
  21. bool complete = false;
  22. };
  23. // A named constraint. See EntityWithParamsBase regarding the inheritance here.
  24. struct NamedConstraint : public EntityWithParamsBase,
  25. public NamedConstraintFields,
  26. public Printable<NamedConstraint> {
  27. auto Print(llvm::raw_ostream& out) const -> void {
  28. out << "{";
  29. PrintBaseFields(out);
  30. out << ", require_impls_block_id: " << require_impls_block_id;
  31. out << "}";
  32. }
  33. // This is false until we reach the `}` of the constraint definition.
  34. auto is_complete() const -> bool { return complete; }
  35. // Determines whether we're currently defining the constraint. This is true
  36. // between the braces of the constraint.
  37. auto is_being_defined() const -> bool {
  38. return has_definition_started() && !is_complete();
  39. }
  40. };
  41. using NamedConstraintStore = ValueStore<NamedConstraintId, NamedConstraint>;
  42. } // namespace Carbon::SemIR
  43. #endif // CARBON_TOOLCHAIN_SEM_IR_NAMED_CONSTRAINT_H_