Rob Shearman : widl: Allow pointers, type-qualifiers and other more complicated constructions in sizeof and cast expressions .

Alexandre Julliard julliard at winehq.org
Mon Nov 9 15:14:20 CST 2009


Module: wine
Branch: master
Commit: 0228008bb889b8b69ec57622b1b8a577b13617b9
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=0228008bb889b8b69ec57622b1b8a577b13617b9

Author: Rob Shearman <robertshearman at gmail.com>
Date:   Sat Nov  7 15:55:22 2009 +0100

widl: Allow pointers, type-qualifiers and other more complicated constructions in sizeof and cast expressions.

---

 dlls/ole32/marshal.c |    2 +-
 include/objidl.idl   |    4 +-
 tools/widl/expr.c    |   10 +++++++-
 tools/widl/expr.h    |    2 +-
 tools/widl/parser.y  |   62 +++++++++++++++++++++++++++++++++++++++++--------
 5 files changed, 65 insertions(+), 15 deletions(-)

diff --git a/dlls/ole32/marshal.c b/dlls/ole32/marshal.c
index a5c4d11..821cb87 100644
--- a/dlls/ole32/marshal.c
+++ b/dlls/ole32/marshal.c
@@ -554,7 +554,7 @@ static HRESULT WINAPI ProxyCliSec_SetBlanket(IClientSecurity *iface,
                                              DWORD Capabilities)
 {
     FIXME("(%p, %d, %d, %s, %d, %d, %p, 0x%x): stub\n", pProxy, AuthnSvc, AuthzSvc,
-          pServerPrincName == (OLECHAR*)COLE_DEFAULT_PRINCIPAL ? "<default principal>" : debugstr_w(pServerPrincName),
+          pServerPrincName == COLE_DEFAULT_PRINCIPAL ? "<default principal>" : debugstr_w(pServerPrincName),
           AuthnLevel, ImpLevel, pAuthInfo, Capabilities);
     return E_NOTIMPL;
 }
diff --git a/include/objidl.idl b/include/objidl.idl
index 95f4b9f..70f93ab 100644
--- a/include/objidl.idl
+++ b/include/objidl.idl
@@ -1950,8 +1950,8 @@ interface IClientSecurity : IUnknown
     void *pAuthInfo;
   } SOLE_AUTHENTICATION_INFO;
 
-  const OLECHAR *COLE_DEFAULT_PRINCIPAL = /*(OLECHAR*)*/ -1;
-  const void *COLE_DEFAULT_AUTHINFO = /*(void*)*/ -1;
+  const OLECHAR *COLE_DEFAULT_PRINCIPAL = (OLECHAR*) -1;
+  const void *COLE_DEFAULT_AUTHINFO = (void*) -1;
 
   typedef struct tagSOLE_AUTHENTICATION_LIST {
     DWORD cAuthInfo;
diff --git a/tools/widl/expr.c b/tools/widl/expr.c
index cfe672d..b528376 100644
--- a/tools/widl/expr.c
+++ b/tools/widl/expr.c
@@ -101,9 +101,16 @@ expr_t *make_exprs(enum expr_type type, char *val)
     return e;
 }
 
-expr_t *make_exprt(enum expr_type type, type_t *tref, expr_t *expr)
+expr_t *make_exprt(enum expr_type type, var_t *var, expr_t *expr)
 {
     expr_t *e;
+    type_t *tref;
+
+    if (var->stgclass != STG_NONE && var->stgclass != STG_REGISTER)
+        error_loc("invalid storage class for type expression\n");
+
+    tref = var->type;
+
     e = xmalloc(sizeof(expr_t));
     e->type = type;
     e->ref = expr;
@@ -125,6 +132,7 @@ expr_t *make_exprt(enum expr_type type, type_t *tref, expr_t *expr)
         e->is_const = TRUE;
         e->cval = expr->cval;
     }
+    free(var);
     return e;
 }
 
