[GCC-XML] Determining template parameter types

Adrian Taylor adrian at macrobug.com
Wed Aug 20 12:29:03 EDT 2008


Hi Chris,

The patch below is a hack which links back from the instantiated  
template function back to the original uninstantiated form. It doesn't  
attempt to describe the parameters of the instantiation, nor does it  
cope with intermediate instantiations/specializations/etc.

Obviously this only does 1% of what's required for a general solution  
- but it may help you to identify a few of the right macros and  
functions to use to put a proper solution in place. Good luck!

As Brad said, you'll find cp-tree.h useful, but also take a look at cp- 
tree.def.

Regards

Adrian

--
Adrian Taylor, Macrobug Ltd.
A company registered in England and Wales no 5892155, 352 Mill Road,  
Cambridge CB1 3NN
VAT reg. GB 892 4122 21. http://www.macrobug.com/




Index: GCC/gcc/cp/xml.c
===================================================================
--- GCC/gcc/cp/xml.c    (revision 2510)
+++ GCC/gcc/cp/xml.c    (working copy)
@@ -1079,6 +1079,24 @@
  }

  / 
*--------------------------------------------------------------------------*/
+/* Print XML attribute listing stating the original abstract version  
of this
+ * instantiated templated function.  */
+static void
+xml_print_template_attribute (xml_dump_info_p xdi, tree fd, int  
complete)
+{
+  tree ti = DECL_TEMPLATE_INFO (fd);
+  if(ti)
+    {
+    tree td = DECL_TEMPLATE_RESULT(most_general_template(fd));
+    if (td != fd)
+      {
+      int id = xml_add_node(xdi, td, complete);
+      fprintf (xdi->file, " template_origin=\"_%d\"", id);
+      }
+    }
+}
+
+/ 
*--------------------------------------------------------------------------*/
  /* Print XML attribute listing types that this type can throw.  */
  static void
  xml_print_throw_attribute (xml_dump_info_p xdi, tree ft, int complete)
@@ -1660,6 +1678,7 @@
    if(do_virtual) xml_print_virtual_method_attributes (xdi, fd);
    if(do_static)  xml_print_static_method_attribute (xdi, fd);
    if(do_artificial)  xml_print_artificial_attribute (xdi, fd);
+  xml_print_template_attribute (xdi, fd, dn->complete);
    xml_print_throw_attribute (xdi, TREE_TYPE (fd), dn->complete);
    xml_print_context_attribute (xdi, fd);
    xml_print_mangled_attribute (xdi, fd);


On 16 Aug 2008, at 17:08, Chris Waldron wrote:

> Brad,
>
>  I'm interested in at least taking a look at the effort required to
> implement this feature.  Can you point me in the right direction?
>
> Thanks,
> Chris
>
> -----Original Message-----
> From: Brad King [mailto:brad.king at kitware.com]
> Sent: Monday, August 04, 2008 10:49 AM
> To: Chris Waldron
> Cc: Roman Yakovenko; gccxml
> Subject: Re: [GCC-XML] Determining template parameter types
>
> Chris Waldron wrote:
>> Thanks for the tip and you have what looks like cool tool.  However
> I've
>> written my own tool to scan the resultant XML because I have a
> specific
>> requirement.  I could detemine the type from parsing the template
>> parameters and matching the type names.  However since GCC_XML
> contains
>> the information, it should export it on the Class element.  Also
> having
>> the additional attribute will help to rapidly identify template class
>> definitons.
>
> There are two reasons I've held off doing this:
>
> 1.)  The real solution is to have full dumping of uninstantiated
> templates.  Specification of arguments used for instantiation should  
> be
> in a form that references the template and then lists references to  
> the
> arguments.
>
> 2.)  The project that funds gccxml development doesn't need it.
>
> If anyone wants to contribute support for templates I can help get you
> started.
>
> -Brad
>
>> -----Original Message-----
>> From: Roman Yakovenko [mailto:roman.yakovenko at gmail.com]
>> Sent: Saturday, August 02, 2008 10:07 AM
>> To: Chris Waldron
>> Cc: gccxml
>> Subject: Re: [GCC-XML] Determining template parameter types
>>
>> On Sat, Aug 2, 2008 at 7:09 PM, Chris Waldron  
>> <cwaldron at intrinsyc.com>
>> wrote:
>>> As a feature request, it would nice if template parameter types can
> be
>> added
>>> as an attribute of the Class Element. For example:
>>> template <typename P1, typename P2> TemplateClass {
>>>
>>>
>>>
>>> };
>>>
>>>
>>>
>>> class TemplateClass<void, int>
>>>
>>> {
>>>
>>>
>>>
>>> };
>>>
>>>
>>>
>>>
>>>
>>> <Class id="_10" name="TemplateClass&lt;void,int*&gt;" members="_23
> _25
>> _26
>>> _27 _28 _29 _30 " bases="_21 _24 " tparams="_20 _21">
>>>
>>>    <Base type="_21" access="public" virtual="0" offset="12"/>
>>>
>>>    <Base type="_24" access="public" virtual="0" offset="0"/>
> </Class>
>>>
>>>
>>>
>>> The tparams attribute indicates the template parameter types defined
>> on the
>>> class.  I cannot seem to find an easy way of determining the  
>>> template
>>> parameter types from the XML output.
>>
>> pygccxml does it right, in most cases:
>>
> http://www.language-binding.net/pygccxml/apidocs/pygccxml.declarations.t
>> emplates-module.html
>>
>
> _______________________________________________
> gccxml mailing list
> gccxml at gccxml.org
> http://www.gccxml.org/mailman/listinfo/gccxml



More information about the gccxml mailing list