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


Thanks Doug for clarifying.

I have one more query though. I find the CModel being built using the core.parser.ast. Now that the core.parser.ast is on its way out, what is the plan for the CModel? Would you be planning to remove that as well? Or would it have to be re-written to use the core.dom.ast?

Thanks,
Subbu




Doug Schaefer <DSchaefer@xxxxxxx>
Sent by: cdt-dev-bounces@xxxxxxxxxxx

10/24/2005 07:24 PM

Please respond to
"CDT General developers list."

To
"CDT General developers list." <cdt-dev@xxxxxxxxxxx>
cc
Subject
RE: [cdt-dev] How to access C/C++ source structure thru API





Comments below,
 
Cheers,
Doug
 
 



From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Subramanian Neelakantan
Sent:
Monday, October 24, 2005 4:38 AM
To:
cdt-dev@xxxxxxxxxxx
Subject:
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.


Doug> CModelBuilder is an internal interface. Use the CoreModel to create elements of the CModel including ITranslationUnit which calls the CModelBuilder to parse the file.

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.


Doug> Yes, that is correct. The ‘CDOM’ class is the starting point for creating ASTs.

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?


Doug> The core.parser.ast is from our old parser. It wasn’t a true AST. These were the objects that were passed back to the parser clients through callbacks at strategic points. The core.dom.ast objects are from the new DOM and form a full AST with other goodies. My objective is to remove the old parser and, thus, the old AST objects. Please use the DOM going forward.

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
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev


Back to the top