2 * Copyright (C) 2012 David Anderson
4 * This file is part of JITCraft.
6 * JITCraft is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option)
11 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * JITCraft. If not, see http://www.gnu.org/licenses/.
18 #ifndef _include_name_binding_h_
19 #define _include_name_binding_h_
21 #include "PoolAllocator.h"
35 class BoundName : public PoolObject
38 ScopedRoot<String> name_;
39 ScopedRoot<Type> type_;
50 BoundName(Scope *scope, Handle<String> name, const SourcePosition &pos);
52 virtual Kind kind() const = 0;
54 String *name() const {
57 Scope *scope() const {
60 Variable *toVariable() {
61 assert(kind() == VARIABLE);
62 return reinterpret_cast<Variable *>(this);
64 NamedFunction *toNamedFunction() {
65 assert(kind() == FUNCTION);
66 return reinterpret_cast<NamedFunction *>(this);
68 NamedConstant *toNamedConstant() {
69 assert(kind() == CONSTANT);
70 return reinterpret_cast<NamedConstant *>(this);
75 void setType(Handle<Type> type) {
78 const SourcePosition &pos() {
83 class NamedFunction : public BoundName
88 NamedFunction(Scope *scope, Handle<String> name, const SourcePosition &pos);
93 void allocate(unsigned slot) {
96 unsigned slot() const {
101 class NamedEnum : public BoundName
104 NamedEnum(Scope *scope, Handle<String> name, const SourcePosition &pos)
105 : BoundName(scope, name, pos)
114 class NamedConstant : public BoundName
116 BoxedPrimitive value_;
120 NamedConstant(Scope *scope, Handle<String> name, const SourcePosition &pos)
121 : BoundName(scope, name, pos),
129 void set(Type *type, const BoxedPrimitive &value) {
136 BoxedPrimitive value() const {
141 class Variable : public BoundName
150 Variable(Scope *scope, Handle<String> name, const SourcePosition &pos);
155 bool unallocated() const {
156 return location() == UNALLOCATED;
158 void allocate(Location location, unsigned slot) {
159 location_ = location;
162 Location location() const {
165 unsigned slot() const {
166 assert(!unallocated());
177 #endif // _include_name_binding_h_