interface.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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/sem_ir/entity_with_params_base.h"
  7. #include "toolchain/sem_ir/ids.h"
  8. namespace Carbon::SemIR {
  9. // Interface-specific fields.
  10. struct InterfaceFields {
  11. // The following members are set at the `{` of the interface definition.
  12. // The interface scope.
  13. NameScopeId scope_id = NameScopeId::None;
  14. // The first block of the interface body.
  15. // TODO: Handle control flow in the interface body, such as if-expressions.
  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 interface definition.
  20. InstBlockId associated_entities_id = InstBlockId::None;
  21. };
  22. // An interface. See EntityWithParamsBase regarding the inheritance here.
  23. struct Interface : public EntityWithParamsBase,
  24. public InterfaceFields,
  25. public Printable<Interface> {
  26. auto Print(llvm::raw_ostream& out) const -> void {
  27. out << "{";
  28. PrintBaseFields(out);
  29. out << "}";
  30. }
  31. // Determines whether this interface has been fully defined. This is false
  32. // until we reach the `}` of the interface definition.
  33. auto is_defined() const -> bool { return associated_entities_id.has_value(); }
  34. // Determines whether we're currently defining the interface. This is true
  35. // between the braces of the interface.
  36. auto is_being_defined() const -> bool {
  37. return has_definition_started() && !is_defined();
  38. }
  39. };
  40. } // namespace Carbon::SemIR
  41. #endif // CARBON_TOOLCHAIN_SEM_IR_INTERFACE_H_