- To: gcc-help@xxxxxxxxxxx
- Subject: GCC Plugin TRANSLATION_UNIT_DECL - Parsing global functions
- From: "Mario Miller" <mario-miller@xxxxxx>
- Date: Wed, 15 Aug 2012 13:15:49 +0200
- Comment: DKIM? See http://www.dkim.org
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
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?
[Linux C Programming]
[Linux Kernel]
[eCos]
[Fedora Development]
[Fedora Announce]
[Autoconf]
[The DWARVES Debugging Tools]
[Yosemite Campsites]
[Yosemite News]
[Linux GCC]