// GCC header includes to get the parse tree // declarations. The order is important and // doesn't follow any kind of logic. // #include "config.h" /* Needed to undef because gcc-plugins redefine them */ #undef PACKAGE_BUGREPORT #undef PACKAGE_NAME #undef PACKAGE_STRING #undef PACKAGE_TARNAME #undef PACKAGE_VERSION #include #include #include #include // Include before GCC poisons // some declarations. extern "C" { #include "gcc-plugin.h" #include "plugin-version.h" #include "system.h" #include "coretypes.h" #include "tree.h" #include "intl.h" #include "tm.h" #include "diagnostic.h" #include "c-common.h" #include "c-pragma.h" #include "cp/cp-tree.h" } #include #include "tree-iterator.h" int plugin_is_GPL_compatible; void collect (tree ns) { tree decl; cp_binding_level* level (NAMESPACE_LEVEL (ns)); // Collect declarations. // for (decl = level->names; decl != 0; decl = TREE_CHAIN (decl)) { if (DECL_IS_BUILTIN (decl)) continue; if (TREE_CODE(decl) == FUNCTION_DECL) std::cerr << IDENTIFIER_POINTER(DECL_NAME(decl)) << " " << DECL_SAVED_TREE(decl) << "\n"; } } extern "C" void gate_callback (void *gcc_data, void *user_data) { // If there were errors during compilation, // let GCC handle the exit. // if (errorcount || sorrycount) return; // int r (0); // // Process AST. Issue diagnostics and set r // to 1 in case of an error. // std::cerr << gcc_data << "\n"; std::cerr << PLUGIN_PRE_GENERICIZE << "\n"; std::cerr << "processing " << main_input_filename << "\n"; collect (global_namespace); // exit (r); } extern "C" int plugin_init (plugin_name_args* info, plugin_gcc_version* ver) { if (!plugin_default_version_check (ver, &gcc_version)) return 1; int r (0); std::cerr << "starting " << info->base_name << "\n"; register_callback (info->base_name, PLUGIN_PRE_GENERICIZE, &gate_callback, 0); return r; }