Type.cpp

Go to the documentation of this file.
00001 /*
00002  *      Type.cpp - General type object
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 "Type.h"
00024 
00025 /****************************************************************************
00026         Type
00027  ****************************************************************************/
00028 
00029 const char * const Type::_namearr[] =
00030         { "void", "byte", "word", "dword",
00031           "string", "pid", "var", "list",
00032           "slist", "strptr", "invalid"
00033         };
00034 
00035 void Type::print_unk(Console &o) const
00036 {
00037         o.Printf("(%s)", name());
00038 }
00039 
00040 /****************************************************************************
00041         DataType
00042  ****************************************************************************/
00043 //class GlobalName;
00044 
00045 //extern std::map<uint32, GlobalName> GlobalNames;
00046 
00047 void DataType::print_value_unk(Console &o) const
00048 {
00049         switch(_dtype)
00050         {
00051                 case DT_NULL:     /* o.Printf(""); outputs 'nothing' */       break;
00052                 case DT_BYTES:
00053                         switch(_vtype.type())
00054                         {
00055                                 case Type::T_BYTE:  o.Printf("0x%0*Xh", 2, static_cast<sint8 >(_value)); break;
00056                                 case Type::T_WORD:  o.Printf("0x%0*Xh", 4, static_cast<sint16>(_value)); break;
00057                                 case Type::T_DWORD: o.Printf("0x%0*Xh", 8, static_cast<sint32>(_value)); break;
00058                                 default: assert(false);
00059                         }
00060                         break;
00061                 case DT_BP:        o.Printf("%s", suc::print_bp(_value));          break;
00062                 //case DT_BPLIST:    o.Printf("list(%s, %d)", print_bp(value), value); break;
00063                 case DT_BPADDR:    o.Printf("addressof(%s)", suc::print_bp(_value)); break;
00064                 /*case DT_BPSTRPTR:  o.Printf("strptr(%s)", print_bp(value));    break;
00065                 case DT_SP:        o.Printf("%s", print_sp(value));            break;
00066                 case DT_SPADDR:    o.Printf("addressof(%s)", print_sp(value)); break;*/
00067                 case DT_STRING:    o.Printf("\"%s\"", _strvalue.c_str());         break;
00068                 case DT_PID:       o.Printf("pid");                            break;
00069                 /*case DT_PRESULT:   o.Printf("presult");                        break;
00070                 case DT_RESULT:    o.Printf("result");                         break;*/
00071                 case DT_GLOBAL:    o.Printf("global %s(%04X, %02X)",
00072                         "name", /*FIXME: Insert: GlobalNames[_value].name.c_str() <- here*/ _value, _valueIndex); break;
00073                 case DT_TEMP:      o.Printf("temp");                      break;
00074                 default:           assert(false); /* can't happen */      break;
00075         }
00076 }
00077 
00078 void DataType::print_value_asm(Console &o) const
00079 {
00080         switch(_dtype)
00081         {
00082                 //case DT_NULL:     /* o.Printf(""); outputs 'nothing' */       break;
00083                 case DT_BYTES:
00084                         switch(_vtype.type())
00085                         {
00086                                 case Type::T_BYTE:  o.Printf("%0*Xh", 2, static_cast<sint8 >(_value)); break;
00087                                 case Type::T_WORD:  o.Printf("%0*Xh", 4, static_cast<sint16>(_value)); break;
00088                                 case Type::T_DWORD: o.Printf("%0*Xh", 8, static_cast<sint32>(_value)); break;
00089                                 default: assert(false);
00090                         }
00091                         break;
00092                 case DT_BP:
00093                         switch(_vtype.type())
00094                         {
00095                                 case Type::T_WORD:
00096                                 case Type::T_DWORD: o.Printf("%s", suc::print_bp(_value)); break;
00097                                 default: assert(false);
00098                         }
00099                         break;
00100                 case DT_BPADDR:
00101                         switch(_vtype.type())
00102                         {
00103                                 case Type::T_DWORD: o.Printf("%s", suc::print_bp(_value)); break;
00104                                 default: assert(false);
00105                         }
00106                         break;
00107                 case DT_STRING:
00108                         switch(_vtype.type())
00109                         {
00110                                 case Type::T_STRING: o.Printf("\"%s\"", _strvalue.c_str()); break;
00111                                 default: assert(false);
00112                         }
00113                         break;
00114                 case DT_PID:
00115                 case DT_TEMP:
00116                         //do nothing, I think...
00117                         break;
00118                 case DT_GLOBAL:
00119                         switch(_vtype.type())
00120                         {
00121                                 case Type::T_WORD: o.Printf("[%04X %02X]", _value, _valueIndex); break;
00122                                 default: assert(false);
00123                         }
00124                         break;
00125                         
00126                 default: assert(false);
00127         }
00128 }
00129 
00130 void DataType::print_value_bin(ODequeDataSource &o) const
00131 {
00132         switch(_dtype)
00133         {
00134                 //case DT_NULL:     /* o.Printf(""); outputs 'nothing' */       break;
00135                 case DT_BYTES:
00136                         switch(_vtype.type())
00137                         {
00138                                 case Type::T_BYTE:  o.write1(static_cast<sint8 >(_value)); break;
00139                                 case Type::T_WORD:  o.write2(static_cast<sint16>(_value)); break;
00140                                 case Type::T_DWORD: o.write4(static_cast<sint32>(_value)); break;
00141                                 default: assert(false);
00142                         }
00143                         break;
00144                 case DT_BP:
00145                         switch(_vtype.type())
00146                         {
00147                                 case Type::T_WORD:
00148                                 case Type::T_DWORD: o.write1(_value); break;
00149                                 default: assert(false);
00150                         }
00151                         break;
00152                 case DT_BPADDR:
00153                         switch(_vtype.type())
00154                         {
00155                                 case Type::T_DWORD: o.write1(_value); break;
00156                                 default: assert(false);
00157                         }
00158                         break;
00159                 case DT_STRING:
00160                         switch(_vtype.type())
00161                         {
00162                                 case Type::T_STRING:
00163                                         o.write2(_strvalue.size());
00164                                         for(uint16 i = 0; i<_strvalue.size(); i++)
00165                                                 o.write1(_strvalue[i]);
00166                                         break;
00167                                 default: assert(false);
00168                         }
00169                         break;
00170                 case DT_PID:
00171                 case DT_TEMP:
00172                         // do nothing, I think...
00173                         break;
00174                 case DT_GLOBAL:
00175                         assert(_vtype.type()==Type::T_WORD);
00176                         o.write2(_value);
00177                         o.write1(_valueIndex);
00178                         break;
00179                 default: assert(false);
00180         }
00181 }

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