#ifndef __AST_SYMBOL_H #define __AST_SYMBOL_H /* 5D programming language Copyright (C) 2011 Danny Milosavljevic This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "AST/AST" #ifdef __GNUC__ #define G_5D_GNUC_PURE __attribute__ ((pure)) #else #define G_5D_GNUC_PURE #endif namespace AST { struct Symbol : Node { const char* name; virtual std::string toString(void) const; }; struct SymbolReference : Node { NodeT symbol; int index; public: SymbolReference(NodeT symbol, int index); virtual std::string toString(void) const; }; NodeT symbolFromStr(const char* name) G_5D_GNUC_PURE; static inline bool symbol_P(AST::NodeT argument) { return(dynamic_cast(argument) != NULL || dynamic_cast(argument) != NULL); } static inline bool symbol1_P(AST::NodeT argument) { return(dynamic_cast(argument) != NULL); } /* will return NULL if not a Symbol. */ static inline const char* get_symbol_name(AST::NodeT argument) { SymbolReference* r = dynamic_cast(argument); Symbol* s = dynamic_cast(r ? r->symbol : argument); return s ? s->name : NULL; } /* will return NULL if not a Symbol. */ static inline const char* get_symbol1_name(AST::NodeT argument) { Symbol* s = dynamic_cast(argument); return s ? s->name : NULL; } static inline AST::NodeT get_symbol_reference_name(AST::NodeT root) { AST::SymbolReference* refNode = dynamic_cast(root); if(refNode) return(refNode->symbol); else return(NULL); } static inline int get_symbol_reference_index(AST::NodeT root) { AST::SymbolReference* refNode = dynamic_cast(root); if(refNode) return(refNode->index); else return(-1); } static inline bool symbol_reference_P(AST::NodeT root) { return(dynamic_cast(root) != NULL); } }; #endif /* ndef __AST_SYMBOL_H */