[cfe-dev] How to get Function Definition from CallExpr
Kevin Boos
kevinaboos at gmail.com
Tue Jul 16 15:27:58 PDT 2013
Hello,
I have a piece of C code like so:
==========================================
void foo(); // just a declaration (sometimes in a header file instead)
void bar() {
// definition here
}
int main() {
bar(); // this one is fine
foo(); // this one doesn't work
}
void foo() {
// definition here
}
============================================
I'm using VisitStmt and looking at the CallExprs in main(). For the "bar()"
function above, I can get the FunctionDecl* using
CallExpr::getDirectCallee(). However, that doesn't work for the "foo()"
function -- calling getDirectCallee() gives me the function prototype, not
the definition of "foo()"...
So I tried using the Redeclarable class's "redecl_iterator" to dump each
redeclaration starting from getDirectCallee()->redecls_begin. However, it
only iterates once for the function prototype and doesn't include the
actual definition of "foo()."
How can I get the real definition of foo() at the bottom of the code above?
I know it's probably something easy, but I just can't seem to get there.
Thanks in advance,
Kevin Boos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130716/ba31f3e2/attachment.html>
More information about the cfe-dev
mailing list