[GCC-XML] Encoding of init values

Thomas Heller theller at python.net
Fri Feb 18 14:01:20 EST 2005


Brad King <brad.king at kitware.com> writes:

> Thomas Heller wrote:
>> How does gccxml encode the init="..." value?
>> It seems to depend on the type of the value also - what are the rules?
>
> GCC has an internal function to convert an expression into a
> string. Whatever this function produces is what GCC-XML supports.  It
> is a minimal feature to provide some basic information since full
> expression dumping is not implemented.

I'm using it successfully to get enum values, and after three passes
over the source files with some template magic also for #define'd
symbols. Here's what I found out so far:

If the init value starts with a '0' character, it is a hex value.  If
the init value start with another digit, it's a decimal value.  If it
starts with ", it's a string.  If it starts with ', it's a character.
If the string *type* is 'wchar_t *', the init value seems to be a utf-16
encoded string, with an additional NUL byte appended:

(source file)
#define SERVICES_ACTIVE_DATABASEW      L"ServicesActive"

(xml output)
<Variable id="_5456"
 name="ACCESS_DS_SOURCE_W"
 type="_14999" init=""D\000S\000\000""
 context="_1" location="f0:4283" file="f0" line="4283"/>

Is this interpretation basically correct?

----------

While I have your attention, please allow another question.

(source file)
typedef void * HANDLE;
extern HANDLE GetModuleHandleA(HANDLE);

(xml file, stripped a bit for clarity)
<?xml version="1.0"?>
<GCC_XML cvs_revision="1.96">
  <Function id="_3" name="GetModuleHandleA"
returns="_5"
  context="_1" mangled="_Z16GetModuleHandleAPv" location="f0:3"
  file="f0" line="3" extern="1">
    <Argument type="_4"/>
  </Function>
  <PointerType id="_4" type="_6" size="32" align="32"/>
  <Typedef id="_5" name="HANDLE" type="_4" context="_1" location="f0:1" file="f0" line="1"/>
  <FundamentalType id="_6" name="void" align="8"/>
  <File id="f0" name="x.h"/>
</GCC_XML>

So, the xml file refers to HANDLE with id="_5", and to 'void *' with
id="_4".  So, it looks like the function would have been declared as

typedef void * HANDLE;
extern HANDLE GetModuleHandleA(void *);


Could this be fixed somehow?

Thanks,

Thomas




More information about the gccxml mailing list