5 * Copyright 2002 Ove Kaaven
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
42 /* Berkeley yacc (byacc) doesn't seem to know about these */
43 /* Some *BSD supplied versions do define these though */
45 # define YYEMPTY (-1) /* Empty lookahead value of yychar */
48 # define YYLEX yylex()
51 #elif defined(YYBISON)
52 /* Bison was used for original development */
53 /* #define YYEMPTY -2 */
54 /* #define YYLEX yylex() */
57 /* No yacc we know yet */
58 # if !defined(YYEMPTY) || !defined(YYLEX)
59 # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
60 # elif defined(__GNUC__) /* gcc defines the #warning directive */
61 # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
62 /* #else we just take a chance that it works... */
66 #define YYERROR_VERBOSE
68 unsigned char pointer_default
= RPC_FC_UP
;
69 static int is_object_interface
= FALSE
;
71 typedef
struct list typelist_t
;
77 typelist_t incomplete_types
= LIST_INIT
(incomplete_types
);
79 static void add_incomplete
(type_t
*t
);
80 static void fix_incomplete
(void);
82 static str_list_t
*append_str
(str_list_t
*list
, char *str
);
83 static attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
);
84 static attr_t
*make_attr
(enum attr_type type
);
85 static attr_t
*make_attrv
(enum attr_type type
, unsigned long val
);
86 static attr_t
*make_attrp
(enum attr_type type
, void *val
);
87 static expr_t
*make_expr
(enum expr_type type
);
88 static expr_t
*make_exprl
(enum expr_type type
, long val
);
89 static expr_t
*make_exprd
(enum expr_type type
, double val
);
90 static expr_t
*make_exprs
(enum expr_type type
, char *val
);
91 static expr_t
*make_exprt
(enum expr_type type
, type_t
*tref
, expr_t
*expr
);
92 static expr_t
*make_expr1
(enum expr_type type
, expr_t
*expr
);
93 static expr_t
*make_expr2
(enum expr_type type
, expr_t
*exp1
, expr_t
*exp2
);
94 static expr_t
*make_expr3
(enum expr_type type
, expr_t
*expr1
, expr_t
*expr2
, expr_t
*expr3
);
95 static type_t
*make_type
(unsigned char type
, type_t
*ref
);
96 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
);
97 static array_dims_t
*append_array
(array_dims_t
*list
, expr_t
*expr
);
98 static void set_type
(var_t
*v
, type_t
*type
, const pident_t
*pident
, array_dims_t
*arr
, int top
);
99 static ifref_list_t
*append_ifref
(ifref_list_t
*list
, ifref_t
*iface
);
100 static ifref_t
*make_ifref
(type_t
*iface
);
101 static var_list_t
*append_var
(var_list_t
*list
, var_t
*var
);
102 static var_t
*make_var
(char *name
);
103 static pident_list_t
*append_pident
(pident_list_t
*list
, pident_t
*p
);
104 static pident_t
*make_pident
(var_t
*var
);
105 static func_list_t
*append_func
(func_list_t
*list
, func_t
*func
);
106 static func_t
*make_func
(var_t
*def
, var_list_t
*args
);
107 static type_t
*make_class
(char *name
);
108 static type_t
*make_safearray
(type_t
*type
);
109 static type_t
*make_builtin
(char *name
);
110 static type_t
*make_int
(int sign
);
112 static type_t
*reg_type
(type_t
*type
, const char *name
, int t
);
113 static type_t
*reg_typedefs
(type_t
*type
, var_list_t
*names
, attr_list_t
*attrs
);
114 static type_t
*find_type
(const char *name
, int t
);
115 static type_t
*find_type2
(char *name
, int t
);
116 static type_t
*get_type
(unsigned char type
, char *name
, int t
);
117 static type_t
*get_typev
(unsigned char type
, var_t
*name
, int t
);
118 static int get_struct_type
(var_list_t
*fields
);
120 static var_t
*reg_const
(var_t
*var
);
121 static var_t
*find_const
(char *name
, int f
);
123 static void write_libid
(const char *name
, const attr_list_t
*attr
);
124 static void write_clsid
(type_t
*cls
);
125 static void write_diid
(type_t
*iface
);
126 static void write_iid
(type_t
*iface
);
128 static int compute_method_indexes
(type_t
*iface
);
129 static char *gen_name
(void);
130 static void process_typedefs
(var_list_t
*names
);
131 static void check_arg
(var_t
*arg
);
132 static void check_all_user_types
(ifref_list_t
*ifaces
);
133 static const attr_list_t
*check_iface_attrs
(const char *name
, const attr_list_t
*attrs
);
134 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
);
135 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
);
136 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
);
137 static const attr_list_t
*check_library_attrs
(const char *name
, const attr_list_t
*attrs
);
138 static attr_list_t
*check_dispiface_attrs
(const char *name
, attr_list_t
*attrs
);
139 static const attr_list_t
*check_module_attrs
(const char *name
, const attr_list_t
*attrs
);
140 static const attr_list_t
*check_coclass_attrs
(const char *name
, const attr_list_t
*attrs
);
149 attr_list_t
*attr_list
;
150 str_list_t
*str_list
;
152 expr_list_t
*expr_list
;
153 array_dims_t
*array_dims
;
156 var_list_t
*var_list
;
158 pident_list_t
*pident_list
;
160 func_list_t
*func_list
;
162 ifref_list_t
*ifref_list
;
167 interface_info_t ifinfo
;
170 %token
<str
> aIDENTIFIER
171 %token
<str
> aKNOWNTYPE
172 %token
<num
> aNUM aHEXNUM
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
300 input: gbl_statements
{ fix_incomplete
();
301 check_all_user_types
($1);
309 gbl_statements: { $$
= NULL
; }
310 | gbl_statements interfacedec
{ $$
= $1; }
311 | gbl_statements interfacedef
{ $$
= append_ifref
( $1, make_ifref
($2) ); }
312 | gbl_statements coclass
';' { $$
= $1;
313 reg_type
($2, $2->name
, 0);
314 if
(!parse_only
&& do_header
) write_coclass_forward
($2);
316 | gbl_statements coclassdef
{ $$
= $1;
317 add_typelib_entry
($2);
318 reg_type
($2, $2->name
, 0);
319 if
(!parse_only
&& do_header
) write_coclass_forward
($2);
321 | gbl_statements moduledef
{ $$
= $1; add_typelib_entry
($2); }
322 | gbl_statements librarydef
{ $$
= $1; }
323 | gbl_statements statement
{ $$
= $1; }
327 | imp_statements interfacedec
{ if
(!parse_only
) add_typelib_entry
($2); }
328 | imp_statements interfacedef
{ if
(!parse_only
) add_typelib_entry
($2); }
329 | imp_statements coclass
';' { reg_type
($2, $2->name
, 0); if
(!parse_only
&& do_header
) write_coclass_forward
($2); }
330 | imp_statements coclassdef
{ if
(!parse_only
) add_typelib_entry
($2);
331 reg_type
($2, $2->name
, 0);
332 if
(!parse_only
&& do_header
) write_coclass_forward
($2);
334 | imp_statements moduledef
{ if
(!parse_only
) add_typelib_entry
($2); }
335 | imp_statements statement
{}
336 | imp_statements importlib
{}
337 | imp_statements librarydef
{}
340 int_statements: { $$
= NULL
; }
341 | int_statements funcdef
';' { $$
= append_func
( $1, $2 ); }
342 | int_statements statement
{ $$
= $1; }
349 statement: constdef
';' { if
(!parse_only
&& do_header
) { write_constdef
($1); } }
351 | enumdef
';' { if
(!parse_only
&& do_header
) {
352 write_type_def_or_decl
(header
, $1, FALSE
, NULL
);
353 fprintf
(header
, ";\n\n");
356 | externdef
';' { if
(!parse_only
&& do_header
) { write_externdef
($1); } }
358 | structdef
';' { if
(!parse_only
&& do_header
) {
359 write_type_def_or_decl
(header
, $1, FALSE
, NULL
);
360 fprintf
(header
, ";\n\n");
364 | uniondef
';' { if
(!parse_only
&& do_header
) {
365 write_type_def_or_decl
(header
, $1, FALSE
, NULL
);
366 fprintf
(header
, ";\n\n");
371 cppquote: tCPPQUOTE
'(' aSTRING
')' { if
(!parse_only
&& do_header
) fprintf
(header
, "%s\n", $3); }
373 import_start: tIMPORT aSTRING
';' { assert
(yychar == YYEMPTY
);
375 if
(!$$
) yychar = aEOF
;
379 import: import_start imp_statements aEOF
380 { if
($1) pop_import
(); }
383 importlib: tIMPORTLIB
'(' aSTRING
')'
384 semicolon_opt
{ if
(!parse_only
) add_importlib
($3); }
387 libraryhdr: tLIBRARY aIDENTIFIER
{ $$
= $2; }
389 library_start: attributes libraryhdr
'{' { check_library_attrs
($2, $1);
390 if
(!parse_only
) start_typelib
($2, $1);
391 if
(!parse_only
&& do_header
) write_library
($2, $1);
392 if
(!parse_only
&& do_idfile
) write_libid
($2, $1);
395 librarydef: library_start imp_statements
'}'
396 semicolon_opt
{ if
(!parse_only
) end_typelib
(); }
399 m_args: { $$
= NULL
; }
403 no_args: tVOID
{ $$
= NULL
; }
406 args: arg
{ check_arg
($1); $$
= append_var
( NULL
, $1 ); }
407 | args
',' arg
{ check_arg
($3); $$
= append_var
( $1, $3); }
411 /* split into two rules to get bison to resolve a tVOID conflict */
412 arg: attributes type pident array
{ $$
= $3->var
;
414 set_type
($$
, $2, $3, $4, TRUE
);
417 | type pident array
{ $$
= $2->var
;
418 set_type
($$
, $1, $2, $3, TRUE
);
423 array: { $$
= NULL
; }
424 |
'[' array_list
']' { $$
= $2; }
425 |
'[' '*' ']' { $$
= append_array
( NULL
, make_expr
(EXPR_VOID
) ); }
428 array_list: m_expr
/* size of first dimension is optional */ { $$
= append_array
( NULL
, $1 ); }
429 | array_list
',' expr
{ $$
= append_array
( $1, $3 ); }
430 | array_list
']' '[' expr
{ $$
= append_array
( $1, $4 ); }
433 m_attributes: { $$
= NULL
; }
438 '[' attrib_list
']' { $$
= $2;
440 error_loc
("empty attribute lists unsupported\n");
444 attrib_list: attribute
{ $$
= append_attr
( NULL
, $1 ); }
445 | attrib_list
',' attribute
{ $$
= append_attr
( $1, $3 ); }
446 | attrib_list
']' '[' attribute
{ $$
= append_attr
( $1, $4 ); }
449 str_list: aSTRING
{ $$
= append_str
( NULL
, $1 ); }
450 | str_list
',' aSTRING
{ $$
= append_str
( $1, $3 ); }
453 attribute: { $$
= NULL
; }
454 | tAGGREGATABLE
{ $$
= make_attr
(ATTR_AGGREGATABLE
); }
455 | tAPPOBJECT
{ $$
= make_attr
(ATTR_APPOBJECT
); }
456 | tASYNC
{ $$
= make_attr
(ATTR_ASYNC
); }
457 | tAUTOHANDLE
{ $$
= make_attr
(ATTR_AUTO_HANDLE
); }
458 | tBINDABLE
{ $$
= make_attr
(ATTR_BINDABLE
); }
459 | tCALLAS
'(' ident
')' { $$
= make_attrp
(ATTR_CALLAS
, $3); }
460 | tCASE
'(' expr_list_const
')' { $$
= make_attrp
(ATTR_CASE
, $3); }
461 | tCONTEXTHANDLE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); }
462 | tCONTEXTHANDLENOSERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
463 | tCONTEXTHANDLESERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
464 | tCONTROL
{ $$
= make_attr
(ATTR_CONTROL
); }
465 | tDEFAULT
{ $$
= make_attr
(ATTR_DEFAULT
); }
466 | tDEFAULTCOLLELEM
{ $$
= make_attr
(ATTR_DEFAULTCOLLELEM
); }
467 | tDEFAULTVALUE
'(' expr_const
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE_EXPR
, $3); }
468 | tDEFAULTVALUE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE_STRING
, $3); }
469 | tDEFAULTVTABLE
{ $$
= make_attr
(ATTR_DEFAULTVTABLE
); }
470 | tDISPLAYBIND
{ $$
= make_attr
(ATTR_DISPLAYBIND
); }
471 | tDLLNAME
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DLLNAME
, $3); }
472 | tDUAL
{ $$
= make_attr
(ATTR_DUAL
); }
473 | tENDPOINT
'(' str_list
')' { $$
= make_attrp
(ATTR_ENDPOINT
, $3); }
474 | tENTRY
'(' aSTRING
')' { $$
= make_attrp
(ATTR_ENTRY_STRING
, $3); }
475 | tENTRY
'(' expr_const
')' { $$
= make_attrp
(ATTR_ENTRY_ORDINAL
, $3); }
476 | tEXPLICITHANDLE
{ $$
= make_attr
(ATTR_EXPLICIT_HANDLE
); }
477 | tHANDLE
{ $$
= make_attr
(ATTR_HANDLE
); }
478 | tHELPCONTEXT
'(' expr_const
')' { $$
= make_attrp
(ATTR_HELPCONTEXT
, $3); }
479 | tHELPFILE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPFILE
, $3); }
480 | tHELPSTRING
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRING
, $3); }
481 | tHELPSTRINGCONTEXT
'(' expr_const
')' { $$
= make_attrp
(ATTR_HELPSTRINGCONTEXT
, $3); }
482 | tHELPSTRINGDLL
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRINGDLL
, $3); }
483 | tHIDDEN
{ $$
= make_attr
(ATTR_HIDDEN
); }
484 | tID
'(' expr_const
')' { $$
= make_attrp
(ATTR_ID
, $3); }
485 | tIDEMPOTENT
{ $$
= make_attr
(ATTR_IDEMPOTENT
); }
486 | tIIDIS
'(' expr
')' { $$
= make_attrp
(ATTR_IIDIS
, $3); }
487 | tIMMEDIATEBIND
{ $$
= make_attr
(ATTR_IMMEDIATEBIND
); }
488 | tIMPLICITHANDLE
'(' tHANDLET aIDENTIFIER
')' { $$
= make_attrp
(ATTR_IMPLICIT_HANDLE
, $4); }
489 | tIN
{ $$
= make_attr
(ATTR_IN
); }
490 | tINPUTSYNC
{ $$
= make_attr
(ATTR_INPUTSYNC
); }
491 | tLENGTHIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_LENGTHIS
, $3); }
492 | tLOCAL
{ $$
= make_attr
(ATTR_LOCAL
); }
493 | tNONBROWSABLE
{ $$
= make_attr
(ATTR_NONBROWSABLE
); }
494 | tNONCREATABLE
{ $$
= make_attr
(ATTR_NONCREATABLE
); }
495 | tNONEXTENSIBLE
{ $$
= make_attr
(ATTR_NONEXTENSIBLE
); }
496 | tOBJECT
{ $$
= make_attr
(ATTR_OBJECT
); }
497 | tODL
{ $$
= make_attr
(ATTR_ODL
); }
498 | tOLEAUTOMATION
{ $$
= make_attr
(ATTR_OLEAUTOMATION
); }
499 | tOPTIONAL
{ $$
= make_attr
(ATTR_OPTIONAL
); }
500 | tOUT
{ $$
= make_attr
(ATTR_OUT
); }
501 | tPOINTERDEFAULT
'(' pointer_type
')' { $$
= make_attrv
(ATTR_POINTERDEFAULT
, $3); }
502 | tPROPGET
{ $$
= make_attr
(ATTR_PROPGET
); }
503 | tPROPPUT
{ $$
= make_attr
(ATTR_PROPPUT
); }
504 | tPROPPUTREF
{ $$
= make_attr
(ATTR_PROPPUTREF
); }
505 | tPUBLIC
{ $$
= make_attr
(ATTR_PUBLIC
); }
506 | tRANGE
'(' expr_const
',' expr_const
')' { expr_list_t
*list
= append_expr
( NULL
, $3 );
507 list
= append_expr
( list
, $5 );
508 $$
= make_attrp
(ATTR_RANGE
, list
); }
509 | tREADONLY
{ $$
= make_attr
(ATTR_READONLY
); }
510 | tREQUESTEDIT
{ $$
= make_attr
(ATTR_REQUESTEDIT
); }
511 | tRESTRICTED
{ $$
= make_attr
(ATTR_RESTRICTED
); }
512 | tRETVAL
{ $$
= make_attr
(ATTR_RETVAL
); }
513 | tSIZEIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_SIZEIS
, $3); }
514 | tSOURCE
{ $$
= make_attr
(ATTR_SOURCE
); }
515 | tSTRICTCONTEXTHANDLE
{ $$
= make_attr
(ATTR_STRICTCONTEXTHANDLE
); }
516 | tSTRING
{ $$
= make_attr
(ATTR_STRING
); }
517 | tSWITCHIS
'(' expr
')' { $$
= make_attrp
(ATTR_SWITCHIS
, $3); }
518 | tSWITCHTYPE
'(' type
')' { $$
= make_attrp
(ATTR_SWITCHTYPE
, $3); }
519 | tTRANSMITAS
'(' type
')' { $$
= make_attrp
(ATTR_TRANSMITAS
, $3); }
520 | tUUID
'(' uuid_string
')' { $$
= make_attrp
(ATTR_UUID
, $3); }
521 | tV1ENUM
{ $$
= make_attr
(ATTR_V1ENUM
); }
522 | tVARARG
{ $$
= make_attr
(ATTR_VARARG
); }
523 | tVERSION
'(' version
')' { $$
= make_attrv
(ATTR_VERSION
, $3); }
524 | tWIREMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_WIREMARSHAL
, $3); }
525 | pointer_type
{ $$
= make_attrv
(ATTR_POINTERTYPE
, $1); }
530 | aSTRING
{ if
(!is_valid_uuid
($1))
531 error_loc
("invalid UUID: %s\n", $1);
532 $$
= parse_uuid
($1); }
535 callconv: tCDECL
{ $$
= $
<str
>1; }
536 | tFASTCALL
{ $$
= $
<str
>1; }
537 | tPASCAL
{ $$
= $
<str
>1; }
538 | tSTDCALL
{ $$
= $
<str
>1; }
541 cases: { $$
= NULL
; }
542 | cases case
{ $$
= append_var
( $1, $2 ); }
545 case: tCASE expr
':' field
{ attr_t
*a
= make_attrp
(ATTR_CASE
, append_expr
( NULL
, $2 ));
546 $$
= $4; if
(!$$
) $$
= make_var
(NULL
);
547 $$
->attrs
= append_attr
( $$
->attrs
, a
);
549 | tDEFAULT
':' field
{ attr_t
*a
= make_attr
(ATTR_DEFAULT
);
550 $$
= $3; if
(!$$
) $$
= make_var
(NULL
);
551 $$
->attrs
= append_attr
( $$
->attrs
, a
);
555 constdef: tCONST type ident
'=' expr_const
{ $$
= reg_const
($3);
556 set_type
($$
, $2, NULL
, NULL
, FALSE
);
561 enums: { $$
= NULL
; }
562 | enum_list
',' { $$
= $1; }
566 enum_list: enum { if
(!$1->eval
)
567 $1->eval
= make_exprl
(EXPR_NUM
, 0 /* default for first enum entry */);
568 $$
= append_var
( NULL
, $1 );
570 | enum_list
',' enum { if
(!$3->eval
)
572 var_t
*last
= LIST_ENTRY
( list_tail
($$
), var_t
, entry
);
573 $3->eval
= make_exprl
(EXPR_NUM
, last
->eval
->cval
+ 1);
575 $$
= append_var
( $1, $3 );
579 enum: ident
'=' expr_const
{ $$
= reg_const
($1);
581 $$
->type
= make_int
(0);
583 | ident
{ $$
= reg_const
($1);
584 $$
->type
= make_int
(0);
588 enumdef: tENUM t_ident
'{' enums
'}' { $$
= get_typev
(RPC_FC_ENUM16
, $2, tsENUM
);
589 $$
->kind
= TKIND_ENUM
;
590 $$
->fields_or_args
= $4;
593 add_typelib_entry
($$
);
597 m_exprs: m_expr
{ $$
= append_expr
( NULL
, $1 ); }
598 | m_exprs
',' m_expr
{ $$
= append_expr
( $1, $3 ); }
602 exprs: { $$ = make_expr(EXPR_VOID); }
607 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
611 m_expr: { $$
= make_expr
(EXPR_VOID
); }
615 expr: aNUM
{ $$
= make_exprl
(EXPR_NUM
, $1); }
616 | aHEXNUM
{ $$
= make_exprl
(EXPR_HEXNUM
, $1); }
617 | aDOUBLE
{ $$
= make_exprd
(EXPR_DOUBLE
, $1); }
618 | tFALSE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 0); }
619 | tTRUE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 1); }
620 | aIDENTIFIER
{ $$
= make_exprs
(EXPR_IDENTIFIER
, $1); }
621 | expr
'?' expr
':' expr
{ $$
= make_expr3
(EXPR_COND
, $1, $3, $5); }
622 | expr
'|' expr
{ $$
= make_expr2
(EXPR_OR
, $1, $3); }
623 | expr
'&' expr
{ $$
= make_expr2
(EXPR_AND
, $1, $3); }
624 | expr
'+' expr
{ $$
= make_expr2
(EXPR_ADD
, $1, $3); }
625 | expr
'-' expr
{ $$
= make_expr2
(EXPR_SUB
, $1, $3); }
626 | expr
'*' expr
{ $$
= make_expr2
(EXPR_MUL
, $1, $3); }
627 | expr
'/' expr
{ $$
= make_expr2
(EXPR_DIV
, $1, $3); }
628 | expr SHL expr
{ $$
= make_expr2
(EXPR_SHL
, $1, $3); }
629 | expr SHR expr
{ $$
= make_expr2
(EXPR_SHR
, $1, $3); }
630 |
'~' expr
{ $$
= make_expr1
(EXPR_NOT
, $2); }
631 |
'-' expr %prec NEG
{ $$
= make_expr1
(EXPR_NEG
, $2); }
632 |
'&' expr %prec ADDRESSOF
{ $$
= make_expr1
(EXPR_ADDRESSOF
, $2); }
633 |
'*' expr %prec PPTR
{ $$
= make_expr1
(EXPR_PPTR
, $2); }
634 |
'(' type
')' expr %prec CAST
{ $$
= make_exprt
(EXPR_CAST
, $2, $4); }
635 | tSIZEOF
'(' type
')' { $$
= make_exprt
(EXPR_SIZEOF
, $3, NULL
); }
636 |
'(' expr
')' { $$
= $2; }
639 expr_list_const: expr_const
{ $$
= append_expr
( NULL
, $1 ); }
640 | expr_list_const
',' expr_const
{ $$
= append_expr
( $1, $3 ); }
643 expr_const: expr
{ $$
= $1;
645 error_loc
("expression is not constant\n");
649 externdef: tEXTERN tCONST type ident
{ $$
= $4;
650 set_type
($$
, $3, NULL
, NULL
, FALSE
);
654 fields: { $$
= NULL
; }
655 | fields field
{ $$
= append_var
( $1, $2 ); }
658 field: s_field
';' { $$
= $1; }
659 | m_attributes uniondef
';' { $$
= make_var
(NULL
); $$
->type
= $2; $$
->attrs
= $1; }
660 | attributes
';' { $$
= make_var
(NULL
); $$
->attrs
= $1; }
664 s_field: m_attributes type pident array
{ $$
= $3->var
;
665 $$
->attrs
= check_field_attrs
($$
->name
, $1);
666 set_type
($$
, $2, $3, $4, FALSE
);
672 m_attributes type pident
{ var_t
*v
= $3->var
;
673 var_list_t
*args
= $3->args
;
674 v
->attrs
= check_function_attrs
(v
->name
, $1);
675 set_type
(v
, $2, $3, NULL
, FALSE
);
677 $$
= make_func
(v
, args
);
681 m_ident: { $$
= NULL
; }
685 t_ident: { $$
= NULL
; }
686 | aIDENTIFIER
{ $$
= make_var
($1); }
687 | aKNOWNTYPE
{ $$
= make_var
($1); }
690 ident: aIDENTIFIER
{ $$
= make_var
($1); }
691 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
692 | aKNOWNTYPE
{ $$
= make_var
($
<str
>1); }
695 base_type: tBYTE
{ $$
= make_builtin
($
<str
>1); }
696 | tWCHAR
{ $$
= make_builtin
($
<str
>1); }
698 | tSIGNED int_std
{ $$
= $2; $$
->sign
= 1; }
699 | tUNSIGNED int_std
{ $$
= $2; $$
->sign
= -1;
701 case RPC_FC_CHAR
: break
;
702 case RPC_FC_SMALL
: $$
->type
= RPC_FC_USMALL
; break
;
703 case RPC_FC_SHORT
: $$
->type
= RPC_FC_USHORT
; break
;
704 case RPC_FC_LONG
: $$
->type
= RPC_FC_ULONG
; break
;
706 if
($$
->name
[0] == 'h') /* hyper, as opposed to __int64 */
708 $$
= alias
($$
, "MIDL_uhyper");
715 | tUNSIGNED
{ $$
= make_int
(-1); }
716 | tFLOAT
{ $$
= make_builtin
($
<str
>1); }
717 | tSINGLE
{ $$
= duptype
(find_type
("float", 0), 1); }
718 | tDOUBLE
{ $$
= make_builtin
($
<str
>1); }
719 | tBOOLEAN
{ $$
= make_builtin
($
<str
>1); }
720 | tERRORSTATUST
{ $$
= make_builtin
($
<str
>1); }
721 | tHANDLET
{ $$
= make_builtin
($
<str
>1); }
728 int_std: tINT
{ $$
= make_builtin
($
<str
>1); }
729 | tSHORT m_int
{ $$
= make_builtin
($
<str
>1); }
730 | tSMALL
{ $$
= make_builtin
($
<str
>1); }
731 | tLONG m_int
{ $$
= make_builtin
($
<str
>1); }
732 | tHYPER m_int
{ $$
= make_builtin
($
<str
>1); }
733 | tINT64
{ $$
= make_builtin
($
<str
>1); }
734 | tCHAR
{ $$
= make_builtin
($
<str
>1); }
737 coclass: tCOCLASS aIDENTIFIER
{ $$
= make_class
($2); }
738 | tCOCLASS aKNOWNTYPE
{ $$
= find_type
($2, 0);
739 if
($$
->defined
) error_loc
("multiple definition error\n");
740 if
($$
->kind
!= TKIND_COCLASS
) error_loc
("%s was not declared a coclass\n", $2);
744 coclasshdr: attributes coclass
{ $$
= $2;
745 $$
->attrs
= check_coclass_attrs
($2->name
, $1);
746 if
(!parse_only
&& do_header
)
748 if
(!parse_only
&& do_idfile
)
753 coclassdef: coclasshdr
'{' coclass_ints
'}' semicolon_opt
760 coclass_ints: { $$
= NULL
; }
761 | coclass_ints coclass_int
{ $$
= append_ifref
( $1, $2 ); }
765 m_attributes interfacedec
{ $$
= make_ifref
($2); $$
->attrs
= $1; }
768 dispinterface: tDISPINTERFACE aIDENTIFIER
{ $$
= get_type
(0, $2, 0); $$
->kind
= TKIND_DISPATCH
; }
769 | tDISPINTERFACE aKNOWNTYPE
{ $$
= get_type
(0, $2, 0); $$
->kind
= TKIND_DISPATCH
; }
772 dispinterfacehdr: attributes dispinterface
{ attr_t
*attrs
;
773 is_object_interface
= TRUE
;
775 if
($$
->defined
) error_loc
("multiple definition error\n");
776 attrs
= make_attr
(ATTR_DISPINTERFACE
);
777 $$
->attrs
= append_attr
( check_dispiface_attrs
($2->name
, $1), attrs
);
778 $$
->ref
= find_type
("IDispatch", 0);
779 if
(!$$
->ref
) error_loc
("IDispatch is undefined\n");
781 if
(!parse_only
&& do_header
) write_forward
($$
);
785 dispint_props: tPROPERTIES
':' { $$
= NULL
; }
786 | dispint_props s_field
';' { $$
= append_var
( $1, $2 ); }
789 dispint_meths: tMETHODS
':' { $$
= NULL
; }
790 | dispint_meths funcdef
';' { $$
= append_func
( $1, $2 ); }
793 dispinterfacedef: dispinterfacehdr
'{'
797 $$
->fields_or_args
= $3;
799 if
(!parse_only
&& do_header
) write_dispinterface
($$
);
800 if
(!parse_only
&& do_idfile
) write_diid
($$
);
803 '{' interface
';' '}' { $$
= $1;
804 $$
->fields_or_args
= $3->fields_or_args
;
805 $$
->funcs
= $3->funcs
;
806 if
(!parse_only
&& do_header
) write_dispinterface
($$
);
807 if
(!parse_only
&& do_idfile
) write_diid
($$
);
811 inherit: { $$
= NULL
; }
812 |
':' aKNOWNTYPE
{ $$
= find_type2
($2, 0); }
815 interface: tINTERFACE aIDENTIFIER
{ $$
= get_type
(RPC_FC_IP
, $2, 0); $$
->kind
= TKIND_INTERFACE
; }
816 | tINTERFACE aKNOWNTYPE
{ $$
= get_type
(RPC_FC_IP
, $2, 0); $$
->kind
= TKIND_INTERFACE
; }
819 interfacehdr: attributes interface
{ $$.interface
= $2;
820 $$.old_pointer_default
= pointer_default
;
821 if
(is_attr
($1, ATTR_POINTERDEFAULT
))
822 pointer_default
= get_attrv
($1, ATTR_POINTERDEFAULT
);
823 is_object_interface
= is_object
($1);
824 if
($2->defined
) error_loc
("multiple definition error\n");
825 $2->attrs
= check_iface_attrs
($2->name
, $1);
827 if
(!parse_only
&& do_header
) write_forward
($2);
831 interfacedef: interfacehdr inherit
832 '{' int_statements
'}' semicolon_opt
{ $$
= $1.interface
;
835 compute_method_indexes
($$
);
836 if
(!parse_only
&& do_header
) write_interface
($$
);
837 if
(!parse_only
&& local_stubs
) write_locals
(local_stubs
, $$
, TRUE
);
838 if
(!parse_only
&& do_idfile
) write_iid
($$
);
839 pointer_default
= $1.old_pointer_default
;
841 /* MIDL is able to import the definition of a base class from inside the
842 * definition of a derived class, I'll try to support it with this rule */
843 | interfacehdr
':' aIDENTIFIER
844 '{' import int_statements
'}'
845 semicolon_opt
{ $$
= $1.interface
;
846 $$
->ref
= find_type2
($3, 0);
847 if
(!$$
->ref
) error_loc
("base class '%s' not found in import\n", $3);
849 compute_method_indexes
($$
);
850 if
(!parse_only
&& do_header
) write_interface
($$
);
851 if
(!parse_only
&& local_stubs
) write_locals
(local_stubs
, $$
, TRUE
);
852 if
(!parse_only
&& do_idfile
) write_iid
($$
);
853 pointer_default
= $1.old_pointer_default
;
855 | dispinterfacedef semicolon_opt
{ $$
= $1; }
859 interface
';' { $$
= $1; if
(!parse_only
&& do_header
) write_forward
($$
); }
860 | dispinterface
';' { $$
= $1; if
(!parse_only
&& do_header
) write_forward
($$
); }
863 module: tMODULE aIDENTIFIER
{ $$
= make_type
(0, NULL
); $$
->name
= $2; $$
->kind
= TKIND_MODULE
; }
864 | tMODULE aKNOWNTYPE
{ $$
= make_type
(0, NULL
); $$
->name
= $2; $$
->kind
= TKIND_MODULE
; }
867 modulehdr: attributes module
{ $$
= $2;
868 $$
->attrs
= check_module_attrs
($2->name
, $1);
872 moduledef: modulehdr
'{' int_statements
'}'
873 semicolon_opt
{ $$
= $1;
875 /* FIXME: if (!parse_only && do_header) write_module($$); */
879 pident: '*' pident %prec PPTR
{ $$
= $2; $$
->ptr_level
++; }
880 | tCONST pident
{ $$
= $2; /* FIXME */ }
881 | callconv pident
{ $$
= $2;
882 if
($$
->callconv
) parser_warning
("multiple calling conventions %s, %s for function %s\n", $$
->callconv
, $1, $$
->var
->name
);
888 func_ident: direct_ident
'(' m_args
')'
895 direct_ident: ident
{ $$
= make_pident
($1); }
896 |
'(' pident
')' { $$
= $2; }
897 | func_ident
{ $$
= $1;
898 $$
->func_ptr_level
= $$
->ptr_level
;
904 pident
{ $$
= append_pident
( NULL
, $1 ); }
905 | pident_list
',' pident
{ $$
= append_pident
( $1, $3 ); }
909 tREF
{ $$
= RPC_FC_RP
; }
910 | tUNIQUE
{ $$
= RPC_FC_UP
; }
911 | tPTR
{ $$
= RPC_FC_FP
; }
914 structdef: tSTRUCT t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_STRUCT
, $2, tsSTRUCT
);
915 /* overwrite RPC_FC_STRUCT with a more exact type */
916 $$
->type
= get_struct_type
( $4 );
917 $$
->kind
= TKIND_RECORD
;
918 $$
->fields_or_args
= $4;
921 add_typelib_entry
($$
);
925 type: tVOID
{ $$
= duptype
(find_type
("void", 0), 1); }
926 | aKNOWNTYPE
{ $$
= find_type
($1, 0); }
927 | base_type
{ $$
= $1; }
928 | tCONST type
{ $$
= duptype
($2, 1); $$
->is_const
= TRUE
; }
929 | enumdef
{ $$
= $1; }
930 | tENUM aIDENTIFIER
{ $$
= find_type2
($2, tsENUM
); }
931 | structdef
{ $$
= $1; }
932 | tSTRUCT aIDENTIFIER
{ $$
= get_type
(RPC_FC_STRUCT
, $2, tsSTRUCT
); }
933 | uniondef
{ $$
= $1; }
934 | tUNION aIDENTIFIER
{ $$
= find_type2
($2, tsUNION
); }
935 | tSAFEARRAY
'(' type
')' { $$
= make_safearray
($3); }
938 typedef: tTYPEDEF m_attributes type pident_list
{ reg_typedefs
($3, $4, check_typedef_attrs
($2));
939 process_typedefs
($4);
943 uniondef: tUNION t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_NON_ENCAPSULATED_UNION
, $2, tsUNION
);
944 $$
->kind
= TKIND_UNION
;
945 $$
->fields_or_args
= $4;
949 tSWITCH
'(' s_field
')'
950 m_ident
'{' cases
'}' { var_t
*u
= $7;
951 $$
= get_typev
(RPC_FC_ENCAPSULATED_UNION
, $2, tsUNION
);
952 $$
->kind
= TKIND_UNION
;
953 if
(!u
) u
= make_var
( xstrdup
("tagged_union") );
954 u
->type
= make_type
(RPC_FC_NON_ENCAPSULATED_UNION
, NULL
);
955 u
->type
->kind
= TKIND_UNION
;
956 u
->type
->fields_or_args
= $9;
957 u
->type
->defined
= TRUE
;
958 $$
->fields_or_args
= append_var
( $$
->fields_or_args
, $5 );
959 $$
->fields_or_args
= append_var
( $$
->fields_or_args
, u
);
965 aNUM
{ $$
= MAKEVERSION
($1, 0); }
966 | aNUM
'.' aNUM
{ $$
= MAKEVERSION
($1, $3); }
971 static void decl_builtin
(const char *name
, unsigned char type
)
973 type_t
*t
= make_type
(type
, NULL
);
974 t
->name
= xstrdup
(name
);
975 reg_type
(t
, name
, 0);
978 static type_t
*make_builtin
(char *name
)
980 /* NAME is strdup'd in the lexer */
981 type_t
*t
= duptype
(find_type
(name
, 0), 0);
986 static type_t
*make_int
(int sign
)
988 type_t
*t
= duptype
(find_type
("int", 0), 1);
992 t
->type
= t
->type
== RPC_FC_LONG ? RPC_FC_ULONG
: RPC_FC_USHORT
;
997 void init_types
(void)
999 decl_builtin
("void", 0);
1000 decl_builtin
("byte", RPC_FC_BYTE
);
1001 decl_builtin
("wchar_t", RPC_FC_WCHAR
);
1002 decl_builtin
("int", RPC_FC_LONG
); /* win32 */
1003 decl_builtin
("short", RPC_FC_SHORT
);
1004 decl_builtin
("small", RPC_FC_SMALL
);
1005 decl_builtin
("long", RPC_FC_LONG
);
1006 decl_builtin
("hyper", RPC_FC_HYPER
);
1007 decl_builtin
("__int64", RPC_FC_HYPER
);
1008 decl_builtin
("char", RPC_FC_CHAR
);
1009 decl_builtin
("float", RPC_FC_FLOAT
);
1010 decl_builtin
("double", RPC_FC_DOUBLE
);
1011 decl_builtin
("boolean", RPC_FC_BYTE
);
1012 decl_builtin
("error_status_t", RPC_FC_ERROR_STATUS_T
);
1013 decl_builtin
("handle_t", RPC_FC_BIND_PRIMITIVE
);
1016 static str_list_t
*append_str
(str_list_t
*list
, char *str
)
1018 struct str_list_entry_t
*entry
;
1020 if
(!str
) return list
;
1023 list
= xmalloc
( sizeof
(*list
) );
1026 entry
= xmalloc
( sizeof
(*entry
) );
1028 list_add_tail
( list
, &entry
->entry
);
1032 static attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
)
1034 if
(!attr
) return list
;
1037 list
= xmalloc
( sizeof
(*list
) );
1040 list_add_tail
( list
, &attr
->entry
);
1044 static attr_t
*make_attr
(enum attr_type type
)
1046 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1052 static attr_t
*make_attrv
(enum attr_type type
, unsigned long val
)
1054 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1060 static attr_t
*make_attrp
(enum attr_type type
, void *val
)
1062 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1068 static expr_t
*make_expr
(enum expr_type type
)
1070 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
1074 e
->is_const
= FALSE
;
1079 static expr_t
*make_exprl
(enum expr_type type
, long val
)
1081 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
1085 e
->is_const
= FALSE
;
1086 /* check for numeric constant */
1087 if
(type
== EXPR_NUM || type
== EXPR_HEXNUM || type
== EXPR_TRUEFALSE
) {
1088 /* make sure true/false value is valid */
1089 assert
(type
!= EXPR_TRUEFALSE || val
== 0 || val
== 1);
1096 static expr_t
*make_exprd
(enum expr_type type
, double val
)
1098 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
1107 static expr_t
*make_exprs
(enum expr_type type
, char *val
)
1110 e
= xmalloc
(sizeof
(expr_t
));
1114 e
->is_const
= FALSE
;
1115 /* check for predefined constants */
1116 if
(type
== EXPR_IDENTIFIER
) {
1117 var_t
*c
= find_const
(val
, 0);
1119 e
->u.sval
= c
->name
;
1122 e
->cval
= c
->eval
->cval
;
1128 static expr_t
*make_exprt
(enum expr_type type
, type_t
*tref
, expr_t
*expr
)
1131 e
= xmalloc
(sizeof
(expr_t
));
1135 e
->is_const
= FALSE
;
1136 /* check for cast of constant expression */
1137 if
(type
== EXPR_SIZEOF
) {
1138 switch
(tref
->type
) {
1155 case RPC_FC_ERROR_STATUS_T
:
1166 if
(type
== EXPR_CAST
&& expr
->is_const
) {
1168 e
->cval
= expr
->cval
;
1173 static expr_t
*make_expr1
(enum expr_type type
, expr_t
*expr
)
1176 if
(type
== EXPR_ADDRESSOF
&& expr
->type
!= EXPR_IDENTIFIER
)
1177 error("address-of operator applied to invalid expression\n");
1178 e
= xmalloc
(sizeof
(expr_t
));
1182 e
->is_const
= FALSE
;
1183 /* check for compile-time optimization */
1184 if
(expr
->is_const
) {
1188 e
->cval
= -expr
->cval
;
1191 e
->cval
= ~expr
->cval
;
1194 e
->is_const
= FALSE
;
1201 static expr_t
*make_expr2
(enum expr_type type
, expr_t
*expr1
, expr_t
*expr2
)
1204 e
= xmalloc
(sizeof
(expr_t
));
1208 e
->is_const
= FALSE
;
1209 /* check for compile-time optimization */
1210 if
(expr1
->is_const
&& expr2
->is_const
) {
1214 e
->cval
= expr1
->cval
+ expr2
->cval
;
1217 e
->cval
= expr1
->cval
- expr2
->cval
;
1220 e
->cval
= expr1
->cval
* expr2
->cval
;
1223 e
->cval
= expr1
->cval
/ expr2
->cval
;
1226 e
->cval
= expr1
->cval | expr2
->cval
;
1229 e
->cval
= expr1
->cval
& expr2
->cval
;
1232 e
->cval
= expr1
->cval
<< expr2
->cval
;
1235 e
->cval
= expr1
->cval
>> expr2
->cval
;
1238 e
->is_const
= FALSE
;
1245 static expr_t
*make_expr3
(enum expr_type type
, expr_t
*expr1
, expr_t
*expr2
, expr_t
*expr3
)
1248 e
= xmalloc
(sizeof
(expr_t
));
1253 e
->is_const
= FALSE
;
1254 /* check for compile-time optimization */
1255 if
(expr1
->is_const
&& expr2
->is_const
&& expr3
->is_const
) {
1259 e
->cval
= expr1
->cval ? expr2
->cval
: expr3
->cval
;
1262 e
->is_const
= FALSE
;
1269 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
)
1271 if
(!expr
) return list
;
1274 list
= xmalloc
( sizeof
(*list
) );
1277 list_add_tail
( list
, &expr
->entry
);
1281 static array_dims_t
*append_array
(array_dims_t
*list
, expr_t
*expr
)
1283 if
(!expr
) return list
;
1286 list
= xmalloc
( sizeof
(*list
) );
1289 list_add_tail
( list
, &expr
->entry
);
1293 static struct list type_pool
= LIST_INIT
(type_pool
);
1300 type_t
*alloc_type
(void)
1302 type_pool_node_t
*node
= xmalloc
(sizeof
*node
);
1303 list_add_tail
(&type_pool
, &node
->link
);
1307 void set_all_tfswrite
(int val
)
1309 type_pool_node_t
*node
;
1310 LIST_FOR_EACH_ENTRY
(node
, &type_pool
, type_pool_node_t
, link
)
1311 node
->data.tfswrite
= val
;
1314 static type_t
*make_type
(unsigned char type
, type_t
*ref
)
1316 type_t
*t
= alloc_type
();
1318 t
->kind
= TKIND_PRIMITIVE
;
1324 t
->fields_or_args
= NULL
;
1328 t
->length_is
= NULL
;
1329 t
->typestring_offset
= 0;
1331 t
->declarray
= FALSE
;
1332 t
->ignore
= (parse_only
!= 0);
1333 t
->is_const
= FALSE
;
1337 t
->user_types_registered
= FALSE
;
1338 t
->tfswrite
= FALSE
;
1339 t
->typelib_idx
= -1;
1343 static void set_type
(var_t
*v
, type_t
*type
, const pident_t
*pident
, array_dims_t
*arr
,
1346 expr_list_t
*sizes
= get_attrp
(v
->attrs
, ATTR_SIZEIS
);
1347 expr_list_t
*lengs
= get_attrp
(v
->attrs
, ATTR_LENGTHIS
);
1348 int ptr_attr
= get_attrv
(v
->attrs
, ATTR_POINTERTYPE
);
1349 int ptr_type
= ptr_attr
;
1350 int sizeless
, has_varconf
;
1352 type_t
*atype
, **ptype
;
1353 int ptr_level
= (pident ? pident
->ptr_level
: 0);
1357 if
(!ptr_type
&& top
)
1358 ptr_type
= RPC_FC_RP
;
1360 for
( ; 0 < ptr_level
; --ptr_level
)
1362 v
->type
= make_type
(pointer_default
, v
->type
);
1363 if
(ptr_level
== 1 && ptr_type
&& !arr
)
1365 v
->type
->type
= ptr_type
;
1370 if
(ptr_type
&& !arr
)
1372 if
(is_ptr
(v
->type
))
1374 if
(v
->type
->type
!= ptr_type
)
1376 v
->type
= duptype
(v
->type
, 1);
1377 v
->type
->type
= ptr_type
;
1380 else if
(!arr
&& ptr_attr
)
1381 error("%s: pointer attribute applied to non-pointer type\n", v
->name
);
1384 if
(pident
&& pident
->is_func
) {
1385 int func_ptr_level
= pident
->func_ptr_level
;
1386 v
->type
= make_type
(RPC_FC_FUNCTION
, v
->type
);
1387 v
->type
->fields_or_args
= pident
->args
;
1388 if
(pident
->callconv
)
1389 v
->type
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, pident
->callconv
));
1390 else if
(is_object_interface
) {
1391 static char *stdmethodcalltype
;
1392 if
(!stdmethodcalltype
) stdmethodcalltype
= strdup
("STDMETHODCALLTYPE");
1393 v
->type
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, stdmethodcalltype
));
1395 for
(; func_ptr_level
> 0; func_ptr_level
--)
1396 v
->type
= make_type
(ptr_type
, v
->type
);
1400 if
(arr
) LIST_FOR_EACH_ENTRY_REV
(dim
, arr
, expr_t
, entry
)
1403 error("%s: only the first array dimension can be unspecified\n", v
->name
);
1407 unsigned int align
= 0;
1408 size_t size
= type_memsize
(v
->type
, &align
);
1411 error("%s: array dimension must be positive\n", v
->name
);
1413 if
(0xffffffffuL
/ size
< (unsigned long) dim
->cval
)
1414 error("%s: total array size is too large\n", v
->name
);
1415 else if
(0xffffuL
< size
* dim
->cval
)
1416 v
->type
= make_type
(RPC_FC_LGFARRAY
, v
->type
);
1418 v
->type
= make_type
(RPC_FC_SMFARRAY
, v
->type
);
1423 v
->type
= make_type
(RPC_FC_CARRAY
, v
->type
);
1426 v
->type
->declarray
= TRUE
;
1427 v
->type
->dim
= dim
->cval
;
1431 has_varconf
= FALSE
;
1432 if
(sizes
) LIST_FOR_EACH_ENTRY
(dim
, sizes
, expr_t
, entry
)
1434 if
(dim
->type
!= EXPR_VOID
)
1437 atype
= *ptype
= duptype
(*ptype
, 0);
1439 if
(atype
->type
== RPC_FC_SMFARRAY || atype
->type
== RPC_FC_LGFARRAY
)
1440 error("%s: cannot specify size_is for a fixed sized array\n", v
->name
);
1442 if
(atype
->type
!= RPC_FC_CARRAY
&& !is_ptr
(atype
))
1443 error("%s: size_is attribute applied to illegal type\n", v
->name
);
1445 atype
->type
= RPC_FC_CARRAY
;
1446 atype
->size_is
= dim
;
1449 ptype
= &(*ptype
)->ref
;
1451 error("%s: too many expressions in size_is attribute\n", v
->name
);
1455 if
(lengs
) LIST_FOR_EACH_ENTRY
(dim
, lengs
, expr_t
, entry
)
1457 if
(dim
->type
!= EXPR_VOID
)
1460 atype
= *ptype
= duptype
(*ptype
, 0);
1462 if
(atype
->type
== RPC_FC_SMFARRAY
)
1463 atype
->type
= RPC_FC_SMVARRAY
;
1464 else if
(atype
->type
== RPC_FC_LGFARRAY
)
1465 atype
->type
= RPC_FC_LGVARRAY
;
1466 else if
(atype
->type
== RPC_FC_CARRAY
)
1467 atype
->type
= RPC_FC_CVARRAY
;
1469 error("%s: length_is attribute applied to illegal type\n", v
->name
);
1471 atype
->length_is
= dim
;
1474 ptype
= &(*ptype
)->ref
;
1476 error("%s: too many expressions in length_is attribute\n", v
->name
);
1479 if
(has_varconf
&& !last_array
(v
->type
))
1482 for
(ptype
= &v
->type
; is_array
(*ptype
); ptype
= &(*ptype
)->ref
)
1484 *ptype
= duptype
(*ptype
, 0);
1485 (*ptype
)->type
= RPC_FC_BOGUS_ARRAY
;
1489 if
(is_array
(v
->type
))
1491 const type_t
*rt
= v
->type
->ref
;
1492 if
(is_user_type
(rt
))
1493 v
->type
->type
= RPC_FC_BOGUS_ARRAY
;
1497 case RPC_FC_BOGUS_STRUCT
:
1498 case RPC_FC_NON_ENCAPSULATED_UNION
:
1499 case RPC_FC_ENCAPSULATED_UNION
:
1501 v
->type
->type
= RPC_FC_BOGUS_ARRAY
;
1503 /* FC_RP should be above, but widl overuses these, and will break things. */
1506 if
(rt
->ref
->type
== RPC_FC_IP
)
1507 v
->type
->type
= RPC_FC_BOGUS_ARRAY
;
1513 static ifref_list_t
*append_ifref
(ifref_list_t
*list
, ifref_t
*iface
)
1515 if
(!iface
) return list
;
1518 list
= xmalloc
( sizeof
(*list
) );
1521 list_add_tail
( list
, &iface
->entry
);
1525 static ifref_t
*make_ifref
(type_t
*iface
)
1527 ifref_t
*l
= xmalloc
(sizeof
(ifref_t
));
1533 static var_list_t
*append_var
(var_list_t
*list
, var_t
*var
)
1535 if
(!var
) return list
;
1538 list
= xmalloc
( sizeof
(*list
) );
1541 list_add_tail
( list
, &var
->entry
);
1545 static var_t
*make_var
(char *name
)
1547 var_t
*v
= xmalloc
(sizeof
(var_t
));
1555 static pident_list_t
*append_pident
(pident_list_t
*list
, pident_t
*p
)
1557 if
(!p
) return list
;
1559 list
= xmalloc
(sizeof
(*list
));
1562 list_add_tail
(list
, &p
->entry
);
1566 static pident_t
*make_pident
(var_t
*var
)
1568 pident_t
*p
= xmalloc
(sizeof
(*p
));
1572 p
->func_ptr_level
= 0;
1578 static func_list_t
*append_func
(func_list_t
*list
, func_t
*func
)
1580 if
(!func
) return list
;
1583 list
= xmalloc
( sizeof
(*list
) );
1586 list_add_tail
( list
, &func
->entry
);
1590 static func_t
*make_func
(var_t
*def
, var_list_t
*args
)
1592 func_t
*f
= xmalloc
(sizeof
(func_t
));
1595 f
->ignore
= parse_only
;
1600 static type_t
*make_class
(char *name
)
1602 type_t
*c
= make_type
(0, NULL
);
1604 c
->kind
= TKIND_COCLASS
;
1608 static type_t
*make_safearray
(type_t
*type
)
1610 type_t
*sa
= duptype
(find_type
("SAFEARRAY", 0), 1);
1612 return make_type
(pointer_default
, sa
);
1617 static int hash_ident
(const char *name
)
1619 const char *p
= name
;
1621 /* a simple sum hash is probably good enough */
1626 return sum
& (HASHMAX
-1);
1629 /***** type repository *****/
1638 struct rtype
*type_hash
[HASHMAX
];
1640 static type_t
*reg_type
(type_t
*type
, const char *name
, int t
)
1645 error_loc
("registering named type without name\n");
1648 hash
= hash_ident
(name
);
1649 nt
= xmalloc
(sizeof
(struct rtype
));
1653 nt
->next
= type_hash
[hash
];
1654 type_hash
[hash
] = nt
;
1658 static int is_incomplete
(const type_t
*t
)
1660 return
!t
->defined
&& (is_struct
(t
->type
) || is_union
(t
->type
));
1663 static void add_incomplete
(type_t
*t
)
1665 struct typenode
*tn
= xmalloc
(sizeof
*tn
);
1667 list_add_tail
(&incomplete_types
, &tn
->entry
);
1670 static void fix_type
(type_t
*t
)
1672 if
(t
->kind
== TKIND_ALIAS
&& is_incomplete
(t
)) {
1673 type_t
*ot
= t
->orig
;
1675 t
->fields_or_args
= ot
->fields_or_args
;
1676 t
->defined
= ot
->defined
;
1680 static void fix_incomplete
(void)
1682 struct typenode
*tn
, *next
;
1684 LIST_FOR_EACH_ENTRY_SAFE
(tn
, next
, &incomplete_types
, struct typenode
, entry
) {
1690 static type_t
*reg_typedefs
(type_t
*type
, pident_list_t
*pidents
, attr_list_t
*attrs
)
1693 const pident_t
*pident
;
1695 int is_str
= is_attr
(attrs
, ATTR_STRING
);
1696 unsigned char ptr_type
= get_attrv
(attrs
, ATTR_POINTERTYPE
);
1707 if
(c
!= RPC_FC_CHAR
&& c
!= RPC_FC_BYTE
&& c
!= RPC_FC_WCHAR
)
1709 pident
= LIST_ENTRY
( list_head
( pidents
), const pident_t
, entry
);
1710 error_loc
("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
1715 /* We must generate names for tagless enum, struct or union.
1716 Typedef-ing a tagless enum, struct or union means we want the typedef
1717 to be included in a library whether it has other attributes or not,
1718 hence the public attribute. */
1719 if
((type
->kind
== TKIND_ENUM || type
->kind
== TKIND_RECORD
1720 || type
->kind
== TKIND_UNION
) && ! type
->name
&& ! parse_only
)
1722 if
(! is_attr
(attrs
, ATTR_PUBLIC
))
1723 attrs
= append_attr
( attrs
, make_attr
(ATTR_PUBLIC
) );
1724 type
->name
= gen_name
();
1727 LIST_FOR_EACH_ENTRY
( pident
, pidents
, const pident_t
, entry
)
1729 var_t
*name
= pident
->var
;
1733 int cptr
= pident
->ptr_level
;
1735 while
(cptr
> ptrc
) {
1736 cur
= ptr
= make_type
(pointer_default
, cur
);
1740 while
(cptr
< ptrc
) {
1745 if
(pident
->is_func
) {
1746 int func_ptr_level
= pident
->func_ptr_level
;
1747 cur
= make_type
(RPC_FC_FUNCTION
, cur
);
1748 cur
->fields_or_args
= pident
->args
;
1749 if
(pident
->callconv
)
1750 cur
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, pident
->callconv
));
1751 else if
(is_object_interface
) {
1752 static char *stdmethodcalltype
;
1753 if
(!stdmethodcalltype
) stdmethodcalltype
= strdup
("STDMETHODCALLTYPE");
1754 cur
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, stdmethodcalltype
));
1756 for
(; func_ptr_level
> 0; func_ptr_level
--)
1757 cur
= make_type
(pointer_default
, cur
);
1759 cur
= alias
(cur
, name
->name
);
1764 cur
->type
= ptr_type
;
1766 error_loc
("'%s': pointer attribute applied to non-pointer type\n",
1769 else if
(is_str
&& ! is_ptr
(cur
))
1770 error_loc
("'%s': [string] attribute applied to non-pointer type\n",
1773 if
(is_incomplete
(cur
))
1774 add_incomplete
(cur
);
1775 reg_type
(cur
, cur
->name
, 0);
1781 static type_t
*find_type
(const char *name
, int t
)
1783 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
1784 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
1787 error_loc
("type '%s' not found\n", name
);
1793 static type_t
*find_type2
(char *name
, int t
)
1795 type_t
*tp
= find_type
(name
, t
);
1800 int is_type
(const char *name
)
1802 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
1803 while
(cur
&& (cur
->t || strcmp
(cur
->name
, name
)))
1805 if
(cur
) return TRUE
;
1809 static type_t
*get_type
(unsigned char type
, char *name
, int t
)
1811 struct rtype
*cur
= NULL
;
1814 cur
= type_hash
[hash_ident
(name
)];
1815 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
1822 tp
= make_type
(type
, NULL
);
1824 if
(!name
) return tp
;
1825 return reg_type
(tp
, name
, t
);
1828 static type_t
*get_typev
(unsigned char type
, var_t
*name
, int t
)
1835 return get_type
(type
, sname
, t
);
1838 static int get_struct_type
(var_list_t
*fields
)
1840 int has_pointer
= 0;
1841 int has_conformance
= 0;
1842 int has_variance
= 0;
1845 if
(get_padding
(fields
))
1846 return RPC_FC_BOGUS_STRUCT
;
1848 if
(fields
) LIST_FOR_EACH_ENTRY
( field
, fields
, var_t
, entry
)
1850 type_t
*t
= field
->type
;
1852 if
(is_user_type
(t
))
1853 return RPC_FC_BOGUS_STRUCT
;
1864 case RPC_FC_ENCAPSULATED_UNION
:
1865 case RPC_FC_NON_ENCAPSULATED_UNION
:
1866 case RPC_FC_BOGUS_STRUCT
:
1867 return RPC_FC_BOGUS_STRUCT
;
1874 if
(field
->type
->declarray
)
1876 if
(is_string_type
(field
->attrs
, field
->type
))
1878 if
(is_conformant_array
(field
->type
))
1879 has_conformance
= 1;
1884 if
(is_array
(field
->type
->ref
))
1885 return RPC_FC_BOGUS_STRUCT
;
1887 if
(is_conformant_array
(field
->type
))
1889 has_conformance
= 1;
1890 if
(field
->type
->declarray
&& list_next
(fields
, &field
->entry
))
1891 error_loc
("field '%s' deriving from a conformant array must be the last field in the structure\n",
1894 if
(field
->type
->length_is
)
1897 t
= field
->type
->ref
;
1903 * RPC_FC_BYTE, RPC_FC_STRUCT, etc
1904 * Simple types don't effect the type of struct.
1905 * A struct containing a simple struct is still a simple struct.
1906 * So long as we can block copy the data, we return RPC_FC_STRUCT.
1908 case
0: /* void pointer */
1918 case RPC_FC_INT3264
:
1919 case RPC_FC_UINT3264
:
1932 case RPC_FC_CVARRAY
:
1933 case RPC_FC_BOGUS_ARRAY
:
1938 * Propagate member attributes
1939 * a struct should be at least as complex as its member
1941 case RPC_FC_CVSTRUCT
:
1942 has_conformance
= 1;
1947 case RPC_FC_CPSTRUCT
:
1948 has_conformance
= 1;
1949 if
(list_next
( fields
, &field
->entry
))
1950 error_loc
("field '%s' deriving from a conformant array must be the last field in the structure\n",
1955 case RPC_FC_CSTRUCT
:
1956 has_conformance
= 1;
1957 if
(list_next
( fields
, &field
->entry
))
1958 error_loc
("field '%s' deriving from a conformant array must be the last field in the structure\n",
1962 case RPC_FC_PSTRUCT
:
1967 error_loc
("Unknown struct member %s with type (0x%02x)\n", field
->name
, t
->type
);
1968 /* fallthru - treat it as complex */
1970 /* as soon as we see one of these these members, it's bogus... */
1971 case RPC_FC_ENCAPSULATED_UNION
:
1972 case RPC_FC_NON_ENCAPSULATED_UNION
:
1973 case RPC_FC_BOGUS_STRUCT
:
1975 return RPC_FC_BOGUS_STRUCT
;
1981 if
( has_conformance
)
1982 return RPC_FC_CVSTRUCT
;
1984 return RPC_FC_BOGUS_STRUCT
;
1986 if
( has_conformance
&& has_pointer
)
1987 return RPC_FC_CPSTRUCT
;
1988 if
( has_conformance
)
1989 return RPC_FC_CSTRUCT
;
1991 return RPC_FC_PSTRUCT
;
1992 return RPC_FC_STRUCT
;
1995 /***** constant repository *****/
2000 struct rconst
*next
;
2003 struct rconst
*const_hash
[HASHMAX
];
2005 static var_t
*reg_const
(var_t
*var
)
2010 error_loc
("registering constant without name\n");
2013 hash
= hash_ident
(var
->name
);
2014 nc
= xmalloc
(sizeof
(struct rconst
));
2015 nc
->name
= var
->name
;
2017 nc
->next
= const_hash
[hash
];
2018 const_hash
[hash
] = nc
;
2022 static var_t
*find_const
(char *name
, int f
)
2024 struct rconst
*cur
= const_hash
[hash_ident
(name
)];
2025 while
(cur
&& strcmp
(cur
->name
, name
))
2028 if
(f
) error_loc
("constant '%s' not found\n", name
);
2034 static void write_libid
(const char *name
, const attr_list_t
*attr
)
2036 const UUID
*uuid
= get_attrp
(attr
, ATTR_UUID
);
2037 write_guid
(idfile
, "LIBID", name
, uuid
);
2040 static void write_clsid
(type_t
*cls
)
2042 const UUID
*uuid
= get_attrp
(cls
->attrs
, ATTR_UUID
);
2043 write_guid
(idfile
, "CLSID", cls
->name
, uuid
);
2046 static void write_diid
(type_t
*iface
)
2048 const UUID
*uuid
= get_attrp
(iface
->attrs
, ATTR_UUID
);
2049 write_guid
(idfile
, "DIID", iface
->name
, uuid
);
2052 static void write_iid
(type_t
*iface
)
2054 const UUID
*uuid
= get_attrp
(iface
->attrs
, ATTR_UUID
);
2055 write_guid
(idfile
, "IID", iface
->name
, uuid
);
2058 static int compute_method_indexes
(type_t
*iface
)
2064 idx
= compute_method_indexes
(iface
->ref
);
2071 LIST_FOR_EACH_ENTRY
( f
, iface
->funcs
, func_t
, entry
)
2072 if
(! is_callas
(f
->def
->attrs
))
2078 static char *gen_name
(void)
2080 static const char format
[] = "__WIDL_%s_generated_name_%08lX";
2081 static unsigned long n
= 0;
2082 static const char *file_id
;
2088 char *dst
= dup_basename
(input_name
, ".idl");
2092 if
(! isalnum
((unsigned char) *dst
))
2095 size
= sizeof format
- 7 + strlen
(file_id
) + 8;
2098 name
= xmalloc
(size
);
2099 sprintf
(name
, format
, file_id
, n
++);
2103 static void process_typedefs
(pident_list_t
*pidents
)
2105 pident_t
*pident
, *next
;
2107 if
(!pidents
) return
;
2108 LIST_FOR_EACH_ENTRY_SAFE
( pident
, next
, pidents
, pident_t
, entry
)
2110 var_t
*var
= pident
->var
;
2111 type_t
*type
= find_type
(var
->name
, 0);
2113 if
(! parse_only
&& do_header
)
2114 write_typedef
(type
);
2115 if
(in_typelib
&& type
->attrs
)
2116 add_typelib_entry
(type
);
2125 unsigned int dce_compatible
: 1;
2126 unsigned int acf
: 1;
2127 unsigned int on_interface
: 1;
2128 unsigned int on_function
: 1;
2129 unsigned int on_arg
: 1;
2130 unsigned int on_type
: 1;
2131 unsigned int on_field
: 1;
2132 unsigned int on_library
: 1;
2133 unsigned int on_dispinterface
: 1;
2134 unsigned int on_module
: 1;
2135 unsigned int on_coclass
: 1;
2136 const char *display_name
;
2139 struct allowed_attr allowed_attr
[] =
2141 /* attr { D ACF I Fn ARG T Fi L DI M C <display name> } */
2142 /* ATTR_AGGREGATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "aggregatable" },
2143 /* ATTR_APPOBJECT */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "appobject" },
2144 /* ATTR_ASYNC */ { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, "async" },
2145 /* ATTR_AUTO_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "auto_handle" },
2146 /* ATTR_BINDABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "bindable" },
2147 /* ATTR_CALLAS */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "call_as" },
2148 /* ATTR_CALLCONV */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
},
2149 /* ATTR_CASE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "case" },
2150 /* ATTR_CONTEXTHANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "context_handle" },
2151 /* ATTR_CONTROL */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, "control" },
2152 /* ATTR_DEFAULT */ { 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, "default" },
2153 /* ATTR_DEFAULTCOLLELEM */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "defaultcollelem" },
2154 /* ATTR_DEFAULTVALUE_EXPR */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "defaultvalue" },
2155 /* ATTR_DEFAULTVALUE_STRING */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "defaultvalue" },
2156 /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "defaultvtable" },
2157 /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
},
2158 /* ATTR_DISPLAYBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "displaybind" },
2159 /* ATTR_DLLNAME */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, "dllname" },
2160 /* ATTR_DUAL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "dual" },
2161 /* ATTR_ENDPOINT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "endpoint" },
2162 /* ATTR_ENTRY_ORDINAL */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "entry" },
2163 /* ATTR_ENTRY_STRING */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "entry" },
2164 /* ATTR_EXPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "explicit_handle" },
2165 /* ATTR_HANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "handle" },
2166 /* ATTR_HELPCONTEXT */ { 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, "helpcontext" },
2167 /* ATTR_HELPFILE */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpfile" },
2168 /* ATTR_HELPSTRING */ { 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, "helpstring" },
2169 /* ATTR_HELPSTRINGCONTEXT */ { 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, "helpstringcontext" },
2170 /* ATTR_HELPSTRINGDLL */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpstringdll" },
2171 /* ATTR_HIDDEN */ { 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, "hidden" },
2172 /* ATTR_ID */ { 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, "id" },
2173 /* ATTR_IDEMPOTENT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "idempotent" },
2174 /* ATTR_IIDIS */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "iid_is" },
2175 /* ATTR_IMMEDIATEBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "immediatebind" },
2176 /* ATTR_IMPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "implicit_handle" },
2177 /* ATTR_IN */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "in" },
2178 /* ATTR_INPUTSYNC */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inputsync" },
2179 /* ATTR_LENGTHIS */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "length_is" },
2180 /* ATTR_LOCAL */ { 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, "local" },
2181 /* ATTR_NONBROWSABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "nonbrowsable" },
2182 /* ATTR_NONCREATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "noncreatable" },
2183 /* ATTR_NONEXTENSIBLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "nonextensible" },
2184 /* ATTR_OBJECT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "object" },
2185 /* ATTR_ODL */ { 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, "odl" },
2186 /* ATTR_OLEAUTOMATION */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "oleautomation" },
2187 /* ATTR_OPTIONAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "optional" },
2188 /* ATTR_OUT */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "out" },
2189 /* ATTR_POINTERDEFAULT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "pointer_default" },
2190 /* ATTR_POINTERTYPE */ { 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, "ref, unique or ptr" },
2191 /* ATTR_PROPGET */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "propget" },
2192 /* ATTR_PROPPUT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "propput" },
2193 /* ATTR_PROPPUTREF */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "propputref" },
2194 /* ATTR_PUBLIC */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "public" },
2195 /* ATTR_RANGE */ { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, "range" },
2196 /* ATTR_READONLY */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "readonly" },
2197 /* ATTR_REQUESTEDIT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "requestedit" },
2198 /* ATTR_RESTRICTED */ { 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, "restricted" },
2199 /* ATTR_RETVAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "retval" },
2200 /* ATTR_SIZEIS */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "size_is" },
2201 /* ATTR_SOURCE */ { 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, "source" },
2202 /* ATTR_STRICTCONTEXTHANDLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "strict_context_handle" },
2203 /* ATTR_STRING */ { 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, "string" },
2204 /* ATTR_SWITCHIS */ { 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "switch_is" },
2205 /* ATTR_SWITCHTYPE */ { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, "switch_type" },
2206 /* ATTR_TRANSMITAS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "transmit_as" },
2207 /* ATTR_UUID */ { 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, "uuid" },
2208 /* ATTR_V1ENUM */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "v1_enum" },
2209 /* ATTR_VARARG */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "vararg" },
2210 /* ATTR_VERSION */ { 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, "version" },
2211 /* ATTR_WIREMARSHAL */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "wire_marshal" },
2214 static const attr_list_t
*check_iface_attrs
(const char *name
, const attr_list_t
*attrs
)
2217 if
(!attrs
) return attrs
;
2218 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2220 if
(!allowed_attr
[attr
->type
].on_interface
)
2221 error_loc
("inapplicable attribute %s for interface %s\n",
2222 allowed_attr
[attr
->type
].display_name
, name
);
2227 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
)
2230 if
(!attrs
) return attrs
;
2231 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2233 if
(!allowed_attr
[attr
->type
].on_function
)
2234 error_loc
("inapplicable attribute %s for function %s\n",
2235 allowed_attr
[attr
->type
].display_name
, name
);
2240 static void check_arg
(var_t
*arg
)
2242 const type_t
*t
= arg
->type
;
2245 if
(t
->type
== 0 && ! is_var_ptr
(arg
))
2246 error_loc
("argument '%s' has void type\n", arg
->name
);
2250 LIST_FOR_EACH_ENTRY
(attr
, arg
->attrs
, const attr_t
, entry
)
2252 if
(!allowed_attr
[attr
->type
].on_arg
)
2253 error_loc
("inapplicable attribute %s for argument %s\n",
2254 allowed_attr
[attr
->type
].display_name
, arg
->name
);
2259 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
)
2262 if
(!attrs
) return attrs
;
2263 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2265 if
(!allowed_attr
[attr
->type
].on_type
)
2266 error_loc
("inapplicable attribute %s for typedef\n",
2267 allowed_attr
[attr
->type
].display_name
);
2272 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
)
2275 if
(!attrs
) return attrs
;
2276 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2278 if
(!allowed_attr
[attr
->type
].on_field
)
2279 error_loc
("inapplicable attribute %s for field %s\n",
2280 allowed_attr
[attr
->type
].display_name
, name
);
2285 static const attr_list_t
*check_library_attrs
(const char *name
, const attr_list_t
*attrs
)
2288 if
(!attrs
) return attrs
;
2289 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2291 if
(!allowed_attr
[attr
->type
].on_library
)
2292 error_loc
("inapplicable attribute %s for library %s\n",
2293 allowed_attr
[attr
->type
].display_name
, name
);
2298 static attr_list_t
*check_dispiface_attrs
(const char *name
, attr_list_t
*attrs
)
2301 if
(!attrs
) return attrs
;
2302 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2304 if
(!allowed_attr
[attr
->type
].on_dispinterface
)
2305 error_loc
("inapplicable attribute %s for dispinterface %s\n",
2306 allowed_attr
[attr
->type
].display_name
, name
);
2311 static const attr_list_t
*check_module_attrs
(const char *name
, const attr_list_t
*attrs
)
2314 if
(!attrs
) return attrs
;
2315 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2317 if
(!allowed_attr
[attr
->type
].on_module
)
2318 error_loc
("inapplicable attribute %s for module %s\n",
2319 allowed_attr
[attr
->type
].display_name
, name
);
2324 static const attr_list_t
*check_coclass_attrs
(const char *name
, const attr_list_t
*attrs
)
2327 if
(!attrs
) return attrs
;
2328 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2330 if
(!allowed_attr
[attr
->type
].on_coclass
)
2331 error_loc
("inapplicable attribute %s for coclass %s\n",
2332 allowed_attr
[attr
->type
].display_name
, name
);
2337 static void check_all_user_types
(ifref_list_t
*ifrefs
)
2339 const ifref_t
*ifref
;
2342 if
(ifrefs
) LIST_FOR_EACH_ENTRY
(ifref
, ifrefs
, const ifref_t
, entry
)
2344 const func_list_t
*fs
= ifref
->iface
->funcs
;
2345 if
(fs
) LIST_FOR_EACH_ENTRY
(f
, fs
, const func_t
, entry
)
2346 check_for_additional_prototype_types
(f
->args
);
2350 int is_valid_uuid
(const char *s
)
2354 for
(i
= 0; i
< 36; ++i
)
2355 if
(i
== 8 || i
== 13 || i
== 18 || i
== 23)
2361 if
(!isxdigit
(s
[i
]))
2364 return s
[i
] == '\0';