00001 /* 00002 * CompileNodes.h - The defintions of all the compile node types 00003 * 00004 * Copyright (C) 2002-2003 The Pentagram Team 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 */ 00020 00021 #ifndef COMPILENODES_H 00022 #define COMPILENODES_H 00023 00024 #include "llcTokens.h" 00025 00026 #include <string> 00027 #include <list> 00028 00029 // Basic Node Class ********************************************************* 00030 class CompileNode 00031 { 00032 public: 00033 CompileNode(const uint32 _linenum) : linenum(_linenum) {}; 00034 00035 virtual void print_unk(std::ostream &o)=0; 00036 virtual bool isA(const LLCToken &tok)=0; // check if node is of particular type 00037 00038 const uint32 linenum; 00039 }; 00040 00041 // General stringy stuff ***************************************************** 00042 class CStringNode : public CompileNode 00043 { 00044 public: 00045 CStringNode(const char * const _str, const uint32 _linenum) : 00046 CompileNode(_linenum), str(_str) {}; 00047 virtual ~CStringNode() {}; 00048 00049 virtual void print_unk(std::ostream &o) { o << str; }; 00050 virtual bool isA(const LLCToken &tok) { return tok==LLC_STRING; }; 00051 const std::string str; 00052 }; 00053 00054 class VarIdentNode : public CStringNode 00055 { 00056 public: 00057 VarIdentNode(const char * const _idname, const uint32 _linenum) : 00058 CStringNode(_idname, _linenum) {}; 00059 virtual ~VarIdentNode() {}; 00060 00061 virtual bool isA(const LLCToken &tok) { return tok==LLC_IDENT; }; 00062 00063 }; 00064 00065 // Classes, functions and statements. (Oh my!) ******************************* 00066 00067 class FuncNode : public CompileNode 00068 { 00069 public: 00070 FuncNode(const uint32 _linenum) : CompileNode(_linenum) {}; 00071 00072 void print_unk(std::ostream &o) {}; 00073 bool isA(const LLCToken &tok) { return false; }; //FIXME:! 00074 00075 }; 00076 00077 class ClassNode : public CompileNode 00078 { 00079 public: 00080 ClassNode(const uint32 _linenum) : CompileNode(_linenum) {} 00081 virtual ~ClassNode() {} 00082 00083 void print_unk(std::ostream &o) 00084 { 00085 o << "class "; 00086 if(name!="") 00087 o << name << ' '; 00088 } 00089 00090 bool isA(const LLCToken &tok) { return tok==LLC_CLASS; }; 00091 00092 std::string name; 00093 std::list<FuncNode *> functions; 00094 }; 00095 00096 // Randoms... **************************************************************** 00097 // Just general pointless classes that are 'just' tokens and aren't use for 00098 // anything other then making parsing easier... 00099 00100 class FencePostNode : public CompileNode 00101 { 00102 public: 00103 FencePostNode(const LLCToken _tok, const uint32 _linenum) : 00104 CompileNode(_linenum), iTok(_tok) {}; 00105 virtual ~FencePostNode() {}; 00106 00107 virtual void print_unk(std::ostream &o) 00108 { 00109 switch(iTok) 00110 { 00111 case LLC_OPEN_BRACE: o << '{'; break; 00112 case LLC_CLOSE_BRACE: o << '}'; break; 00113 default: assert(false); 00114 } 00115 }; 00116 virtual bool isA(const LLCToken &tok) { return tok==iTok; }; 00117 00118 private: 00119 const LLCToken iTok; 00120 }; 00121 00122 00123 #endif 00124