CDT Model Parsing ... [message #201273] |
Mon, 10 September 2007 06:27  |
Eclipse User |
|
|
|
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 #523880 is a reply to message #201362] |
Mon, 29 March 2010 08:40  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.04628 seconds