diff --git a/tools/widl/expr.h b/tools/widl/expr.h
index 31ce31d..e16975a 100644
--- a/tools/widl/expr.h
+++ b/tools/widl/expr.h
@@ -29,7 +29,7 @@ extern expr_t *make_expr(enum expr_type type);
 extern expr_t *make_exprl(enum expr_type type, long val);
 extern expr_t *make_exprd(enum expr_type type, double val);
 extern expr_t *make_exprs(enum expr_type type, char *val);
-extern expr_t *make_exprt(enum expr_type type, type_t *tref, expr_t *expr);
+extern expr_t *make_exprt(enum expr_type type, var_t *var, expr_t *expr);
 extern expr_t *make_expr1(enum expr_type type, expr_t *expr);
 extern expr_t *make_expr2(enum expr_type type, expr_t *exp1, expr_t *exp2);
 extern expr_t *make_expr3(enum expr_type type, expr_t *expr1, expr_t *expr2, expr_t *expr3);
diff --git a/tools/widl/parser.y b/tools/widl/parser.y
index 0c216ec..de44ab5 100644
--- a/tools/widl/parser.y
+++ b/tools/widl/parser.y
@@ -297,7 +297,8 @@ static statement_list_t *append_statement(statement_list_t *list, statement_t *s
 %type <var_list> fields ne_union_fields cases enums enum_list dispint_props field
 %type <var> m_ident ident
 %type <declarator> declarator direct_declarator init_declarator struct_declarator
-%type <declarator> m_any_declarator any_declarator any_declarator_no_ident any_direct_declarator
+%type <declarator> m_any_declarator any_declarator any_declarator_no_direct any_direct_declarator
+%type <declarator> m_abstract_declarator abstract_declarator abstract_declarator_no_direct abstract_direct_declarator
 %type <declarator_list> declarator_list struct_declarator_list
 %type <func> funcdef
 %type <type> coclass coclasshdr coclassdef
@@ -440,12 +441,12 @@ args:	  arg_list
 arg:	  attributes decl_spec m_any_declarator	{ if ($2->stgclass != STG_NONE && $2->stgclass != STG_REGISTER)
 						    error_loc("invalid storage class for function parameter\n");
 						  $$ = declare_var($1, $2, $3, TRUE);
-						  free($3);
+						  free($2); free($3);
 						}
 	| decl_spec m_any_declarator		{ if ($1->stgclass != STG_NONE && $1->stgclass != STG_REGISTER)
 						    error_loc("invalid storage class for function parameter\n");
 						  $$ = declare_var(NULL, $1, $2, TRUE);
-						  free($2);
+						  free($1); free($2);
 						}
 	;
 
@@ -659,8 +660,10 @@ expr:	  aNUM					{ $$ = make_exprl(EXPR_NUM, $1); }
 	| '*' expr %prec PPTR			{ $$ = make_expr1(EXPR_PPTR, $2); }
 	| expr MEMBERPTR aIDENTIFIER		{ $$ = make_expr2(EXPR_MEMBER, make_expr1(EXPR_PPTR, $1), make_exprs(EXPR_IDENTIFIER, $3)); }
 	| expr '.' aIDENTIFIER			{ $$ = make_expr2(EXPR_MEMBER, $1, make_exprs(EXPR_IDENTIFIER, $3)); }
-	| '(' type ')' expr %prec CAST		{ $$ = make_exprt(EXPR_CAST, $2, $4); }
-	| tSIZEOF '(' type ')'			{ $$ = make_exprt(EXPR_SIZEOF, $3, NULL); }
+	| '(' decl_spec m_abstract_declarator ')' expr %prec CAST
+						{ $$ = make_exprt(EXPR_CAST, declare_var(NULL, $2, $3, 0), $5); free($2); free($3); }
+	| tSIZEOF '(' decl_spec m_abstract_declarator ')'
+						{ $$ = make_exprt(EXPR_SIZEOF, declare_var(NULL, $3, $4, 0), NULL); free($3); free($4); }
 	| expr '[' expr ']'			{ $$ = make_expr2(EXPR_ARRAY, $1, $3); }
 	| '(' expr ')'				{ $$ = $2; }
 	;
@@ -942,6 +945,43 @@ direct_declarator:
 						}
 	;
 
