vtable.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  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_VTABLE_H_
  5. #define CARBON_TOOLCHAIN_SEM_IR_VTABLE_H_
  6. #include "toolchain/base/value_store.h"
  7. #include "toolchain/sem_ir/ids.h"
  8. namespace Carbon::SemIR {
  9. // Vtable-specific fields.
  10. struct VtableFields {
  11. // The class this is the vtable for.
  12. ClassId class_id;
  13. // A block containing all the virtual functions in this class and
  14. // non-overriden functions in base classes, forming the complete vtable for
  15. // the class.
  16. InstBlockId virtual_functions_id;
  17. };
  18. struct Vtable : public VtableFields, public Printable<Vtable> {
  19. auto Print(llvm::raw_ostream& out) const -> void {
  20. out << "{class: " << class_id << ", {";
  21. virtual_functions_id.Print(out);
  22. out << "}}";
  23. }
  24. };
  25. using VtableStore = ValueStore<VtableId, Vtable, Tag<CheckIRId>>;
  26. } // namespace Carbon::SemIR
  27. #endif // CARBON_TOOLCHAIN_SEM_IR_VTABLE_H_