Finding uses of functions with a TemplateType argument
Bertjan Broeksema
bertjan at kdab.net
Tue Oct 20 10:59:19 UTC 2009
On Tuesday 20 October 2009 12:00:44 David Nolden wrote:
> 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?
The CppTemplateParamaterType is the result of the ExpressionParser evaluating
"const T *" in the right context. I also have the declaration of the function
and retrieve the argument type of it by
functionDecl->internalFunctionContext()->localDeclarations().at(i)
The latter, however seems to be evaluated to a normal type (i.e. in this case
a pointer type pointing to a const T). This is the first thing that doesn't
look okay to me. I'll try to have a look at it to see where it goes wrong.
What I expect is that it should resolve to "const <template> T *", correct me
if I'm wrong on this.
The second thing is the following:
template <class T>
class Test
{
public:
void contains(const T *t) {}
template<class X>
void contains(X x) {}
};
When resolving the Identifier of X I get QPtrList::X, when putting that into an
expression like:
"const Test::X *x" the expression parser gives an error about not being able
to resolve X. This might be me giving the wrong context to the parser, the
possibility that Test::X is just wrong or that the expression parser doesn't
work as expected. I'm expecting the second. I don't think that the template
parameter is dependent on the place where it is defined.
> Greetings, David
>
> --
> KDevelop-devel mailing list
> KDevelop-devel at kdevelop.org
> https://barney.cs.uni-potsdam.de/mailman/listinfo/kdevelop-devel
More information about the KDevelop-devel
mailing list