Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Get ICPPASTFunctionDefinition for a PDOMCPPFunctionTemplate

Hi

I need to get an ICPPASTFunctionDefinition where I can call #getBody() for a PDOM instance because I want to do the following:
— find the definition of a function template instance
— get the definition and find all ICPPASTFunctionCallExpression in this body.

This is the smallest example I could think of, there may be no other function calls in this, but just for clarification what I intend to do.
#include <algorithm>
int main() {
std::min(1,2);
}

So for this code, I want to get the definition for the min function in the header file. This would be no problem if the file was in my workspace but since it’s outside I don’t know how to get an IASTTranslationUnit? I’m able to get the source code string from looking and copying from CSourceHover but that doesn’t help me. So how do I obtain the ICPPASTFunctionDefinition?

What I have so far (simplified):
ICPPTemplateInstance templateInstance = (ICPPTemplateInstance) adaptedBinding;
ICPPTemplateDefinition templateDefinition = templateInstance.getTemplateDefinition(); // type PDOMCPPFunctionTemplate
IBinding specializedBinding = ((ICPPSpecialization) adaptedBinding).getSpecializedBinding();
ast.getDefinitions(specializedBinding); // where ast is an IASTTranslationUnit for the currently opened file

The last line returns a PDOMName and I don’t know what to do with it. With an IASTName I would do getParent().getParent() to get the definition. I also now how the get the IASTTranslationUnit for a file name which I have, but only if the file is in my workspace.

I’m new to CDT developing and probably didn’t understand everything correctly or I’m trying to do something that can be achieved much simpler. In the end I’m happy to find all subcalls.

Thanks!
Marco




Back to the top