interface.h 2.0 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_INTERFACE_H_
  5. #define CARBON_TOOLCHAIN_SEM_IR_INTERFACE_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. // Interface-specific fields.
  11. struct InterfaceFields {
  12. // The following members are set at the `{` of the interface definition.
  13. // The interface scope.
  14. NameScopeId scope_id = NameScopeId::None;
  15. // The first block of the interface body.
  16. // TODO: Handle control flow in the interface body, such as if-expressions.
  17. InstBlockId body_block_id = InstBlockId::None;
  18. // The implicit `Self` parameter. This is a SymbolicBinding instruction.
  19. InstId self_param_id = InstId::None;
  20. // The following members are set at the `}` of the interface definition.
  21. RequireImplsBlockId require_impls_block_id = RequireImplsBlockId::None;
  22. InstBlockId associated_entities_id = InstBlockId::None;
  23. };
  24. // An interface. See EntityWithParamsBase regarding the inheritance here.
  25. struct Interface : public EntityWithParamsBase,
  26. public InterfaceFields,
  27. public Printable<Interface> {
  28. auto Print(llvm::raw_ostream& out) const -> void {
  29. out << "{";
  30. PrintBaseFields(out);
  31. out << ", require_impls_block_id: " << require_impls_block_id;
  32. out << "}";
  33. }
  34. // This is false until we reach the `}` of the interface definition.
  35. auto is_complete() const -> bool {
  36. return associated_entities_id.has_value();
  37. }
  38. // Determines whether we're currently defining the interface. This is true
  39. // between the braces of the interface.
  40. auto is_being_defined() const -> bool {
  41. return has_definition_started() && !is_complete();
  42. }
  43. };
  44. using InterfaceStore = ValueStore<InterfaceId, Interface, Tag<CheckIRId>>;
  45. } // namespace Carbon::SemIR
  46. #endif // CARBON_TOOLCHAIN_SEM_IR_INTERFACE_H_