LoopScriptNodes.cpp

Go to the documentation of this file.
00001 /*
00002  *      LoopScriptNodes.cpp -
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 #include "pent_include.h"
00022 
00023 #include "LoopScriptNodes.h"
00024 
00025 #include <map>
00026 #include <string>
00027 extern std::map<sint32, std::string> ScriptExpressions;
00028 
00029 /****************************************************************************
00030         LoopScriptNode
00031  ****************************************************************************/
00032  
00033 void LoopScriptNode::print_unk(Console &o, const uint32 isize) const
00034 {
00035         assert(rtype().type()==Type::T_INVALID);
00036         Node::print_linenum_unk(o, isize);
00037         o.Printf("loopscr(%c)", static_cast<char>(scriptTok));
00038 }
00039 
00040 void LoopScriptNode::print_asm(Console &o) const   
00041 {
00042         assert(rtype().type()==Type::T_INVALID);
00043         Node::print_linenum_asm(o);
00044         o.Printf("loopscr\t\t%02X \"%c\" - %s", scriptTok, static_cast<char>(scriptTok), ScriptExpressions[scriptTok].c_str());
00045 }
00046 
00047 void LoopScriptNode::print_bin(ODequeDataSource &o) const
00048 {
00049         assert(rtype().type()==Type::T_INVALID);
00050         Node::print_linenum_bin(o);
00051         o.write1(0x74);
00052         o.write1(scriptTok);
00053 }
00054 
00055 bool LoopScriptNode::fold(DCUnit * /*unit*/, std::deque<Node *> &nodes)
00056 {
00057         fold_linenum(nodes); // TODO: maybe? Might not get line numbers attached since it's rather special...
00058 
00059         return true;
00060 }
00061 
00062 /****************************************************************************
00063         LoopNode
00064  ****************************************************************************/
00065  
00066 bool LoopNode::fold(DCUnit * /*unit*/, std::deque<Node *> &nodes)
00067 {
00068                 // we need to remove ourselves from the stack before doing anything tricky
00069                 //assert(acceptOp(nodes.back()->opcode(), 0x70) || print_assert(this, unit));
00070                 //Node *us=nodes.back();
00071                 //nodes.pop_back();
00072                 
00073                 // grab the nodes, removing them all until we get to a $ 'end' node
00074                 assert(nodes.size()>0);
00075                 while(nodes.size()>0 && (acceptOp(nodes.back()->opcode(), 0x74) && static_cast<LoopScriptNode*>(nodes.back())->lsTok()=='$'))
00076                 {
00077                         pnode.push_back(grab(nodes));
00078                 }
00079                 //grab_p(nodes, std::abs(static_cast<sint32>(addSP->size())));
00080                 
00081                 // add us back to the stack
00082                 //nodes.push_back(us);
00083         
00084         // potential line numbers come 'before' the pushed values, so we need to grab
00085         // them after the values
00086         fold_linenum(nodes);
00087         
00088         return false;
00089 }
00090 
00091 void LoopNode::print_unk(Console &o, const uint32 isize) const
00092 {
00093         print_linenum_unk(o, isize);
00094         o.Printf("search_%s_type_%02X(", suc::print_bp(currObj), searchType);
00095         for(std::deque<Node *>::const_reverse_iterator i=pnode.rbegin(); i!=pnode.rend(); ++i)
00096         {
00097                 if(i!=pnode.rbegin()) o.Print(", ");
00098                 (*i)->print_unk(o, isize);
00099         }
00100         o.Putchar(')');
00101 }
00102 
00103 void LoopNode::print_asm(Console &o) const
00104 {
00105         print_linenum_asm(o);
00106         for(std::deque<Node *>::const_reverse_iterator i=pnode.rbegin(); i!=pnode.rend(); ++i)
00107         {
00108                 (*i)->print_asm(o); o.Putchar('\n');
00109         }
00110         Node::print_asm(o);
00111         o.Printf("loop\t\t%s %02X %02X", suc::print_bp(currObj), strSize, searchType);
00112 }
00113 
00114 void LoopNode::print_bin(ODequeDataSource &o) const
00115 {
00116         print_linenum_bin(o);
00117         for(std::deque<Node *>::const_reverse_iterator i=pnode.rbegin(); i!=pnode.rend(); ++i)
00118         {
00119                 (*i)->print_bin(o);
00120         }
00121         o.write1(0x70);
00122         o.write1(currObj);
00123         o.write1(strSize);
00124         o.write1(searchType);
00125 }
00126 
00127 /****************************************************************************
00128         LoopNextNode
00129  ****************************************************************************/
00130 
00131 void LoopNextNode::print_unk(Console &o, const uint32 isize) const
00132 {
00133         assert(rtype().type()==Type::T_INVALID);
00134         Node::print_linenum_unk(o, isize);
00135         o.Printf("/*loopnext_NOPRINT()*/");
00136 }
00137 
00138 void LoopNextNode::print_asm(Console &o) const   
00139 {
00140         assert(rtype().type()==Type::T_INVALID);
00141         Node::print_linenum_asm(o);
00142         o.Printf("loopnext");
00143 }
00144 
00145 void LoopNextNode::print_bin(ODequeDataSource &o) const
00146 {
00147         assert(rtype().type()==Type::T_INVALID);
00148         Node::print_linenum_bin(o);
00149         o.write1(0x73);
00150 }
00151 
00152 bool LoopNextNode::fold(DCUnit * /*unit*/, std::deque<Node *> & /*nodes*/)
00153 {
00154         //fold_linenum(nodes); // should never be a linenum before this
00155 
00156         return true;
00157 }
00158 

Generated on Fri Jul 27 22:27:23 2007 for pentagram by  doxygen 1.4.7