More const preparation: allow type casts to follow qualification.
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_sp2_symbol_h_
20 #define _include_sp2_symbol_h_
22 #include "../PoolAllocator.h"
23 #include "../Handles.h"
24 #include "../Opcodes.h"
26 #include "../Strings.h"
32 #define SYMBOL_KINDS(_) \
33 /* Any kind of variable or argument produces a VariableSymbol. */ \
35 /* A function declaration produces a FunctionSymbol. */ \
37 /* A named constant produces a ConstantSymbol. */ \
39 /* A named type (class struct, typedef, etc) produces a TypeSymbol. */ \
41 /* // A module import produces a ModuleSymbol. */ \
44 #define _(name) class name##Symbol;
50 // A symbol represents the declaration of a named entity.
51 class Symbol : public PoolObject
55 # define _(name) k##name,
62 Symbol(Scope *scope, Handle<String> name, const SourcePosition &pos)
69 virtual Kind kind() const = 0;
71 Handle<String> name() const {
74 const SourcePosition &pos() const {
77 Handle<Type> type() const {
80 Scope *scope() const {
86 bool is##name() const { \
87 return (kind() == k##name); \
89 name##Symbol *as##name() { \
94 name##Symbol *to##name() { \
96 return reinterpret_cast<name##Symbol *>(this); \
103 ScopedRoot<String> name_;
107 ScopedRoot<Type> type_;
110 class VariableSymbol : public Symbol
121 VariableSymbol(Scope *scope, Handle<String> name, const SourcePosition &pos)
122 : Symbol(scope, name, pos),
127 VariableSymbol(Scope *scope, Handle<String> name, const SourcePosition &pos, Handle<Type> type)
128 : Symbol(scope, name, pos),
137 void setType(Type *type) {
141 void allocate(Storage storage, unsigned slot) {
145 Storage storage() const {
148 unsigned slot() const {
149 assert(storage() != Unknown);
158 class TypeSymbol : public Symbol
161 TypeSymbol(Scope *scope, Handle<String> name, Handle<Type> type)
162 : Symbol(scope, name, SourcePosition())
172 class FunctionSymbol : public Symbol
175 FunctionSymbol(Scope *scope, Handle<String> name, const SourcePosition &pos, Handle<FunctionType> type)
176 : Symbol(scope, name, pos)
184 FunctionType *type() const {
185 return FunctionType::cast(type_);
189 class ConstantSymbol : public Symbol
192 ConstantSymbol(Scope *scope, Handle<String> name, const SourcePosition &pos, Handle<Type> type,
193 const BoxedPrimitive &prim)
194 : Symbol(scope, name, pos),
203 const BoxedPrimitive &value() const {
208 BoxedPrimitive value_;
213 #endif // _include_sp2_symbol_h_