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
);
141 const char *get_attr_display_name
(enum attr_type type
);
150 attr_list_t
*attr_list
;
151 str_list_t
*str_list
;
153 expr_list_t
*expr_list
;
154 array_dims_t
*array_dims
;
157 var_list_t
*var_list
;
159 pident_list_t
*pident_list
;
161 func_list_t
*func_list
;
163 ifref_list_t
*ifref_list
;
168 interface_info_t ifinfo
;
171 %token
<str
> aIDENTIFIER
172 %token
<str
> aKNOWNTYPE
173 %token
<num
> aNUM aHEXNUM
179 %token tAGGREGATABLE tALLOCATE tAPPOBJECT tASYNC tASYNCUUID
180 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
181 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
182 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
183 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
185 %token tDEFAULTCOLLELEM
187 %token tDEFAULTVTABLE
189 %token tDISPINTERFACE
190 %token tDLLNAME tDOUBLE tDUAL
192 %token tENTRY tENUM tERRORSTATUST
193 %token tEXPLICITHANDLE tEXTERN
199 %token tHELPCONTEXT tHELPFILE
200 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
202 %token tHYPER tID tIDEMPOTENT
204 %token tIMMEDIATEBIND
205 %token tIMPLICITHANDLE
206 %token tIMPORT tIMPORTLIB
212 %token tLENGTHIS tLIBRARY
219 %token tNONEXTENSIBLE
220 %token tOBJECT tODL tOLEAUTOMATION
224 %token tPOINTERDEFAULT
226 %token tPROPGET tPROPPUT tPROPPUTREF
230 %token tREADONLY tREF
238 %token tSIZEIS tSIZEOF
242 %token tSTRICTCONTEXTHANDLE
243 %token tSTRING tSTRUCT
244 %token tSWITCH tSWITCHIS tSWITCHTYPE
256 %token tWCHAR tWIREMARSHAL
258 %type
<attr
> attribute
259 %type
<attr_list
> m_attributes attributes attrib_list
260 %type
<str_list
> str_list
261 %type
<expr
> m_expr expr expr_const
262 %type
<expr_list
> m_exprs
/* exprs expr_list */ expr_list_const
263 %type
<array_dims
> array array_list
264 %type
<ifinfo
> interfacehdr
265 %type
<type
> inherit interface interfacedef interfacedec
266 %type
<type
> dispinterface dispinterfacehdr dispinterfacedef
267 %type
<type
> module modulehdr moduledef
268 %type
<type
> base_type int_std
269 %type
<type
> enumdef structdef uniondef
271 %type
<ifref
> coclass_int
272 %type
<ifref_list
> gbl_statements coclass_ints
273 %type
<var
> arg field s_field case
enum constdef externdef
274 %type
<var_list
> m_args no_args args fields cases enums enum_list dispint_props
275 %type
<var
> m_ident t_ident ident
276 %type
<pident
> pident func_ident direct_ident
277 %type
<pident_list
> pident_list
279 %type
<func_list
> int_statements dispint_meths
280 %type
<type
> coclass coclasshdr coclassdef
281 %type
<num
> pointer_type version
282 %type
<str
> libraryhdr callconv
283 %type
<uuid
> uuid_string
284 %type
<num
> import_start
301 input: gbl_statements
{ fix_incomplete
();
302 check_all_user_types
($1);
310 gbl_statements: { $$
= NULL
; }
311 | gbl_statements interfacedec
{ $$
= $1; }
312 | gbl_statements interfacedef
{ $$
= append_ifref
( $1, make_ifref
($2) ); }
313 | gbl_statements coclass
';' { $$
= $1;
314 reg_type
($2, $2->name
, 0);
315 if
(!parse_only
&& do_header
) write_coclass_forward
($2);
317 | gbl_statements coclassdef
{ $$
= $1;
318 add_typelib_entry
($2);
319 reg_type
($2, $2->name
, 0);
320 if
(!parse_only
&& do_header
) write_coclass_forward
($2);
322 | gbl_statements moduledef
{ $$
= $1; add_typelib_entry
($2); }
323 | gbl_statements librarydef
{ $$
= $1; }
324 | gbl_statements statement
{ $$
= $1; }
328 | imp_statements interfacedec
{ if
(!parse_only
) add_typelib_entry
($2); }
329 | imp_statements interfacedef
{ if
(!parse_only
) add_typelib_entry
($2); }
330 | imp_statements coclass
';' { reg_type
($2, $2->name
, 0); if
(!parse_only
&& do_header
) write_coclass_forward
($2); }
331 | imp_statements coclassdef
{ if
(!parse_only
) add_typelib_entry
($2);
332 reg_type
($2, $2->name
, 0);
333 if
(!parse_only
&& do_header
) write_coclass_forward
($2);
335 | imp_statements moduledef
{ if
(!parse_only
) add_typelib_entry
($2); }
336 | imp_statements statement
{}
337 | imp_statements importlib
{}
338 | imp_statements librarydef
{}
341 int_statements: { $$
= NULL
; }
342 | int_statements funcdef
';' { $$
= append_func
( $1, $2 ); }
343 | int_statements statement
{ $$
= $1; }
350 statement: constdef
';' { if
(!parse_only
&& do_header
) { write_constdef
($1); } }
352 | enumdef
';' { if
(!parse_only
&& do_header
) {
353 write_type_def_or_decl
(header
, $1, FALSE
, NULL
);
354 fprintf
(header
, ";\n\n");
357 | externdef
';' { if
(!parse_only
&& do_header
) { write_externdef
($1); } }
359 | structdef
';' { if
(!parse_only
&& do_header
) {
360 write_type_def_or_decl
(header
, $1, FALSE
, NULL
);
361 fprintf
(header
, ";\n\n");
365 | uniondef
';' { if
(!parse_only
&& do_header
) {
366 write_type_def_or_decl
(header
, $1, FALSE
, NULL
);
367 fprintf
(header
, ";\n\n");
372 cppquote: tCPPQUOTE
'(' aSTRING
')' { if
(!parse_only
&& do_header
) fprintf
(header
, "%s\n", $3); }
374 import_start: tIMPORT aSTRING
';' { assert
(yychar == YYEMPTY
);
376 if
(!$$
) yychar = aEOF
;
380 import: import_start imp_statements aEOF
381 { if
($1) pop_import
(); }
384 importlib: tIMPORTLIB
'(' aSTRING
')'
385 semicolon_opt
{ if
(!parse_only
) add_importlib
($3); }
388 libraryhdr: tLIBRARY aIDENTIFIER
{ $$
= $2; }
390 library_start: attributes libraryhdr
'{' { check_library_attrs
($2, $1);
391 if
(!parse_only
) start_typelib
($2, $1);
392 if
(!parse_only
&& do_header
) write_library
($2, $1);
393 if
(!parse_only
&& do_idfile
) write_libid
($2, $1);
396 librarydef: library_start imp_statements
'}'
397 semicolon_opt
{ if
(!parse_only
) end_typelib
(); }
400 m_args: { $$
= NULL
; }
404 no_args: tVOID
{ $$
= NULL
; }
407 args: arg
{ check_arg
($1); $$
= append_var
( NULL
, $1 ); }
408 | args
',' arg
{ check_arg
($3); $$
= append_var
( $1, $3); }
412 /* split into two rules to get bison to resolve a tVOID conflict */
413 arg: attributes type pident array
{ $$
= $3->var
;
415 set_type
($$
, $2, $3, $4, TRUE
);
418 | type pident array
{ $$
= $2->var
;
419 set_type
($$
, $1, $2, $3, TRUE
);
424 array: { $$
= NULL
; }
425 |
'[' array_list
']' { $$
= $2; }
426 |
'[' '*' ']' { $$
= append_array
( NULL
, make_expr
(EXPR_VOID
) ); }
429 array_list: m_expr
/* size of first dimension is optional */ { $$
= append_array
( NULL
, $1 ); }
430 | array_list
',' expr
{ $$
= append_array
( $1, $3 ); }
431 | array_list
']' '[' expr
{ $$
= append_array
( $1, $4 ); }
434 m_attributes: { $$
= NULL
; }
439 '[' attrib_list
']' { $$
= $2;
441 error_loc
("empty attribute lists unsupported\n");
445 attrib_list: attribute
{ $$
= append_attr
( NULL
, $1 ); }
446 | attrib_list
',' attribute
{ $$
= append_attr
( $1, $3 ); }
447 | attrib_list
']' '[' attribute
{ $$
= append_attr
( $1, $4 ); }
450 str_list: aSTRING
{ $$
= append_str
( NULL
, $1 ); }
451 | str_list
',' aSTRING
{ $$
= append_str
( $1, $3 ); }
454 attribute: { $$
= NULL
; }
455 | tAGGREGATABLE
{ $$
= make_attr
(ATTR_AGGREGATABLE
); }
456 | tAPPOBJECT
{ $$
= make_attr
(ATTR_APPOBJECT
); }
457 | tASYNC
{ $$
= make_attr
(ATTR_ASYNC
); }
458 | tAUTOHANDLE
{ $$
= make_attr
(ATTR_AUTO_HANDLE
); }
459 | tBINDABLE
{ $$
= make_attr
(ATTR_BINDABLE
); }
460 | tBROADCAST
{ $$
= make_attr
(ATTR_BROADCAST
); }
461 | tCALLAS
'(' ident
')' { $$
= make_attrp
(ATTR_CALLAS
, $3); }
462 | tCASE
'(' expr_list_const
')' { $$
= make_attrp
(ATTR_CASE
, $3); }
463 | tCONTEXTHANDLE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); }
464 | tCONTEXTHANDLENOSERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
465 | tCONTEXTHANDLESERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
466 | tCONTROL
{ $$
= make_attr
(ATTR_CONTROL
); }
467 | tDEFAULT
{ $$
= make_attr
(ATTR_DEFAULT
); }
468 | tDEFAULTCOLLELEM
{ $$
= make_attr
(ATTR_DEFAULTCOLLELEM
); }
469 | tDEFAULTVALUE
'(' expr_const
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE_EXPR
, $3); }
470 | tDEFAULTVALUE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE_STRING
, $3); }
471 | tDEFAULTVTABLE
{ $$
= make_attr
(ATTR_DEFAULTVTABLE
); }
472 | tDISPLAYBIND
{ $$
= make_attr
(ATTR_DISPLAYBIND
); }
473 | tDLLNAME
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DLLNAME
, $3); }
474 | tDUAL
{ $$
= make_attr
(ATTR_DUAL
); }
475 | tENDPOINT
'(' str_list
')' { $$
= make_attrp
(ATTR_ENDPOINT
, $3); }
476 | tENTRY
'(' aSTRING
')' { $$
= make_attrp
(ATTR_ENTRY_STRING
, $3); }
477 | tENTRY
'(' expr_const
')' { $$
= make_attrp
(ATTR_ENTRY_ORDINAL
, $3); }
478 | tEXPLICITHANDLE
{ $$
= make_attr
(ATTR_EXPLICIT_HANDLE
); }
479 | tHANDLE
{ $$
= make_attr
(ATTR_HANDLE
); }
480 | tHELPCONTEXT
'(' expr_const
')' { $$
= make_attrp
(ATTR_HELPCONTEXT
, $3); }
481 | tHELPFILE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPFILE
, $3); }
482 | tHELPSTRING
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRING
, $3); }
483 | tHELPSTRINGCONTEXT
'(' expr_const
')' { $$
= make_attrp
(ATTR_HELPSTRINGCONTEXT
, $3); }
484 | tHELPSTRINGDLL
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRINGDLL
, $3); }
485 | tHIDDEN
{ $$
= make_attr
(ATTR_HIDDEN
); }
486 | tID
'(' expr_const
')' { $$
= make_attrp
(ATTR_ID
, $3); }
487 | tIDEMPOTENT
{ $$
= make_attr
(ATTR_IDEMPOTENT
); }
488 | tIIDIS
'(' expr
')' { $$
= make_attrp
(ATTR_IIDIS
, $3); }
489 | tIMMEDIATEBIND
{ $$
= make_attr
(ATTR_IMMEDIATEBIND
); }
490 | tIMPLICITHANDLE
'(' tHANDLET aIDENTIFIER
')' { $$
= make_attrp
(ATTR_IMPLICIT_HANDLE
, $4); }
491 | tIN
{ $$
= make_attr
(ATTR_IN
); }
492 | tINPUTSYNC
{ $$
= make_attr
(ATTR_INPUTSYNC
); }
493 | tLENGTHIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_LENGTHIS
, $3); }
494 | tLOCAL
{ $$
= make_attr
(ATTR_LOCAL
); }
495 | tNONBROWSABLE
{ $$
= make_attr
(ATTR_NONBROWSABLE
); }
496 | tNONCREATABLE
{ $$
= make_attr
(ATTR_NONCREATABLE
); }
497 | tNONEXTENSIBLE
{ $$
= make_attr
(ATTR_NONEXTENSIBLE
); }
498 | tOBJECT
{ $$
= make_attr
(ATTR_OBJECT
); }
499 | tODL
{ $$
= make_attr
(ATTR_ODL
); }
500 | tOLEAUTOMATION
{ $$
= make_attr
(ATTR_OLEAUTOMATION
); }
501 | tOPTIONAL
{ $$
= make_attr
(ATTR_OPTIONAL
); }
502 | tOUT
{ $$
= make_attr
(ATTR_OUT
); }
503 | tPOINTERDEFAULT
'(' pointer_type
')' { $$
= make_attrv
(ATTR_POINTERDEFAULT
, $3); }
504 | tPROPGET
{ $$
= make_attr
(ATTR_PROPGET
); }
505 | tPROPPUT
{ $$
= make_attr
(ATTR_PROPPUT
); }
506 | tPROPPUTREF
{ $$
= make_attr
(ATTR_PROPPUTREF
); }
507 | tPUBLIC
{ $$
= make_attr
(ATTR_PUBLIC
); }
508 | tRANGE
'(' expr_const
',' expr_const
')' { expr_list_t
*list
= append_expr
( NULL
, $3 );
509 list
= append_expr
( list
, $5 );
510 $$
= make_attrp
(ATTR_RANGE
, list
); }
511 | tREADONLY
{ $$
= make_attr
(ATTR_READONLY
); }
512 | tREQUESTEDIT
{ $$
= make_attr
(ATTR_REQUESTEDIT
); }
513 | tRESTRICTED
{ $$
= make_attr
(ATTR_RESTRICTED
); }
514 | tRETVAL
{ $$
= make_attr
(ATTR_RETVAL
); }
515 | tSIZEIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_SIZEIS
, $3); }
516 | tSOURCE
{ $$
= make_attr
(ATTR_SOURCE
); }
517 | tSTRICTCONTEXTHANDLE
{ $$
= make_attr
(ATTR_STRICTCONTEXTHANDLE
); }
518 | tSTRING
{ $$
= make_attr
(ATTR_STRING
); }
519 | tSWITCHIS
'(' expr
')' { $$
= make_attrp
(ATTR_SWITCHIS
, $3); }
520 | tSWITCHTYPE
'(' type
')' { $$
= make_attrp
(ATTR_SWITCHTYPE
, $3); }
521 | tTRANSMITAS
'(' type
')' { $$
= make_attrp
(ATTR_TRANSMITAS
, $3); }
522 | tUUID
'(' uuid_string
')' { $$
= make_attrp
(ATTR_UUID
, $3); }
523 | tV1ENUM
{ $$
= make_attr
(ATTR_V1ENUM
); }
524 | tVARARG
{ $$
= make_attr
(ATTR_VARARG
); }
525 | tVERSION
'(' version
')' { $$
= make_attrv
(ATTR_VERSION
, $3); }
526 | tWIREMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_WIREMARSHAL
, $3); }
527 | pointer_type
{ $$
= make_attrv
(ATTR_POINTERTYPE
, $1); }
532 | aSTRING
{ if
(!is_valid_uuid
($1))
533 error_loc
("invalid UUID: %s\n", $1);
534 $$
= parse_uuid
($1); }
537 callconv: tCDECL
{ $$
= $
<str
>1; }
538 | tFASTCALL
{ $$
= $
<str
>1; }
539 | tPASCAL
{ $$
= $
<str
>1; }
540 | tSTDCALL
{ $$
= $
<str
>1; }
543 cases: { $$
= NULL
; }
544 | cases case
{ $$
= append_var
( $1, $2 ); }
547 case: tCASE expr
':' field
{ attr_t
*a
= make_attrp
(ATTR_CASE
, append_expr
( NULL
, $2 ));
548 $$
= $4; if
(!$$
) $$
= make_var
(NULL
);
549 $$
->attrs
= append_attr
( $$
->attrs
, a
);
551 | tDEFAULT
':' field
{ attr_t
*a
= make_attr
(ATTR_DEFAULT
);
552 $$
= $3; if
(!$$
) $$
= make_var
(NULL
);
553 $$
->attrs
= append_attr
( $$
->attrs
, a
);
557 constdef: tCONST type ident
'=' expr_const
{ $$
= reg_const
($3);
558 set_type
($$
, $2, NULL
, NULL
, FALSE
);
563 enums: { $$
= NULL
; }
564 | enum_list
',' { $$
= $1; }
568 enum_list: enum { if
(!$1->eval
)
569 $1->eval
= make_exprl
(EXPR_NUM
, 0 /* default for first enum entry */);
570 $$
= append_var
( NULL
, $1 );
572 | enum_list
',' enum { if
(!$3->eval
)
574 var_t
*last
= LIST_ENTRY
( list_tail
($$
), var_t
, entry
);
575 $3->eval
= make_exprl
(EXPR_NUM
, last
->eval
->cval
+ 1);
577 $$
= append_var
( $1, $3 );
581 enum: ident
'=' expr_const
{ $$
= reg_const
($1);
583 $$
->type
= make_int
(0);
585 | ident
{ $$
= reg_const
($1);
586 $$
->type
= make_int
(0);
590 enumdef: tENUM t_ident
'{' enums
'}' { $$
= get_typev
(RPC_FC_ENUM16
, $2, tsENUM
);
591 $$
->kind
= TKIND_ENUM
;
592 $$
->fields_or_args
= $4;
595 add_typelib_entry
($$
);
599 m_exprs: m_expr
{ $$
= append_expr
( NULL
, $1 ); }
600 | m_exprs
',' m_expr
{ $$
= append_expr
( $1, $3 ); }
604 exprs: { $$ = make_expr(EXPR_VOID); }
609 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
613 m_expr: { $$
= make_expr
(EXPR_VOID
); }
617 expr: aNUM
{ $$
= make_exprl
(EXPR_NUM
, $1); }
618 | aHEXNUM
{ $$
= make_exprl
(EXPR_HEXNUM
, $1); }
619 | aDOUBLE
{ $$
= make_exprd
(EXPR_DOUBLE
, $1); }
620 | tFALSE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 0); }
621 | tTRUE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 1); }
622 | aIDENTIFIER
{ $$
= make_exprs
(EXPR_IDENTIFIER
, $1); }
623 | expr
'?' expr
':' expr
{ $$
= make_expr3
(EXPR_COND
, $1, $3, $5); }
624 | expr
'|' expr
{ $$
= make_expr2
(EXPR_OR
, $1, $3); }
625 | expr
'&' expr
{ $$
= make_expr2
(EXPR_AND
, $1, $3); }
626 | expr
'+' expr
{ $$
= make_expr2
(EXPR_ADD
, $1, $3); }
627 | expr
'-' expr
{ $$
= make_expr2
(EXPR_SUB
, $1, $3); }
628 | expr
'*' expr
{ $$
= make_expr2
(EXPR_MUL
, $1, $3); }
629 | expr
'/' expr
{ $$
= make_expr2
(EXPR_DIV
, $1, $3); }
630 | expr SHL expr
{ $$
= make_expr2
(EXPR_SHL
, $1, $3); }
631 | expr SHR expr
{ $$
= make_expr2
(EXPR_SHR
, $1, $3); }
632 |
'~' expr
{ $$
= make_expr1
(EXPR_NOT
, $2); }
633 |
'-' expr %prec NEG
{ $$
= make_expr1
(EXPR_NEG
, $2); }
634 |
'&' expr %prec ADDRESSOF
{ $$
= make_expr1
(EXPR_ADDRESSOF
, $2); }
635 |
'*' expr %prec PPTR
{ $$
= make_expr1
(EXPR_PPTR
, $2); }
636 |
'(' type
')' expr %prec CAST
{ $$
= make_exprt
(EXPR_CAST
, $2, $4); }
637 | tSIZEOF
'(' type
')' { $$
= make_exprt
(EXPR_SIZEOF
, $3, NULL
); }
638 |
'(' expr
')' { $$
= $2; }
641 expr_list_const: expr_const
{ $$
= append_expr
( NULL
, $1 ); }
642 | expr_list_const
',' expr_const
{ $$
= append_expr
( $1, $3 ); }
645 expr_const: expr
{ $$
= $1;
647 error_loc
("expression is not constant\n");
651 externdef: tEXTERN tCONST type ident
{ $$
= $4;
652 set_type
($$
, $3, NULL
, NULL
, FALSE
);
656 fields: { $$
= NULL
; }
657 | fields field
{ $$
= append_var
( $1, $2 ); }
660 field: s_field
';' { $$
= $1; }
661 | m_attributes uniondef
';' { $$
= make_var
(NULL
); $$
->type
= $2; $$
->attrs
= $1; }
662 | attributes
';' { $$
= make_var
(NULL
); $$
->attrs
= $1; }
666 s_field: m_attributes type pident array
{ $$
= $3->var
;
667 $$
->attrs
= check_field_attrs
($$
->name
, $1);
668 set_type
($$
, $2, $3, $4, FALSE
);
674 m_attributes type pident
{ var_t
*v
= $3->var
;
675 var_list_t
*args
= $3->args
;
676 v
->attrs
= check_function_attrs
(v
->name
, $1);
677 set_type
(v
, $2, $3, NULL
, FALSE
);
679 $$
= make_func
(v
, args
);
683 m_ident: { $$
= NULL
; }
687 t_ident: { $$
= NULL
; }
688 | aIDENTIFIER
{ $$
= make_var
($1); }
689 | aKNOWNTYPE
{ $$
= make_var
($1); }
692 ident: aIDENTIFIER
{ $$
= make_var
($1); }
693 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
694 | aKNOWNTYPE
{ $$
= make_var
($
<str
>1); }
697 base_type: tBYTE
{ $$
= make_builtin
($
<str
>1); }
698 | tWCHAR
{ $$
= make_builtin
($
<str
>1); }
700 | tSIGNED int_std
{ $$
= $2; $$
->sign
= 1; }
701 | tUNSIGNED int_std
{ $$
= $2; $$
->sign
= -1;
703 case RPC_FC_CHAR
: break
;
704 case RPC_FC_SMALL
: $$
->type
= RPC_FC_USMALL
; break
;
705 case RPC_FC_SHORT
: $$
->type
= RPC_FC_USHORT
; break
;
706 case RPC_FC_LONG
: $$
->type
= RPC_FC_ULONG
; break
;
708 if
($$
->name
[0] == 'h') /* hyper, as opposed to __int64 */
710 $$
= alias
($$
, "MIDL_uhyper");
717 | tUNSIGNED
{ $$
= make_int
(-1); }
718 | tFLOAT
{ $$
= make_builtin
($
<str
>1); }
719 | tSINGLE
{ $$
= duptype
(find_type
("float", 0), 1); }
720 | tDOUBLE
{ $$
= make_builtin
($
<str
>1); }
721 | tBOOLEAN
{ $$
= make_builtin
($
<str
>1); }
722 | tERRORSTATUST
{ $$
= make_builtin
($
<str
>1); }
723 | tHANDLET
{ $$
= make_builtin
($
<str
>1); }
730 int_std: tINT
{ $$
= make_builtin
($
<str
>1); }
731 | tSHORT m_int
{ $$
= make_builtin
($
<str
>1); }
732 | tSMALL
{ $$
= make_builtin
($
<str
>1); }
733 | tLONG m_int
{ $$
= make_builtin
($
<str
>1); }
734 | tHYPER m_int
{ $$
= make_builtin
($
<str
>1); }
735 | tINT64
{ $$
= make_builtin
($
<str
>1); }
736 | tCHAR
{ $$
= make_builtin
($
<str
>1); }
739 coclass: tCOCLASS aIDENTIFIER
{ $$
= make_class
($2); }
740 | tCOCLASS aKNOWNTYPE
{ $$
= find_type
($2, 0);
741 if
($$
->defined
) error_loc
("multiple definition error\n");
742 if
($$
->kind
!= TKIND_COCLASS
) error_loc
("%s was not declared a coclass\n", $2);
746 coclasshdr: attributes coclass
{ $$
= $2;
747 $$
->attrs
= check_coclass_attrs
($2->name
, $1);
748 if
(!parse_only
&& do_header
)
750 if
(!parse_only
&& do_idfile
)
755 coclassdef: coclasshdr
'{' coclass_ints
'}' semicolon_opt
762 coclass_ints: { $$
= NULL
; }
763 | coclass_ints coclass_int
{ $$
= append_ifref
( $1, $2 ); }
767 m_attributes interfacedec
{ $$
= make_ifref
($2); $$
->attrs
= $1; }
770 dispinterface: tDISPINTERFACE aIDENTIFIER
{ $$
= get_type
(0, $2, 0); $$
->kind
= TKIND_DISPATCH
; }
771 | tDISPINTERFACE aKNOWNTYPE
{ $$
= get_type
(0, $2, 0); $$
->kind
= TKIND_DISPATCH
; }
774 dispinterfacehdr: attributes dispinterface
{ attr_t
*attrs
;
775 is_object_interface
= TRUE
;
777 if
($$
->defined
) error_loc
("multiple definition error\n");
778 attrs
= make_attr
(ATTR_DISPINTERFACE
);
779 $$
->attrs
= append_attr
( check_dispiface_attrs
($2->name
, $1), attrs
);
780 $$
->ref
= find_type
("IDispatch", 0);
781 if
(!$$
->ref
) error_loc
("IDispatch is undefined\n");
783 if
(!parse_only
&& do_header
) write_forward
($$
);
787 dispint_props: tPROPERTIES
':' { $$
= NULL
; }
788 | dispint_props s_field
';' { $$
= append_var
( $1, $2 ); }
791 dispint_meths: tMETHODS
':' { $$
= NULL
; }
792 | dispint_meths funcdef
';' { $$
= append_func
( $1, $2 ); }
795 dispinterfacedef: dispinterfacehdr
'{'
799 $$
->fields_or_args
= $3;
801 if
(!parse_only
&& do_header
) write_dispinterface
($$
);
802 if
(!parse_only
&& do_idfile
) write_diid
($$
);
805 '{' interface
';' '}' { $$
= $1;
806 $$
->fields_or_args
= $3->fields_or_args
;
807 $$
->funcs
= $3->funcs
;
808 if
(!parse_only
&& do_header
) write_dispinterface
($$
);
809 if
(!parse_only
&& do_idfile
) write_diid
($$
);
813 inherit: { $$
= NULL
; }
814 |
':' aKNOWNTYPE
{ $$
= find_type2
($2, 0); }
817 interface: tINTERFACE aIDENTIFIER
{ $$
= get_type
(RPC_FC_IP
, $2, 0); $$
->kind
= TKIND_INTERFACE
; }
818 | tINTERFACE aKNOWNTYPE
{ $$
= get_type
(RPC_FC_IP
, $2, 0); $$
->kind
= TKIND_INTERFACE
; }
821 interfacehdr: attributes interface
{ $$.interface
= $2;
822 $$.old_pointer_default
= pointer_default
;
823 if
(is_attr
($1, ATTR_POINTERDEFAULT
))
824 pointer_default
= get_attrv
($1, ATTR_POINTERDEFAULT
);
825 is_object_interface
= is_object
($1);
826 if
($2->defined
) error_loc
("multiple definition error\n");
827 $2->attrs
= check_iface_attrs
($2->name
, $1);
829 if
(!parse_only
&& do_header
) write_forward
($2);
833 interfacedef: interfacehdr inherit
834 '{' int_statements
'}' semicolon_opt
{ $$
= $1.interface
;
837 compute_method_indexes
($$
);
838 if
(!parse_only
&& do_header
) write_interface
($$
);
839 if
(!parse_only
&& local_stubs
) write_locals
(local_stubs
, $$
, TRUE
);
840 if
(!parse_only
&& do_idfile
) write_iid
($$
);
841 pointer_default
= $1.old_pointer_default
;
843 /* MIDL is able to import the definition of a base class from inside the
844 * definition of a derived class, I'll try to support it with this rule */
845 | interfacehdr
':' aIDENTIFIER
846 '{' import int_statements
'}'
847 semicolon_opt
{ $$
= $1.interface
;
848 $$
->ref
= find_type2
($3, 0);
849 if
(!$$
->ref
) error_loc
("base class '%s' not found in import\n", $3);
851 compute_method_indexes
($$
);
852 if
(!parse_only
&& do_header
) write_interface
($$
);
853 if
(!parse_only
&& local_stubs
) write_locals
(local_stubs
, $$
, TRUE
);
854 if
(!parse_only
&& do_idfile
) write_iid
($$
);
855 pointer_default
= $1.old_pointer_default
;
857 | dispinterfacedef semicolon_opt
{ $$
= $1; }
861 interface
';' { $$
= $1; if
(!parse_only
&& do_header
) write_forward
($$
); }
862 | dispinterface
';' { $$
= $1; if
(!parse_only
&& do_header
) write_forward
($$
); }
865 module: tMODULE aIDENTIFIER
{ $$
= make_type
(0, NULL
); $$
->name
= $2; $$
->kind
= TKIND_MODULE
; }
866 | tMODULE aKNOWNTYPE
{ $$
= make_type
(0, NULL
); $$
->name
= $2; $$
->kind
= TKIND_MODULE
; }
869 modulehdr: attributes module
{ $$
= $2;
870 $$
->attrs
= check_module_attrs
($2->name
, $1);
874 moduledef: modulehdr
'{' int_statements
'}'
875 semicolon_opt
{ $$
= $1;
877 /* FIXME: if (!parse_only && do_header) write_module($$); */
881 pident: '*' pident %prec PPTR
{ $$
= $2; $$
->ptr_level
++; }
882 | tCONST pident
{ $$
= $2; /* FIXME */ }
883 | callconv pident
{ $$
= $2;
884 if
($$
->callconv
) parser_warning
("multiple calling conventions %s, %s for function %s\n", $$
->callconv
, $1, $$
->var
->name
);
890 func_ident: direct_ident
'(' m_args
')'
897 direct_ident: ident
{ $$
= make_pident
($1); }
898 |
'(' pident
')' { $$
= $2; }
899 | func_ident
{ $$
= $1;
900 $$
->func_ptr_level
= $$
->ptr_level
;
906 pident
{ $$
= append_pident
( NULL
, $1 ); }
907 | pident_list
',' pident
{ $$
= append_pident
( $1, $3 ); }
911 tREF
{ $$
= RPC_FC_RP
; }
912 | tUNIQUE
{ $$
= RPC_FC_UP
; }
913 | tPTR
{ $$
= RPC_FC_FP
; }
916 structdef: tSTRUCT t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_STRUCT
, $2, tsSTRUCT
);
917 /* overwrite RPC_FC_STRUCT with a more exact type */
918 $$
->type
= get_struct_type
( $4 );
919 $$
->kind
= TKIND_RECORD
;
920 $$
->fields_or_args
= $4;
923 add_typelib_entry
($$
);
927 type: tVOID
{ $$
= duptype
(find_type
("void", 0), 1); }
928 | aKNOWNTYPE
{ $$
= find_type
($1, 0); }
929 | base_type
{ $$
= $1; }
930 | tCONST type
{ $$
= duptype
($2, 1); $$
->is_const
= TRUE
; }
931 | enumdef
{ $$
= $1; }
932 | tENUM aIDENTIFIER
{ $$
= find_type2
($2, tsENUM
); }
933 | structdef
{ $$
= $1; }
934 | tSTRUCT aIDENTIFIER
{ $$
= get_type
(RPC_FC_STRUCT
, $2, tsSTRUCT
); }
935 | uniondef
{ $$
= $1; }
936 | tUNION aIDENTIFIER
{ $$
= find_type2
($2, tsUNION
); }
937 | tSAFEARRAY
'(' type
')' { $$
= make_safearray
($3); }
940 typedef: tTYPEDEF m_attributes type pident_list
{ reg_typedefs
($3, $4, check_typedef_attrs
($2));
941 process_typedefs
($4);
945 uniondef: tUNION t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_NON_ENCAPSULATED_UNION
, $2, tsUNION
);
946 $$
->kind
= TKIND_UNION
;
947 $$
->fields_or_args
= $4;
951 tSWITCH
'(' s_field
')'
952 m_ident
'{' cases
'}' { var_t
*u
= $7;
953 $$
= get_typev
(RPC_FC_ENCAPSULATED_UNION
, $2, tsUNION
);
954 $$
->kind
= TKIND_UNION
;
955 if
(!u
) u
= make_var
( xstrdup
("tagged_union") );
956 u
->type
= make_type
(RPC_FC_NON_ENCAPSULATED_UNION
, NULL
);
957 u
->type
->kind
= TKIND_UNION
;
958 u
->type
->fields_or_args
= $9;
959 u
->type
->defined
= TRUE
;
960 $$
->fields_or_args
= append_var
( $$
->fields_or_args
, $5 );
961 $$
->fields_or_args
= append_var
( $$
->fields_or_args
, u
);
967 aNUM
{ $$
= MAKEVERSION
($1, 0); }
968 | aNUM
'.' aNUM
{ $$
= MAKEVERSION
($1, $3); }
973 static void decl_builtin
(const char *name
, unsigned char type
)
975 type_t
*t
= make_type
(type
, NULL
);
976 t
->name
= xstrdup
(name
);
977 reg_type
(t
, name
, 0);
980 static type_t
*make_builtin
(char *name
)
982 /* NAME is strdup'd in the lexer */
983 type_t
*t
= duptype
(find_type
(name
, 0), 0);
988 static type_t
*make_int
(int sign
)
990 type_t
*t
= duptype
(find_type
("int", 0), 1);
994 t
->type
= t
->type
== RPC_FC_LONG ? RPC_FC_ULONG
: RPC_FC_USHORT
;
999 void init_types
(void)
1001 decl_builtin
("void", 0);
1002 decl_builtin
("byte", RPC_FC_BYTE
);
1003 decl_builtin
("wchar_t", RPC_FC_WCHAR
);
1004 decl_builtin
("int", RPC_FC_LONG
); /* win32 */
1005 decl_builtin
("short", RPC_FC_SHORT
);
1006 decl_builtin
("small", RPC_FC_SMALL
);
1007 decl_builtin
("long", RPC_FC_LONG
);
1008 decl_builtin
("hyper", RPC_FC_HYPER
);
1009 decl_builtin
("__int64", RPC_FC_HYPER
);
1010 decl_builtin
("char", RPC_FC_CHAR
);
1011 decl_builtin
("float", RPC_FC_FLOAT
);
1012 decl_builtin
("double", RPC_FC_DOUBLE
);
1013 decl_builtin
("boolean", RPC_FC_BYTE
);
1014 decl_builtin
("error_status_t", RPC_FC_ERROR_STATUS_T
);
1015 decl_builtin
("handle_t", RPC_FC_BIND_PRIMITIVE
);
1018 static str_list_t
*append_str
(str_list_t
*list
, char *str
)
1020 struct str_list_entry_t
*entry
;
1022 if
(!str
) return list
;
1025 list
= xmalloc
( sizeof
(*list
) );
1028 entry
= xmalloc
( sizeof
(*entry
) );
1030 list_add_tail
( list
, &entry
->entry
);
1034 static attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
)
1036 attr_t
*attr_existing
;
1037 if
(!attr
) return list
;
1040 list
= xmalloc
( sizeof
(*list
) );
1043 LIST_FOR_EACH_ENTRY
(attr_existing
, list
, attr_t
, entry
)
1044 if
(attr_existing
->type
== attr
->type
)
1046 parser_warning
("duplicate attribute %s\n", get_attr_display_name
(attr
->type
));
1047 /* use the last attribute, like MIDL does */
1048 list_remove
(&attr_existing
->entry
);
1051 list_add_tail
( list
, &attr
->entry
);
1055 static attr_t
*make_attr
(enum attr_type type
)
1057 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1063 static attr_t
*make_attrv
(enum attr_type type
, unsigned long val
)
1065 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1071 static attr_t
*make_attrp
(enum attr_type type
, void *val
)
1073 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1079 static expr_t
*make_expr
(enum expr_type type
)
1081 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
1085 e
->is_const
= FALSE
;
1090 static expr_t
*make_exprl
(enum expr_type type
, long val
)
1092 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
1096 e
->is_const
= FALSE
;
1097 /* check for numeric constant */
1098 if
(type
== EXPR_NUM || type
== EXPR_HEXNUM || type
== EXPR_TRUEFALSE
) {
1099 /* make sure true/false value is valid */
1100 assert
(type
!= EXPR_TRUEFALSE || val
== 0 || val
== 1);
1107 static expr_t
*make_exprd
(enum expr_type type
, double val
)
1109 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
1118 static expr_t
*make_exprs
(enum expr_type type
, char *val
)
1121 e
= xmalloc
(sizeof
(expr_t
));
1125 e
->is_const
= FALSE
;
1126 /* check for predefined constants */
1127 if
(type
== EXPR_IDENTIFIER
) {
1128 var_t
*c
= find_const
(val
, 0);
1130 e
->u.sval
= c
->name
;
1133 e
->cval
= c
->eval
->cval
;
1139 static expr_t
*make_exprt
(enum expr_type type
, type_t
*tref
, expr_t
*expr
)
1142 e
= xmalloc
(sizeof
(expr_t
));
1146 e
->is_const
= FALSE
;
1147 /* check for cast of constant expression */
1148 if
(type
== EXPR_SIZEOF
) {
1149 switch
(tref
->type
) {
1166 case RPC_FC_ERROR_STATUS_T
:
1177 if
(type
== EXPR_CAST
&& expr
->is_const
) {
1179 e
->cval
= expr
->cval
;
1184 static expr_t
*make_expr1
(enum expr_type type
, expr_t
*expr
)
1187 if
(type
== EXPR_ADDRESSOF
&& expr
->type
!= EXPR_IDENTIFIER
)
1188 error("address-of operator applied to invalid expression\n");
1189 e
= xmalloc
(sizeof
(expr_t
));
1193 e
->is_const
= FALSE
;
1194 /* check for compile-time optimization */
1195 if
(expr
->is_const
) {
1199 e
->cval
= -expr
->cval
;
1202 e
->cval
= ~expr
->cval
;
1205 e
->is_const
= FALSE
;
1212 static expr_t
*make_expr2
(enum expr_type type
, expr_t
*expr1
, expr_t
*expr2
)
1215 e
= xmalloc
(sizeof
(expr_t
));
1219 e
->is_const
= FALSE
;
1220 /* check for compile-time optimization */
1221 if
(expr1
->is_const
&& expr2
->is_const
) {
1225 e
->cval
= expr1
->cval
+ expr2
->cval
;
1228 e
->cval
= expr1
->cval
- expr2
->cval
;
1231 e
->cval
= expr1
->cval
* expr2
->cval
;
1234 e
->cval
= expr1
->cval
/ expr2
->cval
;
1237 e
->cval
= expr1
->cval | expr2
->cval
;
1240 e
->cval
= expr1
->cval
& expr2
->cval
;
1243 e
->cval
= expr1
->cval
<< expr2
->cval
;
1246 e
->cval
= expr1
->cval
>> expr2
->cval
;
1249 e
->is_const
= FALSE
;
1256 static expr_t
*make_expr3
(enum expr_type type
, expr_t
*expr1
, expr_t
*expr2
, expr_t
*expr3
)
1259 e
= xmalloc
(sizeof
(expr_t
));
1264 e
->is_const
= FALSE
;
1265 /* check for compile-time optimization */
1266 if
(expr1
->is_const
&& expr2
->is_const
&& expr3
->is_const
) {
1270 e
->cval
= expr1
->cval ? expr2
->cval
: expr3
->cval
;
1273 e
->is_const
= FALSE
;
1280 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
)
1282 if
(!expr
) return list
;
1285 list
= xmalloc
( sizeof
(*list
) );
1288 list_add_tail
( list
, &expr
->entry
);
1292 static array_dims_t
*append_array
(array_dims_t
*list
, expr_t
*expr
)
1294 if
(!expr
) return list
;
1297 list
= xmalloc
( sizeof
(*list
) );
1300 list_add_tail
( list
, &expr
->entry
);
1304 static struct list type_pool
= LIST_INIT
(type_pool
);
1311 type_t
*alloc_type
(void)
1313 type_pool_node_t
*node
= xmalloc
(sizeof
*node
);
1314 list_add_tail
(&type_pool
, &node
->link
);
1318 void set_all_tfswrite
(int val
)
1320 type_pool_node_t
*node
;
1321 LIST_FOR_EACH_ENTRY
(node
, &type_pool
, type_pool_node_t
, link
)
1322 node
->data.tfswrite
= val
;
1325 static type_t
*make_type
(unsigned char type
, type_t
*ref
)
1327 type_t
*t
= alloc_type
();
1329 t
->kind
= TKIND_PRIMITIVE
;
1335 t
->fields_or_args
= NULL
;
1339 t
->length_is
= NULL
;
1340 t
->typestring_offset
= 0;
1342 t
->declarray
= FALSE
;
1343 t
->ignore
= (parse_only
!= 0);
1344 t
->is_const
= FALSE
;
1348 t
->user_types_registered
= FALSE
;
1349 t
->tfswrite
= FALSE
;
1350 t
->typelib_idx
= -1;
1354 static void set_type
(var_t
*v
, type_t
*type
, const pident_t
*pident
, array_dims_t
*arr
,
1357 expr_list_t
*sizes
= get_attrp
(v
->attrs
, ATTR_SIZEIS
);
1358 expr_list_t
*lengs
= get_attrp
(v
->attrs
, ATTR_LENGTHIS
);
1359 int ptr_attr
= get_attrv
(v
->attrs
, ATTR_POINTERTYPE
);
1360 int ptr_type
= ptr_attr
;
1361 int sizeless
, has_varconf
;
1363 type_t
*atype
, **ptype
;
1364 int ptr_level
= (pident ? pident
->ptr_level
: 0);
1368 if
(!ptr_type
&& top
)
1369 ptr_type
= RPC_FC_RP
;
1371 for
( ; 0 < ptr_level
; --ptr_level
)
1373 v
->type
= make_type
(pointer_default
, v
->type
);
1374 if
(ptr_level
== 1 && ptr_type
&& !arr
)
1376 v
->type
->type
= ptr_type
;
1381 if
(ptr_type
&& !arr
)
1383 if
(is_ptr
(v
->type
))
1385 if
(v
->type
->type
!= ptr_type
)
1387 v
->type
= duptype
(v
->type
, 1);
1388 v
->type
->type
= ptr_type
;
1391 else if
(!arr
&& ptr_attr
)
1392 error("%s: pointer attribute applied to non-pointer type\n", v
->name
);
1395 if
(pident
&& pident
->is_func
) {
1396 int func_ptr_level
= pident
->func_ptr_level
;
1397 v
->type
= make_type
(RPC_FC_FUNCTION
, v
->type
);
1398 v
->type
->fields_or_args
= pident
->args
;
1399 if
(pident
->callconv
)
1400 v
->type
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, pident
->callconv
));
1401 else if
(is_object_interface
) {
1402 static char *stdmethodcalltype
;
1403 if
(!stdmethodcalltype
) stdmethodcalltype
= strdup
("STDMETHODCALLTYPE");
1404 v
->type
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, stdmethodcalltype
));
1406 for
(; func_ptr_level
> 0; func_ptr_level
--)
1407 v
->type
= make_type
(ptr_type
, v
->type
);
1411 if
(arr
) LIST_FOR_EACH_ENTRY_REV
(dim
, arr
, expr_t
, entry
)
1414 error("%s: only the first array dimension can be unspecified\n", v
->name
);
1418 unsigned int align
= 0;
1419 size_t size
= type_memsize
(v
->type
, &align
);
1422 error("%s: array dimension must be positive\n", v
->name
);
1424 if
(0xffffffffuL
/ size
< (unsigned long) dim
->cval
)
1425 error("%s: total array size is too large\n", v
->name
);
1426 else if
(0xffffuL
< size
* dim
->cval
)
1427 v
->type
= make_type
(RPC_FC_LGFARRAY
, v
->type
);
1429 v
->type
= make_type
(RPC_FC_SMFARRAY
, v
->type
);
1434 v
->type
= make_type
(RPC_FC_CARRAY
, v
->type
);
1437 v
->type
->declarray
= TRUE
;
1438 v
->type
->dim
= dim
->cval
;
1442 has_varconf
= FALSE
;
1443 if
(sizes
) LIST_FOR_EACH_ENTRY
(dim
, sizes
, expr_t
, entry
)
1445 if
(dim
->type
!= EXPR_VOID
)
1448 atype
= *ptype
= duptype
(*ptype
, 0);
1450 if
(atype
->type
== RPC_FC_SMFARRAY || atype
->type
== RPC_FC_LGFARRAY
)
1451 error("%s: cannot specify size_is for a fixed sized array\n", v
->name
);
1453 if
(atype
->type
!= RPC_FC_CARRAY
&& !is_ptr
(atype
))
1454 error("%s: size_is attribute applied to illegal type\n", v
->name
);
1456 atype
->type
= RPC_FC_CARRAY
;
1457 atype
->size_is
= dim
;
1460 ptype
= &(*ptype
)->ref
;
1462 error("%s: too many expressions in size_is attribute\n", v
->name
);
1466 if
(lengs
) LIST_FOR_EACH_ENTRY
(dim
, lengs
, expr_t
, entry
)
1468 if
(dim
->type
!= EXPR_VOID
)
1471 atype
= *ptype
= duptype
(*ptype
, 0);
1473 if
(atype
->type
== RPC_FC_SMFARRAY
)
1474 atype
->type
= RPC_FC_SMVARRAY
;
1475 else if
(atype
->type
== RPC_FC_LGFARRAY
)
1476 atype
->type
= RPC_FC_LGVARRAY
;
1477 else if
(atype
->type
== RPC_FC_CARRAY
)
1478 atype
->type
= RPC_FC_CVARRAY
;
1480 error("%s: length_is attribute applied to illegal type\n", v
->name
);
1482 atype
->length_is
= dim
;
1485 ptype
= &(*ptype
)->ref
;
1487 error("%s: too many expressions in length_is attribute\n", v
->name
);
1490 if
(has_varconf
&& !last_array
(v
->type
))
1493 for
(ptype
= &v
->type
; is_array
(*ptype
); ptype
= &(*ptype
)->ref
)
1495 *ptype
= duptype
(*ptype
, 0);
1496 (*ptype
)->type
= RPC_FC_BOGUS_ARRAY
;
1500 if
(is_array
(v
->type
))
1502 const type_t
*rt
= v
->type
->ref
;
1503 if
(is_user_type
(rt
))
1504 v
->type
->type
= RPC_FC_BOGUS_ARRAY
;
1508 case RPC_FC_BOGUS_STRUCT
:
1509 case RPC_FC_NON_ENCAPSULATED_UNION
:
1510 case RPC_FC_ENCAPSULATED_UNION
:
1512 v
->type
->type
= RPC_FC_BOGUS_ARRAY
;
1514 /* FC_RP should be above, but widl overuses these, and will break things. */
1517 if
(rt
->ref
->type
== RPC_FC_IP
)
1518 v
->type
->type
= RPC_FC_BOGUS_ARRAY
;
1524 static ifref_list_t
*append_ifref
(ifref_list_t
*list
, ifref_t
*iface
)
1526 if
(!iface
) return list
;
1529 list
= xmalloc
( sizeof
(*list
) );
1532 list_add_tail
( list
, &iface
->entry
);
1536 static ifref_t
*make_ifref
(type_t
*iface
)
1538 ifref_t
*l
= xmalloc
(sizeof
(ifref_t
));
1544 static var_list_t
*append_var
(var_list_t
*list
, var_t
*var
)
1546 if
(!var
) return list
;
1549 list
= xmalloc
( sizeof
(*list
) );
1552 list_add_tail
( list
, &var
->entry
);
1556 static var_t
*make_var
(char *name
)
1558 var_t
*v
= xmalloc
(sizeof
(var_t
));
1566 static pident_list_t
*append_pident
(pident_list_t
*list
, pident_t
*p
)
1568 if
(!p
) return list
;
1570 list
= xmalloc
(sizeof
(*list
));
1573 list_add_tail
(list
, &p
->entry
);
1577 static pident_t
*make_pident
(var_t
*var
)
1579 pident_t
*p
= xmalloc
(sizeof
(*p
));
1583 p
->func_ptr_level
= 0;
1589 static func_list_t
*append_func
(func_list_t
*list
, func_t
*func
)
1591 if
(!func
) return list
;
1594 list
= xmalloc
( sizeof
(*list
) );
1597 list_add_tail
( list
, &func
->entry
);
1601 static func_t
*make_func
(var_t
*def
, var_list_t
*args
)
1603 func_t
*f
= xmalloc
(sizeof
(func_t
));
1606 f
->ignore
= parse_only
;
1611 static type_t
*make_class
(char *name
)
1613 type_t
*c
= make_type
(0, NULL
);
1615 c
->kind
= TKIND_COCLASS
;
1619 static type_t
*make_safearray
(type_t
*type
)
1621 type_t
*sa
= duptype
(find_type
("SAFEARRAY", 0), 1);
1623 return make_type
(pointer_default
, sa
);
1628 static int hash_ident
(const char *name
)
1630 const char *p
= name
;
1632 /* a simple sum hash is probably good enough */
1637 return sum
& (HASHMAX
-1);
1640 /***** type repository *****/
1649 struct rtype
*type_hash
[HASHMAX
];
1651 static type_t
*reg_type
(type_t
*type
, const char *name
, int t
)
1656 error_loc
("registering named type without name\n");
1659 hash
= hash_ident
(name
);
1660 nt
= xmalloc
(sizeof
(struct rtype
));
1664 nt
->next
= type_hash
[hash
];
1665 type_hash
[hash
] = nt
;
1669 static int is_incomplete
(const type_t
*t
)
1671 return
!t
->defined
&& (is_struct
(t
->type
) || is_union
(t
->type
));
1674 static void add_incomplete
(type_t
*t
)
1676 struct typenode
*tn
= xmalloc
(sizeof
*tn
);
1678 list_add_tail
(&incomplete_types
, &tn
->entry
);
1681 static void fix_type
(type_t
*t
)
1683 if
(t
->kind
== TKIND_ALIAS
&& is_incomplete
(t
)) {
1684 type_t
*ot
= t
->orig
;
1686 t
->fields_or_args
= ot
->fields_or_args
;
1687 t
->defined
= ot
->defined
;
1691 static void fix_incomplete
(void)
1693 struct typenode
*tn
, *next
;
1695 LIST_FOR_EACH_ENTRY_SAFE
(tn
, next
, &incomplete_types
, struct typenode
, entry
) {
1701 static type_t
*reg_typedefs
(type_t
*type
, pident_list_t
*pidents
, attr_list_t
*attrs
)
1704 const pident_t
*pident
;
1706 int is_str
= is_attr
(attrs
, ATTR_STRING
);
1707 unsigned char ptr_type
= get_attrv
(attrs
, ATTR_POINTERTYPE
);
1718 if
(c
!= RPC_FC_CHAR
&& c
!= RPC_FC_BYTE
&& c
!= RPC_FC_WCHAR
)
1720 pident
= LIST_ENTRY
( list_head
( pidents
), const pident_t
, entry
);
1721 error_loc
("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
1726 /* We must generate names for tagless enum, struct or union.
1727 Typedef-ing a tagless enum, struct or union means we want the typedef
1728 to be included in a library whether it has other attributes or not,
1729 hence the public attribute. */
1730 if
((type
->kind
== TKIND_ENUM || type
->kind
== TKIND_RECORD
1731 || type
->kind
== TKIND_UNION
) && ! type
->name
&& ! parse_only
)
1733 if
(! is_attr
(attrs
, ATTR_PUBLIC
))
1734 attrs
= append_attr
( attrs
, make_attr
(ATTR_PUBLIC
) );
1735 type
->name
= gen_name
();
1738 LIST_FOR_EACH_ENTRY
( pident
, pidents
, const pident_t
, entry
)
1740 var_t
*name
= pident
->var
;
1744 int cptr
= pident
->ptr_level
;
1746 while
(cptr
> ptrc
) {
1747 cur
= ptr
= make_type
(pointer_default
, cur
);
1751 while
(cptr
< ptrc
) {
1756 if
(pident
->is_func
) {
1757 int func_ptr_level
= pident
->func_ptr_level
;
1758 cur
= make_type
(RPC_FC_FUNCTION
, cur
);
1759 cur
->fields_or_args
= pident
->args
;
1760 if
(pident
->callconv
)
1761 cur
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, pident
->callconv
));
1762 else if
(is_object_interface
) {
1763 static char *stdmethodcalltype
;
1764 if
(!stdmethodcalltype
) stdmethodcalltype
= strdup
("STDMETHODCALLTYPE");
1765 cur
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, stdmethodcalltype
));
1767 for
(; func_ptr_level
> 0; func_ptr_level
--)
1768 cur
= make_type
(pointer_default
, cur
);
1770 cur
= alias
(cur
, name
->name
);
1775 cur
->type
= ptr_type
;
1777 error_loc
("'%s': pointer attribute applied to non-pointer type\n",
1780 else if
(is_str
&& ! is_ptr
(cur
))
1781 error_loc
("'%s': [string] attribute applied to non-pointer type\n",
1784 if
(is_incomplete
(cur
))
1785 add_incomplete
(cur
);
1786 reg_type
(cur
, cur
->name
, 0);
1792 static type_t
*find_type
(const char *name
, int t
)
1794 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
1795 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
1798 error_loc
("type '%s' not found\n", name
);
1804 static type_t
*find_type2
(char *name
, int t
)
1806 type_t
*tp
= find_type
(name
, t
);
1811 int is_type
(const char *name
)
1813 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
1814 while
(cur
&& (cur
->t || strcmp
(cur
->name
, name
)))
1816 if
(cur
) return TRUE
;
1820 static type_t
*get_type
(unsigned char type
, char *name
, int t
)
1822 struct rtype
*cur
= NULL
;
1825 cur
= type_hash
[hash_ident
(name
)];
1826 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
1833 tp
= make_type
(type
, NULL
);
1835 if
(!name
) return tp
;
1836 return reg_type
(tp
, name
, t
);
1839 static type_t
*get_typev
(unsigned char type
, var_t
*name
, int t
)
1846 return get_type
(type
, sname
, t
);
1849 static int get_struct_type
(var_list_t
*fields
)
1851 int has_pointer
= 0;
1852 int has_conformance
= 0;
1853 int has_variance
= 0;
1856 if
(get_padding
(fields
))
1857 return RPC_FC_BOGUS_STRUCT
;
1859 if
(fields
) LIST_FOR_EACH_ENTRY
( field
, fields
, var_t
, entry
)
1861 type_t
*t
= field
->type
;
1863 if
(is_user_type
(t
))
1864 return RPC_FC_BOGUS_STRUCT
;
1875 case RPC_FC_ENCAPSULATED_UNION
:
1876 case RPC_FC_NON_ENCAPSULATED_UNION
:
1877 case RPC_FC_BOGUS_STRUCT
:
1878 return RPC_FC_BOGUS_STRUCT
;
1885 if
(field
->type
->declarray
)
1887 if
(is_string_type
(field
->attrs
, field
->type
))
1889 if
(is_conformant_array
(field
->type
))
1890 has_conformance
= 1;
1895 if
(is_array
(field
->type
->ref
))
1896 return RPC_FC_BOGUS_STRUCT
;
1898 if
(is_conformant_array
(field
->type
))
1900 has_conformance
= 1;
1901 if
(field
->type
->declarray
&& list_next
(fields
, &field
->entry
))
1902 error_loc
("field '%s' deriving from a conformant array must be the last field in the structure\n",
1905 if
(field
->type
->length_is
)
1908 t
= field
->type
->ref
;
1914 * RPC_FC_BYTE, RPC_FC_STRUCT, etc
1915 * Simple types don't effect the type of struct.
1916 * A struct containing a simple struct is still a simple struct.
1917 * So long as we can block copy the data, we return RPC_FC_STRUCT.
1919 case
0: /* void pointer */
1929 case RPC_FC_INT3264
:
1930 case RPC_FC_UINT3264
:
1943 case RPC_FC_CVARRAY
:
1944 case RPC_FC_BOGUS_ARRAY
:
1949 * Propagate member attributes
1950 * a struct should be at least as complex as its member
1952 case RPC_FC_CVSTRUCT
:
1953 has_conformance
= 1;
1958 case RPC_FC_CPSTRUCT
:
1959 has_conformance
= 1;
1960 if
(list_next
( fields
, &field
->entry
))
1961 error_loc
("field '%s' deriving from a conformant array must be the last field in the structure\n",
1966 case RPC_FC_CSTRUCT
:
1967 has_conformance
= 1;
1968 if
(list_next
( fields
, &field
->entry
))
1969 error_loc
("field '%s' deriving from a conformant array must be the last field in the structure\n",
1973 case RPC_FC_PSTRUCT
:
1978 error_loc
("Unknown struct member %s with type (0x%02x)\n", field
->name
, t
->type
);
1979 /* fallthru - treat it as complex */
1981 /* as soon as we see one of these these members, it's bogus... */
1982 case RPC_FC_ENCAPSULATED_UNION
:
1983 case RPC_FC_NON_ENCAPSULATED_UNION
:
1984 case RPC_FC_BOGUS_STRUCT
:
1986 return RPC_FC_BOGUS_STRUCT
;
1992 if
( has_conformance
)
1993 return RPC_FC_CVSTRUCT
;
1995 return RPC_FC_BOGUS_STRUCT
;
1997 if
( has_conformance
&& has_pointer
)
1998 return RPC_FC_CPSTRUCT
;
1999 if
( has_conformance
)
2000 return RPC_FC_CSTRUCT
;
2002 return RPC_FC_PSTRUCT
;
2003 return RPC_FC_STRUCT
;
2006 /***** constant repository *****/
2011 struct rconst
*next
;
2014 struct rconst
*const_hash
[HASHMAX
];
2016 static var_t
*reg_const
(var_t
*var
)
2021 error_loc
("registering constant without name\n");
2024 hash
= hash_ident
(var
->name
);
2025 nc
= xmalloc
(sizeof
(struct rconst
));
2026 nc
->name
= var
->name
;
2028 nc
->next
= const_hash
[hash
];
2029 const_hash
[hash
] = nc
;
2033 static var_t
*find_const
(char *name
, int f
)
2035 struct rconst
*cur
= const_hash
[hash_ident
(name
)];
2036 while
(cur
&& strcmp
(cur
->name
, name
))
2039 if
(f
) error_loc
("constant '%s' not found\n", name
);
2045 static void write_libid
(const char *name
, const attr_list_t
*attr
)
2047 const UUID
*uuid
= get_attrp
(attr
, ATTR_UUID
);
2048 write_guid
(idfile
, "LIBID", name
, uuid
);
2051 static void write_clsid
(type_t
*cls
)
2053 const UUID
*uuid
= get_attrp
(cls
->attrs
, ATTR_UUID
);
2054 write_guid
(idfile
, "CLSID", cls
->name
, uuid
);
2057 static void write_diid
(type_t
*iface
)
2059 const UUID
*uuid
= get_attrp
(iface
->attrs
, ATTR_UUID
);
2060 write_guid
(idfile
, "DIID", iface
->name
, uuid
);
2063 static void write_iid
(type_t
*iface
)
2065 const UUID
*uuid
= get_attrp
(iface
->attrs
, ATTR_UUID
);
2066 write_guid
(idfile
, "IID", iface
->name
, uuid
);
2069 static int compute_method_indexes
(type_t
*iface
)
2075 idx
= compute_method_indexes
(iface
->ref
);
2082 LIST_FOR_EACH_ENTRY
( f
, iface
->funcs
, func_t
, entry
)
2083 if
(! is_callas
(f
->def
->attrs
))
2089 static char *gen_name
(void)
2091 static const char format
[] = "__WIDL_%s_generated_name_%08lX";
2092 static unsigned long n
= 0;
2093 static const char *file_id
;
2099 char *dst
= dup_basename
(input_name
, ".idl");
2103 if
(! isalnum
((unsigned char) *dst
))
2106 size
= sizeof format
- 7 + strlen
(file_id
) + 8;
2109 name
= xmalloc
(size
);
2110 sprintf
(name
, format
, file_id
, n
++);
2114 static void process_typedefs
(pident_list_t
*pidents
)
2116 pident_t
*pident
, *next
;
2118 if
(!pidents
) return
;
2119 LIST_FOR_EACH_ENTRY_SAFE
( pident
, next
, pidents
, pident_t
, entry
)
2121 var_t
*var
= pident
->var
;
2122 type_t
*type
= find_type
(var
->name
, 0);
2124 if
(! parse_only
&& do_header
)
2125 write_typedef
(type
);
2126 if
(in_typelib
&& type
->attrs
)
2127 add_typelib_entry
(type
);
2136 unsigned int dce_compatible
: 1;
2137 unsigned int acf
: 1;
2138 unsigned int on_interface
: 1;
2139 unsigned int on_function
: 1;
2140 unsigned int on_arg
: 1;
2141 unsigned int on_type
: 1;
2142 unsigned int on_field
: 1;
2143 unsigned int on_library
: 1;
2144 unsigned int on_dispinterface
: 1;
2145 unsigned int on_module
: 1;
2146 unsigned int on_coclass
: 1;
2147 const char *display_name
;
2150 struct allowed_attr allowed_attr
[] =
2152 /* attr { D ACF I Fn ARG T Fi L DI M C <display name> } */
2153 /* ATTR_AGGREGATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "aggregatable" },
2154 /* ATTR_APPOBJECT */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "appobject" },
2155 /* ATTR_ASYNC */ { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, "async" },
2156 /* ATTR_AUTO_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "auto_handle" },
2157 /* ATTR_BINDABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "bindable" },
2158 /* ATTR_BROADCAST */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "broadcast" },
2159 /* ATTR_CALLAS */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "call_as" },
2160 /* ATTR_CALLCONV */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
},
2161 /* ATTR_CASE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "case" },
2162 /* ATTR_CONTEXTHANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "context_handle" },
2163 /* ATTR_CONTROL */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, "control" },
2164 /* ATTR_DEFAULT */ { 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, "default" },
2165 /* ATTR_DEFAULTCOLLELEM */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "defaultcollelem" },
2166 /* ATTR_DEFAULTVALUE_EXPR */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "defaultvalue" },
2167 /* ATTR_DEFAULTVALUE_STRING */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "defaultvalue" },
2168 /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "defaultvtable" },
2169 /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
},
2170 /* ATTR_DISPLAYBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "displaybind" },
2171 /* ATTR_DLLNAME */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, "dllname" },
2172 /* ATTR_DUAL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "dual" },
2173 /* ATTR_ENDPOINT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "endpoint" },
2174 /* ATTR_ENTRY_ORDINAL */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "entry" },
2175 /* ATTR_ENTRY_STRING */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "entry" },
2176 /* ATTR_EXPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "explicit_handle" },
2177 /* ATTR_HANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "handle" },
2178 /* ATTR_HELPCONTEXT */ { 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, "helpcontext" },
2179 /* ATTR_HELPFILE */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpfile" },
2180 /* ATTR_HELPSTRING */ { 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, "helpstring" },
2181 /* ATTR_HELPSTRINGCONTEXT */ { 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, "helpstringcontext" },
2182 /* ATTR_HELPSTRINGDLL */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpstringdll" },
2183 /* ATTR_HIDDEN */ { 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, "hidden" },
2184 /* ATTR_ID */ { 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, "id" },
2185 /* ATTR_IDEMPOTENT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "idempotent" },
2186 /* ATTR_IIDIS */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "iid_is" },
2187 /* ATTR_IMMEDIATEBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "immediatebind" },
2188 /* ATTR_IMPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "implicit_handle" },
2189 /* ATTR_IN */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "in" },
2190 /* ATTR_INPUTSYNC */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inputsync" },
2191 /* ATTR_LENGTHIS */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "length_is" },
2192 /* ATTR_LOCAL */ { 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, "local" },
2193 /* ATTR_NONBROWSABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "nonbrowsable" },
2194 /* ATTR_NONCREATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "noncreatable" },
2195 /* ATTR_NONEXTENSIBLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "nonextensible" },
2196 /* ATTR_OBJECT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "object" },
2197 /* ATTR_ODL */ { 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, "odl" },
2198 /* ATTR_OLEAUTOMATION */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "oleautomation" },
2199 /* ATTR_OPTIONAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "optional" },
2200 /* ATTR_OUT */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "out" },
2201 /* ATTR_POINTERDEFAULT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "pointer_default" },
2202 /* ATTR_POINTERTYPE */ { 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, "ref, unique or ptr" },
2203 /* ATTR_PROPGET */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "propget" },
2204 /* ATTR_PROPPUT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "propput" },
2205 /* ATTR_PROPPUTREF */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "propputref" },
2206 /* ATTR_PUBLIC */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "public" },
2207 /* ATTR_RANGE */ { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, "range" },
2208 /* ATTR_READONLY */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "readonly" },
2209 /* ATTR_REQUESTEDIT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "requestedit" },
2210 /* ATTR_RESTRICTED */ { 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, "restricted" },
2211 /* ATTR_RETVAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "retval" },
2212 /* ATTR_SIZEIS */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "size_is" },
2213 /* ATTR_SOURCE */ { 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, "source" },
2214 /* ATTR_STRICTCONTEXTHANDLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "strict_context_handle" },
2215 /* ATTR_STRING */ { 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, "string" },
2216 /* ATTR_SWITCHIS */ { 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "switch_is" },
2217 /* ATTR_SWITCHTYPE */ { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, "switch_type" },
2218 /* ATTR_TRANSMITAS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "transmit_as" },
2219 /* ATTR_UUID */ { 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, "uuid" },
2220 /* ATTR_V1ENUM */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "v1_enum" },
2221 /* ATTR_VARARG */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "vararg" },
2222 /* ATTR_VERSION */ { 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, "version" },
2223 /* ATTR_WIREMARSHAL */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "wire_marshal" },
2226 const char *get_attr_display_name
(enum attr_type type
)
2228 return allowed_attr
[type
].display_name
;
2231 static const attr_list_t
*check_iface_attrs
(const char *name
, const attr_list_t
*attrs
)
2234 if
(!attrs
) return attrs
;
2235 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2237 if
(!allowed_attr
[attr
->type
].on_interface
)
2238 error_loc
("inapplicable attribute %s for interface %s\n",
2239 allowed_attr
[attr
->type
].display_name
, name
);
2244 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
)
2247 if
(!attrs
) return attrs
;
2248 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2250 if
(!allowed_attr
[attr
->type
].on_function
)
2251 error_loc
("inapplicable attribute %s for function %s\n",
2252 allowed_attr
[attr
->type
].display_name
, name
);
2257 static void check_arg
(var_t
*arg
)
2259 const type_t
*t
= arg
->type
;
2262 if
(t
->type
== 0 && ! is_var_ptr
(arg
))
2263 error_loc
("argument '%s' has void type\n", arg
->name
);
2267 LIST_FOR_EACH_ENTRY
(attr
, arg
->attrs
, const attr_t
, entry
)
2269 if
(!allowed_attr
[attr
->type
].on_arg
)
2270 error_loc
("inapplicable attribute %s for argument %s\n",
2271 allowed_attr
[attr
->type
].display_name
, arg
->name
);
2276 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
)
2279 if
(!attrs
) return attrs
;
2280 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2282 if
(!allowed_attr
[attr
->type
].on_type
)
2283 error_loc
("inapplicable attribute %s for typedef\n",
2284 allowed_attr
[attr
->type
].display_name
);
2289 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
)
2292 if
(!attrs
) return attrs
;
2293 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2295 if
(!allowed_attr
[attr
->type
].on_field
)
2296 error_loc
("inapplicable attribute %s for field %s\n",
2297 allowed_attr
[attr
->type
].display_name
, name
);
2302 static const attr_list_t
*check_library_attrs
(const char *name
, const attr_list_t
*attrs
)
2305 if
(!attrs
) return attrs
;
2306 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2308 if
(!allowed_attr
[attr
->type
].on_library
)
2309 error_loc
("inapplicable attribute %s for library %s\n",
2310 allowed_attr
[attr
->type
].display_name
, name
);
2315 static attr_list_t
*check_dispiface_attrs
(const char *name
, attr_list_t
*attrs
)
2318 if
(!attrs
) return attrs
;
2319 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2321 if
(!allowed_attr
[attr
->type
].on_dispinterface
)
2322 error_loc
("inapplicable attribute %s for dispinterface %s\n",
2323 allowed_attr
[attr
->type
].display_name
, name
);
2328 static const attr_list_t
*check_module_attrs
(const char *name
, const attr_list_t
*attrs
)
2331 if
(!attrs
) return attrs
;
2332 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2334 if
(!allowed_attr
[attr
->type
].on_module
)
2335 error_loc
("inapplicable attribute %s for module %s\n",
2336 allowed_attr
[attr
->type
].display_name
, name
);
2341 static const attr_list_t
*check_coclass_attrs
(const char *name
, const attr_list_t
*attrs
)
2344 if
(!attrs
) return attrs
;
2345 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2347 if
(!allowed_attr
[attr
->type
].on_coclass
)
2348 error_loc
("inapplicable attribute %s for coclass %s\n",
2349 allowed_attr
[attr
->type
].display_name
, name
);
2354 static void check_all_user_types
(ifref_list_t
*ifrefs
)
2356 const ifref_t
*ifref
;
2359 if
(ifrefs
) LIST_FOR_EACH_ENTRY
(ifref
, ifrefs
, const ifref_t
, entry
)
2361 const func_list_t
*fs
= ifref
->iface
->funcs
;
2362 if
(fs
) LIST_FOR_EACH_ENTRY
(f
, fs
, const func_t
, entry
)
2363 check_for_additional_prototype_types
(f
->args
);
2367 int is_valid_uuid
(const char *s
)
2371 for
(i
= 0; i
< 36; ++i
)
2372 if
(i
== 8 || i
== 13 || i
== 18 || i
== 23)
2378 if
(!isxdigit
(s
[i
]))
2381 return s
[i
] == '\0';