Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members

decodetype.cc

Go to the documentation of this file.
00001 /*--------------------------------------------------------------------
00002  *
00003  * (C) Copyright Koninklijke Philips Electronics NV 2006. 
00004  * All rights reserved. This software is licensed under the terms of
00005  * version 2.1 of the GNU Lesser General Public License as published 
00006  * by the Free Software Foundation. For licensing and warranty
00007  * information, see the file COPYING in the main directory.
00008  *
00009  *------------------------------------------------------------------*/
00010 
00011 #include "decodetype.h"
00012 
00013 /*
00014  * For gcc decoding see
00015  * http://www.delorie.com/gnu/docs/gcc/gxxint_15.html
00016 */
00017 
00018 #ifdef __GNUC__
00019 
00020 #include <assert.h>
00021 #include <ctype.h>
00022 #include <stdio.h>
00023 #include <string>
00024 #include <iostream>
00025 
00026 using std::string;
00027 using std::cout;
00028 using std::cerr;
00029 using std::endl;
00030 
00031 static char *in;
00032 static char out[256];
00033 
00034 string scanType();
00035 
00036 char scanChar()
00037 {
00038   return *in++;
00039 }
00040 
00041 void unScanChar()
00042 {
00043   in--;
00044 }
00045 
00046 unsigned int scanInt()
00047 {
00048   char c;
00049   unsigned int l = 0;
00050   while (isdigit(c = scanChar()))
00051     l = l*10 + c - '0';
00052   unScanChar();
00053   return l;
00054 }
00055 
00056 string scanName()
00057 { 
00058   string r;
00059   unsigned int l = scanInt();
00060   for (unsigned int i=0; i<l; i++)
00061     r += scanChar();
00062 
00063   // new template format (g++ 3.0.*)
00064   char c = scanChar();
00065   if (c == 'I') {
00066     // new
00067     r += "< ";
00068     unsigned int n = 0;
00069     while ((c = scanChar()) != 'E')
00070     {
00071       unScanChar();
00072       if (n != 0)
00073         r += ", ";
00074       r += scanType();
00075       n++;
00076     }
00077     r += " >";
00078   } else {
00079     unScanChar();
00080   }
00081   return r;
00082 }
00083 
00084 string itoa(unsigned int i)
00085 {
00086   char buf[32];
00087   sprintf(buf, "%d", i);
00088   return buf;
00089 }
00090 
00091 string scanArray()
00092 {
00093   unsigned int l = scanInt();
00094   char c = scanChar(); 
00095   assert(c = '_');
00096   string t = scanType();
00097   return t + '[' + itoa(l) + ']';
00098 }
00099 
00100 string scanTemplate()
00101 {
00102   // old template format (g++ 2.95.*)
00103   string r = scanName();
00104   unsigned int n = scanInt();
00105   r += "< ";
00106   for (unsigned int i=0; i<n; i++)
00107   {
00108     assert(scanChar() == 'Z');
00109     r += scanType();
00110     if (i == n-1)
00111       r += " >";
00112     else
00113       r += ", ";
00114   }
00115   return r;
00116 }
00117 
00118 string scanType()
00119 {
00120   switch(scanChar())
00121   {
00122   case 'b': return "bool";
00123   case 'c': return "char";
00124   case 's': return "short";
00125   case 'i': return "int";
00126   case 'l': return "long";
00127   case 'f': return "float";
00128   case 'd': return "double";
00129   case 'v': return "void";
00130   case 'h': return "unsigned char";
00131   case 'j': return "unsigned int";
00132   case 'x': return "long long";
00133   case 'w': return "wchar_t";
00134   case 'J': return "complex";
00135   case 'C': 
00136   case 'K': 
00137     return "const " + scanType();
00138   case 'U': 
00139     return "unsigned " + scanType();
00140   case 'S':
00141     return "signed " + scanType();
00142   case 'P':
00143     return scanType() + "*";
00144   case 'R':
00145     return scanType() + "&";
00146   case 't':
00147 #if (__GNUC__ >= 3)
00148     return "unsigned short";
00149 #else
00150     return scanTemplate();
00151 #endif
00152   case 'A':
00153     return scanArray();
00154 
00155   case '0':
00156   case '1':
00157   case '2':
00158   case '3':
00159   case '4':
00160   case '5':
00161   case '6':
00162   case '7':
00163   case '8':
00164   case '9':
00165     unScanChar();
00166     return scanName();
00167 
00168   default:
00169     unScanChar();
00170     cerr << "Cannot decode type " << in << endl;
00171     return "?";
00172   }
00173 }
00174 
00175 char* decodeType(const char* n)
00176 {
00177   in = (char*)n;
00178   // cout << in << endl;
00179   string r = scanType();
00180   strncpy(out, r.c_str(), r.size());
00181   out[r.size()] = '\0';
00182   return out;
00183 }
00184 
00185 #else
00186 
00187 char* decodeType(const char* n)
00188 {
00189   return (char*)n;
00190 }
00191 
00192 #endif

Generated on Wed Feb 15 14:52:38 2006 for yapi by doxygen 1.3.2