Skip to main content

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

We don't store full ASTs in the index. Therefore, you cannot get access to IAST* objects given a binding in the index (PDOM*).

If you need the function body of a function stored in the index, you'll have to re-parse the file containing the function definition. My advice would be to look at how the indexer does it.

Hope that helps,

Date: Tue, 4 Nov 2014 16:19:42 +0100
From: marco.syfrig@xxxxxxxxx
To: cdt-dev@xxxxxxxxxxx
Subject: [cdt-dev] Get ICPPASTFunctionDefinition for a PDOMCPPFunctionTemplate


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() {

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.


_______________________________________________ cdt-dev mailing list cdt-dev@xxxxxxxxxxx To change your delivery options, retrieve your password, or unsubscribe from this list, visit

Back to the top