T
Thomas Heller
I need to convert C preprocessor definitions into python code. The
definitions are dumped out of gccxml (see http://www.gccxml.org) ,
running over the windows header files (for example).
This creates output like this (some excerpts):
#define DATABITS_8 ((WORD)0x0008)
#define KEY_WRITE ((STANDARD_RIGHTS_WRITE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY) & (~SYNCHRONIZE))
#define MS_NBF "MNBF"
#define PSN_FIRST (0U-200U)
#define RT_ANIICON MAKEINTRESOURCE(22)
#define STG_E_FILENOTFOUND _HRESULT_TYPEDEF_(0x80030002L)
I thought I be clever, and I wrote a couple of overloaded function to
dump out the definitions in Python syntax:
void dump(char *name, LPSTR value)
{
int a = (int)(void *)value;
if ((a & 0xFFFF0000) == 0)
cout << name << " = " << "LPSTR(" << a << ")" << endl;
else
cout << name << " = " << "r\"\"\"" << value << "\"\"\"" << endl;
}
void dump(char *name, int value)
{ cout << name << " = " << value << endl; }
void dump(char *name, unsigned int value)
{ cout << name << " = " << value << endl; }
#define DUMP(sym) dump(#sym, sym)
Now I can create a small program to dump out the definitions, compile it
and call it:
int main (int argc, char **argv)
{
DUMP(DATABITS_8);
DUMP(KEY_WRITE);
DUMP(MS_NBF);
DUMP(PSN_FIRST);
DUMP(RT_ANIICON);
DUMP(STG_E_FILENOTFOUND);
}
This works pretty well, and creates this output:
DATABITS_8 = 8
KEY_WRITE = 131078
MS_NBF = r"""MNBF"""
PSN_FIRST = 4294967096
RT_ANIICON = LPSTR(22)
STG_E_FILENOTFOUND = -2147287038
What I'm wondering now is: Is it possible to do the same with templates,
so that it isn't needed to compile and run the program? gccxml is the
parsing engine of GCC, which spits out the parsing result in xml format,
apparently after templates have been expanded (don't know if that's the
correct term).
As far as I have learned so far (I'm an experienced C programmer, but
not a c++ one) templates can only be invoked and specialized with types,
but not with the types of values. So, is this impossible?
Cheers,
Thomas
definitions are dumped out of gccxml (see http://www.gccxml.org) ,
running over the windows header files (for example).
This creates output like this (some excerpts):
#define DATABITS_8 ((WORD)0x0008)
#define KEY_WRITE ((STANDARD_RIGHTS_WRITE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY) & (~SYNCHRONIZE))
#define MS_NBF "MNBF"
#define PSN_FIRST (0U-200U)
#define RT_ANIICON MAKEINTRESOURCE(22)
#define STG_E_FILENOTFOUND _HRESULT_TYPEDEF_(0x80030002L)
I thought I be clever, and I wrote a couple of overloaded function to
dump out the definitions in Python syntax:
void dump(char *name, LPSTR value)
{
int a = (int)(void *)value;
if ((a & 0xFFFF0000) == 0)
cout << name << " = " << "LPSTR(" << a << ")" << endl;
else
cout << name << " = " << "r\"\"\"" << value << "\"\"\"" << endl;
}
void dump(char *name, int value)
{ cout << name << " = " << value << endl; }
void dump(char *name, unsigned int value)
{ cout << name << " = " << value << endl; }
#define DUMP(sym) dump(#sym, sym)
Now I can create a small program to dump out the definitions, compile it
and call it:
int main (int argc, char **argv)
{
DUMP(DATABITS_8);
DUMP(KEY_WRITE);
DUMP(MS_NBF);
DUMP(PSN_FIRST);
DUMP(RT_ANIICON);
DUMP(STG_E_FILENOTFOUND);
}
This works pretty well, and creates this output:
DATABITS_8 = 8
KEY_WRITE = 131078
MS_NBF = r"""MNBF"""
PSN_FIRST = 4294967096
RT_ANIICON = LPSTR(22)
STG_E_FILENOTFOUND = -2147287038
What I'm wondering now is: Is it possible to do the same with templates,
so that it isn't needed to compile and run the program? gccxml is the
parsing engine of GCC, which spits out the parsing result in xml format,
apparently after templates have been expanded (don't know if that's the
correct term).
As far as I have learned so far (I'm an experienced C programmer, but
not a c++ one) templates can only be invoked and specialized with types,
but not with the types of values. So, is this impossible?
Cheers,
Thomas