Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » CDT Model Parsing ...
CDT Model Parsing ... [message #201273] Mon, 10 September 2007 06:27 Go to next message
Eclipse UserFriend
Hi

We have started to work on CDT and our motive is to provide a C File and
programmatically parse through the CDT created Model and dump the
information into a XML File.

We did manage to get a handle to parse and retrieve the ITranslationUnit
of the corresponding C File. Now when we get the functions in that
translation unit we are not able to retrieve the variables or statements
defined under that function.

It just seems to have a method called as getSource which retrieves the
code as String but no getChildren method to retrieve the ICElement inside
the IFunction.

We realised little later that there is something called as CDOM also that
generates the ASTTranslationUnit. But this also seems of no use as we are
not able to get anything more than the includeDirectives.

Can anyone help pls ... ?

regards
Annamalai
Re: CDT Model Parsing ... [message #201290 is a reply to message #201273] Mon, 10 September 2007 08:54 Go to previous messageGo to next message
Eclipse UserFriend
Annamalai wrote:
> Hi
>
> We have started to work on CDT and our motive is to provide a C File and
> programmatically parse through the CDT created Model and dump the
> information into a XML File.
>
> We did manage to get a handle to parse and retrieve the ITranslationUnit
> of the corresponding C File. Now when we get the functions in that
> translation unit we are not able to retrieve the variables or statements
> defined under that function.
>
> It just seems to have a method called as getSource which retrieves the
> code as String but no getChildren method to retrieve the ICElement
> inside the IFunction.
>
> We realised little later that there is something called as CDOM also
> that generates the ASTTranslationUnit. But this also seems of no use as
> we are not able to get anything more than the includeDirectives.
>
> Can anyone help pls ... ?
>
> regards
> Annamalai
>


The CModel (i.e. ICElements) do not track statements and expressions.
Pretty much only declarations and includes.

The CDOM is ancient and deprecated. Don't use it. It is not likely
going to work properly. It's like going to be removed outright for
Ganymede.

What you want is the DOM AST. These are in the *.dom.ast.* packages.

===========================

Chris Recoskie
Team Lead, IBM CDT Team
IBM Toronto
http://www.eclipse.org/cdt
Re: CDT Model Parsing ... [message #201347 is a reply to message #201290] Tue, 11 September 2007 03:48 Go to previous messageGo to next message
Eclipse UserFriend
Thank you CHRIS ...
I did try to hunt into AST API. But couldnt really find a handle like
CDOM.getInstance().getTranslationUnit to retrieve the IASTTranslationUnit.
I used the same CDOM.getInstance().getTranslationUnit() but then didnt
know what to do with it.

It would be great if you could name the class that i need to start with in
CORE AST to get the elements inside the C File.

regards
Malai
Re: CDT Model Parsing ... [message #201362 is a reply to message #201347] Tue, 11 September 2007 11:12 Go to previous messageGo to next message
Eclipse UserFriend
Annamalai wrote:
> Thank you CHRIS ...
> I did try to hunt into AST API. But couldnt really find a handle like
> CDOM.getInstance().getTranslationUnit to retrieve the
> IASTTranslationUnit. I used the same
> CDOM.getInstance().getTranslationUnit() but then didnt know what to do
> with it.
>
> It would be great if you could name the class that i need to start with
> in CORE AST to get the elements inside the C File.
>
> regards
> Malai
>

ILanguage.getASTTranslationUnit()

===========================

Chris Recoskie
Team Lead, IBM CDT Team
IBM Toronto
http://www.eclipse.org/cdt
Re: CDT Model Parsing ... [message #201413 is a reply to message #201362] Wed, 12 September 2007 00:34 Go to previous messageGo to next message
Eclipse UserFriend
Dear Chris

Thanks for your reply again ... i would definitely try that out ...
Just a quick question ... w.r.t
http://dev.eclipse.org/mhonarc/lists/ptp-dev/msg00011.html

It seems there is a AST DOM View available for CDT on the CVS System.
I dont kno how to reach the CDT CVS System. Could you please tell me the
connection string .. that would be of great help ..

I did try the connection string available in the wiki-> resources but that
doesnt seem to have the repository path for cdt.

regards
Malai
Re: CDT Model Parsing ... [message #201420 is a reply to message #201413] Wed, 12 September 2007 03:46 Go to previous messageGo to next message
Eclipse UserFriend
Annamalai wrote:

> It seems there is a AST DOM View available for CDT on the CVS System.
> I dont kno how to reach the CDT CVS System. Could you please tell me the
> connection string .. that would be of great help ..

The DOM View is also part of the CDT Testing Feature. If you only want to
use this view you can install the testing feature using the update site.

> I did try the connection string available in the wiki-> resources but that
> doesnt seem to have the repository path for cdt.

This is the CVS connection
string. :pserver:anonymous@dev.eclipse.org:/cvsroot/tools

And here is a detailed tutorial how you get CDT source from CVS.
http://wiki.eclipse.org/CDT/User/FAQ#Working_on_the_CDT

regards
Emanuel
Re: CDT Model Parsing ... [message #523880 is a reply to message #201362] Mon, 29 March 2010 08:40 Go to previous message
Eclipse UserFriend
Originally posted by: samuel-dot-devulder.geensoft.com

Chris Recoskie a écrit :
> Annamalai wrote:
>> Thank you CHRIS ...
>> I did try to hunt into AST API. But couldnt really find a handle like
>> CDOM.getInstance().getTranslationUnit to retrieve the
>> IASTTranslationUnit. I used the same
>> CDOM.getInstance().getTranslationUnit() but then didnt know what to do
>> with it.
>>
>> It would be great if you could name the class that i need to start
>> with in CORE AST to get the elements inside the C File.
>>
>> regards
>> Malai
>>
>
> ILanguage.getASTTranslationUnit()
>
> ===========================

Hello!

I'm jummping into this old discussion because I'm facing the same kind
of problem. I used to get AST of a C file not residing in a C project in
a relative simple way using the following peace of code:

----8< ------------------------------------------------------------ -----
ICodeReaderFactory appendReaderFactory =
CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_SAVED_RES OURCES);
try {
appendReaderFactory.getCodeReaderCache().flush();
unit = CDOM.getInstance().getASTService().
getTranslationUnit(cfile, appendReaderFactory, false);
} catch (UnsupportedDialectException e) {
Utils.reportError(e);
}
----8< ------------------------------------------------------------ -----
(that code is probably comming out from an old/outdated FAQ).

Now that CDOM is deprecated, how do I achieve the same result?

The comment on the deprecated mark indicates ILanguage juste like you
said. However ILanguage does not have any static access. The closest I
found was to use GCCLanguage.getDefault(). But even then, the
getASTTranslationUnit has a lot of parameters (compared to the previous
code) for which I don't have a clue.

GCCLanguage.getDefault().
getASTTranslationUnit(reader, scanInfo, fileCreator, index,
options, log)

Is there any up-to-date FAQ explaining these parameters and possibly
addressing the problem of parsing a standalone plain C-File located
outside of a CDT project ?

regards,

sam.
Previous Topic:Eclipse console + CDT + SDL library
Next Topic:Output Path warning
Goto Forum:
  


Current Time: Sun Jun 22 06:54:04 EDT 2025

Powered by FUDForum. Page generated in 0.05289 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top