[GCC-XML] Re: Using gccxml on a C file?

Brad King brad.king at kitware.com
Tue Jan 3 10:20:46 EST 2006


Tony Whitley wrote:
> I'm using gccxml to extract source file information from a C file but I get
> a variety of C++ errors like:
> 
>  error: ISO C++ forbids declaration of `...` with no type
> 
> and I'd rather not edit all the (header) files to make them C++ compatible.
> 
> I tried using
> 
>  set GCCXML_FLAGS=-x c
> 
> but that just produces the error
> 
>  gccxml_cc1plus.exe: error: unrecognized option `-x c'
> 
> Is there a way of making gccxml handle a plain C file?

No, because unlike "gcc" the "gccxml" front end always calls the GCC C++ 
parser (called gccxml_cc1plus instead of cc1plus).  The GCC-XML dump 
code is written in GCC/gcc/cp/xml.c inside the patched gcc tree, so it 
is C++-specific.

Your best option is to get xml.c to work with the GCC C compiler.  Look 
in the source tree under GCC/gcc/* for the C compiler files.  Also, in 
GCC/gcc/cp/semantics.c there is a call to do_xml_output inside the 
finish_translation_unit function.  This is the entry point for the C++ 
dump.  You'll have to find the equivalent place in the C compiler.  My 
guess at a quick glance is the finish_file function in c-lang.c.  Then 
you need to add a gccxml_cc1 executable that builds the C compiler files.

Once the C compiler is getting built then the GCC_XML/GXFront/* files 
will have to be modified to execute gccxml_cc1 instead of gccxml_cc1plus 
when a C file is given as input.

I might eventually get to making changes like this but I have no time 
right now.  You can submit a feature request here:

http://www.gccxml.org/Bug

If you make the changes yourself please go back in to the bug report and 
add information about them.

Good luck,
-Brad



More information about the gccxml mailing list