This is my code:
class CheckCodeVisitor extends ASTVisitor {
@Override
public int visit(IASTDeclaration decl) {
IASTDeclarationImplClass.visit(index, decl);
return PROCESS_CONTINUE;
}
}
If we check IASTDeclaration document (https://help.eclipse.org/2019-12/index.jsp), we can see these information:
org.eclipse.cdt.core.dom.ast
Interface IASTDeclaration
All Superinterfaces:
IASTNode
All Known Subinterfaces:
IASTASMDeclaration,
IASTFunctionDefinition,
IASTProblemDeclaration,
IASTSimpleDeclaration,
ICPPASTAliasDeclaration,
ICPPASTExplicitTemplateInstantiation,
ICPPASTFunctionDefinition,
ICPPASTFunctionWithTryBlock,
ICPPASTInitCapture,
ICPPASTLinkageSpecification,
ICPPASTNamespaceAlias,
ICPPASTNamespaceDefinition,
ICPPASTStaticAssertDeclaration,
ICPPASTStructuredBindingDeclaration,
ICPPASTTemplateDeclaration,
ICPPASTTemplateSpecialization,
ICPPASTUsingDeclaration,
ICPPASTUsingDirective,
ICPPASTVisibilityLabel,
IGPPASTExplicitTemplateInstantiation
My concern is that if I can use
IASTSimpleDeclaration
to get all C++ code information, why we need
ICPPASTExplicitTemplateInstantiation/ICPPASTxxxxxxx etc?
Again this is my
IASTDeclarationImplClass code:
public class IASTDeclarationImplClass {
private static final Logger log = LoggerFactory.getLogger(IASTDeclarationImplClass.class);
public static int visit(IIndex index, IASTDeclaration decl) {
if (decl instanceof CASTAmbiguousSimpleDeclaration) {
CASTAmbiguousSimpleDeclaration simpleDeclaration = (CASTAmbiguousSimpleDeclaration) decl;
return visit(index, simpleDeclaration);
} else if (decl instanceof CASTASMDeclaration) {
CASTASMDeclaration asmDeclaration = (CASTASMDeclaration) decl;
return visit(index, asmDeclaration);
} else if (decl instanceof CASTFunctionDefinition) {
CASTFunctionDefinition funcDecl = (CASTFunctionDefinition) decl;
return visit(index, funcDecl);
} else if (decl instanceof CASTProblemDeclaration) {
CASTProblemDeclaration problemDecl = (CASTProblemDeclaration) decl;
return visit(index, problemDecl);
} else if (decl instanceof CPPASTAmbiguousSimpleDeclaration) {
CPPASTAmbiguousSimpleDeclaration cppSimpleDeclaration = (CPPASTAmbiguousSimpleDeclaration) decl;
return visit(index, cppSimpleDeclaration);
} else if (decl instanceof IASTSimpleDeclaration) {
IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) decl;
return visit(index, simpleDeclaration);
} else if (decl instanceof CPPASTASMDeclaration) {
CPPASTASMDeclaration cppASMDeclaration = (CPPASTASMDeclaration) decl;
return visit(index, cppASMDeclaration);
} else if (decl instanceof CPPASTExplicitTemplateInstantiation) {
CPPASTExplicitTemplateInstantiation explicitTemplateInstantiation = (CPPASTExplicitTemplateInstantiation) decl;
return visit(index, explicitTemplateInstantiation);
} else if (decl instanceof CPPASTFunctionDefinition) {
CPPASTFunctionDefinition cppFuncDefinition = (CPPASTFunctionDefinition) decl;
return visit(index, cppFuncDefinition);
} else if (decl instanceof CPPASTFunctionWithTryBlock) {
CPPASTFunctionWithTryBlock cppFunctionWithTryBlock = (CPPASTFunctionWithTryBlock) decl;
return visit(index, cppFunctionWithTryBlock);
} else if (decl instanceof ICPPASTInternalTemplateDeclaration) {
ICPPASTInternalTemplateDeclaration internalTempDecl = (ICPPASTInternalTemplateDeclaration) decl;
return visit(index, internalTempDecl);
} else if (decl instanceof CPPASTLinkageSpecification) {
CPPASTLinkageSpecification linkageSpec = (CPPASTLinkageSpecification) decl;
return visit(index, linkageSpec);
} else if (decl instanceof CPPASTNamespaceAlias) {
CPPASTNamespaceAlias nsAlias = (CPPASTNamespaceAlias) decl;
return visit(index, nsAlias);
} else if (decl instanceof CPPASTNamespaceDefinition) {
CPPASTNamespaceDefinition nsDefn = (CPPASTNamespaceDefinition) decl;
return visit(index, nsDefn);
} else if (decl instanceof CPPASTProblemDeclaration) {
CPPASTProblemDeclaration problemDeclaration = (CPPASTProblemDeclaration) decl;
return visit(index, problemDeclaration);
} else if (decl instanceof CPPASTSimpleDeclaration) {
CPPASTSimpleDeclaration cppSimpleDeclaration = (CPPASTSimpleDeclaration) decl;
return visit(index, cppSimpleDeclaration);
} else if (decl instanceof CPPASTStaticAssertionDeclaration) {
CPPASTStaticAssertionDeclaration staticAssertDecl = (CPPASTStaticAssertionDeclaration) decl;
return visit(index, staticAssertDecl);
} else if (decl instanceof CPPASTTemplateDeclaration) {
CPPASTTemplateDeclaration cppTempDecl = (CPPASTTemplateDeclaration) decl;
return visit(index, cppTempDecl);
} else if (decl instanceof CPPASTTemplateSpecialization) {
CPPASTTemplateSpecialization cppTempSpecialization = (CPPASTTemplateSpecialization) decl;
return visit(index, cppTempSpecialization);
} else if (decl instanceof CPPASTUsingDeclaration) {
CPPASTUsingDeclaration cppUsingDecl = (CPPASTUsingDeclaration) decl;
return visit(index, cppUsingDecl);
} else if (decl instanceof CPPASTUsingDirective) {
CPPASTUsingDirective cppUsingDirective = (CPPASTUsingDirective) decl;
return visit(index, cppUsingDirective);
} else if (decl instanceof CPPASTVisibilityLabel) {
CPPASTVisibilityLabel cppVisibilityLabel = (CPPASTVisibilityLabel) decl;
return visit(index, cppVisibilityLabel);
} else if (decl instanceof GPPASTExplicitTemplateInstantiation) {
GPPASTExplicitTemplateInstantiation cppExplicitTemplateInstantiation = (GPPASTExplicitTemplateInstantiation) decl;
return visit(index, cppExplicitTemplateInstantiation);
}
return PROCESS_SKIP;
}
private static int visit(IIndex index, CASTAmbiguousSimpleDeclaration simpleDeclaration) {
display("Visiting CASTAmbiguousSimpleDeclaration: " + simpleDeclaration.getRawSignature());
return PROCESS_CONTINUE;
}
…
}
According to yours and Jonah’s replies, it seems the following possible impl should be enough?
IASTASMDeclaration,
IASTFunctionDefinition,
IASTProblemDeclaration,
IASTSimpleDeclaration
public class IASTDeclarationImplClass {
private static final Logger log = LoggerFactory.getLogger(IASTDeclarationImplClass.class);
public static int visit(IIndex index, IASTDeclaration decl) {
if (decl instanceof
IASTASMDeclaration) {
IASTASMDeclaration asmDeclaration = (IASTASMDeclaration)
decl;
return visit(index, asmDeclaration);
} else if (decl instanceof
IASTFunctionDefinition) {
IASTFunctionDefinition funcDefn = (IASTFunctionDefinition)
decl;
return visit(index, funcDefn);
} else if (decl instanceof
IASTProblemDeclaration) {
IASTProblemDeclaration problem = (IASTProblemDeclaration)
decl;
return visit(index, problem);
} else if (decl instanceof IASTSimpleDeclaration) {
IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) decl;
return visit(index, simpleDeclaration);
}
return PROCESS_SKIP;
}
private static int visit(IIndex index, IASTSimpleDeclaration simpleDeclaration) {
display("Visiting IASTSimpleDeclaration: " + simpleDeclaration.getRawSignature());
// use IASTSimpleDeclaration public API to get more detail information like whether it’s class or struct, or explicit template class instantiation etc?
return PROCESS_CONTINUE;
}
……
}
Sent from
Mail for Windows 10
> You said something but I feel they are not relevant to “yet without using internal iface/class” directly.
All of the mentioned interfaces for AST nodes (e.g. IASTSimpleDeclaration, IASTFunctionDefinition, etc.) and the methods for navigating the AST (e.g. IASTSimpleDeclaration.getDeclSpecifier()) are public APIs.
Regards,
Nate