[tools 1/2] Handle "midl_pragma warning" statement in parser
Bolotov Sergey
bolotov.s.s at yandex.ru
Sun Mar 20 05:11:59 CDT 2016
Signed-off-by: Bolotov Sergey <bolotov.s.s at yandex.ru>
---
tools/widl/parser.h | 2 ++
tools/widl/parser.l | 25 +++++++++++++++++++++++++
tools/widl/parser.y | 38 +++++++++++++++++++++++++++++++++++++-
tools/widl/widltypes.h | 7 +++++++
4 files changed, 71 insertions(+), 1 deletion(-)
diff --git a/tools/widl/parser.h b/tools/widl/parser.h
index 1bcc3c1..c15d874 100644
--- a/tools/widl/parser.h
+++ b/tools/widl/parser.h
@@ -45,6 +45,8 @@ void pop_import(void);
int is_type(const char *name);
+int do_warning(char *toggle, warning_list_t *wnum);
+
extern char *temp_name;
#endif
diff --git a/tools/widl/parser.l b/tools/widl/parser.l
index 5c2dcab..65e0f45 100644
--- a/tools/widl/parser.l
+++ b/tools/widl/parser.l
@@ -164,6 +164,7 @@ UUID *parse_uuid(const char *u)
yy_pop_state();
}
<PP_PRAGMA>[^\n]* parser_lval.str = xstrdup(yytext); yy_pop_state(); return aPRAGMA;
+<INITIAL>^{ws}*"midl_pragma warning" return tPRAGMA_WARNING;
<INITIAL,ATTR>\" yy_push_state(QUOTE); cbufidx = 0;
<QUOTE>\" {
yy_pop_state();
@@ -555,3 +556,27 @@ void abort_import(void)
for (ptr=0; ptr<import_stack_ptr; ptr++)
unlink(import_stack[ptr].temp_name);
}
+
+static void warning_disable(int warning)
+{
+ printf("disable %d\n", warning);
+}
+
+static void warning_enable(int warning)
+{
+ printf("enable %d\n", warning);
+}
+
+int do_warning(char *toggle, warning_list_t *wnum)
+{
+ warning_t *warning;
+ if(!strcmp(toggle, "disable"))
+ LIST_FOR_EACH_ENTRY(warning, wnum, warning_t, entry)
+ warning_disable(warning->num);
+ else if(!strcmp(toggle, "enable"))
+ LIST_FOR_EACH_ENTRY(warning, wnum, warning_t, entry)
+ warning_enable(warning->num);
+ else
+ return 0;
+ return 1;
+}
diff --git a/tools/widl/parser.y b/tools/widl/parser.y
index 7de7567..6551ea2 100644
--- a/tools/widl/parser.y
+++ b/tools/widl/parser.y
@@ -83,6 +83,7 @@ static declarator_t *make_declarator(var_t *var);
static type_t *make_safearray(type_t *type);
static typelib_t *make_library(const char *name, const attr_list_t *attrs);
static type_t *append_ptrchain_type(type_t *ptrchain, type_t *type);
+static warning_list_t *append_warning(warning_list_t *, int);
static type_t *reg_typedefs(decl_spec_t *decl_spec, var_list_t *names, attr_list_t *attrs);
static type_t *find_type_or_error(const char *name, int t);
@@ -148,6 +149,8 @@ static struct namespace *current_namespace = &global_namespace;
declarator_list_t *declarator_list;
statement_t *statement;
statement_list_t *stmt_list;
+ warning_t *warning;
+ warning_list_t *warning_list;
ifref_t *ifref;
ifref_list_t *ifref_list;
char *str;
@@ -224,6 +227,7 @@ static struct namespace *current_namespace = &global_namespace;
%token tOUT
%token tPARTIALIGNORE tPASCAL
%token tPOINTERDEFAULT
+%token tPRAGMA_WARNING
%token tPROGID tPROPERTIES
%token tPROPGET tPROPPUT tPROPPUTREF
%token tPROXY tPTR
@@ -291,8 +295,9 @@ static struct namespace *current_namespace = &global_namespace;
%type <uuid> uuid_string
%type <import> import_start
%type <typelib> library_start librarydef
-%type <statement> statement typedef
+%type <statement> statement typedef pragma_warning
%type <stmt_list> gbl_statements imp_statements int_statements
+%type <warning_list> warnings
%left ','
%right '?' ':'
@@ -373,6 +378,22 @@ statement:
| import { $$ = make_statement_import($1); }
| typedef ';' { $$ = $1; }
| aPRAGMA { $$ = make_statement_pragma($1); }
+ | pragma_warning { $$ = NULL; }
+ ;
+
+pragma_warning: tPRAGMA_WARNING '(' aIDENTIFIER ':' warnings ')'
+ {
+ int result;
+ $$ = NULL;
+ result = do_warning($3, $5);
+ if(!result)
+ error_loc("expected \"disable\" or \"enable\"\n");
+ }
+ ;
+
+warnings:
+ aNUM { $$ = append_warning(NULL, $1); }
+ | warnings aNUM { $$ = append_warning($1, $2); }
;
typedecl:
@@ -1413,6 +1434,21 @@ static type_t *append_ptrchain_type(type_t *ptrchain, type_t *type)
return ptrchain;
}
+static warning_list_t *append_warning(warning_list_t *list, int num)
+{
+ warning_t *entry;
+
+ if(!list)
+ {
+ list = xmalloc( sizeof(*list) );
+ list_init( list );
+ }
+ entry = xmalloc( sizeof(*entry) );
+ entry->num = num;
+ list_add_tail( list, &entry->entry );
+ return list;
+}
+
static var_t *declare_var(attr_list_t *attrs, decl_spec_t *decl_spec, const declarator_t *decl,
int top)
{
diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h
index 4d51312..1f4a9dd 100644
--- a/tools/widl/widltypes.h
+++ b/tools/widl/widltypes.h
@@ -51,6 +51,7 @@ typedef struct _user_type_t context_handle_t;
typedef struct _user_type_t generic_handle_t;
typedef struct _type_list_t type_list_t;
typedef struct _statement_t statement_t;
+typedef struct _warning_t warning_t;
typedef struct list attr_list_t;
typedef struct list str_list_t;
@@ -63,6 +64,7 @@ typedef struct list user_type_list_t;
typedef struct list context_handle_list_t;
typedef struct list generic_handle_list_t;
typedef struct list statement_list_t;
+typedef struct list warning_list_t;
enum attr_type
{
@@ -538,6 +540,11 @@ struct _statement_t {
} u;
};
+struct _warning_t {
+ int num;
+ struct list entry;
+};
+
typedef enum {
SYS_WIN16,
SYS_WIN32,
--
1.9.1
More information about the wine-patches
mailing list