Which variable stores the root node of a C GENERIC AST in gcc?
I am trying to write a plugin for g开发者_如何学编程cc 4.5 that will perform some analysis on the AST (GENERIC representation) just after parsing is complete. My source language is C and the plugin will be written in C as well. There are a few posts here that explain how to do such a thing for C++. Both the GENERIC documentation and the previous link state that the variable global_namespace
stores the root node of a C++ GENERIC AST. Which variable stores the root node of a C GENERIC AST?
Thanks in advance!
There are obviously no such things as namespaces for C but the concept of scopes does exist however. You can access the englobing scope of where you are (that depends on which event your plugin is called by GCC) through the function pop_scope()
defined in c-tree.h
. This returns a tree
which is composed of a block
. You can access all the declarations of this block, i.e. the symbols (variables, functions, etc.) declared at this scope through the macro BLOCK_VARS
which provides you with a tree
of decl-nodes.
If you neeed access to a function body, remember than you can always access it from the function definition through the macro DECL_SAVED_TREE(node)
, node
being your FUNCTION_DECL
node. This is valid only if the definition is in the same file and already built, again, it depends on where you hook your plugin.
Disclaimer: this is valid for GCC 4.8 and the interface is subject to frequent changes. As of GCC 4.9, the plugin interface is partially written in C++.
精彩评论