Concept for finding Struct definitions in external header files [message #1754930] |
Fri, 24 February 2017 08:09 |
Jens Frieben Messages: 1 Registered: February 2017 |
Junior Member |
|
|
Hello,
I am pretty new to CDT development so forgive me any obvious questions.
My goal is to parse a CPP file, find all IASTFunctionCallExpressions for a given Operation, identify the parameters used, and output the structure of all non-primitive types.
The first two steps work like a charm with a custom ASTVisitor.
IASTTranslationUnit ast = tu.getAST(index, 0);
outputText.add("Location: " + ast.getFileLocation().getFileName());
outputText.add("CppProject: " + tu.getCProject().getElementName());
outputText.add("");
// traverse the ast using the visitor pattern
AddPortInfoVisitor searcher = new AddPortInfoVisitor();
ast.accept(searcher);
for (IASTFunctionCallExpression funcCallEx : searcher.getFunctionCallList()) {
outputText.add("");
// now get the LiteralExpression as the port name
IASTLiteralExpression literalExpression = getLiteralExpression(funcCallEx);
outputText.add("Portname: " + String.valueOf(literalExpression.getValue()));
// second part is an UnaryExpression
IASTUnaryExpression unaryExpression = getUnaryExpression(funcCallEx);
IASTExpression operand = unaryExpression.getOperand();
if (operand instanceof IASTFieldReference) {
IASTFieldReference fref = (IASTFieldReference) operand;
outputText.add("Owner: '" + fref.getFieldOwner().toString() + "' -> Field: '"
+ fref.getFieldName().toString() + "'");
outputText.add("Type: " + fref.getExpressionType());
However, I now have the problem to use the Index to find the location of the Struct Declaration and to parse it with an ASTVisitor again.
Could anyone point me in the right direction? The additional (header) files are within the same project, therefore the used index is based on a selected project. My code is based on the CDT Pages (https://wiki.eclipse.org/CDT/designs/Overview_of_Parsing) and two documents "Using Eclipse CDT/PTP for Static Analysis" and "Using CDT APIs to programmatically introspect C/C++ code".
Best regards and thanks for the help!
|
|
|
Powered by
FUDForum. Page generated in 0.04704 seconds