[GCC-XML]Templated methods questions

Brad King brad.king at kitware.com
Fri Mar 12 13:02:15 EST 2004


Pere Mato Vila wrote:

>   I have a couple of questions concerning the generated information for
> templated methods. If I have class as following one with some explicit
> member function template instantiations
> 
> class TMethods {
>   public:
>     template <class T> T get() const { return T(); }
>     template <class T> void set(const T& d) { }
> };
> 
> template int    TMethods::get<int>() const;
> template float  TMethods::get<float>() const;
> template void   TMethods::set(const int&);
> 
> I obtain with gccxml (0.6.0) the following:
> 
> ...
> <Class id="_3" name="TMethods" context="_1" mangled="8TMethods"
> location="f0:2" file="f0" line="2" members="_4 _5 " bases=""/>
> ...
> <Method id="_6" name="get" returns="_10" const="1" context="_3"
> mangled="_ZNK8TMethods3getIfEET_v" location="f0:4" file="f0" line="4"
> endline="4"/>
> <Method id="_7" name="get" returns="_11" const="1" context="_3"
> mangled="_ZNK8TMethods3getIiEET_v" location="f0:4" file="f0" line="4"
> endline="4"/>
> <Method id="_8" name="set" returns="_12" context="_3"
> mangled="_ZN8TMethods3setIiEEvRKT_" location="f0:5" file="f0" line="5"
> endline="5">
>     <Argument name="d" type="_13"/>
> </Method>
> ...
> 
> The questions are:
>  - Why Methods _6 _7 _8 are not members of Class _3 ? Note that the
> reverse relation ( via Context )is true.

Member templates are not included in the member list due to trouble 
during the implementation.  Recovering the information at the right time 
from GCC's internal representation is very hard, and I have no time to 
implement it.  The only safe way to get all the members is to look for 
elements with the context set correctly.  I've been meaning to remove 
the members attribute altogether due to this problem and the fact that 
it is duplicate information anyway.

>  - The name of the method _6 and _7 is "get" in both cases, but in C++
> the names are in fact "get<int>" and "get<float>". Is there a way to
> obtain the real C++ name? 

The name of the method template is "get" and in the case of deduced 
argument types it can be called with just "get".  When dumping of 
uninstantiated templates is implemented, then the method will have an 
attribute like "instantiates" that points at the original template and 
somehow references the template arugments used for the instantiation. 
The string "get<int>" is not enough to recover the argument types used 
in all cases.  Until this is done I do not think there is a way to get 
the information.

-Brad




More information about the gccxml mailing list