Fix bug in bytecode resizing.
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of SourcePawn.
7 * SourcePawn 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 * SourcePawn 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 * SourcePawn. If not, see http://www.gnu.org/licenses/.
19 #ifndef _include_name_binding_h_
20 #define _include_name_binding_h_
22 #include "PoolAllocator.h"
37 class BoundName : public PoolObject
40 ScopedRoot<String> name_;
41 ScopedRoot<Type> type_;
56 BoundName(Scope *scope, Handle<String> name, const SourcePosition &pos);
58 virtual Kind kind() const = 0;
60 String *name() const {
63 Scope *scope() const {
66 Variable *toVariable() {
67 assert(kind() == VARIABLE);
68 return reinterpret_cast<Variable *>(this);
70 NamedFunction *toNamedFunction() {
71 assert(kind() == FUNCTION);
72 return reinterpret_cast<NamedFunction *>(this);
74 NamedConstant *toNamedConstant() {
75 assert(kind() == CONSTANT);
76 return reinterpret_cast<NamedConstant *>(this);
78 NamedType *toNamedType() {
79 assert(kind() == TYPE);
80 return reinterpret_cast<NamedType *>(this);
85 void setType(Handle<Type> type) {
94 const SourcePosition &pos() {
99 class NamedFunction : public BoundName
103 ScopedRoot<Type> forwardType_;
104 bool isVariadicNative_;
105 Vector<BoundName *, PoolAllocationPolicy> globals_;
108 NamedFunction(Scope *scope, Handle<String> name, const SourcePosition &pos, TokenKind token);
113 void allocate(unsigned slot) {
116 bool isForward() const {
117 return token_ == TOK_FORWARD;
119 bool isPublic() const {
120 return token_ == TOK_PUBLIC;
122 bool isNative() const {
123 return token_ == TOK_NATIVE;
125 TokenKind token() const {
128 void setForwardType(Handle<Type> type) {
131 Type *forwardType() {
134 void setImplemented(const SourcePosition &at) {
138 void markNativeVariadic() {
139 assert(token_ == TOK_NATIVE);
140 isVariadicNative_ = true;
142 bool isNativeVariadic() {
143 assert(token_ == TOK_NATIVE);
144 return isVariadicNative_;
146 unsigned slot() const {
149 bool addUsedGlobal(BoundName *name) {
150 return globals_.append(name);
152 Vector<BoundName *, PoolAllocationPolicy> *usedGlobals() {
157 class NamedConstant : public BoundName
159 BoxedPrimitive value_;
162 NamedConstant(Scope *scope, Handle<String> name, const SourcePosition &pos)
163 : BoundName(scope, name, pos)
170 void set(Handle<Type> type, const BoxedPrimitive &value) {
174 BoxedPrimitive value() const {
179 class NamedType : public BoundName
182 NamedType(Scope *scope, Handle<String> name, Handle<Type> type)
183 : BoundName(scope, name, SourcePosition())
188 NamedType(Scope *scope, Handle<String> name, const SourcePosition &pos)
189 : BoundName(scope, name, pos)
198 class UnboundName : public BoundName
201 UnboundName(Scope *scope, Handle<String> name)
202 : BoundName(scope, name, SourcePosition())
211 class Variable : public BoundName
221 Variable(Scope *scope, Handle<String> name, const SourcePosition &pos);
226 bool unallocated() const {
227 return location() == UNALLOCATED;
229 void allocate(Location location, unsigned slot) {
230 location_ = location;
233 Location location() const {
236 unsigned slot() const {
237 assert(!unallocated());
244 bool isPublic() const {
247 bool needsHeapAllocation();
257 #endif // _include_name_binding_h_