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
47 static str_list_t
*append_str
(str_list_t
*list
, char *str
);
48 static decl_spec_t
*make_decl_spec
(type_t
*type
, decl_spec_t
*left
, decl_spec_t
*right
,
49 enum storage_class stgclass
, enum type_qualifier qual
, enum function_specifier func_specifier
);
50 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
);
51 static var_t
*declare_var
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_t
*decl
, int top
);
52 static var_list_t
*set_var_types
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_list_t
*decls
);
53 static var_list_t
*append_var_list
(var_list_t
*list
, var_list_t
*vars
);
54 static declarator_list_t
*append_declarator
(declarator_list_t
*list
, declarator_t
*p
);
55 static declarator_t
*make_declarator
(var_t
*var
);
56 static type_t
*make_safearray
(type_t
*type
);
57 static typelib_t
*make_library
(const char *name
, const attr_list_t
*attrs
);
58 static void append_array
(declarator_t
*decl
, expr_t
*expr
);
59 static void append_chain_type
(declarator_t
*decl
, type_t
*type
, enum type_qualifier qual
);
60 static void append_chain_callconv
( struct location where
, type_t
*chain
, char *callconv
);
61 static warning_list_t
*append_warning
(warning_list_t
*, int);
63 static type_t
*reg_typedefs
( struct location where
, decl_spec_t
*decl_spec
, var_list_t
*names
, attr_list_t
*attrs
);
64 static type_t
*find_type_or_error
(struct namespace
*parent
, const char *name
);
65 static struct namespace
*find_namespace_or_error
(struct namespace
*namespace
, const char *name
);
67 static var_t
*reg_const
(var_t
*var
);
69 static void push_namespaces
(str_list_t
*names
);
70 static void pop_namespaces
(str_list_t
*names
);
71 static void push_parameters_namespace
(const char *name
);
72 static void pop_parameters_namespace
(const char *name
);
74 static statement_list_t
*append_parameterized_type_stmts
(statement_list_t
*stmts
);
75 static void check_statements
(const statement_list_t
*stmts
, int is_inside_library
);
76 static void check_all_user_types
(const statement_list_t
*stmts
);
77 static void add_explicit_handle_if_necessary
(const type_t
*iface
, var_t
*func
);
79 static void check_async_uuid
(type_t
*iface
);
81 static statement_t
*make_statement
(enum statement_type type
);
82 static statement_t
*make_statement_type_decl
(type_t
*type
);
83 static statement_t
*make_statement_reference
(type_t
*type
);
84 static statement_t
*make_statement_declaration
(var_t
*var
);
85 static statement_t
*make_statement_library
(typelib_t
*typelib
);
86 static statement_t
*make_statement_pragma
(const char *str
);
87 static statement_t
*make_statement_cppquote
(const char *str
);
88 static statement_t
*make_statement_importlib
(const char *str
);
89 static statement_t
*make_statement_module
(type_t
*type
);
90 static statement_t
*make_statement_typedef
(var_list_t
*names
, int declonly
);
91 static statement_t
*make_statement_import
(const char *str
);
92 static statement_t
*make_statement_parameterized_type
(type_t
*type
, typeref_list_t
*params
);
93 static statement_t
*make_statement_delegate
(type_t
*ret
, var_list_t
*args
);
94 static statement_list_t
*append_statement
(statement_list_t
*list
, statement_t
*stmt
);
95 static statement_list_t
*append_statements
(statement_list_t
*, statement_list_t
*);
97 static struct namespace global_namespace
= {
98 NULL
, NULL
, LIST_INIT
(global_namespace.entry
), LIST_INIT
(global_namespace.children
)
101 static struct namespace
*current_namespace
= &global_namespace
;
102 static struct namespace
*parameters_namespace
= NULL
;
103 static statement_list_t
*parameterized_type_stmts
= NULL
;
105 static typelib_t
*current_typelib
;
112 #define PARSER_LTYPE struct location
119 int parser_lex
( PARSER_STYPE
*yylval, PARSER_LTYPE
*yylloc );
120 void push_import
( const char *fname
, PARSER_LTYPE
*yylloc );
121 void pop_import
( PARSER_LTYPE
*yylloc );
123 # define YYLLOC_DEFAULT( cur, rhs, n ) \
124 do
{ if
(n
) init_location
( &(cur
), &YYRHSLOC
( rhs
, 1 ), &YYRHSLOC
( rhs
, n
) ); \
125 else init_location
( &(cur
), &YYRHSLOC
( rhs
, 0 ), NULL
); } while
(0)
129 %define api.prefix
{parser_
}
130 %define api.pure full
131 %define parse.
error verbose
136 attr_list_t
*attr_list
;
137 str_list_t
*str_list
;
139 expr_list_t
*expr_list
;
142 var_list_t
*var_list
;
143 declarator_t
*declarator
;
144 declarator_list_t
*declarator_list
;
145 statement_t
*statement
;
146 statement_list_t
*stmt_list
;
148 warning_list_t
*warning_list
;
150 typeref_list_t
*typeref_list
;
156 struct _import_t
*import
;
157 struct _decl_spec_t
*declspec
;
158 enum storage_class stgclass
;
159 enum type_qualifier type_qualifier
;
160 enum function_specifier function_specifier
;
161 struct namespace
*namespace
;
164 %token
<str
> aIDENTIFIER aPRAGMA
165 %token
<str
> aKNOWNTYPE
166 %token
<num
> aNUM aHEXNUM
168 %token
<str
> aSTRING aWSTRING aSQSTRING
170 %token
<str
> tFASTCALL
172 %token
<str
> tSTDCALL
177 %token EQUALITY INEQUALITY
178 %token GREATEREQUAL LESSEQUAL
179 %token LOGICALOR LOGICALAND
184 %token tALLNODES tALLOCATE tANNOTATION
186 %token tAPPOBJECT tASYNC tASYNCUUID
187 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
188 %token tCALLAS tCALLBACK tCASE tCHAR tCOCLASS tCODE tCOMMSTATUS
190 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
191 %token tCONTEXTHANDLESERIALIZE
193 %token tCONTRACTVERSION
194 %token tCONTROL tCPPQUOTE
197 %token tDECODE tDEFAULT tDEFAULTBIND
199 %token tDEFAULT_OVERLOAD
200 %token tDEFAULTCOLLELEM
202 %token tDEFAULTVTABLE
204 %token tDISABLECONSISTENCYCHECK tDISPLAYBIND
205 %token tDISPINTERFACE
206 %token tDLLNAME tDONTFREE tDOUBLE tDUAL
207 %token tENABLEALLOCATE tENCODE tENDPOINT
208 %token tENTRY tENUM tERRORSTATUST
209 %token tEVENTADD tEVENTREMOVE
211 %token tEXPLICITHANDLE tEXTERN
215 %token tFLOAT tFORCEALLOCATE
218 %token tHELPCONTEXT tHELPFILE
219 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
221 %token tHYPER tID tIDEMPOTENT
222 %token tIGNORE tIIDIS
223 %token tIMMEDIATEBIND
224 %token tIMPLICITHANDLE
225 %token tIMPORT tIMPORTLIB
226 %token tIN tIN_LINE tINLINE
228 %token tINT tINT32 tINT3264 tINT64
231 %token tLENGTHIS tLIBRARY
232 %token tLICENSED tLOCAL
234 %token tMARSHALINGBEHAVIOR
235 %token tMAYBE tMESSAGE
240 %token tNOCODE tNONBROWSABLE
243 %token tNONEXTENSIBLE
244 %token tNOTIFY tNOTIFYFLAG
246 %token tOBJECT tODL tOLEAUTOMATION
247 %token tOPTIMIZE tOPTIONAL
250 %token tPARTIALIGNORE
251 %token tPOINTERDEFAULT
252 %token tPRAGMA_WARNING
253 %token tPROGID tPROPERTIES
254 %token tPROPGET tPROPPUT tPROPPUTREF
259 %token tREADONLY tREF
260 %token tREGISTER tREPRESENTAS
268 %token tSIGNED tSINGLENODE
269 %token tSIZEIS tSIZEOF
274 %token tSTRICTCONTEXTHANDLE
275 %token tSTRING tSTRUCT
276 %token tSWITCH tSWITCHIS tSWITCHTYPE
277 %token tTHREADING tTRANSMITAS
280 %token tUIDEFAULT tUNION
283 %token tUSESGETLASTERROR tUSERMARSHAL tUUID
286 %token tVERSION tVIPROGID
288 %token tWCHAR tWIREMARSHAL
289 %token tAPARTMENT tNEUTRAL tSINGLE tFREE tBOTH
291 %type
<attr
> access_attr
292 %type
<attr
> attribute acf_attribute
293 %type
<attr_list
> m_attributes attributes attrib_list
294 %type
<attr_list
> acf_attributes acf_attribute_list
295 %type
<attr_list
> dispattributes
296 %type
<str_list
> str_list
297 %type
<expr
> m_expr expr expr_const expr_int_const array m_bitfield
298 %type
<expr_list
> m_exprs
/* exprs expr_list */ expr_list_int_const
299 %type
<expr
> contract_req
300 %type
<expr
> static_attr
301 %type
<expr
> activatable_attr
302 %type
<expr
> composable_attr
303 %type
<expr
> deprecated_attr
304 %type
<type
> delegatedef
305 %type
<stgclass
> storage_cls_spec
306 %type
<type_qualifier
> type_qualifier m_type_qual_list
307 %type
<function_specifier
> function_specifier
308 %type
<declspec
> decl_spec unqualified_decl_spec decl_spec_no_type m_decl_spec_no_type
309 %type
<type
> inherit interface interfacedef
310 %type
<type
> interfaceref
311 %type
<type
> dispinterfaceref
312 %type
<type
> dispinterface dispinterfacedef
313 %type
<type
> module moduledef
314 %type
<str_list
> namespacedef
315 %type
<type
> base_type int_std
316 %type
<type
> enumdef structdef uniondef typedecl
317 %type
<type
> type unqualified_type qualified_type
318 %type
<type
> type_parameter
319 %type
<typeref_list
> type_parameters
320 %type
<type
> parameterized_type
321 %type
<type
> parameterized_type_arg
322 %type
<typeref_list
> parameterized_type_args
323 %type
<typeref
> class_interface
324 %type
<typeref_list
> class_interfaces
325 %type
<typeref_list
> requires required_types
326 %type
<var
> arg ne_union_field union_field s_field case
enum enum_member declaration
328 %type
<var_list
> m_args arg_list args dispint_meths
329 %type
<var_list
> fields ne_union_fields cases enums enum_list dispint_props field
330 %type
<var
> m_ident ident
331 %type
<declarator
> declarator direct_declarator init_declarator struct_declarator
332 %type
<declarator
> m_any_declarator any_declarator any_declarator_no_direct any_direct_declarator
333 %type
<declarator
> m_abstract_declarator abstract_declarator abstract_declarator_no_direct abstract_direct_declarator
334 %type
<declarator_list
> declarator_list struct_declarator_list
335 %type
<type
> coclass coclassdef
336 %type
<type
> runtimeclass runtimeclass_def
337 %type
<type
> apicontract apicontract_def
338 %type
<num
> contract_ver
339 %type
<num
> pointer_type threading_type marshaling_behavior version
340 %type
<str
> libraryhdr callconv cppquote importlib import
341 %type
<str
> typename m_typename
342 %type
<str
> import_start
343 %type
<typelib
> library_start librarydef
344 %type
<statement
> statement typedef pragma_warning
345 %type
<stmt_list
> gbl_statements imp_statements int_statements
346 %type
<stmt_list
> decl_block decl_statements
347 %type
<stmt_list
> imp_decl_block imp_decl_statements
348 %type
<warning_list
> warnings
349 %type
<num
> allocate_option_list allocate_option
350 %type
<namespace
> namespace_pfx
359 %left EQUALITY INEQUALITY
360 %left
'<' '>' LESSEQUAL GREATEREQUAL
364 %right
'!' '~' CAST PPTR POS NEG ADDRESSOF tSIZEOF
365 %left
'.' MEMBERPTR
'[' ']'
369 input: gbl_statements m_acf
{ $1 = append_parameterized_type_stmts
($1);
370 check_statements
($1, FALSE
);
371 check_all_user_types
($1);
378 write_typelib_regscript
($1);
380 write_local_stubs
($1);
386 | aACF acf_statements
390 : %empty
{ $$
= NULL
; }
391 | decl_statements tINTERFACE qualified_type
'<' parameterized_type_args
'>' ';'
392 { parameterized_type_stmts
= append_statement
(parameterized_type_stmts
, make_statement_parameterized_type
($3, $5));
393 $$
= append_statement
($1, make_statement_reference
(type_parameterized_type_specialize_declare
($3, $5)));
397 decl_block: tDECLARE
'{' decl_statements
'}' { $$
= $3; }
401 : %empty
{ $$
= NULL
; }
402 | imp_decl_statements tINTERFACE qualified_type
'<' parameterized_type_args
'>' ';'
403 { $$
= append_statement
($1, make_statement_reference
(type_parameterized_type_specialize_declare
($3, $5))); }
407 : tDECLARE
'{' imp_decl_statements
'}' { $$
= $3; }
411 : %empty
{ $$
= NULL
; }
412 | gbl_statements namespacedef
'{' { push_namespaces
($2); } gbl_statements
'}'
413 { pop_namespaces
($2); $$
= append_statements
($1, $5); }
414 | gbl_statements interface
';' { $$
= append_statement
($1, make_statement_reference
($2)); }
415 | gbl_statements dispinterface
';' { $$
= append_statement
($1, make_statement_reference
($2)); }
416 | gbl_statements interfacedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); }
417 | gbl_statements delegatedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); }
418 | gbl_statements coclass
';' { $$
= $1;
419 reg_type
($2, $2->name
, current_namespace
, 0);
421 | gbl_statements coclassdef
{ $$
= append_statement
($1, make_statement_type_decl
($2));
422 reg_type
($2, $2->name
, current_namespace
, 0);
424 | gbl_statements apicontract
';' { $$
= $1; reg_type
($2, $2->name
, current_namespace
, 0); }
425 | gbl_statements apicontract_def
{ $$
= append_statement
($1, make_statement_type_decl
($2));
426 reg_type
($2, $2->name
, current_namespace
, 0); }
427 | gbl_statements runtimeclass
';' { $$
= $1; reg_type
($2, $2->name
, current_namespace
, 0); }
428 | gbl_statements runtimeclass_def
{ $$
= append_statement
($1, make_statement_type_decl
($2));
429 reg_type
($2, $2->name
, current_namespace
, 0); }
430 | gbl_statements moduledef
{ $$
= append_statement
($1, make_statement_module
($2)); }
431 | gbl_statements librarydef
{ $$
= append_statement
($1, make_statement_library
($2)); }
432 | gbl_statements statement
{ $$
= append_statement
($1, $2); }
433 | gbl_statements decl_block
{ $$
= append_statements
($1, $2); }
437 : %empty
{ $$
= NULL
; }
438 | imp_statements interface
';' { $$
= append_statement
($1, make_statement_reference
($2)); }
439 | imp_statements dispinterface
';' { $$
= append_statement
($1, make_statement_reference
($2)); }
440 | imp_statements namespacedef
'{' { push_namespaces
($2); } imp_statements
'}'
441 { pop_namespaces
($2); $$
= append_statements
($1, $5); }
442 | imp_statements interfacedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); }
443 | imp_statements delegatedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); }
444 | imp_statements coclass
';' { $$
= $1; reg_type
($2, $2->name
, current_namespace
, 0); }
445 | imp_statements coclassdef
{ $$
= append_statement
($1, make_statement_type_decl
($2));
446 reg_type
($2, $2->name
, current_namespace
, 0);
448 | imp_statements apicontract
';' { $$
= $1; reg_type
($2, $2->name
, current_namespace
, 0); }
449 | imp_statements apicontract_def
{ $$
= append_statement
($1, make_statement_type_decl
($2));
450 reg_type
($2, $2->name
, current_namespace
, 0); }
451 | imp_statements runtimeclass
';' { $$
= $1; reg_type
($2, $2->name
, current_namespace
, 0); }
452 | imp_statements runtimeclass_def
{ $$
= append_statement
($1, make_statement_type_decl
($2));
453 reg_type
($2, $2->name
, current_namespace
, 0); }
454 | imp_statements moduledef
{ $$
= append_statement
($1, make_statement_module
($2)); }
455 | imp_statements statement
{ $$
= append_statement
($1, $2); }
456 | imp_statements importlib
{ $$
= append_statement
($1, make_statement_importlib
($2)); }
457 | imp_statements librarydef
{ $$
= append_statement
($1, make_statement_library
($2)); }
458 | imp_statements imp_decl_block
{ $$
= append_statements
($1, $2); }
462 : %empty
{ $$
= NULL
; }
463 | int_statements statement
{ $$
= append_statement
($1, $2); }
472 cppquote
{ $$
= make_statement_cppquote
($1); }
473 | typedecl
';' { $$
= make_statement_type_decl
($1); }
474 | declaration
';' { $$
= make_statement_declaration
($1); }
475 | import
{ $$
= make_statement_import
($1); }
476 | typedef
';' { $$
= $1; }
477 | aPRAGMA
{ $$
= make_statement_pragma
($1); }
478 | pragma_warning
{ $$
= NULL
; }
481 pragma_warning: tPRAGMA_WARNING
'(' aIDENTIFIER
':' warnings
')'
485 result
= do_warning
($3, $5);
487 error_loc
("expected \"disable\", \"enable\" or \"default\"\n");
489 | tPRAGMA_WARNING
'(' tDEFAULT
':' warnings
')'
492 do_warning
("default", $5);
497 aNUM
{ $$
= append_warning
(NULL
, $1); }
498 | warnings aNUM
{ $$
= append_warning
($1, $2); }
503 | tENUM aIDENTIFIER
{ $$
= type_new_enum
($2, current_namespace
, FALSE
, NULL
); }
505 | tSTRUCT aIDENTIFIER
{ $$
= type_new_struct
($2, current_namespace
, FALSE
, NULL
); }
507 | tUNION aIDENTIFIER
{ $$
= type_new_nonencapsulated_union
($2, current_namespace
, FALSE
, NULL
); }
508 | attributes enumdef
{ $$
= $2; $$
->attrs
= check_enum_attrs
($1); }
509 | attributes structdef
{ $$
= $2; $$
->attrs
= check_struct_attrs
($1); }
510 | attributes uniondef
{ $$
= $2; $$
->attrs
= check_union_attrs
($1); }
513 cppquote: tCPPQUOTE
'(' aSTRING
')' { $$
= $3; }
516 import_start: tIMPORT aSTRING
';' { $$
= $2; push_import
( $2, &yylloc ); }
518 import: import_start imp_statements aEOF
{ pop_import
( &yylloc ); }
521 importlib: tIMPORTLIB
'(' aSTRING
')'
522 semicolon_opt
{ $$
= $3; if
(!parse_only
) add_importlib
($3, current_typelib
); }
525 libraryhdr: tLIBRARY typename
{ $$
= $2; }
527 library_start: attributes libraryhdr
'{' { $$
= make_library
($2, check_library_attrs
($2, $1));
528 if
(!parse_only
&& do_typelib
) current_typelib
= $$
;
531 librarydef: library_start imp_statements
'}'
532 semicolon_opt
{ $$
= $1; $$
->stmts
= $2; }
536 : %empty
{ $$
= NULL
; }
540 arg_list: arg
{ check_arg_attrs
($1); $$
= append_var
( NULL
, $1 ); }
541 | arg_list
',' arg
{ check_arg_attrs
($3); $$
= append_var
( $1, $3 ); }
545 | arg_list
',' ELLIPSIS
{ $$
= append_var
( $1, make_var
(xstrdup
("...")) ); }
548 /* split into two rules to get bison to resolve a tVOID conflict */
549 arg: attributes decl_spec m_any_declarator
{ if
($2->stgclass
!= STG_NONE
&& $2->stgclass
!= STG_REGISTER
)
550 error_loc
("invalid storage class for function parameter\n");
551 $$
= declare_var
($1, $2, $3, TRUE
);
554 | decl_spec m_any_declarator
{ if
($1->stgclass
!= STG_NONE
&& $1->stgclass
!= STG_REGISTER
)
555 error_loc
("invalid storage class for function parameter\n");
556 $$
= declare_var
(NULL
, $1, $2, TRUE
);
561 array: '[' expr
']' { $$
= $2;
562 if
(!$$
->is_const || $$
->cval
<= 0)
563 error_loc
("array dimension is not a positive integer constant\n");
565 |
'[' '*' ']' { $$
= make_expr
(EXPR_VOID
); }
566 |
'[' ']' { $$
= make_expr
(EXPR_VOID
); }
570 : %empty
{ $$
= NULL
; }
575 '[' attrib_list
']' { $$
= $2; }
578 attrib_list: attribute
{ $$
= append_attr
( NULL
, $1 ); }
579 | attrib_list
',' attribute
{ $$
= append_attr
( $1, $3 ); }
580 | attrib_list
']' '[' attribute
{ $$
= append_attr
( $1, $4 ); }
583 str_list: aSTRING
{ $$
= append_str
( NULL
, $1 ); }
584 | str_list
',' aSTRING
{ $$
= append_str
( $1, $3 ); }
588 tAGILE
{ $$
= MARSHALING_AGILE
; }
589 | tNONE
{ $$
= MARSHALING_NONE
; }
590 | tSTANDARD
{ $$
= MARSHALING_STANDARD
; }
594 aNUM
{ $$
= MAKEVERSION
(0, $1); }
595 | aNUM
'.' aNUM
{ $$
= MAKEVERSION
($3, $1); }
599 : decl_spec
',' contract_ver
{ if
($1->type
->type_type
!= TYPE_APICONTRACT
)
600 error_loc
("type %s is not an apicontract\n", $1->type
->name
);
601 $$
= make_exprl
(EXPR_NUM
, $3);
602 $$
= make_exprt
(EXPR_GTREQL
, declare_var
(NULL
, $1, make_declarator
(NULL
), 0), $$
);
607 : decl_spec
',' contract_req
{ if
($1->type
->type_type
!= TYPE_INTERFACE
)
608 error_loc
("type %s is not an interface\n", $1->type
->name
);
609 $$
= make_exprt
(EXPR_MEMBER
, declare_var
(NULL
, $1, make_declarator
(NULL
), 0), $3);
614 decl_spec
',' contract_req
{ if
($1->type
->type_type
!= TYPE_INTERFACE
)
615 error_loc
("type %s is not an interface\n", $1->type
->name
);
616 $$
= make_exprt
(EXPR_MEMBER
, declare_var
(NULL
, $1, make_declarator
(NULL
), 0), $3);
618 | contract_req
{ $$
= $1; } /* activatable on the default activation factory */
622 : tPUBLIC
{ $$
= attr_int
( @$
, ATTR_PUBLIC
, 0 ); }
623 | tPROTECTED
{ $$
= attr_int
( @$
, ATTR_PROTECTED
, 0 ); }
627 : decl_spec
',' access_attr
',' contract_req
628 { if
($1->type
->type_type
!= TYPE_INTERFACE
)
629 error_loc
( "type %s is not an interface\n", $1->type
->name
);
630 $$
= make_exprt
( EXPR_MEMBER
, declare_var
( append_attr
( NULL
, $3 ), $1, make_declarator
( NULL
), 0 ), $5 );
635 : aSTRING
',' aIDENTIFIER
',' contract_req
636 { $$
= make_expr3
( EXPR_MEMBER
, make_exprs
( EXPR_STRLIT
, $1 ), make_exprs
( EXPR_IDENTIFIER
, $3 ), $5 ); }
640 : %empty
{ $$
= NULL
; }
641 | tACTIVATABLE
'(' activatable_attr
')' { $$
= attr_ptr
( @$
, ATTR_ACTIVATABLE
, $3 ); }
642 | tAGGREGATABLE
{ $$
= attr_int
( @$
, ATTR_AGGREGATABLE
, 0 ); }
643 | tANNOTATION
'(' aSTRING
')' { $$
= attr_ptr
( @$
, ATTR_ANNOTATION
, $3 ); }
644 | tAPPOBJECT
{ $$
= attr_int
( @$
, ATTR_APPOBJECT
, 0 ); }
645 | tASYNC
{ $$
= attr_int
( @$
, ATTR_ASYNC
, 0 ); }
646 | tAUTOHANDLE
{ $$
= attr_int
( @$
, ATTR_AUTO_HANDLE
, 0 ); }
647 | tBINDABLE
{ $$
= attr_int
( @$
, ATTR_BINDABLE
, 0 ); }
648 | tBROADCAST
{ $$
= attr_int
( @$
, ATTR_BROADCAST
, 0 ); }
649 | tCALLAS
'(' ident
')' { $$
= attr_ptr
( @$
, ATTR_CALLAS
, $3 ); }
650 | tCASE
'(' expr_list_int_const
')' { $$
= attr_ptr
( @$
, ATTR_CASE
, $3 ); }
651 | tCODE
{ $$
= attr_int
( @$
, ATTR_CODE
, 0 ); }
652 | tCOMPOSABLE
'(' composable_attr
')' { $$
= attr_ptr
( @$
, ATTR_COMPOSABLE
, $3 ); }
653 | tCOMMSTATUS
{ $$
= attr_int
( @$
, ATTR_COMMSTATUS
, 0 ); }
654 | tCONTEXTHANDLE
{ $$
= attr_int
( @$
, ATTR_CONTEXTHANDLE
, 0 ); }
655 | tCONTEXTHANDLENOSERIALIZE
{ $$
= attr_int
( @$
, ATTR_CONTEXTHANDLE
, 0 ); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
656 | tCONTEXTHANDLESERIALIZE
{ $$
= attr_int
( @$
, ATTR_CONTEXTHANDLE
, 0 ); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
657 | tCONTRACT
'(' contract_req
')' { $$
= attr_ptr
( @$
, ATTR_CONTRACT
, $3 ); }
658 | tCONTRACTVERSION
'(' contract_ver
')' { $$
= attr_int
( @$
, ATTR_CONTRACTVERSION
, $3 ); }
659 | tCONTROL
{ $$
= attr_int
( @$
, ATTR_CONTROL
, 0 ); }
660 | tCUSTOM
'(' aUUID
',' expr_const
')' { attr_custdata_t
*data
= xmalloc
( sizeof
(*data
) );
661 data
->id
= *$3; data
->pval
= $5;
662 $$
= attr_ptr
( @$
, ATTR_CUSTOM
, data
);
664 | tDECODE
{ $$
= attr_int
( @$
, ATTR_DECODE
, 0 ); }
665 | tDEFAULT
{ $$
= attr_int
( @$
, ATTR_DEFAULT
, 0 ); }
666 | tDEFAULT_OVERLOAD
{ $$
= attr_int
( @$
, ATTR_DEFAULT_OVERLOAD
, 0 ); }
667 | tDEFAULTBIND
{ $$
= attr_int
( @$
, ATTR_DEFAULTBIND
, 0 ); }
668 | tDEFAULTCOLLELEM
{ $$
= attr_int
( @$
, ATTR_DEFAULTCOLLELEM
, 0 ); }
669 | tDEFAULTVALUE
'(' expr_const
')' { $$
= attr_ptr
( @$
, ATTR_DEFAULTVALUE
, $3 ); }
670 | tDEFAULTVTABLE
{ $$
= attr_int
( @$
, ATTR_DEFAULTVTABLE
, 0 ); }
671 | tDEPRECATED
'(' deprecated_attr
')' { $$
= attr_ptr
( @$
, ATTR_DEPRECATED
, $3 ); }
672 | tDISABLECONSISTENCYCHECK
{ $$
= attr_int
( @$
, ATTR_DISABLECONSISTENCYCHECK
, 0 ); }
673 | tDISPLAYBIND
{ $$
= attr_int
( @$
, ATTR_DISPLAYBIND
, 0 ); }
674 | tDLLNAME
'(' aSTRING
')' { $$
= attr_ptr
( @$
, ATTR_DLLNAME
, $3 ); }
675 | tDUAL
{ $$
= attr_int
( @$
, ATTR_DUAL
, 0 ); }
676 | tENABLEALLOCATE
{ $$
= attr_int
( @$
, ATTR_ENABLEALLOCATE
, 0 ); }
677 | tENCODE
{ $$
= attr_int
( @$
, ATTR_ENCODE
, 0 ); }
678 | tENDPOINT
'(' str_list
')' { $$
= attr_ptr
( @$
, ATTR_ENDPOINT
, $3 ); }
679 | tENTRY
'(' expr_const
')' { $$
= attr_ptr
( @$
, ATTR_ENTRY
, $3 ); }
680 | tEVENTADD
{ $$
= attr_int
( @$
, ATTR_EVENTADD
, 0 ); }
681 | tEVENTREMOVE
{ $$
= attr_int
( @$
, ATTR_EVENTREMOVE
, 0 ); }
682 | tEXCLUSIVETO
'(' decl_spec
')' { if
($3->type
->type_type
!= TYPE_RUNTIMECLASS
)
683 error_loc
( "type %s is not a runtimeclass\n", $3->type
->name
);
684 $$
= attr_ptr
( @$
, ATTR_EXCLUSIVETO
, $3->type
);
686 | tEXPLICITHANDLE
{ $$
= attr_int
( @$
, ATTR_EXPLICIT_HANDLE
, 0 ); }
687 | tFAULTSTATUS
{ $$
= attr_int
( @$
, ATTR_FAULTSTATUS
, 0 ); }
688 | tFLAGS
{ $$
= attr_int
( @$
, ATTR_FLAGS
, 0 ); }
689 | tFORCEALLOCATE
{ $$
= attr_int
( @$
, ATTR_FORCEALLOCATE
, 0 ); }
690 | tHANDLE
{ $$
= attr_int
( @$
, ATTR_HANDLE
, 0 ); }
691 | tHELPCONTEXT
'(' expr_int_const
')' { $$
= attr_ptr
( @$
, ATTR_HELPCONTEXT
, $3 ); }
692 | tHELPFILE
'(' aSTRING
')' { $$
= attr_ptr
( @$
, ATTR_HELPFILE
, $3 ); }
693 | tHELPSTRING
'(' aSTRING
')' { $$
= attr_ptr
( @$
, ATTR_HELPSTRING
, $3 ); }
694 | tHELPSTRINGCONTEXT
'(' expr_int_const
')'
695 { $$
= attr_ptr
( @$
, ATTR_HELPSTRINGCONTEXT
, $3 ); }
696 | tHELPSTRINGDLL
'(' aSTRING
')' { $$
= attr_ptr
( @$
, ATTR_HELPSTRINGDLL
, $3 ); }
697 | tHIDDEN
{ $$
= attr_int
( @$
, ATTR_HIDDEN
, 0 ); }
698 | tID
'(' expr_int_const
')' { $$
= attr_ptr
( @$
, ATTR_ID
, $3 ); }
699 | tIDEMPOTENT
{ $$
= attr_int
( @$
, ATTR_IDEMPOTENT
, 0 ); }
700 | tIGNORE
{ $$
= attr_int
( @$
, ATTR_IGNORE
, 0 ); }
701 | tIIDIS
'(' expr
')' { $$
= attr_ptr
( @$
, ATTR_IIDIS
, $3 ); }
702 | tIMMEDIATEBIND
{ $$
= attr_int
( @$
, ATTR_IMMEDIATEBIND
, 0 ); }
703 | tIMPLICITHANDLE
'(' arg
')' { $$
= attr_ptr
( @$
, ATTR_IMPLICIT_HANDLE
, $3 ); }
704 | tIN
{ $$
= attr_int
( @$
, ATTR_IN
, 0 ); }
705 | tINPUTSYNC
{ $$
= attr_int
( @$
, ATTR_INPUTSYNC
, 0 ); }
706 | tLENGTHIS
'(' m_exprs
')' { $$
= attr_ptr
( @$
, ATTR_LENGTHIS
, $3 ); }
707 | tLCID
'(' expr_int_const
')' { $$
= attr_ptr
( @$
, ATTR_LIBLCID
, $3 ); }
708 | tLCID
{ $$
= attr_int
( @$
, ATTR_PARAMLCID
, 0 ); }
709 | tLICENSED
{ $$
= attr_int
( @$
, ATTR_LICENSED
, 0 ); }
710 | tLOCAL
{ $$
= attr_int
( @$
, ATTR_LOCAL
, 0 ); }
711 | tMARSHALINGBEHAVIOR
'(' marshaling_behavior
')'
712 { $$
= attr_int
( @$
, ATTR_MARSHALING_BEHAVIOR
, $3 ); }
713 | tMAYBE
{ $$
= attr_int
( @$
, ATTR_MAYBE
, 0 ); }
714 | tMESSAGE
{ $$
= attr_int
( @$
, ATTR_MESSAGE
, 0 ); }
715 | tNOCODE
{ $$
= attr_int
( @$
, ATTR_NOCODE
, 0 ); }
716 | tNONBROWSABLE
{ $$
= attr_int
( @$
, ATTR_NONBROWSABLE
, 0 ); }
717 | tNONCREATABLE
{ $$
= attr_int
( @$
, ATTR_NONCREATABLE
, 0 ); }
718 | tNONEXTENSIBLE
{ $$
= attr_int
( @$
, ATTR_NONEXTENSIBLE
, 0 ); }
719 | tNOTIFY
{ $$
= attr_int
( @$
, ATTR_NOTIFY
, 0 ); }
720 | tNOTIFYFLAG
{ $$
= attr_int
( @$
, ATTR_NOTIFYFLAG
, 0 ); }
721 | tOBJECT
{ $$
= attr_int
( @$
, ATTR_OBJECT
, 0 ); }
722 | tODL
{ $$
= attr_int
( @$
, ATTR_ODL
, 0 ); }
723 | tOLEAUTOMATION
{ $$
= attr_int
( @$
, ATTR_OLEAUTOMATION
, 0 ); }
724 | tOPTIMIZE
'(' aSTRING
')' { $$
= attr_ptr
( @$
, ATTR_OPTIMIZE
, $3 ); }
725 | tOPTIONAL
{ $$
= attr_int
( @$
, ATTR_OPTIONAL
, 0 ); }
726 | tOUT
{ $$
= attr_int
( @$
, ATTR_OUT
, 0 ); }
727 | tOVERLOAD
'(' aSTRING
')' { $$
= attr_ptr
( @$
, ATTR_OVERLOAD
, $3 ); }
728 | tPARTIALIGNORE
{ $$
= attr_int
( @$
, ATTR_PARTIALIGNORE
, 0 ); }
729 | tPOINTERDEFAULT
'(' pointer_type
')' { $$
= attr_int
( @$
, ATTR_POINTERDEFAULT
, $3 ); }
730 | tPROGID
'(' aSTRING
')' { $$
= attr_ptr
( @$
, ATTR_PROGID
, $3 ); }
731 | tPROPGET
{ $$
= attr_int
( @$
, ATTR_PROPGET
, 0 ); }
732 | tPROPPUT
{ $$
= attr_int
( @$
, ATTR_PROPPUT
, 0 ); }
733 | tPROPPUTREF
{ $$
= attr_int
( @$
, ATTR_PROPPUTREF
, 0 ); }
734 | tPROTECTED
{ $$
= attr_int
( @$
, ATTR_PROTECTED
, 0 ); }
735 | tPROXY
{ $$
= attr_int
( @$
, ATTR_PROXY
, 0 ); }
736 | tPUBLIC
{ $$
= attr_int
( @$
, ATTR_PUBLIC
, 0 ); }
737 | tRANGE
'(' expr_int_const
',' expr_int_const
')'
738 { expr_list_t
*list
= append_expr
( NULL
, $3 );
739 list
= append_expr
( list
, $5 );
740 $$
= attr_ptr
( @$
, ATTR_RANGE
, list
);
742 | tREADONLY
{ $$
= attr_int
( @$
, ATTR_READONLY
, 0 ); }
743 | tREPRESENTAS
'(' type
')' { $$
= attr_ptr
( @$
, ATTR_REPRESENTAS
, $3 ); }
744 | tREQUESTEDIT
{ $$
= attr_int
( @$
, ATTR_REQUESTEDIT
, 0 ); }
745 | tRESTRICTED
{ $$
= attr_int
( @$
, ATTR_RESTRICTED
, 0 ); }
746 | tRETVAL
{ $$
= attr_int
( @$
, ATTR_RETVAL
, 0 ); }
747 | tSIZEIS
'(' m_exprs
')' { $$
= attr_ptr
( @$
, ATTR_SIZEIS
, $3 ); }
748 | tSOURCE
{ $$
= attr_int
( @$
, ATTR_SOURCE
, 0 ); }
749 | tSTATIC
'(' static_attr
')' { $$
= attr_ptr
( @$
, ATTR_STATIC
, $3 ); }
750 | tSTRICTCONTEXTHANDLE
{ $$
= attr_int
( @$
, ATTR_STRICTCONTEXTHANDLE
, 0 ); }
751 | tSTRING
{ $$
= attr_int
( @$
, ATTR_STRING
, 0 ); }
752 | tSWITCHIS
'(' expr
')' { $$
= attr_ptr
( @$
, ATTR_SWITCHIS
, $3 ); }
753 | tSWITCHTYPE
'(' type
')' { $$
= attr_ptr
( @$
, ATTR_SWITCHTYPE
, $3 ); }
754 | tTRANSMITAS
'(' type
')' { $$
= attr_ptr
( @$
, ATTR_TRANSMITAS
, $3 ); }
755 | tTHREADING
'(' threading_type
')' { $$
= attr_int
( @$
, ATTR_THREADING
, $3 ); }
756 | tUIDEFAULT
{ $$
= attr_int
( @$
, ATTR_UIDEFAULT
, 0 ); }
757 | tUSESGETLASTERROR
{ $$
= attr_int
( @$
, ATTR_USESGETLASTERROR
, 0 ); }
758 | tUSERMARSHAL
'(' type
')' { $$
= attr_ptr
( @$
, ATTR_USERMARSHAL
, $3 ); }
759 | tUUID
'(' aUUID
')' { $$
= attr_ptr
( @$
, ATTR_UUID
, $3 ); }
760 | tASYNCUUID
'(' aUUID
')' { $$
= attr_ptr
( @$
, ATTR_ASYNCUUID
, $3 ); }
761 | tV1ENUM
{ $$
= attr_int
( @$
, ATTR_V1ENUM
, 0 ); }
762 | tVARARG
{ $$
= attr_int
( @$
, ATTR_VARARG
, 0 ); }
763 | tVERSION
'(' version
')' { $$
= attr_int
( @$
, ATTR_VERSION
, $3 ); }
764 | tVIPROGID
'(' aSTRING
')' { $$
= attr_ptr
( @$
, ATTR_VIPROGID
, $3 ); }
765 | tWIREMARSHAL
'(' type
')' { $$
= attr_ptr
( @$
, ATTR_WIREMARSHAL
, $3 ); }
766 | pointer_type
{ $$
= attr_int
( @$
, ATTR_POINTERTYPE
, $1 ); }
776 : %empty
{ $$
= NULL
; }
777 | cases case
{ $$
= append_var
( $1, $2 ); }
780 case
: tCASE expr_int_const
':' union_field
{ attr_t
*a
= attr_ptr
( @$
, ATTR_CASE
, append_expr
( NULL
, $2 ) );
781 $$
= $4; if
(!$$
) $$
= make_var
( NULL
);
782 $$
->attrs
= append_attr
( $$
->attrs
, a
);
784 | tDEFAULT
':' union_field
{ attr_t
*a
= attr_int
( @$
, ATTR_DEFAULT
, 0 );
785 $$
= $3; if
(!$$
) $$
= make_var
( NULL
);
786 $$
->attrs
= append_attr
( $$
->attrs
, a
);
791 : %empty
{ $$
= NULL
; }
792 | enum_list
',' { $$
= $1; }
796 enum_list: enum { if
(!$1->eval
)
797 $1->eval
= make_exprl
(EXPR_NUM
, 0 /* default for first enum entry */);
798 $$
= append_var
( NULL
, $1 );
800 | enum_list
',' enum { if
(!$3->eval
)
802 var_t
*last
= LIST_ENTRY
( list_tail
($$
), var_t
, entry
);
803 enum expr_type type
= EXPR_NUM
;
804 if
(last
->eval
->type
== EXPR_HEXNUM
) type
= EXPR_HEXNUM
;
805 if
(last
->eval
->cval
+ 1 < 0) type
= EXPR_HEXNUM
;
806 $3->eval
= make_exprl
(type
, last
->eval
->cval
+ 1);
808 $$
= append_var
( $1, $3 );
812 enum_member: m_attributes ident
{ $$
= $2;
813 $$
->attrs
= check_enum_member_attrs
($1);
817 enum: enum_member
'=' expr_int_const
{ $$
= reg_const
($1);
819 $$
->declspec.type
= type_new_int
(TYPE_BASIC_INT
, 0);
821 | enum_member
{ $$
= reg_const
($1);
822 $$
->declspec.type
= type_new_int
(TYPE_BASIC_INT
, 0);
826 enumdef: tENUM m_typename
'{' enums
'}' { $$
= type_new_enum
($2, current_namespace
, TRUE
, $4); }
829 m_exprs: m_expr
{ $$
= append_expr
( NULL
, $1 ); }
830 | m_exprs
',' m_expr
{ $$
= append_expr
( $1, $3 ); }
834 : %empty
{ $$
= make_expr
(EXPR_VOID
); }
838 expr: aNUM
{ $$
= make_exprl
(EXPR_NUM
, $1); }
839 | aHEXNUM
{ $$
= make_exprl
(EXPR_HEXNUM
, $1); }
840 | aDOUBLE
{ $$
= make_exprd
(EXPR_DOUBLE
, $1); }
841 | tFALSE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 0); }
842 | tNULL
{ $$
= make_exprl
(EXPR_NUM
, 0); }
843 | tTRUE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 1); }
844 | aSTRING
{ $$
= make_exprs
(EXPR_STRLIT
, $1); }
845 | aWSTRING
{ $$
= make_exprs
(EXPR_WSTRLIT
, $1); }
846 | aSQSTRING
{ $$
= make_exprs
(EXPR_CHARCONST
, $1); }
847 | aIDENTIFIER
{ $$
= make_exprs
(EXPR_IDENTIFIER
, $1); }
848 | expr
'?' expr
':' expr
{ $$
= make_expr3
(EXPR_COND
, $1, $3, $5); }
849 | expr LOGICALOR expr
{ $$
= make_expr2
(EXPR_LOGOR
, $1, $3); }
850 | expr LOGICALAND expr
{ $$
= make_expr2
(EXPR_LOGAND
, $1, $3); }
851 | expr
'|' expr
{ $$
= make_expr2
(EXPR_OR
, $1, $3); }
852 | expr
'^' expr
{ $$
= make_expr2
(EXPR_XOR
, $1, $3); }
853 | expr
'&' expr
{ $$
= make_expr2
(EXPR_AND
, $1, $3); }
854 | expr EQUALITY expr
{ $$
= make_expr2
(EXPR_EQUALITY
, $1, $3); }
855 | expr INEQUALITY expr
{ $$
= make_expr2
(EXPR_INEQUALITY
, $1, $3); }
856 | expr
'>' expr
{ $$
= make_expr2
(EXPR_GTR
, $1, $3); }
857 | expr
'<' expr
{ $$
= make_expr2
(EXPR_LESS
, $1, $3); }
858 | expr GREATEREQUAL expr
{ $$
= make_expr2
(EXPR_GTREQL
, $1, $3); }
859 | expr LESSEQUAL expr
{ $$
= make_expr2
(EXPR_LESSEQL
, $1, $3); }
860 | expr SHL expr
{ $$
= make_expr2
(EXPR_SHL
, $1, $3); }
861 | expr SHR expr
{ $$
= make_expr2
(EXPR_SHR
, $1, $3); }
862 | expr
'+' expr
{ $$
= make_expr2
(EXPR_ADD
, $1, $3); }
863 | expr
'-' expr
{ $$
= make_expr2
(EXPR_SUB
, $1, $3); }
864 | expr
'%' expr
{ $$
= make_expr2
(EXPR_MOD
, $1, $3); }
865 | expr
'*' expr
{ $$
= make_expr2
(EXPR_MUL
, $1, $3); }
866 | expr
'/' expr
{ $$
= make_expr2
(EXPR_DIV
, $1, $3); }
867 |
'!' expr
{ $$
= make_expr1
(EXPR_LOGNOT
, $2); }
868 |
'~' expr
{ $$
= make_expr1
(EXPR_NOT
, $2); }
869 |
'+' expr %prec POS
{ $$
= make_expr1
(EXPR_POS
, $2); }
870 |
'-' expr %prec NEG
{ $$
= make_expr1
(EXPR_NEG
, $2); }
871 |
'&' expr %prec ADDRESSOF
{ $$
= make_expr1
(EXPR_ADDRESSOF
, $2); }
872 |
'*' expr %prec PPTR
{ $$
= make_expr1
(EXPR_PPTR
, $2); }
873 | expr MEMBERPTR aIDENTIFIER
{ $$
= make_expr2
(EXPR_MEMBER
, make_expr1
(EXPR_PPTR
, $1), make_exprs
(EXPR_IDENTIFIER
, $3)); }
874 | expr
'.' aIDENTIFIER
{ $$
= make_expr2
(EXPR_MEMBER
, $1, make_exprs
(EXPR_IDENTIFIER
, $3)); }
875 |
'(' unqualified_decl_spec m_abstract_declarator
')' expr %prec CAST
876 { $$
= make_exprt
(EXPR_CAST
, declare_var
(NULL
, $2, $3, 0), $5); free
($2); free
($3); }
877 | tSIZEOF
'(' unqualified_decl_spec m_abstract_declarator
')'
878 { $$
= make_exprt
(EXPR_SIZEOF
, declare_var
(NULL
, $3, $4, 0), NULL
); free
($3); free
($4); }
879 | expr
'[' expr
']' { $$
= make_expr2
(EXPR_ARRAY
, $1, $3); }
880 |
'(' expr
')' { $$
= $2; }
883 expr_list_int_const: expr_int_const
{ $$
= append_expr
( NULL
, $1 ); }
884 | expr_list_int_const
',' expr_int_const
{ $$
= append_expr
( $1, $3 ); }
887 expr_int_const: expr
{ $$
= $1;
889 error_loc
("expression is not an integer constant\n");
893 expr_const: expr
{ $$
= $1;
894 if
(!$$
->is_const
&& $$
->type
!= EXPR_STRLIT
&& $$
->type
!= EXPR_WSTRLIT
)
895 error_loc
("expression is not constant\n");
900 : %empty
{ $$
= NULL
; }
901 | fields field
{ $$
= append_var_list
($1, $2); }
904 field: m_attributes decl_spec struct_declarator_list
';'
905 { const char *first
= LIST_ENTRY
(list_head
($3), declarator_t
, entry
)->var
->name
;
906 check_field_attrs
(first
, $1);
907 $$
= set_var_types
($1, $2, $3);
909 | m_attributes uniondef
';' { var_t
*v
= make_var
(NULL
);
910 v
->declspec.type
= $2; v
->attrs
= $1;
911 $$
= append_var
(NULL
, v
);
916 s_field
';' { $$
= $1; }
917 | attributes
';' { $$
= make_var
(NULL
); $$
->attrs
= $1; }
921 : %empty
{ $$
= NULL
; }
922 | ne_union_fields ne_union_field
{ $$
= append_var
( $1, $2 ); }
926 s_field
';' { $$
= $1; }
930 s_field: m_attributes decl_spec declarator
{ $$
= declare_var
(check_field_attrs
($3->var
->name
, $1),
934 | m_attributes structdef
{ var_t
*v
= make_var
(NULL
);
935 v
->declspec.type
= $2; v
->attrs
= $1;
940 funcdef: declaration
{ $$
= $1;
941 if
(type_get_type
($$
->declspec.type
) != TYPE_FUNCTION
)
942 error_loc
("only methods may be declared inside the methods section of a dispinterface\n");
943 check_function_attrs
($$
->name
, $$
->attrs
);
948 attributes decl_spec init_declarator
949 { $$
= declare_var
($1, $2, $3, FALSE
);
952 | decl_spec init_declarator
{ $$
= declare_var
(NULL
, $1, $2, FALSE
);
958 : %empty
{ $$
= NULL
; }
963 : %empty
{ $$
= NULL
; }
967 typename: aIDENTIFIER
971 ident: typename
{ $$
= make_var
($1); }
974 base_type: tBYTE
{ $$
= find_type_or_error
( NULL
, "byte" ); }
975 | tWCHAR
{ $$
= find_type_or_error
( NULL
, "wchar_t" ); }
977 | tSIGNED int_std
{ $$
= type_new_int
(type_basic_get_type
($2), -1); }
978 | tUNSIGNED int_std
{ $$
= type_new_int
(type_basic_get_type
($2), 1); }
979 | tUNSIGNED
{ $$
= type_new_int
(TYPE_BASIC_INT
, 1); }
980 | tFLOAT
{ $$
= find_type_or_error
( NULL
, "float" ); }
981 | tDOUBLE
{ $$
= find_type_or_error
( NULL
, "double" ); }
982 | tBOOLEAN
{ $$
= find_type_or_error
( NULL
, "boolean" ); }
983 | tERRORSTATUST
{ $$
= find_type_or_error
( NULL
, "error_status_t" ); }
984 | tHANDLET
{ $$
= find_type_or_error
( NULL
, "handle_t" ); }
992 int_std: tINT
{ $$
= type_new_int
(TYPE_BASIC_INT
, 0); }
993 | tSHORT m_int
{ $$
= type_new_int
(TYPE_BASIC_INT16
, 0); }
994 | tSMALL
{ $$
= type_new_int
(TYPE_BASIC_INT8
, 0); }
995 | tLONG m_int
{ $$
= type_new_int
(TYPE_BASIC_LONG
, 0); }
996 | tHYPER m_int
{ $$
= type_new_int
(TYPE_BASIC_HYPER
, 0); }
997 | tINT64
{ $$
= type_new_int
(TYPE_BASIC_INT64
, 0); }
998 | tCHAR
{ $$
= type_new_int
(TYPE_BASIC_CHAR
, 0); }
999 | tINT32
{ $$
= type_new_int
(TYPE_BASIC_INT32
, 0); }
1000 | tINT3264
{ $$
= type_new_int
(TYPE_BASIC_INT3264
, 0); }
1004 aIDENTIFIER
'.' { $$
= find_namespace_or_error
(&global_namespace
, $1); }
1005 | namespace_pfx aIDENTIFIER
'.' { $$
= find_namespace_or_error
($1, $2); }
1009 typename
{ $$
= find_type_or_error
(current_namespace
, $1); }
1010 | namespace_pfx typename
{ $$
= find_type_or_error
($1, $2); }
1013 parameterized_type: qualified_type
'<' parameterized_type_args
'>'
1014 { $$
= find_parameterized_type
($1, $3); }
1017 parameterized_type_arg:
1018 base_type
{ $$
= $1; }
1019 | qualified_type
{ $$
= $1; }
1020 | qualified_type
'*' { $$
= type_new_pointer
($1); }
1021 | parameterized_type
{ $$
= $1; }
1022 | parameterized_type
'*' { $$
= type_new_pointer
($1); }
1025 parameterized_type_args:
1026 parameterized_type_arg
{ $$
= append_typeref
(NULL
, make_typeref
($1)); }
1027 | parameterized_type_args
',' parameterized_type_arg
1028 { $$
= append_typeref
($1, make_typeref
($3)); }
1031 coclass: tCOCLASS typename
{ $$
= type_coclass_declare
($2); }
1034 coclassdef: attributes coclass
'{' class_interfaces
'}' semicolon_opt
1035 { $$
= type_coclass_define
($2, $1, $4); }
1038 runtimeclass: tRUNTIMECLASS typename
{ $$
= type_runtimeclass_declare
($2, current_namespace
); }
1041 runtimeclass_def: attributes runtimeclass inherit
'{' class_interfaces
'}' semicolon_opt
1042 { if
($3 && type_get_type
($3) != TYPE_RUNTIMECLASS
) error_loc
("%s is not a runtimeclass\n", $3->name
);
1043 $$
= type_runtimeclass_define
($2, $1, $5); }
1046 apicontract: tAPICONTRACT typename
{ $$
= type_apicontract_declare
($2, current_namespace
); }
1049 apicontract_def: attributes apicontract
'{' '}' semicolon_opt
1050 { $$
= type_apicontract_define
($2, $1); }
1053 namespacedef: tNAMESPACE aIDENTIFIER
{ $$
= append_str
( NULL
, $2 ); }
1054 | namespacedef
'.' aIDENTIFIER
{ $$
= append_str
( $1, $3 ); }
1058 : %empty
{ $$
= NULL
; }
1059 | class_interfaces class_interface
{ $$
= append_typeref
( $1, $2 ); }
1063 m_attributes interfaceref
';' { $$
= make_typeref
($2); $$
->attrs
= $1; }
1064 | m_attributes dispinterfaceref
';' { $$
= make_typeref
($2); $$
->attrs
= $1; }
1067 dispinterface: tDISPINTERFACE typename
{ $$
= type_dispinterface_declare
($2); }
1070 dispattributes: attributes
{ $$
= append_attr
( $1, attr_int
( @$
, ATTR_DISPINTERFACE
, 0 ) ); }
1073 dispint_props: tPROPERTIES
':' { $$
= NULL
; }
1074 | dispint_props s_field
';' { $$
= append_var
( $1, $2 ); }
1077 dispint_meths: tMETHODS
':' { $$
= NULL
; }
1078 | dispint_meths funcdef
';' { $$
= append_var
( $1, $2 ); }
1082 dispattributes dispinterface
'{' dispint_props dispint_meths
'}'
1083 { $$
= type_dispinterface_define
($2, $1, $4, $5); }
1084 | dispattributes dispinterface
'{' interface
';' '}'
1085 { $$
= type_dispinterface_define_from_iface
($2, $1, $4); }
1089 : %empty
{ $$
= NULL
; }
1090 |
':' qualified_type
{ $$
= $2; }
1091 |
':' parameterized_type
{ $$
= $2; }
1094 type_parameter: typename
{ $$
= get_type
(TYPE_PARAMETER
, $1, parameters_namespace
, 0); }
1098 type_parameter
{ $$
= append_typeref
(NULL
, make_typeref
($1)); }
1099 | type_parameters
',' type_parameter
{ $$
= append_typeref
($1, make_typeref
($3)); }
1103 tINTERFACE typename
{ $$
= type_interface_declare
($2, current_namespace
); }
1104 | tINTERFACE typename
'<' { push_parameters_namespace
($2); } type_parameters
{ pop_parameters_namespace
($2); } '>'
1105 { $$
= type_parameterized_interface_declare
($2, current_namespace
, $5); }
1108 delegatedef: m_attributes tDELEGATE type ident
'(' m_args
')' semicolon_opt
1109 { $$
= type_delegate_declare
($4->name
, current_namespace
);
1110 $$
= type_delegate_define
($$
, $1, append_statement
(NULL
, make_statement_delegate
($3, $6)));
1112 | m_attributes tDELEGATE type ident
1113 '<' { push_parameters_namespace
($4->name
); } type_parameters
'>'
1114 '(' m_args
')' { pop_parameters_namespace
($4->name
); } semicolon_opt
1115 { $$
= type_parameterized_delegate_declare
($4->name
, current_namespace
, $7);
1116 $$
= type_parameterized_delegate_define
($$
, $1, append_statement
(NULL
, make_statement_delegate
($3, $10)));
1121 qualified_type
{ $$
= append_typeref
(NULL
, make_typeref
($1)); }
1122 | parameterized_type
{ $$
= append_typeref
(NULL
, make_typeref
($1)); }
1123 | required_types
',' qualified_type
{ $$
= append_typeref
($1, make_typeref
($3)); }
1124 | required_types
',' parameterized_type
{ $$
= append_typeref
($1, make_typeref
($3)); }
1128 : %empty
{ $$
= NULL
; }
1129 | tREQUIRES required_types
{ $$
= $2; }
1132 interfacedef: attributes interface
{ if
($2->type_type
== TYPE_PARAMETERIZED_TYPE
) push_parameters_namespace
($2->name
); }
1133 inherit requires
'{' int_statements
'}' semicolon_opt
1134 { if
($2->type_type
== TYPE_PARAMETERIZED_TYPE
)
1136 $$
= type_parameterized_interface_define
($2, $1, $4, $7, $5);
1137 pop_parameters_namespace
($2->name
);
1141 $$
= type_interface_define
($2, $1, $4, $7, $5);
1142 check_async_uuid
($$
);
1145 | dispinterfacedef semicolon_opt
{ $$
= $1; }
1149 tINTERFACE typename
{ $$
= get_type
(TYPE_INTERFACE
, $2, current_namespace
, 0); }
1150 | tINTERFACE namespace_pfx typename
{ $$
= get_type
(TYPE_INTERFACE
, $3, $2, 0); }
1151 | tINTERFACE parameterized_type
{ if
(type_get_type
(($$
= $2)) != TYPE_INTERFACE
) error_loc
("%s is not an interface\n", $$
->name
); }
1155 tDISPINTERFACE typename
{ $$
= get_type
(TYPE_INTERFACE
, $2, current_namespace
, 0); }
1158 module: tMODULE typename
{ $$
= type_module_declare
($2); }
1161 moduledef: m_attributes module
'{' int_statements
'}' semicolon_opt
1162 { $$
= type_module_define
($2, $1, $4); }
1166 tEXTERN
{ $$
= STG_EXTERN
; }
1167 | tSTATIC
{ $$
= STG_STATIC
; }
1168 | tREGISTER
{ $$
= STG_REGISTER
; }
1172 tINLINE
{ $$
= FUNCTION_SPECIFIER_INLINE
; }
1176 tCONST
{ $$
= TYPE_QUALIFIER_CONST
; }
1180 : %empty
{ $$
= 0; }
1181 | m_type_qual_list type_qualifier
{ $$
= $1 |
$2; }
1184 decl_spec: type m_decl_spec_no_type
{ $$
= make_decl_spec
($1, $2, NULL
, STG_NONE
, 0, 0); }
1185 | decl_spec_no_type type m_decl_spec_no_type
1186 { $$
= make_decl_spec
($2, $1, $3, STG_NONE
, 0, 0); }
1189 unqualified_decl_spec: unqualified_type m_decl_spec_no_type
1190 { $$
= make_decl_spec
($1, $2, NULL
, STG_NONE
, 0, 0); }
1191 | decl_spec_no_type unqualified_type m_decl_spec_no_type
1192 { $$
= make_decl_spec
($2, $1, $3, STG_NONE
, 0, 0); }
1196 : %empty
{ $$
= NULL
; }
1201 type_qualifier m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, STG_NONE
, $1, 0); }
1202 | function_specifier m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, STG_NONE
, 0, $1); }
1203 | storage_cls_spec m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, $1, 0, 0); }
1207 '*' m_type_qual_list declarator %prec PPTR
1208 { $$
= $3; append_chain_type
($$
, type_new_pointer
(NULL
), $2); }
1209 | callconv declarator
{ $$
= $2; append_chain_callconv
( @$
, $$
->type
, $1 ); }
1214 ident
{ $$
= make_declarator
($1); }
1215 |
'(' declarator
')' { $$
= $2; }
1216 | direct_declarator array
{ $$
= $1; append_array
($$
, $2); }
1217 | direct_declarator
'(' m_args
')' { $$
= $1; append_chain_type
($$
, type_new_function
($3), 0); }
1220 /* abstract declarator */
1221 abstract_declarator:
1222 '*' m_type_qual_list m_abstract_declarator %prec PPTR
1223 { $$
= $3; append_chain_type
($$
, type_new_pointer
(NULL
), $2); }
1224 | callconv m_abstract_declarator
{ $$
= $2; append_chain_callconv
( @$
, $$
->type
, $1 ); }
1225 | abstract_direct_declarator
1228 /* abstract declarator without accepting direct declarator */
1229 abstract_declarator_no_direct:
1230 '*' m_type_qual_list m_any_declarator %prec PPTR
1231 { $$
= $3; append_chain_type
($$
, type_new_pointer
(NULL
), $2); }
1232 | callconv m_any_declarator
{ $$
= $2; append_chain_callconv
( @$
, $$
->type
, $1 ); }
1235 /* abstract declarator or empty */
1236 m_abstract_declarator
1237 : %empty
{ $$
= make_declarator
(NULL
); }
1238 | abstract_declarator
1241 /* abstract direct declarator */
1242 abstract_direct_declarator:
1243 '(' abstract_declarator_no_direct
')' { $$
= $2; }
1244 | abstract_direct_declarator array
{ $$
= $1; append_array
($$
, $2); }
1245 | array
{ $$
= make_declarator
(NULL
); append_array
($$
, $1); }
1247 { $$
= make_declarator
(NULL
);
1248 append_chain_type
($$
, type_new_function
($2), 0);
1250 | abstract_direct_declarator
'(' m_args
')'
1252 append_chain_type
($$
, type_new_function
($3), 0);
1256 /* abstract or non-abstract declarator */
1258 '*' m_type_qual_list m_any_declarator %prec PPTR
1259 { $$
= $3; append_chain_type
($$
, type_new_pointer
(NULL
), $2); }
1260 | callconv m_any_declarator
{ $$
= $2; append_chain_callconv
( @$
, $$
->type
, $1 ); }
1261 | any_direct_declarator
1264 /* abstract or non-abstract declarator without accepting direct declarator */
1265 any_declarator_no_direct:
1266 '*' m_type_qual_list m_any_declarator %prec PPTR
1267 { $$
= $3; append_chain_type
($$
, type_new_pointer
(NULL
), $2); }
1268 | callconv m_any_declarator
{ $$
= $2; append_chain_callconv
( @$
, $$
->type
, $1 ); }
1271 /* abstract or non-abstract declarator or empty */
1273 : %empty
{ $$
= make_declarator
(NULL
); }
1277 /* abstract or non-abstract direct declarator. note: direct declarators
1278 * aren't accepted inside brackets to avoid ambiguity with the rule for
1279 * function arguments */
1280 any_direct_declarator:
1281 ident
{ $$
= make_declarator
($1); }
1282 |
'(' any_declarator_no_direct
')' { $$
= $2; }
1283 | any_direct_declarator array
{ $$
= $1; append_array
($$
, $2); }
1284 | array
{ $$
= make_declarator
(NULL
); append_array
($$
, $1); }
1286 { $$
= make_declarator
(NULL
);
1287 append_chain_type
($$
, type_new_function
($2), 0);
1289 | any_direct_declarator
'(' m_args
')'
1291 append_chain_type
($$
, type_new_function
($3), 0);
1296 declarator
{ $$
= append_declarator
( NULL
, $1 ); }
1297 | declarator_list
',' declarator
{ $$
= append_declarator
( $1, $3 ); }
1301 : %empty
{ $$
= NULL
; }
1302 |
':' expr_const
{ $$
= $2; }
1305 struct_declarator: any_declarator m_bitfield
{ $$
= $1; $$
->bits
= $2;
1306 if
(!$$
->bits
&& !$$
->var
->name
)
1307 error_loc
("unnamed fields are not allowed\n");
1311 struct_declarator_list:
1312 struct_declarator
{ $$
= append_declarator
( NULL
, $1 ); }
1313 | struct_declarator_list
',' struct_declarator
1314 { $$
= append_declarator
( $1, $3 ); }
1318 declarator
{ $$
= $1; }
1319 | declarator
'=' expr_const
{ $$
= $1; $1->var
->eval
= $3; }
1323 tAPARTMENT
{ $$
= THREADING_APARTMENT
; }
1324 | tNEUTRAL
{ $$
= THREADING_NEUTRAL
; }
1325 | tSINGLE
{ $$
= THREADING_SINGLE
; }
1326 | tFREE
{ $$
= THREADING_FREE
; }
1327 | tBOTH
{ $$
= THREADING_BOTH
; }
1328 | tMTA
{ $$
= THREADING_FREE
; }
1332 tREF
{ $$
= FC_RP
; }
1333 | tUNIQUE
{ $$
= FC_UP
; }
1334 | tPTR
{ $$
= FC_FP
; }
1337 structdef: tSTRUCT m_typename
'{' fields
'}' { $$
= type_new_struct
($2, current_namespace
, TRUE
, $4); }
1341 tVOID
{ $$
= type_new_void
(); }
1342 | base_type
{ $$
= $1; }
1343 | enumdef
{ $$
= $1; }
1344 | tENUM aIDENTIFIER
{ $$
= type_new_enum
($2, current_namespace
, FALSE
, NULL
); }
1345 | structdef
{ $$
= $1; }
1346 | tSTRUCT aIDENTIFIER
{ $$
= type_new_struct
($2, current_namespace
, FALSE
, NULL
); }
1347 | uniondef
{ $$
= $1; }
1348 | tUNION aIDENTIFIER
{ $$
= type_new_nonencapsulated_union
($2, current_namespace
, FALSE
, NULL
); }
1349 | tSAFEARRAY
'(' type
')' { $$
= make_safearray
($3); }
1350 | aKNOWNTYPE
{ $$
= find_type_or_error
(current_namespace
, $1); }
1355 | namespace_pfx typename
{ $$
= find_type_or_error
($1, $2); }
1356 | parameterized_type
{ $$
= $1; }
1359 typedef: m_attributes tTYPEDEF m_attributes decl_spec declarator_list
1360 { $1 = append_attribs
($1, $3);
1361 reg_typedefs
( @$
, $4, $5, check_typedef_attrs
( $1 ) );
1362 $$
= make_statement_typedef
($5, !$4->type
->defined
);
1366 uniondef: tUNION m_typename
'{' ne_union_fields
'}'
1367 { $$
= type_new_nonencapsulated_union
($2, current_namespace
, TRUE
, $4); }
1369 tSWITCH
'(' s_field
')'
1370 m_ident
'{' cases
'}' { $$
= type_new_encapsulated_union
($2, $5, $7, $9); }
1374 aNUM
{ $$
= MAKEVERSION
($1, 0); }
1375 | aNUM
'.' aNUM
{ $$
= MAKEVERSION
($1, $3); }
1376 | aHEXNUM
{ $$
= $1; }
1381 | acf_interface acf_statements
1386 | acf_int_statement acf_int_statements
1390 : tTYPEDEF acf_attributes aKNOWNTYPE
';'
1391 { type_t
*type
= find_type_or_error
(current_namespace
, $3);
1392 type
->attrs
= append_attr_list
(type
->attrs
, $2);
1397 : acf_attributes tINTERFACE aKNOWNTYPE
'{' acf_int_statements
'}'
1398 { type_t
*iface
= find_type_or_error
(current_namespace
, $3);
1399 if
(type_get_type
(iface
) != TYPE_INTERFACE
)
1400 error_loc
("%s is not an interface\n", iface
->name
);
1401 iface
->attrs
= append_attr_list
(iface
->attrs
, $1);
1406 : %empty
{ $$
= NULL
; }
1407 |
'[' acf_attribute_list
']' { $$
= $2; }
1411 : acf_attribute
{ $$
= append_attr
(NULL
, $1); }
1412 | acf_attribute_list
',' acf_attribute
{ $$
= append_attr
($1, $3); }
1416 : tALLOCATE
'(' allocate_option_list
')'
1417 { $$
= attr_int
( @$
, ATTR_ALLOCATE
, $3 ); }
1418 | tENCODE
{ $$
= attr_int
( @$
, ATTR_ENCODE
, 0 ); }
1419 | tDECODE
{ $$
= attr_int
( @$
, ATTR_DECODE
, 0 ); }
1420 | tEXPLICITHANDLE
{ $$
= attr_int
( @$
, ATTR_EXPLICIT_HANDLE
, 0 ); }
1423 allocate_option_list
1424 : allocate_option
{ $$
= $1; }
1425 | allocate_option_list
',' allocate_option
1430 : tDONTFREE
{ $$
= FC_DONT_FREE
; }
1432 | tALLNODES
{ $$
= FC_ALLOCATE_ALL_NODES
; }
1433 | tSINGLENODE
{ $$
= 0; }
1438 static void decl_builtin_basic
(const char *name
, enum type_basic_type type
)
1440 type_t
*t
= type_new_basic
(type
);
1441 reg_type
(t
, name
, NULL
, 0);
1444 static void decl_builtin_alias
(const char *name
, type_t
*t
)
1446 const decl_spec_t ds
= {.type
= t
};
1447 reg_type
(type_new_alias
(&ds
, name
), name
, NULL
, 0);
1450 void init_types
(void)
1452 decl_builtin_basic
("byte", TYPE_BASIC_BYTE
);
1453 decl_builtin_basic
("wchar_t", TYPE_BASIC_WCHAR
);
1454 decl_builtin_basic
("float", TYPE_BASIC_FLOAT
);
1455 decl_builtin_basic
("double", TYPE_BASIC_DOUBLE
);
1456 decl_builtin_basic
("error_status_t", TYPE_BASIC_ERROR_STATUS_T
);
1457 decl_builtin_basic
("handle_t", TYPE_BASIC_HANDLE
);
1458 decl_builtin_alias
("boolean", type_new_basic
(TYPE_BASIC_CHAR
));
1461 static str_list_t
*append_str
(str_list_t
*list
, char *str
)
1463 struct str_list_entry_t
*entry
;
1465 if
(!str
) return list
;
1468 list
= xmalloc
( sizeof
(*list
) );
1471 entry
= xmalloc
( sizeof
(*entry
) );
1473 list_add_tail
( list
, &entry
->entry
);
1478 static decl_spec_t
*make_decl_spec
(type_t
*type
, decl_spec_t
*left
, decl_spec_t
*right
,
1479 enum storage_class stgclass
, enum type_qualifier qual
, enum function_specifier func_specifier
)
1481 decl_spec_t
*declspec
= left ? left
: right
;
1484 declspec
= xmalloc
(sizeof
(*declspec
));
1485 declspec
->type
= NULL
;
1486 declspec
->stgclass
= STG_NONE
;
1487 declspec
->qualifier
= 0;
1488 declspec
->func_specifier
= 0;
1490 declspec
->type
= type
;
1491 if
(left
&& declspec
!= left
)
1493 if
(declspec
->stgclass
== STG_NONE
)
1494 declspec
->stgclass
= left
->stgclass
;
1495 else if
(left
->stgclass
!= STG_NONE
)
1496 error_loc
("only one storage class can be specified\n");
1497 declspec
->qualifier |
= left
->qualifier
;
1498 declspec
->func_specifier |
= left
->func_specifier
;
1499 assert
(!left
->type
);
1502 if
(right
&& declspec
!= right
)
1504 if
(declspec
->stgclass
== STG_NONE
)
1505 declspec
->stgclass
= right
->stgclass
;
1506 else if
(right
->stgclass
!= STG_NONE
)
1507 error_loc
("only one storage class can be specified\n");
1508 declspec
->qualifier |
= right
->qualifier
;
1509 declspec
->func_specifier |
= right
->func_specifier
;
1510 assert
(!right
->type
);
1514 if
(declspec
->stgclass
== STG_NONE
)
1515 declspec
->stgclass
= stgclass
;
1516 else if
(stgclass
!= STG_NONE
)
1517 error_loc
("only one storage class can be specified\n");
1518 declspec
->qualifier |
= qual
;
1519 declspec
->func_specifier |
= func_specifier
;
1524 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
)
1526 if
(!expr
) return list
;
1529 list
= xmalloc
( sizeof
(*list
) );
1532 list_add_tail
( list
, &expr
->entry
);
1536 static void append_array
(declarator_t
*decl
, expr_t
*expr
)
1543 /* An array is always a reference pointer unless explicitly marked otherwise
1544 * (regardless of what the default pointer attribute is). */
1545 array
= type_new_array
(NULL
, NULL
, FALSE
, expr
->is_const ? expr
->cval
: 0,
1546 expr
->is_const ? NULL
: expr
, NULL
);
1548 append_chain_type
(decl
, array
, 0);
1551 static struct list type_pool
= LIST_INIT
(type_pool
);
1558 type_t
*alloc_type
(void)
1560 type_pool_node_t
*node
= xmalloc
(sizeof
*node
);
1561 list_add_tail
(&type_pool
, &node
->link
);
1565 void set_all_tfswrite
(int val
)
1567 type_pool_node_t
*node
;
1568 LIST_FOR_EACH_ENTRY
(node
, &type_pool
, type_pool_node_t
, link
)
1569 node
->data.tfswrite
= val
;
1572 void clear_all_offsets
(void)
1574 type_pool_node_t
*node
;
1575 LIST_FOR_EACH_ENTRY
(node
, &type_pool
, type_pool_node_t
, link
)
1576 node
->data.typestring_offset
= node
->data.ptrdesc
= 0;
1579 static void type_function_add_head_arg
(type_t
*type
, var_t
*arg
)
1581 if
(!type
->details.function
->args
)
1583 type
->details.function
->args
= xmalloc
( sizeof
(*type
->details.function
->args
) );
1584 list_init
( type
->details.function
->args
);
1586 list_add_head
( type
->details.function
->args
, &arg
->entry
);
1589 static int is_allowed_range_type
(const type_t
*type
)
1591 switch
(type_get_type
(type
))
1596 switch
(type_basic_get_type
(type
))
1598 case TYPE_BASIC_INT8
:
1599 case TYPE_BASIC_INT16
:
1600 case TYPE_BASIC_INT32
:
1601 case TYPE_BASIC_INT64
:
1602 case TYPE_BASIC_INT
:
1603 case TYPE_BASIC_INT3264
:
1604 case TYPE_BASIC_LONG
:
1605 case TYPE_BASIC_BYTE
:
1606 case TYPE_BASIC_CHAR
:
1607 case TYPE_BASIC_WCHAR
:
1608 case TYPE_BASIC_HYPER
:
1610 case TYPE_BASIC_FLOAT
:
1611 case TYPE_BASIC_DOUBLE
:
1612 case TYPE_BASIC_ERROR_STATUS_T
:
1613 case TYPE_BASIC_HANDLE
:
1622 static type_t
*get_chain_ref
(type_t
*type
)
1625 return type_pointer_get_ref_type
(type
);
1626 else if
(is_array
(type
))
1627 return type_array_get_element_type
(type
);
1628 else if
(is_func
(type
))
1629 return type_function_get_rettype
(type
);
1633 static type_t
*get_chain_end
(type_t
*type
)
1636 while
((inner
= get_chain_ref
(type
)))
1641 static void append_chain_type
(declarator_t
*decl
, type_t
*type
, enum type_qualifier qual
)
1648 decl
->qualifier
= qual
;
1651 chain_type
= get_chain_end
(decl
->type
);
1653 if
(is_ptr
(chain_type
))
1655 chain_type
->details.pointer.ref.type
= type
;
1656 chain_type
->details.pointer.ref.qualifier
= qual
;
1658 else if
(is_array
(chain_type
))
1660 chain_type
->details.array.elem.type
= type
;
1661 chain_type
->details.array.elem.qualifier
= qual
;
1663 else if
(is_func
(chain_type
))
1665 chain_type
->details.function
->retval
->declspec.type
= type
;
1666 chain_type
->details.function
->retval
->declspec.qualifier
= qual
;
1671 if
(!is_func
(chain_type
))
1672 type
->attrs
= move_attr
(type
->attrs
, chain_type
->attrs
, ATTR_CALLCONV
);
1675 static void append_chain_callconv
( struct location where
, type_t
*chain
, char *callconv
)
1679 if
(chain
&& (chain_end
= get_chain_end
(chain
)))
1680 chain_end
->attrs
= append_attr
( chain_end
->attrs
, attr_ptr
( where
, ATTR_CALLCONV
, callconv
) );
1682 error_loc
("calling convention applied to non-function type\n");
1685 static warning_list_t
*append_warning
(warning_list_t
*list
, int num
)
1691 list
= xmalloc
( sizeof
(*list
) );
1694 entry
= xmalloc
( sizeof
(*entry
) );
1696 list_add_tail
( list
, &entry
->entry
);
1700 static var_t
*declare_var
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_t
*decl
,
1703 var_t
*v
= decl
->var
;
1704 expr_list_t
*sizes
= get_attrp
(attrs
, ATTR_SIZEIS
);
1705 expr_list_t
*lengs
= get_attrp
(attrs
, ATTR_LENGTHIS
);
1708 type_t
*type
= decl_spec
->type
;
1710 if
(decl_spec
->func_specifier
& FUNCTION_SPECIFIER_INLINE
)
1712 if
(!decl ||
!is_func
(decl
->type
))
1713 error_loc
("inline attribute applied to non-function type\n");
1716 /* add type onto the end of the pointers in pident->type */
1717 append_chain_type
(decl
, type
, decl_spec
->qualifier
);
1718 v
->declspec
= *decl_spec
;
1719 v
->declspec.type
= decl
->type
;
1720 v
->declspec.qualifier
= decl
->qualifier
;
1722 v
->declonly
= !type
->defined
;
1724 if
(is_attr
(type
->attrs
, ATTR_CALLCONV
) && !is_func
(type
))
1725 error_loc
("calling convention applied to non-function type\n");
1727 /* check for pointer attribute being applied to non-pointer, non-array
1729 if
(!is_array
(v
->declspec.type
))
1731 int ptr_attr
= get_attrv
(v
->attrs
, ATTR_POINTERTYPE
);
1732 const type_t
*ptr
= NULL
;
1733 for
(ptr
= v
->declspec.type
; ptr
&& !ptr_attr
; )
1735 ptr_attr
= get_attrv
(ptr
->attrs
, ATTR_POINTERTYPE
);
1736 if
(!ptr_attr
&& type_is_alias
(ptr
))
1737 ptr
= type_alias_get_aliasee_type
(ptr
);
1743 if
(ptr_attr
&& ptr_attr
!= FC_UP
&&
1744 type_get_type
(type_pointer_get_ref_type
(ptr
)) == TYPE_INTERFACE
)
1745 warning_at
( &v
->where
, "%s: pointer attribute applied to interface pointer type has no effect\n", v
->name
);
1746 if
(!ptr_attr
&& top
)
1748 /* FIXME: this is a horrible hack to cope with the issue that we
1749 * store an offset to the typeformat string in the type object, but
1750 * two typeformat strings may be written depending on whether the
1751 * pointer is a toplevel parameter or not */
1752 v
->declspec.type
= duptype
(v
->declspec.type
, 1);
1756 error_loc
("%s: pointer attribute applied to non-pointer type\n", v
->name
);
1759 if
(is_attr
(v
->attrs
, ATTR_STRING
))
1763 if
(!is_ptr
(v
->declspec.type
) && !is_array
(v
->declspec.type
))
1764 error_loc
("'%s': [string] attribute applied to non-pointer, non-array type\n",
1770 t
= type_pointer_get_ref_type
(t
);
1771 else if
(is_array
(t
))
1772 t
= type_array_get_element_type
(t
);
1777 if
(type_get_type
(t
) != TYPE_BASIC
&&
1778 (get_basic_fc
(t
) != FC_CHAR
&&
1779 get_basic_fc
(t
) != FC_BYTE
&&
1780 get_basic_fc
(t
) != FC_WCHAR
))
1782 error_loc
("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
1787 if
(is_attr
(v
->attrs
, ATTR_V1ENUM
))
1789 if
(type_get_type_detect_alias
(v
->declspec.type
) != TYPE_ENUM
)
1790 error_loc
("'%s': [v1_enum] attribute applied to non-enum type\n", v
->name
);
1793 if
(is_attr
(v
->attrs
, ATTR_RANGE
) && !is_allowed_range_type
(v
->declspec.type
))
1794 error_loc
("'%s': [range] attribute applied to non-integer type\n",
1797 ptype
= &v
->declspec.type
;
1798 if
(sizes
) LIST_FOR_EACH_ENTRY
(dim
, sizes
, expr_t
, entry
)
1800 if
(dim
->type
!= EXPR_VOID
)
1802 if
(is_array
(*ptype
))
1804 if
(!type_array_get_conformance
(*ptype
) ||
1805 type_array_get_conformance
(*ptype
)->type
!= EXPR_VOID
)
1806 error_loc
("%s: cannot specify size_is for an already sized array\n", v
->name
);
1808 *ptype
= type_new_array
((*ptype
)->name
,
1809 type_array_get_element
(*ptype
), FALSE
,
1812 else if
(is_ptr
(*ptype
))
1813 *ptype
= type_new_array
((*ptype
)->name
, type_pointer_get_ref
(*ptype
), TRUE
,
1816 error_loc
("%s: size_is attribute applied to illegal type\n", v
->name
);
1820 ptype
= &(*ptype
)->details.pointer.ref.type
;
1821 else if
(is_array
(*ptype
))
1822 ptype
= &(*ptype
)->details.array.elem.type
;
1824 error_loc
("%s: too many expressions in size_is attribute\n", v
->name
);
1827 ptype
= &v
->declspec.type
;
1828 if
(lengs
) LIST_FOR_EACH_ENTRY
(dim
, lengs
, expr_t
, entry
)
1830 if
(dim
->type
!= EXPR_VOID
)
1832 if
(is_array
(*ptype
))
1834 *ptype
= type_new_array
((*ptype
)->name
,
1835 type_array_get_element
(*ptype
),
1836 type_array_is_decl_as_ptr
(*ptype
),
1837 type_array_get_dim
(*ptype
),
1838 type_array_get_conformance
(*ptype
), dim
);
1841 error_loc
("%s: length_is attribute applied to illegal type\n", v
->name
);
1845 ptype
= &(*ptype
)->details.pointer.ref.type
;
1846 else if
(is_array
(*ptype
))
1847 ptype
= &(*ptype
)->details.array.elem.type
;
1849 error_loc
("%s: too many expressions in length_is attribute\n", v
->name
);
1853 v
->declspec.type
= type_new_bitfield
(v
->declspec.type
, decl
->bits
);
1858 static var_list_t
*set_var_types
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_list_t
*decls
)
1860 declarator_t
*decl
, *next
;
1861 var_list_t
*var_list
= NULL
;
1863 LIST_FOR_EACH_ENTRY_SAFE
( decl
, next
, decls
, declarator_t
, entry
)
1865 var_t
*var
= declare_var
(attrs
, decl_spec
, decl
, 0);
1866 var_list
= append_var
(var_list
, var
);
1873 typeref_list_t
*append_typeref
(typeref_list_t
*list
, typeref_t
*ref
)
1875 if
(!ref
) return list
;
1878 list
= xmalloc
( sizeof
(*list
) );
1881 list_add_tail
( list
, &ref
->entry
);
1885 typeref_t
*make_typeref
(type_t
*type
)
1887 typeref_t
*ref
= xmalloc
(sizeof
(typeref_t
));
1893 var_list_t
*append_var
(var_list_t
*list
, var_t
*var
)
1895 if
(!var
) return list
;
1898 list
= xmalloc
( sizeof
(*list
) );
1901 list_add_tail
( list
, &var
->entry
);
1905 static var_list_t
*append_var_list
(var_list_t
*list
, var_list_t
*vars
)
1907 if
(!vars
) return list
;
1910 list
= xmalloc
( sizeof
(*list
) );
1913 list_move_tail
( list
, vars
);
1917 var_t
*make_var
(char *name
)
1919 var_t
*v
= xmalloc
(sizeof
(var_t
));
1921 init_declspec
(&v
->declspec
, NULL
);
1924 init_location
( &v
->where
, NULL
, NULL
);
1925 v
->declonly
= FALSE
;
1929 static var_t
*copy_var
(var_t
*src
, char *name
, map_attrs_filter_t attr_filter
)
1931 var_t
*v
= xmalloc
(sizeof
(var_t
));
1933 v
->declspec
= src
->declspec
;
1934 v
->attrs
= map_attrs
(src
->attrs
, attr_filter
);
1935 v
->eval
= src
->eval
;
1936 v
->where
= src
->where
;
1940 static declarator_list_t
*append_declarator
(declarator_list_t
*list
, declarator_t
*d
)
1942 if
(!d
) return list
;
1944 list
= xmalloc
(sizeof
(*list
));
1947 list_add_tail
(list
, &d
->entry
);
1951 static declarator_t
*make_declarator
(var_t
*var
)
1953 declarator_t
*d
= xmalloc
(sizeof
(*d
));
1954 d
->var
= var ? var
: make_var
(NULL
);
1961 static type_t
*make_safearray
(type_t
*type
)
1963 decl_spec_t ds
= {.type
= type
};
1964 ds.type
= type_new_alias
(&ds
, "SAFEARRAY");
1965 return type_new_array
(NULL
, &ds
, TRUE
, 0, NULL
, NULL
);
1968 static typelib_t
*make_library
(const char *name
, const attr_list_t
*attrs
)
1970 typelib_t
*typelib
= xmalloc
(sizeof
(*typelib
));
1971 memset
(typelib
, 0, sizeof
(*typelib
));
1972 typelib
->name
= xstrdup
(name
);
1973 typelib
->attrs
= attrs
;
1974 list_init
( &typelib
->importlibs
);
1978 static int hash_ident
(const char *name
)
1980 const char *p
= name
;
1982 /* a simple sum hash is probably good enough */
1987 return sum
& (HASHMAX
-1);
1990 /***** type repository *****/
1992 static struct namespace
*find_sub_namespace
(struct namespace
*namespace
, const char *name
)
1994 struct namespace
*cur
;
1996 LIST_FOR_EACH_ENTRY
(cur
, &namespace
->children
, struct namespace
, entry
) {
1997 if
(!strcmp
(cur
->name
, name
))
2004 static void push_namespace
(const char *name
)
2006 struct namespace
*namespace
;
2008 namespace
= find_sub_namespace
(current_namespace
, name
);
2010 namespace
= xmalloc
(sizeof
(*namespace
));
2011 namespace
->name
= xstrdup
(name
);
2012 namespace
->parent
= current_namespace
;
2013 list_add_tail
(¤t_namespace
->children
, &namespace
->entry
);
2014 list_init
(&namespace
->children
);
2015 memset
(namespace
->type_hash
, 0, sizeof
(namespace
->type_hash
));
2018 current_namespace
= namespace
;
2021 static void pop_namespace
(const char *name
)
2023 assert
(!strcmp
(current_namespace
->name
, name
) && current_namespace
->parent
);
2024 current_namespace
= current_namespace
->parent
;
2027 static void push_namespaces
(str_list_t
*names
)
2029 const struct str_list_entry_t
*name
;
2030 LIST_FOR_EACH_ENTRY
(name
, names
, const struct str_list_entry_t
, entry
)
2031 push_namespace
(name
->str
);
2034 static void pop_namespaces
(str_list_t
*names
)
2036 const struct str_list_entry_t
*name
;
2037 LIST_FOR_EACH_ENTRY_REV
(name
, names
, const struct str_list_entry_t
, entry
)
2038 pop_namespace
(name
->str
);
2041 static void push_parameters_namespace
(const char *name
)
2043 struct namespace
*namespace
;
2045 if
(!(namespace
= find_sub_namespace
(current_namespace
, name
)))
2047 namespace
= xmalloc
(sizeof
(*namespace
));
2048 namespace
->name
= xstrdup
(name
);
2049 namespace
->parent
= current_namespace
;
2050 list_add_tail
(¤t_namespace
->children
, &namespace
->entry
);
2051 list_init
(&namespace
->children
);
2052 memset
(namespace
->type_hash
, 0, sizeof
(namespace
->type_hash
));
2055 parameters_namespace
= namespace
;
2058 static void pop_parameters_namespace
(const char *name
)
2060 assert
(!strcmp
(parameters_namespace
->name
, name
) && parameters_namespace
->parent
);
2061 parameters_namespace
= NULL
;
2071 type_t
*reg_type
(type_t
*type
, const char *name
, struct namespace
*namespace
, int t
)
2076 error_loc
("registering named type without name\n");
2080 namespace
= &global_namespace
;
2081 hash
= hash_ident
(name
);
2082 nt
= xmalloc
(sizeof
(struct rtype
));
2084 if
(is_global_namespace
(namespace
))
2086 type
->c_name
= name
;
2087 type
->qualified_name
= name
;
2091 type
->c_name
= format_namespace
(namespace
, "__x_", "_C", name
, use_abi_namespace ?
"ABI" : NULL
);
2092 type
->qualified_name
= format_namespace
(namespace
, "", "::", name
, use_abi_namespace ?
"ABI" : NULL
);
2096 nt
->next
= namespace
->type_hash
[hash
];
2097 namespace
->type_hash
[hash
] = nt
;
2101 static type_t
*reg_typedefs
( struct location where
, decl_spec_t
*decl_spec
, declarator_list_t
*decls
, attr_list_t
*attrs
)
2104 type_t
*type
= decl_spec
->type
;
2106 if
(is_attr
(attrs
, ATTR_UUID
) && !is_attr
(attrs
, ATTR_PUBLIC
))
2107 attrs
= append_attr
( attrs
, attr_int
( where
, ATTR_PUBLIC
, 0 ) );
2109 /* We must generate names for tagless enum, struct or union.
2110 Typedef-ing a tagless enum, struct or union means we want the typedef
2111 to be included in a library hence the public attribute. */
2112 if
(type_get_type_detect_alias
(type
) == TYPE_ENUM ||
2113 type_get_type_detect_alias
(type
) == TYPE_STRUCT ||
2114 type_get_type_detect_alias
(type
) == TYPE_UNION ||
2115 type_get_type_detect_alias
(type
) == TYPE_ENCAPSULATED_UNION
)
2119 type
->name
= gen_name
();
2120 if
(!is_attr
(attrs
, ATTR_PUBLIC
))
2121 attrs
= append_attr
( attrs
, attr_int
( where
, ATTR_PUBLIC
, 0 ) );
2124 /* replace existing attributes when generating a typelib */
2126 type
->attrs
= attrs
;
2129 LIST_FOR_EACH_ENTRY
( decl
, decls
, declarator_t
, entry
)
2132 if
(decl
->var
->name
) {
2136 cur
= find_type
(decl
->var
->name
, current_namespace
, 0);
2139 * MIDL allows shadowing types that are declared in imported files.
2140 * We don't throw an error in this case and instead add a new type
2141 * (which is earlier on the list in hash table, so it will be used
2142 * instead of shadowed type).
2144 * FIXME: We may consider string separated type tables for each input
2145 * for cleaner solution.
2147 if
(cur
&& input_name
== cur
->where.input_name
)
2148 error_loc
( "%s: redefinition error; original definition was at %s:%d\n",
2149 cur
->name
, cur
->where.input_name
, cur
->where.first_line
);
2151 name
= declare_var
(attrs
, decl_spec
, decl
, 0);
2152 cur
= type_new_alias
(&name
->declspec
, name
->name
);
2155 reg_type
(cur
, cur
->name
, current_namespace
, 0);
2161 type_t
*find_type
(const char *name
, struct namespace
*namespace
, int t
)
2165 if
(namespace
&& namespace
!= &global_namespace
) {
2166 for
(cur
= namespace
->type_hash
[hash_ident
(name
)]; cur
; cur
= cur
->next
) {
2167 if
(cur
->t
== t
&& !strcmp
(cur
->name
, name
))
2171 for
(cur
= global_namespace.type_hash
[hash_ident
(name
)]; cur
; cur
= cur
->next
) {
2172 if
(cur
->t
== t
&& !strcmp
(cur
->name
, name
))
2178 static type_t
*find_type_or_error
(struct namespace
*namespace
, const char *name
)
2181 if
(!(type
= find_type
(name
, namespace
, 0)) &&
2182 !(type
= find_type
(name
, parameters_namespace
, 0)))
2184 error_loc
("type '%s' not found in %s namespace\n", name
, namespace
&& namespace
->name ? namespace
->name
: "global");
2190 static struct namespace
*find_namespace_or_error
(struct namespace
*parent
, const char *name
)
2192 struct namespace
*namespace
= NULL
;
2195 error_loc
("namespaces are only supported in winrt mode.\n");
2196 else if
(!(namespace
= find_sub_namespace
(parent
, name
)))
2197 error_loc
("namespace '%s' not found in '%s'\n", name
, parent
->name
);
2202 int is_type
(const char *name
)
2204 return find_type
(name
, current_namespace
, 0) != NULL ||
2205 find_type
(name
, parameters_namespace
, 0);
2208 type_t
*get_type
(enum type_type type
, char *name
, struct namespace
*namespace
, int t
)
2212 namespace
= &global_namespace
;
2214 tp
= find_type
(name
, namespace
, t
);
2220 tp
= make_type
(type
);
2222 tp
->namespace
= namespace
;
2223 if
(!name
) return tp
;
2224 return reg_type
(tp
, name
, namespace
, t
);
2227 /***** constant repository *****/
2232 struct rconst
*next
;
2235 struct rconst
*const_hash
[HASHMAX
];
2237 static var_t
*reg_const
(var_t
*var
)
2242 error_loc
("registering constant without name\n");
2245 hash
= hash_ident
(var
->name
);
2246 nc
= xmalloc
(sizeof
(struct rconst
));
2247 nc
->name
= var
->name
;
2249 nc
->next
= const_hash
[hash
];
2250 const_hash
[hash
] = nc
;
2254 var_t
*find_const
(const char *name
, int f
)
2256 struct rconst
*cur
= const_hash
[hash_ident
(name
)];
2257 while
(cur
&& strcmp
(cur
->name
, name
))
2260 if
(f
) error_loc
("constant '%s' not found\n", name
);
2266 char *gen_name
(void)
2268 static unsigned long n
= 0;
2269 static const char *file_id
;
2273 char *dst
= replace_extension
( idl_name
, ".idl", "" );
2277 if
(! isalnum
((unsigned char) *dst
))
2280 return strmake
("__WIDL_%s_generated_name_%08lX", file_id
, n
++);
2283 static int is_allowed_conf_type
(const type_t
*type
)
2285 switch
(type_get_type
(type
))
2290 switch
(type_basic_get_type
(type
))
2292 case TYPE_BASIC_INT8
:
2293 case TYPE_BASIC_INT16
:
2294 case TYPE_BASIC_INT32
:
2295 case TYPE_BASIC_INT64
:
2296 case TYPE_BASIC_INT
:
2297 case TYPE_BASIC_LONG
:
2298 case TYPE_BASIC_CHAR
:
2299 case TYPE_BASIC_HYPER
:
2300 case TYPE_BASIC_BYTE
:
2301 case TYPE_BASIC_WCHAR
:
2307 /* shouldn't get here because of type_get_type call above */
2312 case TYPE_ENCAPSULATED_UNION
:
2319 case TYPE_INTERFACE
:
2321 case TYPE_RUNTIMECLASS
:
2324 case TYPE_APICONTRACT
:
2325 case TYPE_PARAMETERIZED_TYPE
:
2326 case TYPE_PARAMETER
:
2327 /* not supposed to be here */
2334 static int is_ptr_guid_type
(const type_t
*type
)
2336 /* first, make sure it is a pointer to something */
2337 if
(!is_ptr
(type
)) return FALSE
;
2339 /* second, make sure it is a pointer to something of size sizeof(GUID),
2341 return
(type_memsize
(type_pointer_get_ref_type
(type
)) == 16);
2344 static void check_conformance_expr_list
(const char *attr_name
, const var_t
*arg
, const type_t
*container_type
, expr_list_t
*expr_list
)
2347 struct expr_loc expr_loc
;
2349 expr_loc.attr
= attr_name
;
2350 if
(expr_list
) LIST_FOR_EACH_ENTRY
(dim
, expr_list
, expr_t
, entry
)
2352 if
(dim
->type
!= EXPR_VOID
)
2354 const type_t
*expr_type
= expr_resolve_type
(&expr_loc
, container_type
, dim
);
2355 if
(!is_allowed_conf_type
(expr_type
))
2356 error_at
( &arg
->where
, "expression must resolve to integral type <= 32bits for attribute %s\n", attr_name
);
2361 static void check_remoting_fields
(const var_t
*var
, type_t
*type
);
2363 /* checks that properties common to fields and arguments are consistent */
2364 static void check_field_common
(const type_t
*container_type
,
2365 const char *container_name
, const var_t
*arg
)
2367 type_t
*type
= arg
->declspec.type
;
2369 const char *container_type_name
;
2370 const char *var_type
;
2372 switch
(type_get_type
(container_type
))
2375 container_type_name
= "struct";
2379 container_type_name
= "union";
2382 case TYPE_ENCAPSULATED_UNION
:
2383 container_type_name
= "encapsulated union";
2387 container_type_name
= "function";
2388 var_type
= "parameter";
2391 /* should be no other container types */
2396 if
(is_attr
(arg
->attrs
, ATTR_LENGTHIS
) &&
2397 (is_attr
(arg
->attrs
, ATTR_STRING
) || is_aliaschain_attr
(arg
->declspec.type
, ATTR_STRING
)))
2398 error_at
( &arg
->where
, "string and length_is specified for argument %s are mutually exclusive attributes\n", arg
->name
);
2400 if
(is_attr
(arg
->attrs
, ATTR_SIZEIS
))
2402 expr_list_t
*size_is_exprs
= get_attrp
(arg
->attrs
, ATTR_SIZEIS
);
2403 check_conformance_expr_list
("size_is", arg
, container_type
, size_is_exprs
);
2405 if
(is_attr
(arg
->attrs
, ATTR_LENGTHIS
))
2407 expr_list_t
*length_is_exprs
= get_attrp
(arg
->attrs
, ATTR_LENGTHIS
);
2408 check_conformance_expr_list
("length_is", arg
, container_type
, length_is_exprs
);
2410 if
(is_attr
(arg
->attrs
, ATTR_IIDIS
))
2412 struct expr_loc expr_loc
;
2413 expr_t
*expr
= get_attrp
(arg
->attrs
, ATTR_IIDIS
);
2414 if
(expr
->type
!= EXPR_VOID
)
2416 const type_t
*expr_type
;
2418 expr_loc.attr
= "iid_is";
2419 expr_type
= expr_resolve_type
(&expr_loc
, container_type
, expr
);
2420 if
(!expr_type ||
!is_ptr_guid_type
(expr_type
))
2421 error_at
( &arg
->where
, "expression must resolve to pointer to GUID type for attribute iid_is\n" );
2424 if
(is_attr
(arg
->attrs
, ATTR_SWITCHIS
))
2426 struct expr_loc expr_loc
;
2427 expr_t
*expr
= get_attrp
(arg
->attrs
, ATTR_SWITCHIS
);
2428 if
(expr
->type
!= EXPR_VOID
)
2430 const type_t
*expr_type
;
2432 expr_loc.attr
= "switch_is";
2433 expr_type
= expr_resolve_type
(&expr_loc
, container_type
, expr
);
2434 if
(!expr_type ||
!is_allowed_conf_type
(expr_type
))
2435 error_at
( &arg
->where
, "expression must resolve to integral type <= 32bits for attribute %s\n", expr_loc.attr
);
2443 switch
(typegen_detect_type
(type
, arg
->attrs
, TDT_IGNORE_STRINGS
))
2447 check_remoting_fields
(arg
, type
);
2451 const char *reason
= "is invalid";
2452 switch
(type_get_type
(type
))
2455 reason
= "cannot derive from void *";
2458 reason
= "cannot be a function pointer";
2461 reason
= "cannot be a bit-field";
2464 reason
= "cannot be a class";
2466 case TYPE_INTERFACE
:
2467 reason
= "cannot be a non-pointer to an interface";
2470 reason
= "cannot be a module";
2475 error_at
( &arg
->where
, "%s \'%s\' of %s \'%s\' %s\n", var_type
, arg
->name
, container_type_name
, container_name
, reason
);
2478 case TGT_CTXT_HANDLE
:
2479 case TGT_CTXT_HANDLE_POINTER
:
2480 if
(type_get_type
(container_type
) != TYPE_FUNCTION
)
2481 error_at
( &arg
->where
, "%s \'%s\' of %s \'%s\' cannot be a context handle\n",
2482 var_type
, arg
->name
, container_type_name
, container_name
);
2486 const type_t
*t
= type
;
2488 t
= type_pointer_get_ref_type
(t
);
2489 if
(is_aliaschain_attr
(t
, ATTR_RANGE
))
2490 warning_at
( &arg
->where
, "%s: range not verified for a string of ranged types\n", arg
->name
);
2494 if
(type_get_type
(type_pointer_get_ref_type
(type
)) != TYPE_VOID ||
2495 !type
->name || strcmp
(type
->name
, "HANDLE"))
2497 type
= type_pointer_get_ref_type
(type
);
2502 type
= type_array_get_element_type
(type
);
2506 type
= type_get_real_type
(type
);
2507 if
(!type_is_complete
(type
))
2508 error_at
( &arg
->where
, "undefined type declaration \"enum %s\"\n", type
->name
);
2510 case TGT_IFACE_POINTER
:
2516 } while
(more_to_do
);
2519 static void check_remoting_fields
(const var_t
*var
, type_t
*type
)
2522 const var_list_t
*fields
= NULL
;
2524 type
= type_get_real_type
(type
);
2529 type
->checked
= TRUE
;
2531 if
(type_get_type
(type
) == TYPE_STRUCT
)
2533 if
(type_is_complete
(type
))
2534 fields
= type_struct_get_fields
(type
);
2536 error_at
( &var
->where
, "undefined type declaration \"struct %s\"\n", type
->name
);
2538 else if
(type_get_type
(type
) == TYPE_UNION || type_get_type
(type
) == TYPE_ENCAPSULATED_UNION
)
2540 if
(type_is_complete
(type
))
2541 fields
= type_union_get_cases
(type
);
2543 error_at
( &var
->where
, "undefined type declaration \"union %s\"\n", type
->name
);
2546 if
(fields
) LIST_FOR_EACH_ENTRY
( field
, fields
, const var_t
, entry
)
2547 if
(field
->declspec.type
) check_field_common
(type
, type
->name
, field
);
2550 /* checks that arguments for a function make sense for marshalling and unmarshalling */
2551 static void check_remoting_args
(const var_t
*func
)
2553 const char *funcname
= func
->name
;
2556 if
(!type_function_get_args
(func
->declspec.type
))
2559 LIST_FOR_EACH_ENTRY
( arg
, type_function_get_args
(func
->declspec.type
), const var_t
, entry
)
2561 const type_t
*type
= arg
->declspec.type
;
2563 /* check that [out] parameters have enough pointer levels */
2564 if
(is_attr
(arg
->attrs
, ATTR_OUT
))
2566 switch
(typegen_detect_type
(type
, arg
->attrs
, TDT_ALL_TYPES
))
2573 case TGT_CTXT_HANDLE
:
2575 error_at
( &arg
->where
, "out parameter \'%s\' of function \'%s\' is not a pointer\n", arg
->name
, funcname
);
2577 case TGT_IFACE_POINTER
:
2578 error_at
( &arg
->where
, "out interface pointer \'%s\' of function \'%s\' is not a double pointer\n", arg
->name
, funcname
);
2583 /* needs conformance or fixed dimension */
2584 if
(type_array_has_conformance
(type
) &&
2585 type_array_get_conformance
(type
)->type
!= EXPR_VOID
) break
;
2586 if
(!type_array_has_conformance
(type
) && type_array_get_dim
(type
)) break
;
2588 if
(is_attr
( arg
->attrs
, ATTR_IN
)) break
;
2589 error_at
( &arg
->where
, "out parameter \'%s\' of function \'%s\' cannot be an unsized string\n", arg
->name
, funcname
);
2592 /* already error'd before we get here */
2593 case TGT_CTXT_HANDLE_POINTER
:
2601 check_field_common
(func
->declspec.type
, funcname
, arg
);
2604 if
(type_get_type
(type_function_get_rettype
(func
->declspec.type
)) != TYPE_VOID
)
2608 var.declspec.type
= type_function_get_rettype
(func
->declspec.type
);
2609 var.name
= xstrdup
("return value");
2610 check_field_common
(func
->declspec.type
, funcname
, &var
);
2615 static void add_explicit_handle_if_necessary
(const type_t
*iface
, var_t
*func
)
2617 unsigned char explicit_fc
, implicit_fc
;
2619 /* check for a defined binding handle */
2620 if
(!get_func_handle_var
( iface
, func
, &explicit_fc
, &implicit_fc
) ||
!explicit_fc
)
2622 /* no explicit handle specified so add
2623 * "[in] handle_t IDL_handle" as the first parameter to the
2625 var_t
*idl_handle
= make_var
(xstrdup
("IDL_handle"));
2626 idl_handle
->attrs
= append_attr
( NULL
, attr_int
( iface
->where
, ATTR_IN
, 0 ) );
2627 idl_handle
->declspec.type
= find_type_or_error
(NULL
, "handle_t");
2628 type_function_add_head_arg
(func
->declspec.type
, idl_handle
);
2632 static void check_functions
(const type_t
*iface
, int is_inside_library
)
2634 const statement_t
*stmt
;
2635 /* check for duplicates */
2636 if
(is_attr
(iface
->attrs
, ATTR_DISPINTERFACE
))
2638 var_list_t
*methods
= type_dispiface_get_methods
(iface
);
2639 var_t
*func
, *func_iter
;
2641 if
(methods
) LIST_FOR_EACH_ENTRY
( func
, methods
, var_t
, entry
)
2643 LIST_FOR_EACH_ENTRY
( func_iter
, methods
, var_t
, entry
)
2645 if
(func
== func_iter
) break
;
2646 if
(strcmp
(func
->name
, func_iter
->name
)) continue
;
2647 if
(is_attr
(func
->attrs
, ATTR_EVENTADD
) != is_attr
(func_iter
->attrs
, ATTR_EVENTADD
)) continue
;
2648 if
(is_attr
(func
->attrs
, ATTR_EVENTREMOVE
) != is_attr
(func_iter
->attrs
, ATTR_EVENTREMOVE
)) continue
;
2649 if
(is_attr
(func
->attrs
, ATTR_PROPGET
) != is_attr
(func_iter
->attrs
, ATTR_PROPGET
)) continue
;
2650 if
(is_attr
(func
->attrs
, ATTR_PROPPUT
) != is_attr
(func_iter
->attrs
, ATTR_PROPPUT
)) continue
;
2651 if
(is_attr
(func
->attrs
, ATTR_PROPPUTREF
) != is_attr
(func_iter
->attrs
, ATTR_PROPPUTREF
)) continue
;
2652 error_at
( &func
->where
, "duplicated function \'%s\'\n", func
->name
);
2656 if
(is_attr
(iface
->attrs
, ATTR_EXPLICIT_HANDLE
))
2658 STATEMENTS_FOR_EACH_FUNC
( stmt
, type_iface_get_stmts
(iface
) )
2660 var_t
*func
= stmt
->u.var
;
2661 add_explicit_handle_if_necessary
(iface
, func
);
2664 if
(!is_inside_library
&& !is_attr
(iface
->attrs
, ATTR_LOCAL
))
2666 STATEMENTS_FOR_EACH_FUNC
( stmt
, type_iface_get_stmts
(iface
) )
2668 const var_t
*func
= stmt
->u.var
;
2669 if
(!is_attr
(func
->attrs
, ATTR_LOCAL
))
2670 check_remoting_args
(func
);
2675 static int async_iface_attrs
(attr_list_t
*attrs
, const attr_t
*attr
)
2681 case ATTR_ASYNCUUID
:
2682 append_attr
( attrs
, attr_ptr
( attr
->where
, ATTR_UUID
, attr
->u.pval
) );
2689 static int arg_in_attrs
(attr_list_t
*attrs
, const attr_t
*attr
)
2691 return attr
->type
!= ATTR_OUT
&& attr
->type
!= ATTR_RETVAL
;
2694 static int arg_out_attrs
(attr_list_t
*attrs
, const attr_t
*attr
)
2696 return attr
->type
!= ATTR_IN
;
2699 static void check_async_uuid
(type_t
*iface
)
2701 statement_list_t
*stmts
= NULL
;
2703 type_t
*async_iface
;
2706 if
(!is_attr
(iface
->attrs
, ATTR_ASYNCUUID
)) return
;
2708 inherit
= type_iface_get_inherit
(iface
);
2709 if
(inherit
&& strcmp
(inherit
->name
, "IUnknown"))
2710 inherit
= type_iface_get_async_iface
(inherit
);
2712 error_loc
("async_uuid applied to an interface with incompatible parent\n");
2714 async_iface
= type_interface_declare
(strmake
("Async%s", iface
->name
), iface
->namespace
);
2716 STATEMENTS_FOR_EACH_FUNC
( stmt
, type_iface_get_stmts
(iface
) )
2718 var_t
*begin_func
, *finish_func
, *func
= stmt
->u.var
, *arg
;
2719 var_list_t
*begin_args
= NULL
, *finish_args
= NULL
, *args
;
2721 if
(is_attr
(func
->attrs
, ATTR_CALLAS
)) continue
;
2723 args
= type_function_get_args
(func
->declspec.type
);
2724 if
(args
) LIST_FOR_EACH_ENTRY
(arg
, args
, var_t
, entry
)
2726 if
(is_attr
(arg
->attrs
, ATTR_IN
) ||
!is_attr
(arg
->attrs
, ATTR_OUT
))
2727 begin_args
= append_var
(begin_args
, copy_var
(arg
, xstrdup
(arg
->name
), arg_in_attrs
));
2728 if
(is_attr
(arg
->attrs
, ATTR_OUT
))
2729 finish_args
= append_var
(finish_args
, copy_var
(arg
, xstrdup
(arg
->name
), arg_out_attrs
));
2732 begin_func
= copy_var
(func
, strmake
("Begin_%s", func
->name
), NULL
);
2733 begin_func
->declspec.type
= type_new_function
(begin_args
);
2734 begin_func
->declspec.type
->attrs
= func
->attrs
;
2735 begin_func
->declspec.type
->details.function
->retval
= func
->declspec.type
->details.function
->retval
;
2736 stmts
= append_statement
(stmts
, make_statement_declaration
(begin_func
));
2738 finish_func
= copy_var
(func
, strmake
("Finish_%s", func
->name
), NULL
);
2739 finish_func
->declspec.type
= type_new_function
(finish_args
);
2740 finish_func
->declspec.type
->attrs
= func
->attrs
;
2741 finish_func
->declspec.type
->details.function
->retval
= func
->declspec.type
->details.function
->retval
;
2742 stmts
= append_statement
(stmts
, make_statement_declaration
(finish_func
));
2745 type_interface_define
(async_iface
, map_attrs
(iface
->attrs
, async_iface_attrs
), inherit
, stmts
, NULL
);
2746 iface
->details.iface
->async_iface
= async_iface
->details.iface
->async_iface
= async_iface
;
2749 static statement_list_t
*append_parameterized_type_stmts
(statement_list_t
*stmts
)
2751 statement_t
*stmt
, *next
;
2753 if
(stmts
&& parameterized_type_stmts
) LIST_FOR_EACH_ENTRY_SAFE
(stmt
, next
, parameterized_type_stmts
, statement_t
, entry
)
2758 stmt
->u.type
= type_parameterized_type_specialize_define
(stmt
->u.type
);
2759 stmt
->declonly
= FALSE
;
2760 list_remove
(&stmt
->entry
);
2761 stmts
= append_statement
(stmts
, stmt
);
2764 assert
(0); /* should not be there */
2772 static void check_statements
(const statement_list_t
*stmts
, int is_inside_library
)
2774 const statement_t
*stmt
;
2776 if
(stmts
) LIST_FOR_EACH_ENTRY
(stmt
, stmts
, const statement_t
, entry
)
2778 switch
(stmt
->type
) {
2780 check_statements
(stmt
->u.lib
->stmts
, TRUE
);
2783 switch
(type_get_type
(stmt
->u.type
)) {
2784 case TYPE_INTERFACE
:
2785 check_functions
(stmt
->u.type
, is_inside_library
);
2789 error_loc
("coclass is not allowed in Windows Runtime mode\n");
2801 static void check_all_user_types
(const statement_list_t
*stmts
)
2803 const statement_t
*stmt
;
2806 if
(stmts
) LIST_FOR_EACH_ENTRY
(stmt
, stmts
, const statement_t
, entry
)
2808 if
(stmt
->type
== STMT_LIBRARY
)
2809 check_all_user_types
(stmt
->u.lib
->stmts
);
2810 else if
(stmt
->type
== STMT_TYPE
&& type_get_type
(stmt
->u.type
) == TYPE_INTERFACE
&&
2811 !is_local
(stmt
->u.type
->attrs
))
2813 const statement_t
*stmt_func
;
2814 STATEMENTS_FOR_EACH_FUNC
(stmt_func
, type_iface_get_stmts
(stmt
->u.type
)) {
2815 const var_t
*func
= stmt_func
->u.var
;
2816 if
(type_function_get_args
(func
->declspec.type
))
2817 LIST_FOR_EACH_ENTRY
( v
, type_function_get_args
(func
->declspec.type
), const var_t
, entry
)
2818 check_for_additional_prototype_types
(v
->declspec.type
);
2819 check_for_additional_prototype_types
(type_function_get_rettype
(func
->declspec.type
));
2825 static statement_t
*make_statement
(enum statement_type type
)
2827 statement_t
*stmt
= xmalloc
(sizeof
(*stmt
));
2832 static statement_t
*make_statement_type_decl
(type_t
*type
)
2834 statement_t
*stmt
= make_statement
(STMT_TYPE
);
2835 stmt
->u.type
= type
;
2836 stmt
->declonly
= !type
->defined
;
2840 static statement_t
*make_statement_reference
(type_t
*type
)
2842 statement_t
*stmt
= make_statement
(STMT_TYPEREF
);
2843 stmt
->u.type
= type
;
2847 static statement_t
*make_statement_declaration
(var_t
*var
)
2849 statement_t
*stmt
= make_statement
(STMT_DECLARATION
);
2851 if
(var
->declspec.stgclass
== STG_EXTERN
&& var
->eval
)
2852 warning
("'%s' initialised and declared extern\n", var
->name
);
2853 if
(is_const_decl
(var
))
2858 else if
(type_get_type
(var
->declspec.type
) == TYPE_FUNCTION
)
2859 check_function_attrs
(var
->name
, var
->attrs
);
2860 else if
(var
->declspec.stgclass
== STG_NONE || var
->declspec.stgclass
== STG_REGISTER
)
2861 error_loc
("instantiation of data is illegal\n");
2865 static statement_t
*make_statement_library
(typelib_t
*typelib
)
2867 statement_t
*stmt
= make_statement
(STMT_LIBRARY
);
2868 stmt
->u.lib
= typelib
;
2872 static statement_t
*make_statement_pragma
(const char *str
)
2874 statement_t
*stmt
= make_statement
(STMT_PRAGMA
);
2879 static statement_t
*make_statement_cppquote
(const char *str
)
2881 statement_t
*stmt
= make_statement
(STMT_CPPQUOTE
);
2886 static statement_t
*make_statement_importlib
(const char *str
)
2888 statement_t
*stmt
= make_statement
(STMT_IMPORTLIB
);
2893 static statement_t
*make_statement_import
(const char *str
)
2895 statement_t
*stmt
= make_statement
(STMT_IMPORT
);
2900 static statement_t
*make_statement_module
(type_t
*type
)
2902 statement_t
*stmt
= make_statement
(STMT_MODULE
);
2903 stmt
->u.type
= type
;
2907 static statement_t
*make_statement_typedef
(declarator_list_t
*decls
, int declonly
)
2909 declarator_t
*decl
, *next
;
2912 if
(!decls
) return NULL
;
2914 stmt
= make_statement
(STMT_TYPEDEF
);
2915 stmt
->u.type_list
= NULL
;
2916 stmt
->declonly
= declonly
;
2918 LIST_FOR_EACH_ENTRY_SAFE
( decl
, next
, decls
, declarator_t
, entry
)
2920 var_t
*var
= decl
->var
;
2921 type_t
*type
= find_type_or_error
(current_namespace
, var
->name
);
2922 stmt
->u.type_list
= append_typeref
(stmt
->u.type_list
, make_typeref
(type
));
2930 static statement_t
*make_statement_parameterized_type
(type_t
*type
, typeref_list_t
*params
)
2932 statement_t
*stmt
= make_statement
(STMT_TYPE
);
2933 stmt
->u.type
= type_parameterized_type_specialize_partial
(type
, params
);
2937 static statement_t
*make_statement_delegate
(type_t
*ret
, var_list_t
*args
)
2939 declarator_t
*decl
= make_declarator
(make_var
(xstrdup
("Invoke")));
2940 decl_spec_t
*spec
= make_decl_spec
(ret
, NULL
, NULL
, STG_NONE
, 0, 0);
2941 append_chain_type
(decl
, type_new_function
(args
), 0);
2942 return make_statement_declaration
(declare_var
(NULL
, spec
, decl
, FALSE
));
2945 static statement_list_t
*append_statements
(statement_list_t
*l1
, statement_list_t
*l2
)
2948 if
(!l1 || l1
== l2
) return l2
;
2949 list_move_tail
(l1
, l2
);
2953 static statement_list_t
*append_statement
(statement_list_t
*list
, statement_t
*stmt
)
2955 if
(!stmt
) return list
;
2958 list
= xmalloc
( sizeof
(*list
) );
2961 list_add_tail
( list
, &stmt
->entry
);
2965 type_t
*find_parameterized_type
(type_t
*type
, typeref_list_t
*params
)
2967 char *name
= format_parameterized_type_name
(type
, params
);
2969 if
(parameters_namespace
)
2971 assert
(type
->type_type
== TYPE_PARAMETERIZED_TYPE
);
2972 type
= type_parameterized_type_specialize_partial
(type
, params
);
2974 else if
((type
= find_type
(name
, type
->namespace
, 0)))
2975 assert
(type
->type_type
!= TYPE_PARAMETERIZED_TYPE
);
2977 error_loc
("parameterized type '%s' not declared\n", name
);