Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Newbie question to parse standalone C/C++ header file and retrieve all function declarations programmaticaly

Hello,

I am new to using Eclipse CDT directly from its Java API. So sorry if my question is irrelevant.
Actually I've read in this post ( https://www.eclipse.org/forums/index.php/t/1087955/ ) that this list is more indicated than the forum for my type of question.
Unfortunately I could not easily look at all the archived emails to see if my question is already answered :/ sorry if it is the case.

Anyway, here is my problem and thank you in advance for your help :
I want to parse standalone (I don't want to resolve the includes) C and C++ header files (I get an IFile object pointing to each of them) and retrieve all function declarations (as IFunctionDeclaration objects I guess). In short, I want to retrieve the content of the outline view, but programmatically and directly on an IFile of any project not being C/C++ project.

After some hours of googling, I found a few relevant posts but I failed to obtain a MWE from them.
Moreover the snippets I tried are using the AST whereas I believe that the C-Model or the C-Index seem more convenient to get the function declarations only.
- https://wiki.eclipse.org/CDT/User/FAQ#I_am_developing_a_plug-in_that_requires_a_parsing_a_c_file_and_obtaining_the_information_such_as_method_signatures.2C_parameter_types_etc._How_can_I_do_this_using_the_CDT_parser.3F (does not really indicate how to retrieve the functions)

I have tried a small part of the last sourced link in my own project, especially by using
GPPLanguage.getDefault().getASTTranslationUnit(fileContent, info, emptyIncludes, index, options, log).getDeclarations()
However, all the functions declared in the header are fetched with the CPPASTSimpleDeclaration type instead of IFunctionDeclaration or something similar. So I don't know if it is an error in my code or if I am only missing a few more steps.
I can provide more comprehensive examples and source files if needed.

I guess this is dummy question, but unfortunately I also had troubles to read the doc: I did not find the javadoc of the CDT project online, did I miss a link?

Best regards,

Alexandre Honorat


Back to the top