mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-30 22:02:41 +01:00
This PR includes the following changes: * Added destruction process for tuples * Fix: In the current version only the last member of a object can be destroyed * Fix: In the current version, the destructor of the object is called after each method call I hope it is useful Co-authored-by: m new <michael.burzan@outlook.de> Co-authored-by: Geoff Romer <gromer@google.com>
46 lines
1.6 KiB
C++
46 lines
1.6 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#ifndef CARBON_EXPLORER_INTERPRETER_HEAP_ALLOCATION_INTERFACE_H_
|
|
#define CARBON_EXPLORER_INTERPRETER_HEAP_ALLOCATION_INTERFACE_H_
|
|
|
|
#include "explorer/common/arena.h"
|
|
#include "explorer/common/nonnull.h"
|
|
#include "explorer/interpreter/address.h"
|
|
|
|
namespace Carbon {
|
|
|
|
class Value;
|
|
|
|
// The allocation interface for Heap, factored out as an interface in order to
|
|
// resolve a layering issue. No other class should derive from this.
|
|
class HeapAllocationInterface {
|
|
public:
|
|
HeapAllocationInterface(const HeapAllocationInterface&) = delete;
|
|
auto operator=(const HeapAllocationInterface&)
|
|
-> HeapAllocationInterface& = delete;
|
|
|
|
// Put the given value on the heap and mark it as alive.
|
|
virtual auto AllocateValue(Nonnull<const Value*> v) -> AllocationId = 0;
|
|
|
|
// Marks this allocation, and all of its sub-objects, as dead.
|
|
virtual void Deallocate(AllocationId allocation) = 0;
|
|
|
|
// Returns the arena used to allocate the values in this heap.
|
|
virtual auto arena() const -> Arena& = 0;
|
|
|
|
// Returns the ID of the first allocation that holds `v`, if one exists.
|
|
// TODO: Find a way to remove this.
|
|
virtual auto GetAllocationId(Nonnull<const Value*> v) const
|
|
-> std::optional<AllocationId> = 0;
|
|
|
|
protected:
|
|
HeapAllocationInterface() = default;
|
|
virtual ~HeapAllocationInterface() = default;
|
|
};
|
|
|
|
} // namespace Carbon
|
|
|
|
#endif // CARBON_EXPLORER_INTERPRETER_HEAP_ALLOCATION_INTERFACE_H_
|