Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] How to access C/C++ source structure thru API


Ok, this is what I have figured out.  Kindly validate my understanding.

The CModel is just a structural parse (or a quick parse) of the C/C++ source file. This means that the function bodies, expressions, etc will not be parsed. We can get to this model using the CModelBuilder.parse(boolean) method.

The CDOM AST is the complete parse of the C/C++ source file. This should be used if "all" of the C/C++ source is required to be parsed.

What I am still trying to figure out is the relation between the two packages - "org.eclipse.cdt.core.dom.ast" and "org.eclipse.cdt.core.parser.ast".  Both of these seem to have an AST representation of the C/C++ source. Could anyone kindly highlight the difference between these two packages, and which type of parse generates each of these ASTs?

Thanks,
Subbu


----- Forwarded by Subramanian Neelakantan/India/IBM on 10/24/2005 10:49 AM -----
Subramanian Neelakantan/India/IBM@IBMIN
Sent by: cdt-dev-bounces@xxxxxxxxxxx

10/23/2005 07:59 PM

Please respond to
"CDT General developers list."

To
cdt-dev@xxxxxxxxxxx
cc
Subject
[cdt-dev] How to access C/C++ source structure thru API






I find two ways to read a C/C++ source file using the CDT framework.


1.         Use ISourceReference.getTranslationUnit() on a IFile to get to the ITranslationUnit.

       Call ITranslationUnit.parse(), and then browse around the org.eclipse.cdt.core.model package elements (eg. using IParent.getChildrenOfType(int), and access the ICElement tree hierarchy)


2.         Use CDOM.getInstance().getASTService().getTranslationUnit(

                                                       IFile,

                                                       CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_SAVED_RESOURCES));

       Then use IASTTranslationUnit.getDeclarations() method to get to the AST tree and browse around the org.eclipse.cdt.core.dom.ast package elements.


Are both of these valid? Which is the recommended way to access the contents of a C/C++ source file? What are the differences between these two packages (org.eclipse.cdt.core.model and org.eclipse.cdt.core.dom.ast) ?


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

Back to the top