Template class Uses.

David Nolden zwabel at googlemail.com
Wed Oct 7 15:17:38 UTC 2009


Am Mittwoch 07 Oktober 2009 13:55:02 schrieb Bertjan Broeksema:
> Hi all,
> 
> I've this simple piece of code:
> 
> --- begin ---
> template <class T> class Test
> { };
> 
> int main()
> {
>   Test<float> floatTest;
>   Test<int> intTest;
>   return 0;
> }
> --- end ---
> 
> Renaming Test at line one in KDevelop doesn't result in renaming of the
> instantiations. Some small test I tried locally seems to show that there
>  are no uses coupled to declarations of template classes. However when
>  hovering over the Test<float> declaration I can see where it is declared
>  so there seems to be *some* link between template instantiations and the
>  declarations.
That thing is not implemented right now, but would be trivial to do, as the 
information is there. The only problem is that the information is within the 
"cppduchain" module.

Take a look at "TemplateDeclaration", it can return you all instantiations, 
and also the opposite direction (instantiations() and instantiatedFrom()).

What happens is that whenever a template is instantiated, the whole 
declaration, contexts, etc. are completely copied, and it becomes an own 
Declaration object, that is linked to the template class through the mentioned 
functions.

For contexts, the same functions are available within 
CppDUContext<DUChontext>.

But note that template instantiations are not stored to disk, they are created 
on-demand, so instantiations() only returns those that are currently in 
memory. That is basically everything that has been parsed recently and/or is 
included into one of the currently open files.

Greetings, David




More information about the KDevelop-devel mailing list