heap_allocation_interface.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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_EXPLORER_INTERPRETER_HEAP_ALLOCATION_INTERFACE_H_
  5. #define CARBON_EXPLORER_INTERPRETER_HEAP_ALLOCATION_INTERFACE_H_
  6. #include "explorer/common/arena.h"
  7. #include "explorer/common/nonnull.h"
  8. #include "explorer/interpreter/address.h"
  9. namespace Carbon {
  10. class Value;
  11. // The allocation interface for Heap, factored out as an interface in order to
  12. // resolve a layering issue. No other class should derive from this.
  13. class HeapAllocationInterface {
  14. public:
  15. HeapAllocationInterface(const HeapAllocationInterface&) = delete;
  16. auto operator=(const HeapAllocationInterface&)
  17. -> HeapAllocationInterface& = delete;
  18. // Put the given value on the heap and mark it as alive.
  19. virtual auto AllocateValue(Nonnull<const Value*> v) -> AllocationId = 0;
  20. // Marks this allocation, and all of its sub-objects, as dead.
  21. virtual void Deallocate(AllocationId allocation) = 0;
  22. // Returns the arena used to allocate the values in this heap.
  23. virtual auto arena() const -> Arena& = 0;
  24. protected:
  25. HeapAllocationInterface() = default;
  26. virtual ~HeapAllocationInterface() = default;
  27. };
  28. } // namespace Carbon
  29. #endif // CARBON_EXPLORER_INTERPRETER_HEAP_ALLOCATION_INTERFACE_H_