Normalise line endings.
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 /* An import name. */ \
43 /* A name implicitly derived from an import. */ \
46 #define _(name) class name##Symbol;
52 // A symbol represents the declaration of a named entity.
53 class Symbol : public PoolObject
57 # define _(name) k##name,
64 Symbol(Scope *scope, Handle<String> name, const SourcePosition &pos)
71 virtual Kind kind() const = 0;
73 Handle<String> name() const {
76 const SourcePosition &pos() const {
79 Handle<Type> type() const {
82 Scope *scope() const {
88 bool is##name() const { \
89 return (kind() == k##name); \
91 name##Symbol *as##name() { \
96 name##Symbol *to##name() { \
98 return reinterpret_cast<name##Symbol *>(this); \
105 ScopedRoot<String> name_;
109 ScopedRoot<Type> type_;
112 class VariableSymbol : public Symbol
123 VariableSymbol(Scope *scope, Handle<String> name, const SourcePosition &pos)
124 : Symbol(scope, name, pos),
129 VariableSymbol(Scope *scope, Handle<String> name, const SourcePosition &pos, Handle<Type> type)
130 : Symbol(scope, name, pos),
139 void setType(Type *type) {
143 void allocate(Storage storage, unsigned slot) {
147 Storage storage() const {
150 unsigned slot() const {
151 assert(storage() != Unknown);
160 class TypeSymbol : public Symbol
163 TypeSymbol(Scope *scope, Handle<String> name, Handle<Type> type, Handle<Type> effective)
164 : Symbol(scope, name, SourcePosition()),
165 effective_(effective)
173 Handle<Type> effective() {
178 ScopedRoot<Type> effective_;
181 class FunctionSymbol : public Symbol
184 FunctionSymbol(Scope *scope, Handle<String> name, const SourcePosition &pos, Handle<FunctionType> type)
185 : Symbol(scope, name, pos)
193 FunctionType *type() const {
194 return FunctionType::cast(type_);
198 class ConstantSymbol : public Symbol
201 ConstantSymbol(Scope *scope, Handle<String> name, const SourcePosition &pos, Handle<Type> type,
202 const BoxedPrimitive &prim)
203 : Symbol(scope, name, pos),
212 const BoxedPrimitive &value() const {
217 BoxedPrimitive value_;
220 class ImportSymbol : public Symbol
223 ImportSymbol(Scope *scope, Handle<String> name, const SourcePosition &pos, Handle<Type> type,
225 : Symbol(scope, name, pos),
234 unsigned index() const {
242 class ImplicitSymbol : public Symbol
245 ImplicitSymbol(Scope *scope, Handle<String> name, const SourcePosition &pos, Handle<Type> type,
247 : Symbol(scope, name, pos),
249 fieldIndex_(unsigned(-1))
255 return fieldIndex_ != unsigned(-1);
260 unsigned index() const {
263 void bind(unsigned fieldIndex) {
264 fieldIndex_ = fieldIndex;
266 unsigned fieldIndex() const {
273 unsigned fieldIndex_;
278 #endif // _include_sp2_symbol_h_