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);
100 static str_list_t
*append_str
(str_list_t
*list
, char *str
);
101 static attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
);
102 static attr_list_t
*append_attr_list
(attr_list_t
*new_list
, attr_list_t
*old_list
);
103 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
);
104 static attr_t
*make_attr
(enum attr_type type
);
105 static attr_t
*make_attrv
(enum attr_type type
, unsigned long val
);
106 static attr_t
*make_attrp
(enum attr_type type
, void *val
);
107 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
);
108 static array_dims_t
*append_array
(array_dims_t
*list
, expr_t
*expr
);
109 static void set_type
(var_t
*v
, decl_spec_t
*decl_spec
, const declarator_t
*decl
, int top
);
110 static var_list_t
*set_var_types
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_list_t
*decls
);
111 static ifref_list_t
*append_ifref
(ifref_list_t
*list
, ifref_t
*iface
);
112 static ifref_t
*make_ifref
(type_t
*iface
);
113 static var_list_t
*append_var
(var_list_t
*list
, var_t
*var
);
114 static var_list_t
*append_var_list
(var_list_t
*list
, var_list_t
*vars
);
115 static var_t
*make_var
(char *name
);
116 static declarator_list_t
*append_declarator
(declarator_list_t
*list
, declarator_t
*p
);
117 static declarator_t
*make_declarator
(var_t
*var
);
118 static func_list_t
*append_func
(func_list_t
*list
, func_t
*func
);
119 static func_t
*make_func
(var_t
*def
);
120 static type_t
*make_class
(char *name
);
121 static type_t
*make_safearray
(type_t
*type
);
122 static type_t
*make_builtin
(char *name
);
123 static type_t
*make_int
(int sign
);
124 static typelib_t
*make_library
(const char *name
, const attr_list_t
*attrs
);
125 static type_t
*make_func_type
(var_list_t
*args
);
126 static type_t
*make_pointer_type
(type_t
*ref
, attr_list_t
*attrs
);
127 static type_t
*append_ptrchain_type
(type_t
*ptrchain
, type_t
*type
);
129 static type_t
*reg_type
(type_t
*type
, const char *name
, int t
);
130 static type_t
*reg_typedefs
(decl_spec_t
*decl_spec
, var_list_t
*names
, attr_list_t
*attrs
);
131 static type_t
*find_type_or_error
(const char *name
, int t
);
132 static type_t
*find_type_or_error2
(char *name
, int t
);
133 static type_t
*get_type
(unsigned char type
, char *name
, int t
);
134 static type_t
*get_typev
(unsigned char type
, var_t
*name
, int t
);
135 static int get_struct_type
(var_list_t
*fields
);
137 static var_t
*reg_const
(var_t
*var
);
139 static void write_libid
(const typelib_t
*typelib
);
140 static void write_clsid
(type_t
*cls
);
141 static void write_diid
(type_t
*iface
);
142 static void write_iid
(type_t
*iface
);
144 static int compute_method_indexes
(type_t
*iface
);
145 static char *gen_name
(void);
146 static statement_t
*process_typedefs
(var_list_t
*names
);
147 static void check_arg
(var_t
*arg
);
148 static void check_functions
(const type_t
*iface
);
149 static void check_all_user_types
(const statement_list_t
*stmts
);
150 static attr_list_t
*check_iface_attrs
(const char *name
, attr_list_t
*attrs
);
151 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
);
152 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
);
153 static attr_list_t
*check_enum_attrs
(attr_list_t
*attrs
);
154 static attr_list_t
*check_struct_attrs
(attr_list_t
*attrs
);
155 static attr_list_t
*check_union_attrs
(attr_list_t
*attrs
);
156 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
);
157 static attr_list_t
*check_library_attrs
(const char *name
, attr_list_t
*attrs
);
158 static attr_list_t
*check_dispiface_attrs
(const char *name
, attr_list_t
*attrs
);
159 static attr_list_t
*check_module_attrs
(const char *name
, attr_list_t
*attrs
);
160 static attr_list_t
*check_coclass_attrs
(const char *name
, attr_list_t
*attrs
);
161 const char *get_attr_display_name
(enum attr_type type
);
162 static void add_explicit_handle_if_necessary
(func_t
*func
);
163 static void check_def
(const type_t
*t
);
165 static statement_t
*make_statement
(enum statement_type type
);
166 static statement_t
*make_statement_type_decl
(type_t
*type
);
167 static statement_t
*make_statement_reference
(type_t
*type
);
168 static statement_t
*make_statement_declaration
(var_t
*var
);
169 static statement_t
*make_statement_library
(typelib_t
*typelib
);
170 static statement_t
*make_statement_cppquote
(const char *str
);
171 static statement_t
*make_statement_importlib
(const char *str
);
172 static statement_t
*make_statement_module
(type_t
*type
);
173 static statement_t
*make_statement_import
(const char *str
);
174 static statement_list_t
*append_statement
(statement_list_t
*list
, statement_t
*stmt
);
175 static func_list_t
*append_func_from_statement
(func_list_t
*list
, statement_t
*stmt
);
184 attr_list_t
*attr_list
;
185 str_list_t
*str_list
;
187 expr_list_t
*expr_list
;
188 array_dims_t
*array_dims
;
191 var_list_t
*var_list
;
192 declarator_t
*declarator
;
193 declarator_list_t
*declarator_list
;
195 func_list_t
*func_list
;
196 statement_t
*statement
;
197 statement_list_t
*stmt_list
;
199 ifref_list_t
*ifref_list
;
204 interface_info_t ifinfo
;
206 struct _import_t
*import
;
207 struct _decl_spec_t
*declspec
;
208 enum storage_class stgclass
;
211 %token
<str
> aIDENTIFIER
212 %token
<str
> aKNOWNTYPE
213 %token
<num
> aNUM aHEXNUM
215 %token
<str
> aSTRING aWSTRING
220 %token EQUALITY INEQUALITY
221 %token GREATEREQUAL LESSEQUAL
222 %token LOGICALOR LOGICALAND
223 %token tAGGREGATABLE tALLOCATE tAPPOBJECT tASYNC tASYNCUUID
224 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
225 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
226 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
227 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
229 %token tDEFAULTCOLLELEM
231 %token tDEFAULTVTABLE
233 %token tDISPINTERFACE
234 %token tDLLNAME tDOUBLE tDUAL
236 %token tENTRY tENUM tERRORSTATUST
237 %token tEXPLICITHANDLE tEXTERN
243 %token tHELPCONTEXT tHELPFILE
244 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
246 %token tHYPER tID tIDEMPOTENT
248 %token tIMMEDIATEBIND
249 %token tIMPLICITHANDLE
250 %token tIMPORT tIMPORTLIB
251 %token tIN tIN_LINE tINLINE
256 %token tLENGTHIS tLIBRARY
263 %token tNONEXTENSIBLE
265 %token tOBJECT tODL tOLEAUTOMATION
269 %token tPOINTERDEFAULT
271 %token tPROPGET tPROPPUT tPROPPUTREF
275 %token tREADONLY tREF
284 %token tSIZEIS tSIZEOF
289 %token tSTRICTCONTEXTHANDLE
290 %token tSTRING tSTRUCT
291 %token tSWITCH tSWITCHIS tSWITCHTYPE
303 %token tWCHAR tWIREMARSHAL
305 %type
<attr
> attribute type_qualifier function_specifier
306 %type
<attr_list
> m_attributes attributes attrib_list m_type_qual_list
307 %type
<str_list
> str_list
308 %type
<expr
> m_expr expr expr_const expr_int_const array
309 %type
<expr_list
> m_exprs
/* exprs expr_list */ expr_list_int_const
310 %type
<ifinfo
> interfacehdr
311 %type
<stgclass
> storage_cls_spec
312 %type
<declspec
> decl_spec decl_spec_no_type m_decl_spec_no_type
313 %type
<type
> inherit interface interfacedef interfacedec
314 %type
<type
> dispinterface dispinterfacehdr dispinterfacedef
315 %type
<type
> module modulehdr moduledef
316 %type
<type
> base_type int_std
317 %type
<type
> enumdef structdef uniondef typedecl
319 %type
<ifref
> coclass_int
320 %type
<ifref_list
> coclass_ints
321 %type
<var
> arg ne_union_field union_field s_field case
enum declaration
322 %type
<var_list
> m_args no_args args fields ne_union_fields cases enums enum_list dispint_props field
323 %type
<var
> m_ident t_ident ident
324 %type
<declarator
> declarator direct_declarator init_declarator
325 %type
<declarator_list
> declarator_list
327 %type
<func_list
> int_statements dispint_meths
328 %type
<type
> coclass coclasshdr coclassdef
329 %type
<num
> pointer_type version
330 %type
<str
> libraryhdr callconv cppquote importlib import
331 %type
<uuid
> uuid_string
332 %type
<import
> import_start
333 %type
<typelib
> library_start librarydef
334 %type
<statement
> statement typedef
335 %type
<stmt_list
> gbl_statements imp_statements
344 %left EQUALITY INEQUALITY
345 %left
'<' '>' LESSEQUAL GREATEREQUAL
349 %right
'!' '~' CAST PPTR POS NEG ADDRESSOF tSIZEOF
350 %left
'.' MEMBERPTR
'[' ']'
354 input: gbl_statements
{ fix_incomplete
();
355 check_all_user_types
($1);
363 gbl_statements: { $$
= NULL
; }
364 | gbl_statements interfacedec
{ $$
= $1; }
365 | gbl_statements interfacedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); }
366 | gbl_statements coclass
';' { $$
= $1;
367 reg_type
($2, $2->name
, 0);
368 if
(!parse_only
&& do_header
) write_coclass_forward
($2);
370 | gbl_statements coclassdef
{ $$
= append_statement
($1, make_statement_type_decl
($2));
371 add_typelib_entry
($2);
372 reg_type
($2, $2->name
, 0);
373 if
(!parse_only
&& do_header
) write_coclass_forward
($2);
375 | gbl_statements moduledef
{ $$
= append_statement
($1, make_statement_module
($2));
376 add_typelib_entry
($2);
378 | gbl_statements librarydef
{ $$
= append_statement
($1, make_statement_library
($2)); }
379 | gbl_statements statement
{ $$
= append_statement
($1, $2); }
382 imp_statements: { $$
= NULL
; }
383 | imp_statements interfacedec
{ $$
= append_statement
($1, make_statement_reference
($2)); if
(!parse_only
) add_typelib_entry
($2); }
384 | imp_statements interfacedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); if
(!parse_only
) add_typelib_entry
($2); }
385 | imp_statements coclass
';' { $$
= $1; reg_type
($2, $2->name
, 0); if
(!parse_only
&& do_header
) write_coclass_forward
($2); }
386 | imp_statements coclassdef
{ $$
= append_statement
($1, make_statement_type_decl
($2));
387 if
(!parse_only
) add_typelib_entry
($2);
388 reg_type
($2, $2->name
, 0);
389 if
(!parse_only
&& do_header
) write_coclass_forward
($2);
391 | imp_statements moduledef
{ $$
= append_statement
($1, make_statement_module
($2)); if
(!parse_only
) add_typelib_entry
($2); }
392 | imp_statements statement
{ $$
= append_statement
($1, $2); }
393 | imp_statements importlib
{ $$
= append_statement
($1, make_statement_importlib
($2)); }
394 | imp_statements librarydef
{ $$
= append_statement
($1, make_statement_library
($2)); }
397 int_statements: { $$
= NULL
; }
398 | int_statements statement
{ $$
= append_func_from_statement
( $1, $2 ); }
406 cppquote
{ $$
= make_statement_cppquote
($1); }
407 | typedecl
';' { $$
= make_statement_type_decl
($1);
408 if
(!parse_only
&& do_header
) {
409 write_type_def_or_decl
(header
, $1, FALSE
, NULL
);
410 fprintf
(header
, ";\n\n");
413 | declaration
';' { $$
= make_statement_declaration
($1);
414 if
(!parse_only
&& do_header
) write_declaration
($1, is_in_interface
);
416 | import
{ $$
= make_statement_import
($1); }
417 | typedef
';' { $$
= $1; }
424 | attributes enumdef
{ $$
= $2; $$
->attrs
= check_enum_attrs
($1); }
425 | attributes structdef
{ $$
= $2; $$
->attrs
= check_struct_attrs
($1); }
426 | attributes uniondef
{ $$
= $2; $$
->attrs
= check_union_attrs
($1); }
429 cppquote: tCPPQUOTE
'(' aSTRING
')' { $$
= $3; if
(!parse_only
&& do_header
) fprintf
(header
, "%s\n", $3); }
431 import_start: tIMPORT aSTRING
';' { assert
(yychar == YYEMPTY
);
432 $$
= xmalloc
(sizeof
(struct _import_t
));
434 $$
->import_performed
= do_import
($2);
435 if
(!$$
->import_performed
) yychar = aEOF
;
439 import: import_start imp_statements aEOF
{ $$
= $1->name
;
440 if
($1->import_performed
) pop_import
();
442 if
(!parse_only
&& do_header
) write_import
($$
);
446 importlib: tIMPORTLIB
'(' aSTRING
')'
447 semicolon_opt
{ $$
= $3; if
(!parse_only
) add_importlib
($3); }
450 libraryhdr: tLIBRARY aIDENTIFIER
{ $$
= $2; }
452 library_start: attributes libraryhdr
'{' { $$
= make_library
($2, check_library_attrs
($2, $1));
453 if
(!parse_only
) start_typelib
($$
);
454 if
(!parse_only
&& do_header
) write_library
($$
);
455 if
(!parse_only
&& do_idfile
) write_libid
($$
);
456 is_inside_library
= TRUE
;
459 librarydef: library_start imp_statements
'}'
460 semicolon_opt
{ $$
= $1;
462 if
(!parse_only
) end_typelib
();
463 is_inside_library
= FALSE
;
467 m_args: { $$
= NULL
; }
471 no_args: tVOID
{ $$
= NULL
; }
474 args: arg
{ check_arg
($1); $$
= append_var
( NULL
, $1 ); }
475 | args
',' arg
{ check_arg
($3); $$
= append_var
( $1, $3); }
479 /* split into two rules to get bison to resolve a tVOID conflict */
480 arg: attributes decl_spec declarator
{ $$
= $3->var
;
482 if
($2->stgclass
!= STG_NONE
&& $2->stgclass
!= STG_REGISTER
)
483 error_loc
("invalid storage class for function parameter\n");
484 set_type
($$
, $2, $3, TRUE
);
487 | decl_spec declarator
{ $$
= $2->var
;
488 if
($1->stgclass
!= STG_NONE
&& $1->stgclass
!= STG_REGISTER
)
489 error_loc
("invalid storage class for function parameter\n");
490 set_type
($$
, $1, $2, TRUE
);
495 array: '[' m_expr
']' { $$
= $2; }
496 |
'[' '*' ']' { $$
= make_expr
(EXPR_VOID
); }
499 m_attributes: { $$
= NULL
; }
504 '[' attrib_list
']' { $$
= $2; }
507 attrib_list: attribute
{ $$
= append_attr
( NULL
, $1 ); }
508 | attrib_list
',' attribute
{ $$
= append_attr
( $1, $3 ); }
509 | attrib_list
']' '[' attribute
{ $$
= append_attr
( $1, $4 ); }
512 str_list: aSTRING
{ $$
= append_str
( NULL
, $1 ); }
513 | str_list
',' aSTRING
{ $$
= append_str
( $1, $3 ); }
516 attribute: { $$
= NULL
; }
517 | tAGGREGATABLE
{ $$
= make_attr
(ATTR_AGGREGATABLE
); }
518 | tAPPOBJECT
{ $$
= make_attr
(ATTR_APPOBJECT
); }
519 | tASYNC
{ $$
= make_attr
(ATTR_ASYNC
); }
520 | tAUTOHANDLE
{ $$
= make_attr
(ATTR_AUTO_HANDLE
); }
521 | tBINDABLE
{ $$
= make_attr
(ATTR_BINDABLE
); }
522 | tBROADCAST
{ $$
= make_attr
(ATTR_BROADCAST
); }
523 | tCALLAS
'(' ident
')' { $$
= make_attrp
(ATTR_CALLAS
, $3); }
524 | tCASE
'(' expr_list_int_const
')' { $$
= make_attrp
(ATTR_CASE
, $3); }
525 | tCONTEXTHANDLE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); }
526 | tCONTEXTHANDLENOSERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
527 | tCONTEXTHANDLESERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
528 | tCONTROL
{ $$
= make_attr
(ATTR_CONTROL
); }
529 | tDEFAULT
{ $$
= make_attr
(ATTR_DEFAULT
); }
530 | tDEFAULTCOLLELEM
{ $$
= make_attr
(ATTR_DEFAULTCOLLELEM
); }
531 | tDEFAULTVALUE
'(' expr_const
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE
, $3); }
532 | tDEFAULTVTABLE
{ $$
= make_attr
(ATTR_DEFAULTVTABLE
); }
533 | tDISPLAYBIND
{ $$
= make_attr
(ATTR_DISPLAYBIND
); }
534 | tDLLNAME
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DLLNAME
, $3); }
535 | tDUAL
{ $$
= make_attr
(ATTR_DUAL
); }
536 | tENDPOINT
'(' str_list
')' { $$
= make_attrp
(ATTR_ENDPOINT
, $3); }
537 | tENTRY
'(' expr_const
')' { $$
= make_attrp
(ATTR_ENTRY
, $3); }
538 | tEXPLICITHANDLE
{ $$
= make_attr
(ATTR_EXPLICIT_HANDLE
); }
539 | tHANDLE
{ $$
= make_attr
(ATTR_HANDLE
); }
540 | tHELPCONTEXT
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_HELPCONTEXT
, $3); }
541 | tHELPFILE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPFILE
, $3); }
542 | tHELPSTRING
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRING
, $3); }
543 | tHELPSTRINGCONTEXT
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_HELPSTRINGCONTEXT
, $3); }
544 | tHELPSTRINGDLL
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRINGDLL
, $3); }
545 | tHIDDEN
{ $$
= make_attr
(ATTR_HIDDEN
); }
546 | tID
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_ID
, $3); }
547 | tIDEMPOTENT
{ $$
= make_attr
(ATTR_IDEMPOTENT
); }
548 | tIIDIS
'(' expr
')' { $$
= make_attrp
(ATTR_IIDIS
, $3); }
549 | tIMMEDIATEBIND
{ $$
= make_attr
(ATTR_IMMEDIATEBIND
); }
550 | tIMPLICITHANDLE
'(' tHANDLET aIDENTIFIER
')' { $$
= make_attrp
(ATTR_IMPLICIT_HANDLE
, $4); }
551 | tIN
{ $$
= make_attr
(ATTR_IN
); }
552 | tINPUTSYNC
{ $$
= make_attr
(ATTR_INPUTSYNC
); }
553 | tLENGTHIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_LENGTHIS
, $3); }
554 | tLCID
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_LIBLCID
, $3); }
555 | tLOCAL
{ $$
= make_attr
(ATTR_LOCAL
); }
556 | tNONBROWSABLE
{ $$
= make_attr
(ATTR_NONBROWSABLE
); }
557 | tNONCREATABLE
{ $$
= make_attr
(ATTR_NONCREATABLE
); }
558 | tNONEXTENSIBLE
{ $$
= make_attr
(ATTR_NONEXTENSIBLE
); }
559 | tOBJECT
{ $$
= make_attr
(ATTR_OBJECT
); }
560 | tODL
{ $$
= make_attr
(ATTR_ODL
); }
561 | tOLEAUTOMATION
{ $$
= make_attr
(ATTR_OLEAUTOMATION
); }
562 | tOPTIONAL
{ $$
= make_attr
(ATTR_OPTIONAL
); }
563 | tOUT
{ $$
= make_attr
(ATTR_OUT
); }
564 | tPOINTERDEFAULT
'(' pointer_type
')' { $$
= make_attrv
(ATTR_POINTERDEFAULT
, $3); }
565 | tPROPGET
{ $$
= make_attr
(ATTR_PROPGET
); }
566 | tPROPPUT
{ $$
= make_attr
(ATTR_PROPPUT
); }
567 | tPROPPUTREF
{ $$
= make_attr
(ATTR_PROPPUTREF
); }
568 | tPUBLIC
{ $$
= make_attr
(ATTR_PUBLIC
); }
569 | tRANGE
'(' expr_int_const
',' expr_int_const
')'
570 { expr_list_t
*list
= append_expr
( NULL
, $3 );
571 list
= append_expr
( list
, $5 );
572 $$
= make_attrp
(ATTR_RANGE
, list
); }
573 | tREADONLY
{ $$
= make_attr
(ATTR_READONLY
); }
574 | tREQUESTEDIT
{ $$
= make_attr
(ATTR_REQUESTEDIT
); }
575 | tRESTRICTED
{ $$
= make_attr
(ATTR_RESTRICTED
); }
576 | tRETVAL
{ $$
= make_attr
(ATTR_RETVAL
); }
577 | tSIZEIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_SIZEIS
, $3); }
578 | tSOURCE
{ $$
= make_attr
(ATTR_SOURCE
); }
579 | tSTRICTCONTEXTHANDLE
{ $$
= make_attr
(ATTR_STRICTCONTEXTHANDLE
); }
580 | tSTRING
{ $$
= make_attr
(ATTR_STRING
); }
581 | tSWITCHIS
'(' expr
')' { $$
= make_attrp
(ATTR_SWITCHIS
, $3); }
582 | tSWITCHTYPE
'(' type
')' { $$
= make_attrp
(ATTR_SWITCHTYPE
, $3); }
583 | tTRANSMITAS
'(' type
')' { $$
= make_attrp
(ATTR_TRANSMITAS
, $3); }
584 | tUUID
'(' uuid_string
')' { $$
= make_attrp
(ATTR_UUID
, $3); }
585 | tV1ENUM
{ $$
= make_attr
(ATTR_V1ENUM
); }
586 | tVARARG
{ $$
= make_attr
(ATTR_VARARG
); }
587 | tVERSION
'(' version
')' { $$
= make_attrv
(ATTR_VERSION
, $3); }
588 | tWIREMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_WIREMARSHAL
, $3); }
589 | pointer_type
{ $$
= make_attrv
(ATTR_POINTERTYPE
, $1); }
594 | aSTRING
{ if
(!is_valid_uuid
($1))
595 error_loc
("invalid UUID: %s\n", $1);
596 $$
= parse_uuid
($1); }
599 callconv: tCDECL
{ $$
= $
<str
>1; }
600 | tFASTCALL
{ $$
= $
<str
>1; }
601 | tPASCAL
{ $$
= $
<str
>1; }
602 | tSTDCALL
{ $$
= $
<str
>1; }
605 cases: { $$
= NULL
; }
606 | cases case
{ $$
= append_var
( $1, $2 ); }
609 case: tCASE expr_int_const
':' union_field
{ attr_t
*a
= make_attrp
(ATTR_CASE
, append_expr
( NULL
, $2 ));
610 $$
= $4; if
(!$$
) $$
= make_var
(NULL
);
611 $$
->attrs
= append_attr
( $$
->attrs
, a
);
613 | tDEFAULT
':' union_field
{ attr_t
*a
= make_attr
(ATTR_DEFAULT
);
614 $$
= $3; if
(!$$
) $$
= make_var
(NULL
);
615 $$
->attrs
= append_attr
( $$
->attrs
, a
);
619 enums: { $$
= NULL
; }
620 | enum_list
',' { $$
= $1; }
624 enum_list: enum { if
(!$1->eval
)
625 $1->eval
= make_exprl
(EXPR_NUM
, 0 /* default for first enum entry */);
626 $$
= append_var
( NULL
, $1 );
628 | enum_list
',' enum { if
(!$3->eval
)
630 var_t
*last
= LIST_ENTRY
( list_tail
($$
), var_t
, entry
);
631 $3->eval
= make_exprl
(EXPR_NUM
, last
->eval
->cval
+ 1);
633 $$
= append_var
( $1, $3 );
637 enum: ident
'=' expr_int_const
{ $$
= reg_const
($1);
639 $$
->type
= make_int
(0);
641 | ident
{ $$
= reg_const
($1);
642 $$
->type
= make_int
(0);
646 enumdef: tENUM t_ident
'{' enums
'}' { $$
= get_typev
(RPC_FC_ENUM16
, $2, tsENUM
);
647 $$
->kind
= TKIND_ENUM
;
648 $$
->fields_or_args
= $4;
651 add_typelib_entry
($$
);
655 m_exprs: m_expr
{ $$
= append_expr
( NULL
, $1 ); }
656 | m_exprs
',' m_expr
{ $$
= append_expr
( $1, $3 ); }
660 exprs: { $$ = make_expr(EXPR_VOID); }
665 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
669 m_expr: { $$
= make_expr
(EXPR_VOID
); }
673 expr: aNUM
{ $$
= make_exprl
(EXPR_NUM
, $1); }
674 | aHEXNUM
{ $$
= make_exprl
(EXPR_HEXNUM
, $1); }
675 | aDOUBLE
{ $$
= make_exprd
(EXPR_DOUBLE
, $1); }
676 | tFALSE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 0); }
677 | tNULL
{ $$
= make_exprl
(EXPR_NUM
, 0); }
678 | tTRUE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 1); }
679 | aSTRING
{ $$
= make_exprs
(EXPR_STRLIT
, $1); }
680 | aWSTRING
{ $$
= make_exprs
(EXPR_WSTRLIT
, $1); }
681 | aIDENTIFIER
{ $$
= make_exprs
(EXPR_IDENTIFIER
, $1); }
682 | expr
'?' expr
':' expr
{ $$
= make_expr3
(EXPR_COND
, $1, $3, $5); }
683 | expr LOGICALOR expr
{ $$
= make_expr2
(EXPR_LOGOR
, $1, $3); }
684 | expr LOGICALAND expr
{ $$
= make_expr2
(EXPR_LOGAND
, $1, $3); }
685 | expr
'|' expr
{ $$
= make_expr2
(EXPR_OR
, $1, $3); }
686 | expr
'^' expr
{ $$
= make_expr2
(EXPR_XOR
, $1, $3); }
687 | expr
'&' expr
{ $$
= make_expr2
(EXPR_AND
, $1, $3); }
688 | expr EQUALITY expr
{ $$
= make_expr2
(EXPR_EQUALITY
, $1, $3); }
689 | expr INEQUALITY expr
{ $$
= make_expr2
(EXPR_INEQUALITY
, $1, $3); }
690 | expr
'>' expr
{ $$
= make_expr2
(EXPR_GTR
, $1, $3); }
691 | expr
'<' expr
{ $$
= make_expr2
(EXPR_LESS
, $1, $3); }
692 | expr GREATEREQUAL expr
{ $$
= make_expr2
(EXPR_GTREQL
, $1, $3); }
693 | expr LESSEQUAL expr
{ $$
= make_expr2
(EXPR_LESSEQL
, $1, $3); }
694 | expr SHL expr
{ $$
= make_expr2
(EXPR_SHL
, $1, $3); }
695 | expr SHR expr
{ $$
= make_expr2
(EXPR_SHR
, $1, $3); }
696 | expr
'+' expr
{ $$
= make_expr2
(EXPR_ADD
, $1, $3); }
697 | expr
'-' expr
{ $$
= make_expr2
(EXPR_SUB
, $1, $3); }
698 | expr
'%' expr
{ $$
= make_expr2
(EXPR_MOD
, $1, $3); }
699 | expr
'*' expr
{ $$
= make_expr2
(EXPR_MUL
, $1, $3); }
700 | expr
'/' expr
{ $$
= make_expr2
(EXPR_DIV
, $1, $3); }
701 |
'!' expr
{ $$
= make_expr1
(EXPR_LOGNOT
, $2); }
702 |
'~' expr
{ $$
= make_expr1
(EXPR_NOT
, $2); }
703 |
'+' expr %prec POS
{ $$
= make_expr1
(EXPR_POS
, $2); }
704 |
'-' expr %prec NEG
{ $$
= make_expr1
(EXPR_NEG
, $2); }
705 |
'&' expr %prec ADDRESSOF
{ $$
= make_expr1
(EXPR_ADDRESSOF
, $2); }
706 |
'*' expr %prec PPTR
{ $$
= make_expr1
(EXPR_PPTR
, $2); }
707 | expr MEMBERPTR aIDENTIFIER
{ $$
= make_expr2
(EXPR_MEMBER
, make_expr1
(EXPR_PPTR
, $1), make_exprs
(EXPR_IDENTIFIER
, $3)); }
708 | expr
'.' aIDENTIFIER
{ $$
= make_expr2
(EXPR_MEMBER
, $1, make_exprs
(EXPR_IDENTIFIER
, $3)); }
709 |
'(' type
')' expr %prec CAST
{ $$
= make_exprt
(EXPR_CAST
, $2, $4); }
710 | tSIZEOF
'(' type
')' { $$
= make_exprt
(EXPR_SIZEOF
, $3, NULL
); }
711 | expr
'[' expr
']' { $$
= make_expr2
(EXPR_ARRAY
, $1, $3); }
712 |
'(' expr
')' { $$
= $2; }
715 expr_list_int_const: expr_int_const
{ $$
= append_expr
( NULL
, $1 ); }
716 | expr_list_int_const
',' expr_int_const
{ $$
= append_expr
( $1, $3 ); }
719 expr_int_const: expr
{ $$
= $1;
721 error_loc
("expression is not an integer constant\n");
725 expr_const: expr
{ $$
= $1;
726 if
(!$$
->is_const
&& $$
->type
!= EXPR_STRLIT
&& $$
->type
!= EXPR_WSTRLIT
)
727 error_loc
("expression is not constant\n");
731 fields: { $$
= NULL
; }
732 | fields field
{ $$
= append_var_list
($1, $2); }
735 field: m_attributes decl_spec declarator_list
';'
736 { const char *first
= LIST_ENTRY
(list_head
($3), declarator_t
, entry
)->var
->name
;
737 check_field_attrs
(first
, $1);
738 $$
= set_var_types
($1, $2, $3);
740 | m_attributes uniondef
';' { var_t
*v
= make_var
(NULL
);
741 v
->type
= $2; v
->attrs
= $1;
742 $$
= append_var
(NULL
, v
);
747 s_field
';' { $$
= $1; }
748 | attributes
';' { $$
= make_var
(NULL
); $$
->attrs
= $1; }
751 ne_union_fields: { $$
= NULL
; }
752 | ne_union_fields ne_union_field
{ $$
= append_var
( $1, $2 ); }
756 s_field
';' { $$
= $1; }
760 s_field: m_attributes decl_spec declarator
{ $$
= $3->var
;
761 $$
->attrs
= check_field_attrs
($$
->name
, $1);
762 set_type
($$
, $2, $3, FALSE
);
768 m_attributes decl_spec declarator
{ var_t
*v
= $3->var
;
769 v
->attrs
= check_function_attrs
(v
->name
, $1);
770 set_type
(v
, $2, $3, FALSE
);
777 attributes decl_spec init_declarator
780 set_type
($$
, $2, $3, FALSE
);
783 | decl_spec init_declarator
{ $$
= $2->var
;
784 set_type
($$
, $1, $2, FALSE
);
789 m_ident: { $$
= NULL
; }
793 t_ident: { $$
= NULL
; }
794 | aIDENTIFIER
{ $$
= make_var
($1); }
795 | aKNOWNTYPE
{ $$
= make_var
($1); }
798 ident: aIDENTIFIER
{ $$
= make_var
($1); }
799 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
800 | aKNOWNTYPE
{ $$
= make_var
($
<str
>1); }
803 base_type: tBYTE
{ $$
= make_builtin
($
<str
>1); }
804 | tWCHAR
{ $$
= make_builtin
($
<str
>1); }
806 | tSIGNED int_std
{ $$
= $2; $$
->sign
= 1; }
807 | tUNSIGNED int_std
{ $$
= $2; $$
->sign
= -1;
809 case RPC_FC_CHAR
: break
;
810 case RPC_FC_SMALL
: $$
->type
= RPC_FC_USMALL
; break
;
811 case RPC_FC_SHORT
: $$
->type
= RPC_FC_USHORT
; break
;
812 case RPC_FC_LONG
: $$
->type
= RPC_FC_ULONG
; break
;
814 if
($$
->name
[0] == 'h') /* hyper, as opposed to __int64 */
816 $$
= alias
($$
, "MIDL_uhyper");
823 | tUNSIGNED
{ $$
= make_int
(-1); }
824 | tFLOAT
{ $$
= make_builtin
($
<str
>1); }
825 | tSINGLE
{ $$
= find_type
("float", 0); }
826 | tDOUBLE
{ $$
= make_builtin
($
<str
>1); }
827 | tBOOLEAN
{ $$
= make_builtin
($
<str
>1); }
828 | tERRORSTATUST
{ $$
= make_builtin
($
<str
>1); }
829 | tHANDLET
{ $$
= make_builtin
($
<str
>1); }
836 int_std: tINT
{ $$
= make_builtin
($
<str
>1); }
837 | tSHORT m_int
{ $$
= make_builtin
($
<str
>1); }
838 | tSMALL
{ $$
= make_builtin
($
<str
>1); }
839 | tLONG m_int
{ $$
= make_builtin
($
<str
>1); }
840 | tHYPER m_int
{ $$
= make_builtin
($
<str
>1); }
841 | tINT64
{ $$
= make_builtin
($
<str
>1); }
842 | tCHAR
{ $$
= make_builtin
($
<str
>1); }
845 coclass: tCOCLASS aIDENTIFIER
{ $$
= make_class
($2); }
846 | tCOCLASS aKNOWNTYPE
{ $$
= find_type
($2, 0);
847 if
($$
->kind
!= TKIND_COCLASS
)
848 error_loc
("%s was not declared a coclass at %s:%d\n",
849 $2, $$
->loc_info.input_name
,
850 $$
->loc_info.line_number
);
854 coclasshdr: attributes coclass
{ $$
= $2;
856 $$
->attrs
= check_coclass_attrs
($2->name
, $1);
857 if
(!parse_only
&& do_header
)
859 if
(!parse_only
&& do_idfile
)
864 coclassdef: coclasshdr
'{' coclass_ints
'}' semicolon_opt
871 coclass_ints: { $$
= NULL
; }
872 | coclass_ints coclass_int
{ $$
= append_ifref
( $1, $2 ); }
876 m_attributes interfacedec
{ $$
= make_ifref
($2); $$
->attrs
= $1; }
879 dispinterface: tDISPINTERFACE aIDENTIFIER
{ $$
= get_type
(RPC_FC_IP
, $2, 0); $$
->kind
= TKIND_DISPATCH
; }
880 | tDISPINTERFACE aKNOWNTYPE
{ $$
= get_type
(RPC_FC_IP
, $2, 0); $$
->kind
= TKIND_DISPATCH
; }
883 dispinterfacehdr: attributes dispinterface
{ attr_t
*attrs
;
884 is_in_interface
= TRUE
;
885 is_object_interface
= TRUE
;
888 attrs
= make_attr
(ATTR_DISPINTERFACE
);
889 $$
->attrs
= append_attr
( check_dispiface_attrs
($2->name
, $1), attrs
);
890 $$
->ref
= find_type
("IDispatch", 0);
891 if
(!$$
->ref
) error_loc
("IDispatch is undefined\n");
893 if
(!parse_only
&& do_header
) write_forward
($$
);
897 dispint_props: tPROPERTIES
':' { $$
= NULL
; }
898 | dispint_props s_field
';' { $$
= append_var
( $1, $2 ); }
901 dispint_meths: tMETHODS
':' { $$
= NULL
; }
902 | dispint_meths funcdef
';' { $$
= append_func
( $1, $2 ); }
905 dispinterfacedef: dispinterfacehdr
'{'
909 $$
->fields_or_args
= $3;
911 if
(!parse_only
&& do_header
) write_interface
($$
);
912 if
(!parse_only
&& do_idfile
) write_diid
($$
);
913 is_in_interface
= FALSE
;
916 '{' interface
';' '}' { $$
= $1;
917 $$
->fields_or_args
= $3->fields_or_args
;
918 $$
->funcs
= $3->funcs
;
919 if
(!parse_only
&& do_header
) write_interface
($$
);
920 if
(!parse_only
&& do_idfile
) write_diid
($$
);
921 is_in_interface
= FALSE
;
925 inherit: { $$
= NULL
; }
926 |
':' aKNOWNTYPE
{ $$
= find_type_or_error2
($2, 0); }
929 interface: tINTERFACE aIDENTIFIER
{ $$
= get_type
(RPC_FC_IP
, $2, 0); $$
->kind
= TKIND_INTERFACE
; }
930 | tINTERFACE aKNOWNTYPE
{ $$
= get_type
(RPC_FC_IP
, $2, 0); $$
->kind
= TKIND_INTERFACE
; }
933 interfacehdr: attributes interface
{ $$.interface
= $2;
934 $$.old_pointer_default
= pointer_default
;
935 if
(is_attr
($1, ATTR_POINTERDEFAULT
))
936 pointer_default
= get_attrv
($1, ATTR_POINTERDEFAULT
);
937 is_object_interface
= is_object
($1);
938 is_in_interface
= TRUE
;
940 $2->attrs
= check_iface_attrs
($2->name
, $1);
942 if
(!parse_only
&& do_header
) write_forward
($2);
946 interfacedef: interfacehdr inherit
947 '{' int_statements
'}' semicolon_opt
{ $$
= $1.interface
;
951 compute_method_indexes
($$
);
952 if
(!parse_only
&& do_header
) write_interface
($$
);
953 if
(!parse_only
&& local_stubs
) write_locals
(local_stubs
, $$
, TRUE
);
954 if
(!parse_only
&& do_idfile
) write_iid
($$
);
955 pointer_default
= $1.old_pointer_default
;
956 is_in_interface
= FALSE
;
958 /* MIDL is able to import the definition of a base class from inside the
959 * definition of a derived class, I'll try to support it with this rule */
960 | interfacehdr
':' aIDENTIFIER
961 '{' import int_statements
'}'
962 semicolon_opt
{ $$
= $1.interface
;
963 $$
->ref
= find_type_or_error2
($3, 0);
964 if
(!$$
->ref
) error_loc
("base class '%s' not found in import\n", $3);
966 compute_method_indexes
($$
);
967 if
(!parse_only
&& do_header
) write_interface
($$
);
968 if
(!parse_only
&& local_stubs
) write_locals
(local_stubs
, $$
, TRUE
);
969 if
(!parse_only
&& do_idfile
) write_iid
($$
);
970 pointer_default
= $1.old_pointer_default
;
971 is_in_interface
= FALSE
;
973 | dispinterfacedef semicolon_opt
{ $$
= $1; }
977 interface
';' { $$
= $1; if
(!parse_only
&& do_header
) write_forward
($$
); }
978 | dispinterface
';' { $$
= $1; if
(!parse_only
&& do_header
) write_forward
($$
); }
981 module: tMODULE aIDENTIFIER
{ $$
= make_type
(0, NULL
); $$
->name
= $2; $$
->kind
= TKIND_MODULE
; }
982 | tMODULE aKNOWNTYPE
{ $$
= make_type
(0, NULL
); $$
->name
= $2; $$
->kind
= TKIND_MODULE
; }
985 modulehdr: attributes module
{ $$
= $2;
986 $$
->attrs
= check_module_attrs
($2->name
, $1);
990 moduledef: modulehdr
'{' int_statements
'}'
991 semicolon_opt
{ $$
= $1;
993 /* FIXME: if (!parse_only && do_header) write_module($$); */
998 tEXTERN
{ $$
= STG_EXTERN
; }
999 | tSTATIC
{ $$
= STG_STATIC
; }
1000 | tREGISTER
{ $$
= STG_REGISTER
; }
1004 tINLINE
{ $$
= make_attr
(ATTR_INLINE
); }
1008 tCONST
{ $$
= make_attr
(ATTR_CONST
); }
1011 m_type_qual_list: { $$
= NULL
; }
1012 | m_type_qual_list type_qualifier
{ $$
= append_attr
($1, $2); }
1015 decl_spec: type m_decl_spec_no_type
{ $$
= make_decl_spec
($1, $2, NULL
, NULL
, STG_NONE
); }
1016 | decl_spec_no_type type m_decl_spec_no_type
1017 { $$
= make_decl_spec
($2, $1, $3, NULL
, STG_NONE
); }
1020 m_decl_spec_no_type: { $$
= NULL
; }
1025 type_qualifier m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, $1, STG_NONE
); }
1026 | function_specifier m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, $1, STG_NONE
); }
1027 | storage_cls_spec m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, NULL
, $1); }
1031 '*' m_type_qual_list declarator %prec PPTR
1032 { $$
= $3; $$
->type
= append_ptrchain_type
($$
->type
, make_pointer_type
(NULL
, $2)); }
1033 | callconv declarator
{ $$
= $2; $$
->type
->attrs
= append_attr
($$
->type
->attrs
, make_attrp
(ATTR_CALLCONV
, $1)); }
1038 ident
{ $$
= make_declarator
($1); }
1039 |
'(' declarator
')' { $$
= $2; }
1040 | direct_declarator array
{ $$
= $1; $$
->array
= append_array
($$
->array
, $2); }
1041 | direct_declarator
'(' m_args
')' { $$
= $1;
1042 $$
->func_type
= append_ptrchain_type
($$
->type
, make_func_type
($3));
1048 declarator
{ $$
= append_declarator
( NULL
, $1 ); }
1049 | declarator_list
',' declarator
{ $$
= append_declarator
( $1, $3 ); }
1053 declarator
{ $$
= $1; }
1054 | declarator
'=' expr_const
{ $$
= $1; $1->var
->eval
= $3; }
1058 tREF
{ $$
= RPC_FC_RP
; }
1059 | tUNIQUE
{ $$
= RPC_FC_UP
; }
1060 | tPTR
{ $$
= RPC_FC_FP
; }
1063 structdef: tSTRUCT t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_STRUCT
, $2, tsSTRUCT
);
1064 /* overwrite RPC_FC_STRUCT with a more exact type */
1066 $$
->type
= get_struct_type
( $4 );
1067 $$
->kind
= TKIND_RECORD
;
1068 $$
->fields_or_args
= $4;
1071 add_typelib_entry
($$
);
1075 type: tVOID
{ $$
= find_type_or_error
("void", 0); }
1076 | aKNOWNTYPE
{ $$
= find_type_or_error
($1, 0); }
1077 | base_type
{ $$
= $1; }
1078 | enumdef
{ $$
= $1; }
1079 | tENUM aIDENTIFIER
{ $$
= find_type_or_error2
($2, tsENUM
); }
1080 | structdef
{ $$
= $1; }
1081 | tSTRUCT aIDENTIFIER
{ $$
= get_type
(RPC_FC_STRUCT
, $2, tsSTRUCT
); }
1082 | uniondef
{ $$
= $1; }
1083 | tUNION aIDENTIFIER
{ $$
= find_type_or_error2
($2, tsUNION
); }
1084 | tSAFEARRAY
'(' type
')' { $$
= make_safearray
($3); }
1087 typedef: tTYPEDEF m_attributes decl_spec declarator_list
1088 { reg_typedefs
($3, $4, check_typedef_attrs
($2));
1089 $$
= process_typedefs
($4);
1093 uniondef: tUNION t_ident
'{' ne_union_fields
'}'
1094 { $$
= get_typev
(RPC_FC_NON_ENCAPSULATED_UNION
, $2, tsUNION
);
1096 $$
->kind
= TKIND_UNION
;
1097 $$
->fields_or_args
= $4;
1101 tSWITCH
'(' s_field
')'
1102 m_ident
'{' cases
'}' { var_t
*u
= $7;
1103 $$
= get_typev
(RPC_FC_ENCAPSULATED_UNION
, $2, tsUNION
);
1105 $$
->kind
= TKIND_UNION
;
1106 if
(!u
) u
= make_var
( xstrdup
("tagged_union") );
1107 u
->type
= make_type
(RPC_FC_NON_ENCAPSULATED_UNION
, NULL
);
1108 u
->type
->kind
= TKIND_UNION
;
1109 u
->type
->fields_or_args
= $9;
1110 u
->type
->defined
= TRUE
;
1111 $$
->fields_or_args
= append_var
( $$
->fields_or_args
, $5 );
1112 $$
->fields_or_args
= append_var
( $$
->fields_or_args
, u
);
1118 aNUM
{ $$
= MAKEVERSION
($1, 0); }
1119 | aNUM
'.' aNUM
{ $$
= MAKEVERSION
($1, $3); }
1124 static void decl_builtin
(const char *name
, unsigned char type
)
1126 type_t
*t
= make_type
(type
, NULL
);
1127 t
->name
= xstrdup
(name
);
1128 reg_type
(t
, name
, 0);
1131 static type_t
*make_builtin
(char *name
)
1133 /* NAME is strdup'd in the lexer */
1134 type_t
*t
= duptype
(find_type_or_error
(name
, 0), 0);
1139 static type_t
*make_int
(int sign
)
1141 type_t
*t
= duptype
(find_type_or_error
("int", 0), 1);
1145 t
->type
= t
->type
== RPC_FC_LONG ? RPC_FC_ULONG
: RPC_FC_USHORT
;
1150 void init_types
(void)
1152 decl_builtin
("void", 0);
1153 decl_builtin
("byte", RPC_FC_BYTE
);
1154 decl_builtin
("wchar_t", RPC_FC_WCHAR
);
1155 decl_builtin
("int", RPC_FC_LONG
); /* win32 */
1156 decl_builtin
("short", RPC_FC_SHORT
);
1157 decl_builtin
("small", RPC_FC_SMALL
);
1158 decl_builtin
("long", RPC_FC_LONG
);
1159 decl_builtin
("hyper", RPC_FC_HYPER
);
1160 decl_builtin
("__int64", RPC_FC_HYPER
);
1161 decl_builtin
("char", RPC_FC_CHAR
);
1162 decl_builtin
("float", RPC_FC_FLOAT
);
1163 decl_builtin
("double", RPC_FC_DOUBLE
);
1164 decl_builtin
("boolean", RPC_FC_BYTE
);
1165 decl_builtin
("error_status_t", RPC_FC_ERROR_STATUS_T
);
1166 decl_builtin
("handle_t", RPC_FC_BIND_PRIMITIVE
);
1169 static str_list_t
*append_str
(str_list_t
*list
, char *str
)
1171 struct str_list_entry_t
*entry
;
1173 if
(!str
) return list
;
1176 list
= xmalloc
( sizeof
(*list
) );
1179 entry
= xmalloc
( sizeof
(*entry
) );
1181 list_add_tail
( list
, &entry
->entry
);
1185 static attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
)
1187 attr_t
*attr_existing
;
1188 if
(!attr
) return list
;
1191 list
= xmalloc
( sizeof
(*list
) );
1194 LIST_FOR_EACH_ENTRY
(attr_existing
, list
, attr_t
, entry
)
1195 if
(attr_existing
->type
== attr
->type
)
1197 parser_warning
("duplicate attribute %s\n", get_attr_display_name
(attr
->type
));
1198 /* use the last attribute, like MIDL does */
1199 list_remove
(&attr_existing
->entry
);
1202 list_add_tail
( list
, &attr
->entry
);
1206 static attr_list_t
*move_attr
(attr_list_t
*dst
, attr_list_t
*src
, enum attr_type type
)
1209 if
(!src
) return dst
;
1210 LIST_FOR_EACH_ENTRY
(attr
, src
, attr_t
, entry
)
1211 if
(attr
->type
== type
)
1213 list_remove
(&attr
->entry
);
1214 return append_attr
(dst
, attr
);
1219 static attr_list_t
*append_attr_list
(attr_list_t
*new_list
, attr_list_t
*old_list
)
1223 if
(!old_list
) return new_list
;
1225 while
((entry
= list_head
(old_list
)))
1227 attr_t
*attr
= LIST_ENTRY
(entry
, attr_t
, entry
);
1229 new_list
= append_attr
(new_list
, attr
);
1234 static attr_list_t
*dupattrs
(const attr_list_t
*list
)
1236 attr_list_t
*new_list
;
1239 if
(!list
) return NULL
;
1241 new_list
= xmalloc
( sizeof
(*list
) );
1242 list_init
( new_list
);
1243 LIST_FOR_EACH_ENTRY
(attr
, list
, const attr_t
, entry
)
1245 attr_t
*new_attr
= xmalloc
(sizeof
(*new_attr
));
1247 list_add_tail
(new_list
, &new_attr
->entry
);
1252 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
)
1254 decl_spec_t
*declspec
= left ? left
: right
;
1257 declspec
= xmalloc
(sizeof
(*declspec
));
1258 declspec
->type
= NULL
;
1259 declspec
->attrs
= NULL
;
1260 declspec
->stgclass
= STG_NONE
;
1262 declspec
->type
= type
;
1263 if
(left
&& declspec
!= left
)
1265 declspec
->attrs
= append_attr_list
(declspec
->attrs
, left
->attrs
);
1266 if
(declspec
->stgclass
== STG_NONE
)
1267 declspec
->stgclass
= left
->stgclass
;
1268 else if
(left
->stgclass
!= STG_NONE
)
1269 error_loc
("only one storage class can be specified\n");
1270 assert
(!left
->type
);
1273 if
(right
&& declspec
!= right
)
1275 declspec
->attrs
= append_attr_list
(declspec
->attrs
, right
->attrs
);
1276 if
(declspec
->stgclass
== STG_NONE
)
1277 declspec
->stgclass
= right
->stgclass
;
1278 else if
(right
->stgclass
!= STG_NONE
)
1279 error_loc
("only one storage class can be specified\n");
1280 assert
(!right
->type
);
1284 declspec
->attrs
= append_attr
(declspec
->attrs
, attr
);
1285 if
(declspec
->stgclass
== STG_NONE
)
1286 declspec
->stgclass
= stgclass
;
1287 else if
(stgclass
!= STG_NONE
)
1288 error_loc
("only one storage class can be specified\n");
1290 /* apply attributes to type */
1291 if
(type
&& declspec
->attrs
)
1294 declspec
->type
= duptype
(type
, 1);
1295 attrs
= dupattrs
(type
->attrs
);
1296 declspec
->type
->attrs
= append_attr_list
(attrs
, declspec
->attrs
);
1297 declspec
->attrs
= NULL
;
1303 static attr_t
*make_attr
(enum attr_type type
)
1305 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1311 static attr_t
*make_attrv
(enum attr_type type
, unsigned long val
)
1313 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1319 static attr_t
*make_attrp
(enum attr_type type
, void *val
)
1321 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1327 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
)
1329 if
(!expr
) return list
;
1332 list
= xmalloc
( sizeof
(*list
) );
1335 list_add_tail
( list
, &expr
->entry
);
1339 static array_dims_t
*append_array
(array_dims_t
*list
, expr_t
*expr
)
1341 if
(!expr
) return list
;
1344 list
= xmalloc
( sizeof
(*list
) );
1347 list_add_tail
( list
, &expr
->entry
);
1351 static struct list type_pool
= LIST_INIT
(type_pool
);
1358 type_t
*alloc_type
(void)
1360 type_pool_node_t
*node
= xmalloc
(sizeof
*node
);
1361 list_add_tail
(&type_pool
, &node
->link
);
1365 void set_all_tfswrite
(int val
)
1367 type_pool_node_t
*node
;
1368 LIST_FOR_EACH_ENTRY
(node
, &type_pool
, type_pool_node_t
, link
)
1369 node
->data.tfswrite
= val
;
1372 type_t
*make_type
(unsigned char type
, type_t
*ref
)
1374 type_t
*t
= alloc_type
();
1376 t
->kind
= TKIND_PRIMITIVE
;
1382 t
->fields_or_args
= NULL
;
1386 t
->length_is
= NULL
;
1387 t
->typestring_offset
= 0;
1389 t
->declarray
= FALSE
;
1390 t
->ignore
= (parse_only
!= 0);
1394 t
->user_types_registered
= FALSE
;
1395 t
->tfswrite
= FALSE
;
1397 t
->typelib_idx
= -1;
1398 init_loc_info
(&t
->loc_info
);
1402 static type_t
*make_func_type
(var_list_t
*args
)
1404 type_t
*t
= make_type
(RPC_FC_FUNCTION
, NULL
);
1405 t
->fields_or_args
= args
;
1409 static type_t
*make_pointer_type
(type_t
*ref
, attr_list_t
*attrs
)
1411 type_t
*t
= make_type
(pointer_default
, ref
);
1416 static type_t
*append_ptrchain_type
(type_t
*ptrchain
, type_t
*type
)
1418 type_t
*ptrchain_type
;
1421 for
(ptrchain_type
= ptrchain
; ptrchain_type
->ref
; ptrchain_type
= ptrchain_type
->ref
)
1423 ptrchain_type
->ref
= type
;
1427 static void set_type
(var_t
*v
, decl_spec_t
*decl_spec
, const declarator_t
*decl
,
1430 expr_list_t
*sizes
= get_attrp
(v
->attrs
, ATTR_SIZEIS
);
1431 expr_list_t
*lengs
= get_attrp
(v
->attrs
, ATTR_LENGTHIS
);
1432 int sizeless
, has_varconf
;
1434 type_t
*atype
, **ptype
;
1435 array_dims_t
*arr
= decl ? decl
->array
: NULL
;
1436 type_t
*func_type
= decl ? decl
->func_type
: NULL
;
1437 type_t
*type
= decl_spec
->type
;
1439 if
(is_attr
(type
->attrs
, ATTR_INLINE
))
1442 error_loc
("inline attribute applied to non-function type\n");
1446 /* move inline attribute from return type node to function node */
1447 for
(t
= func_type
; is_ptr
(t
); t
= t
->ref
)
1449 t
->attrs
= move_attr
(t
->attrs
, type
->attrs
, ATTR_INLINE
);
1453 /* add type onto the end of the pointers in pident->type */
1454 v
->type
= append_ptrchain_type
(decl ? decl
->type
: NULL
, type
);
1455 v
->stgclass
= decl_spec
->stgclass
;
1457 /* the highest level of pointer specified should default to the var's ptr attr
1458 * or (RPC_FC_RP if not specified and it's a top level ptr), not
1459 * pointer_default so we need to fix that up here */
1462 int ptr_attr
= get_attrv
(v
->attrs
, ATTR_POINTERTYPE
);
1463 const type_t
*ptr
= NULL
;
1464 /* pointer attributes on the left side of the type belong to the function
1465 * pointer, if one is being declared */
1466 type_t
**pt
= func_type ?
&func_type
: &v
->type
;
1467 for
(ptr
= *pt
; ptr
&& !ptr_attr
; )
1469 ptr_attr
= get_attrv
(ptr
->attrs
, ATTR_POINTERTYPE
);
1470 if
(!ptr_attr
&& ptr
->kind
== TKIND_ALIAS
)
1475 if
(ptr
&& is_ptr
(ptr
) && (ptr_attr || top
))
1477 /* duplicate type to avoid changing original type */
1478 *pt
= duptype
(*pt
, 1);
1479 (*pt
)->type
= ptr_attr ? ptr_attr
: RPC_FC_RP
;
1482 error_loc
("%s: pointer attribute applied to non-pointer type\n", v
->name
);
1485 if
(is_attr
(v
->attrs
, ATTR_STRING
) && !is_ptr
(v
->type
) && !arr
)
1486 error_loc
("'%s': [string] attribute applied to non-pointer, non-array type\n",
1489 if
(is_attr
(v
->attrs
, ATTR_V1ENUM
))
1491 if
(v
->type
->type
== RPC_FC_ENUM16
)
1492 v
->type
->type
= RPC_FC_ENUM32
;
1494 error_loc
("'%s': [v1_enum] attribute applied to non-enum type\n", v
->name
);
1498 if
(arr
) LIST_FOR_EACH_ENTRY_REV
(dim
, arr
, expr_t
, entry
)
1501 error_loc
("%s: only the first array dimension can be unspecified\n", v
->name
);
1505 unsigned int align
= 0;
1506 size_t size
= type_memsize
(v
->type
, &align
);
1509 error_loc
("%s: array dimension must be positive\n", v
->name
);
1511 if
(0xffffffffuL
/ size
< (unsigned long) dim
->cval
)
1512 error_loc
("%s: total array size is too large\n", v
->name
);
1513 else if
(0xffffuL
< size
* dim
->cval
)
1514 v
->type
= make_type
(RPC_FC_LGFARRAY
, v
->type
);
1516 v
->type
= make_type
(RPC_FC_SMFARRAY
, v
->type
);
1521 v
->type
= make_type
(RPC_FC_CARRAY
, v
->type
);
1524 v
->type
->declarray
= TRUE
;
1525 v
->type
->dim
= dim
->cval
;
1529 has_varconf
= FALSE
;
1530 if
(sizes
) LIST_FOR_EACH_ENTRY
(dim
, sizes
, expr_t
, entry
)
1532 if
(dim
->type
!= EXPR_VOID
)
1535 atype
= *ptype
= duptype
(*ptype
, 0);
1537 if
(atype
->type
== RPC_FC_SMFARRAY || atype
->type
== RPC_FC_LGFARRAY
)
1538 error_loc
("%s: cannot specify size_is for a fixed sized array\n", v
->name
);
1540 if
(atype
->type
!= RPC_FC_CARRAY
&& !is_ptr
(atype
))
1541 error_loc
("%s: size_is attribute applied to illegal type\n", v
->name
);
1543 atype
->type
= RPC_FC_CARRAY
;
1544 atype
->size_is
= dim
;
1547 ptype
= &(*ptype
)->ref
;
1549 error_loc
("%s: too many expressions in size_is attribute\n", v
->name
);
1553 if
(lengs
) LIST_FOR_EACH_ENTRY
(dim
, lengs
, expr_t
, entry
)
1555 if
(dim
->type
!= EXPR_VOID
)
1558 atype
= *ptype
= duptype
(*ptype
, 0);
1560 if
(atype
->type
== RPC_FC_SMFARRAY
)
1561 atype
->type
= RPC_FC_SMVARRAY
;
1562 else if
(atype
->type
== RPC_FC_LGFARRAY
)
1563 atype
->type
= RPC_FC_LGVARRAY
;
1564 else if
(atype
->type
== RPC_FC_CARRAY
)
1565 atype
->type
= RPC_FC_CVARRAY
;
1567 error_loc
("%s: length_is attribute applied to illegal type\n", v
->name
);
1569 atype
->length_is
= dim
;
1572 ptype
= &(*ptype
)->ref
;
1574 error_loc
("%s: too many expressions in length_is attribute\n", v
->name
);
1577 if
(has_varconf
&& !last_array
(v
->type
))
1580 for
(ptype
= &v
->type
; is_array
(*ptype
); ptype
= &(*ptype
)->ref
)
1582 *ptype
= duptype
(*ptype
, 0);
1583 (*ptype
)->type
= RPC_FC_BOGUS_ARRAY
;
1587 if
(is_array
(v
->type
))
1589 const type_t
*rt
= v
->type
->ref
;
1590 if
(is_user_type
(rt
))
1591 v
->type
->type
= RPC_FC_BOGUS_ARRAY
;
1595 case RPC_FC_BOGUS_STRUCT
:
1596 case RPC_FC_NON_ENCAPSULATED_UNION
:
1597 case RPC_FC_ENCAPSULATED_UNION
:
1599 v
->type
->type
= RPC_FC_BOGUS_ARRAY
;
1601 /* FC_RP should be above, but widl overuses these, and will break things. */
1604 if
(rt
->ref
->type
== RPC_FC_IP
)
1605 v
->type
->type
= RPC_FC_BOGUS_ARRAY
;
1610 /* v->type is currently pointing to the type on the left-side of the
1611 * declaration, so we need to fix this up so that it is the return type of the
1612 * function and make v->type point to the function side of the declaration */
1616 type_t
*return_type
= v
->type
;
1617 v
->type
= func_type
;
1618 for
(ft
= v
->type
; is_ptr
(ft
); ft
= ft
->ref
)
1620 assert
(ft
->type
== RPC_FC_FUNCTION
);
1621 ft
->ref
= return_type
;
1622 /* move calling convention attribute, if present, from pointer nodes to
1624 for
(t
= v
->type
; is_ptr
(t
); t
= t
->ref
)
1625 ft
->attrs
= move_attr
(ft
->attrs
, t
->attrs
, ATTR_CALLCONV
);
1626 if
(is_object_interface
&& !is_attr
(ft
->attrs
, ATTR_CALLCONV
))
1628 static char *stdmethodcalltype
;
1629 if
(!stdmethodcalltype
) stdmethodcalltype
= strdup
("STDMETHODCALLTYPE");
1630 ft
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, stdmethodcalltype
));
1636 for
(t
= v
->type
; is_ptr
(t
); t
= t
->ref
)
1637 if
(is_attr
(t
->attrs
, ATTR_CALLCONV
))
1638 error_loc
("calling convention applied to non-function-pointer type\n");
1642 static var_list_t
*set_var_types
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_list_t
*decls
)
1644 declarator_t
*decl
, *next
;
1645 var_list_t
*var_list
= NULL
;
1647 LIST_FOR_EACH_ENTRY_SAFE
( decl
, next
, decls
, declarator_t
, entry
)
1649 var_t
*var
= decl
->var
;
1652 set_type
(var
, decl_spec
, decl
, 0);
1653 var_list
= append_var
(var_list
, var
);
1659 static ifref_list_t
*append_ifref
(ifref_list_t
*list
, ifref_t
*iface
)
1661 if
(!iface
) return list
;
1664 list
= xmalloc
( sizeof
(*list
) );
1667 list_add_tail
( list
, &iface
->entry
);
1671 static ifref_t
*make_ifref
(type_t
*iface
)
1673 ifref_t
*l
= xmalloc
(sizeof
(ifref_t
));
1679 static var_list_t
*append_var
(var_list_t
*list
, var_t
*var
)
1681 if
(!var
) return list
;
1684 list
= xmalloc
( sizeof
(*list
) );
1687 list_add_tail
( list
, &var
->entry
);
1691 static var_list_t
*append_var_list
(var_list_t
*list
, var_list_t
*vars
)
1693 if
(!vars
) return list
;
1696 list
= xmalloc
( sizeof
(*list
) );
1699 list_move_tail
( list
, vars
);
1703 static var_t
*make_var
(char *name
)
1705 var_t
*v
= xmalloc
(sizeof
(var_t
));
1710 v
->stgclass
= STG_NONE
;
1711 init_loc_info
(&v
->loc_info
);
1715 static declarator_list_t
*append_declarator
(declarator_list_t
*list
, declarator_t
*d
)
1717 if
(!d
) return list
;
1719 list
= xmalloc
(sizeof
(*list
));
1722 list_add_tail
(list
, &d
->entry
);
1726 static declarator_t
*make_declarator
(var_t
*var
)
1728 declarator_t
*d
= xmalloc
(sizeof
(*d
));
1731 d
->func_type
= NULL
;
1736 static func_list_t
*append_func
(func_list_t
*list
, func_t
*func
)
1738 if
(!func
) return list
;
1741 list
= xmalloc
( sizeof
(*list
) );
1744 list_add_tail
( list
, &func
->entry
);
1748 static func_t
*make_func
(var_t
*def
)
1750 func_t
*f
= xmalloc
(sizeof
(func_t
));
1752 f
->args
= def
->type
->fields_or_args
;
1753 f
->ignore
= parse_only
;
1758 static type_t
*make_class
(char *name
)
1760 type_t
*c
= make_type
(RPC_FC_COCLASS
, NULL
);
1762 c
->kind
= TKIND_COCLASS
;
1766 static type_t
*make_safearray
(type_t
*type
)
1768 type_t
*sa
= find_type_or_error
("SAFEARRAY", 0);
1770 return make_type
(pointer_default
, sa
);
1773 static typelib_t
*make_library
(const char *name
, const attr_list_t
*attrs
)
1775 typelib_t
*typelib
= xmalloc
(sizeof
(*typelib
));
1776 typelib
->name
= xstrdup
(name
);
1777 typelib
->filename
= NULL
;
1778 typelib
->attrs
= attrs
;
1779 list_init
( &typelib
->entries
);
1780 list_init
( &typelib
->importlibs
);
1786 static int hash_ident
(const char *name
)
1788 const char *p
= name
;
1790 /* a simple sum hash is probably good enough */
1795 return sum
& (HASHMAX
-1);
1798 /***** type repository *****/
1807 struct rtype
*type_hash
[HASHMAX
];
1809 static type_t
*reg_type
(type_t
*type
, const char *name
, int t
)
1814 error_loc
("registering named type without name\n");
1817 hash
= hash_ident
(name
);
1818 nt
= xmalloc
(sizeof
(struct rtype
));
1822 nt
->next
= type_hash
[hash
];
1823 type_hash
[hash
] = nt
;
1827 static int is_incomplete
(const type_t
*t
)
1829 return
!t
->defined
&& (is_struct
(t
->type
) || is_union
(t
->type
));
1832 static void add_incomplete
(type_t
*t
)
1834 struct typenode
*tn
= xmalloc
(sizeof
*tn
);
1836 list_add_tail
(&incomplete_types
, &tn
->entry
);
1839 static void fix_type
(type_t
*t
)
1841 if
(t
->kind
== TKIND_ALIAS
&& is_incomplete
(t
)) {
1842 type_t
*ot
= t
->orig
;
1844 t
->fields_or_args
= ot
->fields_or_args
;
1845 t
->defined
= ot
->defined
;
1849 static void fix_incomplete
(void)
1851 struct typenode
*tn
, *next
;
1853 LIST_FOR_EACH_ENTRY_SAFE
(tn
, next
, &incomplete_types
, struct typenode
, entry
) {
1859 static type_t
*reg_typedefs
(decl_spec_t
*decl_spec
, declarator_list_t
*decls
, attr_list_t
*attrs
)
1861 const declarator_t
*decl
;
1862 int is_str
= is_attr
(attrs
, ATTR_STRING
);
1863 type_t
*type
= decl_spec
->type
;
1867 type_t
*t
= decl_spec
->type
;
1874 if
(c
!= RPC_FC_CHAR
&& c
!= RPC_FC_BYTE
&& c
!= RPC_FC_WCHAR
)
1876 decl
= LIST_ENTRY
( list_head
( decls
), const declarator_t
, entry
);
1877 error_loc
("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
1882 /* We must generate names for tagless enum, struct or union.
1883 Typedef-ing a tagless enum, struct or union means we want the typedef
1884 to be included in a library hence the public attribute. */
1885 if
((type
->kind
== TKIND_ENUM || type
->kind
== TKIND_RECORD
1886 || type
->kind
== TKIND_UNION
) && ! type
->name
&& ! parse_only
)
1888 if
(! is_attr
(attrs
, ATTR_PUBLIC
))
1889 attrs
= append_attr
( attrs
, make_attr
(ATTR_PUBLIC
) );
1890 type
->name
= gen_name
();
1892 else if
(is_attr
(attrs
, ATTR_UUID
) && !is_attr
(attrs
, ATTR_PUBLIC
))
1893 attrs
= append_attr
( attrs
, make_attr
(ATTR_PUBLIC
) );
1895 LIST_FOR_EACH_ENTRY
( decl
, decls
, const declarator_t
, entry
)
1897 var_t
*name
= decl
->var
;
1902 cur
= find_type
(name
->name
, 0);
1904 error_loc
("%s: redefinition error; original definition was at %s:%d\n",
1905 cur
->name
, cur
->loc_info.input_name
,
1906 cur
->loc_info.line_number
);
1908 /* set the attributes to allow set_type to do some checks on them */
1909 name
->attrs
= attrs
;
1910 set_type
(name
, decl_spec
, decl
, 0);
1911 cur
= alias
(name
->type
, name
->name
);
1914 if
(is_incomplete
(cur
))
1915 add_incomplete
(cur
);
1916 reg_type
(cur
, cur
->name
, 0);
1922 type_t
*find_type
(const char *name
, int t
)
1924 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
1925 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
1927 return cur ? cur
->type
: NULL
;
1930 static type_t
*find_type_or_error
(const char *name
, int t
)
1932 type_t
*type
= find_type
(name
, t
);
1934 error_loc
("type '%s' not found\n", name
);
1940 static type_t
*find_type_or_error2
(char *name
, int t
)
1942 type_t
*tp
= find_type_or_error
(name
, t
);
1947 int is_type
(const char *name
)
1949 return find_type
(name
, 0) != NULL
;
1952 static type_t
*get_type
(unsigned char type
, char *name
, int t
)
1956 tp
= find_type
(name
, t
);
1962 tp
= make_type
(type
, NULL
);
1964 if
(!name
) return tp
;
1965 return reg_type
(tp
, name
, t
);
1968 static type_t
*get_typev
(unsigned char type
, var_t
*name
, int t
)
1975 return get_type
(type
, sname
, t
);
1978 static int get_struct_type
(var_list_t
*fields
)
1980 int has_pointer
= 0;
1981 int has_conformance
= 0;
1982 int has_variance
= 0;
1985 if
(get_padding
(fields
))
1986 return RPC_FC_BOGUS_STRUCT
;
1988 if
(fields
) LIST_FOR_EACH_ENTRY
( field
, fields
, var_t
, entry
)
1990 type_t
*t
= field
->type
;
1992 if
(is_user_type
(t
))
1993 return RPC_FC_BOGUS_STRUCT
;
2004 case RPC_FC_ENCAPSULATED_UNION
:
2005 case RPC_FC_NON_ENCAPSULATED_UNION
:
2006 case RPC_FC_BOGUS_STRUCT
:
2007 return RPC_FC_BOGUS_STRUCT
;
2014 if
(field
->type
->declarray
)
2016 if
(is_string_type
(field
->attrs
, field
->type
))
2018 if
(is_conformant_array
(field
->type
))
2019 has_conformance
= 1;
2024 if
(is_array
(field
->type
->ref
))
2025 return RPC_FC_BOGUS_STRUCT
;
2027 if
(is_conformant_array
(field
->type
))
2029 has_conformance
= 1;
2030 if
(field
->type
->declarray
&& list_next
(fields
, &field
->entry
))
2031 error_loc
("field '%s' deriving from a conformant array must be the last field in the structure\n",
2034 if
(field
->type
->length_is
)
2037 t
= field
->type
->ref
;
2043 * RPC_FC_BYTE, RPC_FC_STRUCT, etc
2044 * Simple types don't effect the type of struct.
2045 * A struct containing a simple struct is still a simple struct.
2046 * So long as we can block copy the data, we return RPC_FC_STRUCT.
2048 case
0: /* void pointer */
2058 case RPC_FC_INT3264
:
2059 case RPC_FC_UINT3264
:
2072 case RPC_FC_CVARRAY
:
2073 case RPC_FC_BOGUS_ARRAY
:
2078 * Propagate member attributes
2079 * a struct should be at least as complex as its member
2081 case RPC_FC_CVSTRUCT
:
2082 has_conformance
= 1;
2087 case RPC_FC_CPSTRUCT
:
2088 has_conformance
= 1;
2089 if
(list_next
( fields
, &field
->entry
))
2090 error_loc
("field '%s' deriving from a conformant array must be the last field in the structure\n",
2095 case RPC_FC_CSTRUCT
:
2096 has_conformance
= 1;
2097 if
(list_next
( fields
, &field
->entry
))
2098 error_loc
("field '%s' deriving from a conformant array must be the last field in the structure\n",
2102 case RPC_FC_PSTRUCT
:
2107 error_loc
("Unknown struct member %s with type (0x%02x)\n", field
->name
, t
->type
);
2108 /* fallthru - treat it as complex */
2110 /* as soon as we see one of these these members, it's bogus... */
2111 case RPC_FC_ENCAPSULATED_UNION
:
2112 case RPC_FC_NON_ENCAPSULATED_UNION
:
2113 case RPC_FC_BOGUS_STRUCT
:
2115 return RPC_FC_BOGUS_STRUCT
;
2121 if
( has_conformance
)
2122 return RPC_FC_CVSTRUCT
;
2124 return RPC_FC_BOGUS_STRUCT
;
2126 if
( has_conformance
&& has_pointer
)
2127 return RPC_FC_CPSTRUCT
;
2128 if
( has_conformance
)
2129 return RPC_FC_CSTRUCT
;
2131 return RPC_FC_PSTRUCT
;
2132 return RPC_FC_STRUCT
;
2135 /***** constant repository *****/
2140 struct rconst
*next
;
2143 struct rconst
*const_hash
[HASHMAX
];
2145 static var_t
*reg_const
(var_t
*var
)
2150 error_loc
("registering constant without name\n");
2153 hash
= hash_ident
(var
->name
);
2154 nc
= xmalloc
(sizeof
(struct rconst
));
2155 nc
->name
= var
->name
;
2157 nc
->next
= const_hash
[hash
];
2158 const_hash
[hash
] = nc
;
2162 var_t
*find_const
(const char *name
, int f
)
2164 struct rconst
*cur
= const_hash
[hash_ident
(name
)];
2165 while
(cur
&& strcmp
(cur
->name
, name
))
2168 if
(f
) error_loc
("constant '%s' not found\n", name
);
2174 static void write_libid
(const typelib_t
*typelib
)
2176 const UUID
*uuid
= get_attrp
(typelib
->attrs
, ATTR_UUID
);
2177 write_guid
(idfile
, "LIBID", typelib
->name
, uuid
);
2180 static void write_clsid
(type_t
*cls
)
2182 const UUID
*uuid
= get_attrp
(cls
->attrs
, ATTR_UUID
);
2183 write_guid
(idfile
, "CLSID", cls
->name
, uuid
);
2186 static void write_diid
(type_t
*iface
)
2188 const UUID
*uuid
= get_attrp
(iface
->attrs
, ATTR_UUID
);
2189 write_guid
(idfile
, "DIID", iface
->name
, uuid
);
2192 static void write_iid
(type_t
*iface
)
2194 const UUID
*uuid
= get_attrp
(iface
->attrs
, ATTR_UUID
);
2195 write_guid
(idfile
, "IID", iface
->name
, uuid
);
2198 static int compute_method_indexes
(type_t
*iface
)
2204 idx
= compute_method_indexes
(iface
->ref
);
2211 LIST_FOR_EACH_ENTRY
( f
, iface
->funcs
, func_t
, entry
)
2212 if
(! is_callas
(f
->def
->attrs
))
2218 static char *gen_name
(void)
2220 static const char format
[] = "__WIDL_%s_generated_name_%08lX";
2221 static unsigned long n
= 0;
2222 static const char *file_id
;
2228 char *dst
= dup_basename
(input_name
, ".idl");
2232 if
(! isalnum
((unsigned char) *dst
))
2235 size
= sizeof format
- 7 + strlen
(file_id
) + 8;
2238 name
= xmalloc
(size
);
2239 sprintf
(name
, format
, file_id
, n
++);
2245 unsigned int dce_compatible
: 1;
2246 unsigned int acf
: 1;
2247 unsigned int on_interface
: 1;
2248 unsigned int on_function
: 1;
2249 unsigned int on_arg
: 1;
2250 unsigned int on_type
: 1;
2251 unsigned int on_enum
: 1;
2252 unsigned int on_struct
: 1;
2253 unsigned int on_union
: 1;
2254 unsigned int on_field
: 1;
2255 unsigned int on_library
: 1;
2256 unsigned int on_dispinterface
: 1;
2257 unsigned int on_module
: 1;
2258 unsigned int on_coclass
: 1;
2259 const char *display_name
;
2262 struct allowed_attr allowed_attr
[] =
2264 /* attr { D ACF I Fn ARG T En St Un Fi L DI M C <display name> } */
2265 /* ATTR_AGGREGATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "aggregatable" },
2266 /* ATTR_APPOBJECT */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "appobject" },
2267 /* ATTR_ASYNC */ { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "async" },
2268 /* ATTR_AUTO_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "auto_handle" },
2269 /* ATTR_BINDABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "bindable" },
2270 /* ATTR_BROADCAST */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "broadcast" },
2271 /* ATTR_CALLAS */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "call_as" },
2272 /* ATTR_CALLCONV */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
},
2273 /* ATTR_CASE */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "case" },
2274 /* ATTR_CONST */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "const" },
2275 /* ATTR_CONTEXTHANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "context_handle" },
2276 /* ATTR_CONTROL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, "control" },
2277 /* ATTR_DEFAULT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, "default" },
2278 /* ATTR_DEFAULTCOLLELEM */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultcollelem" },
2279 /* ATTR_DEFAULTVALUE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultvalue" },
2280 /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "defaultvtable" },
2281 /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
},
2282 /* ATTR_DISPLAYBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "displaybind" },
2283 /* ATTR_DLLNAME */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, "dllname" },
2284 /* ATTR_DUAL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "dual" },
2285 /* ATTR_ENDPOINT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "endpoint" },
2286 /* ATTR_ENTRY */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "entry" },
2287 /* ATTR_EXPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "explicit_handle" },
2288 /* ATTR_HANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "handle" },
2289 /* ATTR_HELPCONTEXT */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpcontext" },
2290 /* ATTR_HELPFILE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpfile" },
2291 /* ATTR_HELPSTRING */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpstring" },
2292 /* ATTR_HELPSTRINGCONTEXT */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpstringcontext" },
2293 /* ATTR_HELPSTRINGDLL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpstringdll" },
2294 /* ATTR_HIDDEN */ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, "hidden" },
2295 /* ATTR_ID */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "id" },
2296 /* ATTR_IDEMPOTENT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "idempotent" },
2297 /* ATTR_IIDIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "iid_is" },
2298 /* ATTR_IMMEDIATEBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "immediatebind" },
2299 /* ATTR_IMPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "implicit_handle" },
2300 /* ATTR_IN */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "in" },
2301 /* ATTR_INLINE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inline" },
2302 /* ATTR_INPUTSYNC */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inputsync" },
2303 /* ATTR_LENGTHIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "length_is" },
2304 /* ATTR_LIBLCID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "lcid" },
2305 /* ATTR_LOCAL */ { 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "local" },
2306 /* ATTR_NONBROWSABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonbrowsable" },
2307 /* ATTR_NONCREATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "noncreatable" },
2308 /* ATTR_NONEXTENSIBLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonextensible" },
2309 /* ATTR_OBJECT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "object" },
2310 /* ATTR_ODL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "odl" },
2311 /* ATTR_OLEAUTOMATION */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "oleautomation" },
2312 /* ATTR_OPTIONAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optional" },
2313 /* ATTR_OUT */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "out" },
2314 /* ATTR_POINTERDEFAULT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "pointer_default" },
2315 /* ATTR_POINTERTYPE */ { 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, "ref, unique or ptr" },
2316 /* ATTR_PROPGET */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propget" },
2317 /* ATTR_PROPPUT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propput" },
2318 /* ATTR_PROPPUTREF */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propputref" },
2319 /* ATTR_PUBLIC */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "public" },
2320 /* ATTR_RANGE */ { 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, "range" },
2321 /* ATTR_READONLY */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "readonly" },
2322 /* ATTR_REQUESTEDIT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "requestedit" },
2323 /* ATTR_RESTRICTED */ { 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, "restricted" },
2324 /* ATTR_RETVAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "retval" },
2325 /* ATTR_SIZEIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "size_is" },
2326 /* ATTR_SOURCE */ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "source" },
2327 /* ATTR_STRICTCONTEXTHANDLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "strict_context_handle" },
2328 /* ATTR_STRING */ { 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, "string" },
2329 /* ATTR_SWITCHIS */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "switch_is" },
2330 /* ATTR_SWITCHTYPE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, "switch_type" },
2331 /* ATTR_TRANSMITAS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "transmit_as" },
2332 /* ATTR_UUID */ { 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "uuid" },
2333 /* ATTR_V1ENUM */ { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, "v1_enum" },
2334 /* ATTR_VARARG */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "vararg" },
2335 /* ATTR_VERSION */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "version" },
2336 /* ATTR_WIREMARSHAL */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "wire_marshal" },
2339 const char *get_attr_display_name
(enum attr_type type
)
2341 return allowed_attr
[type
].display_name
;
2344 static attr_list_t
*check_iface_attrs
(const char *name
, attr_list_t
*attrs
)
2347 if
(!attrs
) return attrs
;
2348 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2350 if
(!allowed_attr
[attr
->type
].on_interface
)
2351 error_loc
("inapplicable attribute %s for interface %s\n",
2352 allowed_attr
[attr
->type
].display_name
, name
);
2357 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
)
2360 if
(!attrs
) return attrs
;
2361 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2363 if
(!allowed_attr
[attr
->type
].on_function
)
2364 error_loc
("inapplicable attribute %s for function %s\n",
2365 allowed_attr
[attr
->type
].display_name
, name
);
2370 static void check_arg
(var_t
*arg
)
2372 const type_t
*t
= arg
->type
;
2375 if
(t
->type
== 0 && ! is_var_ptr
(arg
))
2376 error_loc
("argument '%s' has void type\n", arg
->name
);
2380 LIST_FOR_EACH_ENTRY
(attr
, arg
->attrs
, const attr_t
, entry
)
2382 if
(!allowed_attr
[attr
->type
].on_arg
)
2383 error_loc
("inapplicable attribute %s for argument %s\n",
2384 allowed_attr
[attr
->type
].display_name
, arg
->name
);
2389 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
)
2392 if
(!attrs
) return attrs
;
2393 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2395 if
(!allowed_attr
[attr
->type
].on_type
)
2396 error_loc
("inapplicable attribute %s for typedef\n",
2397 allowed_attr
[attr
->type
].display_name
);
2402 static attr_list_t
*check_enum_attrs
(attr_list_t
*attrs
)
2405 if
(!attrs
) return attrs
;
2406 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2408 if
(!allowed_attr
[attr
->type
].on_enum
)
2409 error_loc
("inapplicable attribute %s for enum\n",
2410 allowed_attr
[attr
->type
].display_name
);
2415 static attr_list_t
*check_struct_attrs
(attr_list_t
*attrs
)
2418 if
(!attrs
) return attrs
;
2419 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2421 if
(!allowed_attr
[attr
->type
].on_struct
)
2422 error_loc
("inapplicable attribute %s for struct\n",
2423 allowed_attr
[attr
->type
].display_name
);
2428 static attr_list_t
*check_union_attrs
(attr_list_t
*attrs
)
2431 if
(!attrs
) return attrs
;
2432 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2434 if
(!allowed_attr
[attr
->type
].on_union
)
2435 error_loc
("inapplicable attribute %s for union\n",
2436 allowed_attr
[attr
->type
].display_name
);
2441 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
)
2444 if
(!attrs
) return attrs
;
2445 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2447 if
(!allowed_attr
[attr
->type
].on_field
)
2448 error_loc
("inapplicable attribute %s for field %s\n",
2449 allowed_attr
[attr
->type
].display_name
, name
);
2454 static attr_list_t
*check_library_attrs
(const char *name
, attr_list_t
*attrs
)
2457 if
(!attrs
) return attrs
;
2458 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2460 if
(!allowed_attr
[attr
->type
].on_library
)
2461 error_loc
("inapplicable attribute %s for library %s\n",
2462 allowed_attr
[attr
->type
].display_name
, name
);
2467 static attr_list_t
*check_dispiface_attrs
(const char *name
, attr_list_t
*attrs
)
2470 if
(!attrs
) return attrs
;
2471 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2473 if
(!allowed_attr
[attr
->type
].on_dispinterface
)
2474 error_loc
("inapplicable attribute %s for dispinterface %s\n",
2475 allowed_attr
[attr
->type
].display_name
, name
);
2480 static attr_list_t
*check_module_attrs
(const char *name
, attr_list_t
*attrs
)
2483 if
(!attrs
) return attrs
;
2484 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2486 if
(!allowed_attr
[attr
->type
].on_module
)
2487 error_loc
("inapplicable attribute %s for module %s\n",
2488 allowed_attr
[attr
->type
].display_name
, name
);
2493 static attr_list_t
*check_coclass_attrs
(const char *name
, attr_list_t
*attrs
)
2496 if
(!attrs
) return attrs
;
2497 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2499 if
(!allowed_attr
[attr
->type
].on_coclass
)
2500 error_loc
("inapplicable attribute %s for coclass %s\n",
2501 allowed_attr
[attr
->type
].display_name
, name
);
2506 static int is_allowed_conf_type
(const type_t
*type
)
2527 static int is_ptr_guid_type
(const type_t
*type
)
2529 unsigned int align
= 0;
2532 if
(type
->kind
== TKIND_ALIAS
)
2534 else if
(is_ptr
(type
))
2542 return
(type_memsize
(type
, &align
) == 16);
2545 static void check_conformance_expr_list
(const char *attr_name
, const var_t
*arg
, const type_t
*container_type
, expr_list_t
*expr_list
)
2548 struct expr_loc expr_loc
;
2550 expr_loc.attr
= attr_name
;
2551 if
(expr_list
) LIST_FOR_EACH_ENTRY
(dim
, expr_list
, expr_t
, entry
)
2553 if
(dim
->type
!= EXPR_VOID
)
2555 const type_t
*expr_type
= expr_resolve_type
(&expr_loc
, container_type
, dim
);
2556 if
(!is_allowed_conf_type
(expr_type
))
2557 error_loc_info
(&arg
->loc_info
, "expression must resolve to integral type <= 32bits for attribute %s\n",
2563 static void check_remoting_fields
(const var_t
*var
, type_t
*type
);
2565 /* checks that properties common to fields and arguments are consistent */
2566 static void check_field_common
(const type_t
*container_type
,
2567 const char *container_name
, const var_t
*arg
)
2569 type_t
*type
= arg
->type
;
2570 int is_wire_marshal
= 0;
2571 int is_context_handle
= 0;
2572 const char *container_type_name
= NULL
;
2574 if
(is_struct
(container_type
->type
))
2575 container_type_name
= "struct";
2576 else if
(is_union
(container_type
->type
))
2577 container_type_name
= "union";
2578 else if
(container_type
->type
== RPC_FC_FUNCTION
)
2579 container_type_name
= "function";
2581 if
(is_attr
(arg
->attrs
, ATTR_LENGTHIS
) &&
2582 (is_attr
(arg
->attrs
, ATTR_STRING
) || is_aliaschain_attr
(arg
->type
, ATTR_STRING
)))
2583 error_loc_info
(&arg
->loc_info
,
2584 "string and length_is specified for argument %s are mutually exclusive attributes\n",
2587 if
(is_attr
(arg
->attrs
, ATTR_SIZEIS
))
2589 expr_list_t
*size_is_exprs
= get_attrp
(arg
->attrs
, ATTR_SIZEIS
);
2590 check_conformance_expr_list
("size_is", arg
, container_type
, size_is_exprs
);
2592 if
(is_attr
(arg
->attrs
, ATTR_LENGTHIS
))
2594 expr_list_t
*length_is_exprs
= get_attrp
(arg
->attrs
, ATTR_LENGTHIS
);
2595 check_conformance_expr_list
("length_is", arg
, container_type
, length_is_exprs
);
2597 if
(is_attr
(arg
->attrs
, ATTR_IIDIS
))
2599 struct expr_loc expr_loc
;
2600 expr_t
*expr
= get_attrp
(arg
->attrs
, ATTR_IIDIS
);
2601 if
(expr
->type
!= EXPR_VOID
)
2603 const type_t
*expr_type
;
2605 expr_loc.attr
= "iid_is";
2606 expr_type
= expr_resolve_type
(&expr_loc
, container_type
, expr
);
2607 if
(!expr_type ||
!is_ptr_guid_type
(expr_type
))
2608 error_loc_info
(&arg
->loc_info
, "expression must resolve to pointer to GUID type for attribute iid_is\n");
2611 if
(is_attr
(arg
->attrs
, ATTR_SWITCHIS
))
2613 struct expr_loc expr_loc
;
2614 expr_t
*expr
= get_attrp
(arg
->attrs
, ATTR_SWITCHIS
);
2615 if
(expr
->type
!= EXPR_VOID
)
2617 const type_t
*expr_type
;
2619 expr_loc.attr
= "switch_is";
2620 expr_type
= expr_resolve_type
(&expr_loc
, container_type
, expr
);
2621 if
(!expr_type ||
!is_allowed_conf_type
(expr_type
))
2622 error_loc_info
(&arg
->loc_info
, "expression must resolve to integral type <= 32bits for attribute %s\n",
2627 /* get fundamental type for the argument */
2630 if
(is_attr
(type
->attrs
, ATTR_WIREMARSHAL
))
2632 is_wire_marshal
= 1;
2635 if
(is_attr
(type
->attrs
, ATTR_CONTEXTHANDLE
))
2637 is_context_handle
= 1;
2640 if
(type
->kind
== TKIND_ALIAS
)
2642 else if
(is_ptr
(type
) || is_array
(type
))
2648 if
(type
->type
== 0 && !is_attr
(arg
->attrs
, ATTR_IIDIS
) && !is_wire_marshal
&& !is_context_handle
)
2649 error_loc_info
(&arg
->loc_info
, "parameter \'%s\' of %s \'%s\' cannot derive from void *\n", arg
->name
, container_type_name
, container_name
);
2650 else if
(type
->type
== RPC_FC_FUNCTION
)
2651 error_loc_info
(&arg
->loc_info
, "parameter \'%s\' of %s \'%s\' cannot be a function pointer\n", arg
->name
, container_type_name
, container_name
);
2652 else if
(!is_wire_marshal
&& (is_struct
(type
->type
) || is_union
(type
->type
)))
2653 check_remoting_fields
(arg
, type
);
2656 static void check_remoting_fields
(const var_t
*var
, type_t
*type
)
2659 const var_list_t
*fields
= NULL
;
2664 type
->checked
= TRUE
;
2666 if
(is_struct
(type
->type
))
2669 fields
= type
->fields_or_args
;
2671 error_loc_info
(&var
->loc_info
, "undefined type declaration %s\n", type
->name
);
2673 else if
(is_union
(type
->type
))
2675 if
(type
->type
== RPC_FC_ENCAPSULATED_UNION
)
2677 const var_t
*uv
= LIST_ENTRY
(list_tail
(type
->fields_or_args
), const var_t
, entry
);
2678 fields
= uv
->type
->fields_or_args
;
2681 fields
= type
->fields_or_args
;
2684 if
(fields
) LIST_FOR_EACH_ENTRY
( field
, fields
, const var_t
, entry
)
2685 if
(field
->type
) check_field_common
(type
, type
->name
, field
);
2688 /* checks that arguments for a function make sense for marshalling and unmarshalling */
2689 static void check_remoting_args
(const func_t
*func
)
2691 const char *funcname
= func
->def
->name
;
2694 if
(func
->args
) LIST_FOR_EACH_ENTRY
( arg
, func
->args
, const var_t
, entry
)
2697 const type_t
*type
= arg
->type
;
2699 /* get pointer level and fundamental type for the argument */
2702 if
(is_attr
(type
->attrs
, ATTR_WIREMARSHAL
))
2704 if
(is_attr
(type
->attrs
, ATTR_CONTEXTHANDLE
))
2706 if
(type
->kind
== TKIND_ALIAS
)
2708 else if
(is_ptr
(type
))
2717 /* check that [out] parameters have enough pointer levels */
2718 if
(is_attr
(arg
->attrs
, ATTR_OUT
))
2720 if
(!is_array
(type
))
2723 error_loc_info
(&arg
->loc_info
, "out parameter \'%s\' of function \'%s\' is not a pointer\n", arg
->name
, funcname
);
2724 if
(type
->type
== RPC_FC_IP
&& ptr_level
== 1)
2725 error_loc_info
(&arg
->loc_info
, "out interface pointer \'%s\' of function \'%s\' is not a double pointer\n", arg
->name
, funcname
);
2729 check_field_common
(func
->def
->type
, funcname
, arg
);
2733 static void add_explicit_handle_if_necessary
(func_t
*func
)
2735 const var_t
* explicit_handle_var
;
2736 const var_t
* explicit_generic_handle_var
= NULL
;
2737 const var_t
* context_handle_var
= NULL
;
2739 /* check for a defined binding handle */
2740 explicit_handle_var
= get_explicit_handle_var
(func
);
2741 if
(!explicit_handle_var
)
2743 explicit_generic_handle_var
= get_explicit_generic_handle_var
(func
);
2744 if
(!explicit_generic_handle_var
)
2746 context_handle_var
= get_context_handle_var
(func
);
2747 if
(!context_handle_var
)
2749 /* no explicit handle specified so add
2750 * "[in] handle_t IDL_handle" as the first parameter to the
2752 var_t
*idl_handle
= make_var
(xstrdup
("IDL_handle"));
2753 idl_handle
->attrs
= append_attr
(NULL
, make_attr
(ATTR_IN
));
2754 idl_handle
->type
= find_type_or_error
("handle_t", 0);
2755 if
(!func
->def
->type
->fields_or_args
)
2757 func
->def
->type
->fields_or_args
= xmalloc
( sizeof
(*func
->def
->type
->fields_or_args
) );
2758 list_init
( func
->def
->type
->fields_or_args
);
2760 list_add_head
( func
->def
->type
->fields_or_args
, &idl_handle
->entry
);
2761 func
->args
= func
->def
->type
->fields_or_args
;
2767 static void check_functions
(const type_t
*iface
)
2769 if
(is_attr
(iface
->attrs
, ATTR_EXPLICIT_HANDLE
) && iface
->funcs
)
2772 LIST_FOR_EACH_ENTRY
( func
, iface
->funcs
, func_t
, entry
)
2773 add_explicit_handle_if_necessary
(func
);
2775 if
(!is_inside_library
&& !is_attr
(iface
->attrs
, ATTR_LOCAL
))
2778 if
(iface
->funcs
) LIST_FOR_EACH_ENTRY
( func
, iface
->funcs
, const func_t
, entry
)
2780 if
(!is_attr
(func
->def
->attrs
, ATTR_LOCAL
))
2781 check_remoting_args
(func
);
2786 static void check_all_user_types
(const statement_list_t
*stmts
)
2788 const statement_t
*stmt
;
2790 if
(stmts
) LIST_FOR_EACH_ENTRY
(stmt
, stmts
, const statement_t
, entry
)
2792 if
(stmt
->type
== STMT_LIBRARY
)
2793 check_all_user_types
(stmt
->u.lib
->stmts
);
2794 else if
(stmt
->type
== STMT_TYPE
&& stmt
->u.type
->type
== RPC_FC_IP
)
2797 const func_list_t
*fs
= stmt
->u.type
->funcs
;
2798 if
(fs
) LIST_FOR_EACH_ENTRY
(f
, fs
, const func_t
, entry
)
2799 check_for_additional_prototype_types
(f
->args
);
2804 int is_valid_uuid
(const char *s
)
2808 for
(i
= 0; i
< 36; ++i
)
2809 if
(i
== 8 || i
== 13 || i
== 18 || i
== 23)
2815 if
(!isxdigit
(s
[i
]))
2818 return s
[i
] == '\0';
2821 static statement_t
*make_statement
(enum statement_type type
)
2823 statement_t
*stmt
= xmalloc
(sizeof
(*stmt
));
2828 static statement_t
*make_statement_type_decl
(type_t
*type
)
2830 statement_t
*stmt
= make_statement
(STMT_TYPE
);
2831 stmt
->u.type
= type
;
2835 static statement_t
*make_statement_reference
(type_t
*type
)
2837 statement_t
*stmt
= make_statement
(STMT_TYPEREF
);
2838 stmt
->u.type
= type
;
2842 static statement_t
*make_statement_declaration
(var_t
*var
)
2844 statement_t
*stmt
= make_statement
(STMT_DECLARATION
);
2846 if
(var
->stgclass
== STG_EXTERN
&& var
->eval
)
2847 warning
("'%s' initialised and declared extern\n", var
->name
);
2848 if
(is_const_decl
(var
))
2853 else if
((var
->stgclass
== STG_NONE || var
->stgclass
== STG_REGISTER
) &&
2854 var
->type
->type
!= RPC_FC_FUNCTION
)
2855 error_loc
("instantiation of data is illegal\n");
2859 static statement_t
*make_statement_library
(typelib_t
*typelib
)
2861 statement_t
*stmt
= make_statement
(STMT_LIBRARY
);
2862 stmt
->u.lib
= typelib
;
2866 static statement_t
*make_statement_cppquote
(const char *str
)
2868 statement_t
*stmt
= make_statement
(STMT_CPPQUOTE
);
2873 static statement_t
*make_statement_importlib
(const char *str
)
2875 statement_t
*stmt
= make_statement
(STMT_IMPORTLIB
);
2880 static statement_t
*make_statement_import
(const char *str
)
2882 statement_t
*stmt
= make_statement
(STMT_IMPORT
);
2887 static statement_t
*make_statement_module
(type_t
*type
)
2889 statement_t
*stmt
= make_statement
(STMT_MODULE
);
2890 stmt
->u.type
= type
;
2894 static statement_t
*process_typedefs
(declarator_list_t
*decls
)
2896 declarator_t
*decl
, *next
;
2898 type_list_t
**type_list
;
2900 if
(!decls
) return NULL
;
2902 stmt
= make_statement
(STMT_TYPEDEF
);
2903 stmt
->u.type_list
= NULL
;
2904 type_list
= &stmt
->u.type_list
;
2906 LIST_FOR_EACH_ENTRY_SAFE
( decl
, next
, decls
, declarator_t
, entry
)
2908 var_t
*var
= decl
->var
;
2909 type_t
*type
= find_type_or_error
(var
->name
, 0);
2910 *type_list
= xmalloc
(sizeof
(type_list_t
));
2911 (*type_list
)->type
= type
;
2912 (*type_list
)->next
= NULL
;
2914 if
(! parse_only
&& do_header
)
2915 write_typedef
(type
);
2916 if
(in_typelib
&& is_attr
(type
->attrs
, ATTR_PUBLIC
))
2917 add_typelib_entry
(type
);
2919 type_list
= &(*type_list
)->next
;
2927 static statement_list_t
*append_statement
(statement_list_t
*list
, statement_t
*stmt
)
2929 if
(!stmt
) return list
;
2932 list
= xmalloc
( sizeof
(*list
) );
2935 list_add_tail
( list
, &stmt
->entry
);
2939 static func_list_t
*append_func_from_statement
(func_list_t
*list
, statement_t
*stmt
)
2941 if
(stmt
->type
== STMT_DECLARATION
)
2943 var_t
*var
= stmt
->u.var
;
2944 if
(var
->stgclass
== STG_NONE
&& var
->type
->type
== RPC_FC_FUNCTION
)
2946 check_function_attrs
(var
->name
, var
->type
->attrs
);
2947 return append_func
(list
, make_func
(stmt
->u.var
));
2953 void init_loc_info
(loc_info_t
*i
)
2955 i
->input_name
= input_name ? input_name
: "stdin";
2956 i
->line_number
= line_number
;
2957 i
->near_text
= parser_text
;
2960 static void check_def
(const type_t
*t
)
2963 error_loc
("%s: redefinition error; original definition was at %s:%d\n",
2964 t
->name
, t
->loc_info.input_name
, t
->loc_info.line_number
);