Hi Nate,
IASTTranslationUnit ast = CurrentGui.getInstance().getGui().getAST(file); // file is an empty file with .cpp extention.
Will if (ast instanceof ICPPASTTranslationUnit) succeed?
Thanks.
Sent from
Mail for Windows 10
A C++ translation unit will have a C++ node factory. So, code like the following is reasonable:
if (ast instanceof ICPPASTTranslationUnit) {
ICPPNodeFactory cppNodeFactory = (ICPPNodeFactory) ast.getASTNodeFactory();
// use cppNodeFactory
} else {
// not a C++ translation unit
}
Hope that helps,
Nate
________________________________________
From: cdt-dev-bounces@xxxxxxxxxxx <cdt-dev-bounces@xxxxxxxxxxx> on behalf of Ming Cheng <chengm349@xxxxxxxxxxx>
Sent: February 27, 2020 2:16 AM
To: CDT General developers list.
Subject: Re: [cdt-dev] INodeFactory and ICPPNodeFactory
I know everyone is very busy.
Hope any expert can give some guide.
Thank you very much!
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
From: Ming Cheng<mailto:chengm349@xxxxxxxxxxx>
Sent: Wednesday, February 26, 2020 4:52 PM
To: cdt-dev@xxxxxxxxxxx<mailto:cdt-dev@xxxxxxxxxxx>
Subject: [cdt-dev] INodeFactory and ICPPNodeFactory
Hi,
IASTTranslationUnit ast = CurrentGui.getInstance().getGui().getAST(file);
ASTRewrite r = ASTRewrite.create( ast );
addIncludeDirectives(ast, r, className + ".h");
INodeFactory factory = ast.getASTNodeFactory();
I have ast, is there a way to get ICPPNodeFactory? I want to "new" a class declaration as simple and natural as possible. For example I don't want ASTRewrite's createLiteralNode to get a IASTNode. Then to add some class's elements. I prefer to get a IASTSimpleDeclaration
with ICPPASTCompositeTypeSpecifier.k_class .
Rgds.
Ming Cheng