Getting more info about function calls.

David Nolden zwabel at googlemail.com
Mon Oct 26 16:54:37 UTC 2009


Am Montag 26 Oktober 2009 10:47:36 schrieb Bertjan Broeksema:
> 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.
No. That is only the case for constructors, where the range of the name is a 
use of the class-name.

> > > * 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?
Hmm, m_lastInstance _should_ contain that information, but since the exact 
object a function is called on was never required until now, it may be that 
m_lastInstance contains only the 'true' or 'false' information in some cases.

> > > 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.

Isn't all that information available through the mapping between uses and the 
AST? For each use, you can get the AST, and from the AST you can 'jump' to all 
the related information, related uses, declarations, etc.

The only possible problem for this might be that it's not possible to jump to 
the 'parent' in the AST, I guess we need a 'parent' member there.

> > > 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>
That's too complicated for me right now. ;-)

Greetings, David




More information about the KDevelop-devel mailing list