[GCC-XML]Including typedefs in the type graph.
Paul Ross
gccxml at paulross.demon.co.uk
Sun Oct 26 07:06:49 EST 2003
I am using gccxml (great product by the way!) for an API
documentation project and I was wondering whether it was possible to
include typedef information in the graph that resolves type
information. For example in this code:
#ifdef BIT16
typedef long INT32;
#else
typedef int INT32;
#endif
void Foo(INT32 i);
Naturally enough the argument to Foo() is int or long depending on
BIT16 but documenting it as such is really documenting an
_implementation_ of the API rather than the API itself. For one thing
this makes finding API differences between releases problematic.
The gccxml output (fragment) is something like:
<Function id="_3" name="Foo" returns="_6" context="_1"
location="f0:10" extern="1">
<Argument type="_4"/>
</Function>
<FundamentalType id="_4" name="long int"/>
<Typedef id="_5" name="INT32" type="_4" context="_1" location="f0:5"/>
Where id _4 is int or long int. If the typedef was included in the
type graph then the function argument reference would be "_5" that
would then resolve to _4. So when resolving the type you could either
stop at the first typedef or continue to the end of the chain for the
actual type. It seems that this would add useful information to
gccxml without detracting anything.
I finally got this working and seems to be fine on the tests I have
run. If you have typedefs to other typedefs or mixed
pointer/references it seems to chain them all together as the correct
graph.
It requires the following changes in xml.c (the diff for $Revision:
1.61 $ is in the postscript):
In: both xml_print_type_attribute() and xml_print_returns_attribute()
Remove:
int id = xml_add_node (xdi, TYPE_MAIN_VARIANT(t), complete);
And replace it with:
int id = 0;
if (TYPE_NAME(t)) {
if (DECL_ORIGINAL_TYPE (TYPE_NAME (t))) {
id = xml_add_node (xdi, TYPE_NAME(t), complete);
} else {
id = xml_add_node (xdi, TYPE_MAIN_VARIANT(t), complete);
}
} else {
id = xml_add_node (xdi, TYPE_MAIN_VARIANT(t), complete);
}
In: xml_output_var_decl ()
Remove:
if(TYPE_NAME (type) && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
Cheers,
Paul Ross
diff for xml.c $Revision: 1.61 $:
paul% diff -u xml.c xml_typedef.c
--- xml.c Sun Oct 5 14:15:08 2003
+++ xml_typedef.c Sun Oct 26 10:48:10 2003
@@ -501,7 +501,19 @@
const char* ch_const = "";
const char* ch_volatile = "";
const char* ch_restrict = "";
- int id = xml_add_node (xdi, TYPE_MAIN_VARIANT(t), complete);
+ //#
+ int id = 0;
+ if (TYPE_NAME(t)) {
+ if (DECL_ORIGINAL_TYPE (TYPE_NAME (t))) {
+ id = xml_add_node (xdi, TYPE_NAME(t), complete);
+ } else {
+ id = xml_add_node (xdi, TYPE_MAIN_VARIANT(t), complete);
+ }
+ } else {
+ id = xml_add_node (xdi, TYPE_MAIN_VARIANT(t), complete);
+ }
+ //#
+ //int id = xml_add_node (xdi, TYPE_MAIN_VARIANT(t), complete);
if (CP_TYPE_CONST_P (t)) { ch_const = "c"; }
if (CP_TYPE_VOLATILE_P (t)) { ch_volatile = "v"; }
if (CP_TYPE_RESTRICT_P (t)) { ch_restrict = "r"; }
@@ -516,7 +528,19 @@
const char* ch_const = "";
const char* ch_volatile = "";
const char* ch_restrict = "";
- int id = xml_add_node (xdi, TYPE_MAIN_VARIANT(t), complete);
+ //#
+ int id = 0;
+ if (TYPE_NAME(t)) {
+ if (DECL_ORIGINAL_TYPE (TYPE_NAME (t))) {
+ id = xml_add_node (xdi, TYPE_NAME(t), complete);
+ } else {
+ id = xml_add_node (xdi, TYPE_MAIN_VARIANT(t), complete);
+ }
+ } else {
+ id = xml_add_node (xdi, TYPE_MAIN_VARIANT(t), complete);
+ }
+ //#
+ //int id = xml_add_node (xdi, TYPE_MAIN_VARIANT(t), complete);
if (CP_TYPE_CONST_P (t)) { ch_const = "c"; }
if (CP_TYPE_VOLATILE_P (t)) { ch_volatile = "v"; }
if (CP_TYPE_RESTRICT_P (t)) { ch_restrict = "r"; }
@@ -1075,8 +1099,6 @@
fprintf (xdi->file, " <Variable");
xml_print_id_attribute (xdi, dn);
xml_print_name_attribute (xdi, DECL_NAME (vd));
- if(TYPE_NAME (type) && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
- type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
xml_print_type_attribute (xdi, type, dn->complete);
xml_print_init_attribute (xdi, DECL_INITIAL (vd));
xml_print_context_attribute (xdi, vd);
More information about the gccxml
mailing list