Getting more info about function calls.

Bertjan Broeksema bertjan at kdab.net
Mon Oct 26 09:47:36 UTC 2009


On Friday 23 October 2009 17:17:20 Milian Wolff wrote:
> On Friday, 23. October 2009 16:08:24 Bertjan Broeksema wrote:
> > Hi all,
> >
> > I'd like to do the following.
> >
> > Given the use of a function, how can I get the following information:
> >
> > * The range of the function name of the specific call.
>
> The Use-Range should be the function name in the call.

No, in most cases it seems to be the range of the opening paren of the 
function.

> > * The range of the accessor (in case of a non-global method  or calls on
> >  this)
> >
> >  * The range of the expression on which the method is called (in case
> >  of non global methods or calls on this)
>
> You'll have to use a tokenizer or something there afaik. I don't think such
> access is in the DUChain API so far. A candidate maybe?

I hope so, but I could use some help on this to get started. My first idea was 
when looking at the the code that m_lastInstance in duchainbuilder referred to 
the instance on which the methods is called but this doesn't seem to be the 
case. Any Ideas how to keep track of the objects on which methods are called?

> > I have the idea that non of this information is currently accessible
> > given the use of a function (i.e. one of the SimpleRange objects returned
> > by ClassFunctionDeclaration::uses() or FunctionDeclaration::uses()). I
> > think this needs work in the DUChain builder but I dont' understand it
> > well enough yet.
> >
> > My idea would be to add a new structure FunctionCall, which will be
> > stored in the DUChain and contain the above information. In addition it
> > could also store a pointer to the declaration of the this object (i.e.
> > the object on which it is called) in case of non global functions. Any
> > suggestions on how to implement this would be more than welcome. If you
> > think this is an useful addition for KDevelop in general I'd of course be
> > more than happy to add it to the (cpp)duchain directly.
> >
> > By the way, the use case is this: In my transform language i'd like to
> >  provide access to different parts of a call.
> >
> > before transform:
> > Class *obj2 = (Class*)someObj->child("name", "Class");
> > Class *obj3 = (Class*)child("name", "Class");
> >
> > After transform:
> > Class *obj2 = (Class*)qFindChild<Class>(someObj, "name");
> > Class *obj3 = (Class*)qFindChild<Class>("name", "Class");
> >
> > Rule:
> > <action type="Replace" item="*">
> > qFindChild<${literalVal(MemberArg[1])}>(${Object},${MemberArg[0]})
> > </action>
> >
> > Cheers,
> >
> > Bertjan





More information about the KDevelop-devel mailing list