This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]