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
;
70 /* are we inside a library block? */
71 static int is_inside_library
= FALSE
;
73 typedef
struct list typelist_t
;
79 typelist_t incomplete_types
= LIST_INIT
(incomplete_types
);
81 static void add_incomplete
(type_t
*t
);
82 static void fix_incomplete
(void);
84 static str_list_t
*append_str
(str_list_t
*list
, char *str
);
85 static attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
);
86 static attr_t
*make_attr
(enum attr_type type
);
87 static attr_t
*make_attrv
(enum attr_type type
, unsigned long val
);
88 static attr_t
*make_attrp
(enum attr_type type
, void *val
);
89 static expr_t
*make_expr
(enum expr_type type
);
90 static expr_t
*make_exprl
(enum expr_type type
, long val
);
91 static expr_t
*make_exprd
(enum expr_type type
, double val
);
92 static expr_t
*make_exprs
(enum expr_type type
, char *val
);
93 static expr_t
*make_exprt
(enum expr_type type
, type_t
*tref
, expr_t
*expr
);
94 static expr_t
*make_expr1
(enum expr_type type
, expr_t
*expr
);
95 static expr_t
*make_expr2
(enum expr_type type
, expr_t
*exp1
, expr_t
*exp2
);
96 static expr_t
*make_expr3
(enum expr_type type
, expr_t
*expr1
, expr_t
*expr2
, expr_t
*expr3
);
97 static type_t
*make_type
(unsigned char type
, type_t
*ref
);
98 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
);
99 static array_dims_t
*append_array
(array_dims_t
*list
, expr_t
*expr
);
100 static void set_type
(var_t
*v
, type_t
*type
, const pident_t
*pident
, array_dims_t
*arr
, int top
);
101 static ifref_list_t
*append_ifref
(ifref_list_t
*list
, ifref_t
*iface
);
102 static ifref_t
*make_ifref
(type_t
*iface
);
103 static var_list_t
*append_var
(var_list_t
*list
, var_t
*var
);
104 static var_t
*make_var
(char *name
);
105 static pident_list_t
*append_pident
(pident_list_t
*list
, pident_t
*p
);
106 static pident_t
*make_pident
(var_t
*var
);
107 static func_list_t
*append_func
(func_list_t
*list
, func_t
*func
);
108 static func_t
*make_func
(var_t
*def
, var_list_t
*args
);
109 static type_t
*make_class
(char *name
);
110 static type_t
*make_safearray
(type_t
*type
);
111 static type_t
*make_builtin
(char *name
);
112 static type_t
*make_int
(int sign
);
114 static type_t
*reg_type
(type_t
*type
, const char *name
, int t
);
115 static type_t
*reg_typedefs
(type_t
*type
, var_list_t
*names
, attr_list_t
*attrs
);
116 static type_t
*find_type
(const char *name
, int t
);
117 static type_t
*find_type2
(char *name
, int t
);
118 static type_t
*get_type
(unsigned char type
, char *name
, int t
);
119 static type_t
*get_typev
(unsigned char type
, var_t
*name
, int t
);
120 static int get_struct_type
(var_list_t
*fields
);
122 static var_t
*reg_const
(var_t
*var
);
123 static var_t
*find_const
(char *name
, int f
);
125 static void write_libid
(const char *name
, const attr_list_t
*attr
);
126 static void write_clsid
(type_t
*cls
);
127 static void write_diid
(type_t
*iface
);
128 static void write_iid
(type_t
*iface
);
130 static int compute_method_indexes
(type_t
*iface
);
131 static char *gen_name
(void);
132 static void process_typedefs
(var_list_t
*names
);
133 static void check_arg
(var_t
*arg
);
134 static void check_functions
(const type_t
*iface
);
135 static void check_all_user_types
(ifref_list_t
*ifaces
);
136 static const attr_list_t
*check_iface_attrs
(const char *name
, const attr_list_t
*attrs
);
137 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
);
138 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
);
139 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
);
140 static const attr_list_t
*check_library_attrs
(const char *name
, const attr_list_t
*attrs
);
141 static attr_list_t
*check_dispiface_attrs
(const char *name
, attr_list_t
*attrs
);
142 static const attr_list_t
*check_module_attrs
(const char *name
, const attr_list_t
*attrs
);
143 static const attr_list_t
*check_coclass_attrs
(const char *name
, const attr_list_t
*attrs
);
144 const char *get_attr_display_name
(enum attr_type type
);
153 attr_list_t
*attr_list
;
154 str_list_t
*str_list
;
156 expr_list_t
*expr_list
;
157 array_dims_t
*array_dims
;
160 var_list_t
*var_list
;
162 pident_list_t
*pident_list
;
164 func_list_t
*func_list
;
166 ifref_list_t
*ifref_list
;
171 interface_info_t ifinfo
;
174 %token
<str
> aIDENTIFIER
175 %token
<str
> aKNOWNTYPE
176 %token
<num
> aNUM aHEXNUM
182 %token tAGGREGATABLE tALLOCATE tAPPOBJECT tASYNC tASYNCUUID
183 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
184 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
185 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
186 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
188 %token tDEFAULTCOLLELEM
190 %token tDEFAULTVTABLE
192 %token tDISPINTERFACE
193 %token tDLLNAME tDOUBLE tDUAL
195 %token tENTRY tENUM tERRORSTATUST
196 %token tEXPLICITHANDLE tEXTERN
202 %token tHELPCONTEXT tHELPFILE
203 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
205 %token tHYPER tID tIDEMPOTENT
207 %token tIMMEDIATEBIND
208 %token tIMPLICITHANDLE
209 %token tIMPORT tIMPORTLIB
215 %token tLENGTHIS tLIBRARY
222 %token tNONEXTENSIBLE
223 %token tOBJECT tODL tOLEAUTOMATION
227 %token tPOINTERDEFAULT
229 %token tPROPGET tPROPPUT tPROPPUTREF
233 %token tREADONLY tREF
241 %token tSIZEIS tSIZEOF
245 %token tSTRICTCONTEXTHANDLE
246 %token tSTRING tSTRUCT
247 %token tSWITCH tSWITCHIS tSWITCHTYPE
259 %token tWCHAR tWIREMARSHAL
261 %type
<attr
> attribute
262 %type
<attr_list
> m_attributes attributes attrib_list
263 %type
<str_list
> str_list
264 %type
<expr
> m_expr expr expr_const
265 %type
<expr_list
> m_exprs
/* exprs expr_list */ expr_list_const
266 %type
<array_dims
> array array_list
267 %type
<ifinfo
> interfacehdr
268 %type
<type
> inherit interface interfacedef interfacedec
269 %type
<type
> dispinterface dispinterfacehdr dispinterfacedef
270 %type
<type
> module modulehdr moduledef
271 %type
<type
> base_type int_std
272 %type
<type
> enumdef structdef uniondef
274 %type
<ifref
> coclass_int
275 %type
<ifref_list
> gbl_statements coclass_ints
276 %type
<var
> arg field s_field case
enum constdef externdef
277 %type
<var_list
> m_args no_args args fields cases enums enum_list dispint_props
278 %type
<var
> m_ident t_ident ident
279 %type
<pident
> pident func_ident direct_ident
280 %type
<pident_list
> pident_list
282 %type
<func_list
> int_statements dispint_meths
283 %type
<type
> coclass coclasshdr coclassdef
284 %type
<num
> pointer_type version
285 %type
<str
> libraryhdr callconv
286 %type
<uuid
> uuid_string
287 %type
<num
> import_start
304 input: gbl_statements
{ fix_incomplete
();
305 check_all_user_types
($1);
313 gbl_statements: { $$
= NULL
; }
314 | gbl_statements interfacedec
{ $$
= $1; }
315 | gbl_statements interfacedef
{ $$
= append_ifref
( $1, make_ifref
($2) ); }
316 | gbl_statements coclass
';' { $$
= $1;
317 reg_type
($2, $2->name
, 0);
318 if
(!parse_only
&& do_header
) write_coclass_forward
($2);
320 | gbl_statements coclassdef
{ $$
= $1;
321 add_typelib_entry
($2);
322 reg_type
($2, $2->name
, 0);
323 if
(!parse_only
&& do_header
) write_coclass_forward
($2);
325 | gbl_statements moduledef
{ $$
= $1; add_typelib_entry
($2); }
326 | gbl_statements librarydef
{ $$
= $1; }
327 | gbl_statements statement
{ $$
= $1; }
331 | imp_statements interfacedec
{ if
(!parse_only
) add_typelib_entry
($2); }
332 | imp_statements interfacedef
{ if
(!parse_only
) add_typelib_entry
($2); }
333 | imp_statements coclass
';' { reg_type
($2, $2->name
, 0); if
(!parse_only
&& do_header
) write_coclass_forward
($2); }
334 | imp_statements coclassdef
{ if
(!parse_only
) add_typelib_entry
($2);
335 reg_type
($2, $2->name
, 0);
336 if
(!parse_only
&& do_header
) write_coclass_forward
($2);
338 | imp_statements moduledef
{ if
(!parse_only
) add_typelib_entry
($2); }
339 | imp_statements statement
{}
340 | imp_statements importlib
{}
341 | imp_statements librarydef
{}
344 int_statements: { $$
= NULL
; }
345 | int_statements funcdef
';' { $$
= append_func
( $1, $2 ); }
346 | int_statements statement
{ $$
= $1; }
353 statement: constdef
';' { if
(!parse_only
&& do_header
) { write_constdef
($1); } }
355 | enumdef
';' { if
(!parse_only
&& do_header
) {
356 write_type_def_or_decl
(header
, $1, FALSE
, NULL
);
357 fprintf
(header
, ";\n\n");
360 | externdef
';' { if
(!parse_only
&& do_header
) { write_externdef
($1); } }
362 | structdef
';' { if
(!parse_only
&& do_header
) {
363 write_type_def_or_decl
(header
, $1, FALSE
, NULL
);
364 fprintf
(header
, ";\n\n");
368 | uniondef
';' { if
(!parse_only
&& do_header
) {
369 write_type_def_or_decl
(header
, $1, FALSE
, NULL
);
370 fprintf
(header
, ";\n\n");
375 cppquote: tCPPQUOTE
'(' aSTRING
')' { if
(!parse_only
&& do_header
) fprintf
(header
, "%s\n", $3); }
377 import_start: tIMPORT aSTRING
';' { assert
(yychar == YYEMPTY
);
379 if
(!$$
) yychar = aEOF
;
383 import: import_start imp_statements aEOF
384 { if
($1) pop_import
(); }
387 importlib: tIMPORTLIB
'(' aSTRING
')'
388 semicolon_opt
{ if
(!parse_only
) add_importlib
($3); }
391 libraryhdr: tLIBRARY aIDENTIFIER
{ $$
= $2; }
393 library_start: attributes libraryhdr
'{' { check_library_attrs
($2, $1);
394 if
(!parse_only
) start_typelib
($2, $1);
395 if
(!parse_only
&& do_header
) write_library
($2, $1);
396 if
(!parse_only
&& do_idfile
) write_libid
($2, $1);
397 is_inside_library
= TRUE
;
400 librarydef: library_start imp_statements
'}'
401 semicolon_opt
{ if
(!parse_only
) end_typelib
(); is_inside_library
= FALSE
; }
404 m_args: { $$
= NULL
; }
408 no_args: tVOID
{ $$
= NULL
; }
411 args: arg
{ check_arg
($1); $$
= append_var
( NULL
, $1 ); }
412 | args
',' arg
{ check_arg
($3); $$
= append_var
( $1, $3); }
416 /* split into two rules to get bison to resolve a tVOID conflict */
417 arg: attributes type pident array
{ $$
= $3->var
;
419 set_type
($$
, $2, $3, $4, TRUE
);
422 | type pident array
{ $$
= $2->var
;
423 set_type
($$
, $1, $2, $3, TRUE
);
428 array: { $$
= NULL
; }
429 |
'[' array_list
']' { $$
= $2; }
430 |
'[' '*' ']' { $$
= append_array
( NULL
, make_expr
(EXPR_VOID
) ); }
433 array_list: m_expr
/* size of first dimension is optional */ { $$
= append_array
( NULL
, $1 ); }
434 | array_list
',' expr
{ $$
= append_array
( $1, $3 ); }
435 | array_list
']' '[' expr
{ $$
= append_array
( $1, $4 ); }
438 m_attributes: { $$
= NULL
; }
443 '[' attrib_list
']' { $$
= $2;
445 error_loc
("empty attribute lists unsupported\n");
449 attrib_list: attribute
{ $$
= append_attr
( NULL
, $1 ); }
450 | attrib_list
',' attribute
{ $$
= append_attr
( $1, $3 ); }
451 | attrib_list
']' '[' attribute
{ $$
= append_attr
( $1, $4 ); }
454 str_list: aSTRING
{ $$
= append_str
( NULL
, $1 ); }
455 | str_list
',' aSTRING
{ $$
= append_str
( $1, $3 ); }
458 attribute: { $$
= NULL
; }
459 | tAGGREGATABLE
{ $$
= make_attr
(ATTR_AGGREGATABLE
); }
460 | tAPPOBJECT
{ $$
= make_attr
(ATTR_APPOBJECT
); }
461 | tASYNC
{ $$
= make_attr
(ATTR_ASYNC
); }
462 | tAUTOHANDLE
{ $$
= make_attr
(ATTR_AUTO_HANDLE
); }
463 | tBINDABLE
{ $$
= make_attr
(ATTR_BINDABLE
); }
464 | tBROADCAST
{ $$
= make_attr
(ATTR_BROADCAST
); }
465 | tCALLAS
'(' ident
')' { $$
= make_attrp
(ATTR_CALLAS
, $3); }
466 | tCASE
'(' expr_list_const
')' { $$
= make_attrp
(ATTR_CASE
, $3); }
467 | tCONTEXTHANDLE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); }
468 | tCONTEXTHANDLENOSERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
469 | tCONTEXTHANDLESERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
470 | tCONTROL
{ $$
= make_attr
(ATTR_CONTROL
); }
471 | tDEFAULT
{ $$
= make_attr
(ATTR_DEFAULT
); }
472 | tDEFAULTCOLLELEM
{ $$
= make_attr
(ATTR_DEFAULTCOLLELEM
); }
473 | tDEFAULTVALUE
'(' expr_const
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE_EXPR
, $3); }
474 | tDEFAULTVALUE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE_STRING
, $3); }
475 | tDEFAULTVTABLE
{ $$
= make_attr
(ATTR_DEFAULTVTABLE
); }
476 | tDISPLAYBIND
{ $$
= make_attr
(ATTR_DISPLAYBIND
); }
477 | tDLLNAME
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DLLNAME
, $3); }
478 | tDUAL
{ $$
= make_attr
(ATTR_DUAL
); }
479 | tENDPOINT
'(' str_list
')' { $$
= make_attrp
(ATTR_ENDPOINT
, $3); }
480 | tENTRY
'(' aSTRING
')' { $$
= make_attrp
(ATTR_ENTRY_STRING
, $3); }
481 | tENTRY
'(' expr_const
')' { $$
= make_attrp
(ATTR_ENTRY_ORDINAL
, $3); }
482 | tEXPLICITHANDLE
{ $$
= make_attr
(ATTR_EXPLICIT_HANDLE
); }
483 | tHANDLE
{ $$
= make_attr
(ATTR_HANDLE
); }
484 | tHELPCONTEXT
'(' expr_const
')' { $$
= make_attrp
(ATTR_HELPCONTEXT
, $3); }
485 | tHELPFILE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPFILE
, $3); }
486 | tHELPSTRING
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRING
, $3); }
487 | tHELPSTRINGCONTEXT
'(' expr_const
')' { $$
= make_attrp
(ATTR_HELPSTRINGCONTEXT
, $3); }
488 | tHELPSTRINGDLL
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRINGDLL
, $3); }
489 | tHIDDEN
{ $$
= make_attr
(ATTR_HIDDEN
); }
490 | tID
'(' expr_const
')' { $$
= make_attrp
(ATTR_ID
, $3); }
491 | tIDEMPOTENT
{ $$
= make_attr
(ATTR_IDEMPOTENT
); }
492 | tIIDIS
'(' expr
')' { $$
= make_attrp
(ATTR_IIDIS
, $3); }
493 | tIMMEDIATEBIND
{ $$
= make_attr
(ATTR_IMMEDIATEBIND
); }
494 | tIMPLICITHANDLE
'(' tHANDLET aIDENTIFIER
')' { $$
= make_attrp
(ATTR_IMPLICIT_HANDLE
, $4); }
495 | tIN
{ $$
= make_attr
(ATTR_IN
); }
496 | tINPUTSYNC
{ $$
= make_attr
(ATTR_INPUTSYNC
); }
497 | tLENGTHIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_LENGTHIS
, $3); }
498 | tLOCAL
{ $$
= make_attr
(ATTR_LOCAL
); }
499 | tNONBROWSABLE
{ $$
= make_attr
(ATTR_NONBROWSABLE
); }
500 | tNONCREATABLE
{ $$
= make_attr
(ATTR_NONCREATABLE
); }
501 | tNONEXTENSIBLE
{ $$
= make_attr
(ATTR_NONEXTENSIBLE
); }
502 | tOBJECT
{ $$
= make_attr
(ATTR_OBJECT
); }
503 | tODL
{ $$
= make_attr
(ATTR_ODL
); }
504 | tOLEAUTOMATION
{ $$
= make_attr
(ATTR_OLEAUTOMATION
); }
505 | tOPTIONAL
{ $$
= make_attr
(ATTR_OPTIONAL
); }
506 | tOUT
{ $$
= make_attr
(ATTR_OUT
); }
507 | tPOINTERDEFAULT
'(' pointer_type
')' { $$
= make_attrv
(ATTR_POINTERDEFAULT
, $3); }
508 | tPROPGET
{ $$
= make_attr
(ATTR_PROPGET
); }
509 | tPROPPUT
{ $$
= make_attr
(ATTR_PROPPUT
); }
510 | tPROPPUTREF
{ $$
= make_attr
(ATTR_PROPPUTREF
); }
511 | tPUBLIC
{ $$
= make_attr
(ATTR_PUBLIC
); }
512 | tRANGE
'(' expr_const
',' expr_const
')' { expr_list_t
*list
= append_expr
( NULL
, $3 );
513 list
= append_expr
( list
, $5 );
514 $$
= make_attrp
(ATTR_RANGE
, list
); }
515 | tREADONLY
{ $$
= make_attr
(ATTR_READONLY
); }
516 | tREQUESTEDIT
{ $$
= make_attr
(ATTR_REQUESTEDIT
); }
517 | tRESTRICTED
{ $$
= make_attr
(ATTR_RESTRICTED
); }
518 | tRETVAL
{ $$
= make_attr
(ATTR_RETVAL
); }
519 | tSIZEIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_SIZEIS
, $3); }
520 | tSOURCE
{ $$
= make_attr
(ATTR_SOURCE
); }
521 | tSTRICTCONTEXTHANDLE
{ $$
= make_attr
(ATTR_STRICTCONTEXTHANDLE
); }
522 | tSTRING
{ $$
= make_attr
(ATTR_STRING
); }
523 | tSWITCHIS
'(' expr
')' { $$
= make_attrp
(ATTR_SWITCHIS
, $3); }
524 | tSWITCHTYPE
'(' type
')' { $$
= make_attrp
(ATTR_SWITCHTYPE
, $3); }
525 | tTRANSMITAS
'(' type
')' { $$
= make_attrp
(ATTR_TRANSMITAS
, $3); }
526 | tUUID
'(' uuid_string
')' { $$
= make_attrp
(ATTR_UUID
, $3); }
527 | tV1ENUM
{ $$
= make_attr
(ATTR_V1ENUM
); }
528 | tVARARG
{ $$
= make_attr
(ATTR_VARARG
); }
529 | tVERSION
'(' version
')' { $$
= make_attrv
(ATTR_VERSION
, $3); }
530 | tWIREMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_WIREMARSHAL
, $3); }
531 | pointer_type
{ $$
= make_attrv
(ATTR_POINTERTYPE
, $1); }
536 | aSTRING
{ if
(!is_valid_uuid
($1))
537 error_loc
("invalid UUID: %s\n", $1);
538 $$
= parse_uuid
($1); }
541 callconv: tCDECL
{ $$
= $
<str
>1; }
542 | tFASTCALL
{ $$
= $
<str
>1; }
543 | tPASCAL
{ $$
= $
<str
>1; }
544 | tSTDCALL
{ $$
= $
<str
>1; }
547 cases: { $$
= NULL
; }
548 | cases case
{ $$
= append_var
( $1, $2 ); }
551 case: tCASE expr
':' field
{ attr_t
*a
= make_attrp
(ATTR_CASE
, append_expr
( NULL
, $2 ));
552 $$
= $4; if
(!$$
) $$
= make_var
(NULL
);
553 $$
->attrs
= append_attr
( $$
->attrs
, a
);
555 | tDEFAULT
':' field
{ attr_t
*a
= make_attr
(ATTR_DEFAULT
);
556 $$
= $3; if
(!$$
) $$
= make_var
(NULL
);
557 $$
->attrs
= append_attr
( $$
->attrs
, a
);
561 constdef: tCONST type ident
'=' expr_const
{ $$
= reg_const
($3);
562 set_type
($$
, $2, NULL
, NULL
, FALSE
);
567 enums: { $$
= NULL
; }
568 | enum_list
',' { $$
= $1; }
572 enum_list: enum { if
(!$1->eval
)
573 $1->eval
= make_exprl
(EXPR_NUM
, 0 /* default for first enum entry */);
574 $$
= append_var
( NULL
, $1 );
576 | enum_list
',' enum { if
(!$3->eval
)
578 var_t
*last
= LIST_ENTRY
( list_tail
($$
), var_t
, entry
);
579 $3->eval
= make_exprl
(EXPR_NUM
, last
->eval
->cval
+ 1);
581 $$
= append_var
( $1, $3 );
585 enum: ident
'=' expr_const
{ $$
= reg_const
($1);
587 $$
->type
= make_int
(0);
589 | ident
{ $$
= reg_const
($1);
590 $$
->type
= make_int
(0);
594 enumdef: tENUM t_ident
'{' enums
'}' { $$
= get_typev
(RPC_FC_ENUM16
, $2, tsENUM
);
595 $$
->kind
= TKIND_ENUM
;
596 $$
->fields_or_args
= $4;
599 add_typelib_entry
($$
);
603 m_exprs: m_expr
{ $$
= append_expr
( NULL
, $1 ); }
604 | m_exprs
',' m_expr
{ $$
= append_expr
( $1, $3 ); }
608 exprs: { $$ = make_expr(EXPR_VOID); }
613 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
617 m_expr: { $$
= make_expr
(EXPR_VOID
); }
621 expr: aNUM
{ $$
= make_exprl
(EXPR_NUM
, $1); }
622 | aHEXNUM
{ $$
= make_exprl
(EXPR_HEXNUM
, $1); }
623 | aDOUBLE
{ $$
= make_exprd
(EXPR_DOUBLE
, $1); }
624 | tFALSE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 0); }
625 | tTRUE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 1); }
626 | aIDENTIFIER
{ $$
= make_exprs
(EXPR_IDENTIFIER
, $1); }
627 | expr
'?' expr
':' expr
{ $$
= make_expr3
(EXPR_COND
, $1, $3, $5); }
628 | expr
'|' expr
{ $$
= make_expr2
(EXPR_OR
, $1, $3); }
629 | expr
'&' expr
{ $$
= make_expr2
(EXPR_AND
, $1, $3); }
630 | expr
'+' expr
{ $$
= make_expr2
(EXPR_ADD
, $1, $3); }
631 | expr
'-' expr
{ $$
= make_expr2
(EXPR_SUB
, $1, $3); }
632 | expr
'*' expr
{ $$
= make_expr2
(EXPR_MUL
, $1, $3); }
633 | expr
'/' expr
{ $$
= make_expr2
(EXPR_DIV
, $1, $3); }
634 | expr SHL expr
{ $$
= make_expr2
(EXPR_SHL
, $1, $3); }
635 | expr SHR expr
{ $$
= make_expr2
(EXPR_SHR
, $1, $3); }
636 |
'~' expr
{ $$
= make_expr1
(EXPR_NOT
, $2); }
637 |
'-' expr %prec NEG
{ $$
= make_expr1
(EXPR_NEG
, $2); }
638 |
'&' expr %prec ADDRESSOF
{ $$
= make_expr1
(EXPR_ADDRESSOF
, $2); }
639 |
'*' expr %prec PPTR
{ $$
= make_expr1
(EXPR_PPTR
, $2); }
640 |
'(' type
')' expr %prec CAST
{ $$
= make_exprt
(EXPR_CAST
, $2, $4); }
641 | tSIZEOF
'(' type
')' { $$
= make_exprt
(EXPR_SIZEOF
, $3, NULL
); }
642 |
'(' expr
')' { $$
= $2; }
645 expr_list_const: expr_const
{ $$
= append_expr
( NULL
, $1 ); }
646 | expr_list_const
',' expr_const
{ $$
= append_expr
( $1, $3 ); }
649 expr_const: expr
{ $$
= $1;
651 error_loc
("expression is not constant\n");
655 externdef: tEXTERN tCONST type ident
{ $$
= $4;
656 set_type
($$
, $3, NULL
, NULL
, FALSE
);
660 fields: { $$
= NULL
; }
661 | fields field
{ $$
= append_var
( $1, $2 ); }
664 field: s_field
';' { $$
= $1; }
665 | m_attributes uniondef
';' { $$
= make_var
(NULL
); $$
->type
= $2; $$
->attrs
= $1; }
666 | attributes
';' { $$
= make_var
(NULL
); $$
->attrs
= $1; }
670 s_field: m_attributes type pident array
{ $$
= $3->var
;
671 $$
->attrs
= check_field_attrs
($$
->name
, $1);
672 set_type
($$
, $2, $3, $4, FALSE
);
678 m_attributes type pident
{ var_t
*v
= $3->var
;
679 var_list_t
*args
= $3->args
;
680 v
->attrs
= check_function_attrs
(v
->name
, $1);
681 set_type
(v
, $2, $3, NULL
, FALSE
);
683 $$
= make_func
(v
, args
);
687 m_ident: { $$
= NULL
; }
691 t_ident: { $$
= NULL
; }
692 | aIDENTIFIER
{ $$
= make_var
($1); }
693 | aKNOWNTYPE
{ $$
= make_var
($1); }
696 ident: aIDENTIFIER
{ $$
= make_var
($1); }
697 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
698 | aKNOWNTYPE
{ $$
= make_var
($
<str
>1); }
701 base_type: tBYTE
{ $$
= make_builtin
($
<str
>1); }
702 | tWCHAR
{ $$
= make_builtin
($
<str
>1); }
704 | tSIGNED int_std
{ $$
= $2; $$
->sign
= 1; }
705 | tUNSIGNED int_std
{ $$
= $2; $$
->sign
= -1;
707 case RPC_FC_CHAR
: break
;
708 case RPC_FC_SMALL
: $$
->type
= RPC_FC_USMALL
; break
;
709 case RPC_FC_SHORT
: $$
->type
= RPC_FC_USHORT
; break
;
710 case RPC_FC_LONG
: $$
->type
= RPC_FC_ULONG
; break
;
712 if
($$
->name
[0] == 'h') /* hyper, as opposed to __int64 */
714 $$
= alias
($$
, "MIDL_uhyper");
721 | tUNSIGNED
{ $$
= make_int
(-1); }
722 | tFLOAT
{ $$
= make_builtin
($
<str
>1); }
723 | tSINGLE
{ $$
= duptype
(find_type
("float", 0), 1); }
724 | tDOUBLE
{ $$
= make_builtin
($
<str
>1); }
725 | tBOOLEAN
{ $$
= make_builtin
($
<str
>1); }
726 | tERRORSTATUST
{ $$
= make_builtin
($
<str
>1); }
727 | tHANDLET
{ $$
= make_builtin
($
<str
>1); }
734 int_std: tINT
{ $$
= make_builtin
($
<str
>1); }
735 | tSHORT m_int
{ $$
= make_builtin
($
<str
>1); }
736 | tSMALL
{ $$
= make_builtin
($
<str
>1); }
737 | tLONG m_int
{ $$
= make_builtin
($
<str
>1); }
738 | tHYPER m_int
{ $$
= make_builtin
($
<str
>1); }
739 | tINT64
{ $$
= make_builtin
($
<str
>1); }
740 | tCHAR
{ $$
= make_builtin
($
<str
>1); }
743 coclass: tCOCLASS aIDENTIFIER
{ $$
= make_class
($2); }
744 | tCOCLASS aKNOWNTYPE
{ $$
= find_type
($2, 0);
745 if
($$
->defined
) error_loc
("multiple definition error\n");
746 if
($$
->kind
!= TKIND_COCLASS
) error_loc
("%s was not declared a coclass\n", $2);
750 coclasshdr: attributes coclass
{ $$
= $2;
751 $$
->attrs
= check_coclass_attrs
($2->name
, $1);
752 if
(!parse_only
&& do_header
)
754 if
(!parse_only
&& do_idfile
)
759 coclassdef: coclasshdr
'{' coclass_ints
'}' semicolon_opt
766 coclass_ints: { $$
= NULL
; }
767 | coclass_ints coclass_int
{ $$
= append_ifref
( $1, $2 ); }
771 m_attributes interfacedec
{ $$
= make_ifref
($2); $$
->attrs
= $1; }
774 dispinterface: tDISPINTERFACE aIDENTIFIER
{ $$
= get_type
(0, $2, 0); $$
->kind
= TKIND_DISPATCH
; }
775 | tDISPINTERFACE aKNOWNTYPE
{ $$
= get_type
(0, $2, 0); $$
->kind
= TKIND_DISPATCH
; }
778 dispinterfacehdr: attributes dispinterface
{ attr_t
*attrs
;
779 is_object_interface
= TRUE
;
781 if
($$
->defined
) error_loc
("multiple definition error\n");
782 attrs
= make_attr
(ATTR_DISPINTERFACE
);
783 $$
->attrs
= append_attr
( check_dispiface_attrs
($2->name
, $1), attrs
);
784 $$
->ref
= find_type
("IDispatch", 0);
785 if
(!$$
->ref
) error_loc
("IDispatch is undefined\n");
787 if
(!parse_only
&& do_header
) write_forward
($$
);
791 dispint_props: tPROPERTIES
':' { $$
= NULL
; }
792 | dispint_props s_field
';' { $$
= append_var
( $1, $2 ); }
795 dispint_meths: tMETHODS
':' { $$
= NULL
; }
796 | dispint_meths funcdef
';' { $$
= append_func
( $1, $2 ); }
799 dispinterfacedef: dispinterfacehdr
'{'
803 $$
->fields_or_args
= $3;
805 if
(!parse_only
&& do_header
) write_dispinterface
($$
);
806 if
(!parse_only
&& do_idfile
) write_diid
($$
);
809 '{' interface
';' '}' { $$
= $1;
810 $$
->fields_or_args
= $3->fields_or_args
;
811 $$
->funcs
= $3->funcs
;
812 if
(!parse_only
&& do_header
) write_dispinterface
($$
);
813 if
(!parse_only
&& do_idfile
) write_diid
($$
);
817 inherit: { $$
= NULL
; }
818 |
':' aKNOWNTYPE
{ $$
= find_type2
($2, 0); }
821 interface: tINTERFACE aIDENTIFIER
{ $$
= get_type
(RPC_FC_IP
, $2, 0); $$
->kind
= TKIND_INTERFACE
; }
822 | tINTERFACE aKNOWNTYPE
{ $$
= get_type
(RPC_FC_IP
, $2, 0); $$
->kind
= TKIND_INTERFACE
; }
825 interfacehdr: attributes interface
{ $$.interface
= $2;
826 $$.old_pointer_default
= pointer_default
;
827 if
(is_attr
($1, ATTR_POINTERDEFAULT
))
828 pointer_default
= get_attrv
($1, ATTR_POINTERDEFAULT
);
829 is_object_interface
= is_object
($1);
830 if
($2->defined
) error_loc
("multiple definition error\n");
831 $2->attrs
= check_iface_attrs
($2->name
, $1);
833 if
(!parse_only
&& do_header
) write_forward
($2);
837 interfacedef: interfacehdr inherit
838 '{' int_statements
'}' semicolon_opt
{ $$
= $1.interface
;
842 compute_method_indexes
($$
);
843 if
(!parse_only
&& do_header
) write_interface
($$
);
844 if
(!parse_only
&& local_stubs
) write_locals
(local_stubs
, $$
, TRUE
);
845 if
(!parse_only
&& do_idfile
) write_iid
($$
);
846 pointer_default
= $1.old_pointer_default
;
848 /* MIDL is able to import the definition of a base class from inside the
849 * definition of a derived class, I'll try to support it with this rule */
850 | interfacehdr
':' aIDENTIFIER
851 '{' import int_statements
'}'
852 semicolon_opt
{ $$
= $1.interface
;
853 $$
->ref
= find_type2
($3, 0);
854 if
(!$$
->ref
) error_loc
("base class '%s' not found in import\n", $3);
856 compute_method_indexes
($$
);
857 if
(!parse_only
&& do_header
) write_interface
($$
);
858 if
(!parse_only
&& local_stubs
) write_locals
(local_stubs
, $$
, TRUE
);
859 if
(!parse_only
&& do_idfile
) write_iid
($$
);
860 pointer_default
= $1.old_pointer_default
;
862 | dispinterfacedef semicolon_opt
{ $$
= $1; }
866 interface
';' { $$
= $1; if
(!parse_only
&& do_header
) write_forward
($$
); }
867 | dispinterface
';' { $$
= $1; if
(!parse_only
&& do_header
) write_forward
($$
); }
870 module: tMODULE aIDENTIFIER
{ $$
= make_type
(0, NULL
); $$
->name
= $2; $$
->kind
= TKIND_MODULE
; }
871 | tMODULE aKNOWNTYPE
{ $$
= make_type
(0, NULL
); $$
->name
= $2; $$
->kind
= TKIND_MODULE
; }
874 modulehdr: attributes module
{ $$
= $2;
875 $$
->attrs
= check_module_attrs
($2->name
, $1);
879 moduledef: modulehdr
'{' int_statements
'}'
880 semicolon_opt
{ $$
= $1;
882 /* FIXME: if (!parse_only && do_header) write_module($$); */
886 pident: '*' pident %prec PPTR
{ $$
= $2; $$
->ptr_level
++; }
887 | tCONST pident
{ $$
= $2; /* FIXME */ }
888 | callconv pident
{ $$
= $2;
889 if
($$
->callconv
) parser_warning
("multiple calling conventions %s, %s for function %s\n", $$
->callconv
, $1, $$
->var
->name
);
895 func_ident: direct_ident
'(' m_args
')'
902 direct_ident: ident
{ $$
= make_pident
($1); }
903 |
'(' pident
')' { $$
= $2; }
904 | func_ident
{ $$
= $1;
905 $$
->func_ptr_level
= $$
->ptr_level
;
911 pident
{ $$
= append_pident
( NULL
, $1 ); }
912 | pident_list
',' pident
{ $$
= append_pident
( $1, $3 ); }
916 tREF
{ $$
= RPC_FC_RP
; }
917 | tUNIQUE
{ $$
= RPC_FC_UP
; }
918 | tPTR
{ $$
= RPC_FC_FP
; }
921 structdef: tSTRUCT t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_STRUCT
, $2, tsSTRUCT
);
922 /* overwrite RPC_FC_STRUCT with a more exact type */
923 $$
->type
= get_struct_type
( $4 );
924 $$
->kind
= TKIND_RECORD
;
925 $$
->fields_or_args
= $4;
928 add_typelib_entry
($$
);
932 type: tVOID
{ $$
= duptype
(find_type
("void", 0), 1); }
933 | aKNOWNTYPE
{ $$
= find_type
($1, 0); }
934 | base_type
{ $$
= $1; }
935 | tCONST type
{ $$
= duptype
($2, 1); $$
->is_const
= TRUE
; }
936 | enumdef
{ $$
= $1; }
937 | tENUM aIDENTIFIER
{ $$
= find_type2
($2, tsENUM
); }
938 | structdef
{ $$
= $1; }
939 | tSTRUCT aIDENTIFIER
{ $$
= get_type
(RPC_FC_STRUCT
, $2, tsSTRUCT
); }
940 | uniondef
{ $$
= $1; }
941 | tUNION aIDENTIFIER
{ $$
= find_type2
($2, tsUNION
); }
942 | tSAFEARRAY
'(' type
')' { $$
= make_safearray
($3); }
945 typedef: tTYPEDEF m_attributes type pident_list
{ reg_typedefs
($3, $4, check_typedef_attrs
($2));
946 process_typedefs
($4);
950 uniondef: tUNION t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_NON_ENCAPSULATED_UNION
, $2, tsUNION
);
951 $$
->kind
= TKIND_UNION
;
952 $$
->fields_or_args
= $4;
956 tSWITCH
'(' s_field
')'
957 m_ident
'{' cases
'}' { var_t
*u
= $7;
958 $$
= get_typev
(RPC_FC_ENCAPSULATED_UNION
, $2, tsUNION
);
959 $$
->kind
= TKIND_UNION
;
960 if
(!u
) u
= make_var
( xstrdup
("tagged_union") );
961 u
->type
= make_type
(RPC_FC_NON_ENCAPSULATED_UNION
, NULL
);
962 u
->type
->kind
= TKIND_UNION
;
963 u
->type
->fields_or_args
= $9;
964 u
->type
->defined
= TRUE
;
965 $$
->fields_or_args
= append_var
( $$
->fields_or_args
, $5 );
966 $$
->fields_or_args
= append_var
( $$
->fields_or_args
, u
);
972 aNUM
{ $$
= MAKEVERSION
($1, 0); }
973 | aNUM
'.' aNUM
{ $$
= MAKEVERSION
($1, $3); }
978 static void decl_builtin
(const char *name
, unsigned char type
)
980 type_t
*t
= make_type
(type
, NULL
);
981 t
->name
= xstrdup
(name
);
982 reg_type
(t
, name
, 0);
985 static type_t
*make_builtin
(char *name
)
987 /* NAME is strdup'd in the lexer */
988 type_t
*t
= duptype
(find_type
(name
, 0), 0);
993 static type_t
*make_int
(int sign
)
995 type_t
*t
= duptype
(find_type
("int", 0), 1);
999 t
->type
= t
->type
== RPC_FC_LONG ? RPC_FC_ULONG
: RPC_FC_USHORT
;
1004 void init_types
(void)
1006 decl_builtin
("void", 0);
1007 decl_builtin
("byte", RPC_FC_BYTE
);
1008 decl_builtin
("wchar_t", RPC_FC_WCHAR
);
1009 decl_builtin
("int", RPC_FC_LONG
); /* win32 */
1010 decl_builtin
("short", RPC_FC_SHORT
);
1011 decl_builtin
("small", RPC_FC_SMALL
);
1012 decl_builtin
("long", RPC_FC_LONG
);
1013 decl_builtin
("hyper", RPC_FC_HYPER
);
1014 decl_builtin
("__int64", RPC_FC_HYPER
);
1015 decl_builtin
("char", RPC_FC_CHAR
);
1016 decl_builtin
("float", RPC_FC_FLOAT
);
1017 decl_builtin
("double", RPC_FC_DOUBLE
);
1018 decl_builtin
("boolean", RPC_FC_BYTE
);
1019 decl_builtin
("error_status_t", RPC_FC_ERROR_STATUS_T
);
1020 decl_builtin
("handle_t", RPC_FC_BIND_PRIMITIVE
);
1023 static str_list_t
*append_str
(str_list_t
*list
, char *str
)
1025 struct str_list_entry_t
*entry
;
1027 if
(!str
) return list
;
1030 list
= xmalloc
( sizeof
(*list
) );
1033 entry
= xmalloc
( sizeof
(*entry
) );
1035 list_add_tail
( list
, &entry
->entry
);
1039 static attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
)
1041 attr_t
*attr_existing
;
1042 if
(!attr
) return list
;
1045 list
= xmalloc
( sizeof
(*list
) );
1048 LIST_FOR_EACH_ENTRY
(attr_existing
, list
, attr_t
, entry
)
1049 if
(attr_existing
->type
== attr
->type
)
1051 parser_warning
("duplicate attribute %s\n", get_attr_display_name
(attr
->type
));
1052 /* use the last attribute, like MIDL does */
1053 list_remove
(&attr_existing
->entry
);
1056 list_add_tail
( list
, &attr
->entry
);
1060 static attr_t
*make_attr
(enum attr_type type
)
1062 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1068 static attr_t
*make_attrv
(enum attr_type type
, unsigned long val
)
1070 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1076 static attr_t
*make_attrp
(enum attr_type type
, void *val
)
1078 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1084 static expr_t
*make_expr
(enum expr_type type
)
1086 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
1090 e
->is_const
= FALSE
;
1095 static expr_t
*make_exprl
(enum expr_type type
, long val
)
1097 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
1101 e
->is_const
= FALSE
;
1102 /* check for numeric constant */
1103 if
(type
== EXPR_NUM || type
== EXPR_HEXNUM || type
== EXPR_TRUEFALSE
) {
1104 /* make sure true/false value is valid */
1105 assert
(type
!= EXPR_TRUEFALSE || val
== 0 || val
== 1);
1112 static expr_t
*make_exprd
(enum expr_type type
, double val
)
1114 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
1123 static expr_t
*make_exprs
(enum expr_type type
, char *val
)
1126 e
= xmalloc
(sizeof
(expr_t
));
1130 e
->is_const
= FALSE
;
1131 /* check for predefined constants */
1132 if
(type
== EXPR_IDENTIFIER
) {
1133 var_t
*c
= find_const
(val
, 0);
1135 e
->u.sval
= c
->name
;
1138 e
->cval
= c
->eval
->cval
;
1144 static expr_t
*make_exprt
(enum expr_type type
, type_t
*tref
, expr_t
*expr
)
1147 e
= xmalloc
(sizeof
(expr_t
));
1151 e
->is_const
= FALSE
;
1152 /* check for cast of constant expression */
1153 if
(type
== EXPR_SIZEOF
) {
1154 switch
(tref
->type
) {
1171 case RPC_FC_ERROR_STATUS_T
:
1182 if
(type
== EXPR_CAST
&& expr
->is_const
) {
1184 e
->cval
= expr
->cval
;
1189 static expr_t
*make_expr1
(enum expr_type type
, expr_t
*expr
)
1192 if
(type
== EXPR_ADDRESSOF
&& expr
->type
!= EXPR_IDENTIFIER
)
1193 error_loc
("address-of operator applied to invalid expression\n");
1194 e
= xmalloc
(sizeof
(expr_t
));
1198 e
->is_const
= FALSE
;
1199 /* check for compile-time optimization */
1200 if
(expr
->is_const
) {
1204 e
->cval
= -expr
->cval
;
1207 e
->cval
= ~expr
->cval
;
1210 e
->is_const
= FALSE
;
1217 static expr_t
*make_expr2
(enum expr_type type
, expr_t
*expr1
, expr_t
*expr2
)
1220 e
= xmalloc
(sizeof
(expr_t
));
1224 e
->is_const
= FALSE
;
1225 /* check for compile-time optimization */
1226 if
(expr1
->is_const
&& expr2
->is_const
) {
1230 e
->cval
= expr1
->cval
+ expr2
->cval
;
1233 e
->cval
= expr1
->cval
- expr2
->cval
;
1236 e
->cval
= expr1
->cval
* expr2
->cval
;
1239 e
->cval
= expr1
->cval
/ expr2
->cval
;
1242 e
->cval
= expr1
->cval | expr2
->cval
;
1245 e
->cval
= expr1
->cval
& expr2
->cval
;
1248 e
->cval
= expr1
->cval
<< expr2
->cval
;
1251 e
->cval
= expr1
->cval
>> expr2
->cval
;
1254 e
->is_const
= FALSE
;
1261 static expr_t
*make_expr3
(enum expr_type type
, expr_t
*expr1
, expr_t
*expr2
, expr_t
*expr3
)
1264 e
= xmalloc
(sizeof
(expr_t
));
1269 e
->is_const
= FALSE
;
1270 /* check for compile-time optimization */
1271 if
(expr1
->is_const
&& expr2
->is_const
&& expr3
->is_const
) {
1275 e
->cval
= expr1
->cval ? expr2
->cval
: expr3
->cval
;
1278 e
->is_const
= FALSE
;
1285 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
)
1287 if
(!expr
) return list
;
1290 list
= xmalloc
( sizeof
(*list
) );
1293 list_add_tail
( list
, &expr
->entry
);
1297 static array_dims_t
*append_array
(array_dims_t
*list
, expr_t
*expr
)
1299 if
(!expr
) return list
;
1302 list
= xmalloc
( sizeof
(*list
) );
1305 list_add_tail
( list
, &expr
->entry
);
1309 static struct list type_pool
= LIST_INIT
(type_pool
);
1316 type_t
*alloc_type
(void)
1318 type_pool_node_t
*node
= xmalloc
(sizeof
*node
);
1319 list_add_tail
(&type_pool
, &node
->link
);
1323 void set_all_tfswrite
(int val
)
1325 type_pool_node_t
*node
;
1326 LIST_FOR_EACH_ENTRY
(node
, &type_pool
, type_pool_node_t
, link
)
1327 node
->data.tfswrite
= val
;
1330 static type_t
*make_type
(unsigned char type
, type_t
*ref
)
1332 type_t
*t
= alloc_type
();
1334 t
->kind
= TKIND_PRIMITIVE
;
1340 t
->fields_or_args
= NULL
;
1344 t
->length_is
= NULL
;
1345 t
->typestring_offset
= 0;
1347 t
->declarray
= FALSE
;
1348 t
->ignore
= (parse_only
!= 0);
1349 t
->is_const
= FALSE
;
1353 t
->user_types_registered
= FALSE
;
1354 t
->tfswrite
= FALSE
;
1355 t
->typelib_idx
= -1;
1359 static void set_type
(var_t
*v
, type_t
*type
, const pident_t
*pident
, array_dims_t
*arr
,
1362 expr_list_t
*sizes
= get_attrp
(v
->attrs
, ATTR_SIZEIS
);
1363 expr_list_t
*lengs
= get_attrp
(v
->attrs
, ATTR_LENGTHIS
);
1364 int ptr_attr
= get_attrv
(v
->attrs
, ATTR_POINTERTYPE
);
1365 int ptr_type
= ptr_attr
;
1366 int sizeless
, has_varconf
;
1368 type_t
*atype
, **ptype
;
1369 int ptr_level
= (pident ? pident
->ptr_level
: 0);
1373 if
(!ptr_type
&& top
)
1374 ptr_type
= RPC_FC_RP
;
1376 for
( ; 0 < ptr_level
; --ptr_level
)
1378 v
->type
= make_type
(pointer_default
, v
->type
);
1379 if
(ptr_level
== 1 && ptr_type
&& !arr
)
1381 v
->type
->type
= ptr_type
;
1386 if
(ptr_type
&& !arr
)
1388 if
(is_ptr
(v
->type
))
1390 if
(v
->type
->type
!= ptr_type
)
1392 v
->type
= duptype
(v
->type
, 1);
1393 v
->type
->type
= ptr_type
;
1396 else if
(!arr
&& ptr_attr
)
1397 error_loc
("%s: pointer attribute applied to non-pointer type\n", v
->name
);
1400 if
(pident
&& pident
->is_func
) {
1401 int func_ptr_level
= pident
->func_ptr_level
;
1402 v
->type
= make_type
(RPC_FC_FUNCTION
, v
->type
);
1403 v
->type
->fields_or_args
= pident
->args
;
1404 if
(pident
->callconv
)
1405 v
->type
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, pident
->callconv
));
1406 else if
(is_object_interface
) {
1407 static char *stdmethodcalltype
;
1408 if
(!stdmethodcalltype
) stdmethodcalltype
= strdup
("STDMETHODCALLTYPE");
1409 v
->type
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, stdmethodcalltype
));
1411 for
(; func_ptr_level
> 0; func_ptr_level
--)
1412 v
->type
= make_type
(ptr_type
, v
->type
);
1416 if
(arr
) LIST_FOR_EACH_ENTRY_REV
(dim
, arr
, expr_t
, entry
)
1419 error_loc
("%s: only the first array dimension can be unspecified\n", v
->name
);
1423 unsigned int align
= 0;
1424 size_t size
= type_memsize
(v
->type
, &align
);
1427 error_loc
("%s: array dimension must be positive\n", v
->name
);
1429 if
(0xffffffffuL
/ size
< (unsigned long) dim
->cval
)
1430 error_loc
("%s: total array size is too large\n", v
->name
);
1431 else if
(0xffffuL
< size
* dim
->cval
)
1432 v
->type
= make_type
(RPC_FC_LGFARRAY
, v
->type
);
1434 v
->type
= make_type
(RPC_FC_SMFARRAY
, v
->type
);
1439 v
->type
= make_type
(RPC_FC_CARRAY
, v
->type
);
1442 v
->type
->declarray
= TRUE
;
1443 v
->type
->dim
= dim
->cval
;
1447 has_varconf
= FALSE
;
1448 if
(sizes
) LIST_FOR_EACH_ENTRY
(dim
, sizes
, expr_t
, entry
)
1450 if
(dim
->type
!= EXPR_VOID
)
1453 atype
= *ptype
= duptype
(*ptype
, 0);
1455 if
(atype
->type
== RPC_FC_SMFARRAY || atype
->type
== RPC_FC_LGFARRAY
)
1456 error_loc
("%s: cannot specify size_is for a fixed sized array\n", v
->name
);
1458 if
(atype
->type
!= RPC_FC_CARRAY
&& !is_ptr
(atype
))
1459 error_loc
("%s: size_is attribute applied to illegal type\n", v
->name
);
1461 atype
->type
= RPC_FC_CARRAY
;
1462 atype
->size_is
= dim
;
1465 ptype
= &(*ptype
)->ref
;
1467 error_loc
("%s: too many expressions in size_is attribute\n", v
->name
);
1471 if
(lengs
) LIST_FOR_EACH_ENTRY
(dim
, lengs
, expr_t
, entry
)
1473 if
(dim
->type
!= EXPR_VOID
)
1476 atype
= *ptype
= duptype
(*ptype
, 0);
1478 if
(atype
->type
== RPC_FC_SMFARRAY
)
1479 atype
->type
= RPC_FC_SMVARRAY
;
1480 else if
(atype
->type
== RPC_FC_LGFARRAY
)
1481 atype
->type
= RPC_FC_LGVARRAY
;
1482 else if
(atype
->type
== RPC_FC_CARRAY
)
1483 atype
->type
= RPC_FC_CVARRAY
;
1485 error_loc
("%s: length_is attribute applied to illegal type\n", v
->name
);
1487 atype
->length_is
= dim
;
1490 ptype
= &(*ptype
)->ref
;
1492 error_loc
("%s: too many expressions in length_is attribute\n", v
->name
);
1495 if
(has_varconf
&& !last_array
(v
->type
))
1498 for
(ptype
= &v
->type
; is_array
(*ptype
); ptype
= &(*ptype
)->ref
)
1500 *ptype
= duptype
(*ptype
, 0);
1501 (*ptype
)->type
= RPC_FC_BOGUS_ARRAY
;
1505 if
(is_array
(v
->type
))
1507 const type_t
*rt
= v
->type
->ref
;
1508 if
(is_user_type
(rt
))
1509 v
->type
->type
= RPC_FC_BOGUS_ARRAY
;
1513 case RPC_FC_BOGUS_STRUCT
:
1514 case RPC_FC_NON_ENCAPSULATED_UNION
:
1515 case RPC_FC_ENCAPSULATED_UNION
:
1517 v
->type
->type
= RPC_FC_BOGUS_ARRAY
;
1519 /* FC_RP should be above, but widl overuses these, and will break things. */
1522 if
(rt
->ref
->type
== RPC_FC_IP
)
1523 v
->type
->type
= RPC_FC_BOGUS_ARRAY
;
1529 static ifref_list_t
*append_ifref
(ifref_list_t
*list
, ifref_t
*iface
)
1531 if
(!iface
) return list
;
1534 list
= xmalloc
( sizeof
(*list
) );
1537 list_add_tail
( list
, &iface
->entry
);
1541 static ifref_t
*make_ifref
(type_t
*iface
)
1543 ifref_t
*l
= xmalloc
(sizeof
(ifref_t
));
1549 static var_list_t
*append_var
(var_list_t
*list
, var_t
*var
)
1551 if
(!var
) return list
;
1554 list
= xmalloc
( sizeof
(*list
) );
1557 list_add_tail
( list
, &var
->entry
);
1561 static var_t
*make_var
(char *name
)
1563 var_t
*v
= xmalloc
(sizeof
(var_t
));
1568 v
->loc_info.input_name
= input_name ? input_name
: "stdin";
1569 v
->loc_info.line_number
= line_number
;
1570 v
->loc_info.near_text
= parser_text
;
1574 static pident_list_t
*append_pident
(pident_list_t
*list
, pident_t
*p
)
1576 if
(!p
) return list
;
1578 list
= xmalloc
(sizeof
(*list
));
1581 list_add_tail
(list
, &p
->entry
);
1585 static pident_t
*make_pident
(var_t
*var
)
1587 pident_t
*p
= xmalloc
(sizeof
(*p
));
1591 p
->func_ptr_level
= 0;
1597 static func_list_t
*append_func
(func_list_t
*list
, func_t
*func
)
1599 if
(!func
) return list
;
1602 list
= xmalloc
( sizeof
(*list
) );
1605 list_add_tail
( list
, &func
->entry
);
1609 static func_t
*make_func
(var_t
*def
, var_list_t
*args
)
1611 func_t
*f
= xmalloc
(sizeof
(func_t
));
1614 f
->ignore
= parse_only
;
1619 static type_t
*make_class
(char *name
)
1621 type_t
*c
= make_type
(0, NULL
);
1623 c
->kind
= TKIND_COCLASS
;
1627 static type_t
*make_safearray
(type_t
*type
)
1629 type_t
*sa
= duptype
(find_type
("SAFEARRAY", 0), 1);
1631 return make_type
(pointer_default
, sa
);
1636 static int hash_ident
(const char *name
)
1638 const char *p
= name
;
1640 /* a simple sum hash is probably good enough */
1645 return sum
& (HASHMAX
-1);
1648 /***** type repository *****/
1657 struct rtype
*type_hash
[HASHMAX
];
1659 static type_t
*reg_type
(type_t
*type
, const char *name
, int t
)
1664 error_loc
("registering named type without name\n");
1667 hash
= hash_ident
(name
);
1668 nt
= xmalloc
(sizeof
(struct rtype
));
1672 nt
->next
= type_hash
[hash
];
1673 type_hash
[hash
] = nt
;
1677 static int is_incomplete
(const type_t
*t
)
1679 return
!t
->defined
&& (is_struct
(t
->type
) || is_union
(t
->type
));
1682 static void add_incomplete
(type_t
*t
)
1684 struct typenode
*tn
= xmalloc
(sizeof
*tn
);
1686 list_add_tail
(&incomplete_types
, &tn
->entry
);
1689 static void fix_type
(type_t
*t
)
1691 if
(t
->kind
== TKIND_ALIAS
&& is_incomplete
(t
)) {
1692 type_t
*ot
= t
->orig
;
1694 t
->fields_or_args
= ot
->fields_or_args
;
1695 t
->defined
= ot
->defined
;
1699 static void fix_incomplete
(void)
1701 struct typenode
*tn
, *next
;
1703 LIST_FOR_EACH_ENTRY_SAFE
(tn
, next
, &incomplete_types
, struct typenode
, entry
) {
1709 static type_t
*reg_typedefs
(type_t
*type
, pident_list_t
*pidents
, attr_list_t
*attrs
)
1712 const pident_t
*pident
;
1714 int is_str
= is_attr
(attrs
, ATTR_STRING
);
1715 unsigned char ptr_type
= get_attrv
(attrs
, ATTR_POINTERTYPE
);
1726 if
(c
!= RPC_FC_CHAR
&& c
!= RPC_FC_BYTE
&& c
!= RPC_FC_WCHAR
)
1728 pident
= LIST_ENTRY
( list_head
( pidents
), const pident_t
, entry
);
1729 error_loc
("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
1734 /* We must generate names for tagless enum, struct or union.
1735 Typedef-ing a tagless enum, struct or union means we want the typedef
1736 to be included in a library whether it has other attributes or not,
1737 hence the public attribute. */
1738 if
((type
->kind
== TKIND_ENUM || type
->kind
== TKIND_RECORD
1739 || type
->kind
== TKIND_UNION
) && ! type
->name
&& ! parse_only
)
1741 if
(! is_attr
(attrs
, ATTR_PUBLIC
))
1742 attrs
= append_attr
( attrs
, make_attr
(ATTR_PUBLIC
) );
1743 type
->name
= gen_name
();
1746 LIST_FOR_EACH_ENTRY
( pident
, pidents
, const pident_t
, entry
)
1748 var_t
*name
= pident
->var
;
1752 int cptr
= pident
->ptr_level
;
1754 while
(cptr
> ptrc
) {
1755 cur
= ptr
= make_type
(pointer_default
, cur
);
1759 while
(cptr
< ptrc
) {
1764 if
(pident
->is_func
) {
1765 int func_ptr_level
= pident
->func_ptr_level
;
1766 cur
= make_type
(RPC_FC_FUNCTION
, cur
);
1767 cur
->fields_or_args
= pident
->args
;
1768 if
(pident
->callconv
)
1769 cur
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, pident
->callconv
));
1770 else if
(is_object_interface
) {
1771 static char *stdmethodcalltype
;
1772 if
(!stdmethodcalltype
) stdmethodcalltype
= strdup
("STDMETHODCALLTYPE");
1773 cur
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, stdmethodcalltype
));
1775 for
(; func_ptr_level
> 0; func_ptr_level
--)
1776 cur
= make_type
(pointer_default
, cur
);
1778 cur
= alias
(cur
, name
->name
);
1783 cur
->type
= ptr_type
;
1785 error_loc
("'%s': pointer attribute applied to non-pointer type\n",
1788 else if
(is_str
&& ! is_ptr
(cur
))
1789 error_loc
("'%s': [string] attribute applied to non-pointer type\n",
1792 if
(is_incomplete
(cur
))
1793 add_incomplete
(cur
);
1794 reg_type
(cur
, cur
->name
, 0);
1800 static type_t
*find_type
(const char *name
, int t
)
1802 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
1803 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
1806 error_loc
("type '%s' not found\n", name
);
1812 static type_t
*find_type2
(char *name
, int t
)
1814 type_t
*tp
= find_type
(name
, t
);
1819 int is_type
(const char *name
)
1821 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
1822 while
(cur
&& (cur
->t || strcmp
(cur
->name
, name
)))
1824 if
(cur
) return TRUE
;
1828 static type_t
*get_type
(unsigned char type
, char *name
, int t
)
1830 struct rtype
*cur
= NULL
;
1833 cur
= type_hash
[hash_ident
(name
)];
1834 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
1841 tp
= make_type
(type
, NULL
);
1843 if
(!name
) return tp
;
1844 return reg_type
(tp
, name
, t
);
1847 static type_t
*get_typev
(unsigned char type
, var_t
*name
, int t
)
1854 return get_type
(type
, sname
, t
);
1857 static int get_struct_type
(var_list_t
*fields
)
1859 int has_pointer
= 0;
1860 int has_conformance
= 0;
1861 int has_variance
= 0;
1864 if
(get_padding
(fields
))
1865 return RPC_FC_BOGUS_STRUCT
;
1867 if
(fields
) LIST_FOR_EACH_ENTRY
( field
, fields
, var_t
, entry
)
1869 type_t
*t
= field
->type
;
1871 if
(is_user_type
(t
))
1872 return RPC_FC_BOGUS_STRUCT
;
1883 case RPC_FC_ENCAPSULATED_UNION
:
1884 case RPC_FC_NON_ENCAPSULATED_UNION
:
1885 case RPC_FC_BOGUS_STRUCT
:
1886 return RPC_FC_BOGUS_STRUCT
;
1893 if
(field
->type
->declarray
)
1895 if
(is_string_type
(field
->attrs
, field
->type
))
1897 if
(is_conformant_array
(field
->type
))
1898 has_conformance
= 1;
1903 if
(is_array
(field
->type
->ref
))
1904 return RPC_FC_BOGUS_STRUCT
;
1906 if
(is_conformant_array
(field
->type
))
1908 has_conformance
= 1;
1909 if
(field
->type
->declarray
&& list_next
(fields
, &field
->entry
))
1910 error_loc
("field '%s' deriving from a conformant array must be the last field in the structure\n",
1913 if
(field
->type
->length_is
)
1916 t
= field
->type
->ref
;
1922 * RPC_FC_BYTE, RPC_FC_STRUCT, etc
1923 * Simple types don't effect the type of struct.
1924 * A struct containing a simple struct is still a simple struct.
1925 * So long as we can block copy the data, we return RPC_FC_STRUCT.
1927 case
0: /* void pointer */
1937 case RPC_FC_INT3264
:
1938 case RPC_FC_UINT3264
:
1951 case RPC_FC_CVARRAY
:
1952 case RPC_FC_BOGUS_ARRAY
:
1957 * Propagate member attributes
1958 * a struct should be at least as complex as its member
1960 case RPC_FC_CVSTRUCT
:
1961 has_conformance
= 1;
1966 case RPC_FC_CPSTRUCT
:
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",
1974 case RPC_FC_CSTRUCT
:
1975 has_conformance
= 1;
1976 if
(list_next
( fields
, &field
->entry
))
1977 error_loc
("field '%s' deriving from a conformant array must be the last field in the structure\n",
1981 case RPC_FC_PSTRUCT
:
1986 error_loc
("Unknown struct member %s with type (0x%02x)\n", field
->name
, t
->type
);
1987 /* fallthru - treat it as complex */
1989 /* as soon as we see one of these these members, it's bogus... */
1990 case RPC_FC_ENCAPSULATED_UNION
:
1991 case RPC_FC_NON_ENCAPSULATED_UNION
:
1992 case RPC_FC_BOGUS_STRUCT
:
1994 return RPC_FC_BOGUS_STRUCT
;
2000 if
( has_conformance
)
2001 return RPC_FC_CVSTRUCT
;
2003 return RPC_FC_BOGUS_STRUCT
;
2005 if
( has_conformance
&& has_pointer
)
2006 return RPC_FC_CPSTRUCT
;
2007 if
( has_conformance
)
2008 return RPC_FC_CSTRUCT
;
2010 return RPC_FC_PSTRUCT
;
2011 return RPC_FC_STRUCT
;
2014 /***** constant repository *****/
2019 struct rconst
*next
;
2022 struct rconst
*const_hash
[HASHMAX
];
2024 static var_t
*reg_const
(var_t
*var
)
2029 error_loc
("registering constant without name\n");
2032 hash
= hash_ident
(var
->name
);
2033 nc
= xmalloc
(sizeof
(struct rconst
));
2034 nc
->name
= var
->name
;
2036 nc
->next
= const_hash
[hash
];
2037 const_hash
[hash
] = nc
;
2041 static var_t
*find_const
(char *name
, int f
)
2043 struct rconst
*cur
= const_hash
[hash_ident
(name
)];
2044 while
(cur
&& strcmp
(cur
->name
, name
))
2047 if
(f
) error_loc
("constant '%s' not found\n", name
);
2053 static void write_libid
(const char *name
, const attr_list_t
*attr
)
2055 const UUID
*uuid
= get_attrp
(attr
, ATTR_UUID
);
2056 write_guid
(idfile
, "LIBID", name
, uuid
);
2059 static void write_clsid
(type_t
*cls
)
2061 const UUID
*uuid
= get_attrp
(cls
->attrs
, ATTR_UUID
);
2062 write_guid
(idfile
, "CLSID", cls
->name
, uuid
);
2065 static void write_diid
(type_t
*iface
)
2067 const UUID
*uuid
= get_attrp
(iface
->attrs
, ATTR_UUID
);
2068 write_guid
(idfile
, "DIID", iface
->name
, uuid
);
2071 static void write_iid
(type_t
*iface
)
2073 const UUID
*uuid
= get_attrp
(iface
->attrs
, ATTR_UUID
);
2074 write_guid
(idfile
, "IID", iface
->name
, uuid
);
2077 static int compute_method_indexes
(type_t
*iface
)
2083 idx
= compute_method_indexes
(iface
->ref
);
2090 LIST_FOR_EACH_ENTRY
( f
, iface
->funcs
, func_t
, entry
)
2091 if
(! is_callas
(f
->def
->attrs
))
2097 static char *gen_name
(void)
2099 static const char format
[] = "__WIDL_%s_generated_name_%08lX";
2100 static unsigned long n
= 0;
2101 static const char *file_id
;
2107 char *dst
= dup_basename
(input_name
, ".idl");
2111 if
(! isalnum
((unsigned char) *dst
))
2114 size
= sizeof format
- 7 + strlen
(file_id
) + 8;
2117 name
= xmalloc
(size
);
2118 sprintf
(name
, format
, file_id
, n
++);
2122 static void process_typedefs
(pident_list_t
*pidents
)
2124 pident_t
*pident
, *next
;
2126 if
(!pidents
) return
;
2127 LIST_FOR_EACH_ENTRY_SAFE
( pident
, next
, pidents
, pident_t
, entry
)
2129 var_t
*var
= pident
->var
;
2130 type_t
*type
= find_type
(var
->name
, 0);
2132 if
(! parse_only
&& do_header
)
2133 write_typedef
(type
);
2134 if
(in_typelib
&& type
->attrs
)
2135 add_typelib_entry
(type
);
2144 unsigned int dce_compatible
: 1;
2145 unsigned int acf
: 1;
2146 unsigned int on_interface
: 1;
2147 unsigned int on_function
: 1;
2148 unsigned int on_arg
: 1;
2149 unsigned int on_type
: 1;
2150 unsigned int on_field
: 1;
2151 unsigned int on_library
: 1;
2152 unsigned int on_dispinterface
: 1;
2153 unsigned int on_module
: 1;
2154 unsigned int on_coclass
: 1;
2155 const char *display_name
;
2158 struct allowed_attr allowed_attr
[] =
2160 /* attr { D ACF I Fn ARG T Fi L DI M C <display name> } */
2161 /* ATTR_AGGREGATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "aggregatable" },
2162 /* ATTR_APPOBJECT */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "appobject" },
2163 /* ATTR_ASYNC */ { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, "async" },
2164 /* ATTR_AUTO_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "auto_handle" },
2165 /* ATTR_BINDABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "bindable" },
2166 /* ATTR_BROADCAST */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "broadcast" },
2167 /* ATTR_CALLAS */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "call_as" },
2168 /* ATTR_CALLCONV */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
},
2169 /* ATTR_CASE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "case" },
2170 /* ATTR_CONTEXTHANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "context_handle" },
2171 /* ATTR_CONTROL */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, "control" },
2172 /* ATTR_DEFAULT */ { 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, "default" },
2173 /* ATTR_DEFAULTCOLLELEM */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "defaultcollelem" },
2174 /* ATTR_DEFAULTVALUE_EXPR */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "defaultvalue" },
2175 /* ATTR_DEFAULTVALUE_STRING */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "defaultvalue" },
2176 /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "defaultvtable" },
2177 /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
},
2178 /* ATTR_DISPLAYBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "displaybind" },
2179 /* ATTR_DLLNAME */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, "dllname" },
2180 /* ATTR_DUAL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "dual" },
2181 /* ATTR_ENDPOINT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "endpoint" },
2182 /* ATTR_ENTRY_ORDINAL */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "entry" },
2183 /* ATTR_ENTRY_STRING */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "entry" },
2184 /* ATTR_EXPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "explicit_handle" },
2185 /* ATTR_HANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "handle" },
2186 /* ATTR_HELPCONTEXT */ { 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, "helpcontext" },
2187 /* ATTR_HELPFILE */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpfile" },
2188 /* ATTR_HELPSTRING */ { 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, "helpstring" },
2189 /* ATTR_HELPSTRINGCONTEXT */ { 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, "helpstringcontext" },
2190 /* ATTR_HELPSTRINGDLL */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpstringdll" },
2191 /* ATTR_HIDDEN */ { 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, "hidden" },
2192 /* ATTR_ID */ { 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, "id" },
2193 /* ATTR_IDEMPOTENT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "idempotent" },
2194 /* ATTR_IIDIS */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "iid_is" },
2195 /* ATTR_IMMEDIATEBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "immediatebind" },
2196 /* ATTR_IMPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "implicit_handle" },
2197 /* ATTR_IN */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "in" },
2198 /* ATTR_INPUTSYNC */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inputsync" },
2199 /* ATTR_LENGTHIS */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "length_is" },
2200 /* ATTR_LOCAL */ { 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, "local" },
2201 /* ATTR_NONBROWSABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "nonbrowsable" },
2202 /* ATTR_NONCREATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "noncreatable" },
2203 /* ATTR_NONEXTENSIBLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "nonextensible" },
2204 /* ATTR_OBJECT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "object" },
2205 /* ATTR_ODL */ { 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, "odl" },
2206 /* ATTR_OLEAUTOMATION */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "oleautomation" },
2207 /* ATTR_OPTIONAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "optional" },
2208 /* ATTR_OUT */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "out" },
2209 /* ATTR_POINTERDEFAULT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "pointer_default" },
2210 /* ATTR_POINTERTYPE */ { 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, "ref, unique or ptr" },
2211 /* ATTR_PROPGET */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "propget" },
2212 /* ATTR_PROPPUT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "propput" },
2213 /* ATTR_PROPPUTREF */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "propputref" },
2214 /* ATTR_PUBLIC */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "public" },
2215 /* ATTR_RANGE */ { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, "range" },
2216 /* ATTR_READONLY */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "readonly" },
2217 /* ATTR_REQUESTEDIT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "requestedit" },
2218 /* ATTR_RESTRICTED */ { 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, "restricted" },
2219 /* ATTR_RETVAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "retval" },
2220 /* ATTR_SIZEIS */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "size_is" },
2221 /* ATTR_SOURCE */ { 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, "source" },
2222 /* ATTR_STRICTCONTEXTHANDLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "strict_context_handle" },
2223 /* ATTR_STRING */ { 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, "string" },
2224 /* ATTR_SWITCHIS */ { 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "switch_is" },
2225 /* ATTR_SWITCHTYPE */ { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, "switch_type" },
2226 /* ATTR_TRANSMITAS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "transmit_as" },
2227 /* ATTR_UUID */ { 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, "uuid" },
2228 /* ATTR_V1ENUM */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "v1_enum" },
2229 /* ATTR_VARARG */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "vararg" },
2230 /* ATTR_VERSION */ { 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, "version" },
2231 /* ATTR_WIREMARSHAL */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "wire_marshal" },
2234 const char *get_attr_display_name
(enum attr_type type
)
2236 return allowed_attr
[type
].display_name
;
2239 static const attr_list_t
*check_iface_attrs
(const char *name
, const attr_list_t
*attrs
)
2242 if
(!attrs
) return attrs
;
2243 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2245 if
(!allowed_attr
[attr
->type
].on_interface
)
2246 error_loc
("inapplicable attribute %s for interface %s\n",
2247 allowed_attr
[attr
->type
].display_name
, name
);
2252 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
)
2255 if
(!attrs
) return attrs
;
2256 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2258 if
(!allowed_attr
[attr
->type
].on_function
)
2259 error_loc
("inapplicable attribute %s for function %s\n",
2260 allowed_attr
[attr
->type
].display_name
, name
);
2265 static void check_arg
(var_t
*arg
)
2267 const type_t
*t
= arg
->type
;
2270 if
(t
->type
== 0 && ! is_var_ptr
(arg
))
2271 error_loc
("argument '%s' has void type\n", arg
->name
);
2275 LIST_FOR_EACH_ENTRY
(attr
, arg
->attrs
, const attr_t
, entry
)
2277 if
(!allowed_attr
[attr
->type
].on_arg
)
2278 error_loc
("inapplicable attribute %s for argument %s\n",
2279 allowed_attr
[attr
->type
].display_name
, arg
->name
);
2284 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
)
2287 if
(!attrs
) return attrs
;
2288 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2290 if
(!allowed_attr
[attr
->type
].on_type
)
2291 error_loc
("inapplicable attribute %s for typedef\n",
2292 allowed_attr
[attr
->type
].display_name
);
2297 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
)
2300 if
(!attrs
) return attrs
;
2301 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2303 if
(!allowed_attr
[attr
->type
].on_field
)
2304 error_loc
("inapplicable attribute %s for field %s\n",
2305 allowed_attr
[attr
->type
].display_name
, name
);
2310 static const attr_list_t
*check_library_attrs
(const char *name
, const attr_list_t
*attrs
)
2313 if
(!attrs
) return attrs
;
2314 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2316 if
(!allowed_attr
[attr
->type
].on_library
)
2317 error_loc
("inapplicable attribute %s for library %s\n",
2318 allowed_attr
[attr
->type
].display_name
, name
);
2323 static attr_list_t
*check_dispiface_attrs
(const char *name
, attr_list_t
*attrs
)
2326 if
(!attrs
) return attrs
;
2327 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2329 if
(!allowed_attr
[attr
->type
].on_dispinterface
)
2330 error_loc
("inapplicable attribute %s for dispinterface %s\n",
2331 allowed_attr
[attr
->type
].display_name
, name
);
2336 static const attr_list_t
*check_module_attrs
(const char *name
, const attr_list_t
*attrs
)
2339 if
(!attrs
) return attrs
;
2340 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2342 if
(!allowed_attr
[attr
->type
].on_module
)
2343 error_loc
("inapplicable attribute %s for module %s\n",
2344 allowed_attr
[attr
->type
].display_name
, name
);
2349 static const attr_list_t
*check_coclass_attrs
(const char *name
, const attr_list_t
*attrs
)
2352 if
(!attrs
) return attrs
;
2353 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2355 if
(!allowed_attr
[attr
->type
].on_coclass
)
2356 error_loc
("inapplicable attribute %s for coclass %s\n",
2357 allowed_attr
[attr
->type
].display_name
, name
);
2362 /* checks that arguments for a function make sense for marshalling and unmarshalling */
2363 static void check_remoting_args
(const func_t
*func
)
2365 const char *funcname
= func
->def
->name
;
2368 if
(func
->args
) LIST_FOR_EACH_ENTRY
( arg
, func
->args
, const var_t
, entry
)
2371 const type_t
*type
= arg
->type
;
2372 int is_wire_marshal
= 0;
2373 int is_context_handle
= 0;
2375 /* get pointer level and fundamental type for the argument */
2378 if
(!is_wire_marshal
&& is_attr
(type
->attrs
, ATTR_WIREMARSHAL
))
2379 is_wire_marshal
= 1;
2380 if
(!is_context_handle
&& is_attr
(type
->attrs
, ATTR_CONTEXTHANDLE
))
2381 is_context_handle
= 1;
2382 if
(type
->kind
== TKIND_ALIAS
)
2384 else if
(is_ptr
(type
))
2393 /* check that [out] parameters have enough pointer levels */
2394 if
(is_attr
(arg
->attrs
, ATTR_OUT
))
2396 if
(!is_array
(type
))
2399 error_loc_info
(&arg
->loc_info
, "out parameter \'%s\' of function \'%s\' is not a pointer\n", arg
->name
, funcname
);
2400 if
(type
->type
== RPC_FC_IP
&& ptr_level
== 1)
2401 error_loc_info
(&arg
->loc_info
, "out interface pointer \'%s\' of function \'%s\' is not a double pointer\n", arg
->name
, funcname
);
2405 if
(type
->type
== 0 && !is_attr
(arg
->attrs
, ATTR_IIDIS
) && !is_wire_marshal
&& !is_context_handle
)
2406 error_loc_info
(&arg
->loc_info
, "parameter \'%s\' of function \'%s\' cannot derive from void *\n", arg
->name
, funcname
);
2407 else if
(type
->type
== RPC_FC_FUNCTION
)
2408 error_loc_info
(&arg
->loc_info
, "parameter \'%s\' of function \'%s\' cannot be a function pointer\n", arg
->name
, funcname
);
2412 static void check_functions
(const type_t
*iface
)
2414 if
(!is_inside_library
&& !is_attr
(iface
->attrs
, ATTR_LOCAL
))
2417 if
(iface
->funcs
) LIST_FOR_EACH_ENTRY
( func
, iface
->funcs
, const func_t
, entry
)
2419 if
(!is_attr
(func
->def
->attrs
, ATTR_LOCAL
))
2420 check_remoting_args
(func
);
2425 static void check_all_user_types
(ifref_list_t
*ifrefs
)
2427 const ifref_t
*ifref
;
2430 if
(ifrefs
) LIST_FOR_EACH_ENTRY
(ifref
, ifrefs
, const ifref_t
, entry
)
2432 const func_list_t
*fs
= ifref
->iface
->funcs
;
2433 if
(fs
) LIST_FOR_EACH_ENTRY
(f
, fs
, const func_t
, entry
)
2434 check_for_additional_prototype_types
(f
->args
);
2438 int is_valid_uuid
(const char *s
)
2442 for
(i
= 0; i
< 36; ++i
)
2443 if
(i
== 8 || i
== 13 || i
== 18 || i
== 23)
2449 if
(!isxdigit
(s
[i
]))
2452 return s
[i
] == '\0';