Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Concept for finding Struct definitions in external header files(Using AST and Indexer to find declarations and output them)
Concept for finding Struct definitions in external header files [message #1754930] Fri, 24 February 2017 08:09
Jens Frieben is currently offline Jens FriebenFriend
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!
Previous Topic:Problems with Eclipse Kepler
Next Topic:Serial1 on Mega 2560 board
Goto Forum:
  


Current Time: Fri Apr 26 04:48:29 GMT 2024

Powered by FUDForum. Page generated in 0.02570 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top