interface.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. // This is false until we reach the `}` of the interface definition.
  32. auto is_complete() const -> bool {
  33. return associated_entities_id.has_value();
  34. }
  35. // Determines whether we're currently defining the interface. This is true
  36. // between the braces of the interface.
  37. auto is_being_defined() const -> bool {
  38. return has_definition_started() && !is_complete();
  39. }
  40. };
  41. } // namespace Carbon::SemIR
  42. #endif // CARBON_TOOLCHAIN_SEM_IR_INTERFACE_H_