Fix opt clang build.
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_;
52 BoundName(Scope *scope, Handle<String> name, const SourcePosition &pos);
54 virtual Kind kind() const = 0;
56 String *name() const {
59 Scope *scope() const {
62 Variable *toVariable() {
63 assert(kind() == VARIABLE);
64 return reinterpret_cast<Variable *>(this);
66 NamedFunction *toNamedFunction() {
67 assert(kind() == FUNCTION);
68 return reinterpret_cast<NamedFunction *>(this);
70 NamedConstant *toNamedConstant() {
71 assert(kind() == CONSTANT);
72 return reinterpret_cast<NamedConstant *>(this);
77 void setType(Handle<Type> type) {
80 const SourcePosition &pos() {
85 class NamedFunction : public BoundName
89 ScopedRoot<Type> forwardType_;
90 bool isVariadicNative_;
93 NamedFunction(Scope *scope, Handle<String> name, const SourcePosition &pos, TokenKind token);
98 void allocate(unsigned slot) {
101 bool isForward() const {
102 return token_ == TOK_FORWARD;
104 bool isPublic() const {
105 return token_ == TOK_PUBLIC;
107 bool isNative() const {
108 return token_ == TOK_NATIVE;
110 void setForwardType(Handle<Type> type) {
113 Type *forwardType() {
116 void setImplemented(const SourcePosition &at) {
120 void markNativeVariadic() {
121 assert(token_ == TOK_NATIVE);
122 isVariadicNative_ = true;
124 bool isNativeVariadic() {
125 assert(token_ == TOK_NATIVE);
126 return isVariadicNative_;
128 unsigned slot() const {
133 class NamedEnum : public BoundName
136 NamedEnum(Scope *scope, Handle<String> name, const SourcePosition &pos)
137 : BoundName(scope, name, pos)
146 class NamedConstant : public BoundName
148 BoxedPrimitive value_;
152 NamedConstant(Scope *scope, Handle<String> name, const SourcePosition &pos)
153 : BoundName(scope, name, pos),
161 void set(Type *type, const BoxedPrimitive &value) {
168 BoxedPrimitive value() const {
173 class Variable : public BoundName
183 Variable(Scope *scope, Handle<String> name, const SourcePosition &pos);
188 bool unallocated() const {
189 return location() == UNALLOCATED;
191 void allocate(Location location, unsigned slot) {
192 location_ = location;
195 Location location() const {
198 unsigned slot() const {
199 assert(!unallocated());
202 bool needsHeapAllocation();
211 #endif // _include_name_binding_h_