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?

Have you tried getDefinitions()? This method should try to find a
definition in any file that was indexed.
So, to find a definition you need
1. Index a project
2. Create an AST translation unit like this (through CoreModelUtil's
methods. This way AST will use project index):
			ITranslationUnit unit =
CoreModelUtil.findTranslationUnitForLocation(indexFileLocation, null);
			if( unit != null )
			{
				itu = unit.getAST(index, ITranslationUnit.AST_SKIP_INDEXED_HEADERS);
			}

Alternatively, you can use IIndex directly.

Dmitry

2008/11/25 Jimmie Eriksson <eriksson.jimmie@xxxxxxxxx>:
> 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?
> /Jimmie
>
> 2008/11/25 Dmitry Smirnov <divis1969@xxxxxxxxx>
>>
>> I would try
>>
>> name.getTranslationUnit().getDefinitions(binding) or
>> name.getTranslationUnit().getDefinitionsInAST(binding).
>>
>> The binding is the binding of the 'foo'.
>> It can be retrievied this way:
>> IASTExpression nameExpression =
>> functionCallExpression.getFunctionNameExpression();
>> IASTName astName = null;
>> if( nameExpression != null && nameExpression instanceof IASTIdExpression )
>> {
>>  astName = ((IASTIdExpression)nameExpression).getName();
>> }
>>
>> or with Visitor pattern.
>>
>> Dmitry
>>
>> 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
>> > https://dev.eclipse.org/mailman/listinfo/cdt-dev
>> >
>> >
>> _______________________________________________
>> cdt-dev mailing list
>> cdt-dev@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/cdt-dev
>
>
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/cdt-dev
>
>


Back to the top