interface.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 << ", enclosing_scope: " << enclosing_scope_id
  12. << "}";
  13. }
  14. // Determines whether this interface has been fully defined. This is false
  15. // until we reach the `}` of the interface definition.
  16. auto is_defined() const -> bool { return associated_entities_id.is_valid(); }
  17. // Determines whether we're currently defining the interface. This is true
  18. // between the braces of the interface.
  19. auto is_being_defined() const -> bool {
  20. return definition_id.is_valid() && !is_defined();
  21. }
  22. // The following members always have values, and do not change throughout the
  23. // lifetime of the interface.
  24. // The interface name.
  25. NameId name_id;
  26. // The enclosing scope.
  27. NameScopeId enclosing_scope_id;
  28. // The first declaration of the interface. This is a InterfaceDecl.
  29. InstId decl_id;
  30. // The following members are set at the `{` of the interface definition.
  31. // The definition of the interface. This is a InterfaceDecl.
  32. InstId definition_id = InstId::Invalid;
  33. // The interface scope.
  34. NameScopeId scope_id = NameScopeId::Invalid;
  35. // The first block of the interface body.
  36. // TODO: Handle control flow in the interface body, such as if-expressions.
  37. InstBlockId body_block_id = InstBlockId::Invalid;
  38. // The implicit `Self` parameter. This is a BindSymbolicName instruction.
  39. InstId self_param_id = InstId::Invalid;
  40. // The following members are set at the `}` of the interface definition.
  41. InstBlockId associated_entities_id = InstBlockId::Invalid;
  42. };
  43. } // namespace Carbon::SemIR
  44. #endif // CARBON_TOOLCHAIN_SEM_IR_INTERFACE_H_