Initial import of prototype.
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"
22 #include "StringPool.h"
31 class BoundName : public PoolObject
43 BoundName(Scope *scope, Name *name);
45 virtual Kind kind() const = 0;
50 Scope *scope() const {
53 Variable *toVariable() {
54 assert(kind() == VARIABLE);
55 return reinterpret_cast<Variable *>(this);
57 NamedFunction *toNamedFunction() {
58 assert(kind() == FUNCTION);
59 return reinterpret_cast<NamedFunction *>(this);
64 void setType(Type *type) {
69 class NamedFunction : public BoundName
74 NamedFunction(Scope *scope, Name *name);
79 void allocate(unsigned slot) {
82 unsigned slot() const {
87 class Variable : public BoundName
96 Variable(Scope *scope, Name *name);
101 bool unallocated() const {
102 return location() == UNALLOCATED;
104 void allocate(Location location, unsigned slot) {
105 location_ = location;
108 Location location() const {
111 unsigned slot() const {
112 assert(!unallocated());
123 #endif // _include_name_binding_h_