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