This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
GCC Plugin TRANSLATION_UNIT_DECL - Parsing global functions
- From: "Mario Miller" <mario-miller at gmx dot de>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 15 Aug 2012 13:15:49 +0200
- Subject: GCC Plugin TRANSLATION_UNIT_DECL - Parsing global functions
I am writing a GCC Plugin which can parse the bodies of functions.
Parsing member functions of classes works pretty well, but when I
want to parse a global function and use the DECL_CONTEXT Makro I
get a TRANSLATION_UNIT_DECL. For member functions I use the
DECL_SAVED_TREE Makro to parse the function body; this works.
But when I use this Makro on a global function it returns NULL
always. My code looks a bit like this:
if(TREE_CODE(expr) == FUNCTION_DECL)
{
tree context = DECL_CONTEXT(expr);
if(TREE_CODE(context) == TRANSLATION_UNIT_DECL)
{
if(DECL_SAVED_TREE(expr))
traverseExpression(DECL_SAVED_TREE(expr));
else
std::cerr << "DECL_SAVED_TREE(expr) is NULL\n";
}
else
/* Traverse member function */
}
The documentation says about TRANSLATION_UNIT_DECL: "A translation
unit. This is not technically a declaration, since it can't be
looked up, but it's close enough." I don't understand what that
means. Can somebody tell me how I can parse the bodies of global
functions?