Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] how do I know where a call will link?

I don't get it, name.getTranslationUnit() will return the tu of the c file currently being parsed which is the file containing the call, the actual function won't show up in that AST as I understand..
So the question then is.. do I have to manually have to keep track of all c file's ASTs and what functions they contain (an own linker class...) or does CDT have link information where I provide caller FileLocation(IFile, functionName) and get back another FileLocation containing the actual function?

2008/11/25 Dmitry Smirnov <divis1969@xxxxxxxxx>
I would try

name.getTranslationUnit().getDefinitions(binding) or

The binding is the binding of the 'foo'.
It can be retrievied this way:
IASTExpression nameExpression =
IASTName astName = null;
if( nameExpression != null && nameExpression instanceof IASTIdExpression )
 astName = ((IASTIdExpression)nameExpression).getName();

or with Visitor pattern.


2008/11/25 Jimmie Eriksson <eriksson.jimmie@xxxxxxxxx>:
> If I'm at a IASTFunctionCallExpression in an ASTVisitor, how do I determine
> the function it will be linked to?
> //-----
> file:main.c // the file being ASTvisited
> #include "a.h"
> #include "b.h"
> void main() {
>     foo();    // IASTFunctionCallExpression, (that should be linked to foo()
> in a.c)
> }
> //-----
> file:a.c
> void foo() { // link here...
> }
> //-----
> file:b.c
> static void foo() { // do not link here... as it is static (which means
> invisible..)
> }
> //-----
> The natural way would of course be to check all included files (in the c
> file being visited) and their counterpart .c file for a matching function.
> But I suspect that CDT already have the information available somewhere near
> the IASTFunctionCallExpression? can I somehow use the IASTName below a
> IASTFunctionCallExpression name.resolveBinding(); name.getBinding(); or the
> getScope() ? .. or how do I know where the call will link?
> /Jimmie
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
cdt-dev mailing list

Back to the top