interface.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/ids.h"
  7. namespace Carbon::SemIR {
  8. // An interface.
  9. struct Interface : public Printable<Interface> {
  10. auto Print(llvm::raw_ostream& out) const -> void {
  11. out << "{name: " << name_id << ", parent_scope: " << parent_scope_id << "}";
  12. }
  13. // Determines whether this interface has been fully defined. This is false
  14. // until we reach the `}` of the interface definition.
  15. auto is_defined() const -> bool { return associated_entities_id.is_valid(); }
  16. // Determines whether we're currently defining the interface. This is true
  17. // between the braces of the interface.
  18. auto is_being_defined() const -> bool {
  19. return definition_id.is_valid() && !is_defined();
  20. }
  21. // Determines whether this is a generic interface.
  22. auto is_generic() const -> bool {
  23. return implicit_param_refs_id.is_valid() || param_refs_id.is_valid();
  24. }
  25. // The following members always have values, and do not change throughout the
  26. // lifetime of the interface.
  27. // The interface name.
  28. NameId name_id;
  29. // The parent scope.
  30. NameScopeId parent_scope_id;
  31. // If this is a generic function, information about the generic.
  32. GenericId generic_id;
  33. // A block containing a single reference instruction per implicit parameter.
  34. InstBlockId implicit_param_refs_id;
  35. // A block containing a single reference instruction per parameter.
  36. InstBlockId param_refs_id;
  37. // The first declaration of the interface. This is a InterfaceDecl.
  38. InstId decl_id;
  39. // The following members are set at the `{` of the interface definition.
  40. // The definition of the interface. This is a InterfaceDecl.
  41. InstId definition_id = InstId::Invalid;
  42. // The interface scope.
  43. NameScopeId scope_id = NameScopeId::Invalid;
  44. // The first block of the interface body.
  45. // TODO: Handle control flow in the interface body, such as if-expressions.
  46. InstBlockId body_block_id = InstBlockId::Invalid;
  47. // The implicit `Self` parameter. This is a BindSymbolicName instruction.
  48. InstId self_param_id = InstId::Invalid;
  49. // The following members are set at the `}` of the interface definition.
  50. InstBlockId associated_entities_id = InstBlockId::Invalid;
  51. };
  52. } // namespace Carbon::SemIR
  53. #endif // CARBON_TOOLCHAIN_SEM_IR_INTERFACE_H_