5 * Copyright 2002 Ove Kaaven
6 * Copyright 2006-2008 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
44 /* Berkeley yacc (byacc) doesn't seem to know about these */
45 /* Some *BSD supplied versions do define these though */
47 # define YYEMPTY (-1) /* Empty lookahead value of yychar */
50 # define YYLEX yylex()
53 #elif defined(YYBISON)
54 /* Bison was used for original development */
55 /* #define YYEMPTY -2 */
56 /* #define YYLEX yylex() */
59 /* No yacc we know yet */
60 # if !defined(YYEMPTY) || !defined(YYLEX)
61 # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
62 # elif defined(__GNUC__) /* gcc defines the #warning directive */
63 # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
64 /* #else we just take a chance that it works... */
68 #define YYERROR_VERBOSE
70 unsigned char pointer_default
= RPC_FC_UP
;
71 static int is_object_interface
= FALSE
;
72 /* are we inside a library block? */
73 static int is_inside_library
= FALSE
;
75 typedef
struct list typelist_t
;
81 typelist_t incomplete_types
= LIST_INIT
(incomplete_types
);
83 static void add_incomplete
(type_t
*t
);
84 static void fix_incomplete
(void);
86 static str_list_t
*append_str
(str_list_t
*list
, char *str
);
87 static attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
);
88 static attr_t
*make_attr
(enum attr_type type
);
89 static attr_t
*make_attrv
(enum attr_type type
, unsigned long val
);
90 static attr_t
*make_attrp
(enum attr_type type
, void *val
);
91 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
);
92 static array_dims_t
*append_array
(array_dims_t
*list
, expr_t
*expr
);
93 static void set_type
(var_t
*v
, type_t
*type
, const pident_t
*pident
, array_dims_t
*arr
, int top
);
94 static ifref_list_t
*append_ifref
(ifref_list_t
*list
, ifref_t
*iface
);
95 static ifref_t
*make_ifref
(type_t
*iface
);
96 static var_list_t
*append_var
(var_list_t
*list
, var_t
*var
);
97 static var_t
*make_var
(char *name
);
98 static pident_list_t
*append_pident
(pident_list_t
*list
, pident_t
*p
);
99 static pident_t
*make_pident
(var_t
*var
);
100 static func_list_t
*append_func
(func_list_t
*list
, func_t
*func
);
101 static func_t
*make_func
(var_t
*def
, var_list_t
*args
);
102 static type_t
*make_class
(char *name
);
103 static type_t
*make_safearray
(type_t
*type
);
104 static type_t
*make_builtin
(char *name
);
105 static type_t
*make_int
(int sign
);
107 static type_t
*reg_type
(type_t
*type
, const char *name
, int t
);
108 static type_t
*reg_typedefs
(type_t
*type
, var_list_t
*names
, attr_list_t
*attrs
);
109 static type_t
*find_type2
(char *name
, int t
);
110 static type_t
*get_type
(unsigned char type
, char *name
, int t
);
111 static type_t
*get_typev
(unsigned char type
, var_t
*name
, int t
);
112 static int get_struct_type
(var_list_t
*fields
);
114 static var_t
*reg_const
(var_t
*var
);
116 static void write_libid
(const char *name
, const attr_list_t
*attr
);
117 static void write_clsid
(type_t
*cls
);
118 static void write_diid
(type_t
*iface
);
119 static void write_iid
(type_t
*iface
);
121 static int compute_method_indexes
(type_t
*iface
);
122 static char *gen_name
(void);
123 static void process_typedefs
(var_list_t
*names
);
124 static void check_arg
(var_t
*arg
);
125 static void check_functions
(const type_t
*iface
);
126 static void check_all_user_types
(ifref_list_t
*ifaces
);
127 static const attr_list_t
*check_iface_attrs
(const char *name
, const attr_list_t
*attrs
);
128 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
);
129 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
);
130 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
);
131 static const attr_list_t
*check_library_attrs
(const char *name
, const attr_list_t
*attrs
);
132 static attr_list_t
*check_dispiface_attrs
(const char *name
, attr_list_t
*attrs
);
133 static const attr_list_t
*check_module_attrs
(const char *name
, const attr_list_t
*attrs
);
134 static const attr_list_t
*check_coclass_attrs
(const char *name
, const attr_list_t
*attrs
);
135 const char *get_attr_display_name
(enum attr_type type
);
136 static void add_explicit_handle_if_necessary
(func_t
*func
);
145 attr_list_t
*attr_list
;
146 str_list_t
*str_list
;
148 expr_list_t
*expr_list
;
149 array_dims_t
*array_dims
;
152 var_list_t
*var_list
;
154 pident_list_t
*pident_list
;
156 func_list_t
*func_list
;
158 ifref_list_t
*ifref_list
;
163 interface_info_t ifinfo
;
166 %token
<str
> aIDENTIFIER
167 %token
<str
> aKNOWNTYPE
168 %token
<num
> aNUM aHEXNUM
175 %token EQUALITY INEQUALITY
176 %token GREATEREQUAL LESSEQUAL
177 %token LOGICALOR LOGICALAND
178 %token tAGGREGATABLE tALLOCATE tAPPOBJECT tASYNC tASYNCUUID
179 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
180 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
181 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
182 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
184 %token tDEFAULTCOLLELEM
186 %token tDEFAULTVTABLE
188 %token tDISPINTERFACE
189 %token tDLLNAME tDOUBLE tDUAL
191 %token tENTRY tENUM tERRORSTATUST
192 %token tEXPLICITHANDLE tEXTERN
198 %token tHELPCONTEXT tHELPFILE
199 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
201 %token tHYPER tID tIDEMPOTENT
203 %token tIMMEDIATEBIND
204 %token tIMPLICITHANDLE
205 %token tIMPORT tIMPORTLIB
211 %token tLENGTHIS tLIBRARY
218 %token tNONEXTENSIBLE
219 %token tOBJECT tODL tOLEAUTOMATION
223 %token tPOINTERDEFAULT
225 %token tPROPGET tPROPPUT tPROPPUTREF
229 %token tREADONLY tREF
237 %token tSIZEIS tSIZEOF
241 %token tSTRICTCONTEXTHANDLE
242 %token tSTRING tSTRUCT
243 %token tSWITCH tSWITCHIS tSWITCHTYPE
255 %token tWCHAR tWIREMARSHAL
257 %type
<attr
> attribute
258 %type
<attr_list
> m_attributes attributes attrib_list
259 %type
<str_list
> str_list
260 %type
<expr
> m_expr expr expr_const
261 %type
<expr_list
> m_exprs
/* exprs expr_list */ expr_list_const
262 %type
<array_dims
> array array_list
263 %type
<ifinfo
> interfacehdr
264 %type
<type
> inherit interface interfacedef interfacedec
265 %type
<type
> dispinterface dispinterfacehdr dispinterfacedef
266 %type
<type
> module modulehdr moduledef
267 %type
<type
> base_type int_std
268 %type
<type
> enumdef structdef uniondef
270 %type
<ifref
> coclass_int
271 %type
<ifref_list
> gbl_statements coclass_ints
272 %type
<var
> arg field s_field case
enum constdef externdef
273 %type
<var_list
> m_args no_args args fields cases enums enum_list dispint_props
274 %type
<var
> m_ident t_ident ident
275 %type
<pident
> pident func_ident direct_ident
276 %type
<pident_list
> pident_list
278 %type
<func_list
> int_statements dispint_meths
279 %type
<type
> coclass coclasshdr coclassdef
280 %type
<num
> pointer_type version
281 %type
<str
> libraryhdr callconv
282 %type
<uuid
> uuid_string
283 %type
<num
> import_start
292 %left EQUALITY INEQUALITY
293 %left
'<' '>' LESSEQUAL GREATEREQUAL
297 %right
'!' '~' CAST PPTR POS NEG ADDRESSOF tSIZEOF
298 %left
'.' MEMBERPTR
'[' ']'
302 input: gbl_statements
{ fix_incomplete
();
303 check_all_user_types
($1);
311 gbl_statements: { $$
= NULL
; }
312 | gbl_statements interfacedec
{ $$
= $1; }
313 | gbl_statements interfacedef
{ $$
= append_ifref
( $1, make_ifref
($2) ); }
314 | gbl_statements coclass
';' { $$
= $1;
315 reg_type
($2, $2->name
, 0);
316 if
(!parse_only
&& do_header
) write_coclass_forward
($2);
318 | gbl_statements coclassdef
{ $$
= $1;
319 add_typelib_entry
($2);
320 reg_type
($2, $2->name
, 0);
321 if
(!parse_only
&& do_header
) write_coclass_forward
($2);
323 | gbl_statements moduledef
{ $$
= $1; add_typelib_entry
($2); }
324 | gbl_statements librarydef
{ $$
= $1; }
325 | gbl_statements statement
{ $$
= $1; }
329 | imp_statements interfacedec
{ if
(!parse_only
) add_typelib_entry
($2); }
330 | imp_statements interfacedef
{ if
(!parse_only
) add_typelib_entry
($2); }
331 | imp_statements coclass
';' { reg_type
($2, $2->name
, 0); if
(!parse_only
&& do_header
) write_coclass_forward
($2); }
332 | imp_statements coclassdef
{ if
(!parse_only
) add_typelib_entry
($2);
333 reg_type
($2, $2->name
, 0);
334 if
(!parse_only
&& do_header
) write_coclass_forward
($2);
336 | imp_statements moduledef
{ if
(!parse_only
) add_typelib_entry
($2); }
337 | imp_statements statement
{}
338 | imp_statements importlib
{}
339 | imp_statements librarydef
{}
342 int_statements: { $$
= NULL
; }
343 | int_statements funcdef
';' { $$
= append_func
( $1, $2 ); }
344 | int_statements statement
{ $$
= $1; }
351 statement: constdef
';' { if
(!parse_only
&& do_header
) { write_constdef
($1); } }
353 | enumdef
';' { if
(!parse_only
&& do_header
) {
354 write_type_def_or_decl
(header
, $1, FALSE
, NULL
);
355 fprintf
(header
, ";\n\n");
358 | externdef
';' { if
(!parse_only
&& do_header
) { write_externdef
($1); } }
360 | structdef
';' { if
(!parse_only
&& do_header
) {
361 write_type_def_or_decl
(header
, $1, FALSE
, NULL
);
362 fprintf
(header
, ";\n\n");
366 | uniondef
';' { if
(!parse_only
&& do_header
) {
367 write_type_def_or_decl
(header
, $1, FALSE
, NULL
);
368 fprintf
(header
, ";\n\n");
373 cppquote: tCPPQUOTE
'(' aSTRING
')' { if
(!parse_only
&& do_header
) fprintf
(header
, "%s\n", $3); }
375 import_start: tIMPORT aSTRING
';' { assert
(yychar == YYEMPTY
);
377 if
(!$$
) yychar = aEOF
;
381 import: import_start imp_statements aEOF
382 { if
($1) pop_import
(); }
385 importlib: tIMPORTLIB
'(' aSTRING
')'
386 semicolon_opt
{ if
(!parse_only
) add_importlib
($3); }
389 libraryhdr: tLIBRARY aIDENTIFIER
{ $$
= $2; }
391 library_start: attributes libraryhdr
'{' { check_library_attrs
($2, $1);
392 if
(!parse_only
) start_typelib
($2, $1);
393 if
(!parse_only
&& do_header
) write_library
($2, $1);
394 if
(!parse_only
&& do_idfile
) write_libid
($2, $1);
395 is_inside_library
= TRUE
;
398 librarydef: library_start imp_statements
'}'
399 semicolon_opt
{ if
(!parse_only
) end_typelib
(); is_inside_library
= FALSE
; }
402 m_args: { $$
= NULL
; }
406 no_args: tVOID
{ $$
= NULL
; }
409 args: arg
{ check_arg
($1); $$
= append_var
( NULL
, $1 ); }
410 | args
',' arg
{ check_arg
($3); $$
= append_var
( $1, $3); }
414 /* split into two rules to get bison to resolve a tVOID conflict */
415 arg: attributes type pident array
{ $$
= $3->var
;
417 set_type
($$
, $2, $3, $4, TRUE
);
420 | type pident array
{ $$
= $2->var
;
421 set_type
($$
, $1, $2, $3, TRUE
);
426 array: { $$
= NULL
; }
427 |
'[' array_list
']' { $$
= $2; }
428 |
'[' '*' ']' { $$
= append_array
( NULL
, make_expr
(EXPR_VOID
) ); }
431 array_list: m_expr
/* size of first dimension is optional */ { $$
= append_array
( NULL
, $1 ); }
432 | array_list
',' expr
{ $$
= append_array
( $1, $3 ); }
433 | array_list
']' '[' expr
{ $$
= append_array
( $1, $4 ); }
436 m_attributes: { $$
= NULL
; }
441 '[' attrib_list
']' { $$
= $2;
443 error_loc
("empty attribute lists unsupported\n");
447 attrib_list: attribute
{ $$
= append_attr
( NULL
, $1 ); }
448 | attrib_list
',' attribute
{ $$
= append_attr
( $1, $3 ); }
449 | attrib_list
']' '[' attribute
{ $$
= append_attr
( $1, $4 ); }
452 str_list: aSTRING
{ $$
= append_str
( NULL
, $1 ); }
453 | str_list
',' aSTRING
{ $$
= append_str
( $1, $3 ); }
456 attribute: { $$
= NULL
; }
457 | tAGGREGATABLE
{ $$
= make_attr
(ATTR_AGGREGATABLE
); }
458 | tAPPOBJECT
{ $$
= make_attr
(ATTR_APPOBJECT
); }
459 | tASYNC
{ $$
= make_attr
(ATTR_ASYNC
); }
460 | tAUTOHANDLE
{ $$
= make_attr
(ATTR_AUTO_HANDLE
); }
461 | tBINDABLE
{ $$
= make_attr
(ATTR_BINDABLE
); }
462 | tBROADCAST
{ $$
= make_attr
(ATTR_BROADCAST
); }
463 | tCALLAS
'(' ident
')' { $$
= make_attrp
(ATTR_CALLAS
, $3); }
464 | tCASE
'(' expr_list_const
')' { $$
= make_attrp
(ATTR_CASE
, $3); }
465 | tCONTEXTHANDLE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); }
466 | tCONTEXTHANDLENOSERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
467 | tCONTEXTHANDLESERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
468 | tCONTROL
{ $$
= make_attr
(ATTR_CONTROL
); }
469 | tDEFAULT
{ $$
= make_attr
(ATTR_DEFAULT
); }
470 | tDEFAULTCOLLELEM
{ $$
= make_attr
(ATTR_DEFAULTCOLLELEM
); }
471 | tDEFAULTVALUE
'(' expr_const
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE_EXPR
, $3); }
472 | tDEFAULTVALUE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE_STRING
, $3); }
473 | tDEFAULTVTABLE
{ $$
= make_attr
(ATTR_DEFAULTVTABLE
); }
474 | tDISPLAYBIND
{ $$
= make_attr
(ATTR_DISPLAYBIND
); }
475 | tDLLNAME
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DLLNAME
, $3); }
476 | tDUAL
{ $$
= make_attr
(ATTR_DUAL
); }
477 | tENDPOINT
'(' str_list
')' { $$
= make_attrp
(ATTR_ENDPOINT
, $3); }
478 | tENTRY
'(' aSTRING
')' { $$
= make_attrp
(ATTR_ENTRY_STRING
, $3); }
479 | tENTRY
'(' expr_const
')' { $$
= make_attrp
(ATTR_ENTRY_ORDINAL
, $3); }
480 | tEXPLICITHANDLE
{ $$
= make_attr
(ATTR_EXPLICIT_HANDLE
); }
481 | tHANDLE
{ $$
= make_attr
(ATTR_HANDLE
); }
482 | tHELPCONTEXT
'(' expr_const
')' { $$
= make_attrp
(ATTR_HELPCONTEXT
, $3); }
483 | tHELPFILE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPFILE
, $3); }
484 | tHELPSTRING
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRING
, $3); }
485 | tHELPSTRINGCONTEXT
'(' expr_const
')' { $$
= make_attrp
(ATTR_HELPSTRINGCONTEXT
, $3); }
486 | tHELPSTRINGDLL
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRINGDLL
, $3); }
487 | tHIDDEN
{ $$
= make_attr
(ATTR_HIDDEN
); }
488 | tID
'(' expr_const
')' { $$
= make_attrp
(ATTR_ID
, $3); }
489 | tIDEMPOTENT
{ $$
= make_attr
(ATTR_IDEMPOTENT
); }
490 | tIIDIS
'(' expr
')' { $$
= make_attrp
(ATTR_IIDIS
, $3); }
491 | tIMMEDIATEBIND
{ $$
= make_attr
(ATTR_IMMEDIATEBIND
); }
492 | tIMPLICITHANDLE
'(' tHANDLET aIDENTIFIER
')' { $$
= make_attrp
(ATTR_IMPLICIT_HANDLE
, $4); }
493 | tIN
{ $$
= make_attr
(ATTR_IN
); }
494 | tINPUTSYNC
{ $$
= make_attr
(ATTR_INPUTSYNC
); }
495 | tLENGTHIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_LENGTHIS
, $3); }
496 | tLOCAL
{ $$
= make_attr
(ATTR_LOCAL
); }
497 | tNONBROWSABLE
{ $$
= make_attr
(ATTR_NONBROWSABLE
); }
498 | tNONCREATABLE
{ $$
= make_attr
(ATTR_NONCREATABLE
); }
499 | tNONEXTENSIBLE
{ $$
= make_attr
(ATTR_NONEXTENSIBLE
); }
500 | tOBJECT
{ $$
= make_attr
(ATTR_OBJECT
); }
501 | tODL
{ $$
= make_attr
(ATTR_ODL
); }
502 | tOLEAUTOMATION
{ $$
= make_attr
(ATTR_OLEAUTOMATION
); }
503 | tOPTIONAL
{ $$
= make_attr
(ATTR_OPTIONAL
); }
504 | tOUT
{ $$
= make_attr
(ATTR_OUT
); }
505 | tPOINTERDEFAULT
'(' pointer_type
')' { $$
= make_attrv
(ATTR_POINTERDEFAULT
, $3); }
506 | tPROPGET
{ $$
= make_attr
(ATTR_PROPGET
); }
507 | tPROPPUT
{ $$
= make_attr
(ATTR_PROPPUT
); }
508 | tPROPPUTREF
{ $$
= make_attr
(ATTR_PROPPUTREF
); }
509 | tPUBLIC
{ $$
= make_attr
(ATTR_PUBLIC
); }
510 | tRANGE
'(' expr_const
',' expr_const
')' { expr_list_t
*list
= append_expr
( NULL
, $3 );
511 list
= append_expr
( list
, $5 );
512 $$
= make_attrp
(ATTR_RANGE
, list
); }
513 | tREADONLY
{ $$
= make_attr
(ATTR_READONLY
); }
514 | tREQUESTEDIT
{ $$
= make_attr
(ATTR_REQUESTEDIT
); }
515 | tRESTRICTED
{ $$
= make_attr
(ATTR_RESTRICTED
); }
516 | tRETVAL
{ $$
= make_attr
(ATTR_RETVAL
); }
517 | tSIZEIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_SIZEIS
, $3); }
518 | tSOURCE
{ $$
= make_attr
(ATTR_SOURCE
); }
519 | tSTRICTCONTEXTHANDLE
{ $$
= make_attr
(ATTR_STRICTCONTEXTHANDLE
); }
520 | tSTRING
{ $$
= make_attr
(ATTR_STRING
); }
521 | tSWITCHIS
'(' expr
')' { $$
= make_attrp
(ATTR_SWITCHIS
, $3); }
522 | tSWITCHTYPE
'(' type
')' { $$
= make_attrp
(ATTR_SWITCHTYPE
, $3); }
523 | tTRANSMITAS
'(' type
')' { $$
= make_attrp
(ATTR_TRANSMITAS
, $3); }
524 | tUUID
'(' uuid_string
')' { $$
= make_attrp
(ATTR_UUID
, $3); }
525 | tV1ENUM
{ $$
= make_attr
(ATTR_V1ENUM
); }
526 | tVARARG
{ $$
= make_attr
(ATTR_VARARG
); }
527 | tVERSION
'(' version
')' { $$
= make_attrv
(ATTR_VERSION
, $3); }
528 | tWIREMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_WIREMARSHAL
, $3); }
529 | pointer_type
{ $$
= make_attrv
(ATTR_POINTERTYPE
, $1); }
534 | aSTRING
{ if
(!is_valid_uuid
($1))
535 error_loc
("invalid UUID: %s\n", $1);
536 $$
= parse_uuid
($1); }
539 callconv: tCDECL
{ $$
= $
<str
>1; }
540 | tFASTCALL
{ $$
= $
<str
>1; }
541 | tPASCAL
{ $$
= $
<str
>1; }
542 | tSTDCALL
{ $$
= $
<str
>1; }
545 cases: { $$
= NULL
; }
546 | cases case
{ $$
= append_var
( $1, $2 ); }
549 case: tCASE expr_const
':' field
{ attr_t
*a
= make_attrp
(ATTR_CASE
, append_expr
( NULL
, $2 ));
550 $$
= $4; if
(!$$
) $$
= make_var
(NULL
);
551 $$
->attrs
= append_attr
( $$
->attrs
, a
);
553 | tDEFAULT
':' field
{ attr_t
*a
= make_attr
(ATTR_DEFAULT
);
554 $$
= $3; if
(!$$
) $$
= make_var
(NULL
);
555 $$
->attrs
= append_attr
( $$
->attrs
, a
);
559 constdef: tCONST type ident
'=' expr_const
{ $$
= reg_const
($3);
560 set_type
($$
, $2, NULL
, NULL
, FALSE
);
565 enums: { $$
= NULL
; }
566 | enum_list
',' { $$
= $1; }
570 enum_list: enum { if
(!$1->eval
)
571 $1->eval
= make_exprl
(EXPR_NUM
, 0 /* default for first enum entry */);
572 $$
= append_var
( NULL
, $1 );
574 | enum_list
',' enum { if
(!$3->eval
)
576 var_t
*last
= LIST_ENTRY
( list_tail
($$
), var_t
, entry
);
577 $3->eval
= make_exprl
(EXPR_NUM
, last
->eval
->cval
+ 1);
579 $$
= append_var
( $1, $3 );
583 enum: ident
'=' expr_const
{ $$
= reg_const
($1);
585 $$
->type
= make_int
(0);
587 | ident
{ $$
= reg_const
($1);
588 $$
->type
= make_int
(0);
592 enumdef: tENUM t_ident
'{' enums
'}' { $$
= get_typev
(RPC_FC_ENUM16
, $2, tsENUM
);
593 $$
->kind
= TKIND_ENUM
;
594 $$
->fields_or_args
= $4;
597 add_typelib_entry
($$
);
601 m_exprs: m_expr
{ $$
= append_expr
( NULL
, $1 ); }
602 | m_exprs
',' m_expr
{ $$
= append_expr
( $1, $3 ); }
606 exprs: { $$ = make_expr(EXPR_VOID); }
611 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
615 m_expr: { $$
= make_expr
(EXPR_VOID
); }
619 expr: aNUM
{ $$
= make_exprl
(EXPR_NUM
, $1); }
620 | aHEXNUM
{ $$
= make_exprl
(EXPR_HEXNUM
, $1); }
621 | aDOUBLE
{ $$
= make_exprd
(EXPR_DOUBLE
, $1); }
622 | tFALSE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 0); }
623 | tTRUE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 1); }
624 | aIDENTIFIER
{ $$
= make_exprs
(EXPR_IDENTIFIER
, $1); }
625 | expr
'?' expr
':' expr
{ $$
= make_expr3
(EXPR_COND
, $1, $3, $5); }
626 | expr LOGICALOR expr
{ $$
= make_expr2
(EXPR_LOGOR
, $1, $3); }
627 | expr LOGICALAND expr
{ $$
= make_expr2
(EXPR_LOGAND
, $1, $3); }
628 | expr
'|' expr
{ $$
= make_expr2
(EXPR_OR
, $1, $3); }
629 | expr
'^' expr
{ $$
= make_expr2
(EXPR_XOR
, $1, $3); }
630 | expr
'&' expr
{ $$
= make_expr2
(EXPR_AND
, $1, $3); }
631 | expr EQUALITY expr
{ $$
= make_expr2
(EXPR_EQUALITY
, $1, $3); }
632 | expr INEQUALITY expr
{ $$
= make_expr2
(EXPR_INEQUALITY
, $1, $3); }
633 | expr
'>' expr
{ $$
= make_expr2
(EXPR_GTR
, $1, $3); }
634 | expr
'<' expr
{ $$
= make_expr2
(EXPR_LESS
, $1, $3); }
635 | expr GREATEREQUAL expr
{ $$
= make_expr2
(EXPR_GTREQL
, $1, $3); }
636 | expr LESSEQUAL expr
{ $$
= make_expr2
(EXPR_LESSEQL
, $1, $3); }
637 | expr SHL expr
{ $$
= make_expr2
(EXPR_SHL
, $1, $3); }
638 | expr SHR expr
{ $$
= make_expr2
(EXPR_SHR
, $1, $3); }
639 | expr
'+' expr
{ $$
= make_expr2
(EXPR_ADD
, $1, $3); }
640 | expr
'-' expr
{ $$
= make_expr2
(EXPR_SUB
, $1, $3); }
641 | expr
'%' expr
{ $$
= make_expr2
(EXPR_MOD
, $1, $3); }
642 | expr
'*' expr
{ $$
= make_expr2
(EXPR_MUL
, $1, $3); }
643 | expr
'/' expr
{ $$
= make_expr2
(EXPR_DIV
, $1, $3); }
644 |
'!' expr
{ $$
= make_expr1
(EXPR_LOGNOT
, $2); }
645 |
'~' expr
{ $$
= make_expr1
(EXPR_NOT
, $2); }
646 |
'+' expr %prec POS
{ $$
= make_expr1
(EXPR_POS
, $2); }
647 |
'-' expr %prec NEG
{ $$
= make_expr1
(EXPR_NEG
, $2); }
648 |
'&' expr %prec ADDRESSOF
{ $$
= make_expr1
(EXPR_ADDRESSOF
, $2); }
649 |
'*' expr %prec PPTR
{ $$
= make_expr1
(EXPR_PPTR
, $2); }
650 | expr MEMBERPTR aIDENTIFIER
{ $$
= make_expr2
(EXPR_MEMBER
, make_expr1
(EXPR_PPTR
, $1), make_exprs
(EXPR_IDENTIFIER
, $3)); }
651 | expr
'.' aIDENTIFIER
{ $$
= make_expr2
(EXPR_MEMBER
, $1, make_exprs
(EXPR_IDENTIFIER
, $3)); }
652 |
'(' type
')' expr %prec CAST
{ $$
= make_exprt
(EXPR_CAST
, $2, $4); }
653 | tSIZEOF
'(' type
')' { $$
= make_exprt
(EXPR_SIZEOF
, $3, NULL
); }
654 | expr
'[' expr
']' { $$
= make_expr2
(EXPR_ARRAY
, $1, $3); }
655 |
'(' expr
')' { $$
= $2; }
658 expr_list_const: expr_const
{ $$
= append_expr
( NULL
, $1 ); }
659 | expr_list_const
',' expr_const
{ $$
= append_expr
( $1, $3 ); }
662 expr_const: expr
{ $$
= $1;
664 error_loc
("expression is not constant\n");
668 externdef: tEXTERN tCONST type ident
{ $$
= $4;
669 set_type
($$
, $3, NULL
, NULL
, FALSE
);
673 fields: { $$
= NULL
; }
674 | fields field
{ $$
= append_var
( $1, $2 ); }
677 field: s_field
';' { $$
= $1; }
678 | m_attributes uniondef
';' { $$
= make_var
(NULL
); $$
->type
= $2; $$
->attrs
= $1; }
679 | attributes
';' { $$
= make_var
(NULL
); $$
->attrs
= $1; }
683 s_field: m_attributes type pident array
{ $$
= $3->var
;
684 $$
->attrs
= check_field_attrs
($$
->name
, $1);
685 set_type
($$
, $2, $3, $4, FALSE
);
691 m_attributes type pident
{ var_t
*v
= $3->var
;
692 var_list_t
*args
= $3->args
;
693 v
->attrs
= check_function_attrs
(v
->name
, $1);
694 set_type
(v
, $2, $3, NULL
, FALSE
);
696 $$
= make_func
(v
, args
);
700 m_ident: { $$
= NULL
; }
704 t_ident: { $$
= NULL
; }
705 | aIDENTIFIER
{ $$
= make_var
($1); }
706 | aKNOWNTYPE
{ $$
= make_var
($1); }
709 ident: aIDENTIFIER
{ $$
= make_var
($1); }
710 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
711 | aKNOWNTYPE
{ $$
= make_var
($
<str
>1); }
714 base_type: tBYTE
{ $$
= make_builtin
($
<str
>1); }
715 | tWCHAR
{ $$
= make_builtin
($
<str
>1); }
717 | tSIGNED int_std
{ $$
= $2; $$
->sign
= 1; }
718 | tUNSIGNED int_std
{ $$
= $2; $$
->sign
= -1;
720 case RPC_FC_CHAR
: break
;
721 case RPC_FC_SMALL
: $$
->type
= RPC_FC_USMALL
; break
;
722 case RPC_FC_SHORT
: $$
->type
= RPC_FC_USHORT
; break
;
723 case RPC_FC_LONG
: $$
->type
= RPC_FC_ULONG
; break
;
725 if
($$
->name
[0] == 'h') /* hyper, as opposed to __int64 */
727 $$
= alias
($$
, "MIDL_uhyper");
734 | tUNSIGNED
{ $$
= make_int
(-1); }
735 | tFLOAT
{ $$
= make_builtin
($
<str
>1); }
736 | tSINGLE
{ $$
= duptype
(find_type
("float", 0), 1); }
737 | tDOUBLE
{ $$
= make_builtin
($
<str
>1); }
738 | tBOOLEAN
{ $$
= make_builtin
($
<str
>1); }
739 | tERRORSTATUST
{ $$
= make_builtin
($
<str
>1); }
740 | tHANDLET
{ $$
= make_builtin
($
<str
>1); }
747 int_std: tINT
{ $$
= make_builtin
($
<str
>1); }
748 | tSHORT m_int
{ $$
= make_builtin
($
<str
>1); }
749 | tSMALL
{ $$
= make_builtin
($
<str
>1); }
750 | tLONG m_int
{ $$
= make_builtin
($
<str
>1); }
751 | tHYPER m_int
{ $$
= make_builtin
($
<str
>1); }
752 | tINT64
{ $$
= make_builtin
($
<str
>1); }
753 | tCHAR
{ $$
= make_builtin
($
<str
>1); }
756 coclass: tCOCLASS aIDENTIFIER
{ $$
= make_class
($2); }
757 | tCOCLASS aKNOWNTYPE
{ $$
= find_type
($2, 0);
758 if
($$
->defined
) error_loc
("multiple definition error\n");
759 if
($$
->kind
!= TKIND_COCLASS
) error_loc
("%s was not declared a coclass\n", $2);
763 coclasshdr: attributes coclass
{ $$
= $2;
764 $$
->attrs
= check_coclass_attrs
($2->name
, $1);
765 if
(!parse_only
&& do_header
)
767 if
(!parse_only
&& do_idfile
)
772 coclassdef: coclasshdr
'{' coclass_ints
'}' semicolon_opt
779 coclass_ints: { $$
= NULL
; }
780 | coclass_ints coclass_int
{ $$
= append_ifref
( $1, $2 ); }
784 m_attributes interfacedec
{ $$
= make_ifref
($2); $$
->attrs
= $1; }
787 dispinterface: tDISPINTERFACE aIDENTIFIER
{ $$
= get_type
(0, $2, 0); $$
->kind
= TKIND_DISPATCH
; }
788 | tDISPINTERFACE aKNOWNTYPE
{ $$
= get_type
(0, $2, 0); $$
->kind
= TKIND_DISPATCH
; }
791 dispinterfacehdr: attributes dispinterface
{ attr_t
*attrs
;
792 is_object_interface
= TRUE
;
794 if
($$
->defined
) error_loc
("multiple definition error\n");
795 attrs
= make_attr
(ATTR_DISPINTERFACE
);
796 $$
->attrs
= append_attr
( check_dispiface_attrs
($2->name
, $1), attrs
);
797 $$
->ref
= find_type
("IDispatch", 0);
798 if
(!$$
->ref
) error_loc
("IDispatch is undefined\n");
800 if
(!parse_only
&& do_header
) write_forward
($$
);
804 dispint_props: tPROPERTIES
':' { $$
= NULL
; }
805 | dispint_props s_field
';' { $$
= append_var
( $1, $2 ); }
808 dispint_meths: tMETHODS
':' { $$
= NULL
; }
809 | dispint_meths funcdef
';' { $$
= append_func
( $1, $2 ); }
812 dispinterfacedef: dispinterfacehdr
'{'
816 $$
->fields_or_args
= $3;
818 if
(!parse_only
&& do_header
) write_dispinterface
($$
);
819 if
(!parse_only
&& do_idfile
) write_diid
($$
);
822 '{' interface
';' '}' { $$
= $1;
823 $$
->fields_or_args
= $3->fields_or_args
;
824 $$
->funcs
= $3->funcs
;
825 if
(!parse_only
&& do_header
) write_dispinterface
($$
);
826 if
(!parse_only
&& do_idfile
) write_diid
($$
);
830 inherit: { $$
= NULL
; }
831 |
':' aKNOWNTYPE
{ $$
= find_type2
($2, 0); }
834 interface: tINTERFACE aIDENTIFIER
{ $$
= get_type
(RPC_FC_IP
, $2, 0); $$
->kind
= TKIND_INTERFACE
; }
835 | tINTERFACE aKNOWNTYPE
{ $$
= get_type
(RPC_FC_IP
, $2, 0); $$
->kind
= TKIND_INTERFACE
; }
838 interfacehdr: attributes interface
{ $$.interface
= $2;
839 $$.old_pointer_default
= pointer_default
;
840 if
(is_attr
($1, ATTR_POINTERDEFAULT
))
841 pointer_default
= get_attrv
($1, ATTR_POINTERDEFAULT
);
842 is_object_interface
= is_object
($1);
843 if
($2->defined
) error_loc
("multiple definition error\n");
844 $2->attrs
= check_iface_attrs
($2->name
, $1);
846 if
(!parse_only
&& do_header
) write_forward
($2);
850 interfacedef: interfacehdr inherit
851 '{' int_statements
'}' semicolon_opt
{ $$
= $1.interface
;
855 compute_method_indexes
($$
);
856 if
(!parse_only
&& do_header
) write_interface
($$
);
857 if
(!parse_only
&& local_stubs
) write_locals
(local_stubs
, $$
, TRUE
);
858 if
(!parse_only
&& do_idfile
) write_iid
($$
);
859 pointer_default
= $1.old_pointer_default
;
861 /* MIDL is able to import the definition of a base class from inside the
862 * definition of a derived class, I'll try to support it with this rule */
863 | interfacehdr
':' aIDENTIFIER
864 '{' import int_statements
'}'
865 semicolon_opt
{ $$
= $1.interface
;
866 $$
->ref
= find_type2
($3, 0);
867 if
(!$$
->ref
) error_loc
("base class '%s' not found in import\n", $3);
869 compute_method_indexes
($$
);
870 if
(!parse_only
&& do_header
) write_interface
($$
);
871 if
(!parse_only
&& local_stubs
) write_locals
(local_stubs
, $$
, TRUE
);
872 if
(!parse_only
&& do_idfile
) write_iid
($$
);
873 pointer_default
= $1.old_pointer_default
;
875 | dispinterfacedef semicolon_opt
{ $$
= $1; }
879 interface
';' { $$
= $1; if
(!parse_only
&& do_header
) write_forward
($$
); }
880 | dispinterface
';' { $$
= $1; if
(!parse_only
&& do_header
) write_forward
($$
); }
883 module: tMODULE aIDENTIFIER
{ $$
= make_type
(0, NULL
); $$
->name
= $2; $$
->kind
= TKIND_MODULE
; }
884 | tMODULE aKNOWNTYPE
{ $$
= make_type
(0, NULL
); $$
->name
= $2; $$
->kind
= TKIND_MODULE
; }
887 modulehdr: attributes module
{ $$
= $2;
888 $$
->attrs
= check_module_attrs
($2->name
, $1);
892 moduledef: modulehdr
'{' int_statements
'}'
893 semicolon_opt
{ $$
= $1;
895 /* FIXME: if (!parse_only && do_header) write_module($$); */
899 pident: '*' pident %prec PPTR
{ $$
= $2; $$
->ptr_level
++; }
900 | tCONST pident
{ $$
= $2; /* FIXME */ }
901 | callconv pident
{ $$
= $2;
902 if
($$
->callconv
) parser_warning
("multiple calling conventions %s, %s for function %s\n", $$
->callconv
, $1, $$
->var
->name
);
908 func_ident: direct_ident
'(' m_args
')'
915 direct_ident: ident
{ $$
= make_pident
($1); }
916 |
'(' pident
')' { $$
= $2; }
917 | func_ident
{ $$
= $1;
918 $$
->func_ptr_level
= $$
->ptr_level
;
924 pident
{ $$
= append_pident
( NULL
, $1 ); }
925 | pident_list
',' pident
{ $$
= append_pident
( $1, $3 ); }
929 tREF
{ $$
= RPC_FC_RP
; }
930 | tUNIQUE
{ $$
= RPC_FC_UP
; }
931 | tPTR
{ $$
= RPC_FC_FP
; }
934 structdef: tSTRUCT t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_STRUCT
, $2, tsSTRUCT
);
935 /* overwrite RPC_FC_STRUCT with a more exact type */
936 $$
->type
= get_struct_type
( $4 );
937 $$
->kind
= TKIND_RECORD
;
938 $$
->fields_or_args
= $4;
941 add_typelib_entry
($$
);
945 type: tVOID
{ $$
= duptype
(find_type
("void", 0), 1); }
946 | aKNOWNTYPE
{ $$
= find_type
($1, 0); }
947 | base_type
{ $$
= $1; }
948 | tCONST type
{ $$
= duptype
($2, 1); $$
->is_const
= TRUE
; }
949 | enumdef
{ $$
= $1; }
950 | tENUM aIDENTIFIER
{ $$
= find_type2
($2, tsENUM
); }
951 | structdef
{ $$
= $1; }
952 | tSTRUCT aIDENTIFIER
{ $$
= get_type
(RPC_FC_STRUCT
, $2, tsSTRUCT
); }
953 | uniondef
{ $$
= $1; }
954 | tUNION aIDENTIFIER
{ $$
= find_type2
($2, tsUNION
); }
955 | tSAFEARRAY
'(' type
')' { $$
= make_safearray
($3); }
958 typedef: tTYPEDEF m_attributes type pident_list
{ reg_typedefs
($3, $4, check_typedef_attrs
($2));
959 process_typedefs
($4);
963 uniondef: tUNION t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_NON_ENCAPSULATED_UNION
, $2, tsUNION
);
964 $$
->kind
= TKIND_UNION
;
965 $$
->fields_or_args
= $4;
969 tSWITCH
'(' s_field
')'
970 m_ident
'{' cases
'}' { var_t
*u
= $7;
971 $$
= get_typev
(RPC_FC_ENCAPSULATED_UNION
, $2, tsUNION
);
972 $$
->kind
= TKIND_UNION
;
973 if
(!u
) u
= make_var
( xstrdup
("tagged_union") );
974 u
->type
= make_type
(RPC_FC_NON_ENCAPSULATED_UNION
, NULL
);
975 u
->type
->kind
= TKIND_UNION
;
976 u
->type
->fields_or_args
= $9;
977 u
->type
->defined
= TRUE
;
978 $$
->fields_or_args
= append_var
( $$
->fields_or_args
, $5 );
979 $$
->fields_or_args
= append_var
( $$
->fields_or_args
, u
);
985 aNUM
{ $$
= MAKEVERSION
($1, 0); }
986 | aNUM
'.' aNUM
{ $$
= MAKEVERSION
($1, $3); }
991 static void decl_builtin
(const char *name
, unsigned char type
)
993 type_t
*t
= make_type
(type
, NULL
);
994 t
->name
= xstrdup
(name
);
995 reg_type
(t
, name
, 0);
998 static type_t
*make_builtin
(char *name
)
1000 /* NAME is strdup'd in the lexer */
1001 type_t
*t
= duptype
(find_type
(name
, 0), 0);
1006 static type_t
*make_int
(int sign
)
1008 type_t
*t
= duptype
(find_type
("int", 0), 1);
1012 t
->type
= t
->type
== RPC_FC_LONG ? RPC_FC_ULONG
: RPC_FC_USHORT
;
1017 void init_types
(void)
1019 decl_builtin
("void", 0);
1020 decl_builtin
("byte", RPC_FC_BYTE
);
1021 decl_builtin
("wchar_t", RPC_FC_WCHAR
);
1022 decl_builtin
("int", RPC_FC_LONG
); /* win32 */
1023 decl_builtin
("short", RPC_FC_SHORT
);
1024 decl_builtin
("small", RPC_FC_SMALL
);
1025 decl_builtin
("long", RPC_FC_LONG
);
1026 decl_builtin
("hyper", RPC_FC_HYPER
);
1027 decl_builtin
("__int64", RPC_FC_HYPER
);
1028 decl_builtin
("char", RPC_FC_CHAR
);
1029 decl_builtin
("float", RPC_FC_FLOAT
);
1030 decl_builtin
("double", RPC_FC_DOUBLE
);
1031 decl_builtin
("boolean", RPC_FC_BYTE
);
1032 decl_builtin
("error_status_t", RPC_FC_ERROR_STATUS_T
);
1033 decl_builtin
("handle_t", RPC_FC_BIND_PRIMITIVE
);
1036 static str_list_t
*append_str
(str_list_t
*list
, char *str
)
1038 struct str_list_entry_t
*entry
;
1040 if
(!str
) return list
;
1043 list
= xmalloc
( sizeof
(*list
) );
1046 entry
= xmalloc
( sizeof
(*entry
) );
1048 list_add_tail
( list
, &entry
->entry
);
1052 static attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
)
1054 attr_t
*attr_existing
;
1055 if
(!attr
) return list
;
1058 list
= xmalloc
( sizeof
(*list
) );
1061 LIST_FOR_EACH_ENTRY
(attr_existing
, list
, attr_t
, entry
)
1062 if
(attr_existing
->type
== attr
->type
)
1064 parser_warning
("duplicate attribute %s\n", get_attr_display_name
(attr
->type
));
1065 /* use the last attribute, like MIDL does */
1066 list_remove
(&attr_existing
->entry
);
1069 list_add_tail
( list
, &attr
->entry
);
1073 static attr_t
*make_attr
(enum attr_type type
)
1075 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1081 static attr_t
*make_attrv
(enum attr_type type
, unsigned long val
)
1083 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1089 static attr_t
*make_attrp
(enum attr_type type
, void *val
)
1091 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1097 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
)
1099 if
(!expr
) return list
;
1102 list
= xmalloc
( sizeof
(*list
) );
1105 list_add_tail
( list
, &expr
->entry
);
1109 static array_dims_t
*append_array
(array_dims_t
*list
, expr_t
*expr
)
1111 if
(!expr
) return list
;
1114 list
= xmalloc
( sizeof
(*list
) );
1117 list_add_tail
( list
, &expr
->entry
);
1121 static struct list type_pool
= LIST_INIT
(type_pool
);
1128 type_t
*alloc_type
(void)
1130 type_pool_node_t
*node
= xmalloc
(sizeof
*node
);
1131 list_add_tail
(&type_pool
, &node
->link
);
1135 void set_all_tfswrite
(int val
)
1137 type_pool_node_t
*node
;
1138 LIST_FOR_EACH_ENTRY
(node
, &type_pool
, type_pool_node_t
, link
)
1139 node
->data.tfswrite
= val
;
1142 type_t
*make_type
(unsigned char type
, type_t
*ref
)
1144 type_t
*t
= alloc_type
();
1146 t
->kind
= TKIND_PRIMITIVE
;
1152 t
->fields_or_args
= NULL
;
1156 t
->length_is
= NULL
;
1157 t
->typestring_offset
= 0;
1159 t
->declarray
= FALSE
;
1160 t
->ignore
= (parse_only
!= 0);
1161 t
->is_const
= FALSE
;
1165 t
->user_types_registered
= FALSE
;
1166 t
->tfswrite
= FALSE
;
1168 t
->typelib_idx
= -1;
1172 static void set_type
(var_t
*v
, type_t
*type
, const pident_t
*pident
, array_dims_t
*arr
,
1175 expr_list_t
*sizes
= get_attrp
(v
->attrs
, ATTR_SIZEIS
);
1176 expr_list_t
*lengs
= get_attrp
(v
->attrs
, ATTR_LENGTHIS
);
1177 int ptr_attr
= get_attrv
(v
->attrs
, ATTR_POINTERTYPE
);
1178 int ptr_type
= ptr_attr
;
1179 int sizeless
, has_varconf
;
1181 type_t
*atype
, **ptype
;
1182 int ptr_level
= (pident ? pident
->ptr_level
: 0);
1186 if
(!ptr_type
&& top
)
1187 ptr_type
= RPC_FC_RP
;
1189 for
( ; 0 < ptr_level
; --ptr_level
)
1191 v
->type
= make_type
(pointer_default
, v
->type
);
1192 if
(ptr_level
== 1 && ptr_type
&& !arr
)
1194 v
->type
->type
= ptr_type
;
1199 if
(ptr_type
&& !arr
)
1201 if
(is_ptr
(v
->type
))
1203 if
(v
->type
->type
!= ptr_type
)
1205 v
->type
= duptype
(v
->type
, 1);
1206 v
->type
->type
= ptr_type
;
1209 else if
(!arr
&& ptr_attr
)
1210 error_loc
("%s: pointer attribute applied to non-pointer type\n", v
->name
);
1213 if
(pident
&& pident
->is_func
) {
1214 int func_ptr_level
= pident
->func_ptr_level
;
1215 v
->type
= make_type
(RPC_FC_FUNCTION
, v
->type
);
1216 v
->type
->fields_or_args
= pident
->args
;
1217 if
(pident
->callconv
)
1218 v
->type
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, pident
->callconv
));
1219 else if
(is_object_interface
) {
1220 static char *stdmethodcalltype
;
1221 if
(!stdmethodcalltype
) stdmethodcalltype
= strdup
("STDMETHODCALLTYPE");
1222 v
->type
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, stdmethodcalltype
));
1224 for
(; func_ptr_level
> 0; func_ptr_level
--)
1225 v
->type
= make_type
(ptr_type
, v
->type
);
1229 if
(arr
) LIST_FOR_EACH_ENTRY_REV
(dim
, arr
, expr_t
, entry
)
1232 error_loc
("%s: only the first array dimension can be unspecified\n", v
->name
);
1236 unsigned int align
= 0;
1237 size_t size
= type_memsize
(v
->type
, &align
);
1240 error_loc
("%s: array dimension must be positive\n", v
->name
);
1242 if
(0xffffffffuL
/ size
< (unsigned long) dim
->cval
)
1243 error_loc
("%s: total array size is too large\n", v
->name
);
1244 else if
(0xffffuL
< size
* dim
->cval
)
1245 v
->type
= make_type
(RPC_FC_LGFARRAY
, v
->type
);
1247 v
->type
= make_type
(RPC_FC_SMFARRAY
, v
->type
);
1252 v
->type
= make_type
(RPC_FC_CARRAY
, v
->type
);
1255 v
->type
->declarray
= TRUE
;
1256 v
->type
->dim
= dim
->cval
;
1260 has_varconf
= FALSE
;
1261 if
(sizes
) LIST_FOR_EACH_ENTRY
(dim
, sizes
, expr_t
, entry
)
1263 if
(dim
->type
!= EXPR_VOID
)
1266 atype
= *ptype
= duptype
(*ptype
, 0);
1268 if
(atype
->type
== RPC_FC_SMFARRAY || atype
->type
== RPC_FC_LGFARRAY
)
1269 error_loc
("%s: cannot specify size_is for a fixed sized array\n", v
->name
);
1271 if
(atype
->type
!= RPC_FC_CARRAY
&& !is_ptr
(atype
))
1272 error_loc
("%s: size_is attribute applied to illegal type\n", v
->name
);
1274 atype
->type
= RPC_FC_CARRAY
;
1275 atype
->size_is
= dim
;
1278 ptype
= &(*ptype
)->ref
;
1280 error_loc
("%s: too many expressions in size_is attribute\n", v
->name
);
1284 if
(lengs
) LIST_FOR_EACH_ENTRY
(dim
, lengs
, expr_t
, entry
)
1286 if
(dim
->type
!= EXPR_VOID
)
1289 atype
= *ptype
= duptype
(*ptype
, 0);
1291 if
(atype
->type
== RPC_FC_SMFARRAY
)
1292 atype
->type
= RPC_FC_SMVARRAY
;
1293 else if
(atype
->type
== RPC_FC_LGFARRAY
)
1294 atype
->type
= RPC_FC_LGVARRAY
;
1295 else if
(atype
->type
== RPC_FC_CARRAY
)
1296 atype
->type
= RPC_FC_CVARRAY
;
1298 error_loc
("%s: length_is attribute applied to illegal type\n", v
->name
);
1300 atype
->length_is
= dim
;
1303 ptype
= &(*ptype
)->ref
;
1305 error_loc
("%s: too many expressions in length_is attribute\n", v
->name
);
1308 if
(has_varconf
&& !last_array
(v
->type
))
1311 for
(ptype
= &v
->type
; is_array
(*ptype
); ptype
= &(*ptype
)->ref
)
1313 *ptype
= duptype
(*ptype
, 0);
1314 (*ptype
)->type
= RPC_FC_BOGUS_ARRAY
;
1318 if
(is_array
(v
->type
))
1320 const type_t
*rt
= v
->type
->ref
;
1321 if
(is_user_type
(rt
))
1322 v
->type
->type
= RPC_FC_BOGUS_ARRAY
;
1326 case RPC_FC_BOGUS_STRUCT
:
1327 case RPC_FC_NON_ENCAPSULATED_UNION
:
1328 case RPC_FC_ENCAPSULATED_UNION
:
1330 v
->type
->type
= RPC_FC_BOGUS_ARRAY
;
1332 /* FC_RP should be above, but widl overuses these, and will break things. */
1335 if
(rt
->ref
->type
== RPC_FC_IP
)
1336 v
->type
->type
= RPC_FC_BOGUS_ARRAY
;
1342 static ifref_list_t
*append_ifref
(ifref_list_t
*list
, ifref_t
*iface
)
1344 if
(!iface
) return list
;
1347 list
= xmalloc
( sizeof
(*list
) );
1350 list_add_tail
( list
, &iface
->entry
);
1354 static ifref_t
*make_ifref
(type_t
*iface
)
1356 ifref_t
*l
= xmalloc
(sizeof
(ifref_t
));
1362 static var_list_t
*append_var
(var_list_t
*list
, var_t
*var
)
1364 if
(!var
) return list
;
1367 list
= xmalloc
( sizeof
(*list
) );
1370 list_add_tail
( list
, &var
->entry
);
1374 static var_t
*make_var
(char *name
)
1376 var_t
*v
= xmalloc
(sizeof
(var_t
));
1381 v
->loc_info.input_name
= input_name ? input_name
: "stdin";
1382 v
->loc_info.line_number
= line_number
;
1383 v
->loc_info.near_text
= parser_text
;
1387 static pident_list_t
*append_pident
(pident_list_t
*list
, pident_t
*p
)
1389 if
(!p
) return list
;
1391 list
= xmalloc
(sizeof
(*list
));
1394 list_add_tail
(list
, &p
->entry
);
1398 static pident_t
*make_pident
(var_t
*var
)
1400 pident_t
*p
= xmalloc
(sizeof
(*p
));
1404 p
->func_ptr_level
= 0;
1410 static func_list_t
*append_func
(func_list_t
*list
, func_t
*func
)
1412 if
(!func
) return list
;
1415 list
= xmalloc
( sizeof
(*list
) );
1418 list_add_tail
( list
, &func
->entry
);
1422 static func_t
*make_func
(var_t
*def
, var_list_t
*args
)
1424 func_t
*f
= xmalloc
(sizeof
(func_t
));
1427 f
->ignore
= parse_only
;
1432 static type_t
*make_class
(char *name
)
1434 type_t
*c
= make_type
(0, NULL
);
1436 c
->kind
= TKIND_COCLASS
;
1440 static type_t
*make_safearray
(type_t
*type
)
1442 type_t
*sa
= duptype
(find_type
("SAFEARRAY", 0), 1);
1444 return make_type
(pointer_default
, sa
);
1449 static int hash_ident
(const char *name
)
1451 const char *p
= name
;
1453 /* a simple sum hash is probably good enough */
1458 return sum
& (HASHMAX
-1);
1461 /***** type repository *****/
1470 struct rtype
*type_hash
[HASHMAX
];
1472 static type_t
*reg_type
(type_t
*type
, const char *name
, int t
)
1477 error_loc
("registering named type without name\n");
1480 hash
= hash_ident
(name
);
1481 nt
= xmalloc
(sizeof
(struct rtype
));
1485 nt
->next
= type_hash
[hash
];
1486 type_hash
[hash
] = nt
;
1490 static int is_incomplete
(const type_t
*t
)
1492 return
!t
->defined
&& (is_struct
(t
->type
) || is_union
(t
->type
));
1495 static void add_incomplete
(type_t
*t
)
1497 struct typenode
*tn
= xmalloc
(sizeof
*tn
);
1499 list_add_tail
(&incomplete_types
, &tn
->entry
);
1502 static void fix_type
(type_t
*t
)
1504 if
(t
->kind
== TKIND_ALIAS
&& is_incomplete
(t
)) {
1505 type_t
*ot
= t
->orig
;
1507 t
->fields_or_args
= ot
->fields_or_args
;
1508 t
->defined
= ot
->defined
;
1512 static void fix_incomplete
(void)
1514 struct typenode
*tn
, *next
;
1516 LIST_FOR_EACH_ENTRY_SAFE
(tn
, next
, &incomplete_types
, struct typenode
, entry
) {
1522 static type_t
*reg_typedefs
(type_t
*type
, pident_list_t
*pidents
, attr_list_t
*attrs
)
1525 const pident_t
*pident
;
1527 int is_str
= is_attr
(attrs
, ATTR_STRING
);
1528 unsigned char ptr_type
= get_attrv
(attrs
, ATTR_POINTERTYPE
);
1539 if
(c
!= RPC_FC_CHAR
&& c
!= RPC_FC_BYTE
&& c
!= RPC_FC_WCHAR
)
1541 pident
= LIST_ENTRY
( list_head
( pidents
), const pident_t
, entry
);
1542 error_loc
("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
1547 /* We must generate names for tagless enum, struct or union.
1548 Typedef-ing a tagless enum, struct or union means we want the typedef
1549 to be included in a library whether it has other attributes or not,
1550 hence the public attribute. */
1551 if
((type
->kind
== TKIND_ENUM || type
->kind
== TKIND_RECORD
1552 || type
->kind
== TKIND_UNION
) && ! type
->name
&& ! parse_only
)
1554 if
(! is_attr
(attrs
, ATTR_PUBLIC
))
1555 attrs
= append_attr
( attrs
, make_attr
(ATTR_PUBLIC
) );
1556 type
->name
= gen_name
();
1559 LIST_FOR_EACH_ENTRY
( pident
, pidents
, const pident_t
, entry
)
1561 var_t
*name
= pident
->var
;
1565 int cptr
= pident
->ptr_level
;
1567 while
(cptr
> ptrc
) {
1568 cur
= ptr
= make_type
(pointer_default
, cur
);
1572 while
(cptr
< ptrc
) {
1577 if
(pident
->is_func
) {
1578 int func_ptr_level
= pident
->func_ptr_level
;
1579 cur
= make_type
(RPC_FC_FUNCTION
, cur
);
1580 cur
->fields_or_args
= pident
->args
;
1581 if
(pident
->callconv
)
1582 cur
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, pident
->callconv
));
1583 else if
(is_object_interface
) {
1584 static char *stdmethodcalltype
;
1585 if
(!stdmethodcalltype
) stdmethodcalltype
= strdup
("STDMETHODCALLTYPE");
1586 cur
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, stdmethodcalltype
));
1588 for
(; func_ptr_level
> 0; func_ptr_level
--)
1589 cur
= make_type
(pointer_default
, cur
);
1591 cur
= alias
(cur
, name
->name
);
1596 cur
->type
= ptr_type
;
1598 error_loc
("'%s': pointer attribute applied to non-pointer type\n",
1601 else if
(is_str
&& ! is_ptr
(cur
))
1602 error_loc
("'%s': [string] attribute applied to non-pointer type\n",
1605 if
(is_incomplete
(cur
))
1606 add_incomplete
(cur
);
1607 reg_type
(cur
, cur
->name
, 0);
1613 type_t
*find_type
(const char *name
, int t
)
1615 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
1616 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
1619 error_loc
("type '%s' not found\n", name
);
1625 static type_t
*find_type2
(char *name
, int t
)
1627 type_t
*tp
= find_type
(name
, t
);
1632 int is_type
(const char *name
)
1634 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
1635 while
(cur
&& (cur
->t || strcmp
(cur
->name
, name
)))
1637 if
(cur
) return TRUE
;
1641 static type_t
*get_type
(unsigned char type
, char *name
, int t
)
1643 struct rtype
*cur
= NULL
;
1646 cur
= type_hash
[hash_ident
(name
)];
1647 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
1654 tp
= make_type
(type
, NULL
);
1656 if
(!name
) return tp
;
1657 return reg_type
(tp
, name
, t
);
1660 static type_t
*get_typev
(unsigned char type
, var_t
*name
, int t
)
1667 return get_type
(type
, sname
, t
);
1670 static int get_struct_type
(var_list_t
*fields
)
1672 int has_pointer
= 0;
1673 int has_conformance
= 0;
1674 int has_variance
= 0;
1677 if
(get_padding
(fields
))
1678 return RPC_FC_BOGUS_STRUCT
;
1680 if
(fields
) LIST_FOR_EACH_ENTRY
( field
, fields
, var_t
, entry
)
1682 type_t
*t
= field
->type
;
1684 if
(is_user_type
(t
))
1685 return RPC_FC_BOGUS_STRUCT
;
1696 case RPC_FC_ENCAPSULATED_UNION
:
1697 case RPC_FC_NON_ENCAPSULATED_UNION
:
1698 case RPC_FC_BOGUS_STRUCT
:
1699 return RPC_FC_BOGUS_STRUCT
;
1706 if
(field
->type
->declarray
)
1708 if
(is_string_type
(field
->attrs
, field
->type
))
1710 if
(is_conformant_array
(field
->type
))
1711 has_conformance
= 1;
1716 if
(is_array
(field
->type
->ref
))
1717 return RPC_FC_BOGUS_STRUCT
;
1719 if
(is_conformant_array
(field
->type
))
1721 has_conformance
= 1;
1722 if
(field
->type
->declarray
&& list_next
(fields
, &field
->entry
))
1723 error_loc
("field '%s' deriving from a conformant array must be the last field in the structure\n",
1726 if
(field
->type
->length_is
)
1729 t
= field
->type
->ref
;
1735 * RPC_FC_BYTE, RPC_FC_STRUCT, etc
1736 * Simple types don't effect the type of struct.
1737 * A struct containing a simple struct is still a simple struct.
1738 * So long as we can block copy the data, we return RPC_FC_STRUCT.
1740 case
0: /* void pointer */
1750 case RPC_FC_INT3264
:
1751 case RPC_FC_UINT3264
:
1764 case RPC_FC_CVARRAY
:
1765 case RPC_FC_BOGUS_ARRAY
:
1770 * Propagate member attributes
1771 * a struct should be at least as complex as its member
1773 case RPC_FC_CVSTRUCT
:
1774 has_conformance
= 1;
1779 case RPC_FC_CPSTRUCT
:
1780 has_conformance
= 1;
1781 if
(list_next
( fields
, &field
->entry
))
1782 error_loc
("field '%s' deriving from a conformant array must be the last field in the structure\n",
1787 case RPC_FC_CSTRUCT
:
1788 has_conformance
= 1;
1789 if
(list_next
( fields
, &field
->entry
))
1790 error_loc
("field '%s' deriving from a conformant array must be the last field in the structure\n",
1794 case RPC_FC_PSTRUCT
:
1799 error_loc
("Unknown struct member %s with type (0x%02x)\n", field
->name
, t
->type
);
1800 /* fallthru - treat it as complex */
1802 /* as soon as we see one of these these members, it's bogus... */
1803 case RPC_FC_ENCAPSULATED_UNION
:
1804 case RPC_FC_NON_ENCAPSULATED_UNION
:
1805 case RPC_FC_BOGUS_STRUCT
:
1807 return RPC_FC_BOGUS_STRUCT
;
1813 if
( has_conformance
)
1814 return RPC_FC_CVSTRUCT
;
1816 return RPC_FC_BOGUS_STRUCT
;
1818 if
( has_conformance
&& has_pointer
)
1819 return RPC_FC_CPSTRUCT
;
1820 if
( has_conformance
)
1821 return RPC_FC_CSTRUCT
;
1823 return RPC_FC_PSTRUCT
;
1824 return RPC_FC_STRUCT
;
1827 /***** constant repository *****/
1832 struct rconst
*next
;
1835 struct rconst
*const_hash
[HASHMAX
];
1837 static var_t
*reg_const
(var_t
*var
)
1842 error_loc
("registering constant without name\n");
1845 hash
= hash_ident
(var
->name
);
1846 nc
= xmalloc
(sizeof
(struct rconst
));
1847 nc
->name
= var
->name
;
1849 nc
->next
= const_hash
[hash
];
1850 const_hash
[hash
] = nc
;
1854 var_t
*find_const
(const char *name
, int f
)
1856 struct rconst
*cur
= const_hash
[hash_ident
(name
)];
1857 while
(cur
&& strcmp
(cur
->name
, name
))
1860 if
(f
) error_loc
("constant '%s' not found\n", name
);
1866 static void write_libid
(const char *name
, const attr_list_t
*attr
)
1868 const UUID
*uuid
= get_attrp
(attr
, ATTR_UUID
);
1869 write_guid
(idfile
, "LIBID", name
, uuid
);
1872 static void write_clsid
(type_t
*cls
)
1874 const UUID
*uuid
= get_attrp
(cls
->attrs
, ATTR_UUID
);
1875 write_guid
(idfile
, "CLSID", cls
->name
, uuid
);
1878 static void write_diid
(type_t
*iface
)
1880 const UUID
*uuid
= get_attrp
(iface
->attrs
, ATTR_UUID
);
1881 write_guid
(idfile
, "DIID", iface
->name
, uuid
);
1884 static void write_iid
(type_t
*iface
)
1886 const UUID
*uuid
= get_attrp
(iface
->attrs
, ATTR_UUID
);
1887 write_guid
(idfile
, "IID", iface
->name
, uuid
);
1890 static int compute_method_indexes
(type_t
*iface
)
1896 idx
= compute_method_indexes
(iface
->ref
);
1903 LIST_FOR_EACH_ENTRY
( f
, iface
->funcs
, func_t
, entry
)
1904 if
(! is_callas
(f
->def
->attrs
))
1910 static char *gen_name
(void)
1912 static const char format
[] = "__WIDL_%s_generated_name_%08lX";
1913 static unsigned long n
= 0;
1914 static const char *file_id
;
1920 char *dst
= dup_basename
(input_name
, ".idl");
1924 if
(! isalnum
((unsigned char) *dst
))
1927 size
= sizeof format
- 7 + strlen
(file_id
) + 8;
1930 name
= xmalloc
(size
);
1931 sprintf
(name
, format
, file_id
, n
++);
1935 static void process_typedefs
(pident_list_t
*pidents
)
1937 pident_t
*pident
, *next
;
1939 if
(!pidents
) return
;
1940 LIST_FOR_EACH_ENTRY_SAFE
( pident
, next
, pidents
, pident_t
, entry
)
1942 var_t
*var
= pident
->var
;
1943 type_t
*type
= find_type
(var
->name
, 0);
1945 if
(! parse_only
&& do_header
)
1946 write_typedef
(type
);
1947 if
(in_typelib
&& type
->attrs
)
1948 add_typelib_entry
(type
);
1957 unsigned int dce_compatible
: 1;
1958 unsigned int acf
: 1;
1959 unsigned int on_interface
: 1;
1960 unsigned int on_function
: 1;
1961 unsigned int on_arg
: 1;
1962 unsigned int on_type
: 1;
1963 unsigned int on_field
: 1;
1964 unsigned int on_library
: 1;
1965 unsigned int on_dispinterface
: 1;
1966 unsigned int on_module
: 1;
1967 unsigned int on_coclass
: 1;
1968 const char *display_name
;
1971 struct allowed_attr allowed_attr
[] =
1973 /* attr { D ACF I Fn ARG T Fi L DI M C <display name> } */
1974 /* ATTR_AGGREGATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "aggregatable" },
1975 /* ATTR_APPOBJECT */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "appobject" },
1976 /* ATTR_ASYNC */ { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, "async" },
1977 /* ATTR_AUTO_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "auto_handle" },
1978 /* ATTR_BINDABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "bindable" },
1979 /* ATTR_BROADCAST */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "broadcast" },
1980 /* ATTR_CALLAS */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "call_as" },
1981 /* ATTR_CALLCONV */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
},
1982 /* ATTR_CASE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "case" },
1983 /* ATTR_CONTEXTHANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "context_handle" },
1984 /* ATTR_CONTROL */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, "control" },
1985 /* ATTR_DEFAULT */ { 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, "default" },
1986 /* ATTR_DEFAULTCOLLELEM */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "defaultcollelem" },
1987 /* ATTR_DEFAULTVALUE_EXPR */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "defaultvalue" },
1988 /* ATTR_DEFAULTVALUE_STRING */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "defaultvalue" },
1989 /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "defaultvtable" },
1990 /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
},
1991 /* ATTR_DISPLAYBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "displaybind" },
1992 /* ATTR_DLLNAME */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, "dllname" },
1993 /* ATTR_DUAL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "dual" },
1994 /* ATTR_ENDPOINT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "endpoint" },
1995 /* ATTR_ENTRY_ORDINAL */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "entry" },
1996 /* ATTR_ENTRY_STRING */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "entry" },
1997 /* ATTR_EXPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "explicit_handle" },
1998 /* ATTR_HANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "handle" },
1999 /* ATTR_HELPCONTEXT */ { 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, "helpcontext" },
2000 /* ATTR_HELPFILE */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpfile" },
2001 /* ATTR_HELPSTRING */ { 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, "helpstring" },
2002 /* ATTR_HELPSTRINGCONTEXT */ { 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, "helpstringcontext" },
2003 /* ATTR_HELPSTRINGDLL */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpstringdll" },
2004 /* ATTR_HIDDEN */ { 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, "hidden" },
2005 /* ATTR_ID */ { 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, "id" },
2006 /* ATTR_IDEMPOTENT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "idempotent" },
2007 /* ATTR_IIDIS */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "iid_is" },
2008 /* ATTR_IMMEDIATEBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "immediatebind" },
2009 /* ATTR_IMPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "implicit_handle" },
2010 /* ATTR_IN */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "in" },
2011 /* ATTR_INPUTSYNC */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inputsync" },
2012 /* ATTR_LENGTHIS */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "length_is" },
2013 /* ATTR_LOCAL */ { 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, "local" },
2014 /* ATTR_NONBROWSABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "nonbrowsable" },
2015 /* ATTR_NONCREATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "noncreatable" },
2016 /* ATTR_NONEXTENSIBLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "nonextensible" },
2017 /* ATTR_OBJECT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "object" },
2018 /* ATTR_ODL */ { 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, "odl" },
2019 /* ATTR_OLEAUTOMATION */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "oleautomation" },
2020 /* ATTR_OPTIONAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "optional" },
2021 /* ATTR_OUT */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "out" },
2022 /* ATTR_POINTERDEFAULT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "pointer_default" },
2023 /* ATTR_POINTERTYPE */ { 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, "ref, unique or ptr" },
2024 /* ATTR_PROPGET */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "propget" },
2025 /* ATTR_PROPPUT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "propput" },
2026 /* ATTR_PROPPUTREF */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "propputref" },
2027 /* ATTR_PUBLIC */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "public" },
2028 /* ATTR_RANGE */ { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, "range" },
2029 /* ATTR_READONLY */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "readonly" },
2030 /* ATTR_REQUESTEDIT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "requestedit" },
2031 /* ATTR_RESTRICTED */ { 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, "restricted" },
2032 /* ATTR_RETVAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "retval" },
2033 /* ATTR_SIZEIS */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "size_is" },
2034 /* ATTR_SOURCE */ { 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, "source" },
2035 /* ATTR_STRICTCONTEXTHANDLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "strict_context_handle" },
2036 /* ATTR_STRING */ { 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, "string" },
2037 /* ATTR_SWITCHIS */ { 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "switch_is" },
2038 /* ATTR_SWITCHTYPE */ { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, "switch_type" },
2039 /* ATTR_TRANSMITAS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "transmit_as" },
2040 /* ATTR_UUID */ { 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, "uuid" },
2041 /* ATTR_V1ENUM */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "v1_enum" },
2042 /* ATTR_VARARG */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "vararg" },
2043 /* ATTR_VERSION */ { 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, "version" },
2044 /* ATTR_WIREMARSHAL */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "wire_marshal" },
2047 const char *get_attr_display_name
(enum attr_type type
)
2049 return allowed_attr
[type
].display_name
;
2052 static const attr_list_t
*check_iface_attrs
(const char *name
, const attr_list_t
*attrs
)
2055 if
(!attrs
) return attrs
;
2056 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2058 if
(!allowed_attr
[attr
->type
].on_interface
)
2059 error_loc
("inapplicable attribute %s for interface %s\n",
2060 allowed_attr
[attr
->type
].display_name
, name
);
2065 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
)
2068 if
(!attrs
) return attrs
;
2069 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2071 if
(!allowed_attr
[attr
->type
].on_function
)
2072 error_loc
("inapplicable attribute %s for function %s\n",
2073 allowed_attr
[attr
->type
].display_name
, name
);
2078 static void check_arg
(var_t
*arg
)
2080 const type_t
*t
= arg
->type
;
2083 if
(t
->type
== 0 && ! is_var_ptr
(arg
))
2084 error_loc
("argument '%s' has void type\n", arg
->name
);
2088 LIST_FOR_EACH_ENTRY
(attr
, arg
->attrs
, const attr_t
, entry
)
2090 if
(!allowed_attr
[attr
->type
].on_arg
)
2091 error_loc
("inapplicable attribute %s for argument %s\n",
2092 allowed_attr
[attr
->type
].display_name
, arg
->name
);
2097 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
)
2100 if
(!attrs
) return attrs
;
2101 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2103 if
(!allowed_attr
[attr
->type
].on_type
)
2104 error_loc
("inapplicable attribute %s for typedef\n",
2105 allowed_attr
[attr
->type
].display_name
);
2110 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
)
2113 if
(!attrs
) return attrs
;
2114 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2116 if
(!allowed_attr
[attr
->type
].on_field
)
2117 error_loc
("inapplicable attribute %s for field %s\n",
2118 allowed_attr
[attr
->type
].display_name
, name
);
2123 static const attr_list_t
*check_library_attrs
(const char *name
, const attr_list_t
*attrs
)
2126 if
(!attrs
) return attrs
;
2127 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2129 if
(!allowed_attr
[attr
->type
].on_library
)
2130 error_loc
("inapplicable attribute %s for library %s\n",
2131 allowed_attr
[attr
->type
].display_name
, name
);
2136 static attr_list_t
*check_dispiface_attrs
(const char *name
, attr_list_t
*attrs
)
2139 if
(!attrs
) return attrs
;
2140 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2142 if
(!allowed_attr
[attr
->type
].on_dispinterface
)
2143 error_loc
("inapplicable attribute %s for dispinterface %s\n",
2144 allowed_attr
[attr
->type
].display_name
, name
);
2149 static const attr_list_t
*check_module_attrs
(const char *name
, const attr_list_t
*attrs
)
2152 if
(!attrs
) return attrs
;
2153 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2155 if
(!allowed_attr
[attr
->type
].on_module
)
2156 error_loc
("inapplicable attribute %s for module %s\n",
2157 allowed_attr
[attr
->type
].display_name
, name
);
2162 static const attr_list_t
*check_coclass_attrs
(const char *name
, const attr_list_t
*attrs
)
2165 if
(!attrs
) return attrs
;
2166 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2168 if
(!allowed_attr
[attr
->type
].on_coclass
)
2169 error_loc
("inapplicable attribute %s for coclass %s\n",
2170 allowed_attr
[attr
->type
].display_name
, name
);
2175 static int is_allowed_conf_type
(const type_t
*type
)
2196 static int is_ptr_guid_type
(const type_t
*type
)
2198 unsigned int align
= 0;
2201 if
(type
->kind
== TKIND_ALIAS
)
2203 else if
(is_ptr
(type
))
2211 return
(type_memsize
(type
, &align
) == 16);
2214 static void check_conformance_expr_list
(const char *attr_name
, const var_t
*arg
, const type_t
*container_type
, expr_list_t
*expr_list
)
2217 struct expr_loc expr_loc
;
2219 expr_loc.attr
= attr_name
;
2220 if
(expr_list
) LIST_FOR_EACH_ENTRY
(dim
, expr_list
, expr_t
, entry
)
2222 if
(dim
->type
!= EXPR_VOID
)
2224 const type_t
*expr_type
= expr_resolve_type
(&expr_loc
, container_type
, dim
);
2225 if
(!is_allowed_conf_type
(expr_type
))
2226 error_loc_info
(&arg
->loc_info
, "expression must resolve to integral type <= 32bits for attribute %s\n",
2232 static void check_remoting_fields
(const var_t
*var
, type_t
*type
);
2234 /* checks that properties common to fields and arguments are consistent */
2235 static void check_field_common
(const type_t
*container_type
,
2236 const char *container_name
, const var_t
*arg
)
2238 type_t
*type
= arg
->type
;
2239 int is_wire_marshal
= 0;
2240 int is_context_handle
= 0;
2241 const char *container_type_name
= NULL
;
2243 if
(is_struct
(container_type
->type
))
2244 container_type_name
= "struct";
2245 else if
(is_union
(container_type
->type
))
2246 container_type_name
= "union";
2247 else if
(container_type
->type
== RPC_FC_FUNCTION
)
2248 container_type_name
= "function";
2250 if
(is_attr
(arg
->attrs
, ATTR_LENGTHIS
) &&
2251 (is_attr
(arg
->attrs
, ATTR_STRING
) || is_aliaschain_attr
(arg
->type
, ATTR_STRING
)))
2252 error_loc_info
(&arg
->loc_info
,
2253 "string and length_is specified for argument %s are mutually exclusive attributes\n",
2256 if
(is_attr
(arg
->attrs
, ATTR_SIZEIS
))
2258 expr_list_t
*size_is_exprs
= get_attrp
(arg
->attrs
, ATTR_SIZEIS
);
2259 check_conformance_expr_list
("size_is", arg
, container_type
, size_is_exprs
);
2261 if
(is_attr
(arg
->attrs
, ATTR_LENGTHIS
))
2263 expr_list_t
*length_is_exprs
= get_attrp
(arg
->attrs
, ATTR_LENGTHIS
);
2264 check_conformance_expr_list
("length_is", arg
, container_type
, length_is_exprs
);
2266 if
(is_attr
(arg
->attrs
, ATTR_IIDIS
))
2268 struct expr_loc expr_loc
;
2269 expr_t
*expr
= get_attrp
(arg
->attrs
, ATTR_IIDIS
);
2270 if
(expr
->type
!= EXPR_VOID
)
2272 const type_t
*expr_type
;
2274 expr_loc.attr
= "iid_is";
2275 expr_type
= expr_resolve_type
(&expr_loc
, container_type
, expr
);
2276 if
(!expr_type ||
!is_ptr_guid_type
(expr_type
))
2277 error_loc_info
(&arg
->loc_info
, "expression must resolve to pointer to GUID type for attribute iid_is\n");
2280 if
(is_attr
(arg
->attrs
, ATTR_SWITCHIS
))
2282 struct expr_loc expr_loc
;
2283 expr_t
*expr
= get_attrp
(arg
->attrs
, ATTR_SWITCHIS
);
2284 if
(expr
->type
!= EXPR_VOID
)
2286 const type_t
*expr_type
;
2288 expr_loc.attr
= "switch_is";
2289 expr_type
= expr_resolve_type
(&expr_loc
, container_type
, expr
);
2290 if
(!expr_type ||
!is_allowed_conf_type
(expr_type
))
2291 error_loc_info
(&arg
->loc_info
, "expression must resolve to integral type <= 32bits for attribute %s\n",
2296 /* get fundamental type for the argument */
2299 if
(is_attr
(type
->attrs
, ATTR_WIREMARSHAL
))
2301 is_wire_marshal
= 1;
2304 if
(is_attr
(type
->attrs
, ATTR_CONTEXTHANDLE
))
2306 is_context_handle
= 1;
2309 if
(type
->kind
== TKIND_ALIAS
)
2311 else if
(is_ptr
(type
) || is_array
(type
))
2317 if
(type
->type
== 0 && !is_attr
(arg
->attrs
, ATTR_IIDIS
) && !is_wire_marshal
&& !is_context_handle
)
2318 error_loc_info
(&arg
->loc_info
, "parameter \'%s\' of %s \'%s\' cannot derive from void *\n", arg
->name
, container_type_name
, container_name
);
2319 else if
(type
->type
== RPC_FC_FUNCTION
)
2320 error_loc_info
(&arg
->loc_info
, "parameter \'%s\' of %s \'%s\' cannot be a function pointer\n", arg
->name
, container_type_name
, container_name
);
2321 else if
(!is_wire_marshal
&& (is_struct
(type
->type
) || is_union
(type
->type
)))
2322 check_remoting_fields
(arg
, type
);
2325 static void check_remoting_fields
(const var_t
*var
, type_t
*type
)
2328 const var_list_t
*fields
= NULL
;
2333 type
->checked
= TRUE
;
2335 if
(is_struct
(type
->type
))
2336 fields
= type
->fields_or_args
;
2337 else if
(is_union
(type
->type
))
2339 if
(type
->type
== RPC_FC_ENCAPSULATED_UNION
)
2341 const var_t
*uv
= LIST_ENTRY
(list_tail
(type
->fields_or_args
), const var_t
, entry
);
2342 fields
= uv
->type
->fields_or_args
;
2345 fields
= type
->fields_or_args
;
2348 if
(fields
) LIST_FOR_EACH_ENTRY
( field
, type
->fields_or_args
, const var_t
, entry
)
2349 if
(field
->type
) check_field_common
(type
, type
->name
, field
);
2352 /* checks that arguments for a function make sense for marshalling and unmarshalling */
2353 static void check_remoting_args
(const func_t
*func
)
2355 const char *funcname
= func
->def
->name
;
2358 if
(func
->args
) LIST_FOR_EACH_ENTRY
( arg
, func
->args
, const var_t
, entry
)
2361 const type_t
*type
= arg
->type
;
2363 /* get pointer level and fundamental type for the argument */
2366 if
(is_attr
(type
->attrs
, ATTR_WIREMARSHAL
))
2368 if
(is_attr
(type
->attrs
, ATTR_CONTEXTHANDLE
))
2370 if
(type
->kind
== TKIND_ALIAS
)
2372 else if
(is_ptr
(type
))
2381 /* check that [out] parameters have enough pointer levels */
2382 if
(is_attr
(arg
->attrs
, ATTR_OUT
))
2384 if
(!is_array
(type
))
2387 error_loc_info
(&arg
->loc_info
, "out parameter \'%s\' of function \'%s\' is not a pointer\n", arg
->name
, funcname
);
2388 if
(type
->type
== RPC_FC_IP
&& ptr_level
== 1)
2389 error_loc_info
(&arg
->loc_info
, "out interface pointer \'%s\' of function \'%s\' is not a double pointer\n", arg
->name
, funcname
);
2393 check_field_common
(func
->def
->type
, funcname
, arg
);
2397 static void add_explicit_handle_if_necessary
(func_t
*func
)
2399 const var_t
* explicit_handle_var
;
2400 const var_t
* explicit_generic_handle_var
= NULL
;
2401 const var_t
* context_handle_var
= NULL
;
2403 /* check for a defined binding handle */
2404 explicit_handle_var
= get_explicit_handle_var
(func
);
2405 if
(!explicit_handle_var
)
2407 explicit_generic_handle_var
= get_explicit_generic_handle_var
(func
);
2408 if
(!explicit_generic_handle_var
)
2410 context_handle_var
= get_context_handle_var
(func
);
2411 if
(!context_handle_var
)
2413 /* no explicit handle specified so add
2414 * "[in] handle_t IDL_handle" as the first parameter to the
2416 var_t
*idl_handle
= make_var
(xstrdup
("IDL_handle"));
2417 idl_handle
->attrs
= append_attr
(NULL
, make_attr
(ATTR_IN
));
2418 idl_handle
->type
= find_type
("handle_t", 0);
2419 if
(!func
->def
->type
->fields_or_args
)
2421 func
->def
->type
->fields_or_args
= xmalloc
( sizeof
(*func
->def
->type
->fields_or_args
) );
2422 list_init
( func
->def
->type
->fields_or_args
);
2424 list_add_head
( func
->def
->type
->fields_or_args
, &idl_handle
->entry
);
2425 func
->args
= func
->def
->type
->fields_or_args
;
2431 static void check_functions
(const type_t
*iface
)
2433 if
(is_attr
(iface
->attrs
, ATTR_EXPLICIT_HANDLE
) && iface
->funcs
)
2436 LIST_FOR_EACH_ENTRY
( func
, iface
->funcs
, func_t
, entry
)
2437 add_explicit_handle_if_necessary
(func
);
2439 if
(!is_inside_library
&& !is_attr
(iface
->attrs
, ATTR_LOCAL
))
2442 if
(iface
->funcs
) LIST_FOR_EACH_ENTRY
( func
, iface
->funcs
, const func_t
, entry
)
2444 if
(!is_attr
(func
->def
->attrs
, ATTR_LOCAL
))
2445 check_remoting_args
(func
);
2450 static void check_all_user_types
(ifref_list_t
*ifrefs
)
2452 const ifref_t
*ifref
;
2455 if
(ifrefs
) LIST_FOR_EACH_ENTRY
(ifref
, ifrefs
, const ifref_t
, entry
)
2457 const func_list_t
*fs
= ifref
->iface
->funcs
;
2458 if
(fs
) LIST_FOR_EACH_ENTRY
(f
, fs
, const func_t
, entry
)
2459 check_for_additional_prototype_types
(f
->args
);
2463 int is_valid_uuid
(const char *s
)
2467 for
(i
= 0; i
< 36; ++i
)
2468 if
(i
== 8 || i
== 13 || i
== 18 || i
== 23)
2474 if
(!isxdigit
(s
[i
]))
2477 return s
[i
] == '\0';