Added RootScopes for AST roots.
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of JITCraft.
7 * JITCraft is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
12 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with
17 * JITCraft. If not, see http://www.gnu.org/licenses/.
19 #ifndef _include_jitcraft_rooting_h_
20 #define _include_jitcraft_rooting_h_
28 template <typename T> class Local;
29 template <typename T> class ScopedRoot;
37 template <typename S> Handle(const Handle<S> &handle) {
39 thingp_ = reinterpret_cast<T * const *>(handle.address());
41 template <typename S> inline Handle(const Local<S> &local);
42 template <typename S> inline Handle(const ScopedRoot<S> &root);
51 operator T *() { return *thingp_; }
52 operator bool() const {
53 return thingp_ && *thingp_;
55 T * const *address() const {
80 Local<Object> *prev() {
83 Local<Object> *toRaw() {
84 return reinterpret_cast<Local<Object>*>(this);
88 // These are implemented in Zone.h.
89 inline explicit Local(Zone *zone, T *thing = NULL);
92 const Local &operator =(T *thing) {
96 T *operator ->() const {
99 T *operator *() const {
102 operator bool () const {
107 return (Object **)&thing_;
109 Object * const *address() const {
110 return (Object * const *)&thing_;
117 // Disallow heap allocation.
118 void *operator new(size_t size);
119 void *operator new[](size_t size);
121 // Disallow copy construction.
122 Local(const Local<T> &other);
123 Local &operator =(const Local &other);
126 // A ScopedRoot is a special kind of handle for storing references on the
128 template <typename T>
134 // This is implemented in Zone.h.
135 inline T **make(T *other);
137 void assign(T *other) {
139 thingp_ = make(other);
148 // This is implemented in Zone.h.
149 inline ScopedRoot(T *thing);
151 ScopedRoot &operator =(const ScopedRoot<T> &other) {
155 ScopedRoot &operator =(T *other) {
159 T *operator ->() const {
162 T *operator *() const {
165 operator T *() const {
166 return thingp_ ? *thingp_ : NULL;
168 operator bool () const {
169 return thingp_ && *thingp_;
173 template <typename T> template <typename S> inline
174 Handle<T>::Handle(const Local<S> &local)
177 thingp_ = reinterpret_cast<T * const*>(local.address());
182 #endif // _include_jitcraft_rooting_h_