Index: gcc/testsuite/g++.dg/plugin/plugin.exp =================================================================== --- gcc/testsuite/g++.dg/plugin/plugin.exp (revision 174521) +++ gcc/testsuite/g++.dg/plugin/plugin.exp (working copy) @@ -49,6 +49,7 @@ load_lib plugin-support.exp set plugin_test_list [list \ { attribute_plugin.c attribute_plugin-test-1.C } \ { pragma_plugin.c pragma_plugin-test-1.C } \ + { pragma_plugin_with_data.c pragma_plugin_with_data-test-1.C } \ { selfassign.c self-assign-test-1.C self-assign-test-2.C self-assign-test-3.C } \ { dumb_plugin.c dumb-plugin-test-1.C } \ { header_plugin.c header-plugin-test.C } ] Index: gcc/testsuite/g++.dg/plugin/pragma_plugin_with_data.c =================================================================== --- gcc/testsuite/g++.dg/plugin/pragma_plugin_with_data.c (revision 0) +++ gcc/testsuite/g++.dg/plugin/pragma_plugin_with_data.c (revision 0) @@ -0,0 +1,102 @@ +/* Test pragma adding using an extra data field. */ + +#include "gcc-plugin.h" +#include +#include "function.h" +#include "c-family/c-pragma.h" +#include "intl.h" + + + +int plugin_is_GPL_compatible; + + + +#define GCC_PRAGMA_BAD(gmsgid) \ + do { warning (OPT_Wpragmas, gmsgid); goto end; } while (0) + +/* handler of #pragma SPACE NAME command (arg1, arg2, ...) or of type + * #pragma SPACE NAME command . + */ + +static void +handle_pragma_gen (cpp_reader *ARG_UNUSED(dummy), void * data) +{ + char * plugin_name = (char *) data; + + warning (0, G_("The name of the pass: %s"), + plugin_name); + + enum cpp_ttype token; + tree x; + const char * command; + + token = pragma_lex (&x); + if(token != CPP_NAME) + GCC_PRAGMA_BAD ("malformed #pragma melt, ignored"); + + command = IDENTIFIER_POINTER(x); + + /*If the pragma has the form #pragma SPACE NAME cmd (...) then command + contains "cmd". + Next element should be a parenthese opening or an end of line */ + token = pragma_lex (&x); + if (token != CPP_OPEN_PAREN) + { + if (token != CPP_EOF) + GCC_PRAGMA_BAD ("malformed #pragma melt, ignored"); + + else /* we have a pragma of the type '#pragma SPACE NAME command' */ + { + /* We have recover our pragma. */ + warning (OPT_Wpragmas, "%<#pragma GCCPLUGIN newPragma%> a simple \ +instruction: %s", command); + return; + } + } + else + { /* opening parenthesis */ + do + { + token = pragma_lex (&x); + if(token != CPP_NAME && token != CPP_STRING && token != CPP_NUMBER) + GCC_PRAGMA_BAD ("malformed #pragma melt, ignored"); + + token = pragma_lex (&x); + + } while (token == CPP_COMMA); + + if (token == CPP_CLOSE_PAREN && pragma_lex(&x) == CPP_EOF) + { + /* We have recover our pragma. */ + warning (OPT_Wpragmas, "%<#pragma GCCPLUGIN newPragma%> a more complex \ +instruction: %s", command); + return; + } + else + GCC_PRAGMA_BAD ("malformed #pragma melt, ignored"); + } +end: return; +} + +/* Plugin callback called during pragma registration */ + +static void +register_my_pragma (void *event_data, void *data) +{ + warning (0, G_("Callback to register pragmas")); + c_register_pragma_with_data ("GCCPLUGIN", "newPragma", + handle_pragma_gen, data); +} + +/* Init the plugin. */ +int +plugin_init (struct plugin_name_args *plugin_info, + struct plugin_gcc_version *version) +{ + const char *plugin_name = plugin_info->base_name; + + register_callback (plugin_name, PLUGIN_PRAGMAS, register_my_pragma, + (void *) plugin_name); + return 0; +} Index: gcc/testsuite/g++.dg/plugin/pragma_plugin_with_data-test-1.C =================================================================== --- gcc/testsuite/g++.dg/plugin/pragma_plugin_with_data-test-1.C (revision 0) +++ gcc/testsuite/g++.dg/plugin/pragma_plugin_with_data-test-1.C (revision 0) @@ -0,0 +1,8 @@ +// { dg-warning "Callback to register pragmas" "" { target *-*-* } 0 } +// { dg-warning "The name of the pass: pragma_plugin_with_data" "" {target *-*-* } 5 } +// { dg-warning "The name of the pass: pragma_plugin_with_data" "" {target *-*-* } 7 } + +#pragma GCCPLUGIN newPragma do_smt // { dg-warning "'#pragma GCCPLUGIN newPragma' a simple instruction: do_smt" } + +#pragma GCCPLUGIN newPragma do_smt_else (test ,"test", 2) // { dg-warning "'#pragma GCCPLUGIN newPragma' a more complex instruction: do_smt_else" } +