interface.h 1.9 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_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 BindSymbolicName instruction.
  19. InstId self_param_id = InstId::None;
  20. // The following members are set at the `}` of the interface definition.
  21. InstBlockId associated_entities_id = InstBlockId::None;
  22. };
  23. // An interface. See EntityWithParamsBase regarding the inheritance here.
  24. struct Interface : public EntityWithParamsBase,
  25. public InterfaceFields,
  26. public Printable<Interface> {
  27. auto Print(llvm::raw_ostream& out) const -> void {
  28. out << "{";
  29. PrintBaseFields(out);
  30. out << "}";
  31. }
  32. // This is false until we reach the `}` of the interface definition.
  33. auto is_complete() const -> bool {
  34. return associated_entities_id.has_value();
  35. }
  36. // Determines whether we're currently defining the interface. This is true
  37. // between the braces of the interface.
  38. auto is_being_defined() const -> bool {
  39. return has_definition_started() && !is_complete();
  40. }
  41. };
  42. using InterfaceStore = ValueStore<InterfaceId, Interface>;
  43. } // namespace Carbon::SemIR
  44. #endif // CARBON_TOOLCHAIN_SEM_IR_INTERFACE_H_