Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[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


Back to the top