Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Doubts regarding indexer and parsing of source file


Hi.

Please read inline, hope it helps!

regards,
Pavan


From: Nayna Jain/India/IBM@IBMIN
To: cdt-dev@xxxxxxxxxxx
Date: 07/04/09 02:26 PM
Subject: [cdt-dev] Doubts regarding indexer and parsing of source file





Hi all,

I have the following questions :-

#1. Given a class ICPPClassType how to get the header file where it is
defined ?
#2. Given a function IFunction, how to get which header file it is defined
or declared ?
#3. Given a FunctionDeclarator, how to find whether it is only a
declaration or definition or both ?

the getParent call on a FunctionDeclarator returns a IASTSimpleDeclaration for a declaration
and IASTFunctionDefinition for a definition


#4. How to index the specific file or set of files programmatically ?
Did you try calling CCorePlugin.getIndexManager.update(<ICElement>, <Flag>) ?
#1 : if your file is indexed, findDeclarations()/findDefinitions on the index should help you get the file name.
#2 : call getClassOwner and do #1 to get where the function is declared -
am not sure about how you'd get the definition file info out of the binding though!

To give more details on how I actually tried, following is the scenario
given :-

I need to parse C++ SourceFiles or Header files.

I started with getting dom using

CDOM dom = CDOM.getInstance() .

Then,  IASTTranslationUnit tu = dom.getTranslationUnit(new
FileStorage(fileName) , project).

And then using visitor pattern I started parsing this translation unit .
i.e. making shouldVisitDeclarations and shouldVisitDeclSpecifiers = true
and then giving tu.accept().

Till this it was OK.

But then for class methods defined in .C file I wanted to get its header
file. And I also wanted header for SuperClasses of this class.

>From IFunction, ICPPMethod and ICPPClassType I couldn't get anything.

So, I thought that AST doesn't contain any information for binding
locations.

And so I moved to Indexer.

However if the source file is copied into workspace from some other place
then that file is not indexed and so IIndex.findNames() or
findDefinitions() or findDeclarations() also didn't return anything.

So, I realized that the file is not indexed so it won't have information.

So, I tried

IIndexManager.reindex() method or IIndexManager.update(cProject,
IIndexManager.UPDATE_ALL) as I wanted to index all  the files whether they
are modified or not.

But that didn't seem to work for me. i am still not knowing why it didn't
work.

Finally I thought of doing indexing via WritablePDOM. And so used

WritablePDOM.acquireWriteLock()
WritablePDOM.addBinding(binding);
WritablePDOM.releaseWriteLock().

But then sometimes it works and sometimes it doesn't and gives all sort of
surprising exceptions which I couldn't understand. Moreover they are
internal APIs which actually I don't want to use for my project.

Your answers will be of great help.

Thanks & Regards,
     - Nayna Jain

_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev



Back to the top