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 attr_list_t
*append_attr_list
(attr_list_t
*new_list
, attr_list_t
*old_list
);
49 static decl_spec_t
*make_decl_spec
(type_t
*type
, decl_spec_t
*left
, decl_spec_t
*right
,
50 enum storage_class stgclass
, enum type_qualifier qual
, enum function_specifier func_specifier
);
51 static attr_t
*make_attr
(enum attr_type type
);
52 static attr_t
*make_attrv
(enum attr_type type
, unsigned int val
);
53 static attr_t
*make_custom_attr
(struct uuid
*id
, expr_t
*pval
);
54 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
);
55 static var_t
*declare_var
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_t
*decl
, int top
);
56 static var_list_t
*set_var_types
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_list_t
*decls
);
57 static var_list_t
*append_var_list
(var_list_t
*list
, var_list_t
*vars
);
58 static declarator_list_t
*append_declarator
(declarator_list_t
*list
, declarator_t
*p
);
59 static declarator_t
*make_declarator
(var_t
*var
);
60 static type_t
*make_safearray
(type_t
*type
);
61 static typelib_t
*make_library
(const char *name
, const attr_list_t
*attrs
);
62 static void append_array
(declarator_t
*decl
, expr_t
*expr
);
63 static void append_chain_type
(declarator_t
*decl
, type_t
*type
, enum type_qualifier qual
);
64 static void append_chain_callconv
(type_t
*chain
, char *callconv
);
65 static warning_list_t
*append_warning
(warning_list_t
*, int);
67 static type_t
*reg_typedefs
(decl_spec_t
*decl_spec
, var_list_t
*names
, attr_list_t
*attrs
);
68 static type_t
*find_type_or_error
(struct namespace
*parent
, const char *name
);
69 static struct namespace
*find_namespace_or_error
(struct namespace
*namespace
, const char *name
);
71 static var_t
*reg_const
(var_t
*var
);
73 static void push_namespaces
(str_list_t
*names
);
74 static void pop_namespaces
(str_list_t
*names
);
75 static void push_parameters_namespace
(const char *name
);
76 static void pop_parameters_namespace
(const char *name
);
78 static statement_list_t
*append_parameterized_type_stmts
(statement_list_t
*stmts
);
79 static void check_arg_attrs
(const var_t
*arg
);
80 static void check_statements
(const statement_list_t
*stmts
, int is_inside_library
);
81 static void check_all_user_types
(const statement_list_t
*stmts
);
82 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
);
83 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
);
84 static attr_list_t
*check_enum_attrs
(attr_list_t
*attrs
);
85 static attr_list_t
*check_enum_member_attrs
(attr_list_t
*attrs
);
86 static attr_list_t
*check_struct_attrs
(attr_list_t
*attrs
);
87 static attr_list_t
*check_union_attrs
(attr_list_t
*attrs
);
88 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
);
89 static attr_list_t
*check_library_attrs
(const char *name
, attr_list_t
*attrs
);
90 const char *get_attr_display_name
(enum attr_type type
);
91 static void add_explicit_handle_if_necessary
(const type_t
*iface
, var_t
*func
);
93 static void check_async_uuid
(type_t
*iface
);
95 static statement_t
*make_statement
(enum statement_type type
);
96 static statement_t
*make_statement_type_decl
(type_t
*type
);
97 static statement_t
*make_statement_reference
(type_t
*type
);
98 static statement_t
*make_statement_declaration
(var_t
*var
);
99 static statement_t
*make_statement_library
(typelib_t
*typelib
);
100 static statement_t
*make_statement_pragma
(const char *str
);
101 static statement_t
*make_statement_cppquote
(const char *str
);
102 static statement_t
*make_statement_importlib
(const char *str
);
103 static statement_t
*make_statement_module
(type_t
*type
);
104 static statement_t
*make_statement_typedef
(var_list_t
*names
, int declonly
);
105 static statement_t
*make_statement_import
(const char *str
);
106 static statement_t
*make_statement_parameterized_type
(type_t
*type
, typeref_list_t
*params
);
107 static statement_t
*make_statement_delegate
(type_t
*ret
, var_list_t
*args
);
108 static statement_list_t
*append_statement
(statement_list_t
*list
, statement_t
*stmt
);
109 static statement_list_t
*append_statements
(statement_list_t
*, statement_list_t
*);
110 static attr_list_t
*append_attribs
(attr_list_t
*, attr_list_t
*);
112 static struct namespace global_namespace
= {
113 NULL
, NULL
, LIST_INIT
(global_namespace.entry
), LIST_INIT
(global_namespace.children
)
116 static struct namespace
*current_namespace
= &global_namespace
;
117 static struct namespace
*parameters_namespace
= NULL
;
118 static statement_list_t
*parameterized_type_stmts
= NULL
;
120 static typelib_t
*current_typelib
;
127 int parser_lex
( PARSER_STYPE
*yylval, PARSER_LTYPE
*yylloc );
128 void push_import
( const char *fname
, PARSER_LTYPE
*yylloc );
129 void pop_import
( PARSER_LTYPE
*yylloc );
131 # define YYLLOC_DEFAULT( cur, rhs, n ) \
132 do
{ if
(n
) init_location
( &(cur
), &YYRHSLOC
( rhs
, 1 ), &YYRHSLOC
( rhs
, n
) ); \
133 else init_location
( &(cur
), &YYRHSLOC
( rhs
, 0 ), NULL
); } while
(0)
137 %define api.location.type
{struct location
}
138 %define api.prefix
{parser_
}
139 %define api.pure full
140 %define parse.
error verbose
145 attr_list_t
*attr_list
;
146 str_list_t
*str_list
;
148 expr_list_t
*expr_list
;
151 var_list_t
*var_list
;
152 declarator_t
*declarator
;
153 declarator_list_t
*declarator_list
;
154 statement_t
*statement
;
155 statement_list_t
*stmt_list
;
157 warning_list_t
*warning_list
;
159 typeref_list_t
*typeref_list
;
165 struct _import_t
*import
;
166 struct _decl_spec_t
*declspec
;
167 enum storage_class stgclass
;
168 enum type_qualifier type_qualifier
;
169 enum function_specifier function_specifier
;
170 struct namespace
*namespace
;
173 %token
<str
> aIDENTIFIER aPRAGMA
174 %token
<str
> aKNOWNTYPE
175 %token
<num
> aNUM aHEXNUM
177 %token
<str
> aSTRING aWSTRING aSQSTRING
179 %token
<str
> tFASTCALL
181 %token
<str
> tSTDCALL
186 %token EQUALITY INEQUALITY
187 %token GREATEREQUAL LESSEQUAL
188 %token LOGICALOR LOGICALAND
193 %token tALLNODES tALLOCATE tANNOTATION
195 %token tAPPOBJECT tASYNC tASYNCUUID
196 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
197 %token tCALLAS tCALLBACK tCASE tCHAR tCOCLASS tCODE tCOMMSTATUS
198 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
199 %token tCONTEXTHANDLESERIALIZE
201 %token tCONTRACTVERSION
202 %token tCONTROL tCPPQUOTE
205 %token tDECODE tDEFAULT tDEFAULTBIND
207 %token tDEFAULTCOLLELEM
209 %token tDEFAULTVTABLE
210 %token tDISABLECONSISTENCYCHECK tDISPLAYBIND
211 %token tDISPINTERFACE
212 %token tDLLNAME tDONTFREE tDOUBLE tDUAL
213 %token tENABLEALLOCATE tENCODE tENDPOINT
214 %token tENTRY tENUM tERRORSTATUST
215 %token tEVENTADD tEVENTREMOVE
217 %token tEXPLICITHANDLE tEXTERN
221 %token tFLOAT tFORCEALLOCATE
224 %token tHELPCONTEXT tHELPFILE
225 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
227 %token tHYPER tID tIDEMPOTENT
228 %token tIGNORE tIIDIS
229 %token tIMMEDIATEBIND
230 %token tIMPLICITHANDLE
231 %token tIMPORT tIMPORTLIB
232 %token tIN tIN_LINE tINLINE
234 %token tINT tINT32 tINT3264 tINT64
237 %token tLENGTHIS tLIBRARY
238 %token tLICENSED tLOCAL
240 %token tMARSHALINGBEHAVIOR
241 %token tMAYBE tMESSAGE
246 %token tNOCODE tNONBROWSABLE
249 %token tNONEXTENSIBLE
250 %token tNOTIFY tNOTIFYFLAG
252 %token tOBJECT tODL tOLEAUTOMATION
253 %token tOPTIMIZE tOPTIONAL
256 %token tPARTIALIGNORE
257 %token tPOINTERDEFAULT
258 %token tPRAGMA_WARNING
259 %token tPROGID tPROPERTIES
260 %token tPROPGET tPROPPUT tPROPPUTREF
264 %token tREADONLY tREF
265 %token tREGISTER tREPRESENTAS
273 %token tSIGNED tSINGLENODE
274 %token tSIZEIS tSIZEOF
279 %token tSTRICTCONTEXTHANDLE
280 %token tSTRING tSTRUCT
281 %token tSWITCH tSWITCHIS tSWITCHTYPE
282 %token tTHREADING tTRANSMITAS
285 %token tUIDEFAULT tUNION
288 %token tUSESGETLASTERROR tUSERMARSHAL tUUID
291 %token tVERSION tVIPROGID
293 %token tWCHAR tWIREMARSHAL
294 %token tAPARTMENT tNEUTRAL tSINGLE tFREE tBOTH
296 %type
<attr
> attribute acf_attribute
297 %type
<attr_list
> m_attributes attributes attrib_list
298 %type
<attr_list
> acf_attributes acf_attribute_list
299 %type
<attr_list
> dispattributes
300 %type
<str_list
> str_list
301 %type
<expr
> m_expr expr expr_const expr_int_const array m_bitfield
302 %type
<expr_list
> m_exprs
/* exprs expr_list */ expr_list_int_const
303 %type
<expr
> contract_req
304 %type
<expr
> static_attr
305 %type
<expr
> activatable_attr
306 %type
<type
> delegatedef
307 %type
<stgclass
> storage_cls_spec
308 %type
<type_qualifier
> type_qualifier m_type_qual_list
309 %type
<function_specifier
> function_specifier
310 %type
<declspec
> decl_spec unqualified_decl_spec decl_spec_no_type m_decl_spec_no_type
311 %type
<type
> inherit interface interfacedef
312 %type
<type
> interfaceref
313 %type
<type
> dispinterfaceref
314 %type
<type
> dispinterface dispinterfacedef
315 %type
<type
> module moduledef
316 %type
<str_list
> namespacedef
317 %type
<type
> base_type int_std
318 %type
<type
> enumdef structdef uniondef typedecl
319 %type
<type
> type unqualified_type qualified_type
320 %type
<type
> type_parameter
321 %type
<typeref_list
> type_parameters
322 %type
<type
> parameterized_type
323 %type
<type
> parameterized_type_arg
324 %type
<typeref_list
> parameterized_type_args
325 %type
<typeref
> class_interface
326 %type
<typeref_list
> class_interfaces
327 %type
<typeref_list
> requires required_types
328 %type
<var
> arg ne_union_field union_field s_field case
enum enum_member declaration
330 %type
<var_list
> m_args arg_list args dispint_meths
331 %type
<var_list
> fields ne_union_fields cases enums enum_list dispint_props field
332 %type
<var
> m_ident ident
333 %type
<declarator
> declarator direct_declarator init_declarator struct_declarator
334 %type
<declarator
> m_any_declarator any_declarator any_declarator_no_direct any_direct_declarator
335 %type
<declarator
> m_abstract_declarator abstract_declarator abstract_declarator_no_direct abstract_direct_declarator
336 %type
<declarator_list
> declarator_list struct_declarator_list
337 %type
<type
> coclass coclassdef
338 %type
<type
> runtimeclass runtimeclass_def
339 %type
<type
> apicontract apicontract_def
340 %type
<num
> contract_ver
341 %type
<num
> pointer_type threading_type marshaling_behavior version
342 %type
<str
> libraryhdr callconv cppquote importlib import
343 %type
<str
> typename m_typename
344 %type
<str
> import_start
345 %type
<typelib
> library_start librarydef
346 %type
<statement
> statement typedef pragma_warning
347 %type
<stmt_list
> gbl_statements imp_statements int_statements
348 %type
<stmt_list
> decl_block decl_statements
349 %type
<stmt_list
> imp_decl_block imp_decl_statements
350 %type
<warning_list
> warnings
351 %type
<num
> allocate_option_list allocate_option
352 %type
<namespace
> namespace_pfx
361 %left EQUALITY INEQUALITY
362 %left
'<' '>' LESSEQUAL GREATEREQUAL
366 %right
'!' '~' CAST PPTR POS NEG ADDRESSOF tSIZEOF
367 %left
'.' MEMBERPTR
'[' ']'
371 input: gbl_statements m_acf
{ $1 = append_parameterized_type_stmts
($1);
372 check_statements
($1, FALSE
);
373 check_all_user_types
($1);
380 write_typelib_regscript
($1);
382 write_local_stubs
($1);
388 | aACF acf_statements
392 : %empty
{ $$
= NULL
; }
393 | decl_statements tINTERFACE qualified_type
'<' parameterized_type_args
'>' ';'
394 { parameterized_type_stmts
= append_statement
(parameterized_type_stmts
, make_statement_parameterized_type
($3, $5));
395 $$
= append_statement
($1, make_statement_reference
(type_parameterized_type_specialize_declare
($3, $5)));
399 decl_block: tDECLARE
'{' decl_statements
'}' { $$
= $3; }
403 : %empty
{ $$
= NULL
; }
404 | imp_decl_statements tINTERFACE qualified_type
'<' parameterized_type_args
'>' ';'
405 { $$
= append_statement
($1, make_statement_reference
(type_parameterized_type_specialize_declare
($3, $5))); }
409 : tDECLARE
'{' imp_decl_statements
'}' { $$
= $3; }
413 : %empty
{ $$
= NULL
; }
414 | gbl_statements namespacedef
'{' { push_namespaces
($2); } gbl_statements
'}'
415 { pop_namespaces
($2); $$
= append_statements
($1, $5); }
416 | gbl_statements interface
';' { $$
= append_statement
($1, make_statement_reference
($2)); }
417 | gbl_statements dispinterface
';' { $$
= append_statement
($1, make_statement_reference
($2)); }
418 | gbl_statements interfacedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); }
419 | gbl_statements delegatedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); }
420 | gbl_statements coclass
';' { $$
= $1;
421 reg_type
($2, $2->name
, current_namespace
, 0);
423 | gbl_statements coclassdef
{ $$
= append_statement
($1, make_statement_type_decl
($2));
424 reg_type
($2, $2->name
, current_namespace
, 0);
426 | gbl_statements apicontract
';' { $$
= $1; reg_type
($2, $2->name
, current_namespace
, 0); }
427 | gbl_statements apicontract_def
{ $$
= append_statement
($1, make_statement_type_decl
($2));
428 reg_type
($2, $2->name
, current_namespace
, 0); }
429 | gbl_statements runtimeclass
';' { $$
= $1; reg_type
($2, $2->name
, current_namespace
, 0); }
430 | gbl_statements runtimeclass_def
{ $$
= append_statement
($1, make_statement_type_decl
($2));
431 reg_type
($2, $2->name
, current_namespace
, 0); }
432 | gbl_statements moduledef
{ $$
= append_statement
($1, make_statement_module
($2)); }
433 | gbl_statements librarydef
{ $$
= append_statement
($1, make_statement_library
($2)); }
434 | gbl_statements statement
{ $$
= append_statement
($1, $2); }
435 | gbl_statements decl_block
{ $$
= append_statements
($1, $2); }
439 : %empty
{ $$
= NULL
; }
440 | imp_statements interface
';' { $$
= append_statement
($1, make_statement_reference
($2)); }
441 | imp_statements dispinterface
';' { $$
= append_statement
($1, make_statement_reference
($2)); }
442 | imp_statements namespacedef
'{' { push_namespaces
($2); } imp_statements
'}'
443 { pop_namespaces
($2); $$
= append_statements
($1, $5); }
444 | imp_statements interfacedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); }
445 | imp_statements delegatedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); }
446 | imp_statements coclass
';' { $$
= $1; reg_type
($2, $2->name
, current_namespace
, 0); }
447 | imp_statements coclassdef
{ $$
= append_statement
($1, make_statement_type_decl
($2));
448 reg_type
($2, $2->name
, current_namespace
, 0);
450 | imp_statements apicontract
';' { $$
= $1; reg_type
($2, $2->name
, current_namespace
, 0); }
451 | imp_statements apicontract_def
{ $$
= append_statement
($1, make_statement_type_decl
($2));
452 reg_type
($2, $2->name
, current_namespace
, 0); }
453 | imp_statements runtimeclass
';' { $$
= $1; reg_type
($2, $2->name
, current_namespace
, 0); }
454 | imp_statements runtimeclass_def
{ $$
= append_statement
($1, make_statement_type_decl
($2));
455 reg_type
($2, $2->name
, current_namespace
, 0); }
456 | imp_statements moduledef
{ $$
= append_statement
($1, make_statement_module
($2)); }
457 | imp_statements statement
{ $$
= append_statement
($1, $2); }
458 | imp_statements importlib
{ $$
= append_statement
($1, make_statement_importlib
($2)); }
459 | imp_statements librarydef
{ $$
= append_statement
($1, make_statement_library
($2)); }
460 | imp_statements imp_decl_block
{ $$
= append_statements
($1, $2); }
464 : %empty
{ $$
= NULL
; }
465 | int_statements statement
{ $$
= append_statement
($1, $2); }
474 cppquote
{ $$
= make_statement_cppquote
($1); }
475 | typedecl
';' { $$
= make_statement_type_decl
($1); }
476 | declaration
';' { $$
= make_statement_declaration
($1); }
477 | import
{ $$
= make_statement_import
($1); }
478 | typedef
';' { $$
= $1; }
479 | aPRAGMA
{ $$
= make_statement_pragma
($1); }
480 | pragma_warning
{ $$
= NULL
; }
483 pragma_warning: tPRAGMA_WARNING
'(' aIDENTIFIER
':' warnings
')'
487 result
= do_warning
($3, $5);
489 error_loc
("expected \"disable\", \"enable\" or \"default\"\n");
491 | tPRAGMA_WARNING
'(' tDEFAULT
':' warnings
')'
494 do_warning
("default", $5);
499 aNUM
{ $$
= append_warning
(NULL
, $1); }
500 | warnings aNUM
{ $$
= append_warning
($1, $2); }
505 | tENUM aIDENTIFIER
{ $$
= type_new_enum
($2, current_namespace
, FALSE
, NULL
); }
507 | tSTRUCT aIDENTIFIER
{ $$
= type_new_struct
($2, current_namespace
, FALSE
, NULL
); }
509 | tUNION aIDENTIFIER
{ $$
= type_new_nonencapsulated_union
($2, current_namespace
, FALSE
, NULL
); }
510 | attributes enumdef
{ $$
= $2; $$
->attrs
= check_enum_attrs
($1); }
511 | attributes structdef
{ $$
= $2; $$
->attrs
= check_struct_attrs
($1); }
512 | attributes uniondef
{ $$
= $2; $$
->attrs
= check_union_attrs
($1); }
515 cppquote: tCPPQUOTE
'(' aSTRING
')' { $$
= $3; }
518 import_start: tIMPORT aSTRING
';' { $$
= $2; push_import
( $2, &yylloc ); }
520 import: import_start imp_statements aEOF
{ pop_import
( &yylloc ); }
523 importlib: tIMPORTLIB
'(' aSTRING
')'
524 semicolon_opt
{ $$
= $3; if
(!parse_only
) add_importlib
($3, current_typelib
); }
527 libraryhdr: tLIBRARY typename
{ $$
= $2; }
529 library_start: attributes libraryhdr
'{' { $$
= make_library
($2, check_library_attrs
($2, $1));
530 if
(!parse_only
&& do_typelib
) current_typelib
= $$
;
533 librarydef: library_start imp_statements
'}'
534 semicolon_opt
{ $$
= $1; $$
->stmts
= $2; }
538 : %empty
{ $$
= NULL
; }
542 arg_list: arg
{ check_arg_attrs
($1); $$
= append_var
( NULL
, $1 ); }
543 | arg_list
',' arg
{ check_arg_attrs
($3); $$
= append_var
( $1, $3 ); }
547 | arg_list
',' ELLIPSIS
{ $$
= append_var
( $1, make_var
(xstrdup
("...")) ); }
550 /* split into two rules to get bison to resolve a tVOID conflict */
551 arg: attributes decl_spec m_any_declarator
{ if
($2->stgclass
!= STG_NONE
&& $2->stgclass
!= STG_REGISTER
)
552 error_loc
("invalid storage class for function parameter\n");
553 $$
= declare_var
($1, $2, $3, TRUE
);
556 | decl_spec m_any_declarator
{ if
($1->stgclass
!= STG_NONE
&& $1->stgclass
!= STG_REGISTER
)
557 error_loc
("invalid storage class for function parameter\n");
558 $$
= declare_var
(NULL
, $1, $2, TRUE
);
563 array: '[' expr
']' { $$
= $2;
564 if
(!$$
->is_const || $$
->cval
<= 0)
565 error_loc
("array dimension is not a positive integer constant\n");
567 |
'[' '*' ']' { $$
= make_expr
(EXPR_VOID
); }
568 |
'[' ']' { $$
= make_expr
(EXPR_VOID
); }
572 : %empty
{ $$
= NULL
; }
577 '[' attrib_list
']' { $$
= $2; }
580 attrib_list: attribute
{ $$
= append_attr
( NULL
, $1 ); }
581 | attrib_list
',' attribute
{ $$
= append_attr
( $1, $3 ); }
582 | attrib_list
']' '[' attribute
{ $$
= append_attr
( $1, $4 ); }
585 str_list: aSTRING
{ $$
= append_str
( NULL
, $1 ); }
586 | str_list
',' aSTRING
{ $$
= append_str
( $1, $3 ); }
590 tAGILE
{ $$
= MARSHALING_AGILE
; }
591 | tNONE
{ $$
= MARSHALING_NONE
; }
592 | tSTANDARD
{ $$
= MARSHALING_STANDARD
; }
596 aNUM
{ $$
= MAKEVERSION
(0, $1); }
597 | aNUM
'.' aNUM
{ $$
= MAKEVERSION
($3, $1); }
601 : decl_spec
',' contract_ver
{ if
($1->type
->type_type
!= TYPE_APICONTRACT
)
602 error_loc
("type %s is not an apicontract\n", $1->type
->name
);
603 $$
= make_exprl
(EXPR_NUM
, $3);
604 $$
= make_exprt
(EXPR_GTREQL
, declare_var
(NULL
, $1, make_declarator
(NULL
), 0), $$
);
609 : decl_spec
',' contract_req
{ if
($1->type
->type_type
!= TYPE_INTERFACE
)
610 error_loc
("type %s is not an interface\n", $1->type
->name
);
611 $$
= make_exprt
(EXPR_MEMBER
, declare_var
(NULL
, $1, make_declarator
(NULL
), 0), $3);
616 decl_spec
',' contract_req
{ if
($1->type
->type_type
!= TYPE_INTERFACE
)
617 error_loc
("type %s is not an interface\n", $1->type
->name
);
618 $$
= make_exprt
(EXPR_MEMBER
, declare_var
(NULL
, $1, make_declarator
(NULL
), 0), $3);
620 | contract_req
{ $$
= $1; } /* activatable on the default activation factory */
624 : %empty
{ $$
= NULL
; }
625 | tACTIVATABLE
'(' activatable_attr
')' { $$
= make_attrp
(ATTR_ACTIVATABLE
, $3); }
626 | tAGGREGATABLE
{ $$
= make_attr
(ATTR_AGGREGATABLE
); }
627 | tANNOTATION
'(' aSTRING
')' { $$
= make_attrp
(ATTR_ANNOTATION
, $3); }
628 | tAPPOBJECT
{ $$
= make_attr
(ATTR_APPOBJECT
); }
629 | tASYNC
{ $$
= make_attr
(ATTR_ASYNC
); }
630 | tAUTOHANDLE
{ $$
= make_attr
(ATTR_AUTO_HANDLE
); }
631 | tBINDABLE
{ $$
= make_attr
(ATTR_BINDABLE
); }
632 | tBROADCAST
{ $$
= make_attr
(ATTR_BROADCAST
); }
633 | tCALLAS
'(' ident
')' { $$
= make_attrp
(ATTR_CALLAS
, $3); }
634 | tCASE
'(' expr_list_int_const
')' { $$
= make_attrp
(ATTR_CASE
, $3); }
635 | tCODE
{ $$
= make_attr
(ATTR_CODE
); }
636 | tCOMMSTATUS
{ $$
= make_attr
(ATTR_COMMSTATUS
); }
637 | tCONTEXTHANDLE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); }
638 | tCONTEXTHANDLENOSERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
639 | tCONTEXTHANDLESERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
640 | tCONTRACT
'(' contract_req
')' { $$
= make_attrp
(ATTR_CONTRACT
, $3); }
641 | tCONTRACTVERSION
'(' contract_ver
')' { $$
= make_attrv
(ATTR_CONTRACTVERSION
, $3); }
642 | tCONTROL
{ $$
= make_attr
(ATTR_CONTROL
); }
643 | tCUSTOM
'(' aUUID
',' expr_const
')' { $$
= make_custom_attr
($3, $5); }
644 | tDECODE
{ $$
= make_attr
(ATTR_DECODE
); }
645 | tDEFAULT
{ $$
= make_attr
(ATTR_DEFAULT
); }
646 | tDEFAULTBIND
{ $$
= make_attr
(ATTR_DEFAULTBIND
); }
647 | tDEFAULTCOLLELEM
{ $$
= make_attr
(ATTR_DEFAULTCOLLELEM
); }
648 | tDEFAULTVALUE
'(' expr_const
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE
, $3); }
649 | tDEFAULTVTABLE
{ $$
= make_attr
(ATTR_DEFAULTVTABLE
); }
650 | tDISABLECONSISTENCYCHECK
{ $$
= make_attr
(ATTR_DISABLECONSISTENCYCHECK
); }
651 | tDISPLAYBIND
{ $$
= make_attr
(ATTR_DISPLAYBIND
); }
652 | tDLLNAME
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DLLNAME
, $3); }
653 | tDUAL
{ $$
= make_attr
(ATTR_DUAL
); }
654 | tENABLEALLOCATE
{ $$
= make_attr
(ATTR_ENABLEALLOCATE
); }
655 | tENCODE
{ $$
= make_attr
(ATTR_ENCODE
); }
656 | tENDPOINT
'(' str_list
')' { $$
= make_attrp
(ATTR_ENDPOINT
, $3); }
657 | tENTRY
'(' expr_const
')' { $$
= make_attrp
(ATTR_ENTRY
, $3); }
658 | tEVENTADD
{ $$
= make_attr
(ATTR_EVENTADD
); }
659 | tEVENTREMOVE
{ $$
= make_attr
(ATTR_EVENTREMOVE
); }
660 | tEXCLUSIVETO
'(' decl_spec
')' { if
($3->type
->type_type
!= TYPE_RUNTIMECLASS
)
661 error_loc
("type %s is not a runtimeclass\n", $3->type
->name
);
662 $$
= make_attrp
(ATTR_EXCLUSIVETO
, $3->type
); }
663 | tEXPLICITHANDLE
{ $$
= make_attr
(ATTR_EXPLICIT_HANDLE
); }
664 | tFAULTSTATUS
{ $$
= make_attr
(ATTR_FAULTSTATUS
); }
665 | tFLAGS
{ $$
= make_attr
(ATTR_FLAGS
); }
666 | tFORCEALLOCATE
{ $$
= make_attr
(ATTR_FORCEALLOCATE
); }
667 | tHANDLE
{ $$
= make_attr
(ATTR_HANDLE
); }
668 | tHELPCONTEXT
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_HELPCONTEXT
, $3); }
669 | tHELPFILE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPFILE
, $3); }
670 | tHELPSTRING
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRING
, $3); }
671 | tHELPSTRINGCONTEXT
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_HELPSTRINGCONTEXT
, $3); }
672 | tHELPSTRINGDLL
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRINGDLL
, $3); }
673 | tHIDDEN
{ $$
= make_attr
(ATTR_HIDDEN
); }
674 | tID
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_ID
, $3); }
675 | tIDEMPOTENT
{ $$
= make_attr
(ATTR_IDEMPOTENT
); }
676 | tIGNORE
{ $$
= make_attr
(ATTR_IGNORE
); }
677 | tIIDIS
'(' expr
')' { $$
= make_attrp
(ATTR_IIDIS
, $3); }
678 | tIMMEDIATEBIND
{ $$
= make_attr
(ATTR_IMMEDIATEBIND
); }
679 | tIMPLICITHANDLE
'(' arg
')' { $$
= make_attrp
(ATTR_IMPLICIT_HANDLE
, $3); }
680 | tIN
{ $$
= make_attr
(ATTR_IN
); }
681 | tINPUTSYNC
{ $$
= make_attr
(ATTR_INPUTSYNC
); }
682 | tLENGTHIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_LENGTHIS
, $3); }
683 | tLCID
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_LIBLCID
, $3); }
684 | tLCID
{ $$
= make_attr
(ATTR_PARAMLCID
); }
685 | tLICENSED
{ $$
= make_attr
(ATTR_LICENSED
); }
686 | tLOCAL
{ $$
= make_attr
(ATTR_LOCAL
); }
687 | tMARSHALINGBEHAVIOR
'(' marshaling_behavior
')'
688 { $$
= make_attrv
(ATTR_MARSHALING_BEHAVIOR
, $3); }
689 | tMAYBE
{ $$
= make_attr
(ATTR_MAYBE
); }
690 | tMESSAGE
{ $$
= make_attr
(ATTR_MESSAGE
); }
691 | tNOCODE
{ $$
= make_attr
(ATTR_NOCODE
); }
692 | tNONBROWSABLE
{ $$
= make_attr
(ATTR_NONBROWSABLE
); }
693 | tNONCREATABLE
{ $$
= make_attr
(ATTR_NONCREATABLE
); }
694 | tNONEXTENSIBLE
{ $$
= make_attr
(ATTR_NONEXTENSIBLE
); }
695 | tNOTIFY
{ $$
= make_attr
(ATTR_NOTIFY
); }
696 | tNOTIFYFLAG
{ $$
= make_attr
(ATTR_NOTIFYFLAG
); }
697 | tOBJECT
{ $$
= make_attr
(ATTR_OBJECT
); }
698 | tODL
{ $$
= make_attr
(ATTR_ODL
); }
699 | tOLEAUTOMATION
{ $$
= make_attr
(ATTR_OLEAUTOMATION
); }
700 | tOPTIMIZE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_OPTIMIZE
, $3); }
701 | tOPTIONAL
{ $$
= make_attr
(ATTR_OPTIONAL
); }
702 | tOUT
{ $$
= make_attr
(ATTR_OUT
); }
703 | tOVERLOAD
'(' aSTRING
')' { $$
= make_attrp
(ATTR_OVERLOAD
, $3); }
704 | tPARTIALIGNORE
{ $$
= make_attr
(ATTR_PARTIALIGNORE
); }
705 | tPOINTERDEFAULT
'(' pointer_type
')' { $$
= make_attrv
(ATTR_POINTERDEFAULT
, $3); }
706 | tPROGID
'(' aSTRING
')' { $$
= make_attrp
(ATTR_PROGID
, $3); }
707 | tPROPGET
{ $$
= make_attr
(ATTR_PROPGET
); }
708 | tPROPPUT
{ $$
= make_attr
(ATTR_PROPPUT
); }
709 | tPROPPUTREF
{ $$
= make_attr
(ATTR_PROPPUTREF
); }
710 | tPROXY
{ $$
= make_attr
(ATTR_PROXY
); }
711 | tPUBLIC
{ $$
= make_attr
(ATTR_PUBLIC
); }
712 | tRANGE
'(' expr_int_const
',' expr_int_const
')'
713 { expr_list_t
*list
= append_expr
( NULL
, $3 );
714 list
= append_expr
( list
, $5 );
715 $$
= make_attrp
(ATTR_RANGE
, list
); }
716 | tREADONLY
{ $$
= make_attr
(ATTR_READONLY
); }
717 | tREPRESENTAS
'(' type
')' { $$
= make_attrp
(ATTR_REPRESENTAS
, $3); }
718 | tREQUESTEDIT
{ $$
= make_attr
(ATTR_REQUESTEDIT
); }
719 | tRESTRICTED
{ $$
= make_attr
(ATTR_RESTRICTED
); }
720 | tRETVAL
{ $$
= make_attr
(ATTR_RETVAL
); }
721 | tSIZEIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_SIZEIS
, $3); }
722 | tSOURCE
{ $$
= make_attr
(ATTR_SOURCE
); }
723 | tSTATIC
'(' static_attr
')' { $$
= make_attrp
(ATTR_STATIC
, $3); }
724 | tSTRICTCONTEXTHANDLE
{ $$
= make_attr
(ATTR_STRICTCONTEXTHANDLE
); }
725 | tSTRING
{ $$
= make_attr
(ATTR_STRING
); }
726 | tSWITCHIS
'(' expr
')' { $$
= make_attrp
(ATTR_SWITCHIS
, $3); }
727 | tSWITCHTYPE
'(' type
')' { $$
= make_attrp
(ATTR_SWITCHTYPE
, $3); }
728 | tTRANSMITAS
'(' type
')' { $$
= make_attrp
(ATTR_TRANSMITAS
, $3); }
729 | tTHREADING
'(' threading_type
')' { $$
= make_attrv
(ATTR_THREADING
, $3); }
730 | tUIDEFAULT
{ $$
= make_attr
(ATTR_UIDEFAULT
); }
731 | tUSESGETLASTERROR
{ $$
= make_attr
(ATTR_USESGETLASTERROR
); }
732 | tUSERMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_USERMARSHAL
, $3); }
733 | tUUID
'(' aUUID
')' { $$
= make_attrp
(ATTR_UUID
, $3); }
734 | tASYNCUUID
'(' aUUID
')' { $$
= make_attrp
(ATTR_ASYNCUUID
, $3); }
735 | tV1ENUM
{ $$
= make_attr
(ATTR_V1ENUM
); }
736 | tVARARG
{ $$
= make_attr
(ATTR_VARARG
); }
737 | tVERSION
'(' version
')' { $$
= make_attrv
(ATTR_VERSION
, $3); }
738 | tVIPROGID
'(' aSTRING
')' { $$
= make_attrp
(ATTR_VIPROGID
, $3); }
739 | tWIREMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_WIREMARSHAL
, $3); }
740 | pointer_type
{ $$
= make_attrv
(ATTR_POINTERTYPE
, $1); }
750 : %empty
{ $$
= NULL
; }
751 | cases case
{ $$
= append_var
( $1, $2 ); }
754 case: tCASE expr_int_const
':' union_field
{ attr_t
*a
= make_attrp
(ATTR_CASE
, append_expr
( NULL
, $2 ));
755 $$
= $4; if
(!$$
) $$
= make_var
(NULL
);
756 $$
->attrs
= append_attr
( $$
->attrs
, a
);
758 | tDEFAULT
':' union_field
{ attr_t
*a
= make_attr
(ATTR_DEFAULT
);
759 $$
= $3; if
(!$$
) $$
= make_var
(NULL
);
760 $$
->attrs
= append_attr
( $$
->attrs
, a
);
765 : %empty
{ $$
= NULL
; }
766 | enum_list
',' { $$
= $1; }
770 enum_list: enum { if
(!$1->eval
)
771 $1->eval
= make_exprl
(EXPR_NUM
, 0 /* default for first enum entry */);
772 $$
= append_var
( NULL
, $1 );
774 | enum_list
',' enum { if
(!$3->eval
)
776 var_t
*last
= LIST_ENTRY
( list_tail
($$
), var_t
, entry
);
777 enum expr_type type
= EXPR_NUM
;
778 if
(last
->eval
->type
== EXPR_HEXNUM
) type
= EXPR_HEXNUM
;
779 if
(last
->eval
->cval
+ 1 < 0) type
= EXPR_HEXNUM
;
780 $3->eval
= make_exprl
(type
, last
->eval
->cval
+ 1);
782 $$
= append_var
( $1, $3 );
786 enum_member: m_attributes ident
{ $$
= $2;
787 $$
->attrs
= check_enum_member_attrs
($1);
791 enum: enum_member
'=' expr_int_const
{ $$
= reg_const
($1);
793 $$
->declspec.type
= type_new_int
(TYPE_BASIC_INT
, 0);
795 | enum_member
{ $$
= reg_const
($1);
796 $$
->declspec.type
= type_new_int
(TYPE_BASIC_INT
, 0);
800 enumdef: tENUM m_typename
'{' enums
'}' { $$
= type_new_enum
($2, current_namespace
, TRUE
, $4); }
803 m_exprs: m_expr
{ $$
= append_expr
( NULL
, $1 ); }
804 | m_exprs
',' m_expr
{ $$
= append_expr
( $1, $3 ); }
808 : %empty
{ $$
= make_expr
(EXPR_VOID
); }
812 expr: aNUM
{ $$
= make_exprl
(EXPR_NUM
, $1); }
813 | aHEXNUM
{ $$
= make_exprl
(EXPR_HEXNUM
, $1); }
814 | aDOUBLE
{ $$
= make_exprd
(EXPR_DOUBLE
, $1); }
815 | tFALSE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 0); }
816 | tNULL
{ $$
= make_exprl
(EXPR_NUM
, 0); }
817 | tTRUE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 1); }
818 | aSTRING
{ $$
= make_exprs
(EXPR_STRLIT
, $1); }
819 | aWSTRING
{ $$
= make_exprs
(EXPR_WSTRLIT
, $1); }
820 | aSQSTRING
{ $$
= make_exprs
(EXPR_CHARCONST
, $1); }
821 | aIDENTIFIER
{ $$
= make_exprs
(EXPR_IDENTIFIER
, $1); }
822 | expr
'?' expr
':' expr
{ $$
= make_expr3
(EXPR_COND
, $1, $3, $5); }
823 | expr LOGICALOR expr
{ $$
= make_expr2
(EXPR_LOGOR
, $1, $3); }
824 | expr LOGICALAND expr
{ $$
= make_expr2
(EXPR_LOGAND
, $1, $3); }
825 | expr
'|' expr
{ $$
= make_expr2
(EXPR_OR
, $1, $3); }
826 | expr
'^' expr
{ $$
= make_expr2
(EXPR_XOR
, $1, $3); }
827 | expr
'&' expr
{ $$
= make_expr2
(EXPR_AND
, $1, $3); }
828 | expr EQUALITY expr
{ $$
= make_expr2
(EXPR_EQUALITY
, $1, $3); }
829 | expr INEQUALITY expr
{ $$
= make_expr2
(EXPR_INEQUALITY
, $1, $3); }
830 | expr
'>' expr
{ $$
= make_expr2
(EXPR_GTR
, $1, $3); }
831 | expr
'<' expr
{ $$
= make_expr2
(EXPR_LESS
, $1, $3); }
832 | expr GREATEREQUAL expr
{ $$
= make_expr2
(EXPR_GTREQL
, $1, $3); }
833 | expr LESSEQUAL expr
{ $$
= make_expr2
(EXPR_LESSEQL
, $1, $3); }
834 | expr SHL expr
{ $$
= make_expr2
(EXPR_SHL
, $1, $3); }
835 | expr SHR expr
{ $$
= make_expr2
(EXPR_SHR
, $1, $3); }
836 | expr
'+' expr
{ $$
= make_expr2
(EXPR_ADD
, $1, $3); }
837 | expr
'-' expr
{ $$
= make_expr2
(EXPR_SUB
, $1, $3); }
838 | expr
'%' expr
{ $$
= make_expr2
(EXPR_MOD
, $1, $3); }
839 | expr
'*' expr
{ $$
= make_expr2
(EXPR_MUL
, $1, $3); }
840 | expr
'/' expr
{ $$
= make_expr2
(EXPR_DIV
, $1, $3); }
841 |
'!' expr
{ $$
= make_expr1
(EXPR_LOGNOT
, $2); }
842 |
'~' expr
{ $$
= make_expr1
(EXPR_NOT
, $2); }
843 |
'+' expr %prec POS
{ $$
= make_expr1
(EXPR_POS
, $2); }
844 |
'-' expr %prec NEG
{ $$
= make_expr1
(EXPR_NEG
, $2); }
845 |
'&' expr %prec ADDRESSOF
{ $$
= make_expr1
(EXPR_ADDRESSOF
, $2); }
846 |
'*' expr %prec PPTR
{ $$
= make_expr1
(EXPR_PPTR
, $2); }
847 | expr MEMBERPTR aIDENTIFIER
{ $$
= make_expr2
(EXPR_MEMBER
, make_expr1
(EXPR_PPTR
, $1), make_exprs
(EXPR_IDENTIFIER
, $3)); }
848 | expr
'.' aIDENTIFIER
{ $$
= make_expr2
(EXPR_MEMBER
, $1, make_exprs
(EXPR_IDENTIFIER
, $3)); }
849 |
'(' unqualified_decl_spec m_abstract_declarator
')' expr %prec CAST
850 { $$
= make_exprt
(EXPR_CAST
, declare_var
(NULL
, $2, $3, 0), $5); free
($2); free
($3); }
851 | tSIZEOF
'(' unqualified_decl_spec m_abstract_declarator
')'
852 { $$
= make_exprt
(EXPR_SIZEOF
, declare_var
(NULL
, $3, $4, 0), NULL
); free
($3); free
($4); }
853 | expr
'[' expr
']' { $$
= make_expr2
(EXPR_ARRAY
, $1, $3); }
854 |
'(' expr
')' { $$
= $2; }
857 expr_list_int_const: expr_int_const
{ $$
= append_expr
( NULL
, $1 ); }
858 | expr_list_int_const
',' expr_int_const
{ $$
= append_expr
( $1, $3 ); }
861 expr_int_const: expr
{ $$
= $1;
863 error_loc
("expression is not an integer constant\n");
867 expr_const: expr
{ $$
= $1;
868 if
(!$$
->is_const
&& $$
->type
!= EXPR_STRLIT
&& $$
->type
!= EXPR_WSTRLIT
)
869 error_loc
("expression is not constant\n");
874 : %empty
{ $$
= NULL
; }
875 | fields field
{ $$
= append_var_list
($1, $2); }
878 field: m_attributes decl_spec struct_declarator_list
';'
879 { const char *first
= LIST_ENTRY
(list_head
($3), declarator_t
, entry
)->var
->name
;
880 check_field_attrs
(first
, $1);
881 $$
= set_var_types
($1, $2, $3);
883 | m_attributes uniondef
';' { var_t
*v
= make_var
(NULL
);
884 v
->declspec.type
= $2; v
->attrs
= $1;
885 $$
= append_var
(NULL
, v
);
890 s_field
';' { $$
= $1; }
891 | attributes
';' { $$
= make_var
(NULL
); $$
->attrs
= $1; }
895 : %empty
{ $$
= NULL
; }
896 | ne_union_fields ne_union_field
{ $$
= append_var
( $1, $2 ); }
900 s_field
';' { $$
= $1; }
904 s_field: m_attributes decl_spec declarator
{ $$
= declare_var
(check_field_attrs
($3->var
->name
, $1),
908 | m_attributes structdef
{ var_t
*v
= make_var
(NULL
);
909 v
->declspec.type
= $2; v
->attrs
= $1;
914 funcdef: declaration
{ $$
= $1;
915 if
(type_get_type
($$
->declspec.type
) != TYPE_FUNCTION
)
916 error_loc
("only methods may be declared inside the methods section of a dispinterface\n");
917 check_function_attrs
($$
->name
, $$
->attrs
);
922 attributes decl_spec init_declarator
923 { $$
= declare_var
($1, $2, $3, FALSE
);
926 | decl_spec init_declarator
{ $$
= declare_var
(NULL
, $1, $2, FALSE
);
932 : %empty
{ $$
= NULL
; }
937 : %empty
{ $$
= NULL
; }
941 typename: aIDENTIFIER
945 ident: typename
{ $$
= make_var
($1); }
948 base_type: tBYTE
{ $$
= find_type_or_error
( NULL
, "byte" ); }
949 | tWCHAR
{ $$
= find_type_or_error
( NULL
, "wchar_t" ); }
951 | tSIGNED int_std
{ $$
= type_new_int
(type_basic_get_type
($2), -1); }
952 | tUNSIGNED int_std
{ $$
= type_new_int
(type_basic_get_type
($2), 1); }
953 | tUNSIGNED
{ $$
= type_new_int
(TYPE_BASIC_INT
, 1); }
954 | tFLOAT
{ $$
= find_type_or_error
( NULL
, "float" ); }
955 | tDOUBLE
{ $$
= find_type_or_error
( NULL
, "double" ); }
956 | tBOOLEAN
{ $$
= find_type_or_error
( NULL
, "boolean" ); }
957 | tERRORSTATUST
{ $$
= find_type_or_error
( NULL
, "error_status_t" ); }
958 | tHANDLET
{ $$
= find_type_or_error
( NULL
, "handle_t" ); }
966 int_std: tINT
{ $$
= type_new_int
(TYPE_BASIC_INT
, 0); }
967 | tSHORT m_int
{ $$
= type_new_int
(TYPE_BASIC_INT16
, 0); }
968 | tSMALL
{ $$
= type_new_int
(TYPE_BASIC_INT8
, 0); }
969 | tLONG m_int
{ $$
= type_new_int
(TYPE_BASIC_LONG
, 0); }
970 | tHYPER m_int
{ $$
= type_new_int
(TYPE_BASIC_HYPER
, 0); }
971 | tINT64
{ $$
= type_new_int
(TYPE_BASIC_INT64
, 0); }
972 | tCHAR
{ $$
= type_new_int
(TYPE_BASIC_CHAR
, 0); }
973 | tINT32
{ $$
= type_new_int
(TYPE_BASIC_INT32
, 0); }
974 | tINT3264
{ $$
= type_new_int
(TYPE_BASIC_INT3264
, 0); }
978 aIDENTIFIER
'.' { $$
= find_namespace_or_error
(&global_namespace
, $1); }
979 | namespace_pfx aIDENTIFIER
'.' { $$
= find_namespace_or_error
($1, $2); }
983 typename
{ $$
= find_type_or_error
(current_namespace
, $1); }
984 | namespace_pfx typename
{ $$
= find_type_or_error
($1, $2); }
987 parameterized_type: qualified_type
'<' parameterized_type_args
'>'
988 { $$
= find_parameterized_type
($1, $3); }
991 parameterized_type_arg:
992 base_type
{ $$
= $1; }
993 | qualified_type
{ $$
= $1; }
994 | qualified_type
'*' { $$
= type_new_pointer
($1); }
995 | parameterized_type
{ $$
= $1; }
996 | parameterized_type
'*' { $$
= type_new_pointer
($1); }
999 parameterized_type_args:
1000 parameterized_type_arg
{ $$
= append_typeref
(NULL
, make_typeref
($1)); }
1001 | parameterized_type_args
',' parameterized_type_arg
1002 { $$
= append_typeref
($1, make_typeref
($3)); }
1005 coclass: tCOCLASS typename
{ $$
= type_coclass_declare
($2); }
1008 coclassdef: attributes coclass
'{' class_interfaces
'}' semicolon_opt
1009 { $$
= type_coclass_define
($2, $1, $4); }
1012 runtimeclass: tRUNTIMECLASS typename
{ $$
= type_runtimeclass_declare
($2, current_namespace
); }
1015 runtimeclass_def: attributes runtimeclass
'{' class_interfaces
'}' semicolon_opt
1016 { $$
= type_runtimeclass_define
($2, $1, $4); }
1019 apicontract: tAPICONTRACT typename
{ $$
= type_apicontract_declare
($2, current_namespace
); }
1022 apicontract_def: attributes apicontract
'{' '}' semicolon_opt
1023 { $$
= type_apicontract_define
($2, $1); }
1026 namespacedef: tNAMESPACE aIDENTIFIER
{ $$
= append_str
( NULL
, $2 ); }
1027 | namespacedef
'.' aIDENTIFIER
{ $$
= append_str
( $1, $3 ); }
1031 : %empty
{ $$
= NULL
; }
1032 | class_interfaces class_interface
{ $$
= append_typeref
( $1, $2 ); }
1036 m_attributes interfaceref
';' { $$
= make_typeref
($2); $$
->attrs
= $1; }
1037 | m_attributes dispinterfaceref
';' { $$
= make_typeref
($2); $$
->attrs
= $1; }
1040 dispinterface: tDISPINTERFACE typename
{ $$
= type_dispinterface_declare
($2); }
1043 dispattributes: attributes
{ $$
= append_attr
($1, make_attr
(ATTR_DISPINTERFACE
)); }
1046 dispint_props: tPROPERTIES
':' { $$
= NULL
; }
1047 | dispint_props s_field
';' { $$
= append_var
( $1, $2 ); }
1050 dispint_meths: tMETHODS
':' { $$
= NULL
; }
1051 | dispint_meths funcdef
';' { $$
= append_var
( $1, $2 ); }
1055 dispattributes dispinterface
'{' dispint_props dispint_meths
'}'
1056 { $$
= type_dispinterface_define
($2, $1, $4, $5); }
1057 | dispattributes dispinterface
'{' interface
';' '}'
1058 { $$
= type_dispinterface_define_from_iface
($2, $1, $4); }
1062 : %empty
{ $$
= NULL
; }
1063 |
':' qualified_type
{ $$
= $2; }
1064 |
':' parameterized_type
{ $$
= $2; }
1067 type_parameter: typename
{ $$
= get_type
(TYPE_PARAMETER
, $1, parameters_namespace
, 0); }
1071 type_parameter
{ $$
= append_typeref
(NULL
, make_typeref
($1)); }
1072 | type_parameters
',' type_parameter
{ $$
= append_typeref
($1, make_typeref
($3)); }
1076 tINTERFACE typename
{ $$
= type_interface_declare
($2, current_namespace
); }
1077 | tINTERFACE typename
'<' { push_parameters_namespace
($2); } type_parameters
{ pop_parameters_namespace
($2); } '>'
1078 { $$
= type_parameterized_interface_declare
($2, current_namespace
, $5); }
1081 delegatedef: m_attributes tDELEGATE type ident
'(' m_args
')' semicolon_opt
1082 { $$
= type_delegate_declare
($4->name
, current_namespace
);
1083 $$
= type_delegate_define
($$
, $1, append_statement
(NULL
, make_statement_delegate
($3, $6)));
1085 | m_attributes tDELEGATE type ident
1086 '<' { push_parameters_namespace
($4->name
); } type_parameters
'>'
1087 '(' m_args
')' { pop_parameters_namespace
($4->name
); } semicolon_opt
1088 { $$
= type_parameterized_delegate_declare
($4->name
, current_namespace
, $7);
1089 $$
= type_parameterized_delegate_define
($$
, $1, append_statement
(NULL
, make_statement_delegate
($3, $10)));
1094 qualified_type
{ $$
= append_typeref
(NULL
, make_typeref
($1)); }
1095 | parameterized_type
{ $$
= append_typeref
(NULL
, make_typeref
($1)); }
1096 | required_types
',' qualified_type
{ $$
= append_typeref
($1, make_typeref
($3)); }
1097 | required_types
',' parameterized_type
{ $$
= append_typeref
($1, make_typeref
($3)); }
1101 : %empty
{ $$
= NULL
; }
1102 | tREQUIRES required_types
{ $$
= $2; }
1105 interfacedef: attributes interface
{ if
($2->type_type
== TYPE_PARAMETERIZED_TYPE
) push_parameters_namespace
($2->name
); }
1106 inherit requires
'{' int_statements
'}' semicolon_opt
1107 { if
($2->type_type
== TYPE_PARAMETERIZED_TYPE
)
1109 $$
= type_parameterized_interface_define
($2, $1, $4, $7, $5);
1110 pop_parameters_namespace
($2->name
);
1114 $$
= type_interface_define
($2, $1, $4, $7, $5);
1115 check_async_uuid
($$
);
1118 | dispinterfacedef semicolon_opt
{ $$
= $1; }
1122 tINTERFACE typename
{ $$
= get_type
(TYPE_INTERFACE
, $2, current_namespace
, 0); }
1123 | tINTERFACE namespace_pfx typename
{ $$
= get_type
(TYPE_INTERFACE
, $3, $2, 0); }
1124 | tINTERFACE parameterized_type
{ if
(type_get_type
(($$
= $2)) != TYPE_INTERFACE
) error_loc
("%s is not an interface\n", $$
->name
); }
1128 tDISPINTERFACE typename
{ $$
= get_type
(TYPE_INTERFACE
, $2, current_namespace
, 0); }
1131 module: tMODULE typename
{ $$
= type_module_declare
($2); }
1134 moduledef: m_attributes module
'{' int_statements
'}' semicolon_opt
1135 { $$
= type_module_define
($2, $1, $4); }
1139 tEXTERN
{ $$
= STG_EXTERN
; }
1140 | tSTATIC
{ $$
= STG_STATIC
; }
1141 | tREGISTER
{ $$
= STG_REGISTER
; }
1145 tINLINE
{ $$
= FUNCTION_SPECIFIER_INLINE
; }
1149 tCONST
{ $$
= TYPE_QUALIFIER_CONST
; }
1153 : %empty
{ $$
= 0; }
1154 | m_type_qual_list type_qualifier
{ $$
= $1 |
$2; }
1157 decl_spec: type m_decl_spec_no_type
{ $$
= make_decl_spec
($1, $2, NULL
, STG_NONE
, 0, 0); }
1158 | decl_spec_no_type type m_decl_spec_no_type
1159 { $$
= make_decl_spec
($2, $1, $3, STG_NONE
, 0, 0); }
1162 unqualified_decl_spec: unqualified_type m_decl_spec_no_type
1163 { $$
= make_decl_spec
($1, $2, NULL
, STG_NONE
, 0, 0); }
1164 | decl_spec_no_type unqualified_type m_decl_spec_no_type
1165 { $$
= make_decl_spec
($2, $1, $3, STG_NONE
, 0, 0); }
1169 : %empty
{ $$
= NULL
; }
1174 type_qualifier m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, STG_NONE
, $1, 0); }
1175 | function_specifier m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, STG_NONE
, 0, $1); }
1176 | storage_cls_spec m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, $1, 0, 0); }
1180 '*' m_type_qual_list declarator %prec PPTR
1181 { $$
= $3; append_chain_type
($$
, type_new_pointer
(NULL
), $2); }
1182 | callconv declarator
{ $$
= $2; append_chain_callconv
($$
->type
, $1); }
1187 ident
{ $$
= make_declarator
($1); }
1188 |
'(' declarator
')' { $$
= $2; }
1189 | direct_declarator array
{ $$
= $1; append_array
($$
, $2); }
1190 | direct_declarator
'(' m_args
')' { $$
= $1; append_chain_type
($$
, type_new_function
($3), 0); }
1193 /* abstract declarator */
1194 abstract_declarator:
1195 '*' m_type_qual_list m_abstract_declarator %prec PPTR
1196 { $$
= $3; append_chain_type
($$
, type_new_pointer
(NULL
), $2); }
1197 | callconv m_abstract_declarator
{ $$
= $2; append_chain_callconv
($$
->type
, $1); }
1198 | abstract_direct_declarator
1201 /* abstract declarator without accepting direct declarator */
1202 abstract_declarator_no_direct:
1203 '*' m_type_qual_list m_any_declarator %prec PPTR
1204 { $$
= $3; append_chain_type
($$
, type_new_pointer
(NULL
), $2); }
1205 | callconv m_any_declarator
{ $$
= $2; append_chain_callconv
($$
->type
, $1); }
1208 /* abstract declarator or empty */
1209 m_abstract_declarator
1210 : %empty
{ $$
= make_declarator
(NULL
); }
1211 | abstract_declarator
1214 /* abstract direct declarator */
1215 abstract_direct_declarator:
1216 '(' abstract_declarator_no_direct
')' { $$
= $2; }
1217 | abstract_direct_declarator array
{ $$
= $1; append_array
($$
, $2); }
1218 | array
{ $$
= make_declarator
(NULL
); append_array
($$
, $1); }
1220 { $$
= make_declarator
(NULL
);
1221 append_chain_type
($$
, type_new_function
($2), 0);
1223 | abstract_direct_declarator
'(' m_args
')'
1225 append_chain_type
($$
, type_new_function
($3), 0);
1229 /* abstract or non-abstract declarator */
1231 '*' m_type_qual_list m_any_declarator %prec PPTR
1232 { $$
= $3; append_chain_type
($$
, type_new_pointer
(NULL
), $2); }
1233 | callconv m_any_declarator
{ $$
= $2; append_chain_callconv
($$
->type
, $1); }
1234 | any_direct_declarator
1237 /* abstract or non-abstract declarator without accepting direct declarator */
1238 any_declarator_no_direct:
1239 '*' m_type_qual_list m_any_declarator %prec PPTR
1240 { $$
= $3; append_chain_type
($$
, type_new_pointer
(NULL
), $2); }
1241 | callconv m_any_declarator
{ $$
= $2; append_chain_callconv
($$
->type
, $1); }
1244 /* abstract or non-abstract declarator or empty */
1246 : %empty
{ $$
= make_declarator
(NULL
); }
1250 /* abstract or non-abstract direct declarator. note: direct declarators
1251 * aren't accepted inside brackets to avoid ambiguity with the rule for
1252 * function arguments */
1253 any_direct_declarator:
1254 ident
{ $$
= make_declarator
($1); }
1255 |
'(' any_declarator_no_direct
')' { $$
= $2; }
1256 | any_direct_declarator array
{ $$
= $1; append_array
($$
, $2); }
1257 | array
{ $$
= make_declarator
(NULL
); append_array
($$
, $1); }
1259 { $$
= make_declarator
(NULL
);
1260 append_chain_type
($$
, type_new_function
($2), 0);
1262 | any_direct_declarator
'(' m_args
')'
1264 append_chain_type
($$
, type_new_function
($3), 0);
1269 declarator
{ $$
= append_declarator
( NULL
, $1 ); }
1270 | declarator_list
',' declarator
{ $$
= append_declarator
( $1, $3 ); }
1274 : %empty
{ $$
= NULL
; }
1275 |
':' expr_const
{ $$
= $2; }
1278 struct_declarator: any_declarator m_bitfield
{ $$
= $1; $$
->bits
= $2;
1279 if
(!$$
->bits
&& !$$
->var
->name
)
1280 error_loc
("unnamed fields are not allowed\n");
1284 struct_declarator_list:
1285 struct_declarator
{ $$
= append_declarator
( NULL
, $1 ); }
1286 | struct_declarator_list
',' struct_declarator
1287 { $$
= append_declarator
( $1, $3 ); }
1291 declarator
{ $$
= $1; }
1292 | declarator
'=' expr_const
{ $$
= $1; $1->var
->eval
= $3; }
1296 tAPARTMENT
{ $$
= THREADING_APARTMENT
; }
1297 | tNEUTRAL
{ $$
= THREADING_NEUTRAL
; }
1298 | tSINGLE
{ $$
= THREADING_SINGLE
; }
1299 | tFREE
{ $$
= THREADING_FREE
; }
1300 | tBOTH
{ $$
= THREADING_BOTH
; }
1301 | tMTA
{ $$
= THREADING_FREE
; }
1305 tREF
{ $$
= FC_RP
; }
1306 | tUNIQUE
{ $$
= FC_UP
; }
1307 | tPTR
{ $$
= FC_FP
; }
1310 structdef: tSTRUCT m_typename
'{' fields
'}' { $$
= type_new_struct
($2, current_namespace
, TRUE
, $4); }
1314 tVOID
{ $$
= type_new_void
(); }
1315 | base_type
{ $$
= $1; }
1316 | enumdef
{ $$
= $1; }
1317 | tENUM aIDENTIFIER
{ $$
= type_new_enum
($2, current_namespace
, FALSE
, NULL
); }
1318 | structdef
{ $$
= $1; }
1319 | tSTRUCT aIDENTIFIER
{ $$
= type_new_struct
($2, current_namespace
, FALSE
, NULL
); }
1320 | uniondef
{ $$
= $1; }
1321 | tUNION aIDENTIFIER
{ $$
= type_new_nonencapsulated_union
($2, current_namespace
, FALSE
, NULL
); }
1322 | tSAFEARRAY
'(' type
')' { $$
= make_safearray
($3); }
1323 | aKNOWNTYPE
{ $$
= find_type_or_error
(current_namespace
, $1); }
1328 | namespace_pfx typename
{ $$
= find_type_or_error
($1, $2); }
1329 | parameterized_type
{ $$
= $1; }
1332 typedef: m_attributes tTYPEDEF m_attributes decl_spec declarator_list
1333 { $1 = append_attribs
($1, $3);
1334 reg_typedefs
($4, $5, check_typedef_attrs
($1));
1335 $$
= make_statement_typedef
($5, !$4->type
->defined
);
1339 uniondef: tUNION m_typename
'{' ne_union_fields
'}'
1340 { $$
= type_new_nonencapsulated_union
($2, current_namespace
, TRUE
, $4); }
1342 tSWITCH
'(' s_field
')'
1343 m_ident
'{' cases
'}' { $$
= type_new_encapsulated_union
($2, $5, $7, $9); }
1347 aNUM
{ $$
= MAKEVERSION
($1, 0); }
1348 | aNUM
'.' aNUM
{ $$
= MAKEVERSION
($1, $3); }
1349 | aHEXNUM
{ $$
= $1; }
1354 | acf_interface acf_statements
1359 | acf_int_statement acf_int_statements
1363 : tTYPEDEF acf_attributes aKNOWNTYPE
';'
1364 { type_t
*type
= find_type_or_error
(current_namespace
, $3);
1365 type
->attrs
= append_attr_list
(type
->attrs
, $2);
1370 : acf_attributes tINTERFACE aKNOWNTYPE
'{' acf_int_statements
'}'
1371 { type_t
*iface
= find_type_or_error
(current_namespace
, $3);
1372 if
(type_get_type
(iface
) != TYPE_INTERFACE
)
1373 error_loc
("%s is not an interface\n", iface
->name
);
1374 iface
->attrs
= append_attr_list
(iface
->attrs
, $1);
1379 : %empty
{ $$
= NULL
; }
1380 |
'[' acf_attribute_list
']' { $$
= $2; }
1384 : acf_attribute
{ $$
= append_attr
(NULL
, $1); }
1385 | acf_attribute_list
',' acf_attribute
{ $$
= append_attr
($1, $3); }
1389 : tALLOCATE
'(' allocate_option_list
')'
1390 { $$
= make_attrv
(ATTR_ALLOCATE
, $3); }
1391 | tENCODE
{ $$
= make_attr
(ATTR_ENCODE
); }
1392 | tDECODE
{ $$
= make_attr
(ATTR_DECODE
); }
1393 | tEXPLICITHANDLE
{ $$
= make_attr
(ATTR_EXPLICIT_HANDLE
); }
1396 allocate_option_list
1397 : allocate_option
{ $$
= $1; }
1398 | allocate_option_list
',' allocate_option
1403 : tDONTFREE
{ $$
= FC_DONT_FREE
; }
1405 | tALLNODES
{ $$
= FC_ALLOCATE_ALL_NODES
; }
1406 | tSINGLENODE
{ $$
= 0; }
1411 static void decl_builtin_basic
(const char *name
, enum type_basic_type type
)
1413 type_t
*t
= type_new_basic
(type
);
1414 reg_type
(t
, name
, NULL
, 0);
1417 static void decl_builtin_alias
(const char *name
, type_t
*t
)
1419 const decl_spec_t ds
= {.type
= t
};
1420 reg_type
(type_new_alias
(&ds
, name
), name
, NULL
, 0);
1423 void init_types
(void)
1425 decl_builtin_basic
("byte", TYPE_BASIC_BYTE
);
1426 decl_builtin_basic
("wchar_t", TYPE_BASIC_WCHAR
);
1427 decl_builtin_basic
("float", TYPE_BASIC_FLOAT
);
1428 decl_builtin_basic
("double", TYPE_BASIC_DOUBLE
);
1429 decl_builtin_basic
("error_status_t", TYPE_BASIC_ERROR_STATUS_T
);
1430 decl_builtin_basic
("handle_t", TYPE_BASIC_HANDLE
);
1431 decl_builtin_alias
("boolean", type_new_basic
(TYPE_BASIC_CHAR
));
1434 static str_list_t
*append_str
(str_list_t
*list
, char *str
)
1436 struct str_list_entry_t
*entry
;
1438 if
(!str
) return list
;
1441 list
= xmalloc
( sizeof
(*list
) );
1444 entry
= xmalloc
( sizeof
(*entry
) );
1446 list_add_tail
( list
, &entry
->entry
);
1450 static attr_list_t
*move_attr
(attr_list_t
*dst
, attr_list_t
*src
, enum attr_type type
)
1453 if
(!src
) return dst
;
1454 LIST_FOR_EACH_ENTRY
(attr
, src
, attr_t
, entry
)
1455 if
(attr
->type
== type
)
1457 list_remove
(&attr
->entry
);
1458 return append_attr
(dst
, attr
);
1463 static attr_list_t
*append_attr_list
(attr_list_t
*new_list
, attr_list_t
*old_list
)
1467 if
(!old_list
) return new_list
;
1469 while
((entry
= list_head
(old_list
)))
1471 attr_t
*attr
= LIST_ENTRY
(entry
, attr_t
, entry
);
1473 new_list
= append_attr
(new_list
, attr
);
1478 typedef
int (*map_attrs_filter_t
)(attr_list_t
*,const attr_t
*);
1480 static attr_list_t
*map_attrs
(const attr_list_t
*list
, map_attrs_filter_t filter
)
1482 attr_list_t
*new_list
;
1486 if
(!list
) return NULL
;
1488 new_list
= xmalloc
( sizeof
(*list
) );
1489 list_init
( new_list
);
1490 LIST_FOR_EACH_ENTRY
(attr
, list
, const attr_t
, entry
)
1492 if
(filter
&& !filter
(new_list
, attr
)) continue
;
1493 new_attr
= xmalloc
(sizeof
(*new_attr
));
1495 list_add_tail
(new_list
, &new_attr
->entry
);
1500 static decl_spec_t
*make_decl_spec
(type_t
*type
, decl_spec_t
*left
, decl_spec_t
*right
,
1501 enum storage_class stgclass
, enum type_qualifier qual
, enum function_specifier func_specifier
)
1503 decl_spec_t
*declspec
= left ? left
: right
;
1506 declspec
= xmalloc
(sizeof
(*declspec
));
1507 declspec
->type
= NULL
;
1508 declspec
->stgclass
= STG_NONE
;
1509 declspec
->qualifier
= 0;
1510 declspec
->func_specifier
= 0;
1512 declspec
->type
= type
;
1513 if
(left
&& declspec
!= left
)
1515 if
(declspec
->stgclass
== STG_NONE
)
1516 declspec
->stgclass
= left
->stgclass
;
1517 else if
(left
->stgclass
!= STG_NONE
)
1518 error_loc
("only one storage class can be specified\n");
1519 declspec
->qualifier |
= left
->qualifier
;
1520 declspec
->func_specifier |
= left
->func_specifier
;
1521 assert
(!left
->type
);
1524 if
(right
&& declspec
!= right
)
1526 if
(declspec
->stgclass
== STG_NONE
)
1527 declspec
->stgclass
= right
->stgclass
;
1528 else if
(right
->stgclass
!= STG_NONE
)
1529 error_loc
("only one storage class can be specified\n");
1530 declspec
->qualifier |
= right
->qualifier
;
1531 declspec
->func_specifier |
= right
->func_specifier
;
1532 assert
(!right
->type
);
1536 if
(declspec
->stgclass
== STG_NONE
)
1537 declspec
->stgclass
= stgclass
;
1538 else if
(stgclass
!= STG_NONE
)
1539 error_loc
("only one storage class can be specified\n");
1540 declspec
->qualifier |
= qual
;
1541 declspec
->func_specifier |
= func_specifier
;
1546 static attr_t
*make_attr
(enum attr_type type
)
1548 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1554 static attr_t
*make_attrv
(enum attr_type type
, unsigned int val
)
1556 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1562 attr_t
*make_attrp
(enum attr_type type
, void *val
)
1564 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1570 static attr_t
*make_custom_attr
(struct uuid
*id
, expr_t
*pval
)
1572 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1573 attr_custdata_t
*cstdata
= xmalloc
(sizeof
(attr_custdata_t
));
1574 a
->type
= ATTR_CUSTOM
;
1576 cstdata
->pval
= pval
;
1577 a
->u.pval
= cstdata
;
1581 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
)
1583 if
(!expr
) return list
;
1586 list
= xmalloc
( sizeof
(*list
) );
1589 list_add_tail
( list
, &expr
->entry
);
1593 static void append_array
(declarator_t
*decl
, expr_t
*expr
)
1600 /* An array is always a reference pointer unless explicitly marked otherwise
1601 * (regardless of what the default pointer attribute is). */
1602 array
= type_new_array
(NULL
, NULL
, FALSE
, expr
->is_const ? expr
->cval
: 0,
1603 expr
->is_const ? NULL
: expr
, NULL
);
1605 append_chain_type
(decl
, array
, 0);
1608 static struct list type_pool
= LIST_INIT
(type_pool
);
1615 type_t
*alloc_type
(void)
1617 type_pool_node_t
*node
= xmalloc
(sizeof
*node
);
1618 list_add_tail
(&type_pool
, &node
->link
);
1622 void set_all_tfswrite
(int val
)
1624 type_pool_node_t
*node
;
1625 LIST_FOR_EACH_ENTRY
(node
, &type_pool
, type_pool_node_t
, link
)
1626 node
->data.tfswrite
= val
;
1629 void clear_all_offsets
(void)
1631 type_pool_node_t
*node
;
1632 LIST_FOR_EACH_ENTRY
(node
, &type_pool
, type_pool_node_t
, link
)
1633 node
->data.typestring_offset
= node
->data.ptrdesc
= 0;
1636 static void type_function_add_head_arg
(type_t
*type
, var_t
*arg
)
1638 if
(!type
->details.function
->args
)
1640 type
->details.function
->args
= xmalloc
( sizeof
(*type
->details.function
->args
) );
1641 list_init
( type
->details.function
->args
);
1643 list_add_head
( type
->details.function
->args
, &arg
->entry
);
1646 static int is_allowed_range_type
(const type_t
*type
)
1648 switch
(type_get_type
(type
))
1653 switch
(type_basic_get_type
(type
))
1655 case TYPE_BASIC_INT8
:
1656 case TYPE_BASIC_INT16
:
1657 case TYPE_BASIC_INT32
:
1658 case TYPE_BASIC_INT64
:
1659 case TYPE_BASIC_INT
:
1660 case TYPE_BASIC_INT3264
:
1661 case TYPE_BASIC_LONG
:
1662 case TYPE_BASIC_BYTE
:
1663 case TYPE_BASIC_CHAR
:
1664 case TYPE_BASIC_WCHAR
:
1665 case TYPE_BASIC_HYPER
:
1667 case TYPE_BASIC_FLOAT
:
1668 case TYPE_BASIC_DOUBLE
:
1669 case TYPE_BASIC_ERROR_STATUS_T
:
1670 case TYPE_BASIC_HANDLE
:
1679 static type_t
*get_chain_ref
(type_t
*type
)
1682 return type_pointer_get_ref_type
(type
);
1683 else if
(is_array
(type
))
1684 return type_array_get_element_type
(type
);
1685 else if
(is_func
(type
))
1686 return type_function_get_rettype
(type
);
1690 static type_t
*get_chain_end
(type_t
*type
)
1693 while
((inner
= get_chain_ref
(type
)))
1698 static void append_chain_type
(declarator_t
*decl
, type_t
*type
, enum type_qualifier qual
)
1705 decl
->qualifier
= qual
;
1708 chain_type
= get_chain_end
(decl
->type
);
1710 if
(is_ptr
(chain_type
))
1712 chain_type
->details.pointer.ref.type
= type
;
1713 chain_type
->details.pointer.ref.qualifier
= qual
;
1715 else if
(is_array
(chain_type
))
1717 chain_type
->details.array.elem.type
= type
;
1718 chain_type
->details.array.elem.qualifier
= qual
;
1720 else if
(is_func
(chain_type
))
1722 chain_type
->details.function
->retval
->declspec.type
= type
;
1723 chain_type
->details.function
->retval
->declspec.qualifier
= qual
;
1728 if
(!is_func
(chain_type
))
1729 type
->attrs
= move_attr
(type
->attrs
, chain_type
->attrs
, ATTR_CALLCONV
);
1732 static void append_chain_callconv
(type_t
*chain
, char *callconv
)
1736 if
(chain
&& (chain_end
= get_chain_end
(chain
)))
1737 chain_end
->attrs
= append_attr
(chain_end
->attrs
, make_attrp
(ATTR_CALLCONV
, callconv
));
1739 error_loc
("calling convention applied to non-function type\n");
1742 static warning_list_t
*append_warning
(warning_list_t
*list
, int num
)
1748 list
= xmalloc
( sizeof
(*list
) );
1751 entry
= xmalloc
( sizeof
(*entry
) );
1753 list_add_tail
( list
, &entry
->entry
);
1757 static var_t
*declare_var
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_t
*decl
,
1760 var_t
*v
= decl
->var
;
1761 expr_list_t
*sizes
= get_attrp
(attrs
, ATTR_SIZEIS
);
1762 expr_list_t
*lengs
= get_attrp
(attrs
, ATTR_LENGTHIS
);
1765 type_t
*type
= decl_spec
->type
;
1767 if
(decl_spec
->func_specifier
& FUNCTION_SPECIFIER_INLINE
)
1769 if
(!decl ||
!is_func
(decl
->type
))
1770 error_loc
("inline attribute applied to non-function type\n");
1773 /* add type onto the end of the pointers in pident->type */
1774 append_chain_type
(decl
, type
, decl_spec
->qualifier
);
1775 v
->declspec
= *decl_spec
;
1776 v
->declspec.type
= decl
->type
;
1777 v
->declspec.qualifier
= decl
->qualifier
;
1779 v
->declonly
= !type
->defined
;
1781 if
(is_attr
(type
->attrs
, ATTR_CALLCONV
) && !is_func
(type
))
1782 error_loc
("calling convention applied to non-function type\n");
1784 /* check for pointer attribute being applied to non-pointer, non-array
1786 if
(!is_array
(v
->declspec.type
))
1788 int ptr_attr
= get_attrv
(v
->attrs
, ATTR_POINTERTYPE
);
1789 const type_t
*ptr
= NULL
;
1790 for
(ptr
= v
->declspec.type
; ptr
&& !ptr_attr
; )
1792 ptr_attr
= get_attrv
(ptr
->attrs
, ATTR_POINTERTYPE
);
1793 if
(!ptr_attr
&& type_is_alias
(ptr
))
1794 ptr
= type_alias_get_aliasee_type
(ptr
);
1800 if
(ptr_attr
&& ptr_attr
!= FC_UP
&&
1801 type_get_type
(type_pointer_get_ref_type
(ptr
)) == TYPE_INTERFACE
)
1802 warning_at
( &v
->where
, "%s: pointer attribute applied to interface pointer type has no effect\n", v
->name
);
1803 if
(!ptr_attr
&& top
)
1805 /* FIXME: this is a horrible hack to cope with the issue that we
1806 * store an offset to the typeformat string in the type object, but
1807 * two typeformat strings may be written depending on whether the
1808 * pointer is a toplevel parameter or not */
1809 v
->declspec.type
= duptype
(v
->declspec.type
, 1);
1813 error_loc
("%s: pointer attribute applied to non-pointer type\n", v
->name
);
1816 if
(is_attr
(v
->attrs
, ATTR_STRING
))
1820 if
(!is_ptr
(v
->declspec.type
) && !is_array
(v
->declspec.type
))
1821 error_loc
("'%s': [string] attribute applied to non-pointer, non-array type\n",
1827 t
= type_pointer_get_ref_type
(t
);
1828 else if
(is_array
(t
))
1829 t
= type_array_get_element_type
(t
);
1834 if
(type_get_type
(t
) != TYPE_BASIC
&&
1835 (get_basic_fc
(t
) != FC_CHAR
&&
1836 get_basic_fc
(t
) != FC_BYTE
&&
1837 get_basic_fc
(t
) != FC_WCHAR
))
1839 error_loc
("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
1844 if
(is_attr
(v
->attrs
, ATTR_V1ENUM
))
1846 if
(type_get_type_detect_alias
(v
->declspec.type
) != TYPE_ENUM
)
1847 error_loc
("'%s': [v1_enum] attribute applied to non-enum type\n", v
->name
);
1850 if
(is_attr
(v
->attrs
, ATTR_RANGE
) && !is_allowed_range_type
(v
->declspec.type
))
1851 error_loc
("'%s': [range] attribute applied to non-integer type\n",
1854 ptype
= &v
->declspec.type
;
1855 if
(sizes
) LIST_FOR_EACH_ENTRY
(dim
, sizes
, expr_t
, entry
)
1857 if
(dim
->type
!= EXPR_VOID
)
1859 if
(is_array
(*ptype
))
1861 if
(!type_array_get_conformance
(*ptype
) ||
1862 type_array_get_conformance
(*ptype
)->type
!= EXPR_VOID
)
1863 error_loc
("%s: cannot specify size_is for an already sized array\n", v
->name
);
1865 *ptype
= type_new_array
((*ptype
)->name
,
1866 type_array_get_element
(*ptype
), FALSE
,
1869 else if
(is_ptr
(*ptype
))
1870 *ptype
= type_new_array
((*ptype
)->name
, type_pointer_get_ref
(*ptype
), TRUE
,
1873 error_loc
("%s: size_is attribute applied to illegal type\n", v
->name
);
1877 ptype
= &(*ptype
)->details.pointer.ref.type
;
1878 else if
(is_array
(*ptype
))
1879 ptype
= &(*ptype
)->details.array.elem.type
;
1881 error_loc
("%s: too many expressions in size_is attribute\n", v
->name
);
1884 ptype
= &v
->declspec.type
;
1885 if
(lengs
) LIST_FOR_EACH_ENTRY
(dim
, lengs
, expr_t
, entry
)
1887 if
(dim
->type
!= EXPR_VOID
)
1889 if
(is_array
(*ptype
))
1891 *ptype
= type_new_array
((*ptype
)->name
,
1892 type_array_get_element
(*ptype
),
1893 type_array_is_decl_as_ptr
(*ptype
),
1894 type_array_get_dim
(*ptype
),
1895 type_array_get_conformance
(*ptype
), dim
);
1898 error_loc
("%s: length_is attribute applied to illegal type\n", v
->name
);
1902 ptype
= &(*ptype
)->details.pointer.ref.type
;
1903 else if
(is_array
(*ptype
))
1904 ptype
= &(*ptype
)->details.array.elem.type
;
1906 error_loc
("%s: too many expressions in length_is attribute\n", v
->name
);
1910 v
->declspec.type
= type_new_bitfield
(v
->declspec.type
, decl
->bits
);
1915 static var_list_t
*set_var_types
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_list_t
*decls
)
1917 declarator_t
*decl
, *next
;
1918 var_list_t
*var_list
= NULL
;
1920 LIST_FOR_EACH_ENTRY_SAFE
( decl
, next
, decls
, declarator_t
, entry
)
1922 var_t
*var
= declare_var
(attrs
, decl_spec
, decl
, 0);
1923 var_list
= append_var
(var_list
, var
);
1930 typeref_list_t
*append_typeref
(typeref_list_t
*list
, typeref_t
*ref
)
1932 if
(!ref
) return list
;
1935 list
= xmalloc
( sizeof
(*list
) );
1938 list_add_tail
( list
, &ref
->entry
);
1942 typeref_t
*make_typeref
(type_t
*type
)
1944 typeref_t
*ref
= xmalloc
(sizeof
(typeref_t
));
1950 var_list_t
*append_var
(var_list_t
*list
, var_t
*var
)
1952 if
(!var
) return list
;
1955 list
= xmalloc
( sizeof
(*list
) );
1958 list_add_tail
( list
, &var
->entry
);
1962 static var_list_t
*append_var_list
(var_list_t
*list
, var_list_t
*vars
)
1964 if
(!vars
) return list
;
1967 list
= xmalloc
( sizeof
(*list
) );
1970 list_move_tail
( list
, vars
);
1974 var_t
*make_var
(char *name
)
1976 var_t
*v
= xmalloc
(sizeof
(var_t
));
1978 init_declspec
(&v
->declspec
, NULL
);
1981 init_location
( &v
->where
, NULL
, NULL
);
1982 v
->declonly
= FALSE
;
1986 static var_t
*copy_var
(var_t
*src
, char *name
, map_attrs_filter_t attr_filter
)
1988 var_t
*v
= xmalloc
(sizeof
(var_t
));
1990 v
->declspec
= src
->declspec
;
1991 v
->attrs
= map_attrs
(src
->attrs
, attr_filter
);
1992 v
->eval
= src
->eval
;
1993 v
->where
= src
->where
;
1997 static declarator_list_t
*append_declarator
(declarator_list_t
*list
, declarator_t
*d
)
1999 if
(!d
) return list
;
2001 list
= xmalloc
(sizeof
(*list
));
2004 list_add_tail
(list
, &d
->entry
);
2008 static declarator_t
*make_declarator
(var_t
*var
)
2010 declarator_t
*d
= xmalloc
(sizeof
(*d
));
2011 d
->var
= var ? var
: make_var
(NULL
);
2018 static type_t
*make_safearray
(type_t
*type
)
2020 decl_spec_t ds
= {.type
= type
};
2021 ds.type
= type_new_alias
(&ds
, "SAFEARRAY");
2022 return type_new_array
(NULL
, &ds
, TRUE
, 0, NULL
, NULL
);
2025 static typelib_t
*make_library
(const char *name
, const attr_list_t
*attrs
)
2027 typelib_t
*typelib
= xmalloc
(sizeof
(*typelib
));
2028 memset
(typelib
, 0, sizeof
(*typelib
));
2029 typelib
->name
= xstrdup
(name
);
2030 typelib
->attrs
= attrs
;
2031 list_init
( &typelib
->importlibs
);
2035 static int hash_ident
(const char *name
)
2037 const char *p
= name
;
2039 /* a simple sum hash is probably good enough */
2044 return sum
& (HASHMAX
-1);
2047 /***** type repository *****/
2049 static struct namespace
*find_sub_namespace
(struct namespace
*namespace
, const char *name
)
2051 struct namespace
*cur
;
2053 LIST_FOR_EACH_ENTRY
(cur
, &namespace
->children
, struct namespace
, entry
) {
2054 if
(!strcmp
(cur
->name
, name
))
2061 static void push_namespace
(const char *name
)
2063 struct namespace
*namespace
;
2065 namespace
= find_sub_namespace
(current_namespace
, name
);
2067 namespace
= xmalloc
(sizeof
(*namespace
));
2068 namespace
->name
= xstrdup
(name
);
2069 namespace
->parent
= current_namespace
;
2070 list_add_tail
(¤t_namespace
->children
, &namespace
->entry
);
2071 list_init
(&namespace
->children
);
2072 memset
(namespace
->type_hash
, 0, sizeof
(namespace
->type_hash
));
2075 current_namespace
= namespace
;
2078 static void pop_namespace
(const char *name
)
2080 assert
(!strcmp
(current_namespace
->name
, name
) && current_namespace
->parent
);
2081 current_namespace
= current_namespace
->parent
;
2084 static void push_namespaces
(str_list_t
*names
)
2086 const struct str_list_entry_t
*name
;
2087 LIST_FOR_EACH_ENTRY
(name
, names
, const struct str_list_entry_t
, entry
)
2088 push_namespace
(name
->str
);
2091 static void pop_namespaces
(str_list_t
*names
)
2093 const struct str_list_entry_t
*name
;
2094 LIST_FOR_EACH_ENTRY_REV
(name
, names
, const struct str_list_entry_t
, entry
)
2095 pop_namespace
(name
->str
);
2098 static void push_parameters_namespace
(const char *name
)
2100 struct namespace
*namespace
;
2102 if
(!(namespace
= find_sub_namespace
(current_namespace
, name
)))
2104 namespace
= xmalloc
(sizeof
(*namespace
));
2105 namespace
->name
= xstrdup
(name
);
2106 namespace
->parent
= current_namespace
;
2107 list_add_tail
(¤t_namespace
->children
, &namespace
->entry
);
2108 list_init
(&namespace
->children
);
2109 memset
(namespace
->type_hash
, 0, sizeof
(namespace
->type_hash
));
2112 parameters_namespace
= namespace
;
2115 static void pop_parameters_namespace
(const char *name
)
2117 assert
(!strcmp
(parameters_namespace
->name
, name
) && parameters_namespace
->parent
);
2118 parameters_namespace
= NULL
;
2128 type_t
*reg_type
(type_t
*type
, const char *name
, struct namespace
*namespace
, int t
)
2133 error_loc
("registering named type without name\n");
2137 namespace
= &global_namespace
;
2138 hash
= hash_ident
(name
);
2139 nt
= xmalloc
(sizeof
(struct rtype
));
2141 if
(is_global_namespace
(namespace
))
2143 type
->c_name
= name
;
2144 type
->qualified_name
= name
;
2148 type
->c_name
= format_namespace
(namespace
, "__x_", "_C", name
, use_abi_namespace ?
"ABI" : NULL
);
2149 type
->qualified_name
= format_namespace
(namespace
, "", "::", name
, use_abi_namespace ?
"ABI" : NULL
);
2153 nt
->next
= namespace
->type_hash
[hash
];
2154 namespace
->type_hash
[hash
] = nt
;
2158 static type_t
*reg_typedefs
(decl_spec_t
*decl_spec
, declarator_list_t
*decls
, attr_list_t
*attrs
)
2161 type_t
*type
= decl_spec
->type
;
2163 if
(is_attr
(attrs
, ATTR_UUID
) && !is_attr
(attrs
, ATTR_PUBLIC
))
2164 attrs
= append_attr
( attrs
, make_attr
(ATTR_PUBLIC
) );
2166 /* We must generate names for tagless enum, struct or union.
2167 Typedef-ing a tagless enum, struct or union means we want the typedef
2168 to be included in a library hence the public attribute. */
2169 if
(type_get_type_detect_alias
(type
) == TYPE_ENUM ||
2170 type_get_type_detect_alias
(type
) == TYPE_STRUCT ||
2171 type_get_type_detect_alias
(type
) == TYPE_UNION ||
2172 type_get_type_detect_alias
(type
) == TYPE_ENCAPSULATED_UNION
)
2176 type
->name
= gen_name
();
2177 if
(!is_attr
(attrs
, ATTR_PUBLIC
))
2178 attrs
= append_attr
(attrs
, make_attr
(ATTR_PUBLIC
));
2181 /* replace existing attributes when generating a typelib */
2183 type
->attrs
= attrs
;
2186 LIST_FOR_EACH_ENTRY
( decl
, decls
, declarator_t
, entry
)
2189 if
(decl
->var
->name
) {
2193 cur
= find_type
(decl
->var
->name
, current_namespace
, 0);
2196 * MIDL allows shadowing types that are declared in imported files.
2197 * We don't throw an error in this case and instead add a new type
2198 * (which is earlier on the list in hash table, so it will be used
2199 * instead of shadowed type).
2201 * FIXME: We may consider string separated type tables for each input
2202 * for cleaner solution.
2204 if
(cur
&& input_name
== cur
->where.input_name
)
2205 error_loc
( "%s: redefinition error; original definition was at %s:%d\n",
2206 cur
->name
, cur
->where.input_name
, cur
->where.first_line
);
2208 name
= declare_var
(attrs
, decl_spec
, decl
, 0);
2209 cur
= type_new_alias
(&name
->declspec
, name
->name
);
2212 reg_type
(cur
, cur
->name
, current_namespace
, 0);
2218 type_t
*find_type
(const char *name
, struct namespace
*namespace
, int t
)
2222 if
(namespace
&& namespace
!= &global_namespace
) {
2223 for
(cur
= namespace
->type_hash
[hash_ident
(name
)]; cur
; cur
= cur
->next
) {
2224 if
(cur
->t
== t
&& !strcmp
(cur
->name
, name
))
2228 for
(cur
= global_namespace.type_hash
[hash_ident
(name
)]; cur
; cur
= cur
->next
) {
2229 if
(cur
->t
== t
&& !strcmp
(cur
->name
, name
))
2235 static type_t
*find_type_or_error
(struct namespace
*namespace
, const char *name
)
2238 if
(!(type
= find_type
(name
, namespace
, 0)) &&
2239 !(type
= find_type
(name
, parameters_namespace
, 0)))
2241 error_loc
("type '%s' not found in %s namespace\n", name
, namespace
&& namespace
->name ? namespace
->name
: "global");
2247 static struct namespace
*find_namespace_or_error
(struct namespace
*parent
, const char *name
)
2249 struct namespace
*namespace
= NULL
;
2252 error_loc
("namespaces are only supported in winrt mode.\n");
2253 else if
(!(namespace
= find_sub_namespace
(parent
, name
)))
2254 error_loc
("namespace '%s' not found in '%s'\n", name
, parent
->name
);
2259 int is_type
(const char *name
)
2261 return find_type
(name
, current_namespace
, 0) != NULL ||
2262 find_type
(name
, parameters_namespace
, 0);
2265 type_t
*get_type
(enum type_type type
, char *name
, struct namespace
*namespace
, int t
)
2269 namespace
= &global_namespace
;
2271 tp
= find_type
(name
, namespace
, t
);
2277 tp
= make_type
(type
);
2279 tp
->namespace
= namespace
;
2280 if
(!name
) return tp
;
2281 return reg_type
(tp
, name
, namespace
, t
);
2284 /***** constant repository *****/
2289 struct rconst
*next
;
2292 struct rconst
*const_hash
[HASHMAX
];
2294 static var_t
*reg_const
(var_t
*var
)
2299 error_loc
("registering constant without name\n");
2302 hash
= hash_ident
(var
->name
);
2303 nc
= xmalloc
(sizeof
(struct rconst
));
2304 nc
->name
= var
->name
;
2306 nc
->next
= const_hash
[hash
];
2307 const_hash
[hash
] = nc
;
2311 var_t
*find_const
(const char *name
, int f
)
2313 struct rconst
*cur
= const_hash
[hash_ident
(name
)];
2314 while
(cur
&& strcmp
(cur
->name
, name
))
2317 if
(f
) error_loc
("constant '%s' not found\n", name
);
2323 char *gen_name
(void)
2325 static unsigned long n
= 0;
2326 static const char *file_id
;
2330 char *dst
= replace_extension
( get_basename
(input_idl_name
), ".idl", "" );
2334 if
(! isalnum
((unsigned char) *dst
))
2337 return strmake
("__WIDL_%s_generated_name_%08lX", file_id
, n
++);
2342 unsigned int dce_compatible
: 1;
2343 unsigned int acf
: 1;
2344 unsigned int multiple
: 1;
2346 unsigned int on_interface
: 1;
2347 unsigned int on_function
: 1;
2348 unsigned int on_arg
: 1;
2349 unsigned int on_type
: 1;
2350 unsigned int on_enum
: 1;
2351 unsigned int on_enum_member
: 1;
2352 unsigned int on_struct
: 2;
2353 unsigned int on_union
: 1;
2354 unsigned int on_field
: 1;
2355 unsigned int on_library
: 1;
2356 unsigned int on_dispinterface
: 1;
2357 unsigned int on_module
: 1;
2358 unsigned int on_coclass
: 1;
2359 unsigned int on_apicontract
: 1;
2360 unsigned int on_runtimeclass
: 1;
2361 const char *display_name
;
2364 struct allowed_attr allowed_attr
[] =
2366 /* attr { D ACF M I Fn ARG T En Enm St Un Fi L DI M C AC R <display name> } */
2367 /* ATTR_ACTIVATABLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "activatable" },
2368 /* ATTR_AGGREGATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "aggregatable" },
2369 /* ATTR_ALLOCATE */ { 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "allocate" },
2370 /* ATTR_ANNOTATION */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "annotation" },
2371 /* ATTR_APPOBJECT */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "appobject" },
2372 /* ATTR_ASYNC */ { 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "async" },
2373 /* ATTR_ASYNCUUID */ { 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "async_uuid" },
2374 /* ATTR_AUTO_HANDLE */ { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "auto_handle" },
2375 /* ATTR_BINDABLE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "bindable" },
2376 /* ATTR_BROADCAST */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "broadcast" },
2377 /* ATTR_CALLAS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "call_as" },
2378 /* ATTR_CALLCONV */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
},
2379 /* ATTR_CASE */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "case" },
2380 /* ATTR_CODE */ { 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "code" },
2381 /* ATTR_COMMSTATUS */ { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "comm_status" },
2382 /* ATTR_CONTEXTHANDLE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "context_handle" },
2383 /* ATTR_CONTRACT */ { 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, "contract" },
2384 /* ATTR_CONTRACTVERSION */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, "contractversion" },
2385 /* ATTR_CONTROL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, "control" },
2386 /* ATTR_CUSTOM */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, "custom" },
2387 /* ATTR_DECODE */ { 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "decode" },
2388 /* ATTR_DEFAULT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "default" },
2389 /* ATTR_DEFAULTBIND */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultbind" },
2390 /* ATTR_DEFAULTCOLLELEM */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultcollelem" },
2391 /* ATTR_DEFAULTVALUE */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultvalue" },
2392 /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "defaultvtable" },
2393 /* ATTR_DISABLECONSISTENCYCHECK */{ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "disable_consistency_check" },
2394 /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, NULL
},
2395 /* ATTR_DISPLAYBIND */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "displaybind" },
2396 /* ATTR_DLLNAME */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "dllname" },
2397 /* ATTR_DUAL */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "dual" },
2398 /* ATTR_ENABLEALLOCATE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "enable_allocate" },
2399 /* ATTR_ENCODE */ { 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "encode" },
2400 /* ATTR_ENDPOINT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "endpoint" },
2401 /* ATTR_ENTRY */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "entry" },
2402 /* ATTR_EVENTADD */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "eventadd" },
2403 /* ATTR_EVENTREMOVE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "eventremove" },
2404 /* ATTR_EXCLUSIVETO */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "exclusive_to" },
2405 /* ATTR_EXPLICIT_HANDLE */ { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "explicit_handle" },
2406 /* ATTR_FAULTSTATUS */ { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "fault_status" },
2407 /* ATTR_FLAGS */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "flags" },
2408 /* ATTR_FORCEALLOCATE */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "force_allocate" },
2409 /* ATTR_HANDLE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "handle" },
2410 /* ATTR_HELPCONTEXT */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "helpcontext" },
2411 /* ATTR_HELPFILE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "helpfile" },
2412 /* ATTR_HELPSTRING */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "helpstring" },
2413 /* ATTR_HELPSTRINGCONTEXT */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "helpstringcontext" },
2414 /* ATTR_HELPSTRINGDLL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "helpstringdll" },
2415 /* ATTR_HIDDEN */ { 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, "hidden" },
2416 /* ATTR_ID */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, "id" },
2417 /* ATTR_IDEMPOTENT */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "idempotent" },
2418 /* ATTR_IGNORE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "ignore" },
2419 /* ATTR_IIDIS */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "iid_is" },
2420 /* ATTR_IMMEDIATEBIND */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "immediatebind" },
2421 /* ATTR_IMPLICIT_HANDLE */ { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "implicit_handle" },
2422 /* ATTR_IN */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "in" },
2423 /* ATTR_INPUTSYNC */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inputsync" },
2424 /* ATTR_LENGTHIS */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "length_is" },
2425 /* ATTR_LIBLCID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "lcid" },
2426 /* ATTR_LICENSED */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "licensed" },
2427 /* ATTR_LOCAL */ { 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "local" },
2428 /* ATTR_MARSHALING_BEHAVIOR */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "marshaling_behavior" },
2429 /* ATTR_MAYBE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "maybe" },
2430 /* ATTR_MESSAGE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "message" },
2431 /* ATTR_NOCODE */ { 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nocode" },
2432 /* ATTR_NONBROWSABLE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonbrowsable" },
2433 /* ATTR_NONCREATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "noncreatable" },
2434 /* ATTR_NONEXTENSIBLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonextensible" },
2435 /* ATTR_NOTIFY */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "notify" },
2436 /* ATTR_NOTIFYFLAG */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "notify_flag" },
2437 /* ATTR_OBJECT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "object" },
2438 /* ATTR_ODL */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "odl" },
2439 /* ATTR_OLEAUTOMATION */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "oleautomation" },
2440 /* ATTR_OPTIMIZE */ { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optimize" },
2441 /* ATTR_OPTIONAL */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optional" },
2442 /* ATTR_OUT */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "out" },
2443 /* ATTR_OVERLOAD */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "overload" },
2444 /* ATTR_PARAMLCID */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "lcid" },
2445 /* ATTR_PARTIALIGNORE */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "partial_ignore" },
2446 /* ATTR_POINTERDEFAULT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "pointer_default" },
2447 /* ATTR_POINTERTYPE */ { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "ref, unique or ptr" },
2448 /* ATTR_PROGID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "progid" },
2449 /* ATTR_PROPGET */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propget" },
2450 /* ATTR_PROPPUT */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propput" },
2451 /* ATTR_PROPPUTREF */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propputref" },
2452 /* ATTR_PROXY */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "proxy" },
2453 /* ATTR_PUBLIC */ { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "public" },
2454 /* ATTR_RANGE */ { 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "range" },
2455 /* ATTR_READONLY */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "readonly" },
2456 /* ATTR_REPRESENTAS */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "represent_as" },
2457 /* ATTR_REQUESTEDIT */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "requestedit" },
2458 /* ATTR_RESTRICTED */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, "restricted" },
2459 /* ATTR_RETVAL */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "retval" },
2460 /* ATTR_SIZEIS */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "size_is" },
2461 /* ATTR_SOURCE */ { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "source" },
2462 /* ATTR_STATIC */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "static" },
2463 /* ATTR_STRICTCONTEXTHANDLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "strict_context_handle" },
2464 /* ATTR_STRING */ { 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "string" },
2465 /* ATTR_SWITCHIS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "switch_is" },
2466 /* ATTR_SWITCHTYPE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "switch_type" },
2467 /* ATTR_THREADING */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, "threading" },
2468 /* ATTR_TRANSMITAS */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "transmit_as" },
2469 /* ATTR_UIDEFAULT */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "uidefault" },
2470 /* ATTR_USESGETLASTERROR */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "usesgetlasterror" },
2471 /* ATTR_USERMARSHAL */ { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "user_marshal" },
2472 /* ATTR_UUID */ { 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, "uuid" },
2473 /* ATTR_V1ENUM */ { 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "v1_enum" },
2474 /* ATTR_VARARG */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "vararg" },
2475 /* ATTR_VERSION */ { 1, 0, 0, 1, 0, 0, 1, 1, 0, 2, 0, 0, 1, 0, 1, 1, 0, 1, "version" },
2476 /* ATTR_VIPROGID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "vi_progid" },
2477 /* ATTR_WIREMARSHAL */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "wire_marshal" },
2480 attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
)
2482 attr_t
*attr_existing
;
2483 if
(!attr
) return list
;
2486 list
= xmalloc
( sizeof
(*list
) );
2489 if
(!allowed_attr
[attr
->type
].multiple
)
2491 LIST_FOR_EACH_ENTRY
(attr_existing
, list
, attr_t
, entry
)
2492 if
(attr_existing
->type
== attr
->type
)
2494 warning_loc
( "duplicate attribute %s\n", get_attr_display_name
(attr
->type
) );
2495 /* use the last attribute, like MIDL does */
2496 list_remove
(&attr_existing
->entry
);
2500 list_add_tail
( list
, &attr
->entry
);
2504 const char *get_attr_display_name
(enum attr_type type
)
2506 return allowed_attr
[type
].display_name
;
2509 attr_list_t
*check_interface_attrs
(const char *name
, attr_list_t
*attrs
)
2512 if
(!attrs
) return attrs
;
2513 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2515 if
(!allowed_attr
[attr
->type
].on_interface
)
2516 error_loc
("inapplicable attribute %s for interface %s\n",
2517 allowed_attr
[attr
->type
].display_name
, name
);
2518 if
(attr
->type
== ATTR_IMPLICIT_HANDLE
)
2520 const var_t
*var
= attr
->u.pval
;
2521 if
(type_get_type
( var
->declspec.type
) == TYPE_BASIC
&&
2522 type_basic_get_type
( var
->declspec.type
) == TYPE_BASIC_HANDLE
)
2524 if
(is_aliaschain_attr
( var
->declspec.type
, ATTR_HANDLE
))
2526 error_loc
("attribute %s requires a handle type in interface %s\n",
2527 allowed_attr
[attr
->type
].display_name
, name
);
2533 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
)
2536 if
(!attrs
) return attrs
;
2537 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2539 if
(!allowed_attr
[attr
->type
].on_function
)
2540 error_loc
("inapplicable attribute %s for function %s\n",
2541 allowed_attr
[attr
->type
].display_name
, name
);
2546 static void check_arg_attrs
(const var_t
*arg
)
2552 LIST_FOR_EACH_ENTRY
(attr
, arg
->attrs
, const attr_t
, entry
)
2554 if
(!allowed_attr
[attr
->type
].on_arg
)
2555 error_loc
("inapplicable attribute %s for argument %s\n",
2556 allowed_attr
[attr
->type
].display_name
, arg
->name
);
2561 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
)
2564 if
(!attrs
) return attrs
;
2565 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2567 if
(!allowed_attr
[attr
->type
].on_type
)
2568 error_loc
("inapplicable attribute %s for typedef\n",
2569 allowed_attr
[attr
->type
].display_name
);
2574 static attr_list_t
*check_enum_attrs
(attr_list_t
*attrs
)
2577 if
(!attrs
) return attrs
;
2578 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2580 if
(!allowed_attr
[attr
->type
].on_enum
)
2581 error_loc
("inapplicable attribute %s for enum\n",
2582 allowed_attr
[attr
->type
].display_name
);
2587 static attr_list_t
*check_enum_member_attrs
(attr_list_t
*attrs
)
2590 if
(!attrs
) return attrs
;
2591 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2593 if
(!allowed_attr
[attr
->type
].on_enum_member
)
2594 error_loc
("inapplicable attribute %s for enum member\n",
2595 allowed_attr
[attr
->type
].display_name
);
2600 static attr_list_t
*check_struct_attrs
(attr_list_t
*attrs
)
2602 int mask
= winrt_mode ?
3 : 1;
2604 if
(!attrs
) return attrs
;
2605 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2607 if
(!(allowed_attr
[attr
->type
].on_struct
& mask
))
2608 error_loc
("inapplicable attribute %s for struct\n",
2609 allowed_attr
[attr
->type
].display_name
);
2614 static attr_list_t
*check_union_attrs
(attr_list_t
*attrs
)
2617 if
(!attrs
) return attrs
;
2618 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2620 if
(!allowed_attr
[attr
->type
].on_union
)
2621 error_loc
("inapplicable attribute %s for union\n",
2622 allowed_attr
[attr
->type
].display_name
);
2627 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
)
2630 if
(!attrs
) return attrs
;
2631 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2633 if
(!allowed_attr
[attr
->type
].on_field
)
2634 error_loc
("inapplicable attribute %s for field %s\n",
2635 allowed_attr
[attr
->type
].display_name
, name
);
2640 static attr_list_t
*check_library_attrs
(const char *name
, attr_list_t
*attrs
)
2643 if
(!attrs
) return attrs
;
2644 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2646 if
(!allowed_attr
[attr
->type
].on_library
)
2647 error_loc
("inapplicable attribute %s for library %s\n",
2648 allowed_attr
[attr
->type
].display_name
, name
);
2653 attr_list_t
*check_dispiface_attrs
(const char *name
, attr_list_t
*attrs
)
2656 if
(!attrs
) return attrs
;
2657 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2659 if
(!allowed_attr
[attr
->type
].on_dispinterface
)
2660 error_loc
("inapplicable attribute %s for dispinterface %s\n",
2661 allowed_attr
[attr
->type
].display_name
, name
);
2666 attr_list_t
*check_module_attrs
(const char *name
, attr_list_t
*attrs
)
2669 if
(!attrs
) return attrs
;
2670 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2672 if
(!allowed_attr
[attr
->type
].on_module
)
2673 error_loc
("inapplicable attribute %s for module %s\n",
2674 allowed_attr
[attr
->type
].display_name
, name
);
2679 attr_list_t
*check_coclass_attrs
(const char *name
, attr_list_t
*attrs
)
2682 if
(!attrs
) return attrs
;
2683 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2685 if
(!allowed_attr
[attr
->type
].on_coclass
)
2686 error_loc
("inapplicable attribute %s for coclass %s\n",
2687 allowed_attr
[attr
->type
].display_name
, name
);
2692 attr_list_t
*check_runtimeclass_attrs
(const char *name
, attr_list_t
*attrs
)
2695 if
(!attrs
) return attrs
;
2696 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2697 if
(!allowed_attr
[attr
->type
].on_runtimeclass
)
2698 error_loc
("inapplicable attribute %s for runtimeclass %s\n",
2699 allowed_attr
[attr
->type
].display_name
, name
);
2703 attr_list_t
*check_apicontract_attrs
(const char *name
, attr_list_t
*attrs
)
2706 if
(!attrs
) return attrs
;
2707 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2708 if
(!allowed_attr
[attr
->type
].on_apicontract
)
2709 error_loc
("inapplicable attribute %s for apicontract %s\n",
2710 allowed_attr
[attr
->type
].display_name
, name
);
2714 static int is_allowed_conf_type
(const type_t
*type
)
2716 switch
(type_get_type
(type
))
2721 switch
(type_basic_get_type
(type
))
2723 case TYPE_BASIC_INT8
:
2724 case TYPE_BASIC_INT16
:
2725 case TYPE_BASIC_INT32
:
2726 case TYPE_BASIC_INT64
:
2727 case TYPE_BASIC_INT
:
2728 case TYPE_BASIC_LONG
:
2729 case TYPE_BASIC_CHAR
:
2730 case TYPE_BASIC_HYPER
:
2731 case TYPE_BASIC_BYTE
:
2732 case TYPE_BASIC_WCHAR
:
2738 /* shouldn't get here because of type_get_type call above */
2743 case TYPE_ENCAPSULATED_UNION
:
2750 case TYPE_INTERFACE
:
2752 case TYPE_RUNTIMECLASS
:
2755 case TYPE_APICONTRACT
:
2756 case TYPE_PARAMETERIZED_TYPE
:
2757 case TYPE_PARAMETER
:
2758 /* not supposed to be here */
2765 static int is_ptr_guid_type
(const type_t
*type
)
2767 /* first, make sure it is a pointer to something */
2768 if
(!is_ptr
(type
)) return FALSE
;
2770 /* second, make sure it is a pointer to something of size sizeof(GUID),
2772 return
(type_memsize
(type_pointer_get_ref_type
(type
)) == 16);
2775 static void check_conformance_expr_list
(const char *attr_name
, const var_t
*arg
, const type_t
*container_type
, expr_list_t
*expr_list
)
2778 struct expr_loc expr_loc
;
2780 expr_loc.attr
= attr_name
;
2781 if
(expr_list
) LIST_FOR_EACH_ENTRY
(dim
, expr_list
, expr_t
, entry
)
2783 if
(dim
->type
!= EXPR_VOID
)
2785 const type_t
*expr_type
= expr_resolve_type
(&expr_loc
, container_type
, dim
);
2786 if
(!is_allowed_conf_type
(expr_type
))
2787 error_at
( &arg
->where
, "expression must resolve to integral type <= 32bits for attribute %s\n", attr_name
);
2792 static void check_remoting_fields
(const var_t
*var
, type_t
*type
);
2794 /* checks that properties common to fields and arguments are consistent */
2795 static void check_field_common
(const type_t
*container_type
,
2796 const char *container_name
, const var_t
*arg
)
2798 type_t
*type
= arg
->declspec.type
;
2800 const char *container_type_name
;
2801 const char *var_type
;
2803 switch
(type_get_type
(container_type
))
2806 container_type_name
= "struct";
2810 container_type_name
= "union";
2813 case TYPE_ENCAPSULATED_UNION
:
2814 container_type_name
= "encapsulated union";
2818 container_type_name
= "function";
2819 var_type
= "parameter";
2822 /* should be no other container types */
2827 if
(is_attr
(arg
->attrs
, ATTR_LENGTHIS
) &&
2828 (is_attr
(arg
->attrs
, ATTR_STRING
) || is_aliaschain_attr
(arg
->declspec.type
, ATTR_STRING
)))
2829 error_at
( &arg
->where
, "string and length_is specified for argument %s are mutually exclusive attributes\n", arg
->name
);
2831 if
(is_attr
(arg
->attrs
, ATTR_SIZEIS
))
2833 expr_list_t
*size_is_exprs
= get_attrp
(arg
->attrs
, ATTR_SIZEIS
);
2834 check_conformance_expr_list
("size_is", arg
, container_type
, size_is_exprs
);
2836 if
(is_attr
(arg
->attrs
, ATTR_LENGTHIS
))
2838 expr_list_t
*length_is_exprs
= get_attrp
(arg
->attrs
, ATTR_LENGTHIS
);
2839 check_conformance_expr_list
("length_is", arg
, container_type
, length_is_exprs
);
2841 if
(is_attr
(arg
->attrs
, ATTR_IIDIS
))
2843 struct expr_loc expr_loc
;
2844 expr_t
*expr
= get_attrp
(arg
->attrs
, ATTR_IIDIS
);
2845 if
(expr
->type
!= EXPR_VOID
)
2847 const type_t
*expr_type
;
2849 expr_loc.attr
= "iid_is";
2850 expr_type
= expr_resolve_type
(&expr_loc
, container_type
, expr
);
2851 if
(!expr_type ||
!is_ptr_guid_type
(expr_type
))
2852 error_at
( &arg
->where
, "expression must resolve to pointer to GUID type for attribute iid_is\n" );
2855 if
(is_attr
(arg
->attrs
, ATTR_SWITCHIS
))
2857 struct expr_loc expr_loc
;
2858 expr_t
*expr
= get_attrp
(arg
->attrs
, ATTR_SWITCHIS
);
2859 if
(expr
->type
!= EXPR_VOID
)
2861 const type_t
*expr_type
;
2863 expr_loc.attr
= "switch_is";
2864 expr_type
= expr_resolve_type
(&expr_loc
, container_type
, expr
);
2865 if
(!expr_type ||
!is_allowed_conf_type
(expr_type
))
2866 error_at
( &arg
->where
, "expression must resolve to integral type <= 32bits for attribute %s\n", expr_loc.attr
);
2874 switch
(typegen_detect_type
(type
, arg
->attrs
, TDT_IGNORE_STRINGS
))
2878 check_remoting_fields
(arg
, type
);
2882 const char *reason
= "is invalid";
2883 switch
(type_get_type
(type
))
2886 reason
= "cannot derive from void *";
2889 reason
= "cannot be a function pointer";
2892 reason
= "cannot be a bit-field";
2895 reason
= "cannot be a class";
2897 case TYPE_INTERFACE
:
2898 reason
= "cannot be a non-pointer to an interface";
2901 reason
= "cannot be a module";
2906 error_at
( &arg
->where
, "%s \'%s\' of %s \'%s\' %s\n", var_type
, arg
->name
, container_type_name
, container_name
, reason
);
2909 case TGT_CTXT_HANDLE
:
2910 case TGT_CTXT_HANDLE_POINTER
:
2911 if
(type_get_type
(container_type
) != TYPE_FUNCTION
)
2912 error_at
( &arg
->where
, "%s \'%s\' of %s \'%s\' cannot be a context handle\n",
2913 var_type
, arg
->name
, container_type_name
, container_name
);
2917 const type_t
*t
= type
;
2919 t
= type_pointer_get_ref_type
(t
);
2920 if
(is_aliaschain_attr
(t
, ATTR_RANGE
))
2921 warning_at
( &arg
->where
, "%s: range not verified for a string of ranged types\n", arg
->name
);
2925 type
= type_pointer_get_ref_type
(type
);
2929 type
= type_array_get_element_type
(type
);
2933 type
= type_get_real_type
(type
);
2934 if
(!type_is_complete
(type
))
2935 error_at
( &arg
->where
, "undefined type declaration \"enum %s\"\n", type
->name
);
2937 case TGT_IFACE_POINTER
:
2943 } while
(more_to_do
);
2946 static void check_remoting_fields
(const var_t
*var
, type_t
*type
)
2949 const var_list_t
*fields
= NULL
;
2951 type
= type_get_real_type
(type
);
2956 type
->checked
= TRUE
;
2958 if
(type_get_type
(type
) == TYPE_STRUCT
)
2960 if
(type_is_complete
(type
))
2961 fields
= type_struct_get_fields
(type
);
2963 error_at
( &var
->where
, "undefined type declaration \"struct %s\"\n", type
->name
);
2965 else if
(type_get_type
(type
) == TYPE_UNION || type_get_type
(type
) == TYPE_ENCAPSULATED_UNION
)
2967 if
(type_is_complete
(type
))
2968 fields
= type_union_get_cases
(type
);
2970 error_at
( &var
->where
, "undefined type declaration \"union %s\"\n", type
->name
);
2973 if
(fields
) LIST_FOR_EACH_ENTRY
( field
, fields
, const var_t
, entry
)
2974 if
(field
->declspec.type
) check_field_common
(type
, type
->name
, field
);
2977 /* checks that arguments for a function make sense for marshalling and unmarshalling */
2978 static void check_remoting_args
(const var_t
*func
)
2980 const char *funcname
= func
->name
;
2983 if
(!type_function_get_args
(func
->declspec.type
))
2986 LIST_FOR_EACH_ENTRY
( arg
, type_function_get_args
(func
->declspec.type
), const var_t
, entry
)
2988 const type_t
*type
= arg
->declspec.type
;
2990 /* check that [out] parameters have enough pointer levels */
2991 if
(is_attr
(arg
->attrs
, ATTR_OUT
))
2993 switch
(typegen_detect_type
(type
, arg
->attrs
, TDT_ALL_TYPES
))
3000 case TGT_CTXT_HANDLE
:
3002 error_at
( &arg
->where
, "out parameter \'%s\' of function \'%s\' is not a pointer\n", arg
->name
, funcname
);
3004 case TGT_IFACE_POINTER
:
3005 error_at
( &arg
->where
, "out interface pointer \'%s\' of function \'%s\' is not a double pointer\n", arg
->name
, funcname
);
3010 /* needs conformance or fixed dimension */
3011 if
(type_array_has_conformance
(type
) &&
3012 type_array_get_conformance
(type
)->type
!= EXPR_VOID
) break
;
3013 if
(!type_array_has_conformance
(type
) && type_array_get_dim
(type
)) break
;
3015 if
(is_attr
( arg
->attrs
, ATTR_IN
)) break
;
3016 error_at
( &arg
->where
, "out parameter \'%s\' of function \'%s\' cannot be an unsized string\n", arg
->name
, funcname
);
3019 /* already error'd before we get here */
3020 case TGT_CTXT_HANDLE_POINTER
:
3028 check_field_common
(func
->declspec.type
, funcname
, arg
);
3031 if
(type_get_type
(type_function_get_rettype
(func
->declspec.type
)) != TYPE_VOID
)
3035 var.declspec.type
= type_function_get_rettype
(func
->declspec.type
);
3036 var.name
= xstrdup
("return value");
3037 check_field_common
(func
->declspec.type
, funcname
, &var
);
3042 static void add_explicit_handle_if_necessary
(const type_t
*iface
, var_t
*func
)
3044 unsigned char explicit_fc
, implicit_fc
;
3046 /* check for a defined binding handle */
3047 if
(!get_func_handle_var
( iface
, func
, &explicit_fc
, &implicit_fc
) ||
!explicit_fc
)
3049 /* no explicit handle specified so add
3050 * "[in] handle_t IDL_handle" as the first parameter to the
3052 var_t
*idl_handle
= make_var
(xstrdup
("IDL_handle"));
3053 idl_handle
->attrs
= append_attr
(NULL
, make_attr
(ATTR_IN
));
3054 idl_handle
->declspec.type
= find_type_or_error
(NULL
, "handle_t");
3055 type_function_add_head_arg
(func
->declspec.type
, idl_handle
);
3059 static void check_functions
(const type_t
*iface
, int is_inside_library
)
3061 const statement_t
*stmt
;
3062 /* check for duplicates */
3063 if
(is_attr
(iface
->attrs
, ATTR_DISPINTERFACE
))
3065 var_list_t
*methods
= type_dispiface_get_methods
(iface
);
3066 var_t
*func
, *func_iter
;
3068 if
(methods
) LIST_FOR_EACH_ENTRY
( func
, methods
, var_t
, entry
)
3070 LIST_FOR_EACH_ENTRY
( func_iter
, methods
, var_t
, entry
)
3072 if
(func
== func_iter
) break
;
3073 if
(strcmp
(func
->name
, func_iter
->name
)) continue
;
3074 if
(is_attr
(func
->attrs
, ATTR_EVENTADD
) != is_attr
(func_iter
->attrs
, ATTR_EVENTADD
)) continue
;
3075 if
(is_attr
(func
->attrs
, ATTR_EVENTREMOVE
) != is_attr
(func_iter
->attrs
, ATTR_EVENTREMOVE
)) continue
;
3076 if
(is_attr
(func
->attrs
, ATTR_PROPGET
) != is_attr
(func_iter
->attrs
, ATTR_PROPGET
)) continue
;
3077 if
(is_attr
(func
->attrs
, ATTR_PROPPUT
) != is_attr
(func_iter
->attrs
, ATTR_PROPPUT
)) continue
;
3078 if
(is_attr
(func
->attrs
, ATTR_PROPPUTREF
) != is_attr
(func_iter
->attrs
, ATTR_PROPPUTREF
)) continue
;
3079 error_at
( &func
->where
, "duplicated function \'%s\'\n", func
->name
);
3083 if
(is_attr
(iface
->attrs
, ATTR_EXPLICIT_HANDLE
))
3085 STATEMENTS_FOR_EACH_FUNC
( stmt
, type_iface_get_stmts
(iface
) )
3087 var_t
*func
= stmt
->u.var
;
3088 add_explicit_handle_if_necessary
(iface
, func
);
3091 if
(!is_inside_library
&& !is_attr
(iface
->attrs
, ATTR_LOCAL
))
3093 STATEMENTS_FOR_EACH_FUNC
( stmt
, type_iface_get_stmts
(iface
) )
3095 const var_t
*func
= stmt
->u.var
;
3096 if
(!is_attr
(func
->attrs
, ATTR_LOCAL
))
3097 check_remoting_args
(func
);
3102 static int async_iface_attrs
(attr_list_t
*attrs
, const attr_t
*attr
)
3108 case ATTR_ASYNCUUID
:
3109 append_attr
(attrs
, make_attrp
(ATTR_UUID
, attr
->u.pval
));
3116 static int arg_in_attrs
(attr_list_t
*attrs
, const attr_t
*attr
)
3118 return attr
->type
!= ATTR_OUT
&& attr
->type
!= ATTR_RETVAL
;
3121 static int arg_out_attrs
(attr_list_t
*attrs
, const attr_t
*attr
)
3123 return attr
->type
!= ATTR_IN
;
3126 static void check_async_uuid
(type_t
*iface
)
3128 statement_list_t
*stmts
= NULL
;
3130 type_t
*async_iface
;
3133 if
(!is_attr
(iface
->attrs
, ATTR_ASYNCUUID
)) return
;
3135 inherit
= type_iface_get_inherit
(iface
);
3136 if
(inherit
&& strcmp
(inherit
->name
, "IUnknown"))
3137 inherit
= type_iface_get_async_iface
(inherit
);
3139 error_loc
("async_uuid applied to an interface with incompatible parent\n");
3141 async_iface
= type_interface_declare
(strmake
("Async%s", iface
->name
), iface
->namespace
);
3143 STATEMENTS_FOR_EACH_FUNC
( stmt
, type_iface_get_stmts
(iface
) )
3145 var_t
*begin_func
, *finish_func
, *func
= stmt
->u.var
, *arg
;
3146 var_list_t
*begin_args
= NULL
, *finish_args
= NULL
, *args
;
3148 if
(is_attr
(func
->attrs
, ATTR_CALLAS
)) continue
;
3150 args
= type_function_get_args
(func
->declspec.type
);
3151 if
(args
) LIST_FOR_EACH_ENTRY
(arg
, args
, var_t
, entry
)
3153 if
(is_attr
(arg
->attrs
, ATTR_IN
) ||
!is_attr
(arg
->attrs
, ATTR_OUT
))
3154 begin_args
= append_var
(begin_args
, copy_var
(arg
, xstrdup
(arg
->name
), arg_in_attrs
));
3155 if
(is_attr
(arg
->attrs
, ATTR_OUT
))
3156 finish_args
= append_var
(finish_args
, copy_var
(arg
, xstrdup
(arg
->name
), arg_out_attrs
));
3159 begin_func
= copy_var
(func
, strmake
("Begin_%s", func
->name
), NULL
);
3160 begin_func
->declspec.type
= type_new_function
(begin_args
);
3161 begin_func
->declspec.type
->attrs
= func
->attrs
;
3162 begin_func
->declspec.type
->details.function
->retval
= func
->declspec.type
->details.function
->retval
;
3163 stmts
= append_statement
(stmts
, make_statement_declaration
(begin_func
));
3165 finish_func
= copy_var
(func
, strmake
("Finish_%s", func
->name
), NULL
);
3166 finish_func
->declspec.type
= type_new_function
(finish_args
);
3167 finish_func
->declspec.type
->attrs
= func
->attrs
;
3168 finish_func
->declspec.type
->details.function
->retval
= func
->declspec.type
->details.function
->retval
;
3169 stmts
= append_statement
(stmts
, make_statement_declaration
(finish_func
));
3172 type_interface_define
(async_iface
, map_attrs
(iface
->attrs
, async_iface_attrs
), inherit
, stmts
, NULL
);
3173 iface
->details.iface
->async_iface
= async_iface
->details.iface
->async_iface
= async_iface
;
3176 static statement_list_t
*append_parameterized_type_stmts
(statement_list_t
*stmts
)
3178 statement_t
*stmt
, *next
;
3180 if
(stmts
&& parameterized_type_stmts
) LIST_FOR_EACH_ENTRY_SAFE
(stmt
, next
, parameterized_type_stmts
, statement_t
, entry
)
3185 stmt
->u.type
= type_parameterized_type_specialize_define
(stmt
->u.type
);
3186 stmt
->declonly
= FALSE
;
3187 list_remove
(&stmt
->entry
);
3188 stmts
= append_statement
(stmts
, stmt
);
3191 assert
(0); /* should not be there */
3199 static void check_statements
(const statement_list_t
*stmts
, int is_inside_library
)
3201 const statement_t
*stmt
;
3203 if
(stmts
) LIST_FOR_EACH_ENTRY
(stmt
, stmts
, const statement_t
, entry
)
3205 switch
(stmt
->type
) {
3207 check_statements
(stmt
->u.lib
->stmts
, TRUE
);
3210 switch
(type_get_type
(stmt
->u.type
)) {
3211 case TYPE_INTERFACE
:
3212 check_functions
(stmt
->u.type
, is_inside_library
);
3216 error_loc
("coclass is not allowed in Windows Runtime mode\n");
3228 static void check_all_user_types
(const statement_list_t
*stmts
)
3230 const statement_t
*stmt
;
3233 if
(stmts
) LIST_FOR_EACH_ENTRY
(stmt
, stmts
, const statement_t
, entry
)
3235 if
(stmt
->type
== STMT_LIBRARY
)
3236 check_all_user_types
(stmt
->u.lib
->stmts
);
3237 else if
(stmt
->type
== STMT_TYPE
&& type_get_type
(stmt
->u.type
) == TYPE_INTERFACE
&&
3238 !is_local
(stmt
->u.type
->attrs
))
3240 const statement_t
*stmt_func
;
3241 STATEMENTS_FOR_EACH_FUNC
(stmt_func
, type_iface_get_stmts
(stmt
->u.type
)) {
3242 const var_t
*func
= stmt_func
->u.var
;
3243 if
(type_function_get_args
(func
->declspec.type
))
3244 LIST_FOR_EACH_ENTRY
( v
, type_function_get_args
(func
->declspec.type
), const var_t
, entry
)
3245 check_for_additional_prototype_types
(v
->declspec.type
);
3246 check_for_additional_prototype_types
(type_function_get_rettype
(func
->declspec.type
));
3252 static statement_t
*make_statement
(enum statement_type type
)
3254 statement_t
*stmt
= xmalloc
(sizeof
(*stmt
));
3259 static statement_t
*make_statement_type_decl
(type_t
*type
)
3261 statement_t
*stmt
= make_statement
(STMT_TYPE
);
3262 stmt
->u.type
= type
;
3263 stmt
->declonly
= !type
->defined
;
3267 static statement_t
*make_statement_reference
(type_t
*type
)
3269 statement_t
*stmt
= make_statement
(STMT_TYPEREF
);
3270 stmt
->u.type
= type
;
3274 static statement_t
*make_statement_declaration
(var_t
*var
)
3276 statement_t
*stmt
= make_statement
(STMT_DECLARATION
);
3278 if
(var
->declspec.stgclass
== STG_EXTERN
&& var
->eval
)
3279 warning
("'%s' initialised and declared extern\n", var
->name
);
3280 if
(is_const_decl
(var
))
3285 else if
(type_get_type
(var
->declspec.type
) == TYPE_FUNCTION
)
3286 check_function_attrs
(var
->name
, var
->attrs
);
3287 else if
(var
->declspec.stgclass
== STG_NONE || var
->declspec.stgclass
== STG_REGISTER
)
3288 error_loc
("instantiation of data is illegal\n");
3292 static statement_t
*make_statement_library
(typelib_t
*typelib
)
3294 statement_t
*stmt
= make_statement
(STMT_LIBRARY
);
3295 stmt
->u.lib
= typelib
;
3299 static statement_t
*make_statement_pragma
(const char *str
)
3301 statement_t
*stmt
= make_statement
(STMT_PRAGMA
);
3306 static statement_t
*make_statement_cppquote
(const char *str
)
3308 statement_t
*stmt
= make_statement
(STMT_CPPQUOTE
);
3313 static statement_t
*make_statement_importlib
(const char *str
)
3315 statement_t
*stmt
= make_statement
(STMT_IMPORTLIB
);
3320 static statement_t
*make_statement_import
(const char *str
)
3322 statement_t
*stmt
= make_statement
(STMT_IMPORT
);
3327 static statement_t
*make_statement_module
(type_t
*type
)
3329 statement_t
*stmt
= make_statement
(STMT_MODULE
);
3330 stmt
->u.type
= type
;
3334 static statement_t
*make_statement_typedef
(declarator_list_t
*decls
, int declonly
)
3336 declarator_t
*decl
, *next
;
3339 if
(!decls
) return NULL
;
3341 stmt
= make_statement
(STMT_TYPEDEF
);
3342 stmt
->u.type_list
= NULL
;
3343 stmt
->declonly
= declonly
;
3345 LIST_FOR_EACH_ENTRY_SAFE
( decl
, next
, decls
, declarator_t
, entry
)
3347 var_t
*var
= decl
->var
;
3348 type_t
*type
= find_type_or_error
(current_namespace
, var
->name
);
3349 stmt
->u.type_list
= append_typeref
(stmt
->u.type_list
, make_typeref
(type
));
3357 static statement_t
*make_statement_parameterized_type
(type_t
*type
, typeref_list_t
*params
)
3359 statement_t
*stmt
= make_statement
(STMT_TYPE
);
3360 stmt
->u.type
= type_parameterized_type_specialize_partial
(type
, params
);
3364 static statement_t
*make_statement_delegate
(type_t
*ret
, var_list_t
*args
)
3366 declarator_t
*decl
= make_declarator
(make_var
(xstrdup
("Invoke")));
3367 decl_spec_t
*spec
= make_decl_spec
(ret
, NULL
, NULL
, STG_NONE
, 0, 0);
3368 append_chain_type
(decl
, type_new_function
(args
), 0);
3369 return make_statement_declaration
(declare_var
(NULL
, spec
, decl
, FALSE
));
3372 static statement_list_t
*append_statements
(statement_list_t
*l1
, statement_list_t
*l2
)
3375 if
(!l1 || l1
== l2
) return l2
;
3376 list_move_tail
(l1
, l2
);
3380 static attr_list_t
*append_attribs
(attr_list_t
*l1
, attr_list_t
*l2
)
3383 if
(!l1 || l1
== l2
) return l2
;
3384 list_move_tail
(l1
, l2
);
3388 static statement_list_t
*append_statement
(statement_list_t
*list
, statement_t
*stmt
)
3390 if
(!stmt
) return list
;
3393 list
= xmalloc
( sizeof
(*list
) );
3396 list_add_tail
( list
, &stmt
->entry
);
3400 type_t
*find_parameterized_type
(type_t
*type
, typeref_list_t
*params
)
3402 char *name
= format_parameterized_type_name
(type
, params
);
3404 if
(parameters_namespace
)
3406 assert
(type
->type_type
== TYPE_PARAMETERIZED_TYPE
);
3407 type
= type_parameterized_type_specialize_partial
(type
, params
);
3409 else if
((type
= find_type
(name
, type
->namespace
, 0)))
3410 assert
(type
->type_type
!= TYPE_PARAMETERIZED_TYPE
);
3412 error_loc
("parameterized type '%s' not declared\n", name
);