| 1 |
/* A plugin example that shows which declarations are caught by FINISH_DECL */ |
| 2 |
|
| 3 |
#include "gcc-plugin.h" |
| 4 |
#include <stdlib.h> |
| 5 |
#include "config.h" |
| 6 |
#include "system.h" |
| 7 |
#include "coretypes.h" |
| 8 |
#include "tree.h" |
| 9 |
#include "tree-pass.h" |
| 10 |
#include "intl.h" |
| 11 |
#include "diagnostic.h" |
| 12 |
|
| 13 |
int plugin_is_GPL_compatible; |
| 14 |
|
| 15 |
/* Callback function to invoke after GCC finishes a declaration. */ |
| 16 |
|
| 17 |
void plugin_finish_decl (void *event_data, void *data) |
| 18 |
{ |
| 19 |
tree decl = (tree) event_data; |
| 20 |
|
| 21 |
const char *kind = NULL; |
| 22 |
switch (TREE_CODE(decl)) { |
| 23 |
case FUNCTION_DECL: |
| 24 |
kind = "Function"; break; |
| 25 |
case PARM_DECL: |
| 26 |
kind = "Parameter"; break; |
| 27 |
case VAR_DECL: |
| 28 |
if (DECL_FILE_SCOPE_P(decl)) |
| 29 |
kind = "Global"; |
| 30 |
else |
| 31 |
kind = "Local"; |
| 32 |
break; |
| 33 |
case FIELD_DECL: |
| 34 |
kind = "Field"; break; |
| 35 |
default: |
| 36 |
kind = "Unknown"; |
| 37 |
} |
| 38 |
|
| 39 |
warning (0, G_("Decl %s %s"), |
| 40 |
kind, IDENTIFIER_POINTER (DECL_NAME (decl))); |
| 41 |
} |
| 42 |
|
| 43 |
int |
| 44 |
plugin_init (struct plugin_name_args *plugin_info, |
| 45 |
struct plugin_gcc_version *version) |
| 46 |
{ |
| 47 |
const char *plugin_name = plugin_info->base_name; |
| 48 |
|
| 49 |
register_callback (plugin_name, PLUGIN_FINISH_DECL, |
| 50 |
plugin_finish_decl, NULL); |
| 51 |
return 0; |
| 52 |
} |