Add |from x import names| support.
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)
164 : Symbol(scope, name, SourcePosition())
174 class FunctionSymbol : public Symbol
177 FunctionSymbol(Scope *scope, Handle<String> name, const SourcePosition &pos, Handle<FunctionType> type)
178 : Symbol(scope, name, pos)
186 FunctionType *type() const {
187 return FunctionType::cast(type_);
191 class ConstantSymbol : public Symbol
194 ConstantSymbol(Scope *scope, Handle<String> name, const SourcePosition &pos, Handle<Type> type,
195 const BoxedPrimitive &prim)
196 : Symbol(scope, name, pos),
205 const BoxedPrimitive &value() const {
210 BoxedPrimitive value_;
213 class ImportSymbol : public Symbol
216 ImportSymbol(Scope *scope, Handle<String> name, const SourcePosition &pos, Handle<Type> type,
218 : Symbol(scope, name, pos),
227 unsigned index() const {
235 class ImplicitSymbol : public Symbol
238 ImplicitSymbol(Scope *scope, Handle<String> name, const SourcePosition &pos, Handle<Type> type,
240 : Symbol(scope, name, pos),
242 fieldIndex_(unsigned(-1))
248 return fieldIndex_ != unsigned(-1);
253 unsigned index() const {
256 void bind(unsigned fieldIndex) {
257 fieldIndex_ = fieldIndex;
259 unsigned fieldIndex() const {
266 unsigned fieldIndex_;
271 #endif // _include_sp2_symbol_h_