Finding uses of functions with a TemplateType argument

David Nolden zwabel at googlemail.com
Tue Oct 20 10:00:44 UTC 2009


Am Dienstag 20 Oktober 2009 11:24:12 schrieb Bertjan Broeksema:
> On Monday 19 October 2009 16:35:13 David Nolden wrote:
> > Am Montag 19 Oktober 2009 13:03:16 schrieb Bertjan Broeksema:
> > > Hi All,
> > >
> > > Suppose I have:
> > >
> > > template <class type>
> > > class MyClass {
> > >   void blah(const type*);
> > > };
> > >
> > > Now I want to build a query which finds all uses of "blah(const type*)"
> > >
> > > When I arrive at the function declaration the argument does not seem to
> > >  have any hint that it actually is an template type. However, when I
> >
> > The argument-type should be a "KDevelop::DelayedType", which is used only
> > for template-dependent not-yet-resolved types, or for unresolved types.
> 
> I think this is the problem indeed. The parameter of the ArgumentType from
>  the declaration is an delayed type and the ArgumentType that comes out of
>  the evaluation parser is an CppTemplateParameterType type, which inherits
>  from Identified type. Thats why the comparison goes wrong. I wonder what
>  the best approach to make this work would be. Because to be able to
>  iterate over all instantiations I still need to find the right method
>  first.
It is DelayedType to make sure that the type is re-evaluated in possible 
instantiations.

> > >  evaluate the expression: "const type *" at that context it does seem
> > > to have an hint about the fact that it is an template type. I.e. I do:
> > >
> > > argType->toString()         => "const type* d" // From function
> > > declaration expectedType->toString() => "const <template> type*" //
> > > from query description
> > >
> > > I expected to have the one comming from the function declaration also
> > >  having a hint about being a template type. Moreover, I expect:
> > >
> > > argType.indexedType() == expectedType.indexedType()
> >
> > Not sure why it is not marked properly in that case, maybe it is falsely
> > marked as "unresolved" instead of "template"? (Both through
> > KDevelop::DelayedType)
> 
> See  my comment above, the ArgumentType of the declaration is a delayed
>  type but the result of the expression parser is the actual
>  CppTemplateParameterType (which seems correct to me, though I maybe
>  expected this CppTemplateParameter also in the function Declaration).
DelayedTypes are only created by the TypeBuilder to make sure that the type is 
re-evaluated in possible instantiations. If you evaluate the DelayedType in 
the non-instantiated context, then you should also have your 
CppTemplateParameterType, and then the comparison should succeed. I have no 
time to look at it, but there is functions to 'resolve' a DelayedType in 
"templatedeclaration.cpp".

> > > This might be a false assumption of me and another possibility might be
> > > to iterator over all instantiations of the particular function and find
> > > *their* uses.
> >
> > That should work.
> 
> Yeah, but as said before, only when you've first found the right function
> declarations to look up the instantiations for.

But if you have the "CppTemplateParameterType" then you had to take it from 
the function, so you also have the declaration, no?

Greetings, David




More information about the KDevelop-devel mailing list