5 * Copyright 2002 Ove Kaaven
6 * Copyright 2006-2008 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
44 /* Berkeley yacc (byacc) doesn't seem to know about these */
45 /* Some *BSD supplied versions do define these though */
47 # define YYEMPTY (-1) /* Empty lookahead value of yychar */
50 # define YYLEX yylex()
53 #elif defined(YYBISON)
54 /* Bison was used for original development */
55 /* #define YYEMPTY -2 */
56 /* #define YYLEX yylex() */
59 /* No yacc we know yet */
60 # if !defined(YYEMPTY) || !defined(YYLEX)
61 # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
62 # elif defined(__GNUC__) /* gcc defines the #warning directive */
63 # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
64 /* #else we just take a chance that it works... */
68 #define YYERROR_VERBOSE
70 unsigned char pointer_default
= RPC_FC_UP
;
71 static int is_in_interface
= FALSE
;
72 static int is_object_interface
= FALSE
;
73 /* are we inside a library block? */
74 static int is_inside_library
= FALSE
;
76 typedef
struct list typelist_t
;
88 typedef
struct _decl_spec_t
92 enum storage_class stgclass
;
95 typelist_t incomplete_types
= LIST_INIT
(incomplete_types
);
97 static void add_incomplete
(type_t
*t
);
98 static void fix_incomplete
(void);
99 static void fix_incomplete_types
(type_t
*complete_type
);
101 static str_list_t
*append_str
(str_list_t
*list
, char *str
);
102 static attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
);
103 static attr_list_t
*append_attr_list
(attr_list_t
*new_list
, attr_list_t
*old_list
);
104 static decl_spec_t
*make_decl_spec
(type_t
*type
, decl_spec_t
*left
, decl_spec_t
*right
, attr_t
*attr
, enum storage_class stgclass
);
105 static attr_t
*make_attr
(enum attr_type type
);
106 static attr_t
*make_attrv
(enum attr_type type
, unsigned long val
);
107 static attr_t
*make_attrp
(enum attr_type type
, void *val
);
108 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
);
109 static array_dims_t
*append_array
(array_dims_t
*list
, expr_t
*expr
);
110 static void set_type
(var_t
*v
, decl_spec_t
*decl_spec
, const declarator_t
*decl
, int top
);
111 static var_list_t
*set_var_types
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_list_t
*decls
);
112 static ifref_list_t
*append_ifref
(ifref_list_t
*list
, ifref_t
*iface
);
113 static ifref_t
*make_ifref
(type_t
*iface
);
114 static var_list_t
*append_var
(var_list_t
*list
, var_t
*var
);
115 static var_list_t
*append_var_list
(var_list_t
*list
, var_list_t
*vars
);
116 static var_t
*make_var
(char *name
);
117 static declarator_list_t
*append_declarator
(declarator_list_t
*list
, declarator_t
*p
);
118 static declarator_t
*make_declarator
(var_t
*var
);
119 static func_list_t
*append_func
(func_list_t
*list
, func_t
*func
);
120 static func_t
*make_func
(var_t
*def
);
121 static type_t
*make_class
(char *name
);
122 static type_t
*make_safearray
(type_t
*type
);
123 static type_t
*make_builtin
(char *name
);
124 static type_t
*make_int
(int sign
);
125 static typelib_t
*make_library
(const char *name
, const attr_list_t
*attrs
);
126 static type_t
*make_func_type
(var_list_t
*args
);
127 static type_t
*make_enum_type
(char *name
, var_list_t
*enums
);
128 static type_t
*make_struct_type
(char *name
, int defined
, var_list_t
*fields
);
129 static type_t
*make_ne_union_type
(char *name
, var_list_t
*fields
);
130 static type_t
*make_e_union_type
(char *name
, var_t
*switch_field
, var_t
*union_field
, var_list_t
*cases
);
131 static type_t
*make_pointer_type
(type_t
*ref
, attr_list_t
*attrs
);
132 static void define_interface_type
(type_t
*iface
, type_t
*inherit
, func_list_t
*funcs
);
133 static void define_dispinterface_type
(type_t
*iface
, var_list_t
*props
, func_list_t
*methods
);
134 static type_t
*append_ptrchain_type
(type_t
*ptrchain
, type_t
*type
);
136 static type_t
*reg_type
(type_t
*type
, const char *name
, int t
);
137 static type_t
*reg_typedefs
(decl_spec_t
*decl_spec
, var_list_t
*names
, attr_list_t
*attrs
);
138 static type_t
*find_type_or_error
(const char *name
, int t
);
139 static type_t
*find_type_or_error2
(char *name
, int t
);
140 static type_t
*get_type
(unsigned char type
, char *name
, int t
);
141 static int get_struct_type
(var_list_t
*fields
);
143 static var_t
*reg_const
(var_t
*var
);
145 static void write_libid
(const typelib_t
*typelib
);
146 static void write_clsid
(type_t
*cls
);
147 static void write_diid
(type_t
*iface
);
148 static void write_iid
(type_t
*iface
);
150 static int compute_method_indexes
(type_t
*iface
);
151 static char *gen_name
(void);
152 static statement_t
*process_typedefs
(var_list_t
*names
);
153 static void check_arg
(var_t
*arg
);
154 static void check_functions
(const type_t
*iface
);
155 static void check_all_user_types
(const statement_list_t
*stmts
);
156 static attr_list_t
*check_iface_attrs
(const char *name
, attr_list_t
*attrs
);
157 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
);
158 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
);
159 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
);
160 static attr_list_t
*check_library_attrs
(const char *name
, attr_list_t
*attrs
);
161 static attr_list_t
*check_dispiface_attrs
(const char *name
, attr_list_t
*attrs
);
162 static attr_list_t
*check_module_attrs
(const char *name
, attr_list_t
*attrs
);
163 static attr_list_t
*check_coclass_attrs
(const char *name
, attr_list_t
*attrs
);
164 const char *get_attr_display_name
(enum attr_type type
);
165 static void add_explicit_handle_if_necessary
(func_t
*func
);
167 static statement_t
*make_statement
(enum statement_type type
);
168 static statement_t
*make_statement_type_decl
(type_t
*type
);
169 static statement_t
*make_statement_reference
(type_t
*type
);
170 static statement_t
*make_statement_declaration
(var_t
*var
);
171 static statement_t
*make_statement_library
(typelib_t
*typelib
);
172 static statement_t
*make_statement_cppquote
(const char *str
);
173 static statement_t
*make_statement_importlib
(const char *str
);
174 static statement_t
*make_statement_module
(type_t
*type
);
175 static statement_t
*make_statement_import
(const char *str
);
176 static statement_list_t
*append_statement
(statement_list_t
*list
, statement_t
*stmt
);
177 static func_list_t
*append_func_from_statement
(func_list_t
*list
, statement_t
*stmt
);
186 attr_list_t
*attr_list
;
187 str_list_t
*str_list
;
189 expr_list_t
*expr_list
;
190 array_dims_t
*array_dims
;
193 var_list_t
*var_list
;
194 declarator_t
*declarator
;
195 declarator_list_t
*declarator_list
;
197 func_list_t
*func_list
;
198 statement_t
*statement
;
199 statement_list_t
*stmt_list
;
201 ifref_list_t
*ifref_list
;
206 interface_info_t ifinfo
;
208 struct _import_t
*import
;
209 struct _decl_spec_t
*declspec
;
210 enum storage_class stgclass
;
213 %token
<str
> aIDENTIFIER
214 %token
<str
> aKNOWNTYPE
215 %token
<num
> aNUM aHEXNUM
217 %token
<str
> aSTRING aWSTRING
222 %token EQUALITY INEQUALITY
223 %token GREATEREQUAL LESSEQUAL
224 %token LOGICALOR LOGICALAND
225 %token tAGGREGATABLE tALLOCATE tAPPOBJECT tASYNC tASYNCUUID
226 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
227 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
228 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
229 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
231 %token tDEFAULTCOLLELEM
233 %token tDEFAULTVTABLE
235 %token tDISPINTERFACE
236 %token tDLLNAME tDOUBLE tDUAL
238 %token tENTRY tENUM tERRORSTATUST
239 %token tEXPLICITHANDLE tEXTERN
245 %token tHELPCONTEXT tHELPFILE
246 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
248 %token tHYPER tID tIDEMPOTENT
250 %token tIMMEDIATEBIND
251 %token tIMPLICITHANDLE
252 %token tIMPORT tIMPORTLIB
253 %token tIN tIN_LINE tINLINE
258 %token tLENGTHIS tLIBRARY
265 %token tNONEXTENSIBLE
267 %token tOBJECT tODL tOLEAUTOMATION
271 %token tPOINTERDEFAULT
273 %token tPROPGET tPROPPUT tPROPPUTREF
277 %token tREADONLY tREF
286 %token tSIZEIS tSIZEOF
291 %token tSTRICTCONTEXTHANDLE
292 %token tSTRING tSTRUCT
293 %token tSWITCH tSWITCHIS tSWITCHTYPE
305 %token tWCHAR tWIREMARSHAL
307 %type
<attr
> attribute type_qualifier function_specifier
308 %type
<attr_list
> m_attributes attributes attrib_list m_type_qual_list
309 %type
<str_list
> str_list
310 %type
<expr
> m_expr expr expr_const expr_int_const array
311 %type
<expr_list
> m_exprs
/* exprs expr_list */ expr_list_int_const
312 %type
<ifinfo
> interfacehdr
313 %type
<stgclass
> storage_cls_spec
314 %type
<declspec
> decl_spec decl_spec_no_type m_decl_spec_no_type
315 %type
<type
> inherit interface interfacedef interfacedec
316 %type
<type
> dispinterface dispinterfacehdr dispinterfacedef
317 %type
<type
> module modulehdr moduledef
318 %type
<type
> base_type int_std
319 %type
<type
> enumdef structdef uniondef
321 %type
<ifref
> coclass_int
322 %type
<ifref_list
> coclass_ints
323 %type
<var
> arg ne_union_field union_field s_field case
enum declaration
324 %type
<var_list
> m_args no_args args fields ne_union_fields cases enums enum_list dispint_props field
325 %type
<var
> m_ident ident
326 %type
<declarator
> declarator direct_declarator init_declarator
327 %type
<declarator_list
> declarator_list
329 %type
<func_list
> int_statements dispint_meths
330 %type
<type
> coclass coclasshdr coclassdef
331 %type
<num
> pointer_type version
332 %type
<str
> libraryhdr callconv cppquote importlib import t_ident
333 %type
<uuid
> uuid_string
334 %type
<import
> import_start
335 %type
<typelib
> library_start librarydef
336 %type
<statement
> statement typedef
337 %type
<stmt_list
> gbl_statements imp_statements
346 %left EQUALITY INEQUALITY
347 %left
'<' '>' LESSEQUAL GREATEREQUAL
351 %right
'!' '~' CAST PPTR POS NEG ADDRESSOF tSIZEOF
352 %left
'.' MEMBERPTR
'[' ']'
356 input: gbl_statements
{ fix_incomplete
();
357 check_all_user_types
($1);
365 gbl_statements: { $$
= NULL
; }
366 | gbl_statements interfacedec
{ $$
= $1; }
367 | gbl_statements interfacedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); }
368 | gbl_statements coclass
';' { $$
= $1;
369 reg_type
($2, $2->name
, 0);
370 if
(!parse_only
&& do_header
) write_coclass_forward
($2);
372 | gbl_statements coclassdef
{ $$
= append_statement
($1, make_statement_type_decl
($2));
373 add_typelib_entry
($2);
374 reg_type
($2, $2->name
, 0);
375 if
(!parse_only
&& do_header
) write_coclass_forward
($2);
377 | gbl_statements moduledef
{ $$
= append_statement
($1, make_statement_module
($2));
378 add_typelib_entry
($2);
380 | gbl_statements librarydef
{ $$
= append_statement
($1, make_statement_library
($2)); }
381 | gbl_statements statement
{ $$
= append_statement
($1, $2); }
384 imp_statements: { $$
= NULL
; }
385 | imp_statements interfacedec
{ $$
= append_statement
($1, make_statement_reference
($2)); if
(!parse_only
) add_typelib_entry
($2); }
386 | imp_statements interfacedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); if
(!parse_only
) add_typelib_entry
($2); }
387 | imp_statements coclass
';' { $$
= $1; reg_type
($2, $2->name
, 0); if
(!parse_only
&& do_header
) write_coclass_forward
($2); }
388 | imp_statements coclassdef
{ $$
= append_statement
($1, make_statement_type_decl
($2));
389 if
(!parse_only
) add_typelib_entry
($2);
390 reg_type
($2, $2->name
, 0);
391 if
(!parse_only
&& do_header
) write_coclass_forward
($2);
393 | imp_statements moduledef
{ $$
= append_statement
($1, make_statement_module
($2)); if
(!parse_only
) add_typelib_entry
($2); }
394 | imp_statements statement
{ $$
= append_statement
($1, $2); }
395 | imp_statements importlib
{ $$
= append_statement
($1, make_statement_importlib
($2)); }
396 | imp_statements librarydef
{ $$
= append_statement
($1, make_statement_library
($2)); }
399 int_statements: { $$
= NULL
; }
400 | int_statements statement
{ $$
= append_func_from_statement
( $1, $2 ); }
408 cppquote
{ $$
= make_statement_cppquote
($1); }
409 | enumdef
';' { $$
= make_statement_type_decl
($1);
410 if
(!parse_only
&& do_header
) {
411 write_type_def_or_decl
(header
, $1, FALSE
, NULL
);
412 fprintf
(header
, ";\n\n");
415 | declaration
';' { $$
= make_statement_declaration
($1);
416 if
(!parse_only
&& do_header
) write_declaration
($1, is_in_interface
);
418 | import
{ $$
= make_statement_import
($1); }
419 | structdef
';' { $$
= make_statement_type_decl
($1);
420 if
(!parse_only
&& do_header
) {
421 write_type_def_or_decl
(header
, $1, FALSE
, NULL
);
422 fprintf
(header
, ";\n\n");
425 | typedef
';' { $$
= $1; }
426 | uniondef
';' { $$
= make_statement_type_decl
($1);
427 if
(!parse_only
&& do_header
) {
428 write_type_def_or_decl
(header
, $1, FALSE
, NULL
);
429 fprintf
(header
, ";\n\n");
434 cppquote: tCPPQUOTE
'(' aSTRING
')' { $$
= $3; if
(!parse_only
&& do_header
) fprintf
(header
, "%s\n", $3); }
436 import_start: tIMPORT aSTRING
';' { assert
(yychar == YYEMPTY
);
437 $$
= xmalloc
(sizeof
(struct _import_t
));
439 $$
->import_performed
= do_import
($2);
440 if
(!$$
->import_performed
) yychar = aEOF
;
444 import: import_start imp_statements aEOF
{ $$
= $1->name
;
445 if
($1->import_performed
) pop_import
();
447 if
(!parse_only
&& do_header
) write_import
($$
);
451 importlib: tIMPORTLIB
'(' aSTRING
')'
452 semicolon_opt
{ $$
= $3; if
(!parse_only
) add_importlib
($3); }
455 libraryhdr: tLIBRARY aIDENTIFIER
{ $$
= $2; }
457 library_start: attributes libraryhdr
'{' { $$
= make_library
($2, check_library_attrs
($2, $1));
458 if
(!parse_only
) start_typelib
($$
);
459 if
(!parse_only
&& do_header
) write_library
($$
);
460 if
(!parse_only
&& do_idfile
) write_libid
($$
);
461 is_inside_library
= TRUE
;
464 librarydef: library_start imp_statements
'}'
465 semicolon_opt
{ $$
= $1;
467 if
(!parse_only
) end_typelib
();
468 is_inside_library
= FALSE
;
472 m_args: { $$
= NULL
; }
476 no_args: tVOID
{ $$
= NULL
; }
479 args: arg
{ check_arg
($1); $$
= append_var
( NULL
, $1 ); }
480 | args
',' arg
{ check_arg
($3); $$
= append_var
( $1, $3); }
484 /* split into two rules to get bison to resolve a tVOID conflict */
485 arg: attributes decl_spec declarator
{ $$
= $3->var
;
487 if
($2->stgclass
!= STG_NONE
&& $2->stgclass
!= STG_REGISTER
)
488 error_loc
("invalid storage class for function parameter\n");
489 set_type
($$
, $2, $3, TRUE
);
492 | decl_spec declarator
{ $$
= $2->var
;
493 if
($1->stgclass
!= STG_NONE
&& $1->stgclass
!= STG_REGISTER
)
494 error_loc
("invalid storage class for function parameter\n");
495 set_type
($$
, $1, $2, TRUE
);
500 array: '[' m_expr
']' { $$
= $2; }
501 |
'[' '*' ']' { $$
= make_expr
(EXPR_VOID
); }
504 m_attributes: { $$
= NULL
; }
509 '[' attrib_list
']' { $$
= $2;
511 error_loc
("empty attribute lists unsupported\n");
515 attrib_list: attribute
{ $$
= append_attr
( NULL
, $1 ); }
516 | attrib_list
',' attribute
{ $$
= append_attr
( $1, $3 ); }
517 | attrib_list
']' '[' attribute
{ $$
= append_attr
( $1, $4 ); }
520 str_list: aSTRING
{ $$
= append_str
( NULL
, $1 ); }
521 | str_list
',' aSTRING
{ $$
= append_str
( $1, $3 ); }
524 attribute: { $$
= NULL
; }
525 | tAGGREGATABLE
{ $$
= make_attr
(ATTR_AGGREGATABLE
); }
526 | tAPPOBJECT
{ $$
= make_attr
(ATTR_APPOBJECT
); }
527 | tASYNC
{ $$
= make_attr
(ATTR_ASYNC
); }
528 | tAUTOHANDLE
{ $$
= make_attr
(ATTR_AUTO_HANDLE
); }
529 | tBINDABLE
{ $$
= make_attr
(ATTR_BINDABLE
); }
530 | tBROADCAST
{ $$
= make_attr
(ATTR_BROADCAST
); }
531 | tCALLAS
'(' ident
')' { $$
= make_attrp
(ATTR_CALLAS
, $3); }
532 | tCASE
'(' expr_list_int_const
')' { $$
= make_attrp
(ATTR_CASE
, $3); }
533 | tCONTEXTHANDLE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); }
534 | tCONTEXTHANDLENOSERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
535 | tCONTEXTHANDLESERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
536 | tCONTROL
{ $$
= make_attr
(ATTR_CONTROL
); }
537 | tDEFAULT
{ $$
= make_attr
(ATTR_DEFAULT
); }
538 | tDEFAULTCOLLELEM
{ $$
= make_attr
(ATTR_DEFAULTCOLLELEM
); }
539 | tDEFAULTVALUE
'(' expr_const
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE
, $3); }
540 | tDEFAULTVTABLE
{ $$
= make_attr
(ATTR_DEFAULTVTABLE
); }
541 | tDISPLAYBIND
{ $$
= make_attr
(ATTR_DISPLAYBIND
); }
542 | tDLLNAME
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DLLNAME
, $3); }
543 | tDUAL
{ $$
= make_attr
(ATTR_DUAL
); }
544 | tENDPOINT
'(' str_list
')' { $$
= make_attrp
(ATTR_ENDPOINT
, $3); }
545 | tENTRY
'(' expr_const
')' { $$
= make_attrp
(ATTR_ENTRY
, $3); }
546 | tEXPLICITHANDLE
{ $$
= make_attr
(ATTR_EXPLICIT_HANDLE
); }
547 | tHANDLE
{ $$
= make_attr
(ATTR_HANDLE
); }
548 | tHELPCONTEXT
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_HELPCONTEXT
, $3); }
549 | tHELPFILE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPFILE
, $3); }
550 | tHELPSTRING
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRING
, $3); }
551 | tHELPSTRINGCONTEXT
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_HELPSTRINGCONTEXT
, $3); }
552 | tHELPSTRINGDLL
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRINGDLL
, $3); }
553 | tHIDDEN
{ $$
= make_attr
(ATTR_HIDDEN
); }
554 | tID
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_ID
, $3); }
555 | tIDEMPOTENT
{ $$
= make_attr
(ATTR_IDEMPOTENT
); }
556 | tIIDIS
'(' expr
')' { $$
= make_attrp
(ATTR_IIDIS
, $3); }
557 | tIMMEDIATEBIND
{ $$
= make_attr
(ATTR_IMMEDIATEBIND
); }
558 | tIMPLICITHANDLE
'(' tHANDLET aIDENTIFIER
')' { $$
= make_attrp
(ATTR_IMPLICIT_HANDLE
, $4); }
559 | tIN
{ $$
= make_attr
(ATTR_IN
); }
560 | tINPUTSYNC
{ $$
= make_attr
(ATTR_INPUTSYNC
); }
561 | tLENGTHIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_LENGTHIS
, $3); }
562 | tLCID
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_LIBLCID
, $3); }
563 | tLOCAL
{ $$
= make_attr
(ATTR_LOCAL
); }
564 | tNONBROWSABLE
{ $$
= make_attr
(ATTR_NONBROWSABLE
); }
565 | tNONCREATABLE
{ $$
= make_attr
(ATTR_NONCREATABLE
); }
566 | tNONEXTENSIBLE
{ $$
= make_attr
(ATTR_NONEXTENSIBLE
); }
567 | tOBJECT
{ $$
= make_attr
(ATTR_OBJECT
); }
568 | tODL
{ $$
= make_attr
(ATTR_ODL
); }
569 | tOLEAUTOMATION
{ $$
= make_attr
(ATTR_OLEAUTOMATION
); }
570 | tOPTIONAL
{ $$
= make_attr
(ATTR_OPTIONAL
); }
571 | tOUT
{ $$
= make_attr
(ATTR_OUT
); }
572 | tPOINTERDEFAULT
'(' pointer_type
')' { $$
= make_attrv
(ATTR_POINTERDEFAULT
, $3); }
573 | tPROPGET
{ $$
= make_attr
(ATTR_PROPGET
); }
574 | tPROPPUT
{ $$
= make_attr
(ATTR_PROPPUT
); }
575 | tPROPPUTREF
{ $$
= make_attr
(ATTR_PROPPUTREF
); }
576 | tPUBLIC
{ $$
= make_attr
(ATTR_PUBLIC
); }
577 | tRANGE
'(' expr_int_const
',' expr_int_const
')'
578 { expr_list_t
*list
= append_expr
( NULL
, $3 );
579 list
= append_expr
( list
, $5 );
580 $$
= make_attrp
(ATTR_RANGE
, list
); }
581 | tREADONLY
{ $$
= make_attr
(ATTR_READONLY
); }
582 | tREQUESTEDIT
{ $$
= make_attr
(ATTR_REQUESTEDIT
); }
583 | tRESTRICTED
{ $$
= make_attr
(ATTR_RESTRICTED
); }
584 | tRETVAL
{ $$
= make_attr
(ATTR_RETVAL
); }
585 | tSIZEIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_SIZEIS
, $3); }
586 | tSOURCE
{ $$
= make_attr
(ATTR_SOURCE
); }
587 | tSTRICTCONTEXTHANDLE
{ $$
= make_attr
(ATTR_STRICTCONTEXTHANDLE
); }
588 | tSTRING
{ $$
= make_attr
(ATTR_STRING
); }
589 | tSWITCHIS
'(' expr
')' { $$
= make_attrp
(ATTR_SWITCHIS
, $3); }
590 | tSWITCHTYPE
'(' type
')' { $$
= make_attrp
(ATTR_SWITCHTYPE
, $3); }
591 | tTRANSMITAS
'(' type
')' { $$
= make_attrp
(ATTR_TRANSMITAS
, $3); }
592 | tUUID
'(' uuid_string
')' { $$
= make_attrp
(ATTR_UUID
, $3); }
593 | tV1ENUM
{ $$
= make_attr
(ATTR_V1ENUM
); }
594 | tVARARG
{ $$
= make_attr
(ATTR_VARARG
); }
595 | tVERSION
'(' version
')' { $$
= make_attrv
(ATTR_VERSION
, $3); }
596 | tWIREMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_WIREMARSHAL
, $3); }
597 | pointer_type
{ $$
= make_attrv
(ATTR_POINTERTYPE
, $1); }
602 | aSTRING
{ if
(!is_valid_uuid
($1))
603 error_loc
("invalid UUID: %s\n", $1);
604 $$
= parse_uuid
($1); }
607 callconv: tCDECL
{ $$
= $
<str
>1; }
608 | tFASTCALL
{ $$
= $
<str
>1; }
609 | tPASCAL
{ $$
= $
<str
>1; }
610 | tSTDCALL
{ $$
= $
<str
>1; }
613 cases: { $$
= NULL
; }
614 | cases case
{ $$
= append_var
( $1, $2 ); }
617 case: tCASE expr_int_const
':' union_field
{ attr_t
*a
= make_attrp
(ATTR_CASE
, append_expr
( NULL
, $2 ));
618 $$
= $4; if
(!$$
) $$
= make_var
(NULL
);
619 $$
->attrs
= append_attr
( $$
->attrs
, a
);
621 | tDEFAULT
':' union_field
{ attr_t
*a
= make_attr
(ATTR_DEFAULT
);
622 $$
= $3; if
(!$$
) $$
= make_var
(NULL
);
623 $$
->attrs
= append_attr
( $$
->attrs
, a
);
627 enums: { $$
= NULL
; }
628 | enum_list
',' { $$
= $1; }
632 enum_list: enum { if
(!$1->eval
)
633 $1->eval
= make_exprl
(EXPR_NUM
, 0 /* default for first enum entry */);
634 $$
= append_var
( NULL
, $1 );
636 | enum_list
',' enum { if
(!$3->eval
)
638 var_t
*last
= LIST_ENTRY
( list_tail
($$
), var_t
, entry
);
639 $3->eval
= make_exprl
(EXPR_NUM
, last
->eval
->cval
+ 1);
641 $$
= append_var
( $1, $3 );
645 enum: ident
'=' expr_int_const
{ $$
= reg_const
($1);
647 $$
->type
= make_int
(0);
649 | ident
{ $$
= reg_const
($1);
650 $$
->type
= make_int
(0);
654 enumdef: tENUM t_ident
'{' enums
'}' { $$
= make_enum_type
($2, $4);
656 add_typelib_entry
($$
);
660 m_exprs: m_expr
{ $$
= append_expr
( NULL
, $1 ); }
661 | m_exprs
',' m_expr
{ $$
= append_expr
( $1, $3 ); }
665 exprs: { $$ = make_expr(EXPR_VOID); }
670 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
674 m_expr: { $$
= make_expr
(EXPR_VOID
); }
678 expr: aNUM
{ $$
= make_exprl
(EXPR_NUM
, $1); }
679 | aHEXNUM
{ $$
= make_exprl
(EXPR_HEXNUM
, $1); }
680 | aDOUBLE
{ $$
= make_exprd
(EXPR_DOUBLE
, $1); }
681 | tFALSE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 0); }
682 | tNULL
{ $$
= make_exprl
(EXPR_NUM
, 0); }
683 | tTRUE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 1); }
684 | aSTRING
{ $$
= make_exprs
(EXPR_STRLIT
, $1); }
685 | aWSTRING
{ $$
= make_exprs
(EXPR_WSTRLIT
, $1); }
686 | aIDENTIFIER
{ $$
= make_exprs
(EXPR_IDENTIFIER
, $1); }
687 | expr
'?' expr
':' expr
{ $$
= make_expr3
(EXPR_COND
, $1, $3, $5); }
688 | expr LOGICALOR expr
{ $$
= make_expr2
(EXPR_LOGOR
, $1, $3); }
689 | expr LOGICALAND expr
{ $$
= make_expr2
(EXPR_LOGAND
, $1, $3); }
690 | expr
'|' expr
{ $$
= make_expr2
(EXPR_OR
, $1, $3); }
691 | expr
'^' expr
{ $$
= make_expr2
(EXPR_XOR
, $1, $3); }
692 | expr
'&' expr
{ $$
= make_expr2
(EXPR_AND
, $1, $3); }
693 | expr EQUALITY expr
{ $$
= make_expr2
(EXPR_EQUALITY
, $1, $3); }
694 | expr INEQUALITY expr
{ $$
= make_expr2
(EXPR_INEQUALITY
, $1, $3); }
695 | expr
'>' expr
{ $$
= make_expr2
(EXPR_GTR
, $1, $3); }
696 | expr
'<' expr
{ $$
= make_expr2
(EXPR_LESS
, $1, $3); }
697 | expr GREATEREQUAL expr
{ $$
= make_expr2
(EXPR_GTREQL
, $1, $3); }
698 | expr LESSEQUAL expr
{ $$
= make_expr2
(EXPR_LESSEQL
, $1, $3); }
699 | expr SHL expr
{ $$
= make_expr2
(EXPR_SHL
, $1, $3); }
700 | expr SHR expr
{ $$
= make_expr2
(EXPR_SHR
, $1, $3); }
701 | expr
'+' expr
{ $$
= make_expr2
(EXPR_ADD
, $1, $3); }
702 | expr
'-' expr
{ $$
= make_expr2
(EXPR_SUB
, $1, $3); }
703 | expr
'%' expr
{ $$
= make_expr2
(EXPR_MOD
, $1, $3); }
704 | expr
'*' expr
{ $$
= make_expr2
(EXPR_MUL
, $1, $3); }
705 | expr
'/' expr
{ $$
= make_expr2
(EXPR_DIV
, $1, $3); }
706 |
'!' expr
{ $$
= make_expr1
(EXPR_LOGNOT
, $2); }
707 |
'~' expr
{ $$
= make_expr1
(EXPR_NOT
, $2); }
708 |
'+' expr %prec POS
{ $$
= make_expr1
(EXPR_POS
, $2); }
709 |
'-' expr %prec NEG
{ $$
= make_expr1
(EXPR_NEG
, $2); }
710 |
'&' expr %prec ADDRESSOF
{ $$
= make_expr1
(EXPR_ADDRESSOF
, $2); }
711 |
'*' expr %prec PPTR
{ $$
= make_expr1
(EXPR_PPTR
, $2); }
712 | expr MEMBERPTR aIDENTIFIER
{ $$
= make_expr2
(EXPR_MEMBER
, make_expr1
(EXPR_PPTR
, $1), make_exprs
(EXPR_IDENTIFIER
, $3)); }
713 | expr
'.' aIDENTIFIER
{ $$
= make_expr2
(EXPR_MEMBER
, $1, make_exprs
(EXPR_IDENTIFIER
, $3)); }
714 |
'(' type
')' expr %prec CAST
{ $$
= make_exprt
(EXPR_CAST
, $2, $4); }
715 | tSIZEOF
'(' type
')' { $$
= make_exprt
(EXPR_SIZEOF
, $3, NULL
); }
716 | expr
'[' expr
']' { $$
= make_expr2
(EXPR_ARRAY
, $1, $3); }
717 |
'(' expr
')' { $$
= $2; }
720 expr_list_int_const: expr_int_const
{ $$
= append_expr
( NULL
, $1 ); }
721 | expr_list_int_const
',' expr_int_const
{ $$
= append_expr
( $1, $3 ); }
724 expr_int_const: expr
{ $$
= $1;
726 error_loc
("expression is not an integer constant\n");
730 expr_const: expr
{ $$
= $1;
731 if
(!$$
->is_const
&& $$
->type
!= EXPR_STRLIT
&& $$
->type
!= EXPR_WSTRLIT
)
732 error_loc
("expression is not constant\n");
736 fields: { $$
= NULL
; }
737 | fields field
{ $$
= append_var_list
($1, $2); }
740 field: m_attributes decl_spec declarator_list
';'
741 { const char *first
= LIST_ENTRY
(list_head
($3), declarator_t
, entry
)->var
->name
;
742 check_field_attrs
(first
, $1);
743 $$
= set_var_types
($1, $2, $3);
745 | m_attributes uniondef
';' { var_t
*v
= make_var
(NULL
);
746 v
->type
= $2; v
->attrs
= $1;
747 $$
= append_var
(NULL
, v
);
752 s_field
';' { $$
= $1; }
753 | attributes
';' { $$
= make_var
(NULL
); $$
->attrs
= $1; }
756 ne_union_fields: { $$
= NULL
; }
757 | ne_union_fields ne_union_field
{ $$
= append_var
( $1, $2 ); }
761 s_field
';' { $$
= $1; }
765 s_field: m_attributes decl_spec declarator
{ $$
= $3->var
;
766 $$
->attrs
= check_field_attrs
($$
->name
, $1);
767 set_type
($$
, $2, $3, FALSE
);
773 m_attributes decl_spec declarator
{ var_t
*v
= $3->var
;
774 v
->attrs
= check_function_attrs
(v
->name
, $1);
775 set_type
(v
, $2, $3, FALSE
);
782 attributes decl_spec init_declarator
785 set_type
($$
, $2, $3, FALSE
);
788 | decl_spec init_declarator
{ $$
= $2->var
;
789 set_type
($$
, $1, $2, FALSE
);
794 m_ident: { $$
= NULL
; }
798 t_ident: { $$
= NULL
; }
799 | aIDENTIFIER
{ $$
= $1; }
800 | aKNOWNTYPE
{ $$
= $1; }
803 ident: aIDENTIFIER
{ $$
= make_var
($1); }
804 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
805 | aKNOWNTYPE
{ $$
= make_var
($
<str
>1); }
808 base_type: tBYTE
{ $$
= make_builtin
($
<str
>1); }
809 | tWCHAR
{ $$
= make_builtin
($
<str
>1); }
811 | tSIGNED int_std
{ $$
= $2; $$
->sign
= 1; }
812 | tUNSIGNED int_std
{ $$
= $2; $$
->sign
= -1;
814 case RPC_FC_CHAR
: break
;
815 case RPC_FC_SMALL
: $$
->type
= RPC_FC_USMALL
; break
;
816 case RPC_FC_SHORT
: $$
->type
= RPC_FC_USHORT
; break
;
817 case RPC_FC_LONG
: $$
->type
= RPC_FC_ULONG
; break
;
819 if
($$
->name
[0] == 'h') /* hyper, as opposed to __int64 */
821 $$
= alias
($$
, "MIDL_uhyper");
828 | tUNSIGNED
{ $$
= make_int
(-1); }
829 | tFLOAT
{ $$
= make_builtin
($
<str
>1); }
830 | tSINGLE
{ $$
= duptype
(find_type
("float", 0), 1); }
831 | tDOUBLE
{ $$
= make_builtin
($
<str
>1); }
832 | tBOOLEAN
{ $$
= make_builtin
($
<str
>1); }
833 | tERRORSTATUST
{ $$
= make_builtin
($
<str
>1); }
834 | tHANDLET
{ $$
= make_builtin
($
<str
>1); }
841 int_std: tINT
{ $$
= make_builtin
($
<str
>1); }
842 | tSHORT m_int
{ $$
= make_builtin
($
<str
>1); }
843 | tSMALL
{ $$
= make_builtin
($
<str
>1); }
844 | tLONG m_int
{ $$
= make_builtin
($
<str
>1); }
845 | tHYPER m_int
{ $$
= make_builtin
($
<str
>1); }
846 | tINT64
{ $$
= make_builtin
($
<str
>1); }
847 | tCHAR
{ $$
= make_builtin
($
<str
>1); }
850 coclass: tCOCLASS aIDENTIFIER
{ $$
= make_class
($2); }
851 | tCOCLASS aKNOWNTYPE
{ $$
= find_type
($2, 0);
852 if
($$
->defined
) error_loc
("multiple definition error\n");
853 if
($$
->kind
!= TKIND_COCLASS
) error_loc
("%s was not declared a coclass\n", $2);
857 coclasshdr: attributes coclass
{ $$
= $2;
858 $$
->attrs
= check_coclass_attrs
($2->name
, $1);
859 if
(!parse_only
&& do_header
)
861 if
(!parse_only
&& do_idfile
)
866 coclassdef: coclasshdr
'{' coclass_ints
'}' semicolon_opt
873 coclass_ints: { $$
= NULL
; }
874 | coclass_ints coclass_int
{ $$
= append_ifref
( $1, $2 ); }
878 m_attributes interfacedec
{ $$
= make_ifref
($2); $$
->attrs
= $1; }
881 dispinterface: tDISPINTERFACE aIDENTIFIER
{ $$
= get_type
(RPC_FC_IP
, $2, 0); $$
->kind
= TKIND_DISPATCH
; }
882 | tDISPINTERFACE aKNOWNTYPE
{ $$
= get_type
(RPC_FC_IP
, $2, 0); $$
->kind
= TKIND_DISPATCH
; }
885 dispinterfacehdr: attributes dispinterface
{ attr_t
*attrs
;
886 is_in_interface
= TRUE
;
887 is_object_interface
= TRUE
;
889 attrs
= make_attr
(ATTR_DISPINTERFACE
);
890 $$
->attrs
= append_attr
( check_dispiface_attrs
($2->name
, $1), attrs
);
892 if
(!parse_only
&& do_header
) write_forward
($$
);
896 dispint_props: tPROPERTIES
':' { $$
= NULL
; }
897 | dispint_props s_field
';' { $$
= append_var
( $1, $2 ); }
900 dispint_meths: tMETHODS
':' { $$
= NULL
; }
901 | dispint_meths funcdef
';' { $$
= append_func
( $1, $2 ); }
904 dispinterfacedef: dispinterfacehdr
'{'
908 define_dispinterface_type
($$
, $3, $4);
909 if
(!parse_only
&& do_header
) write_interface
($$
);
910 if
(!parse_only
&& do_idfile
) write_diid
($$
);
911 is_in_interface
= FALSE
;
914 '{' interface
';' '}' { $$
= $1;
915 define_dispinterface_type
($$
, $3->details.iface
->disp_props
, $3->details.iface
->disp_methods
);
916 if
(!parse_only
&& do_header
) write_interface
($$
);
917 if
(!parse_only
&& do_idfile
) write_diid
($$
);
918 is_in_interface
= FALSE
;
922 inherit: { $$
= NULL
; }
923 |
':' aKNOWNTYPE
{ $$
= find_type_or_error2
($2, 0); }
926 interface: tINTERFACE aIDENTIFIER
{ $$
= get_type
(RPC_FC_IP
, $2, 0); $$
->kind
= TKIND_INTERFACE
; }
927 | tINTERFACE aKNOWNTYPE
{ $$
= get_type
(RPC_FC_IP
, $2, 0); $$
->kind
= TKIND_INTERFACE
; }
930 interfacehdr: attributes interface
{ $$.interface
= $2;
931 $$.old_pointer_default
= pointer_default
;
932 if
(is_attr
($1, ATTR_POINTERDEFAULT
))
933 pointer_default
= get_attrv
($1, ATTR_POINTERDEFAULT
);
934 is_object_interface
= is_object
($1);
935 is_in_interface
= TRUE
;
936 $2->attrs
= check_iface_attrs
($2->name
, $1);
938 if
(!parse_only
&& do_header
) write_forward
($2);
942 interfacedef: interfacehdr inherit
943 '{' int_statements
'}' semicolon_opt
{ $$
= $1.interface
;
944 define_interface_type
($$
, $2, $4);
945 if
(!parse_only
&& do_header
) write_interface
($$
);
946 if
(!parse_only
&& local_stubs
) write_locals
(local_stubs
, $$
, TRUE
);
947 if
(!parse_only
&& do_idfile
) write_iid
($$
);
948 pointer_default
= $1.old_pointer_default
;
949 is_in_interface
= FALSE
;
951 /* MIDL is able to import the definition of a base class from inside the
952 * definition of a derived class, I'll try to support it with this rule */
953 | interfacehdr
':' aIDENTIFIER
954 '{' import int_statements
'}'
955 semicolon_opt
{ type_t
*inherit
;
957 inherit
= find_type_or_error2
($3, 0);
958 if
(!inherit
) error_loc
("base class '%s' not found in import\n", $3);
959 define_interface_type
($$
, inherit
, $6);
960 if
(!parse_only
&& do_header
) write_interface
($$
);
961 if
(!parse_only
&& local_stubs
) write_locals
(local_stubs
, $$
, TRUE
);
962 if
(!parse_only
&& do_idfile
) write_iid
($$
);
963 pointer_default
= $1.old_pointer_default
;
964 is_in_interface
= FALSE
;
966 | dispinterfacedef semicolon_opt
{ $$
= $1; }
970 interface
';' { $$
= $1; if
(!parse_only
&& do_header
) write_forward
($$
); }
971 | dispinterface
';' { $$
= $1; if
(!parse_only
&& do_header
) write_forward
($$
); }
974 module: tMODULE aIDENTIFIER
{ $$
= make_type
(0, NULL
); $$
->name
= $2; $$
->kind
= TKIND_MODULE
; }
975 | tMODULE aKNOWNTYPE
{ $$
= make_type
(0, NULL
); $$
->name
= $2; $$
->kind
= TKIND_MODULE
; }
978 modulehdr: attributes module
{ $$
= $2;
979 $$
->attrs
= check_module_attrs
($2->name
, $1);
983 moduledef: modulehdr
'{' int_statements
'}'
984 semicolon_opt
{ $$
= $1;
986 /* FIXME: if (!parse_only && do_header) write_module($$); */
991 tEXTERN
{ $$
= STG_EXTERN
; }
992 | tSTATIC
{ $$
= STG_STATIC
; }
993 | tREGISTER
{ $$
= STG_REGISTER
; }
997 tINLINE
{ $$
= make_attr
(ATTR_INLINE
); }
1001 tCONST
{ $$
= make_attr
(ATTR_CONST
); }
1004 m_type_qual_list: { $$
= NULL
; }
1005 | m_type_qual_list type_qualifier
{ $$
= append_attr
($1, $2); }
1008 decl_spec: type m_decl_spec_no_type
{ $$
= make_decl_spec
($1, $2, NULL
, NULL
, STG_NONE
); }
1009 | decl_spec_no_type type m_decl_spec_no_type
1010 { $$
= make_decl_spec
($2, $1, $3, NULL
, STG_NONE
); }
1013 m_decl_spec_no_type: { $$
= NULL
; }
1018 type_qualifier m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, $1, STG_NONE
); }
1019 | function_specifier m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, $1, STG_NONE
); }
1020 | storage_cls_spec m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, NULL
, $1); }
1024 '*' m_type_qual_list declarator %prec PPTR
1025 { $$
= $3; $$
->type
= append_ptrchain_type
($$
->type
, make_pointer_type
(NULL
, $2)); }
1026 | callconv declarator
{ $$
= $2; $$
->type
->attrs
= append_attr
($$
->type
->attrs
, make_attrp
(ATTR_CALLCONV
, $1)); }
1031 ident
{ $$
= make_declarator
($1); }
1032 |
'(' declarator
')' { $$
= $2; }
1033 | direct_declarator array
{ $$
= $1; $$
->array
= append_array
($$
->array
, $2); }
1034 | direct_declarator
'(' m_args
')' { $$
= $1;
1035 $$
->func_type
= append_ptrchain_type
($$
->type
, make_func_type
($3));
1041 declarator
{ $$
= append_declarator
( NULL
, $1 ); }
1042 | declarator_list
',' declarator
{ $$
= append_declarator
( $1, $3 ); }
1046 declarator
{ $$
= $1; }
1047 | declarator
'=' expr_const
{ $$
= $1; $1->var
->eval
= $3; }
1051 tREF
{ $$
= RPC_FC_RP
; }
1052 | tUNIQUE
{ $$
= RPC_FC_UP
; }
1053 | tPTR
{ $$
= RPC_FC_FP
; }
1056 structdef: tSTRUCT t_ident
'{' fields
'}' { $$
= make_struct_type
($2, TRUE
, $4);
1058 add_typelib_entry
($$
);
1062 type: tVOID
{ $$
= duptype
(find_type_or_error
("void", 0), 1); }
1063 | aKNOWNTYPE
{ $$
= find_type_or_error
($1, 0); }
1064 | base_type
{ $$
= $1; }
1065 | enumdef
{ $$
= $1; }
1066 | tENUM aIDENTIFIER
{ $$
= find_type_or_error2
($2, tsENUM
); }
1067 | structdef
{ $$
= $1; }
1068 | tSTRUCT aIDENTIFIER
{ $$
= make_struct_type
($2, FALSE
, NULL
); }
1069 | uniondef
{ $$
= $1; }
1070 | tUNION aIDENTIFIER
{ $$
= find_type_or_error2
($2, tsUNION
); }
1071 | tSAFEARRAY
'(' type
')' { $$
= make_safearray
($3); }
1074 typedef: tTYPEDEF m_attributes decl_spec declarator_list
1075 { reg_typedefs
($3, $4, check_typedef_attrs
($2));
1076 $$
= process_typedefs
($4);
1080 uniondef: tUNION t_ident
'{' ne_union_fields
'}'
1081 { $$
= make_ne_union_type
($2, $4); }
1083 tSWITCH
'(' s_field
')'
1084 m_ident
'{' cases
'}' { $$
= make_e_union_type
($2, $5, $7, $9); }
1088 aNUM
{ $$
= MAKEVERSION
($1, 0); }
1089 | aNUM
'.' aNUM
{ $$
= MAKEVERSION
($1, $3); }
1094 static void decl_builtin
(const char *name
, unsigned char type
)
1096 type_t
*t
= make_type
(type
, NULL
);
1097 t
->name
= xstrdup
(name
);
1098 reg_type
(t
, name
, 0);
1101 static type_t
*make_builtin
(char *name
)
1103 /* NAME is strdup'd in the lexer */
1104 type_t
*t
= duptype
(find_type_or_error
(name
, 0), 0);
1109 static type_t
*make_int
(int sign
)
1111 type_t
*t
= duptype
(find_type_or_error
("int", 0), 1);
1115 t
->type
= t
->type
== RPC_FC_LONG ? RPC_FC_ULONG
: RPC_FC_USHORT
;
1120 void init_types
(void)
1122 decl_builtin
("void", 0);
1123 decl_builtin
("byte", RPC_FC_BYTE
);
1124 decl_builtin
("wchar_t", RPC_FC_WCHAR
);
1125 decl_builtin
("int", RPC_FC_LONG
); /* win32 */
1126 decl_builtin
("short", RPC_FC_SHORT
);
1127 decl_builtin
("small", RPC_FC_SMALL
);
1128 decl_builtin
("long", RPC_FC_LONG
);
1129 decl_builtin
("hyper", RPC_FC_HYPER
);
1130 decl_builtin
("__int64", RPC_FC_HYPER
);
1131 decl_builtin
("char", RPC_FC_CHAR
);
1132 decl_builtin
("float", RPC_FC_FLOAT
);
1133 decl_builtin
("double", RPC_FC_DOUBLE
);
1134 decl_builtin
("boolean", RPC_FC_BYTE
);
1135 decl_builtin
("error_status_t", RPC_FC_ERROR_STATUS_T
);
1136 decl_builtin
("handle_t", RPC_FC_BIND_PRIMITIVE
);
1139 static str_list_t
*append_str
(str_list_t
*list
, char *str
)
1141 struct str_list_entry_t
*entry
;
1143 if
(!str
) return list
;
1146 list
= xmalloc
( sizeof
(*list
) );
1149 entry
= xmalloc
( sizeof
(*entry
) );
1151 list_add_tail
( list
, &entry
->entry
);
1155 static attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
)
1157 attr_t
*attr_existing
;
1158 if
(!attr
) return list
;
1161 list
= xmalloc
( sizeof
(*list
) );
1164 LIST_FOR_EACH_ENTRY
(attr_existing
, list
, attr_t
, entry
)
1165 if
(attr_existing
->type
== attr
->type
)
1167 parser_warning
("duplicate attribute %s\n", get_attr_display_name
(attr
->type
));
1168 /* use the last attribute, like MIDL does */
1169 list_remove
(&attr_existing
->entry
);
1172 list_add_tail
( list
, &attr
->entry
);
1176 static attr_list_t
*move_attr
(attr_list_t
*dst
, attr_list_t
*src
, enum attr_type type
)
1179 if
(!src
) return dst
;
1180 LIST_FOR_EACH_ENTRY
(attr
, src
, attr_t
, entry
)
1181 if
(attr
->type
== type
)
1183 list_remove
(&attr
->entry
);
1184 return append_attr
(dst
, attr
);
1189 static attr_list_t
*append_attr_list
(attr_list_t
*new_list
, attr_list_t
*old_list
)
1193 if
(!old_list
) return new_list
;
1195 while
((entry
= list_head
(old_list
)))
1197 attr_t
*attr
= LIST_ENTRY
(entry
, attr_t
, entry
);
1199 new_list
= append_attr
(new_list
, attr
);
1204 static attr_list_t
*dupattrs
(const attr_list_t
*list
)
1206 attr_list_t
*new_list
;
1209 if
(!list
) return NULL
;
1211 new_list
= xmalloc
( sizeof
(*list
) );
1212 list_init
( new_list
);
1213 LIST_FOR_EACH_ENTRY
(attr
, list
, const attr_t
, entry
)
1215 attr_t
*new_attr
= xmalloc
(sizeof
(*new_attr
));
1217 list_add_tail
(new_list
, &new_attr
->entry
);
1222 static decl_spec_t
*make_decl_spec
(type_t
*type
, decl_spec_t
*left
, decl_spec_t
*right
, attr_t
*attr
, enum storage_class stgclass
)
1224 decl_spec_t
*declspec
= left ? left
: right
;
1227 declspec
= xmalloc
(sizeof
(*declspec
));
1228 declspec
->type
= NULL
;
1229 declspec
->attrs
= NULL
;
1230 declspec
->stgclass
= STG_NONE
;
1232 declspec
->type
= type
;
1233 if
(left
&& declspec
!= left
)
1235 declspec
->attrs
= append_attr_list
(declspec
->attrs
, left
->attrs
);
1236 if
(declspec
->stgclass
== STG_NONE
)
1237 declspec
->stgclass
= left
->stgclass
;
1238 else if
(left
->stgclass
!= STG_NONE
)
1239 error_loc
("only one storage class can be specified\n");
1240 assert
(!left
->type
);
1243 if
(right
&& declspec
!= right
)
1245 declspec
->attrs
= append_attr_list
(declspec
->attrs
, right
->attrs
);
1246 if
(declspec
->stgclass
== STG_NONE
)
1247 declspec
->stgclass
= right
->stgclass
;
1248 else if
(right
->stgclass
!= STG_NONE
)
1249 error_loc
("only one storage class can be specified\n");
1250 assert
(!right
->type
);
1254 declspec
->attrs
= append_attr
(declspec
->attrs
, attr
);
1255 if
(declspec
->stgclass
== STG_NONE
)
1256 declspec
->stgclass
= stgclass
;
1257 else if
(stgclass
!= STG_NONE
)
1258 error_loc
("only one storage class can be specified\n");
1260 /* apply attributes to type */
1261 if
(type
&& declspec
->attrs
)
1264 declspec
->type
= duptype
(type
, 1);
1265 attrs
= dupattrs
(type
->attrs
);
1266 declspec
->type
->attrs
= append_attr_list
(attrs
, declspec
->attrs
);
1267 declspec
->attrs
= NULL
;
1273 static attr_t
*make_attr
(enum attr_type type
)
1275 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1281 static attr_t
*make_attrv
(enum attr_type type
, unsigned long val
)
1283 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1289 static attr_t
*make_attrp
(enum attr_type type
, void *val
)
1291 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1297 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
)
1299 if
(!expr
) return list
;
1302 list
= xmalloc
( sizeof
(*list
) );
1305 list_add_tail
( list
, &expr
->entry
);
1309 static array_dims_t
*append_array
(array_dims_t
*list
, expr_t
*expr
)
1311 if
(!expr
) return list
;
1314 list
= xmalloc
( sizeof
(*list
) );
1317 list_add_tail
( list
, &expr
->entry
);
1321 static struct list type_pool
= LIST_INIT
(type_pool
);
1328 type_t
*alloc_type
(void)
1330 type_pool_node_t
*node
= xmalloc
(sizeof
*node
);
1331 list_add_tail
(&type_pool
, &node
->link
);
1335 void set_all_tfswrite
(int val
)
1337 type_pool_node_t
*node
;
1338 LIST_FOR_EACH_ENTRY
(node
, &type_pool
, type_pool_node_t
, link
)
1339 node
->data.tfswrite
= val
;
1342 type_t
*make_type
(unsigned char type
, type_t
*ref
)
1344 type_t
*t
= alloc_type
();
1346 t
->kind
= TKIND_PRIMITIVE
;
1352 memset
(&t
->details
, 0, sizeof
(t
->details
));
1356 t
->length_is
= NULL
;
1357 t
->typestring_offset
= 0;
1359 t
->declarray
= FALSE
;
1360 t
->ignore
= (parse_only
!= 0);
1364 t
->user_types_registered
= FALSE
;
1365 t
->tfswrite
= FALSE
;
1367 t
->typelib_idx
= -1;
1371 static type_t
*make_func_type
(var_list_t
*args
)
1373 type_t
*t
= make_type
(RPC_FC_FUNCTION
, NULL
);
1374 t
->details.function
= xmalloc
(sizeof
(*t
->details.function
));
1375 t
->details.function
->args
= args
;
1379 static type_t
*make_pointer_type
(type_t
*ref
, attr_list_t
*attrs
)
1381 type_t
*t
= make_type
(pointer_default
, ref
);
1386 static type_t
*make_enum_type
(char *name
, var_list_t
*enums
)
1388 type_t
*t
= get_type
(RPC_FC_ENUM16
, name
, tsENUM
);
1389 t
->kind
= TKIND_ENUM
;
1392 t
->details.enumeration
= xmalloc
(sizeof
(*t
->details.enumeration
));
1393 t
->details.enumeration
->enums
= enums
;
1396 t
->details.enumeration
= NULL
;
1401 static type_t
*make_struct_type
(char *name
, int defined
, var_list_t
*fields
)
1403 type_t
*tag_type
= name ? find_type
(name
, tsSTRUCT
) : NULL
;
1404 type_t
*t
= make_type
(get_struct_type
(fields
), NULL
);
1406 t
->kind
= TKIND_RECORD
;
1407 if
(defined ||
(tag_type
&& tag_type
->details.structure
))
1409 if
(tag_type
&& tag_type
->details.structure
)
1411 t
->details.structure
= tag_type
->details.structure
;
1412 t
->type
= tag_type
->type
;
1416 t
->details.structure
= xmalloc
(sizeof
(*t
->details.structure
));
1417 t
->details.structure
->fields
= fields
;
1424 reg_type
(t
, name
, tsSTRUCT
);
1431 static type_t
*make_ne_union_type
(char *name
, var_list_t
*fields
)
1433 type_t
*t
= get_type
(RPC_FC_NON_ENCAPSULATED_UNION
, name
, tsUNION
);
1434 t
->kind
= TKIND_UNION
;
1435 t
->details.structure
= xmalloc
(sizeof
(*t
->details.structure
));
1436 t
->details.structure
->fields
= fields
;
1441 static type_t
*make_e_union_type
(char *name
, var_t
*switch_field
, var_t
*union_field
, var_list_t
*cases
)
1443 type_t
*t
= get_type
(RPC_FC_ENCAPSULATED_UNION
, name
, tsUNION
);
1444 t
->kind
= TKIND_UNION
;
1445 if
(!union_field
) union_field
= make_var
( xstrdup
("tagged_union") );
1446 union_field
->type
= make_type
(RPC_FC_NON_ENCAPSULATED_UNION
, NULL
);
1447 union_field
->type
->kind
= TKIND_UNION
;
1448 union_field
->type
->details.structure
= xmalloc
(sizeof
(*union_field
->type
->details.structure
));
1449 union_field
->type
->details.structure
->fields
= cases
;
1450 union_field
->type
->defined
= TRUE
;
1451 t
->details.structure
= xmalloc
(sizeof
(*t
->details.structure
));
1452 t
->details.structure
->fields
= append_var
( NULL
, switch_field
);
1453 t
->details.structure
->fields
= append_var
( t
->details.structure
->fields
, union_field
);
1458 static void define_interface_type
(type_t
*iface
, type_t
*inherit
, func_list_t
*funcs
)
1460 if
(iface
->details.iface
) error_loc
("multiple definition error\n");
1461 iface
->ref
= inherit
;
1462 iface
->details.iface
= xmalloc
(sizeof
(*iface
->details.iface
));
1463 iface
->funcs
= funcs
;
1464 iface
->details.iface
->disp_props
= NULL
;
1465 iface
->details.iface
->disp_methods
= NULL
;
1466 iface
->defined
= TRUE
;
1467 check_functions
(iface
);
1468 compute_method_indexes
(iface
);
1471 static void define_dispinterface_type
(type_t
*iface
, var_list_t
*props
, func_list_t
*methods
)
1473 if
(iface
->details.iface
) error_loc
("multiple definition error\n");
1474 iface
->ref
= find_type
("IDispatch", 0);
1475 if
(!iface
->ref
) error_loc
("IDispatch is undefined\n");
1476 iface
->details.iface
= xmalloc
(sizeof
(*iface
->details.iface
));
1477 iface
->funcs
= NULL
;
1478 iface
->details.iface
->disp_props
= props
;
1479 iface
->details.iface
->disp_methods
= methods
;
1480 iface
->defined
= TRUE
;
1481 check_functions
(iface
);
1482 compute_method_indexes
(iface
);
1485 static type_t
*append_ptrchain_type
(type_t
*ptrchain
, type_t
*type
)
1487 type_t
*ptrchain_type
;
1490 for
(ptrchain_type
= ptrchain
; ptrchain_type
->ref
; ptrchain_type
= ptrchain_type
->ref
)
1492 ptrchain_type
->ref
= type
;
1496 static void set_type
(var_t
*v
, decl_spec_t
*decl_spec
, const declarator_t
*decl
,
1499 expr_list_t
*sizes
= get_attrp
(v
->attrs
, ATTR_SIZEIS
);
1500 expr_list_t
*lengs
= get_attrp
(v
->attrs
, ATTR_LENGTHIS
);
1501 int ptr_attr
= get_attrv
(v
->attrs
, ATTR_POINTERTYPE
);
1502 int sizeless
, has_varconf
;
1504 type_t
*atype
, **ptype
;
1505 array_dims_t
*arr
= decl ? decl
->array
: NULL
;
1506 type_t
*func_type
= decl ? decl
->func_type
: NULL
;
1507 type_t
*type
= decl_spec
->type
;
1509 if
(is_attr
(type
->attrs
, ATTR_INLINE
))
1512 error_loc
("inline attribute applied to non-function type\n");
1516 /* move inline attribute from return type node to function node */
1517 for
(t
= func_type
; is_ptr
(t
); t
= t
->ref
)
1519 t
->attrs
= move_attr
(t
->attrs
, type
->attrs
, ATTR_INLINE
);
1523 /* add type onto the end of the pointers in pident->type */
1524 v
->type
= append_ptrchain_type
(decl ? decl
->type
: NULL
, type
);
1525 v
->stgclass
= decl_spec
->stgclass
;
1527 /* the highest level of pointer specified should default to the var's ptr attr
1528 * or (RPC_FC_RP if not specified and it's a top level ptr), not
1529 * pointer_default so we need to fix that up here */
1532 const type_t
*ptr
= NULL
;
1533 /* pointer attributes on the left side of the type belong to the function
1534 * pointer, if one is being declared */
1535 type_t
**pt
= func_type ?
&func_type
: &v
->type
;
1536 for
(ptr
= *pt
; ptr
; )
1538 if
(ptr
->kind
== TKIND_ALIAS
)
1543 if
(ptr
&& is_ptr
(ptr
) && (ptr_attr || top
))
1545 /* duplicate type to avoid changing original type */
1546 *pt
= duptype
(*pt
, 1);
1547 (*pt
)->type
= ptr_attr ? ptr_attr
: RPC_FC_RP
;
1550 error_loc
("%s: pointer attribute applied to non-pointer type\n", v
->name
);
1553 if
(is_attr
(v
->attrs
, ATTR_STRING
) && !is_ptr
(v
->type
) && !arr
)
1554 error_loc
("'%s': [string] attribute applied to non-pointer, non-array type\n",
1557 if
(is_attr
(v
->attrs
, ATTR_V1ENUM
))
1559 if
(v
->type
->type
== RPC_FC_ENUM16
)
1560 v
->type
->type
= RPC_FC_ENUM32
;
1562 error_loc
("'%s': [v1_enum] attribute applied to non-enum type\n", v
->name
);
1566 if
(arr
) LIST_FOR_EACH_ENTRY_REV
(dim
, arr
, expr_t
, entry
)
1569 error_loc
("%s: only the first array dimension can be unspecified\n", v
->name
);
1573 unsigned int align
= 0;
1574 size_t size
= type_memsize
(v
->type
, &align
);
1577 error_loc
("%s: array dimension must be positive\n", v
->name
);
1579 if
(0xffffffffuL
/ size
< (unsigned long) dim
->cval
)
1580 error_loc
("%s: total array size is too large\n", v
->name
);
1581 else if
(0xffffuL
< size
* dim
->cval
)
1582 v
->type
= make_type
(RPC_FC_LGFARRAY
, v
->type
);
1584 v
->type
= make_type
(RPC_FC_SMFARRAY
, v
->type
);
1589 v
->type
= make_type
(RPC_FC_CARRAY
, v
->type
);
1592 v
->type
->declarray
= TRUE
;
1593 v
->type
->dim
= dim
->cval
;
1597 has_varconf
= FALSE
;
1598 if
(sizes
) LIST_FOR_EACH_ENTRY
(dim
, sizes
, expr_t
, entry
)
1600 if
(dim
->type
!= EXPR_VOID
)
1603 atype
= *ptype
= duptype
(*ptype
, 0);
1605 if
(atype
->type
== RPC_FC_SMFARRAY || atype
->type
== RPC_FC_LGFARRAY
)
1606 error_loc
("%s: cannot specify size_is for a fixed sized array\n", v
->name
);
1608 if
(atype
->type
!= RPC_FC_CARRAY
&& !is_ptr
(atype
))
1609 error_loc
("%s: size_is attribute applied to illegal type\n", v
->name
);
1611 atype
->type
= RPC_FC_CARRAY
;
1612 atype
->size_is
= dim
;
1615 ptype
= &(*ptype
)->ref
;
1617 error_loc
("%s: too many expressions in size_is attribute\n", v
->name
);
1621 if
(lengs
) LIST_FOR_EACH_ENTRY
(dim
, lengs
, expr_t
, entry
)
1623 if
(dim
->type
!= EXPR_VOID
)
1626 atype
= *ptype
= duptype
(*ptype
, 0);
1628 if
(atype
->type
== RPC_FC_SMFARRAY
)
1629 atype
->type
= RPC_FC_SMVARRAY
;
1630 else if
(atype
->type
== RPC_FC_LGFARRAY
)
1631 atype
->type
= RPC_FC_LGVARRAY
;
1632 else if
(atype
->type
== RPC_FC_CARRAY
)
1633 atype
->type
= RPC_FC_CVARRAY
;
1635 error_loc
("%s: length_is attribute applied to illegal type\n", v
->name
);
1637 atype
->length_is
= dim
;
1640 ptype
= &(*ptype
)->ref
;
1642 error_loc
("%s: too many expressions in length_is attribute\n", v
->name
);
1645 if
(has_varconf
&& !last_array
(v
->type
))
1648 for
(ptype
= &v
->type
; is_array
(*ptype
); ptype
= &(*ptype
)->ref
)
1650 *ptype
= duptype
(*ptype
, 0);
1651 (*ptype
)->type
= RPC_FC_BOGUS_ARRAY
;
1655 if
(is_array
(v
->type
))
1657 const type_t
*rt
= v
->type
->ref
;
1658 if
(is_user_type
(rt
))
1659 v
->type
->type
= RPC_FC_BOGUS_ARRAY
;
1663 case RPC_FC_BOGUS_STRUCT
:
1664 case RPC_FC_NON_ENCAPSULATED_UNION
:
1665 case RPC_FC_ENCAPSULATED_UNION
:
1667 v
->type
->type
= RPC_FC_BOGUS_ARRAY
;
1669 /* FC_RP should be above, but widl overuses these, and will break things. */
1672 if
(rt
->ref
->type
== RPC_FC_IP
)
1673 v
->type
->type
= RPC_FC_BOGUS_ARRAY
;
1678 /* v->type is currently pointing to the type on the left-side of the
1679 * declaration, so we need to fix this up so that it is the return type of the
1680 * function and make v->type point to the function side of the declaration */
1684 type_t
*return_type
= v
->type
;
1685 v
->type
= func_type
;
1686 for
(ft
= v
->type
; is_ptr
(ft
); ft
= ft
->ref
)
1688 assert
(ft
->type
== RPC_FC_FUNCTION
);
1689 ft
->ref
= return_type
;
1690 /* move calling convention attribute, if present, from pointer nodes to
1692 for
(t
= v
->type
; is_ptr
(t
); t
= t
->ref
)
1693 ft
->attrs
= move_attr
(ft
->attrs
, t
->attrs
, ATTR_CALLCONV
);
1694 if
(is_object_interface
&& !is_attr
(ft
->attrs
, ATTR_CALLCONV
))
1696 static char *stdmethodcalltype
;
1697 if
(!stdmethodcalltype
) stdmethodcalltype
= strdup
("STDMETHODCALLTYPE");
1698 ft
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, stdmethodcalltype
));
1704 for
(t
= v
->type
; is_ptr
(t
); t
= t
->ref
)
1705 if
(is_attr
(t
->attrs
, ATTR_CALLCONV
))
1706 error_loc
("calling convention applied to non-function-pointer type\n");
1710 static var_list_t
*set_var_types
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_list_t
*decls
)
1712 declarator_t
*decl
, *next
;
1713 var_list_t
*var_list
= NULL
;
1715 LIST_FOR_EACH_ENTRY_SAFE
( decl
, next
, decls
, declarator_t
, entry
)
1717 var_t
*var
= decl
->var
;
1720 set_type
(var
, decl_spec
, decl
, 0);
1721 var_list
= append_var
(var_list
, var
);
1727 static ifref_list_t
*append_ifref
(ifref_list_t
*list
, ifref_t
*iface
)
1729 if
(!iface
) return list
;
1732 list
= xmalloc
( sizeof
(*list
) );
1735 list_add_tail
( list
, &iface
->entry
);
1739 static ifref_t
*make_ifref
(type_t
*iface
)
1741 ifref_t
*l
= xmalloc
(sizeof
(ifref_t
));
1747 static var_list_t
*append_var
(var_list_t
*list
, var_t
*var
)
1749 if
(!var
) return list
;
1752 list
= xmalloc
( sizeof
(*list
) );
1755 list_add_tail
( list
, &var
->entry
);
1759 static var_list_t
*append_var_list
(var_list_t
*list
, var_list_t
*vars
)
1761 if
(!vars
) return list
;
1764 list
= xmalloc
( sizeof
(*list
) );
1767 list_move_tail
( list
, vars
);
1771 static var_t
*make_var
(char *name
)
1773 var_t
*v
= xmalloc
(sizeof
(var_t
));
1778 v
->stgclass
= STG_NONE
;
1779 v
->loc_info.input_name
= input_name ? input_name
: "stdin";
1780 v
->loc_info.line_number
= line_number
;
1781 v
->loc_info.near_text
= parser_text
;
1785 static declarator_list_t
*append_declarator
(declarator_list_t
*list
, declarator_t
*d
)
1787 if
(!d
) return list
;
1789 list
= xmalloc
(sizeof
(*list
));
1792 list_add_tail
(list
, &d
->entry
);
1796 static declarator_t
*make_declarator
(var_t
*var
)
1798 declarator_t
*d
= xmalloc
(sizeof
(*d
));
1801 d
->func_type
= NULL
;
1806 static func_list_t
*append_func
(func_list_t
*list
, func_t
*func
)
1808 if
(!func
) return list
;
1811 list
= xmalloc
( sizeof
(*list
) );
1814 list_add_tail
( list
, &func
->entry
);
1818 static func_t
*make_func
(var_t
*def
)
1820 func_t
*f
= xmalloc
(sizeof
(func_t
));
1822 f
->args
= def
->type
->details.function
->args
;
1823 f
->ignore
= parse_only
;
1828 static type_t
*make_class
(char *name
)
1830 type_t
*c
= make_type
(RPC_FC_COCLASS
, NULL
);
1832 c
->kind
= TKIND_COCLASS
;
1836 static type_t
*make_safearray
(type_t
*type
)
1838 type_t
*sa
= duptype
(find_type_or_error
("SAFEARRAY", 0), 1);
1840 return make_type
(pointer_default
, sa
);
1843 static typelib_t
*make_library
(const char *name
, const attr_list_t
*attrs
)
1845 typelib_t
*typelib
= xmalloc
(sizeof
(*typelib
));
1846 typelib
->name
= xstrdup
(name
);
1847 typelib
->filename
= NULL
;
1848 typelib
->attrs
= attrs
;
1849 list_init
( &typelib
->entries
);
1850 list_init
( &typelib
->importlibs
);
1856 static int hash_ident
(const char *name
)
1858 const char *p
= name
;
1860 /* a simple sum hash is probably good enough */
1865 return sum
& (HASHMAX
-1);
1868 /***** type repository *****/
1877 struct rtype
*type_hash
[HASHMAX
];
1879 static type_t
*reg_type
(type_t
*type
, const char *name
, int t
)
1884 error_loc
("registering named type without name\n");
1887 hash
= hash_ident
(name
);
1888 nt
= xmalloc
(sizeof
(struct rtype
));
1892 nt
->next
= type_hash
[hash
];
1893 type_hash
[hash
] = nt
;
1894 if
((t
== tsSTRUCT || t
== tsUNION
))
1895 fix_incomplete_types
(type
);
1899 static int is_incomplete
(const type_t
*t
)
1901 return
!t
->defined
&& (is_struct
(t
->type
) || is_union
(t
->type
));
1904 static void add_incomplete
(type_t
*t
)
1906 struct typenode
*tn
= xmalloc
(sizeof
*tn
);
1908 list_add_tail
(&incomplete_types
, &tn
->entry
);
1911 static void fix_type
(type_t
*t
)
1913 if
(t
->kind
== TKIND_ALIAS
&& is_incomplete
(t
)) {
1914 type_t
*ot
= t
->orig
;
1916 if
(is_struct
(ot
->type
) || is_union
(ot
->type
))
1917 t
->details.structure
= ot
->details.structure
;
1918 t
->defined
= ot
->defined
;
1922 static void fix_incomplete
(void)
1924 struct typenode
*tn
, *next
;
1926 LIST_FOR_EACH_ENTRY_SAFE
(tn
, next
, &incomplete_types
, struct typenode
, entry
) {
1928 list_remove
(&tn
->entry
);
1933 static void fix_incomplete_types
(type_t
*complete_type
)
1935 struct typenode
*tn
, *next
;
1937 LIST_FOR_EACH_ENTRY_SAFE
(tn
, next
, &incomplete_types
, struct typenode
, entry
)
1939 if
(((is_struct
(complete_type
->type
) && is_struct
(tn
->type
->type
)) ||
1940 (is_union
(complete_type
->type
) && is_union
(tn
->type
->type
))) &&
1941 !strcmp
(complete_type
->name
, tn
->type
->name
))
1943 tn
->type
->details.structure
= complete_type
->details.structure
;
1944 tn
->type
->type
= complete_type
->type
;
1945 list_remove
(&tn
->entry
);
1951 static type_t
*reg_typedefs
(decl_spec_t
*decl_spec
, declarator_list_t
*decls
, attr_list_t
*attrs
)
1953 const declarator_t
*decl
;
1954 int is_str
= is_attr
(attrs
, ATTR_STRING
);
1955 type_t
*type
= decl_spec
->type
;
1959 type_t
*t
= decl_spec
->type
;
1966 if
(c
!= RPC_FC_CHAR
&& c
!= RPC_FC_BYTE
&& c
!= RPC_FC_WCHAR
)
1968 decl
= LIST_ENTRY
( list_head
( decls
), const declarator_t
, entry
);
1969 error_loc
("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
1974 /* We must generate names for tagless enum, struct or union.
1975 Typedef-ing a tagless enum, struct or union means we want the typedef
1976 to be included in a library hence the public attribute. */
1977 if
((type
->kind
== TKIND_ENUM || type
->kind
== TKIND_RECORD
1978 || type
->kind
== TKIND_UNION
) && ! type
->name
&& ! parse_only
)
1980 if
(! is_attr
(attrs
, ATTR_PUBLIC
))
1981 attrs
= append_attr
( attrs
, make_attr
(ATTR_PUBLIC
) );
1982 type
->name
= gen_name
();
1984 else if
(is_attr
(attrs
, ATTR_UUID
) && !is_attr
(attrs
, ATTR_PUBLIC
))
1985 attrs
= append_attr
( attrs
, make_attr
(ATTR_PUBLIC
) );
1987 LIST_FOR_EACH_ENTRY
( decl
, decls
, const declarator_t
, entry
)
1989 var_t
*name
= decl
->var
;
1994 /* set the attributes to allow set_type to do some checks on them */
1995 name
->attrs
= attrs
;
1996 set_type
(name
, decl_spec
, decl
, 0);
1997 cur
= alias
(name
->type
, name
->name
);
2000 if
(is_incomplete
(cur
))
2001 add_incomplete
(cur
);
2002 reg_type
(cur
, cur
->name
, 0);
2008 type_t
*find_type
(const char *name
, int t
)
2010 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
2011 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
2013 return cur ? cur
->type
: NULL
;
2016 static type_t
*find_type_or_error
(const char *name
, int t
)
2018 type_t
*type
= find_type
(name
, t
);
2020 error_loc
("type '%s' not found\n", name
);
2026 static type_t
*find_type_or_error2
(char *name
, int t
)
2028 type_t
*tp
= find_type_or_error
(name
, t
);
2033 int is_type
(const char *name
)
2035 return find_type
(name
, 0) != NULL
;
2038 static type_t
*get_type
(unsigned char type
, char *name
, int t
)
2042 tp
= find_type
(name
, t
);
2048 tp
= make_type
(type
, NULL
);
2050 if
(!name
) return tp
;
2051 return reg_type
(tp
, name
, t
);
2054 static int get_struct_type
(var_list_t
*fields
)
2056 int has_pointer
= 0;
2057 int has_conformance
= 0;
2058 int has_variance
= 0;
2061 if
(get_padding
(fields
))
2062 return RPC_FC_BOGUS_STRUCT
;
2064 if
(fields
) LIST_FOR_EACH_ENTRY
( field
, fields
, var_t
, entry
)
2066 type_t
*t
= field
->type
;
2068 if
(is_user_type
(t
))
2069 return RPC_FC_BOGUS_STRUCT
;
2080 case RPC_FC_ENCAPSULATED_UNION
:
2081 case RPC_FC_NON_ENCAPSULATED_UNION
:
2082 case RPC_FC_BOGUS_STRUCT
:
2083 return RPC_FC_BOGUS_STRUCT
;
2090 if
(field
->type
->declarray
)
2092 if
(is_string_type
(field
->attrs
, field
->type
))
2094 if
(is_conformant_array
(field
->type
))
2095 has_conformance
= 1;
2100 if
(is_array
(field
->type
->ref
))
2101 return RPC_FC_BOGUS_STRUCT
;
2103 if
(is_conformant_array
(field
->type
))
2105 has_conformance
= 1;
2106 if
(field
->type
->declarray
&& list_next
(fields
, &field
->entry
))
2107 error_loc
("field '%s' deriving from a conformant array must be the last field in the structure\n",
2110 if
(field
->type
->length_is
)
2113 t
= field
->type
->ref
;
2119 * RPC_FC_BYTE, RPC_FC_STRUCT, etc
2120 * Simple types don't effect the type of struct.
2121 * A struct containing a simple struct is still a simple struct.
2122 * So long as we can block copy the data, we return RPC_FC_STRUCT.
2124 case
0: /* void pointer */
2134 case RPC_FC_INT3264
:
2135 case RPC_FC_UINT3264
:
2148 case RPC_FC_CVARRAY
:
2149 case RPC_FC_BOGUS_ARRAY
:
2154 * Propagate member attributes
2155 * a struct should be at least as complex as its member
2157 case RPC_FC_CVSTRUCT
:
2158 has_conformance
= 1;
2163 case RPC_FC_CPSTRUCT
:
2164 has_conformance
= 1;
2165 if
(list_next
( fields
, &field
->entry
))
2166 error_loc
("field '%s' deriving from a conformant array must be the last field in the structure\n",
2171 case RPC_FC_CSTRUCT
:
2172 has_conformance
= 1;
2173 if
(list_next
( fields
, &field
->entry
))
2174 error_loc
("field '%s' deriving from a conformant array must be the last field in the structure\n",
2178 case RPC_FC_PSTRUCT
:
2183 error_loc
("Unknown struct member %s with type (0x%02x)\n", field
->name
, t
->type
);
2184 /* fallthru - treat it as complex */
2186 /* as soon as we see one of these these members, it's bogus... */
2187 case RPC_FC_ENCAPSULATED_UNION
:
2188 case RPC_FC_NON_ENCAPSULATED_UNION
:
2189 case RPC_FC_BOGUS_STRUCT
:
2191 return RPC_FC_BOGUS_STRUCT
;
2197 if
( has_conformance
)
2198 return RPC_FC_CVSTRUCT
;
2200 return RPC_FC_BOGUS_STRUCT
;
2202 if
( has_conformance
&& has_pointer
)
2203 return RPC_FC_CPSTRUCT
;
2204 if
( has_conformance
)
2205 return RPC_FC_CSTRUCT
;
2207 return RPC_FC_PSTRUCT
;
2208 return RPC_FC_STRUCT
;
2211 /***** constant repository *****/
2216 struct rconst
*next
;
2219 struct rconst
*const_hash
[HASHMAX
];
2221 static var_t
*reg_const
(var_t
*var
)
2226 error_loc
("registering constant without name\n");
2229 hash
= hash_ident
(var
->name
);
2230 nc
= xmalloc
(sizeof
(struct rconst
));
2231 nc
->name
= var
->name
;
2233 nc
->next
= const_hash
[hash
];
2234 const_hash
[hash
] = nc
;
2238 var_t
*find_const
(const char *name
, int f
)
2240 struct rconst
*cur
= const_hash
[hash_ident
(name
)];
2241 while
(cur
&& strcmp
(cur
->name
, name
))
2244 if
(f
) error_loc
("constant '%s' not found\n", name
);
2250 static void write_libid
(const typelib_t
*typelib
)
2252 const UUID
*uuid
= get_attrp
(typelib
->attrs
, ATTR_UUID
);
2253 write_guid
(idfile
, "LIBID", typelib
->name
, uuid
);
2256 static void write_clsid
(type_t
*cls
)
2258 const UUID
*uuid
= get_attrp
(cls
->attrs
, ATTR_UUID
);
2259 write_guid
(idfile
, "CLSID", cls
->name
, uuid
);
2262 static void write_diid
(type_t
*iface
)
2264 const UUID
*uuid
= get_attrp
(iface
->attrs
, ATTR_UUID
);
2265 write_guid
(idfile
, "DIID", iface
->name
, uuid
);
2268 static void write_iid
(type_t
*iface
)
2270 const UUID
*uuid
= get_attrp
(iface
->attrs
, ATTR_UUID
);
2271 write_guid
(idfile
, "IID", iface
->name
, uuid
);
2274 static int compute_method_indexes
(type_t
*iface
)
2280 idx
= compute_method_indexes
(iface
->ref
);
2287 LIST_FOR_EACH_ENTRY
( f
, iface
->funcs
, func_t
, entry
)
2288 if
(! is_callas
(f
->def
->attrs
))
2294 static char *gen_name
(void)
2296 static const char format
[] = "__WIDL_%s_generated_name_%08lX";
2297 static unsigned long n
= 0;
2298 static const char *file_id
;
2304 char *dst
= dup_basename
(input_name
, ".idl");
2308 if
(! isalnum
((unsigned char) *dst
))
2311 size
= sizeof format
- 7 + strlen
(file_id
) + 8;
2314 name
= xmalloc
(size
);
2315 sprintf
(name
, format
, file_id
, n
++);
2321 unsigned int dce_compatible
: 1;
2322 unsigned int acf
: 1;
2323 unsigned int on_interface
: 1;
2324 unsigned int on_function
: 1;
2325 unsigned int on_arg
: 1;
2326 unsigned int on_type
: 1;
2327 unsigned int on_field
: 1;
2328 unsigned int on_library
: 1;
2329 unsigned int on_dispinterface
: 1;
2330 unsigned int on_module
: 1;
2331 unsigned int on_coclass
: 1;
2332 const char *display_name
;
2335 struct allowed_attr allowed_attr
[] =
2337 /* attr { D ACF I Fn ARG T Fi L DI M C <display name> } */
2338 /* ATTR_AGGREGATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "aggregatable" },
2339 /* ATTR_APPOBJECT */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "appobject" },
2340 /* ATTR_ASYNC */ { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, "async" },
2341 /* ATTR_AUTO_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "auto_handle" },
2342 /* ATTR_BINDABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "bindable" },
2343 /* ATTR_BROADCAST */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "broadcast" },
2344 /* ATTR_CALLAS */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "call_as" },
2345 /* ATTR_CALLCONV */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, NULL
},
2346 /* ATTR_CASE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "case" },
2347 /* ATTR_CONST */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "const" },
2348 /* ATTR_CONTEXTHANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "context_handle" },
2349 /* ATTR_CONTROL */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, "control" },
2350 /* ATTR_DEFAULT */ { 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, "default" },
2351 /* ATTR_DEFAULTCOLLELEM */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "defaultcollelem" },
2352 /* ATTR_DEFAULTVALUE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "defaultvalue" },
2353 /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "defaultvtable" },
2354 /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
},
2355 /* ATTR_DISPLAYBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "displaybind" },
2356 /* ATTR_DLLNAME */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, "dllname" },
2357 /* ATTR_DUAL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "dual" },
2358 /* ATTR_ENDPOINT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "endpoint" },
2359 /* ATTR_ENTRY */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "entry" },
2360 /* ATTR_EXPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "explicit_handle" },
2361 /* ATTR_HANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "handle" },
2362 /* ATTR_HELPCONTEXT */ { 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, "helpcontext" },
2363 /* ATTR_HELPFILE */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpfile" },
2364 /* ATTR_HELPSTRING */ { 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, "helpstring" },
2365 /* ATTR_HELPSTRINGCONTEXT */ { 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, "helpstringcontext" },
2366 /* ATTR_HELPSTRINGDLL */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpstringdll" },
2367 /* ATTR_HIDDEN */ { 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, "hidden" },
2368 /* ATTR_ID */ { 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, "id" },
2369 /* ATTR_IDEMPOTENT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "idempotent" },
2370 /* ATTR_IIDIS */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "iid_is" },
2371 /* ATTR_IMMEDIATEBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "immediatebind" },
2372 /* ATTR_IMPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "implicit_handle" },
2373 /* ATTR_IN */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "in" },
2374 /* ATTR_INLINE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inline" },
2375 /* ATTR_INPUTSYNC */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inputsync" },
2376 /* ATTR_LENGTHIS */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "length_is" },
2377 /* ATTR_LIBLCID */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "lcid" },
2378 /* ATTR_LOCAL */ { 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, "local" },
2379 /* ATTR_NONBROWSABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "nonbrowsable" },
2380 /* ATTR_NONCREATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "noncreatable" },
2381 /* ATTR_NONEXTENSIBLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "nonextensible" },
2382 /* ATTR_OBJECT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "object" },
2383 /* ATTR_ODL */ { 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, "odl" },
2384 /* ATTR_OLEAUTOMATION */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "oleautomation" },
2385 /* ATTR_OPTIONAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "optional" },
2386 /* ATTR_OUT */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "out" },
2387 /* ATTR_POINTERDEFAULT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "pointer_default" },
2388 /* ATTR_POINTERTYPE */ { 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, "ref, unique or ptr" },
2389 /* ATTR_PROPGET */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "propget" },
2390 /* ATTR_PROPPUT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "propput" },
2391 /* ATTR_PROPPUTREF */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "propputref" },
2392 /* ATTR_PUBLIC */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "public" },
2393 /* ATTR_RANGE */ { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, "range" },
2394 /* ATTR_READONLY */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "readonly" },
2395 /* ATTR_REQUESTEDIT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "requestedit" },
2396 /* ATTR_RESTRICTED */ { 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, "restricted" },
2397 /* ATTR_RETVAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "retval" },
2398 /* ATTR_SIZEIS */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "size_is" },
2399 /* ATTR_SOURCE */ { 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, "source" },
2400 /* ATTR_STRICTCONTEXTHANDLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "strict_context_handle" },
2401 /* ATTR_STRING */ { 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, "string" },
2402 /* ATTR_SWITCHIS */ { 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "switch_is" },
2403 /* ATTR_SWITCHTYPE */ { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, "switch_type" },
2404 /* ATTR_TRANSMITAS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "transmit_as" },
2405 /* ATTR_UUID */ { 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, "uuid" },
2406 /* ATTR_V1ENUM */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "v1_enum" },
2407 /* ATTR_VARARG */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "vararg" },
2408 /* ATTR_VERSION */ { 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, "version" },
2409 /* ATTR_WIREMARSHAL */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "wire_marshal" },
2412 const char *get_attr_display_name
(enum attr_type type
)
2414 return allowed_attr
[type
].display_name
;
2417 static attr_list_t
*check_iface_attrs
(const char *name
, attr_list_t
*attrs
)
2420 if
(!attrs
) return attrs
;
2421 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2423 if
(!allowed_attr
[attr
->type
].on_interface
)
2424 error_loc
("inapplicable attribute %s for interface %s\n",
2425 allowed_attr
[attr
->type
].display_name
, name
);
2430 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
)
2433 if
(!attrs
) return attrs
;
2434 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2436 if
(!allowed_attr
[attr
->type
].on_function
)
2437 error_loc
("inapplicable attribute %s for function %s\n",
2438 allowed_attr
[attr
->type
].display_name
, name
);
2443 static void check_arg
(var_t
*arg
)
2445 const type_t
*t
= arg
->type
;
2448 if
(t
->type
== 0 && ! is_var_ptr
(arg
))
2449 error_loc
("argument '%s' has void type\n", arg
->name
);
2453 LIST_FOR_EACH_ENTRY
(attr
, arg
->attrs
, const attr_t
, entry
)
2455 if
(!allowed_attr
[attr
->type
].on_arg
)
2456 error_loc
("inapplicable attribute %s for argument %s\n",
2457 allowed_attr
[attr
->type
].display_name
, arg
->name
);
2462 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
)
2465 if
(!attrs
) return attrs
;
2466 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2468 if
(!allowed_attr
[attr
->type
].on_type
)
2469 error_loc
("inapplicable attribute %s for typedef\n",
2470 allowed_attr
[attr
->type
].display_name
);
2475 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
)
2478 if
(!attrs
) return attrs
;
2479 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2481 if
(!allowed_attr
[attr
->type
].on_field
)
2482 error_loc
("inapplicable attribute %s for field %s\n",
2483 allowed_attr
[attr
->type
].display_name
, name
);
2488 static attr_list_t
*check_library_attrs
(const char *name
, attr_list_t
*attrs
)
2491 if
(!attrs
) return attrs
;
2492 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2494 if
(!allowed_attr
[attr
->type
].on_library
)
2495 error_loc
("inapplicable attribute %s for library %s\n",
2496 allowed_attr
[attr
->type
].display_name
, name
);
2501 static attr_list_t
*check_dispiface_attrs
(const char *name
, attr_list_t
*attrs
)
2504 if
(!attrs
) return attrs
;
2505 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2507 if
(!allowed_attr
[attr
->type
].on_dispinterface
)
2508 error_loc
("inapplicable attribute %s for dispinterface %s\n",
2509 allowed_attr
[attr
->type
].display_name
, name
);
2514 static attr_list_t
*check_module_attrs
(const char *name
, attr_list_t
*attrs
)
2517 if
(!attrs
) return attrs
;
2518 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2520 if
(!allowed_attr
[attr
->type
].on_module
)
2521 error_loc
("inapplicable attribute %s for module %s\n",
2522 allowed_attr
[attr
->type
].display_name
, name
);
2527 static attr_list_t
*check_coclass_attrs
(const char *name
, attr_list_t
*attrs
)
2530 if
(!attrs
) return attrs
;
2531 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2533 if
(!allowed_attr
[attr
->type
].on_coclass
)
2534 error_loc
("inapplicable attribute %s for coclass %s\n",
2535 allowed_attr
[attr
->type
].display_name
, name
);
2540 static int is_allowed_conf_type
(const type_t
*type
)
2561 static int is_ptr_guid_type
(const type_t
*type
)
2563 unsigned int align
= 0;
2566 if
(type
->kind
== TKIND_ALIAS
)
2568 else if
(is_ptr
(type
))
2576 return
(type_memsize
(type
, &align
) == 16);
2579 static void check_conformance_expr_list
(const char *attr_name
, const var_t
*arg
, const type_t
*container_type
, expr_list_t
*expr_list
)
2582 struct expr_loc expr_loc
;
2584 expr_loc.attr
= attr_name
;
2585 if
(expr_list
) LIST_FOR_EACH_ENTRY
(dim
, expr_list
, expr_t
, entry
)
2587 if
(dim
->type
!= EXPR_VOID
)
2589 const type_t
*expr_type
= expr_resolve_type
(&expr_loc
, container_type
, dim
);
2590 if
(!is_allowed_conf_type
(expr_type
))
2591 error_loc_info
(&arg
->loc_info
, "expression must resolve to integral type <= 32bits for attribute %s\n",
2597 static void check_remoting_fields
(const var_t
*var
, type_t
*type
);
2599 /* checks that properties common to fields and arguments are consistent */
2600 static void check_field_common
(const type_t
*container_type
,
2601 const char *container_name
, const var_t
*arg
)
2603 type_t
*type
= arg
->type
;
2604 int is_wire_marshal
= 0;
2605 int is_context_handle
= 0;
2606 const char *container_type_name
= NULL
;
2608 if
(is_struct
(container_type
->type
))
2609 container_type_name
= "struct";
2610 else if
(is_union
(container_type
->type
))
2611 container_type_name
= "union";
2612 else if
(container_type
->type
== RPC_FC_FUNCTION
)
2613 container_type_name
= "function";
2615 if
(is_attr
(arg
->attrs
, ATTR_LENGTHIS
) &&
2616 (is_attr
(arg
->attrs
, ATTR_STRING
) || is_aliaschain_attr
(arg
->type
, ATTR_STRING
)))
2617 error_loc_info
(&arg
->loc_info
,
2618 "string and length_is specified for argument %s are mutually exclusive attributes\n",
2621 if
(is_attr
(arg
->attrs
, ATTR_SIZEIS
))
2623 expr_list_t
*size_is_exprs
= get_attrp
(arg
->attrs
, ATTR_SIZEIS
);
2624 check_conformance_expr_list
("size_is", arg
, container_type
, size_is_exprs
);
2626 if
(is_attr
(arg
->attrs
, ATTR_LENGTHIS
))
2628 expr_list_t
*length_is_exprs
= get_attrp
(arg
->attrs
, ATTR_LENGTHIS
);
2629 check_conformance_expr_list
("length_is", arg
, container_type
, length_is_exprs
);
2631 if
(is_attr
(arg
->attrs
, ATTR_IIDIS
))
2633 struct expr_loc expr_loc
;
2634 expr_t
*expr
= get_attrp
(arg
->attrs
, ATTR_IIDIS
);
2635 if
(expr
->type
!= EXPR_VOID
)
2637 const type_t
*expr_type
;
2639 expr_loc.attr
= "iid_is";
2640 expr_type
= expr_resolve_type
(&expr_loc
, container_type
, expr
);
2641 if
(!expr_type ||
!is_ptr_guid_type
(expr_type
))
2642 error_loc_info
(&arg
->loc_info
, "expression must resolve to pointer to GUID type for attribute iid_is\n");
2645 if
(is_attr
(arg
->attrs
, ATTR_SWITCHIS
))
2647 struct expr_loc expr_loc
;
2648 expr_t
*expr
= get_attrp
(arg
->attrs
, ATTR_SWITCHIS
);
2649 if
(expr
->type
!= EXPR_VOID
)
2651 const type_t
*expr_type
;
2653 expr_loc.attr
= "switch_is";
2654 expr_type
= expr_resolve_type
(&expr_loc
, container_type
, expr
);
2655 if
(!expr_type ||
!is_allowed_conf_type
(expr_type
))
2656 error_loc_info
(&arg
->loc_info
, "expression must resolve to integral type <= 32bits for attribute %s\n",
2661 /* get fundamental type for the argument */
2664 if
(is_attr
(type
->attrs
, ATTR_WIREMARSHAL
))
2666 is_wire_marshal
= 1;
2669 if
(is_attr
(type
->attrs
, ATTR_CONTEXTHANDLE
))
2671 is_context_handle
= 1;
2674 if
(type
->kind
== TKIND_ALIAS
)
2676 else if
(is_ptr
(type
) || is_array
(type
))
2682 if
(type
->type
== 0 && !is_attr
(arg
->attrs
, ATTR_IIDIS
) && !is_wire_marshal
&& !is_context_handle
)
2683 error_loc_info
(&arg
->loc_info
, "parameter \'%s\' of %s \'%s\' cannot derive from void *\n", arg
->name
, container_type_name
, container_name
);
2684 else if
(type
->type
== RPC_FC_FUNCTION
)
2685 error_loc_info
(&arg
->loc_info
, "parameter \'%s\' of %s \'%s\' cannot be a function pointer\n", arg
->name
, container_type_name
, container_name
);
2686 else if
(!is_wire_marshal
&& (is_struct
(type
->type
) || is_union
(type
->type
)))
2687 check_remoting_fields
(arg
, type
);
2690 static void check_remoting_fields
(const var_t
*var
, type_t
*type
)
2693 const var_list_t
*fields
= NULL
;
2695 /* find the real type */
2696 while
(type
->kind
== TKIND_ALIAS
)
2702 type
->checked
= TRUE
;
2704 if
(is_struct
(type
->type
))
2706 if
(type
->details.function
)
2707 fields
= type
->details.function
->args
;
2709 error_loc_info
(&var
->loc_info
, "undefined type declaration %s\n", type
->name
);
2711 else if
(is_union
(type
->type
))
2713 if
(type
->type
== RPC_FC_ENCAPSULATED_UNION
)
2715 const var_t
*uv
= LIST_ENTRY
(list_tail
(type
->details.structure
->fields
), const var_t
, entry
);
2716 fields
= uv
->type
->details.structure
->fields
;
2719 fields
= type
->details.structure
->fields
;
2722 if
(fields
) LIST_FOR_EACH_ENTRY
( field
, fields
, const var_t
, entry
)
2723 if
(field
->type
) check_field_common
(type
, type
->name
, field
);
2726 /* checks that arguments for a function make sense for marshalling and unmarshalling */
2727 static void check_remoting_args
(const func_t
*func
)
2729 const char *funcname
= func
->def
->name
;
2732 if
(func
->args
) LIST_FOR_EACH_ENTRY
( arg
, func
->args
, const var_t
, entry
)
2735 const type_t
*type
= arg
->type
;
2737 /* get pointer level and fundamental type for the argument */
2740 if
(is_attr
(type
->attrs
, ATTR_WIREMARSHAL
))
2742 if
(is_attr
(type
->attrs
, ATTR_CONTEXTHANDLE
))
2744 if
(type
->kind
== TKIND_ALIAS
)
2746 else if
(is_ptr
(type
))
2755 /* check that [out] parameters have enough pointer levels */
2756 if
(is_attr
(arg
->attrs
, ATTR_OUT
))
2758 if
(!is_array
(type
))
2761 error_loc_info
(&arg
->loc_info
, "out parameter \'%s\' of function \'%s\' is not a pointer\n", arg
->name
, funcname
);
2762 if
(type
->type
== RPC_FC_IP
&& ptr_level
== 1)
2763 error_loc_info
(&arg
->loc_info
, "out interface pointer \'%s\' of function \'%s\' is not a double pointer\n", arg
->name
, funcname
);
2767 check_field_common
(func
->def
->type
, funcname
, arg
);
2771 static void add_explicit_handle_if_necessary
(func_t
*func
)
2773 const var_t
* explicit_handle_var
;
2774 const var_t
* explicit_generic_handle_var
= NULL
;
2775 const var_t
* context_handle_var
= NULL
;
2777 /* check for a defined binding handle */
2778 explicit_handle_var
= get_explicit_handle_var
(func
);
2779 if
(!explicit_handle_var
)
2781 explicit_generic_handle_var
= get_explicit_generic_handle_var
(func
);
2782 if
(!explicit_generic_handle_var
)
2784 context_handle_var
= get_context_handle_var
(func
);
2785 if
(!context_handle_var
)
2787 /* no explicit handle specified so add
2788 * "[in] handle_t IDL_handle" as the first parameter to the
2790 var_t
*idl_handle
= make_var
(xstrdup
("IDL_handle"));
2791 idl_handle
->attrs
= append_attr
(NULL
, make_attr
(ATTR_IN
));
2792 idl_handle
->type
= find_type_or_error
("handle_t", 0);
2793 if
(!func
->def
->type
->details.function
->args
)
2795 func
->def
->type
->details.function
->args
= xmalloc
( sizeof
(*func
->def
->type
->details.function
->args
) );
2796 list_init
( func
->def
->type
->details.function
->args
);
2798 list_add_head
( func
->def
->type
->details.function
->args
, &idl_handle
->entry
);
2799 func
->args
= func
->def
->type
->details.function
->args
;
2805 static void check_functions
(const type_t
*iface
)
2807 if
(is_attr
(iface
->attrs
, ATTR_EXPLICIT_HANDLE
) && iface
->funcs
)
2810 LIST_FOR_EACH_ENTRY
( func
, iface
->funcs
, func_t
, entry
)
2811 add_explicit_handle_if_necessary
(func
);
2813 if
(!is_inside_library
&& !is_attr
(iface
->attrs
, ATTR_LOCAL
))
2816 if
(iface
->funcs
) LIST_FOR_EACH_ENTRY
( func
, iface
->funcs
, const func_t
, entry
)
2818 if
(!is_attr
(func
->def
->attrs
, ATTR_LOCAL
))
2819 check_remoting_args
(func
);
2824 static void check_all_user_types
(const statement_list_t
*stmts
)
2826 const statement_t
*stmt
;
2828 if
(stmts
) LIST_FOR_EACH_ENTRY
(stmt
, stmts
, const statement_t
, entry
)
2830 if
(stmt
->type
== STMT_LIBRARY
)
2831 check_all_user_types
(stmt
->u.lib
->stmts
);
2832 else if
(stmt
->type
== STMT_TYPE
&& stmt
->u.type
->type
== RPC_FC_IP
&&
2833 !is_local
(stmt
->u.type
->attrs
))
2836 const func_list_t
*fs
= stmt
->u.type
->funcs
;
2837 if
(fs
) LIST_FOR_EACH_ENTRY
(f
, fs
, const func_t
, entry
)
2838 check_for_additional_prototype_types
(f
->args
);
2843 int is_valid_uuid
(const char *s
)
2847 for
(i
= 0; i
< 36; ++i
)
2848 if
(i
== 8 || i
== 13 || i
== 18 || i
== 23)
2854 if
(!isxdigit
(s
[i
]))
2857 return s
[i
] == '\0';
2860 static statement_t
*make_statement
(enum statement_type type
)
2862 statement_t
*stmt
= xmalloc
(sizeof
(*stmt
));
2867 static statement_t
*make_statement_type_decl
(type_t
*type
)
2869 statement_t
*stmt
= make_statement
(STMT_TYPE
);
2870 stmt
->u.type
= type
;
2874 static statement_t
*make_statement_reference
(type_t
*type
)
2876 statement_t
*stmt
= make_statement
(STMT_TYPEREF
);
2877 stmt
->u.type
= type
;
2881 static statement_t
*make_statement_declaration
(var_t
*var
)
2883 statement_t
*stmt
= make_statement
(STMT_DECLARATION
);
2885 if
(var
->stgclass
== STG_EXTERN
&& var
->eval
)
2886 warning
("'%s' initialised and declared extern\n", var
->name
);
2887 if
(is_const_decl
(var
))
2892 else if
((var
->stgclass
== STG_NONE || var
->stgclass
== STG_REGISTER
) &&
2893 var
->type
->type
!= RPC_FC_FUNCTION
)
2894 error_loc
("instantiation of data is illegal\n");
2898 static statement_t
*make_statement_library
(typelib_t
*typelib
)
2900 statement_t
*stmt
= make_statement
(STMT_LIBRARY
);
2901 stmt
->u.lib
= typelib
;
2905 static statement_t
*make_statement_cppquote
(const char *str
)
2907 statement_t
*stmt
= make_statement
(STMT_CPPQUOTE
);
2912 static statement_t
*make_statement_importlib
(const char *str
)
2914 statement_t
*stmt
= make_statement
(STMT_IMPORTLIB
);
2919 static statement_t
*make_statement_import
(const char *str
)
2921 statement_t
*stmt
= make_statement
(STMT_IMPORT
);
2926 static statement_t
*make_statement_module
(type_t
*type
)
2928 statement_t
*stmt
= make_statement
(STMT_MODULE
);
2929 stmt
->u.type
= type
;
2933 static statement_t
*process_typedefs
(declarator_list_t
*decls
)
2935 declarator_t
*decl
, *next
;
2937 type_list_t
**type_list
;
2939 if
(!decls
) return NULL
;
2941 stmt
= make_statement
(STMT_TYPEDEF
);
2942 stmt
->u.type_list
= NULL
;
2943 type_list
= &stmt
->u.type_list
;
2945 LIST_FOR_EACH_ENTRY_SAFE
( decl
, next
, decls
, declarator_t
, entry
)
2947 var_t
*var
= decl
->var
;
2948 type_t
*type
= find_type_or_error
(var
->name
, 0);
2949 *type_list
= xmalloc
(sizeof
(type_list_t
));
2950 (*type_list
)->type
= type
;
2951 (*type_list
)->next
= NULL
;
2953 if
(! parse_only
&& do_header
)
2954 write_typedef
(type
);
2955 if
(in_typelib
&& is_attr
(type
->attrs
, ATTR_PUBLIC
))
2956 add_typelib_entry
(type
);
2958 type_list
= &(*type_list
)->next
;
2966 static statement_list_t
*append_statement
(statement_list_t
*list
, statement_t
*stmt
)
2968 if
(!stmt
) return list
;
2971 list
= xmalloc
( sizeof
(*list
) );
2974 list_add_tail
( list
, &stmt
->entry
);
2978 static func_list_t
*append_func_from_statement
(func_list_t
*list
, statement_t
*stmt
)
2980 if
(stmt
->type
== STMT_DECLARATION
)
2982 var_t
*var
= stmt
->u.var
;
2983 if
(var
->stgclass
== STG_NONE
&& var
->type
->type
== RPC_FC_FUNCTION
)
2985 check_function_attrs
(var
->name
, var
->type
->attrs
);
2986 return append_func
(list
, make_func
(stmt
->u.var
));