Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Mapping a name to include statement

Hi Markus,

I supposed that usage of AST could give me more accurate results.

For example, some name (type or a function) must be defined or
declared in the unit or inside its includes.
Moreover, it should be defined/declared only once otherwise compiler
will claim for this.
With the Index I could get the declarations that are not valid in the
unit I'm parsing.

As for the mapping declaration to a multiply include statement, it is
unclear for me.
Perhaps, this will be true for index-based search, but should not be
true for AST: in include dependency tree, I've seen that some includes
are empty because of include guards (#ifndef MY_HEADER \n #define
MY_HEADER). So, I think there should be a way to map a declaration to
the top-level include.

I just cannot figure out how to map some name to the top-level include
statement.
Obviuos way is to get ASTNode.getContainingFilename() and search for
it in the dependency tree.
Perhaps, there could be simplier ways?

Dmitry


2008/10/31 Schorn, Markus <Markus.Schorn@xxxxxxxxxxxxx>:
> A short note on the problem you defined:
> - a reference in a source-file may be declared multiple times, so there
> is
>  no mapping from references to a declaration, however each reference
> has
>  a list of declarations.
> - a header file indirectly included can be included via different paths
> through
>  the graph of inclusions. So you cannot map a declaration to a single
> inclusion
>  statement, however each declaration can be associated with a list of
> inclusion-
>  statements.
>
> For this sort of analysis you could purly rely on the index, you can
> follow the
> include-hierarchy and you can find all declarations for a reference.
> Here is
> what you need:
> * IIndex.findIncludes(IIndexFile)
> * IIndex.findBinding(IName)
> * IIndex.findNames(IBinding)
> * IIndexName.getFile()
>
> Markus.
>
>> -----Original Message-----
>> From: cdt-dev-bounces@xxxxxxxxxxx
>> [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Dmitry Smirnov
>> Sent: Thursday, October 30, 2008 4:57 PM
>> To: CDT General developers list.
>> Subject: [cdt-dev] Mapping a name to include statement
>> Importance: Low
>>
>> Hi,
>>
>> I need to perform some analisys of inclusions in C files.
>> Particulary, I need to find out whether any declaration or
>> definition of top-level included file (or its sub-includes)
>> is used in the translation unit.
>>
>> What is the best way for this?
>>
>> I'm going to visit all the names in the root translation
>> unit, find all the declarations and definitions of this name (with
>> getDeclarationsInAST()) and check whether these declarations
>> are from includes.
>>
>> The last step is something unclear for me.
>> How can figure out that some name is declared/defined in the
>> context of top-level include?
>>
>> Some small example (in case my description was unclear)
>> test.h:
>> ------------------
>> int value;
>>
>> test2.h
>> -----------------------
>> #include "test.h"
>>
>> test.c
>> ---------------------------
>>
>> int main()
>> {
>>   value = 10;
>> }
>>
>> I need to figure out that 'value' was defined in context of
>> test2.h inclusion.
>>
>> Dmitry
>> _______________________________________________
>> 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