+/* abstract declarator */
+abstract_declarator:
+	  '*' m_type_qual_list m_abstract_declarator %prec PPTR
+						{ $$ = $3; $$->type = append_ptrchain_type($$->type, type_new_pointer(pointer_default, NULL, $2)); }
+	| callconv m_abstract_declarator	{ $$ = $2; $$->type->attrs = append_attr($$->type->attrs, make_attrp(ATTR_CALLCONV, $1)); }
+	| abstract_direct_declarator
+	;
+
+/* abstract declarator without accepting direct declarator */
+abstract_declarator_no_direct:
+	  '*' m_type_qual_list m_any_declarator %prec PPTR
+						{ $$ = $3; $$->type = append_ptrchain_type($$->type, type_new_pointer(pointer_default, NULL, $2)); }
+	| callconv m_any_declarator		{ $$ = $2; $$->type->attrs = append_attr($$->type->attrs, make_attrp(ATTR_CALLCONV, $1)); }
+	;
+
+/* abstract declarator or empty */
+m_abstract_declarator: 				{ $$ = make_declarator(NULL); }
+	| abstract_declarator
+	;
+
+/* abstract direct declarator */
+abstract_direct_declarator:
+	  '(' abstract_declarator_no_direct ')'	{ $$ = $2; }
+	| abstract_direct_declarator array	{ $$ = $1; $$->array = append_array($$->array, $2); }
+	| array					{ $$ = make_declarator(NULL); $$->array = append_array($$->array, $1); }
+	| '(' m_args ')'
+						{ $$ = make_declarator(NULL);
+						  $$->func_type = append_ptrchain_type($$->type, type_new_function($2));
+						  $$->type = NULL;
+						}
+	| abstract_direct_declarator '(' m_args ')'
+						{ $$ = $1;
+						  $$->func_type = append_ptrchain_type($$->type, type_new_function($3));
+						  $$->type = NULL;
+						}
+	;
+
 /* abstract or non-abstract declarator */
 any_declarator:
 	  '*' m_type_qual_list m_any_declarator %prec PPTR
@@ -950,8 +990,8 @@ any_declarator:
 	| any_direct_declarator
 	;
 
-/* abstract or non-abstract declarator without accepting idents */
-any_declarator_no_ident:
+/* abstract or non-abstract declarator without accepting direct declarator */
+any_declarator_no_direct:
 	  '*' m_type_qual_list m_any_declarator %prec PPTR
 						{ $$ = $3; $$->type = append_ptrchain_type($$->type, type_new_pointer(pointer_default, NULL, $2)); }
 	| callconv m_any_declarator		{ $$ = $2; $$->type->attrs = append_attr($$->type->attrs, make_attrp(ATTR_CALLCONV, $1)); }
@@ -962,11 +1002,12 @@ m_any_declarator: 				{ $$ = make_declarator(NULL); }
 	| any_declarator
 	;
 
-/* abstract or non-abstract direct declarator. note: idents aren't accepted
- * inside brackets to avoid ambiguity with the rule for function arguments */
+/* abstract or non-abstract direct declarator. note: direct declarators
+ * aren't accepted inside brackets to avoid ambiguity with the rule for
+ * function arguments */
 any_direct_declarator:
 	  ident					{ $$ = make_declarator($1); }
-	| '(' any_declarator_no_ident ')'	{ $$ = $2; }
+	| '(' any_declarator_no_direct ')'	{ $$ = $2; }
 	| any_direct_declarator array		{ $$ = $1; $$->array = append_array($$->array, $2); }
 	| array					{ $$ = make_declarator(NULL); $$->array = append_array($$->array, $1); }
 	| '(' m_args ')'
@@ -1568,6 +1609,7 @@ static var_list_t *set_var_types(attr_list_t *attrs, decl_spec_t *decl_spec, dec
     var_list = append_var(var_list, var);
     free(decl);
   }
+  free(decl_spec);
   return var_list;
 }
 




More information about the wine-cvs mailing list