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 type_list_t
*append_type
(type_list_t
*list
, type_t
*type
);
49 static attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
);
50 static attr_list_t
*append_attr_list
(attr_list_t
*new_list
, attr_list_t
*old_list
);
51 static decl_spec_t
*make_decl_spec
(type_t
*type
, decl_spec_t
*left
, decl_spec_t
*right
,
52 enum storage_class stgclass
, enum type_qualifier qual
, enum function_specifier func_specifier
);
53 static attr_t
*make_attr
(enum attr_type type
);
54 static attr_t
*make_attrv
(enum attr_type type
, unsigned int val
);
55 static attr_t
*make_attrp
(enum attr_type type
, void *val
);
56 static attr_t
*make_custom_attr
(UUID
*id
, expr_t
*pval
);
57 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
);
58 static var_t
*declare_var
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_t
*decl
, int top
);
59 static var_list_t
*set_var_types
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_list_t
*decls
);
60 static ifref_list_t
*append_ifref
(ifref_list_t
*list
, ifref_t
*iface
);
61 static ifref_t
*make_ifref
(type_t
*iface
);
62 static var_list_t
*append_var_list
(var_list_t
*list
, var_list_t
*vars
);
63 static declarator_list_t
*append_declarator
(declarator_list_t
*list
, declarator_t
*p
);
64 static declarator_t
*make_declarator
(var_t
*var
);
65 static type_t
*make_safearray
(type_t
*type
);
66 static typelib_t
*make_library
(const char *name
, const attr_list_t
*attrs
);
67 static void append_array
(declarator_t
*decl
, expr_t
*expr
);
68 static void append_chain_type
(declarator_t
*decl
, type_t
*type
, enum type_qualifier qual
);
69 static void append_chain_callconv
(type_t
*chain
, char *callconv
);
70 static warning_list_t
*append_warning
(warning_list_t
*, int);
72 static type_t
*reg_typedefs
(decl_spec_t
*decl_spec
, var_list_t
*names
, attr_list_t
*attrs
);
73 static type_t
*find_type_or_error
(struct namespace
*parent
, const char *name
);
74 static struct namespace
*find_namespace_or_error
(struct namespace
*namespace
, const char *name
);
76 static var_t
*reg_const
(var_t
*var
);
78 static void push_namespace
(const char *name
);
79 static void pop_namespace
(const char *name
);
80 static void push_parameters_namespace
(const char *name
);
81 static void pop_parameters_namespace
(const char *name
);
83 static void check_arg_attrs
(const var_t
*arg
);
84 static void check_statements
(const statement_list_t
*stmts
, int is_inside_library
);
85 static void check_all_user_types
(const statement_list_t
*stmts
);
86 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
);
87 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
);
88 static attr_list_t
*check_enum_attrs
(attr_list_t
*attrs
);
89 static attr_list_t
*check_enum_member_attrs
(attr_list_t
*attrs
);
90 static attr_list_t
*check_struct_attrs
(attr_list_t
*attrs
);
91 static attr_list_t
*check_union_attrs
(attr_list_t
*attrs
);
92 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
);
93 static attr_list_t
*check_library_attrs
(const char *name
, attr_list_t
*attrs
);
94 const char *get_attr_display_name
(enum attr_type type
);
95 static void add_explicit_handle_if_necessary
(const type_t
*iface
, var_t
*func
);
97 static void check_async_uuid
(type_t
*iface
);
99 static statement_t
*make_statement
(enum statement_type type
);
100 static statement_t
*make_statement_type_decl
(type_t
*type
);
101 static statement_t
*make_statement_reference
(type_t
*type
);
102 static statement_t
*make_statement_declaration
(var_t
*var
);
103 static statement_t
*make_statement_library
(typelib_t
*typelib
);
104 static statement_t
*make_statement_pragma
(const char *str
);
105 static statement_t
*make_statement_cppquote
(const char *str
);
106 static statement_t
*make_statement_importlib
(const char *str
);
107 static statement_t
*make_statement_module
(type_t
*type
);
108 static statement_t
*make_statement_typedef
(var_list_t
*names
, int declonly
);
109 static statement_t
*make_statement_import
(const char *str
);
110 static statement_list_t
*append_statement
(statement_list_t
*list
, statement_t
*stmt
);
111 static statement_list_t
*append_statements
(statement_list_t
*, statement_list_t
*);
112 static attr_list_t
*append_attribs
(attr_list_t
*, attr_list_t
*);
114 static struct namespace global_namespace
= {
115 NULL
, NULL
, LIST_INIT
(global_namespace.entry
), LIST_INIT
(global_namespace.children
)
118 static struct namespace
*current_namespace
= &global_namespace
;
119 static struct namespace
*parameters_namespace
= NULL
;
121 static typelib_t
*current_typelib
;
126 attr_list_t
*attr_list
;
127 str_list_t
*str_list
;
129 expr_list_t
*expr_list
;
131 type_list_t
*type_list
;
133 var_list_t
*var_list
;
134 declarator_t
*declarator
;
135 declarator_list_t
*declarator_list
;
136 statement_t
*statement
;
137 statement_list_t
*stmt_list
;
139 warning_list_t
*warning_list
;
141 ifref_list_t
*ifref_list
;
147 struct _import_t
*import
;
148 struct _decl_spec_t
*declspec
;
149 enum storage_class stgclass
;
150 enum type_qualifier type_qualifier
;
151 enum function_specifier function_specifier
;
152 struct namespace
*namespace
;
155 %token
<str
> aIDENTIFIER aPRAGMA
156 %token
<str
> aKNOWNTYPE
157 %token
<num
> aNUM aHEXNUM
159 %token
<str
> aSTRING aWSTRING aSQSTRING
164 %token EQUALITY INEQUALITY
165 %token GREATEREQUAL LESSEQUAL
166 %token LOGICALOR LOGICALAND
171 %token tALLNODES tALLOCATE tANNOTATION
173 %token tAPPOBJECT tASYNC tASYNCUUID
174 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
175 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
176 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
177 %token tCONTEXTHANDLESERIALIZE
179 %token tCONTRACTVERSION
180 %token tCONTROL tCPPQUOTE
182 %token tDECODE tDEFAULT tDEFAULTBIND
183 %token tDEFAULTCOLLELEM
185 %token tDEFAULTVTABLE
186 %token tDISABLECONSISTENCYCHECK tDISPLAYBIND
187 %token tDISPINTERFACE
188 %token tDLLNAME tDONTFREE tDOUBLE tDUAL
189 %token tENABLEALLOCATE tENCODE tENDPOINT
190 %token tENTRY tENUM tERRORSTATUST
191 %token tEVENTADD tEVENTREMOVE
193 %token tEXPLICITHANDLE tEXTERN
195 %token tFASTCALL tFAULTSTATUS
197 %token tFLOAT tFORCEALLOCATE
200 %token tHELPCONTEXT tHELPFILE
201 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
203 %token tHYPER tID tIDEMPOTENT
204 %token tIGNORE tIIDIS
205 %token tIMMEDIATEBIND
206 %token tIMPLICITHANDLE
207 %token tIMPORT tIMPORTLIB
208 %token tIN tIN_LINE tINLINE
210 %token tINT tINT32 tINT3264 tINT64
213 %token tLENGTHIS tLIBRARY
214 %token tLICENSED tLOCAL
216 %token tMARSHALINGBEHAVIOR
217 %token tMAYBE tMESSAGE
222 %token tNOCODE tNONBROWSABLE
225 %token tNONEXTENSIBLE
226 %token tNOTIFY tNOTIFYFLAG
228 %token tOBJECT tODL tOLEAUTOMATION
229 %token tOPTIMIZE tOPTIONAL
231 %token tPARTIALIGNORE tPASCAL
232 %token tPOINTERDEFAULT
233 %token tPRAGMA_WARNING
234 %token tPROGID tPROPERTIES
235 %token tPROPGET tPROPPUT tPROPPUTREF
239 %token tREADONLY tREF
240 %token tREGISTER tREPRESENTAS
248 %token tSIGNED tSINGLENODE
249 %token tSIZEIS tSIZEOF
255 %token tSTRICTCONTEXTHANDLE
256 %token tSTRING tSTRUCT
257 %token tSWITCH tSWITCHIS tSWITCHTYPE
258 %token tTHREADING tTRANSMITAS
261 %token tUIDEFAULT tUNION
264 %token tUSESGETLASTERROR tUSERMARSHAL tUUID
267 %token tVERSION tVIPROGID
269 %token tWCHAR tWIREMARSHAL
270 %token tAPARTMENT tNEUTRAL tSINGLE tFREE tBOTH
272 %type
<attr
> attribute acf_attribute
273 %type
<attr_list
> m_attributes attributes attrib_list
274 %type
<attr_list
> acf_attributes acf_attribute_list
275 %type
<attr_list
> dispattributes
276 %type
<str_list
> str_list
277 %type
<expr
> m_expr expr expr_const expr_int_const array m_bitfield
278 %type
<expr_list
> m_exprs
/* exprs expr_list */ expr_list_int_const
279 %type
<expr
> contract_req
280 %type
<expr
> static_attr
281 %type
<stgclass
> storage_cls_spec
282 %type
<type_qualifier
> type_qualifier m_type_qual_list
283 %type
<function_specifier
> function_specifier
284 %type
<declspec
> decl_spec unqualified_decl_spec decl_spec_no_type m_decl_spec_no_type
285 %type
<type
> inherit interface interfacedef
286 %type
<type
> interfaceref
287 %type
<type
> dispinterfaceref
288 %type
<type
> dispinterface dispinterfacedef
289 %type
<type
> module moduledef
290 %type
<str
> namespacedef
291 %type
<type
> base_type int_std
292 %type
<type
> enumdef structdef uniondef typedecl
293 %type
<type
> type unqualified_type qualified_type
294 %type
<type
> type_parameter
295 %type
<type_list
> type_parameters
296 %type
<ifref
> class_interface
297 %type
<ifref_list
> class_interfaces
298 %type
<ifref_list
> requires required_types
299 %type
<var
> arg ne_union_field union_field s_field case
enum enum_member declaration
301 %type
<var_list
> m_args arg_list args dispint_meths
302 %type
<var_list
> fields ne_union_fields cases enums enum_list dispint_props field
303 %type
<var
> m_ident ident
304 %type
<declarator
> declarator direct_declarator init_declarator struct_declarator
305 %type
<declarator
> m_any_declarator any_declarator any_declarator_no_direct any_direct_declarator
306 %type
<declarator
> m_abstract_declarator abstract_declarator abstract_declarator_no_direct abstract_direct_declarator
307 %type
<declarator_list
> declarator_list struct_declarator_list
308 %type
<type
> coclass coclassdef
309 %type
<type
> runtimeclass runtimeclass_def
310 %type
<type
> apicontract apicontract_def
311 %type
<num
> contract_ver
312 %type
<num
> pointer_type threading_type marshaling_behavior version
313 %type
<str
> libraryhdr callconv cppquote importlib import
314 %type
<str
> typename m_typename
315 %type
<uuid
> uuid_string
316 %type
<import
> import_start
317 %type
<typelib
> library_start librarydef
318 %type
<statement
> statement typedef pragma_warning
319 %type
<stmt_list
> gbl_statements imp_statements int_statements
320 %type
<warning_list
> warnings
321 %type
<num
> allocate_option_list allocate_option
322 %type
<namespace
> namespace_pfx
331 %left EQUALITY INEQUALITY
332 %left
'<' '>' LESSEQUAL GREATEREQUAL
336 %right
'!' '~' CAST PPTR POS NEG ADDRESSOF tSIZEOF
337 %left
'.' MEMBERPTR
'[' ']'
339 %define parse.
error verbose
343 input: gbl_statements m_acf
{ check_statements
($1, FALSE
);
344 check_all_user_types
($1);
351 write_typelib_regscript
($1);
353 write_local_stubs
($1);
357 m_acf: /* empty */ | aACF acf_statements
359 gbl_statements: { $$
= NULL
; }
360 | gbl_statements namespacedef
'{' { push_namespace
($2); } gbl_statements
'}'
361 { pop_namespace
($2); $$
= append_statements
($1, $5); }
362 | gbl_statements interface
';' { $$
= append_statement
($1, make_statement_reference
($2)); }
363 | gbl_statements dispinterface
';' { $$
= append_statement
($1, make_statement_reference
($2)); }
364 | gbl_statements interfacedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); }
365 | gbl_statements coclass
';' { $$
= $1;
366 reg_type
($2, $2->name
, current_namespace
, 0);
368 | gbl_statements coclassdef
{ $$
= append_statement
($1, make_statement_type_decl
($2));
369 reg_type
($2, $2->name
, current_namespace
, 0);
371 | gbl_statements apicontract
';' { $$
= $1; reg_type
($2, $2->name
, current_namespace
, 0); }
372 | gbl_statements apicontract_def
{ $$
= append_statement
($1, make_statement_type_decl
($2));
373 reg_type
($2, $2->name
, current_namespace
, 0); }
374 | gbl_statements runtimeclass
';' { $$
= $1; reg_type
($2, $2->name
, current_namespace
, 0); }
375 | gbl_statements runtimeclass_def
{ $$
= append_statement
($1, make_statement_type_decl
($2));
376 reg_type
($2, $2->name
, current_namespace
, 0); }
377 | gbl_statements moduledef
{ $$
= append_statement
($1, make_statement_module
($2)); }
378 | gbl_statements librarydef
{ $$
= append_statement
($1, make_statement_library
($2)); }
379 | gbl_statements statement
{ $$
= append_statement
($1, $2); }
382 imp_statements: { $$
= NULL
; }
383 | imp_statements interface
';' { $$
= append_statement
($1, make_statement_reference
($2)); }
384 | imp_statements dispinterface
';' { $$
= append_statement
($1, make_statement_reference
($2)); }
385 | imp_statements namespacedef
'{' { push_namespace
($2); } imp_statements
'}'
386 { pop_namespace
($2); $$
= append_statements
($1, $5); }
387 | imp_statements interfacedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); }
388 | imp_statements coclass
';' { $$
= $1; reg_type
($2, $2->name
, current_namespace
, 0); }
389 | imp_statements coclassdef
{ $$
= append_statement
($1, make_statement_type_decl
($2));
390 reg_type
($2, $2->name
, current_namespace
, 0);
392 | imp_statements apicontract
';' { $$
= $1; reg_type
($2, $2->name
, current_namespace
, 0); }
393 | imp_statements apicontract_def
{ $$
= append_statement
($1, make_statement_type_decl
($2));
394 reg_type
($2, $2->name
, current_namespace
, 0); }
395 | imp_statements runtimeclass
';' { $$
= $1; reg_type
($2, $2->name
, current_namespace
, 0); }
396 | imp_statements runtimeclass_def
{ $$
= append_statement
($1, make_statement_type_decl
($2));
397 reg_type
($2, $2->name
, current_namespace
, 0); }
398 | imp_statements moduledef
{ $$
= append_statement
($1, make_statement_module
($2)); }
399 | imp_statements statement
{ $$
= append_statement
($1, $2); }
400 | imp_statements importlib
{ $$
= append_statement
($1, make_statement_importlib
($2)); }
401 | imp_statements librarydef
{ $$
= append_statement
($1, make_statement_library
($2)); }
404 int_statements: { $$
= NULL
; }
405 | int_statements statement
{ $$
= append_statement
($1, $2); }
413 cppquote
{ $$
= make_statement_cppquote
($1); }
414 | typedecl
';' { $$
= make_statement_type_decl
($1); }
415 | declaration
';' { $$
= make_statement_declaration
($1); }
416 | import
{ $$
= make_statement_import
($1); }
417 | typedef
';' { $$
= $1; }
418 | aPRAGMA
{ $$
= make_statement_pragma
($1); }
419 | pragma_warning
{ $$
= NULL
; }
422 pragma_warning: tPRAGMA_WARNING
'(' aIDENTIFIER
':' warnings
')'
426 result
= do_warning
($3, $5);
428 error_loc
("expected \"disable\", \"enable\" or \"default\"\n");
430 | tPRAGMA_WARNING
'(' tDEFAULT
':' warnings
')'
433 do_warning
("default", $5);
438 aNUM
{ $$
= append_warning
(NULL
, $1); }
439 | warnings aNUM
{ $$
= append_warning
($1, $2); }
444 | tENUM aIDENTIFIER
{ $$
= type_new_enum
($2, current_namespace
, FALSE
, NULL
); }
446 | tSTRUCT aIDENTIFIER
{ $$
= type_new_struct
($2, current_namespace
, FALSE
, NULL
); }
448 | tUNION aIDENTIFIER
{ $$
= type_new_nonencapsulated_union
($2, FALSE
, NULL
); }
449 | attributes enumdef
{ $$
= $2; $$
->attrs
= check_enum_attrs
($1); }
450 | attributes structdef
{ $$
= $2; $$
->attrs
= check_struct_attrs
($1); }
451 | attributes uniondef
{ $$
= $2; $$
->attrs
= check_union_attrs
($1); }
454 cppquote: tCPPQUOTE
'(' aSTRING
')' { $$
= $3; }
456 import_start: tIMPORT aSTRING
';' { assert
(yychar == YYEMPTY
);
457 $$
= xmalloc
(sizeof
(struct _import_t
));
459 $$
->import_performed
= do_import
($2);
460 if
(!$$
->import_performed
) yychar = aEOF
;
464 import: import_start imp_statements aEOF
{ $$
= $1->name
;
465 if
($1->import_performed
) pop_import
();
470 importlib: tIMPORTLIB
'(' aSTRING
')'
471 semicolon_opt
{ $$
= $3; if
(!parse_only
) add_importlib
($3, current_typelib
); }
474 libraryhdr: tLIBRARY typename
{ $$
= $2; }
476 library_start: attributes libraryhdr
'{' { $$
= make_library
($2, check_library_attrs
($2, $1));
477 if
(!parse_only
&& do_typelib
) current_typelib
= $$
;
480 librarydef: library_start imp_statements
'}'
481 semicolon_opt
{ $$
= $1; $$
->stmts
= $2; }
484 m_args: { $$
= NULL
; }
488 arg_list: arg
{ check_arg_attrs
($1); $$
= append_var
( NULL
, $1 ); }
489 | arg_list
',' arg
{ check_arg_attrs
($3); $$
= append_var
( $1, $3 ); }
493 | arg_list
',' ELLIPSIS
{ $$
= append_var
( $1, make_var
(strdup
("...")) ); }
496 /* split into two rules to get bison to resolve a tVOID conflict */
497 arg: attributes decl_spec m_any_declarator
{ if
($2->stgclass
!= STG_NONE
&& $2->stgclass
!= STG_REGISTER
)
498 error_loc
("invalid storage class for function parameter\n");
499 $$
= declare_var
($1, $2, $3, TRUE
);
502 | decl_spec m_any_declarator
{ if
($1->stgclass
!= STG_NONE
&& $1->stgclass
!= STG_REGISTER
)
503 error_loc
("invalid storage class for function parameter\n");
504 $$
= declare_var
(NULL
, $1, $2, TRUE
);
509 array: '[' expr
']' { $$
= $2;
510 if
(!$$
->is_const || $$
->cval
<= 0)
511 error_loc
("array dimension is not a positive integer constant\n");
513 |
'[' '*' ']' { $$
= make_expr
(EXPR_VOID
); }
514 |
'[' ']' { $$
= make_expr
(EXPR_VOID
); }
517 m_attributes: { $$
= NULL
; }
522 '[' attrib_list
']' { $$
= $2; }
525 attrib_list: attribute
{ $$
= append_attr
( NULL
, $1 ); }
526 | attrib_list
',' attribute
{ $$
= append_attr
( $1, $3 ); }
527 | attrib_list
']' '[' attribute
{ $$
= append_attr
( $1, $4 ); }
530 str_list: aSTRING
{ $$
= append_str
( NULL
, $1 ); }
531 | str_list
',' aSTRING
{ $$
= append_str
( $1, $3 ); }
535 tAGILE
{ $$
= MARSHALING_AGILE
; }
536 | tNONE
{ $$
= MARSHALING_NONE
; }
537 | tSTANDARD
{ $$
= MARSHALING_STANDARD
; }
541 aNUM
{ $$
= MAKEVERSION
(0, $1); }
542 | aNUM
'.' aNUM
{ $$
= MAKEVERSION
($3, $1); }
545 contract_req: decl_spec
',' contract_ver
{ if
($1->type
->type_type
!= TYPE_APICONTRACT
)
546 error_loc
("type %s is not an apicontract\n", $1->type
->name
);
547 $$
= make_exprl
(EXPR_NUM
, $3);
548 $$
= make_exprt
(EXPR_GTREQL
, declare_var
(NULL
, $1, make_declarator
(NULL
), 0), $$
);
551 static_attr: decl_spec
',' contract_req
{ if
($1->type
->type_type
!= TYPE_INTERFACE
)
552 error_loc
("type %s is not an interface\n", $1->type
->name
);
553 $$
= make_exprt
(EXPR_MEMBER
, declare_var
(NULL
, $1, make_declarator
(NULL
), 0), $3);
556 attribute: { $$
= NULL
; }
557 | tACTIVATABLE
'(' contract_req
')' { $$
= make_attrp
(ATTR_ACTIVATABLE
, $3); }
558 | tAGGREGATABLE
{ $$
= make_attr
(ATTR_AGGREGATABLE
); }
559 | tANNOTATION
'(' aSTRING
')' { $$
= make_attrp
(ATTR_ANNOTATION
, $3); }
560 | tAPPOBJECT
{ $$
= make_attr
(ATTR_APPOBJECT
); }
561 | tASYNC
{ $$
= make_attr
(ATTR_ASYNC
); }
562 | tAUTOHANDLE
{ $$
= make_attr
(ATTR_AUTO_HANDLE
); }
563 | tBINDABLE
{ $$
= make_attr
(ATTR_BINDABLE
); }
564 | tBROADCAST
{ $$
= make_attr
(ATTR_BROADCAST
); }
565 | tCALLAS
'(' ident
')' { $$
= make_attrp
(ATTR_CALLAS
, $3); }
566 | tCASE
'(' expr_list_int_const
')' { $$
= make_attrp
(ATTR_CASE
, $3); }
567 | tCODE
{ $$
= make_attr
(ATTR_CODE
); }
568 | tCOMMSTATUS
{ $$
= make_attr
(ATTR_COMMSTATUS
); }
569 | tCONTEXTHANDLE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); }
570 | tCONTEXTHANDLENOSERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
571 | tCONTEXTHANDLESERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
572 | tCONTRACT
'(' contract_req
')' { $$
= make_attrp
(ATTR_CONTRACT
, $3); }
573 | tCONTRACTVERSION
'(' contract_ver
')' { $$
= make_attrv
(ATTR_CONTRACTVERSION
, $3); }
574 | tCONTROL
{ $$
= make_attr
(ATTR_CONTROL
); }
575 | tCUSTOM
'(' uuid_string
',' expr_const
')' { $$
= make_custom_attr
($3, $5); }
576 | tDECODE
{ $$
= make_attr
(ATTR_DECODE
); }
577 | tDEFAULT
{ $$
= make_attr
(ATTR_DEFAULT
); }
578 | tDEFAULTBIND
{ $$
= make_attr
(ATTR_DEFAULTBIND
); }
579 | tDEFAULTCOLLELEM
{ $$
= make_attr
(ATTR_DEFAULTCOLLELEM
); }
580 | tDEFAULTVALUE
'(' expr_const
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE
, $3); }
581 | tDEFAULTVTABLE
{ $$
= make_attr
(ATTR_DEFAULTVTABLE
); }
582 | tDISABLECONSISTENCYCHECK
{ $$
= make_attr
(ATTR_DISABLECONSISTENCYCHECK
); }
583 | tDISPLAYBIND
{ $$
= make_attr
(ATTR_DISPLAYBIND
); }
584 | tDLLNAME
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DLLNAME
, $3); }
585 | tDUAL
{ $$
= make_attr
(ATTR_DUAL
); }
586 | tENABLEALLOCATE
{ $$
= make_attr
(ATTR_ENABLEALLOCATE
); }
587 | tENCODE
{ $$
= make_attr
(ATTR_ENCODE
); }
588 | tENDPOINT
'(' str_list
')' { $$
= make_attrp
(ATTR_ENDPOINT
, $3); }
589 | tENTRY
'(' expr_const
')' { $$
= make_attrp
(ATTR_ENTRY
, $3); }
590 | tEVENTADD
{ $$
= make_attr
(ATTR_EVENTADD
); }
591 | tEVENTREMOVE
{ $$
= make_attr
(ATTR_EVENTREMOVE
); }
592 | tEXCLUSIVETO
'(' decl_spec
')' { if
($3->type
->type_type
!= TYPE_RUNTIMECLASS
)
593 error_loc
("type %s is not a runtimeclass\n", $3->type
->name
);
594 $$
= make_attrp
(ATTR_EXCLUSIVETO
, $3->type
); }
595 | tEXPLICITHANDLE
{ $$
= make_attr
(ATTR_EXPLICIT_HANDLE
); }
596 | tFAULTSTATUS
{ $$
= make_attr
(ATTR_FAULTSTATUS
); }
597 | tFLAGS
{ $$
= make_attr
(ATTR_FLAGS
); }
598 | tFORCEALLOCATE
{ $$
= make_attr
(ATTR_FORCEALLOCATE
); }
599 | tHANDLE
{ $$
= make_attr
(ATTR_HANDLE
); }
600 | tHELPCONTEXT
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_HELPCONTEXT
, $3); }
601 | tHELPFILE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPFILE
, $3); }
602 | tHELPSTRING
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRING
, $3); }
603 | tHELPSTRINGCONTEXT
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_HELPSTRINGCONTEXT
, $3); }
604 | tHELPSTRINGDLL
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRINGDLL
, $3); }
605 | tHIDDEN
{ $$
= make_attr
(ATTR_HIDDEN
); }
606 | tID
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_ID
, $3); }
607 | tIDEMPOTENT
{ $$
= make_attr
(ATTR_IDEMPOTENT
); }
608 | tIGNORE
{ $$
= make_attr
(ATTR_IGNORE
); }
609 | tIIDIS
'(' expr
')' { $$
= make_attrp
(ATTR_IIDIS
, $3); }
610 | tIMMEDIATEBIND
{ $$
= make_attr
(ATTR_IMMEDIATEBIND
); }
611 | tIMPLICITHANDLE
'(' arg
')' { $$
= make_attrp
(ATTR_IMPLICIT_HANDLE
, $3); }
612 | tIN
{ $$
= make_attr
(ATTR_IN
); }
613 | tINPUTSYNC
{ $$
= make_attr
(ATTR_INPUTSYNC
); }
614 | tLENGTHIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_LENGTHIS
, $3); }
615 | tLCID
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_LIBLCID
, $3); }
616 | tLCID
{ $$
= make_attr
(ATTR_PARAMLCID
); }
617 | tLICENSED
{ $$
= make_attr
(ATTR_LICENSED
); }
618 | tLOCAL
{ $$
= make_attr
(ATTR_LOCAL
); }
619 | tMARSHALINGBEHAVIOR
'(' marshaling_behavior
')'
620 { $$
= make_attrv
(ATTR_MARSHALING_BEHAVIOR
, $3); }
621 | tMAYBE
{ $$
= make_attr
(ATTR_MAYBE
); }
622 | tMESSAGE
{ $$
= make_attr
(ATTR_MESSAGE
); }
623 | tNOCODE
{ $$
= make_attr
(ATTR_NOCODE
); }
624 | tNONBROWSABLE
{ $$
= make_attr
(ATTR_NONBROWSABLE
); }
625 | tNONCREATABLE
{ $$
= make_attr
(ATTR_NONCREATABLE
); }
626 | tNONEXTENSIBLE
{ $$
= make_attr
(ATTR_NONEXTENSIBLE
); }
627 | tNOTIFY
{ $$
= make_attr
(ATTR_NOTIFY
); }
628 | tNOTIFYFLAG
{ $$
= make_attr
(ATTR_NOTIFYFLAG
); }
629 | tOBJECT
{ $$
= make_attr
(ATTR_OBJECT
); }
630 | tODL
{ $$
= make_attr
(ATTR_ODL
); }
631 | tOLEAUTOMATION
{ $$
= make_attr
(ATTR_OLEAUTOMATION
); }
632 | tOPTIMIZE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_OPTIMIZE
, $3); }
633 | tOPTIONAL
{ $$
= make_attr
(ATTR_OPTIONAL
); }
634 | tOUT
{ $$
= make_attr
(ATTR_OUT
); }
635 | tPARTIALIGNORE
{ $$
= make_attr
(ATTR_PARTIALIGNORE
); }
636 | tPOINTERDEFAULT
'(' pointer_type
')' { $$
= make_attrv
(ATTR_POINTERDEFAULT
, $3); }
637 | tPROGID
'(' aSTRING
')' { $$
= make_attrp
(ATTR_PROGID
, $3); }
638 | tPROPGET
{ $$
= make_attr
(ATTR_PROPGET
); }
639 | tPROPPUT
{ $$
= make_attr
(ATTR_PROPPUT
); }
640 | tPROPPUTREF
{ $$
= make_attr
(ATTR_PROPPUTREF
); }
641 | tPROXY
{ $$
= make_attr
(ATTR_PROXY
); }
642 | tPUBLIC
{ $$
= make_attr
(ATTR_PUBLIC
); }
643 | tRANGE
'(' expr_int_const
',' expr_int_const
')'
644 { expr_list_t
*list
= append_expr
( NULL
, $3 );
645 list
= append_expr
( list
, $5 );
646 $$
= make_attrp
(ATTR_RANGE
, list
); }
647 | tREADONLY
{ $$
= make_attr
(ATTR_READONLY
); }
648 | tREPRESENTAS
'(' type
')' { $$
= make_attrp
(ATTR_REPRESENTAS
, $3); }
649 | tREQUESTEDIT
{ $$
= make_attr
(ATTR_REQUESTEDIT
); }
650 | tRESTRICTED
{ $$
= make_attr
(ATTR_RESTRICTED
); }
651 | tRETVAL
{ $$
= make_attr
(ATTR_RETVAL
); }
652 | tSIZEIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_SIZEIS
, $3); }
653 | tSOURCE
{ $$
= make_attr
(ATTR_SOURCE
); }
654 | tSTATIC
'(' static_attr
')' { $$
= make_attrp
(ATTR_STATIC
, $3); }
655 | tSTRICTCONTEXTHANDLE
{ $$
= make_attr
(ATTR_STRICTCONTEXTHANDLE
); }
656 | tSTRING
{ $$
= make_attr
(ATTR_STRING
); }
657 | tSWITCHIS
'(' expr
')' { $$
= make_attrp
(ATTR_SWITCHIS
, $3); }
658 | tSWITCHTYPE
'(' type
')' { $$
= make_attrp
(ATTR_SWITCHTYPE
, $3); }
659 | tTRANSMITAS
'(' type
')' { $$
= make_attrp
(ATTR_TRANSMITAS
, $3); }
660 | tTHREADING
'(' threading_type
')' { $$
= make_attrv
(ATTR_THREADING
, $3); }
661 | tUIDEFAULT
{ $$
= make_attr
(ATTR_UIDEFAULT
); }
662 | tUSESGETLASTERROR
{ $$
= make_attr
(ATTR_USESGETLASTERROR
); }
663 | tUSERMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_USERMARSHAL
, $3); }
664 | tUUID
'(' uuid_string
')' { $$
= make_attrp
(ATTR_UUID
, $3); }
665 | tASYNCUUID
'(' uuid_string
')' { $$
= make_attrp
(ATTR_ASYNCUUID
, $3); }
666 | tV1ENUM
{ $$
= make_attr
(ATTR_V1ENUM
); }
667 | tVARARG
{ $$
= make_attr
(ATTR_VARARG
); }
668 | tVERSION
'(' version
')' { $$
= make_attrv
(ATTR_VERSION
, $3); }
669 | tVIPROGID
'(' aSTRING
')' { $$
= make_attrp
(ATTR_VIPROGID
, $3); }
670 | tWIREMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_WIREMARSHAL
, $3); }
671 | pointer_type
{ $$
= make_attrv
(ATTR_POINTERTYPE
, $1); }
676 | aSTRING
{ if
(!is_valid_uuid
($1))
677 error_loc
("invalid UUID: %s\n", $1);
678 $$
= parse_uuid
($1); }
681 callconv: tCDECL
{ $$
= xstrdup
("__cdecl"); }
682 | tFASTCALL
{ $$
= xstrdup
("__fastcall"); }
683 | tPASCAL
{ $$
= xstrdup
("__pascal"); }
684 | tSTDCALL
{ $$
= xstrdup
("__stdcall"); }
687 cases: { $$
= NULL
; }
688 | cases case
{ $$
= append_var
( $1, $2 ); }
691 case: tCASE expr_int_const
':' union_field
{ attr_t
*a
= make_attrp
(ATTR_CASE
, append_expr
( NULL
, $2 ));
692 $$
= $4; if
(!$$
) $$
= make_var
(NULL
);
693 $$
->attrs
= append_attr
( $$
->attrs
, a
);
695 | tDEFAULT
':' union_field
{ attr_t
*a
= make_attr
(ATTR_DEFAULT
);
696 $$
= $3; if
(!$$
) $$
= make_var
(NULL
);
697 $$
->attrs
= append_attr
( $$
->attrs
, a
);
701 enums: { $$
= NULL
; }
702 | enum_list
',' { $$
= $1; }
706 enum_list: enum { if
(!$1->eval
)
707 $1->eval
= make_exprl
(EXPR_NUM
, 0 /* default for first enum entry */);
708 $$
= append_var
( NULL
, $1 );
710 | enum_list
',' enum { if
(!$3->eval
)
712 var_t
*last
= LIST_ENTRY
( list_tail
($$
), var_t
, entry
);
713 enum expr_type type
= EXPR_NUM
;
714 if
(last
->eval
->type
== EXPR_HEXNUM
) type
= EXPR_HEXNUM
;
715 if
(last
->eval
->cval
+ 1 < 0) type
= EXPR_HEXNUM
;
716 $3->eval
= make_exprl
(type
, last
->eval
->cval
+ 1);
718 $$
= append_var
( $1, $3 );
722 enum_member: m_attributes ident
{ $$
= $2;
723 $$
->attrs
= check_enum_member_attrs
($1);
727 enum: enum_member
'=' expr_int_const
{ $$
= reg_const
($1);
729 $$
->declspec.type
= type_new_int
(TYPE_BASIC_INT
, 0);
731 | enum_member
{ $$
= reg_const
($1);
732 $$
->declspec.type
= type_new_int
(TYPE_BASIC_INT
, 0);
736 enumdef: tENUM m_typename
'{' enums
'}' { $$
= type_new_enum
($2, current_namespace
, TRUE
, $4); }
739 m_exprs: m_expr
{ $$
= append_expr
( NULL
, $1 ); }
740 | m_exprs
',' m_expr
{ $$
= append_expr
( $1, $3 ); }
743 m_expr: { $$
= make_expr
(EXPR_VOID
); }
747 expr: aNUM
{ $$
= make_exprl
(EXPR_NUM
, $1); }
748 | aHEXNUM
{ $$
= make_exprl
(EXPR_HEXNUM
, $1); }
749 | aDOUBLE
{ $$
= make_exprd
(EXPR_DOUBLE
, $1); }
750 | tFALSE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 0); }
751 | tNULL
{ $$
= make_exprl
(EXPR_NUM
, 0); }
752 | tTRUE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 1); }
753 | aSTRING
{ $$
= make_exprs
(EXPR_STRLIT
, $1); }
754 | aWSTRING
{ $$
= make_exprs
(EXPR_WSTRLIT
, $1); }
755 | aSQSTRING
{ $$
= make_exprs
(EXPR_CHARCONST
, $1); }
756 | aIDENTIFIER
{ $$
= make_exprs
(EXPR_IDENTIFIER
, $1); }
757 | expr
'?' expr
':' expr
{ $$
= make_expr3
(EXPR_COND
, $1, $3, $5); }
758 | expr LOGICALOR expr
{ $$
= make_expr2
(EXPR_LOGOR
, $1, $3); }
759 | expr LOGICALAND expr
{ $$
= make_expr2
(EXPR_LOGAND
, $1, $3); }
760 | expr
'|' expr
{ $$
= make_expr2
(EXPR_OR
, $1, $3); }
761 | expr
'^' expr
{ $$
= make_expr2
(EXPR_XOR
, $1, $3); }
762 | expr
'&' expr
{ $$
= make_expr2
(EXPR_AND
, $1, $3); }
763 | expr EQUALITY expr
{ $$
= make_expr2
(EXPR_EQUALITY
, $1, $3); }
764 | expr INEQUALITY expr
{ $$
= make_expr2
(EXPR_INEQUALITY
, $1, $3); }
765 | expr
'>' expr
{ $$
= make_expr2
(EXPR_GTR
, $1, $3); }
766 | expr
'<' expr
{ $$
= make_expr2
(EXPR_LESS
, $1, $3); }
767 | expr GREATEREQUAL expr
{ $$
= make_expr2
(EXPR_GTREQL
, $1, $3); }
768 | expr LESSEQUAL expr
{ $$
= make_expr2
(EXPR_LESSEQL
, $1, $3); }
769 | expr SHL expr
{ $$
= make_expr2
(EXPR_SHL
, $1, $3); }
770 | expr SHR expr
{ $$
= make_expr2
(EXPR_SHR
, $1, $3); }
771 | expr
'+' expr
{ $$
= make_expr2
(EXPR_ADD
, $1, $3); }
772 | expr
'-' expr
{ $$
= make_expr2
(EXPR_SUB
, $1, $3); }
773 | expr
'%' expr
{ $$
= make_expr2
(EXPR_MOD
, $1, $3); }
774 | expr
'*' expr
{ $$
= make_expr2
(EXPR_MUL
, $1, $3); }
775 | expr
'/' expr
{ $$
= make_expr2
(EXPR_DIV
, $1, $3); }
776 |
'!' expr
{ $$
= make_expr1
(EXPR_LOGNOT
, $2); }
777 |
'~' expr
{ $$
= make_expr1
(EXPR_NOT
, $2); }
778 |
'+' expr %prec POS
{ $$
= make_expr1
(EXPR_POS
, $2); }
779 |
'-' expr %prec NEG
{ $$
= make_expr1
(EXPR_NEG
, $2); }
780 |
'&' expr %prec ADDRESSOF
{ $$
= make_expr1
(EXPR_ADDRESSOF
, $2); }
781 |
'*' expr %prec PPTR
{ $$
= make_expr1
(EXPR_PPTR
, $2); }
782 | expr MEMBERPTR aIDENTIFIER
{ $$
= make_expr2
(EXPR_MEMBER
, make_expr1
(EXPR_PPTR
, $1), make_exprs
(EXPR_IDENTIFIER
, $3)); }
783 | expr
'.' aIDENTIFIER
{ $$
= make_expr2
(EXPR_MEMBER
, $1, make_exprs
(EXPR_IDENTIFIER
, $3)); }
784 |
'(' unqualified_decl_spec m_abstract_declarator
')' expr %prec CAST
785 { $$
= make_exprt
(EXPR_CAST
, declare_var
(NULL
, $2, $3, 0), $5); free
($2); free
($3); }
786 | tSIZEOF
'(' unqualified_decl_spec m_abstract_declarator
')'
787 { $$
= make_exprt
(EXPR_SIZEOF
, declare_var
(NULL
, $3, $4, 0), NULL
); free
($3); free
($4); }
788 | expr
'[' expr
']' { $$
= make_expr2
(EXPR_ARRAY
, $1, $3); }
789 |
'(' expr
')' { $$
= $2; }
792 expr_list_int_const: expr_int_const
{ $$
= append_expr
( NULL
, $1 ); }
793 | expr_list_int_const
',' expr_int_const
{ $$
= append_expr
( $1, $3 ); }
796 expr_int_const: expr
{ $$
= $1;
798 error_loc
("expression is not an integer constant\n");
802 expr_const: expr
{ $$
= $1;
803 if
(!$$
->is_const
&& $$
->type
!= EXPR_STRLIT
&& $$
->type
!= EXPR_WSTRLIT
)
804 error_loc
("expression is not constant\n");
808 fields: { $$
= NULL
; }
809 | fields field
{ $$
= append_var_list
($1, $2); }
812 field: m_attributes decl_spec struct_declarator_list
';'
813 { const char *first
= LIST_ENTRY
(list_head
($3), declarator_t
, entry
)->var
->name
;
814 check_field_attrs
(first
, $1);
815 $$
= set_var_types
($1, $2, $3);
817 | m_attributes uniondef
';' { var_t
*v
= make_var
(NULL
);
818 v
->declspec.type
= $2; v
->attrs
= $1;
819 $$
= append_var
(NULL
, v
);
824 s_field
';' { $$
= $1; }
825 | attributes
';' { $$
= make_var
(NULL
); $$
->attrs
= $1; }
828 ne_union_fields: { $$
= NULL
; }
829 | ne_union_fields ne_union_field
{ $$
= append_var
( $1, $2 ); }
833 s_field
';' { $$
= $1; }
837 s_field: m_attributes decl_spec declarator
{ $$
= declare_var
(check_field_attrs
($3->var
->name
, $1),
841 | m_attributes structdef
{ var_t
*v
= make_var
(NULL
);
842 v
->declspec.type
= $2; v
->attrs
= $1;
847 funcdef: declaration
{ $$
= $1;
848 if
(type_get_type
($$
->declspec.type
) != TYPE_FUNCTION
)
849 error_loc
("only methods may be declared inside the methods section of a dispinterface\n");
850 check_function_attrs
($$
->name
, $$
->attrs
);
855 attributes decl_spec init_declarator
856 { $$
= declare_var
($1, $2, $3, FALSE
);
859 | decl_spec init_declarator
{ $$
= declare_var
(NULL
, $1, $2, FALSE
);
864 m_ident: { $$
= NULL
; }
868 m_typename: { $$
= NULL
; }
872 typename: aIDENTIFIER
876 ident: typename
{ $$
= make_var
($1); }
879 base_type: tBYTE
{ $$
= find_type_or_error
(NULL
, $
<str
>1); }
880 | tWCHAR
{ $$
= find_type_or_error
(NULL
, $
<str
>1); }
882 | tSIGNED int_std
{ $$
= type_new_int
(type_basic_get_type
($2), -1); }
883 | tUNSIGNED int_std
{ $$
= type_new_int
(type_basic_get_type
($2), 1); }
884 | tUNSIGNED
{ $$
= type_new_int
(TYPE_BASIC_INT
, 1); }
885 | tFLOAT
{ $$
= find_type_or_error
(NULL
, $
<str
>1); }
886 | tDOUBLE
{ $$
= find_type_or_error
(NULL
, $
<str
>1); }
887 | tBOOLEAN
{ $$
= find_type_or_error
(NULL
, $
<str
>1); }
888 | tERRORSTATUST
{ $$
= find_type_or_error
(NULL
, $
<str
>1); }
889 | tHANDLET
{ $$
= find_type_or_error
(NULL
, $
<str
>1); }
896 int_std: tINT
{ $$
= type_new_int
(TYPE_BASIC_INT
, 0); }
897 | tSHORT m_int
{ $$
= type_new_int
(TYPE_BASIC_INT16
, 0); }
898 | tSMALL
{ $$
= type_new_int
(TYPE_BASIC_INT8
, 0); }
899 | tLONG m_int
{ $$
= type_new_int
(TYPE_BASIC_LONG
, 0); }
900 | tHYPER m_int
{ $$
= type_new_int
(TYPE_BASIC_HYPER
, 0); }
901 | tINT64
{ $$
= type_new_int
(TYPE_BASIC_INT64
, 0); }
902 | tCHAR
{ $$
= type_new_int
(TYPE_BASIC_CHAR
, 0); }
903 | tINT32
{ $$
= type_new_int
(TYPE_BASIC_INT32
, 0); }
904 | tINT3264
{ $$
= type_new_int
(TYPE_BASIC_INT3264
, 0); }
908 aIDENTIFIER
'.' { $$
= find_namespace_or_error
(&global_namespace
, $1); }
909 | namespace_pfx aIDENTIFIER
'.' { $$
= find_namespace_or_error
($1, $2); }
913 typename
{ $$
= find_type_or_error
(current_namespace
, $1); }
914 | namespace_pfx typename
{ $$
= find_type_or_error
($1, $2); }
917 coclass: tCOCLASS typename
{ $$
= type_coclass_declare
($2); }
920 coclassdef: attributes coclass
'{' class_interfaces
'}' semicolon_opt
921 { $$
= type_coclass_define
($2, $1, $4); }
924 runtimeclass: tRUNTIMECLASS typename
{ $$
= type_runtimeclass_declare
($2, current_namespace
); }
927 runtimeclass_def: attributes runtimeclass
'{' class_interfaces
'}' semicolon_opt
928 { $$
= type_runtimeclass_define
($2, $1, $4); }
931 apicontract: tAPICONTRACT typename
{ $$
= type_apicontract_declare
($2, current_namespace
); }
934 apicontract_def: attributes apicontract
'{' '}' semicolon_opt
935 { $$
= type_apicontract_define
($2, $1); }
938 namespacedef: tNAMESPACE aIDENTIFIER
{ $$
= $2; }
941 class_interfaces: { $$
= NULL
; }
942 | class_interfaces class_interface
{ $$
= append_ifref
( $1, $2 ); }
946 m_attributes interfaceref
';' { $$
= make_ifref
($2); $$
->attrs
= $1; }
947 | m_attributes dispinterfaceref
';' { $$
= make_ifref
($2); $$
->attrs
= $1; }
950 dispinterface: tDISPINTERFACE typename
{ $$
= type_dispinterface_declare
($2); }
953 dispattributes: attributes
{ $$
= append_attr
($1, make_attr
(ATTR_DISPINTERFACE
)); }
956 dispint_props: tPROPERTIES
':' { $$
= NULL
; }
957 | dispint_props s_field
';' { $$
= append_var
( $1, $2 ); }
960 dispint_meths: tMETHODS
':' { $$
= NULL
; }
961 | dispint_meths funcdef
';' { $$
= append_var
( $1, $2 ); }
965 dispattributes dispinterface
'{' dispint_props dispint_meths
'}'
966 { $$
= type_dispinterface_define
($2, $1, $4, $5); }
967 | dispattributes dispinterface
'{' interface
';' '}'
968 { $$
= type_dispinterface_define_from_iface
($2, $1, $4); }
971 inherit: { $$
= NULL
; }
972 |
':' qualified_type
{ $$
= $2; }
975 type_parameter: typename
{ $$
= get_type
(TYPE_PARAMETER
, $1, parameters_namespace
, 0); }
979 type_parameter
{ $$
= append_type
(NULL
, $1); }
980 | type_parameters
',' type_parameter
{ $$
= append_type
($1, $3); }
984 tINTERFACE typename
{ $$
= type_interface_declare
($2, current_namespace
); }
985 | tINTERFACE typename
'<' { push_parameters_namespace
($2); } type_parameters
{ pop_parameters_namespace
($2); } '>'
986 { $$
= type_parameterized_interface_declare
($2, current_namespace
, $5); }
990 qualified_type
{ $$
= append_ifref
(NULL
, make_ifref
($1)); }
991 | required_types
',' qualified_type
{ $$
= append_ifref
($1, make_ifref
($3)); }
993 requires: { $$
= NULL
; }
994 | tREQUIRES required_types
{ $$
= $2; }
997 interfacedef: attributes interface
{ if
($2->type_type
== TYPE_PARAMETERIZED_TYPE
) push_parameters_namespace
($2->name
); }
998 inherit requires
'{' int_statements
'}' semicolon_opt
999 { if
($2->type_type
== TYPE_PARAMETERIZED_TYPE
)
1001 $$
= type_parameterized_interface_define
($2, $1, $4, $7, $5);
1002 pop_parameters_namespace
($2->name
);
1006 $$
= type_interface_define
($2, $1, $4, $7, $5);
1007 check_async_uuid
($$
);
1010 | dispinterfacedef semicolon_opt
{ $$
= $1; }
1014 tINTERFACE typename
{ $$
= get_type
(TYPE_INTERFACE
, $2, current_namespace
, 0); }
1015 | tINTERFACE namespace_pfx typename
{ $$
= get_type
(TYPE_INTERFACE
, $3, $2, 0); }
1019 tDISPINTERFACE typename
{ $$
= get_type
(TYPE_INTERFACE
, $2, current_namespace
, 0); }
1022 module: tMODULE typename
{ $$
= type_module_declare
($2); }
1025 moduledef: attributes module
'{' int_statements
'}' semicolon_opt
1026 { $$
= type_module_define
($2, $1, $4); }
1030 tEXTERN
{ $$
= STG_EXTERN
; }
1031 | tSTATIC
{ $$
= STG_STATIC
; }
1032 | tREGISTER
{ $$
= STG_REGISTER
; }
1036 tINLINE
{ $$
= FUNCTION_SPECIFIER_INLINE
; }
1040 tCONST
{ $$
= TYPE_QUALIFIER_CONST
; }
1043 m_type_qual_list: { $$
= 0; }
1044 | m_type_qual_list type_qualifier
{ $$
= $1 |
$2; }
1047 decl_spec: type m_decl_spec_no_type
{ $$
= make_decl_spec
($1, $2, NULL
, STG_NONE
, 0, 0); }
1048 | decl_spec_no_type type m_decl_spec_no_type
1049 { $$
= make_decl_spec
($2, $1, $3, STG_NONE
, 0, 0); }
1052 unqualified_decl_spec: unqualified_type m_decl_spec_no_type
1053 { $$
= make_decl_spec
($1, $2, NULL
, STG_NONE
, 0, 0); }
1054 | decl_spec_no_type unqualified_type m_decl_spec_no_type
1055 { $$
= make_decl_spec
($2, $1, $3, STG_NONE
, 0, 0); }
1058 m_decl_spec_no_type: { $$
= NULL
; }
1063 type_qualifier m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, STG_NONE
, $1, 0); }
1064 | function_specifier m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, STG_NONE
, 0, $1); }
1065 | storage_cls_spec m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, $1, 0, 0); }
1069 '*' m_type_qual_list declarator %prec PPTR
1070 { $$
= $3; append_chain_type
($$
, type_new_pointer
(NULL
), $2); }
1071 | callconv declarator
{ $$
= $2; append_chain_callconv
($$
->type
, $1); }
1076 ident
{ $$
= make_declarator
($1); }
1077 |
'(' declarator
')' { $$
= $2; }
1078 | direct_declarator array
{ $$
= $1; append_array
($$
, $2); }
1079 | direct_declarator
'(' m_args
')' { $$
= $1; append_chain_type
($$
, type_new_function
($3), 0); }
1082 /* abstract declarator */
1083 abstract_declarator:
1084 '*' m_type_qual_list m_abstract_declarator %prec PPTR
1085 { $$
= $3; append_chain_type
($$
, type_new_pointer
(NULL
), $2); }
1086 | callconv m_abstract_declarator
{ $$
= $2; append_chain_callconv
($$
->type
, $1); }
1087 | abstract_direct_declarator
1090 /* abstract declarator without accepting direct declarator */
1091 abstract_declarator_no_direct:
1092 '*' m_type_qual_list m_any_declarator %prec PPTR
1093 { $$
= $3; append_chain_type
($$
, type_new_pointer
(NULL
), $2); }
1094 | callconv m_any_declarator
{ $$
= $2; append_chain_callconv
($$
->type
, $1); }
1097 /* abstract declarator or empty */
1098 m_abstract_declarator: { $$
= make_declarator
(NULL
); }
1099 | abstract_declarator
1102 /* abstract direct declarator */
1103 abstract_direct_declarator:
1104 '(' abstract_declarator_no_direct
')' { $$
= $2; }
1105 | abstract_direct_declarator array
{ $$
= $1; append_array
($$
, $2); }
1106 | array
{ $$
= make_declarator
(NULL
); append_array
($$
, $1); }
1108 { $$
= make_declarator
(NULL
);
1109 append_chain_type
($$
, type_new_function
($2), 0);
1111 | abstract_direct_declarator
'(' m_args
')'
1113 append_chain_type
($$
, type_new_function
($3), 0);
1117 /* abstract or non-abstract declarator */
1119 '*' m_type_qual_list m_any_declarator %prec PPTR
1120 { $$
= $3; append_chain_type
($$
, type_new_pointer
(NULL
), $2); }
1121 | callconv m_any_declarator
{ $$
= $2; append_chain_callconv
($$
->type
, $1); }
1122 | any_direct_declarator
1125 /* abstract or non-abstract declarator without accepting direct declarator */
1126 any_declarator_no_direct:
1127 '*' m_type_qual_list m_any_declarator %prec PPTR
1128 { $$
= $3; append_chain_type
($$
, type_new_pointer
(NULL
), $2); }
1129 | callconv m_any_declarator
{ $$
= $2; append_chain_callconv
($$
->type
, $1); }
1132 /* abstract or non-abstract declarator or empty */
1133 m_any_declarator: { $$
= make_declarator
(NULL
); }
1137 /* abstract or non-abstract direct declarator. note: direct declarators
1138 * aren't accepted inside brackets to avoid ambiguity with the rule for
1139 * function arguments */
1140 any_direct_declarator:
1141 ident
{ $$
= make_declarator
($1); }
1142 |
'(' any_declarator_no_direct
')' { $$
= $2; }
1143 | any_direct_declarator array
{ $$
= $1; append_array
($$
, $2); }
1144 | array
{ $$
= make_declarator
(NULL
); append_array
($$
, $1); }
1146 { $$
= make_declarator
(NULL
);
1147 append_chain_type
($$
, type_new_function
($2), 0);
1149 | any_direct_declarator
'(' m_args
')'
1151 append_chain_type
($$
, type_new_function
($3), 0);
1156 declarator
{ $$
= append_declarator
( NULL
, $1 ); }
1157 | declarator_list
',' declarator
{ $$
= append_declarator
( $1, $3 ); }
1160 m_bitfield: { $$
= NULL
; }
1161 |
':' expr_const
{ $$
= $2; }
1164 struct_declarator: any_declarator m_bitfield
{ $$
= $1; $$
->bits
= $2;
1165 if
(!$$
->bits
&& !$$
->var
->name
)
1166 error_loc
("unnamed fields are not allowed\n");
1170 struct_declarator_list:
1171 struct_declarator
{ $$
= append_declarator
( NULL
, $1 ); }
1172 | struct_declarator_list
',' struct_declarator
1173 { $$
= append_declarator
( $1, $3 ); }
1177 declarator
{ $$
= $1; }
1178 | declarator
'=' expr_const
{ $$
= $1; $1->var
->eval
= $3; }
1182 tAPARTMENT
{ $$
= THREADING_APARTMENT
; }
1183 | tNEUTRAL
{ $$
= THREADING_NEUTRAL
; }
1184 | tSINGLE
{ $$
= THREADING_SINGLE
; }
1185 | tFREE
{ $$
= THREADING_FREE
; }
1186 | tBOTH
{ $$
= THREADING_BOTH
; }
1187 | tMTA
{ $$
= THREADING_FREE
; }
1191 tREF
{ $$
= FC_RP
; }
1192 | tUNIQUE
{ $$
= FC_UP
; }
1193 | tPTR
{ $$
= FC_FP
; }
1196 structdef: tSTRUCT m_typename
'{' fields
'}' { $$
= type_new_struct
($2, current_namespace
, TRUE
, $4); }
1200 tVOID
{ $$
= type_new_void
(); }
1201 | base_type
{ $$
= $1; }
1202 | enumdef
{ $$
= $1; }
1203 | tENUM aIDENTIFIER
{ $$
= type_new_enum
($2, current_namespace
, FALSE
, NULL
); }
1204 | structdef
{ $$
= $1; }
1205 | tSTRUCT aIDENTIFIER
{ $$
= type_new_struct
($2, current_namespace
, FALSE
, NULL
); }
1206 | uniondef
{ $$
= $1; }
1207 | tUNION aIDENTIFIER
{ $$
= type_new_nonencapsulated_union
($2, FALSE
, NULL
); }
1208 | tSAFEARRAY
'(' type
')' { $$
= make_safearray
($3); }
1209 | aKNOWNTYPE
{ $$
= find_type_or_error
(current_namespace
, $1); }
1214 | namespace_pfx typename
{ $$
= find_type_or_error
($1, $2); }
1217 typedef: m_attributes tTYPEDEF m_attributes decl_spec declarator_list
1218 { $1 = append_attribs
($1, $3);
1219 reg_typedefs
($4, $5, check_typedef_attrs
($1));
1220 $$
= make_statement_typedef
($5, !$4->type
->defined
);
1224 uniondef: tUNION m_typename
'{' ne_union_fields
'}'
1225 { $$
= type_new_nonencapsulated_union
($2, TRUE
, $4); }
1227 tSWITCH
'(' s_field
')'
1228 m_ident
'{' cases
'}' { $$
= type_new_encapsulated_union
($2, $5, $7, $9); }
1232 aNUM
{ $$
= MAKEVERSION
($1, 0); }
1233 | aNUM
'.' aNUM
{ $$
= MAKEVERSION
($1, $3); }
1234 | aHEXNUM
{ $$
= $1; }
1239 | acf_interface acf_statements
1244 | acf_int_statement acf_int_statements
1248 : tTYPEDEF acf_attributes aKNOWNTYPE
';'
1249 { type_t
*type
= find_type_or_error
(current_namespace
, $3);
1250 type
->attrs
= append_attr_list
(type
->attrs
, $2);
1255 : acf_attributes tINTERFACE aKNOWNTYPE
'{' acf_int_statements
'}'
1256 { type_t
*iface
= find_type_or_error
(current_namespace
, $3);
1257 if
(type_get_type
(iface
) != TYPE_INTERFACE
)
1258 error_loc
("%s is not an interface\n", iface
->name
);
1259 iface
->attrs
= append_attr_list
(iface
->attrs
, $1);
1264 : /* empty */ { $$
= NULL
; };
1265 |
'[' acf_attribute_list
']' { $$
= $2; };
1269 : acf_attribute
{ $$
= append_attr
(NULL
, $1); }
1270 | acf_attribute_list
',' acf_attribute
{ $$
= append_attr
($1, $3); }
1274 : tALLOCATE
'(' allocate_option_list
')'
1275 { $$
= make_attrv
(ATTR_ALLOCATE
, $3); }
1276 | tENCODE
{ $$
= make_attr
(ATTR_ENCODE
); }
1277 | tDECODE
{ $$
= make_attr
(ATTR_DECODE
); }
1278 | tEXPLICITHANDLE
{ $$
= make_attr
(ATTR_EXPLICIT_HANDLE
); }
1281 allocate_option_list
1282 : allocate_option
{ $$
= $1; }
1283 | allocate_option_list
',' allocate_option
1288 : tDONTFREE
{ $$
= FC_DONT_FREE
; }
1290 | tALLNODES
{ $$
= FC_ALLOCATE_ALL_NODES
; }
1291 | tSINGLENODE
{ $$
= 0; }
1296 static void decl_builtin_basic
(const char *name
, enum type_basic_type type
)
1298 type_t
*t
= type_new_basic
(type
);
1299 reg_type
(t
, name
, NULL
, 0);
1302 static void decl_builtin_alias
(const char *name
, type_t
*t
)
1304 const decl_spec_t ds
= {.type
= t
};
1305 reg_type
(type_new_alias
(&ds
, name
), name
, NULL
, 0);
1308 void init_types
(void)
1310 decl_builtin_basic
("byte", TYPE_BASIC_BYTE
);
1311 decl_builtin_basic
("wchar_t", TYPE_BASIC_WCHAR
);
1312 decl_builtin_basic
("float", TYPE_BASIC_FLOAT
);
1313 decl_builtin_basic
("double", TYPE_BASIC_DOUBLE
);
1314 decl_builtin_basic
("error_status_t", TYPE_BASIC_ERROR_STATUS_T
);
1315 decl_builtin_basic
("handle_t", TYPE_BASIC_HANDLE
);
1316 decl_builtin_alias
("boolean", type_new_basic
(TYPE_BASIC_CHAR
));
1319 static str_list_t
*append_str
(str_list_t
*list
, char *str
)
1321 struct str_list_entry_t
*entry
;
1323 if
(!str
) return list
;
1326 list
= xmalloc
( sizeof
(*list
) );
1329 entry
= xmalloc
( sizeof
(*entry
) );
1331 list_add_tail
( list
, &entry
->entry
);
1335 static attr_list_t
*move_attr
(attr_list_t
*dst
, attr_list_t
*src
, enum attr_type type
)
1338 if
(!src
) return dst
;
1339 LIST_FOR_EACH_ENTRY
(attr
, src
, attr_t
, entry
)
1340 if
(attr
->type
== type
)
1342 list_remove
(&attr
->entry
);
1343 return append_attr
(dst
, attr
);
1348 static attr_list_t
*append_attr_list
(attr_list_t
*new_list
, attr_list_t
*old_list
)
1352 if
(!old_list
) return new_list
;
1354 while
((entry
= list_head
(old_list
)))
1356 attr_t
*attr
= LIST_ENTRY
(entry
, attr_t
, entry
);
1358 new_list
= append_attr
(new_list
, attr
);
1363 typedef
int (*map_attrs_filter_t
)(attr_list_t
*,const attr_t
*);
1365 static attr_list_t
*map_attrs
(const attr_list_t
*list
, map_attrs_filter_t filter
)
1367 attr_list_t
*new_list
;
1371 if
(!list
) return NULL
;
1373 new_list
= xmalloc
( sizeof
(*list
) );
1374 list_init
( new_list
);
1375 LIST_FOR_EACH_ENTRY
(attr
, list
, const attr_t
, entry
)
1377 if
(filter
&& !filter
(new_list
, attr
)) continue
;
1378 new_attr
= xmalloc
(sizeof
(*new_attr
));
1380 list_add_tail
(new_list
, &new_attr
->entry
);
1385 static decl_spec_t
*make_decl_spec
(type_t
*type
, decl_spec_t
*left
, decl_spec_t
*right
,
1386 enum storage_class stgclass
, enum type_qualifier qual
, enum function_specifier func_specifier
)
1388 decl_spec_t
*declspec
= left ? left
: right
;
1391 declspec
= xmalloc
(sizeof
(*declspec
));
1392 declspec
->type
= NULL
;
1393 declspec
->stgclass
= STG_NONE
;
1394 declspec
->qualifier
= 0;
1395 declspec
->func_specifier
= 0;
1397 declspec
->type
= type
;
1398 if
(left
&& declspec
!= left
)
1400 if
(declspec
->stgclass
== STG_NONE
)
1401 declspec
->stgclass
= left
->stgclass
;
1402 else if
(left
->stgclass
!= STG_NONE
)
1403 error_loc
("only one storage class can be specified\n");
1404 declspec
->qualifier |
= left
->qualifier
;
1405 declspec
->func_specifier |
= left
->func_specifier
;
1406 assert
(!left
->type
);
1409 if
(right
&& declspec
!= right
)
1411 if
(declspec
->stgclass
== STG_NONE
)
1412 declspec
->stgclass
= right
->stgclass
;
1413 else if
(right
->stgclass
!= STG_NONE
)
1414 error_loc
("only one storage class can be specified\n");
1415 declspec
->qualifier |
= right
->qualifier
;
1416 declspec
->func_specifier |
= right
->func_specifier
;
1417 assert
(!right
->type
);
1421 if
(declspec
->stgclass
== STG_NONE
)
1422 declspec
->stgclass
= stgclass
;
1423 else if
(stgclass
!= STG_NONE
)
1424 error_loc
("only one storage class can be specified\n");
1425 declspec
->qualifier |
= qual
;
1426 declspec
->func_specifier |
= func_specifier
;
1431 static attr_t
*make_attr
(enum attr_type type
)
1433 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1439 static attr_t
*make_attrv
(enum attr_type type
, unsigned int val
)
1441 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1447 static attr_t
*make_attrp
(enum attr_type type
, void *val
)
1449 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1455 static attr_t
*make_custom_attr
(UUID
*id
, expr_t
*pval
)
1457 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1458 attr_custdata_t
*cstdata
= xmalloc
(sizeof
(attr_custdata_t
));
1459 a
->type
= ATTR_CUSTOM
;
1461 cstdata
->pval
= pval
;
1462 a
->u.pval
= cstdata
;
1466 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
)
1468 if
(!expr
) return list
;
1471 list
= xmalloc
( sizeof
(*list
) );
1474 list_add_tail
( list
, &expr
->entry
);
1478 static void append_array
(declarator_t
*decl
, expr_t
*expr
)
1485 /* An array is always a reference pointer unless explicitly marked otherwise
1486 * (regardless of what the default pointer attribute is). */
1487 array
= type_new_array
(NULL
, NULL
, FALSE
, expr
->is_const ? expr
->cval
: 0,
1488 expr
->is_const ? NULL
: expr
, NULL
);
1490 append_chain_type
(decl
, array
, 0);
1493 static struct list type_pool
= LIST_INIT
(type_pool
);
1500 type_t
*alloc_type
(void)
1502 type_pool_node_t
*node
= xmalloc
(sizeof
*node
);
1503 list_add_tail
(&type_pool
, &node
->link
);
1507 void set_all_tfswrite
(int val
)
1509 type_pool_node_t
*node
;
1510 LIST_FOR_EACH_ENTRY
(node
, &type_pool
, type_pool_node_t
, link
)
1511 node
->data.tfswrite
= val
;
1514 void clear_all_offsets
(void)
1516 type_pool_node_t
*node
;
1517 LIST_FOR_EACH_ENTRY
(node
, &type_pool
, type_pool_node_t
, link
)
1518 node
->data.typestring_offset
= node
->data.ptrdesc
= 0;
1521 static void type_function_add_head_arg
(type_t
*type
, var_t
*arg
)
1523 if
(!type
->details.function
->args
)
1525 type
->details.function
->args
= xmalloc
( sizeof
(*type
->details.function
->args
) );
1526 list_init
( type
->details.function
->args
);
1528 list_add_head
( type
->details.function
->args
, &arg
->entry
);
1531 static int is_allowed_range_type
(const type_t
*type
)
1533 switch
(type_get_type
(type
))
1538 switch
(type_basic_get_type
(type
))
1540 case TYPE_BASIC_INT8
:
1541 case TYPE_BASIC_INT16
:
1542 case TYPE_BASIC_INT32
:
1543 case TYPE_BASIC_INT64
:
1544 case TYPE_BASIC_INT
:
1545 case TYPE_BASIC_INT3264
:
1546 case TYPE_BASIC_LONG
:
1547 case TYPE_BASIC_BYTE
:
1548 case TYPE_BASIC_CHAR
:
1549 case TYPE_BASIC_WCHAR
:
1550 case TYPE_BASIC_HYPER
:
1552 case TYPE_BASIC_FLOAT
:
1553 case TYPE_BASIC_DOUBLE
:
1554 case TYPE_BASIC_ERROR_STATUS_T
:
1555 case TYPE_BASIC_HANDLE
:
1564 static type_t
*get_chain_ref
(type_t
*type
)
1567 return type_pointer_get_ref_type
(type
);
1568 else if
(is_array
(type
))
1569 return type_array_get_element_type
(type
);
1570 else if
(is_func
(type
))
1571 return type_function_get_rettype
(type
);
1575 static type_t
*get_chain_end
(type_t
*type
)
1578 while
((inner
= get_chain_ref
(type
)))
1583 static void append_chain_type
(declarator_t
*decl
, type_t
*type
, enum type_qualifier qual
)
1590 decl
->qualifier
= qual
;
1593 chain_type
= get_chain_end
(decl
->type
);
1595 if
(is_ptr
(chain_type
))
1597 chain_type
->details.pointer.ref.type
= type
;
1598 chain_type
->details.pointer.ref.qualifier
= qual
;
1600 else if
(is_array
(chain_type
))
1602 chain_type
->details.array.elem.type
= type
;
1603 chain_type
->details.array.elem.qualifier
= qual
;
1605 else if
(is_func
(chain_type
))
1607 chain_type
->details.function
->retval
->declspec.type
= type
;
1608 chain_type
->details.function
->retval
->declspec.qualifier
= qual
;
1613 if
(!is_func
(chain_type
))
1614 type
->attrs
= move_attr
(type
->attrs
, chain_type
->attrs
, ATTR_CALLCONV
);
1617 static void append_chain_callconv
(type_t
*chain
, char *callconv
)
1621 if
(chain
&& (chain_end
= get_chain_end
(chain
)))
1622 chain_end
->attrs
= append_attr
(chain_end
->attrs
, make_attrp
(ATTR_CALLCONV
, callconv
));
1624 error_loc
("calling convention applied to non-function type\n");
1627 static warning_list_t
*append_warning
(warning_list_t
*list
, int num
)
1633 list
= xmalloc
( sizeof
(*list
) );
1636 entry
= xmalloc
( sizeof
(*entry
) );
1638 list_add_tail
( list
, &entry
->entry
);
1642 static var_t
*declare_var
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_t
*decl
,
1645 var_t
*v
= decl
->var
;
1646 expr_list_t
*sizes
= get_attrp
(attrs
, ATTR_SIZEIS
);
1647 expr_list_t
*lengs
= get_attrp
(attrs
, ATTR_LENGTHIS
);
1650 type_t
*type
= decl_spec
->type
;
1652 if
(decl_spec
->func_specifier
& FUNCTION_SPECIFIER_INLINE
)
1654 if
(!decl ||
!is_func
(decl
->type
))
1655 error_loc
("inline attribute applied to non-function type\n");
1658 /* add type onto the end of the pointers in pident->type */
1659 append_chain_type
(decl
, type
, decl_spec
->qualifier
);
1660 v
->declspec
= *decl_spec
;
1661 v
->declspec.type
= decl
->type
;
1662 v
->declspec.qualifier
= decl
->qualifier
;
1664 v
->declonly
= !type
->defined
;
1666 if
(is_attr
(type
->attrs
, ATTR_CALLCONV
) && !is_func
(type
))
1667 error_loc
("calling convention applied to non-function type\n");
1669 /* check for pointer attribute being applied to non-pointer, non-array
1671 if
(!is_array
(v
->declspec.type
))
1673 int ptr_attr
= get_attrv
(v
->attrs
, ATTR_POINTERTYPE
);
1674 const type_t
*ptr
= NULL
;
1675 for
(ptr
= v
->declspec.type
; ptr
&& !ptr_attr
; )
1677 ptr_attr
= get_attrv
(ptr
->attrs
, ATTR_POINTERTYPE
);
1678 if
(!ptr_attr
&& type_is_alias
(ptr
))
1679 ptr
= type_alias_get_aliasee_type
(ptr
);
1685 if
(ptr_attr
&& ptr_attr
!= FC_UP
&&
1686 type_get_type
(type_pointer_get_ref_type
(ptr
)) == TYPE_INTERFACE
)
1687 warning_loc_info
(&v
->loc_info
,
1688 "%s: pointer attribute applied to interface "
1689 "pointer type has no effect\n", v
->name
);
1690 if
(!ptr_attr
&& top
)
1692 /* FIXME: this is a horrible hack to cope with the issue that we
1693 * store an offset to the typeformat string in the type object, but
1694 * two typeformat strings may be written depending on whether the
1695 * pointer is a toplevel parameter or not */
1696 v
->declspec.type
= duptype
(v
->declspec.type
, 1);
1700 error_loc
("%s: pointer attribute applied to non-pointer type\n", v
->name
);
1703 if
(is_attr
(v
->attrs
, ATTR_STRING
))
1707 if
(!is_ptr
(v
->declspec.type
) && !is_array
(v
->declspec.type
))
1708 error_loc
("'%s': [string] attribute applied to non-pointer, non-array type\n",
1714 t
= type_pointer_get_ref_type
(t
);
1715 else if
(is_array
(t
))
1716 t
= type_array_get_element_type
(t
);
1721 if
(type_get_type
(t
) != TYPE_BASIC
&&
1722 (get_basic_fc
(t
) != FC_CHAR
&&
1723 get_basic_fc
(t
) != FC_BYTE
&&
1724 get_basic_fc
(t
) != FC_WCHAR
))
1726 error_loc
("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
1731 if
(is_attr
(v
->attrs
, ATTR_V1ENUM
))
1733 if
(type_get_type_detect_alias
(v
->declspec.type
) != TYPE_ENUM
)
1734 error_loc
("'%s': [v1_enum] attribute applied to non-enum type\n", v
->name
);
1737 if
(is_attr
(v
->attrs
, ATTR_RANGE
) && !is_allowed_range_type
(v
->declspec.type
))
1738 error_loc
("'%s': [range] attribute applied to non-integer type\n",
1741 ptype
= &v
->declspec.type
;
1742 if
(sizes
) LIST_FOR_EACH_ENTRY
(dim
, sizes
, expr_t
, entry
)
1744 if
(dim
->type
!= EXPR_VOID
)
1746 if
(is_array
(*ptype
))
1748 if
(!type_array_get_conformance
(*ptype
) ||
1749 type_array_get_conformance
(*ptype
)->type
!= EXPR_VOID
)
1750 error_loc
("%s: cannot specify size_is for an already sized array\n", v
->name
);
1752 *ptype
= type_new_array
((*ptype
)->name
,
1753 type_array_get_element
(*ptype
), FALSE
,
1756 else if
(is_ptr
(*ptype
))
1757 *ptype
= type_new_array
((*ptype
)->name
, type_pointer_get_ref
(*ptype
), TRUE
,
1760 error_loc
("%s: size_is attribute applied to illegal type\n", v
->name
);
1764 ptype
= &(*ptype
)->details.pointer.ref.type
;
1765 else if
(is_array
(*ptype
))
1766 ptype
= &(*ptype
)->details.array.elem.type
;
1768 error_loc
("%s: too many expressions in size_is attribute\n", v
->name
);
1771 ptype
= &v
->declspec.type
;
1772 if
(lengs
) LIST_FOR_EACH_ENTRY
(dim
, lengs
, expr_t
, entry
)
1774 if
(dim
->type
!= EXPR_VOID
)
1776 if
(is_array
(*ptype
))
1778 *ptype
= type_new_array
((*ptype
)->name
,
1779 type_array_get_element
(*ptype
),
1780 type_array_is_decl_as_ptr
(*ptype
),
1781 type_array_get_dim
(*ptype
),
1782 type_array_get_conformance
(*ptype
), dim
);
1785 error_loc
("%s: length_is attribute applied to illegal type\n", v
->name
);
1789 ptype
= &(*ptype
)->details.pointer.ref.type
;
1790 else if
(is_array
(*ptype
))
1791 ptype
= &(*ptype
)->details.array.elem.type
;
1793 error_loc
("%s: too many expressions in length_is attribute\n", v
->name
);
1797 v
->declspec.type
= type_new_bitfield
(v
->declspec.type
, decl
->bits
);
1802 static var_list_t
*set_var_types
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_list_t
*decls
)
1804 declarator_t
*decl
, *next
;
1805 var_list_t
*var_list
= NULL
;
1807 LIST_FOR_EACH_ENTRY_SAFE
( decl
, next
, decls
, declarator_t
, entry
)
1809 var_t
*var
= declare_var
(attrs
, decl_spec
, decl
, 0);
1810 var_list
= append_var
(var_list
, var
);
1817 static ifref_list_t
*append_ifref
(ifref_list_t
*list
, ifref_t
*iface
)
1819 if
(!iface
) return list
;
1822 list
= xmalloc
( sizeof
(*list
) );
1825 list_add_tail
( list
, &iface
->entry
);
1829 static ifref_t
*make_ifref
(type_t
*type
)
1831 ifref_t
*l
= xmalloc
(sizeof
(ifref_t
));
1837 static type_list_t
*append_type
(type_list_t
*list
, type_t
*type
)
1840 if
(!type
) return list
;
1841 entry
= xmalloc
( sizeof
(*entry
) );
1847 var_list_t
*append_var
(var_list_t
*list
, var_t
*var
)
1849 if
(!var
) return list
;
1852 list
= xmalloc
( sizeof
(*list
) );
1855 list_add_tail
( list
, &var
->entry
);
1859 static var_list_t
*append_var_list
(var_list_t
*list
, var_list_t
*vars
)
1861 if
(!vars
) return list
;
1864 list
= xmalloc
( sizeof
(*list
) );
1867 list_move_tail
( list
, vars
);
1871 var_t
*make_var
(char *name
)
1873 var_t
*v
= xmalloc
(sizeof
(var_t
));
1875 init_declspec
(&v
->declspec
, NULL
);
1878 init_loc_info
(&v
->loc_info
);
1879 v
->declonly
= FALSE
;
1883 static var_t
*copy_var
(var_t
*src
, char *name
, map_attrs_filter_t attr_filter
)
1885 var_t
*v
= xmalloc
(sizeof
(var_t
));
1887 v
->declspec
= src
->declspec
;
1888 v
->attrs
= map_attrs
(src
->attrs
, attr_filter
);
1889 v
->eval
= src
->eval
;
1890 v
->loc_info
= src
->loc_info
;
1894 static declarator_list_t
*append_declarator
(declarator_list_t
*list
, declarator_t
*d
)
1896 if
(!d
) return list
;
1898 list
= xmalloc
(sizeof
(*list
));
1901 list_add_tail
(list
, &d
->entry
);
1905 static declarator_t
*make_declarator
(var_t
*var
)
1907 declarator_t
*d
= xmalloc
(sizeof
(*d
));
1908 d
->var
= var ? var
: make_var
(NULL
);
1915 static type_t
*make_safearray
(type_t
*type
)
1917 decl_spec_t ds
= {.type
= type
};
1918 ds.type
= type_new_alias
(&ds
, "SAFEARRAY");
1919 return type_new_array
(NULL
, &ds
, TRUE
, 0, NULL
, NULL
);
1922 static typelib_t
*make_library
(const char *name
, const attr_list_t
*attrs
)
1924 typelib_t
*typelib
= xmalloc
(sizeof
(*typelib
));
1925 memset
(typelib
, 0, sizeof
(*typelib
));
1926 typelib
->name
= xstrdup
(name
);
1927 typelib
->attrs
= attrs
;
1928 list_init
( &typelib
->importlibs
);
1932 static int hash_ident
(const char *name
)
1934 const char *p
= name
;
1936 /* a simple sum hash is probably good enough */
1941 return sum
& (HASHMAX
-1);
1944 /***** type repository *****/
1946 static struct namespace
*find_sub_namespace
(struct namespace
*namespace
, const char *name
)
1948 struct namespace
*cur
;
1950 LIST_FOR_EACH_ENTRY
(cur
, &namespace
->children
, struct namespace
, entry
) {
1951 if
(!strcmp
(cur
->name
, name
))
1958 static void push_namespace
(const char *name
)
1960 struct namespace
*namespace
;
1962 namespace
= find_sub_namespace
(current_namespace
, name
);
1964 namespace
= xmalloc
(sizeof
(*namespace
));
1965 namespace
->name
= xstrdup
(name
);
1966 namespace
->parent
= current_namespace
;
1967 list_add_tail
(¤t_namespace
->children
, &namespace
->entry
);
1968 list_init
(&namespace
->children
);
1969 memset
(namespace
->type_hash
, 0, sizeof
(namespace
->type_hash
));
1972 current_namespace
= namespace
;
1975 static void pop_namespace
(const char *name
)
1977 assert
(!strcmp
(current_namespace
->name
, name
) && current_namespace
->parent
);
1978 current_namespace
= current_namespace
->parent
;
1981 static void push_parameters_namespace
(const char *name
)
1983 struct namespace
*namespace
;
1985 if
(!(namespace
= find_sub_namespace
(current_namespace
, name
)))
1987 namespace
= xmalloc
(sizeof
(*namespace
));
1988 namespace
->name
= xstrdup
(name
);
1989 namespace
->parent
= current_namespace
;
1990 list_add_tail
(¤t_namespace
->children
, &namespace
->entry
);
1991 list_init
(&namespace
->children
);
1992 memset
(namespace
->type_hash
, 0, sizeof
(namespace
->type_hash
));
1995 parameters_namespace
= namespace
;
1998 static void pop_parameters_namespace
(const char *name
)
2000 assert
(!strcmp
(parameters_namespace
->name
, name
) && parameters_namespace
->parent
);
2001 parameters_namespace
= NULL
;
2011 type_t
*reg_type
(type_t
*type
, const char *name
, struct namespace
*namespace
, int t
)
2016 error_loc
("registering named type without name\n");
2020 namespace
= &global_namespace
;
2021 hash
= hash_ident
(name
);
2022 nt
= xmalloc
(sizeof
(struct rtype
));
2024 if
(is_global_namespace
(namespace
))
2025 type
->c_name
= name
;
2027 type
->c_name
= format_namespace
(namespace
, "__x_", "_C", name
, use_abi_namespace ?
"ABI" : NULL
);
2030 nt
->next
= namespace
->type_hash
[hash
];
2031 namespace
->type_hash
[hash
] = nt
;
2035 static type_t
*reg_typedefs
(decl_spec_t
*decl_spec
, declarator_list_t
*decls
, attr_list_t
*attrs
)
2038 type_t
*type
= decl_spec
->type
;
2040 if
(is_attr
(attrs
, ATTR_UUID
) && !is_attr
(attrs
, ATTR_PUBLIC
))
2041 attrs
= append_attr
( attrs
, make_attr
(ATTR_PUBLIC
) );
2043 /* We must generate names for tagless enum, struct or union.
2044 Typedef-ing a tagless enum, struct or union means we want the typedef
2045 to be included in a library hence the public attribute. */
2046 if
(type_get_type_detect_alias
(type
) == TYPE_ENUM ||
2047 type_get_type_detect_alias
(type
) == TYPE_STRUCT ||
2048 type_get_type_detect_alias
(type
) == TYPE_UNION ||
2049 type_get_type_detect_alias
(type
) == TYPE_ENCAPSULATED_UNION
)
2053 type
->name
= gen_name
();
2054 if
(!is_attr
(attrs
, ATTR_PUBLIC
))
2055 attrs
= append_attr
(attrs
, make_attr
(ATTR_PUBLIC
));
2058 /* replace existing attributes when generating a typelib */
2060 type
->attrs
= attrs
;
2063 LIST_FOR_EACH_ENTRY
( decl
, decls
, declarator_t
, entry
)
2066 if
(decl
->var
->name
) {
2070 cur
= find_type
(decl
->var
->name
, current_namespace
, 0);
2073 * MIDL allows shadowing types that are declared in imported files.
2074 * We don't throw an error in this case and instead add a new type
2075 * (which is earlier on the list in hash table, so it will be used
2076 * instead of shadowed type).
2078 * FIXME: We may consider string separated type tables for each input
2079 * for cleaner solution.
2081 if
(cur
&& input_name
== cur
->loc_info.input_name
)
2082 error_loc
("%s: redefinition error; original definition was at %s:%d\n",
2083 cur
->name
, cur
->loc_info.input_name
,
2084 cur
->loc_info.line_number
);
2086 name
= declare_var
(attrs
, decl_spec
, decl
, 0);
2087 cur
= type_new_alias
(&name
->declspec
, name
->name
);
2090 reg_type
(cur
, cur
->name
, current_namespace
, 0);
2096 type_t
*find_type
(const char *name
, struct namespace
*namespace
, int t
)
2100 if
(namespace
&& namespace
!= &global_namespace
) {
2101 for
(cur
= namespace
->type_hash
[hash_ident
(name
)]; cur
; cur
= cur
->next
) {
2102 if
(cur
->t
== t
&& !strcmp
(cur
->name
, name
))
2106 for
(cur
= global_namespace.type_hash
[hash_ident
(name
)]; cur
; cur
= cur
->next
) {
2107 if
(cur
->t
== t
&& !strcmp
(cur
->name
, name
))
2113 static type_t
*find_type_or_error
(struct namespace
*namespace
, const char *name
)
2116 if
(!(type
= find_type
(name
, namespace
, 0)) &&
2117 !(type
= find_type
(name
, parameters_namespace
, 0)))
2119 error_loc
("type '%s' not found in %s namespace\n", name
, namespace
&& namespace
->name ? namespace
->name
: "global");
2125 static struct namespace
*find_namespace_or_error
(struct namespace
*parent
, const char *name
)
2127 struct namespace
*namespace
= NULL
;
2130 error_loc
("namespaces are only supported in winrt mode.\n");
2131 else if
(!(namespace
= find_sub_namespace
(parent
, name
)))
2132 error_loc
("namespace '%s' not found in '%s'\n", name
, parent
->name
);
2137 int is_type
(const char *name
)
2139 return find_type
(name
, current_namespace
, 0) != NULL ||
2140 find_type
(name
, parameters_namespace
, 0);
2143 type_t
*get_type
(enum type_type type
, char *name
, struct namespace
*namespace
, int t
)
2147 namespace
= &global_namespace
;
2149 tp
= find_type
(name
, namespace
, t
);
2155 tp
= make_type
(type
);
2157 tp
->namespace
= namespace
;
2158 if
(!name
) return tp
;
2159 return reg_type
(tp
, name
, namespace
, t
);
2162 /***** constant repository *****/
2167 struct rconst
*next
;
2170 struct rconst
*const_hash
[HASHMAX
];
2172 static var_t
*reg_const
(var_t
*var
)
2177 error_loc
("registering constant without name\n");
2180 hash
= hash_ident
(var
->name
);
2181 nc
= xmalloc
(sizeof
(struct rconst
));
2182 nc
->name
= var
->name
;
2184 nc
->next
= const_hash
[hash
];
2185 const_hash
[hash
] = nc
;
2189 var_t
*find_const
(const char *name
, int f
)
2191 struct rconst
*cur
= const_hash
[hash_ident
(name
)];
2192 while
(cur
&& strcmp
(cur
->name
, name
))
2195 if
(f
) error_loc
("constant '%s' not found\n", name
);
2201 char *gen_name
(void)
2203 static unsigned long n
= 0;
2204 static const char *file_id
;
2208 char *dst
= dup_basename
(input_idl_name
, ".idl");
2212 if
(! isalnum
((unsigned char) *dst
))
2215 return strmake
("__WIDL_%s_generated_name_%08lX", file_id
, n
++);
2220 unsigned int dce_compatible
: 1;
2221 unsigned int acf
: 1;
2222 unsigned int multiple
: 1;
2224 unsigned int on_interface
: 1;
2225 unsigned int on_function
: 1;
2226 unsigned int on_arg
: 1;
2227 unsigned int on_type
: 1;
2228 unsigned int on_enum
: 1;
2229 unsigned int on_enum_member
: 1;
2230 unsigned int on_struct
: 2;
2231 unsigned int on_union
: 1;
2232 unsigned int on_field
: 1;
2233 unsigned int on_library
: 1;
2234 unsigned int on_dispinterface
: 1;
2235 unsigned int on_module
: 1;
2236 unsigned int on_coclass
: 1;
2237 unsigned int on_apicontract
: 1;
2238 unsigned int on_runtimeclass
: 1;
2239 const char *display_name
;
2242 struct allowed_attr allowed_attr
[] =
2244 /* attr { D ACF M I Fn ARG T En Enm St Un Fi L DI M C AC R <display name> } */
2245 /* ATTR_ACTIVATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "activatable" },
2246 /* ATTR_AGGREGATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "aggregatable" },
2247 /* ATTR_ALLOCATE */ { 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "allocate" },
2248 /* ATTR_ANNOTATION */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "annotation" },
2249 /* ATTR_APPOBJECT */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "appobject" },
2250 /* ATTR_ASYNC */ { 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "async" },
2251 /* ATTR_ASYNCUUID */ { 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "async_uuid" },
2252 /* ATTR_AUTO_HANDLE */ { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "auto_handle" },
2253 /* ATTR_BINDABLE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "bindable" },
2254 /* ATTR_BROADCAST */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "broadcast" },
2255 /* ATTR_CALLAS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "call_as" },
2256 /* ATTR_CALLCONV */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
},
2257 /* ATTR_CASE */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "case" },
2258 /* ATTR_CODE */ { 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "code" },
2259 /* ATTR_COMMSTATUS */ { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "comm_status" },
2260 /* ATTR_CONTEXTHANDLE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "context_handle" },
2261 /* ATTR_CONTRACT */ { 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, "contract" },
2262 /* ATTR_CONTRACTVERSION */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, "contractversion" },
2263 /* ATTR_CONTROL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, "control" },
2264 /* ATTR_CUSTOM */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, "custom" },
2265 /* ATTR_DECODE */ { 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "decode" },
2266 /* ATTR_DEFAULT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "default" },
2267 /* ATTR_DEFAULTBIND */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultbind" },
2268 /* ATTR_DEFAULTCOLLELEM */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultcollelem" },
2269 /* ATTR_DEFAULTVALUE */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultvalue" },
2270 /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "defaultvtable" },
2271 /* ATTR_DISABLECONSISTENCYCHECK */{ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "disable_consistency_check" },
2272 /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, NULL
},
2273 /* ATTR_DISPLAYBIND */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "displaybind" },
2274 /* ATTR_DLLNAME */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "dllname" },
2275 /* ATTR_DUAL */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "dual" },
2276 /* ATTR_ENABLEALLOCATE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "enable_allocate" },
2277 /* ATTR_ENCODE */ { 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "encode" },
2278 /* ATTR_ENDPOINT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "endpoint" },
2279 /* ATTR_ENTRY */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "entry" },
2280 /* ATTR_EVENTADD */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "eventadd" },
2281 /* ATTR_EVENTREMOVE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "eventremove" },
2282 /* ATTR_EXCLUSIVETO */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "exclusive_to" },
2283 /* ATTR_EXPLICIT_HANDLE */ { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "explicit_handle" },
2284 /* ATTR_FAULTSTATUS */ { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "fault_status" },
2285 /* ATTR_FLAGS */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "flags" },
2286 /* ATTR_FORCEALLOCATE */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "force_allocate" },
2287 /* ATTR_HANDLE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "handle" },
2288 /* ATTR_HELPCONTEXT */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "helpcontext" },
2289 /* ATTR_HELPFILE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "helpfile" },
2290 /* ATTR_HELPSTRING */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "helpstring" },
2291 /* ATTR_HELPSTRINGCONTEXT */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "helpstringcontext" },
2292 /* ATTR_HELPSTRINGDLL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "helpstringdll" },
2293 /* ATTR_HIDDEN */ { 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, "hidden" },
2294 /* ATTR_ID */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, "id" },
2295 /* ATTR_IDEMPOTENT */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "idempotent" },
2296 /* ATTR_IGNORE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "ignore" },
2297 /* ATTR_IIDIS */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "iid_is" },
2298 /* ATTR_IMMEDIATEBIND */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "immediatebind" },
2299 /* ATTR_IMPLICIT_HANDLE */ { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "implicit_handle" },
2300 /* ATTR_IN */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "in" },
2301 /* ATTR_INPUTSYNC */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inputsync" },
2302 /* ATTR_LENGTHIS */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "length_is" },
2303 /* ATTR_LIBLCID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "lcid" },
2304 /* ATTR_LICENSED */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "licensed" },
2305 /* ATTR_LOCAL */ { 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "local" },
2306 /* ATTR_MARSHALING_BEHAVIOR */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "marshaling_behavior" },
2307 /* ATTR_MAYBE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "maybe" },
2308 /* ATTR_MESSAGE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "message" },
2309 /* ATTR_NOCODE */ { 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nocode" },
2310 /* ATTR_NONBROWSABLE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonbrowsable" },
2311 /* ATTR_NONCREATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "noncreatable" },
2312 /* ATTR_NONEXTENSIBLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonextensible" },
2313 /* ATTR_NOTIFY */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "notify" },
2314 /* ATTR_NOTIFYFLAG */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "notify_flag" },
2315 /* ATTR_OBJECT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "object" },
2316 /* ATTR_ODL */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "odl" },
2317 /* ATTR_OLEAUTOMATION */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "oleautomation" },
2318 /* ATTR_OPTIMIZE */ { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optimize" },
2319 /* ATTR_OPTIONAL */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optional" },
2320 /* ATTR_OUT */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "out" },
2321 /* ATTR_PARAMLCID */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "lcid" },
2322 /* ATTR_PARTIALIGNORE */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "partial_ignore" },
2323 /* ATTR_POINTERDEFAULT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "pointer_default" },
2324 /* ATTR_POINTERTYPE */ { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "ref, unique or ptr" },
2325 /* ATTR_PROGID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "progid" },
2326 /* ATTR_PROPGET */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propget" },
2327 /* ATTR_PROPPUT */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propput" },
2328 /* ATTR_PROPPUTREF */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propputref" },
2329 /* ATTR_PROXY */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "proxy" },
2330 /* ATTR_PUBLIC */ { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "public" },
2331 /* ATTR_RANGE */ { 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "range" },
2332 /* ATTR_READONLY */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "readonly" },
2333 /* ATTR_REPRESENTAS */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "represent_as" },
2334 /* ATTR_REQUESTEDIT */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "requestedit" },
2335 /* ATTR_RESTRICTED */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, "restricted" },
2336 /* ATTR_RETVAL */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "retval" },
2337 /* ATTR_SIZEIS */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "size_is" },
2338 /* ATTR_SOURCE */ { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "source" },
2339 /* ATTR_STATIC */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "static" },
2340 /* ATTR_STRICTCONTEXTHANDLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "strict_context_handle" },
2341 /* ATTR_STRING */ { 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "string" },
2342 /* ATTR_SWITCHIS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "switch_is" },
2343 /* ATTR_SWITCHTYPE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "switch_type" },
2344 /* ATTR_THREADING */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, "threading" },
2345 /* ATTR_TRANSMITAS */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "transmit_as" },
2346 /* ATTR_UIDEFAULT */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "uidefault" },
2347 /* ATTR_USESGETLASTERROR */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "usesgetlasterror" },
2348 /* ATTR_USERMARSHAL */ { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "user_marshal" },
2349 /* ATTR_UUID */ { 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, "uuid" },
2350 /* ATTR_V1ENUM */ { 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "v1_enum" },
2351 /* ATTR_VARARG */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "vararg" },
2352 /* ATTR_VERSION */ { 1, 0, 0, 1, 0, 0, 1, 1, 0, 2, 0, 0, 1, 0, 0, 1, 0, 1, "version" },
2353 /* ATTR_VIPROGID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "vi_progid" },
2354 /* ATTR_WIREMARSHAL */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "wire_marshal" },
2357 static attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
)
2359 attr_t
*attr_existing
;
2360 if
(!attr
) return list
;
2363 list
= xmalloc
( sizeof
(*list
) );
2366 if
(!allowed_attr
[attr
->type
].multiple
)
2368 LIST_FOR_EACH_ENTRY
(attr_existing
, list
, attr_t
, entry
)
2369 if
(attr_existing
->type
== attr
->type
)
2371 parser_warning
("duplicate attribute %s\n", get_attr_display_name
(attr
->type
));
2372 /* use the last attribute, like MIDL does */
2373 list_remove
(&attr_existing
->entry
);
2377 list_add_tail
( list
, &attr
->entry
);
2381 const char *get_attr_display_name
(enum attr_type type
)
2383 return allowed_attr
[type
].display_name
;
2386 attr_list_t
*check_interface_attrs
(const char *name
, attr_list_t
*attrs
)
2389 if
(!attrs
) return attrs
;
2390 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2392 if
(!allowed_attr
[attr
->type
].on_interface
)
2393 error_loc
("inapplicable attribute %s for interface %s\n",
2394 allowed_attr
[attr
->type
].display_name
, name
);
2395 if
(attr
->type
== ATTR_IMPLICIT_HANDLE
)
2397 const var_t
*var
= attr
->u.pval
;
2398 if
(type_get_type
( var
->declspec.type
) == TYPE_BASIC
&&
2399 type_basic_get_type
( var
->declspec.type
) == TYPE_BASIC_HANDLE
)
2401 if
(is_aliaschain_attr
( var
->declspec.type
, ATTR_HANDLE
))
2403 error_loc
("attribute %s requires a handle type in interface %s\n",
2404 allowed_attr
[attr
->type
].display_name
, name
);
2410 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
)
2413 if
(!attrs
) return attrs
;
2414 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2416 if
(!allowed_attr
[attr
->type
].on_function
)
2417 error_loc
("inapplicable attribute %s for function %s\n",
2418 allowed_attr
[attr
->type
].display_name
, name
);
2423 static void check_arg_attrs
(const var_t
*arg
)
2429 LIST_FOR_EACH_ENTRY
(attr
, arg
->attrs
, const attr_t
, entry
)
2431 if
(!allowed_attr
[attr
->type
].on_arg
)
2432 error_loc
("inapplicable attribute %s for argument %s\n",
2433 allowed_attr
[attr
->type
].display_name
, arg
->name
);
2438 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
)
2441 if
(!attrs
) return attrs
;
2442 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2444 if
(!allowed_attr
[attr
->type
].on_type
)
2445 error_loc
("inapplicable attribute %s for typedef\n",
2446 allowed_attr
[attr
->type
].display_name
);
2451 static attr_list_t
*check_enum_attrs
(attr_list_t
*attrs
)
2454 if
(!attrs
) return attrs
;
2455 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2457 if
(!allowed_attr
[attr
->type
].on_enum
)
2458 error_loc
("inapplicable attribute %s for enum\n",
2459 allowed_attr
[attr
->type
].display_name
);
2464 static attr_list_t
*check_enum_member_attrs
(attr_list_t
*attrs
)
2467 if
(!attrs
) return attrs
;
2468 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2470 if
(!allowed_attr
[attr
->type
].on_enum_member
)
2471 error_loc
("inapplicable attribute %s for enum member\n",
2472 allowed_attr
[attr
->type
].display_name
);
2477 static attr_list_t
*check_struct_attrs
(attr_list_t
*attrs
)
2479 int mask
= winrt_mode ?
3 : 1;
2481 if
(!attrs
) return attrs
;
2482 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2484 if
(!(allowed_attr
[attr
->type
].on_struct
& mask
))
2485 error_loc
("inapplicable attribute %s for struct\n",
2486 allowed_attr
[attr
->type
].display_name
);
2491 static attr_list_t
*check_union_attrs
(attr_list_t
*attrs
)
2494 if
(!attrs
) return attrs
;
2495 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2497 if
(!allowed_attr
[attr
->type
].on_union
)
2498 error_loc
("inapplicable attribute %s for union\n",
2499 allowed_attr
[attr
->type
].display_name
);
2504 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
)
2507 if
(!attrs
) return attrs
;
2508 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2510 if
(!allowed_attr
[attr
->type
].on_field
)
2511 error_loc
("inapplicable attribute %s for field %s\n",
2512 allowed_attr
[attr
->type
].display_name
, name
);
2517 static attr_list_t
*check_library_attrs
(const char *name
, attr_list_t
*attrs
)
2520 if
(!attrs
) return attrs
;
2521 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2523 if
(!allowed_attr
[attr
->type
].on_library
)
2524 error_loc
("inapplicable attribute %s for library %s\n",
2525 allowed_attr
[attr
->type
].display_name
, name
);
2530 attr_list_t
*check_dispiface_attrs
(const char *name
, attr_list_t
*attrs
)
2533 if
(!attrs
) return attrs
;
2534 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2536 if
(!allowed_attr
[attr
->type
].on_dispinterface
)
2537 error_loc
("inapplicable attribute %s for dispinterface %s\n",
2538 allowed_attr
[attr
->type
].display_name
, name
);
2543 attr_list_t
*check_module_attrs
(const char *name
, attr_list_t
*attrs
)
2546 if
(!attrs
) return attrs
;
2547 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2549 if
(!allowed_attr
[attr
->type
].on_module
)
2550 error_loc
("inapplicable attribute %s for module %s\n",
2551 allowed_attr
[attr
->type
].display_name
, name
);
2556 attr_list_t
*check_coclass_attrs
(const char *name
, attr_list_t
*attrs
)
2559 if
(!attrs
) return attrs
;
2560 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2562 if
(!allowed_attr
[attr
->type
].on_coclass
)
2563 error_loc
("inapplicable attribute %s for coclass %s\n",
2564 allowed_attr
[attr
->type
].display_name
, name
);
2569 attr_list_t
*check_runtimeclass_attrs
(const char *name
, attr_list_t
*attrs
)
2572 if
(!attrs
) return attrs
;
2573 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2574 if
(!allowed_attr
[attr
->type
].on_runtimeclass
)
2575 error_loc
("inapplicable attribute %s for runtimeclass %s\n",
2576 allowed_attr
[attr
->type
].display_name
, name
);
2580 attr_list_t
*check_apicontract_attrs
(const char *name
, attr_list_t
*attrs
)
2583 if
(!attrs
) return attrs
;
2584 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2585 if
(!allowed_attr
[attr
->type
].on_apicontract
)
2586 error_loc
("inapplicable attribute %s for apicontract %s\n",
2587 allowed_attr
[attr
->type
].display_name
, name
);
2591 static int is_allowed_conf_type
(const type_t
*type
)
2593 switch
(type_get_type
(type
))
2598 switch
(type_basic_get_type
(type
))
2600 case TYPE_BASIC_INT8
:
2601 case TYPE_BASIC_INT16
:
2602 case TYPE_BASIC_INT32
:
2603 case TYPE_BASIC_INT64
:
2604 case TYPE_BASIC_INT
:
2605 case TYPE_BASIC_LONG
:
2606 case TYPE_BASIC_CHAR
:
2607 case TYPE_BASIC_HYPER
:
2608 case TYPE_BASIC_BYTE
:
2609 case TYPE_BASIC_WCHAR
:
2615 /* shouldn't get here because of type_get_type call above */
2620 case TYPE_ENCAPSULATED_UNION
:
2627 case TYPE_INTERFACE
:
2629 case TYPE_RUNTIMECLASS
:
2631 case TYPE_APICONTRACT
:
2632 case TYPE_PARAMETERIZED_TYPE
:
2633 case TYPE_PARAMETER
:
2634 /* not supposed to be here */
2641 static int is_ptr_guid_type
(const type_t
*type
)
2643 /* first, make sure it is a pointer to something */
2644 if
(!is_ptr
(type
)) return FALSE
;
2646 /* second, make sure it is a pointer to something of size sizeof(GUID),
2648 return
(type_memsize
(type_pointer_get_ref_type
(type
)) == 16);
2651 static void check_conformance_expr_list
(const char *attr_name
, const var_t
*arg
, const type_t
*container_type
, expr_list_t
*expr_list
)
2654 struct expr_loc expr_loc
;
2656 expr_loc.attr
= attr_name
;
2657 if
(expr_list
) LIST_FOR_EACH_ENTRY
(dim
, expr_list
, expr_t
, entry
)
2659 if
(dim
->type
!= EXPR_VOID
)
2661 const type_t
*expr_type
= expr_resolve_type
(&expr_loc
, container_type
, dim
);
2662 if
(!is_allowed_conf_type
(expr_type
))
2663 error_loc_info
(&arg
->loc_info
, "expression must resolve to integral type <= 32bits for attribute %s\n",
2669 static void check_remoting_fields
(const var_t
*var
, type_t
*type
);
2671 /* checks that properties common to fields and arguments are consistent */
2672 static void check_field_common
(const type_t
*container_type
,
2673 const char *container_name
, const var_t
*arg
)
2675 type_t
*type
= arg
->declspec.type
;
2677 const char *container_type_name
;
2678 const char *var_type
;
2680 switch
(type_get_type
(container_type
))
2683 container_type_name
= "struct";
2687 container_type_name
= "union";
2690 case TYPE_ENCAPSULATED_UNION
:
2691 container_type_name
= "encapsulated union";
2695 container_type_name
= "function";
2696 var_type
= "parameter";
2699 /* should be no other container types */
2704 if
(is_attr
(arg
->attrs
, ATTR_LENGTHIS
) &&
2705 (is_attr
(arg
->attrs
, ATTR_STRING
) || is_aliaschain_attr
(arg
->declspec.type
, ATTR_STRING
)))
2706 error_loc_info
(&arg
->loc_info
,
2707 "string and length_is specified for argument %s are mutually exclusive attributes\n",
2710 if
(is_attr
(arg
->attrs
, ATTR_SIZEIS
))
2712 expr_list_t
*size_is_exprs
= get_attrp
(arg
->attrs
, ATTR_SIZEIS
);
2713 check_conformance_expr_list
("size_is", arg
, container_type
, size_is_exprs
);
2715 if
(is_attr
(arg
->attrs
, ATTR_LENGTHIS
))
2717 expr_list_t
*length_is_exprs
= get_attrp
(arg
->attrs
, ATTR_LENGTHIS
);
2718 check_conformance_expr_list
("length_is", arg
, container_type
, length_is_exprs
);
2720 if
(is_attr
(arg
->attrs
, ATTR_IIDIS
))
2722 struct expr_loc expr_loc
;
2723 expr_t
*expr
= get_attrp
(arg
->attrs
, ATTR_IIDIS
);
2724 if
(expr
->type
!= EXPR_VOID
)
2726 const type_t
*expr_type
;
2728 expr_loc.attr
= "iid_is";
2729 expr_type
= expr_resolve_type
(&expr_loc
, container_type
, expr
);
2730 if
(!expr_type ||
!is_ptr_guid_type
(expr_type
))
2731 error_loc_info
(&arg
->loc_info
, "expression must resolve to pointer to GUID type for attribute iid_is\n");
2734 if
(is_attr
(arg
->attrs
, ATTR_SWITCHIS
))
2736 struct expr_loc expr_loc
;
2737 expr_t
*expr
= get_attrp
(arg
->attrs
, ATTR_SWITCHIS
);
2738 if
(expr
->type
!= EXPR_VOID
)
2740 const type_t
*expr_type
;
2742 expr_loc.attr
= "switch_is";
2743 expr_type
= expr_resolve_type
(&expr_loc
, container_type
, expr
);
2744 if
(!expr_type ||
!is_allowed_conf_type
(expr_type
))
2745 error_loc_info
(&arg
->loc_info
, "expression must resolve to integral type <= 32bits for attribute %s\n",
2754 switch
(typegen_detect_type
(type
, arg
->attrs
, TDT_IGNORE_STRINGS
))
2758 check_remoting_fields
(arg
, type
);
2762 const char *reason
= "is invalid";
2763 switch
(type_get_type
(type
))
2766 reason
= "cannot derive from void *";
2769 reason
= "cannot be a function pointer";
2772 reason
= "cannot be a bit-field";
2775 reason
= "cannot be a class";
2777 case TYPE_INTERFACE
:
2778 reason
= "cannot be a non-pointer to an interface";
2781 reason
= "cannot be a module";
2786 error_loc_info
(&arg
->loc_info
, "%s \'%s\' of %s \'%s\' %s\n",
2787 var_type
, arg
->name
, container_type_name
, container_name
, reason
);
2790 case TGT_CTXT_HANDLE
:
2791 case TGT_CTXT_HANDLE_POINTER
:
2792 if
(type_get_type
(container_type
) != TYPE_FUNCTION
)
2793 error_loc_info
(&arg
->loc_info
,
2794 "%s \'%s\' of %s \'%s\' cannot be a context handle\n",
2795 var_type
, arg
->name
, container_type_name
,
2800 const type_t
*t
= type
;
2802 t
= type_pointer_get_ref_type
(t
);
2803 if
(is_aliaschain_attr
(t
, ATTR_RANGE
))
2804 warning_loc_info
(&arg
->loc_info
, "%s: range not verified for a string of ranged types\n", arg
->name
);
2808 type
= type_pointer_get_ref_type
(type
);
2812 type
= type_array_get_element_type
(type
);
2816 type
= type_get_real_type
(type
);
2817 if
(!type_is_complete
(type
))
2819 error_loc_info
(&arg
->loc_info
, "undefined type declaration \"enum %s\"\n", type
->name
);
2822 case TGT_IFACE_POINTER
:
2828 } while
(more_to_do
);
2831 static void check_remoting_fields
(const var_t
*var
, type_t
*type
)
2834 const var_list_t
*fields
= NULL
;
2836 type
= type_get_real_type
(type
);
2841 type
->checked
= TRUE
;
2843 if
(type_get_type
(type
) == TYPE_STRUCT
)
2845 if
(type_is_complete
(type
))
2846 fields
= type_struct_get_fields
(type
);
2848 error_loc_info
(&var
->loc_info
, "undefined type declaration \"struct %s\"\n", type
->name
);
2850 else if
(type_get_type
(type
) == TYPE_UNION || type_get_type
(type
) == TYPE_ENCAPSULATED_UNION
)
2852 if
(type_is_complete
(type
))
2853 fields
= type_union_get_cases
(type
);
2855 error_loc_info
(&var
->loc_info
, "undefined type declaration \"union %s\"\n", type
->name
);
2858 if
(fields
) LIST_FOR_EACH_ENTRY
( field
, fields
, const var_t
, entry
)
2859 if
(field
->declspec.type
) check_field_common
(type
, type
->name
, field
);
2862 /* checks that arguments for a function make sense for marshalling and unmarshalling */
2863 static void check_remoting_args
(const var_t
*func
)
2865 const char *funcname
= func
->name
;
2868 if
(!type_function_get_args
(func
->declspec.type
))
2871 LIST_FOR_EACH_ENTRY
( arg
, type_function_get_args
(func
->declspec.type
), const var_t
, entry
)
2873 const type_t
*type
= arg
->declspec.type
;
2875 /* check that [out] parameters have enough pointer levels */
2876 if
(is_attr
(arg
->attrs
, ATTR_OUT
))
2878 switch
(typegen_detect_type
(type
, arg
->attrs
, TDT_ALL_TYPES
))
2885 case TGT_CTXT_HANDLE
:
2887 error_loc_info
(&arg
->loc_info
, "out parameter \'%s\' of function \'%s\' is not a pointer\n", arg
->name
, funcname
);
2889 case TGT_IFACE_POINTER
:
2890 error_loc_info
(&arg
->loc_info
, "out interface pointer \'%s\' of function \'%s\' is not a double pointer\n", arg
->name
, funcname
);
2895 /* needs conformance or fixed dimension */
2896 if
(type_array_has_conformance
(type
) &&
2897 type_array_get_conformance
(type
)->type
!= EXPR_VOID
) break
;
2898 if
(!type_array_has_conformance
(type
) && type_array_get_dim
(type
)) break
;
2900 if
(is_attr
( arg
->attrs
, ATTR_IN
)) break
;
2901 error_loc_info
(&arg
->loc_info
, "out parameter \'%s\' of function \'%s\' cannot be an unsized string\n", arg
->name
, funcname
);
2904 /* already error'd before we get here */
2905 case TGT_CTXT_HANDLE_POINTER
:
2913 check_field_common
(func
->declspec.type
, funcname
, arg
);
2916 if
(type_get_type
(type_function_get_rettype
(func
->declspec.type
)) != TYPE_VOID
)
2920 var.declspec.type
= type_function_get_rettype
(func
->declspec.type
);
2921 var.name
= xstrdup
("return value");
2922 check_field_common
(func
->declspec.type
, funcname
, &var
);
2927 static void add_explicit_handle_if_necessary
(const type_t
*iface
, var_t
*func
)
2929 unsigned char explicit_fc
, implicit_fc
;
2931 /* check for a defined binding handle */
2932 if
(!get_func_handle_var
( iface
, func
, &explicit_fc
, &implicit_fc
) ||
!explicit_fc
)
2934 /* no explicit handle specified so add
2935 * "[in] handle_t IDL_handle" as the first parameter to the
2937 var_t
*idl_handle
= make_var
(xstrdup
("IDL_handle"));
2938 idl_handle
->attrs
= append_attr
(NULL
, make_attr
(ATTR_IN
));
2939 idl_handle
->declspec.type
= find_type_or_error
(NULL
, "handle_t");
2940 type_function_add_head_arg
(func
->declspec.type
, idl_handle
);
2944 static void check_functions
(const type_t
*iface
, int is_inside_library
)
2946 const statement_t
*stmt
;
2947 /* check for duplicates */
2948 if
(is_attr
(iface
->attrs
, ATTR_DISPINTERFACE
))
2950 var_list_t
*methods
= type_dispiface_get_methods
(iface
);
2951 var_t
*func
, *func_iter
;
2953 if
(methods
) LIST_FOR_EACH_ENTRY
( func
, methods
, var_t
, entry
)
2955 LIST_FOR_EACH_ENTRY
( func_iter
, methods
, var_t
, entry
)
2957 if
(func
== func_iter
) break
;
2958 if
(strcmp
(func
->name
, func_iter
->name
)) continue
;
2959 if
(is_attr
(func
->attrs
, ATTR_EVENTADD
) != is_attr
(func_iter
->attrs
, ATTR_EVENTADD
)) continue
;
2960 if
(is_attr
(func
->attrs
, ATTR_EVENTREMOVE
) != is_attr
(func_iter
->attrs
, ATTR_EVENTREMOVE
)) continue
;
2961 if
(is_attr
(func
->attrs
, ATTR_PROPGET
) != is_attr
(func_iter
->attrs
, ATTR_PROPGET
)) continue
;
2962 if
(is_attr
(func
->attrs
, ATTR_PROPPUT
) != is_attr
(func_iter
->attrs
, ATTR_PROPPUT
)) continue
;
2963 if
(is_attr
(func
->attrs
, ATTR_PROPPUTREF
) != is_attr
(func_iter
->attrs
, ATTR_PROPPUTREF
)) continue
;
2964 error_loc_info
(&func
->loc_info
, "duplicated function \'%s\'\n", func
->name
);
2968 if
(is_attr
(iface
->attrs
, ATTR_EXPLICIT_HANDLE
))
2970 STATEMENTS_FOR_EACH_FUNC
( stmt
, type_iface_get_stmts
(iface
) )
2972 var_t
*func
= stmt
->u.var
;
2973 add_explicit_handle_if_necessary
(iface
, func
);
2976 if
(!is_inside_library
&& !is_attr
(iface
->attrs
, ATTR_LOCAL
))
2978 STATEMENTS_FOR_EACH_FUNC
( stmt
, type_iface_get_stmts
(iface
) )
2980 const var_t
*func
= stmt
->u.var
;
2981 if
(!is_attr
(func
->attrs
, ATTR_LOCAL
))
2982 check_remoting_args
(func
);
2987 static int async_iface_attrs
(attr_list_t
*attrs
, const attr_t
*attr
)
2993 case ATTR_ASYNCUUID
:
2994 append_attr
(attrs
, make_attrp
(ATTR_UUID
, attr
->u.pval
));
3001 static int arg_in_attrs
(attr_list_t
*attrs
, const attr_t
*attr
)
3003 return attr
->type
!= ATTR_OUT
&& attr
->type
!= ATTR_RETVAL
;
3006 static int arg_out_attrs
(attr_list_t
*attrs
, const attr_t
*attr
)
3008 return attr
->type
!= ATTR_IN
;
3011 static void check_async_uuid
(type_t
*iface
)
3013 statement_list_t
*stmts
= NULL
;
3015 type_t
*async_iface
;
3018 if
(!is_attr
(iface
->attrs
, ATTR_ASYNCUUID
)) return
;
3020 inherit
= type_iface_get_inherit
(iface
);
3021 if
(inherit
&& strcmp
(inherit
->name
, "IUnknown"))
3022 inherit
= type_iface_get_async_iface
(inherit
);
3024 error_loc
("async_uuid applied to an interface with incompatible parent\n");
3026 async_iface
= type_interface_declare
(strmake
("Async%s", iface
->name
), iface
->namespace
);
3028 STATEMENTS_FOR_EACH_FUNC
( stmt
, type_iface_get_stmts
(iface
) )
3030 var_t
*begin_func
, *finish_func
, *func
= stmt
->u.var
, *arg
;
3031 var_list_t
*begin_args
= NULL
, *finish_args
= NULL
, *args
;
3033 if
(is_attr
(func
->attrs
, ATTR_CALLAS
)) continue
;
3035 args
= type_function_get_args
(func
->declspec.type
);
3036 if
(args
) LIST_FOR_EACH_ENTRY
(arg
, args
, var_t
, entry
)
3038 if
(is_attr
(arg
->attrs
, ATTR_IN
) ||
!is_attr
(arg
->attrs
, ATTR_OUT
))
3039 begin_args
= append_var
(begin_args
, copy_var
(arg
, strdup
(arg
->name
), arg_in_attrs
));
3040 if
(is_attr
(arg
->attrs
, ATTR_OUT
))
3041 finish_args
= append_var
(finish_args
, copy_var
(arg
, strdup
(arg
->name
), arg_out_attrs
));
3044 begin_func
= copy_var
(func
, strmake
("Begin_%s", func
->name
), NULL
);
3045 begin_func
->declspec.type
= type_new_function
(begin_args
);
3046 begin_func
->declspec.type
->attrs
= func
->attrs
;
3047 begin_func
->declspec.type
->details.function
->retval
= func
->declspec.type
->details.function
->retval
;
3048 stmts
= append_statement
(stmts
, make_statement_declaration
(begin_func
));
3050 finish_func
= copy_var
(func
, strmake
("Finish_%s", func
->name
), NULL
);
3051 finish_func
->declspec.type
= type_new_function
(finish_args
);
3052 finish_func
->declspec.type
->attrs
= func
->attrs
;
3053 finish_func
->declspec.type
->details.function
->retval
= func
->declspec.type
->details.function
->retval
;
3054 stmts
= append_statement
(stmts
, make_statement_declaration
(finish_func
));
3057 type_interface_define
(async_iface
, map_attrs
(iface
->attrs
, async_iface_attrs
), inherit
, stmts
, NULL
);
3058 iface
->details.iface
->async_iface
= async_iface
->details.iface
->async_iface
= async_iface
;
3061 static void check_statements
(const statement_list_t
*stmts
, int is_inside_library
)
3063 const statement_t
*stmt
;
3065 if
(stmts
) LIST_FOR_EACH_ENTRY
(stmt
, stmts
, const statement_t
, entry
)
3067 switch
(stmt
->type
) {
3069 check_statements
(stmt
->u.lib
->stmts
, TRUE
);
3072 switch
(type_get_type
(stmt
->u.type
)) {
3073 case TYPE_INTERFACE
:
3074 check_functions
(stmt
->u.type
, is_inside_library
);
3078 error_loc
("coclass is not allowed in Windows Runtime mode\n");
3090 static void check_all_user_types
(const statement_list_t
*stmts
)
3092 const statement_t
*stmt
;
3095 if
(stmts
) LIST_FOR_EACH_ENTRY
(stmt
, stmts
, const statement_t
, entry
)
3097 if
(stmt
->type
== STMT_LIBRARY
)
3098 check_all_user_types
(stmt
->u.lib
->stmts
);
3099 else if
(stmt
->type
== STMT_TYPE
&& type_get_type
(stmt
->u.type
) == TYPE_INTERFACE
&&
3100 !is_local
(stmt
->u.type
->attrs
))
3102 const statement_t
*stmt_func
;
3103 STATEMENTS_FOR_EACH_FUNC
(stmt_func
, type_iface_get_stmts
(stmt
->u.type
)) {
3104 const var_t
*func
= stmt_func
->u.var
;
3105 if
(type_function_get_args
(func
->declspec.type
))
3106 LIST_FOR_EACH_ENTRY
( v
, type_function_get_args
(func
->declspec.type
), const var_t
, entry
)
3107 check_for_additional_prototype_types
(v
->declspec.type
);
3108 check_for_additional_prototype_types
(type_function_get_rettype
(func
->declspec.type
));
3114 int is_valid_uuid
(const char *s
)
3118 for
(i
= 0; i
< 36; ++i
)
3119 if
(i
== 8 || i
== 13 || i
== 18 || i
== 23)
3125 if
(!isxdigit
(s
[i
]))
3128 return s
[i
] == '\0';
3131 static statement_t
*make_statement
(enum statement_type type
)
3133 statement_t
*stmt
= xmalloc
(sizeof
(*stmt
));
3138 static statement_t
*make_statement_type_decl
(type_t
*type
)
3140 statement_t
*stmt
= make_statement
(STMT_TYPE
);
3141 stmt
->u.type
= type
;
3142 stmt
->declonly
= !type
->defined
;
3146 static statement_t
*make_statement_reference
(type_t
*type
)
3148 statement_t
*stmt
= make_statement
(STMT_TYPEREF
);
3149 stmt
->u.type
= type
;
3153 static statement_t
*make_statement_declaration
(var_t
*var
)
3155 statement_t
*stmt
= make_statement
(STMT_DECLARATION
);
3157 if
(var
->declspec.stgclass
== STG_EXTERN
&& var
->eval
)
3158 warning
("'%s' initialised and declared extern\n", var
->name
);
3159 if
(is_const_decl
(var
))
3164 else if
(type_get_type
(var
->declspec.type
) == TYPE_FUNCTION
)
3165 check_function_attrs
(var
->name
, var
->attrs
);
3166 else if
(var
->declspec.stgclass
== STG_NONE || var
->declspec.stgclass
== STG_REGISTER
)
3167 error_loc
("instantiation of data is illegal\n");
3171 static statement_t
*make_statement_library
(typelib_t
*typelib
)
3173 statement_t
*stmt
= make_statement
(STMT_LIBRARY
);
3174 stmt
->u.lib
= typelib
;
3178 static statement_t
*make_statement_pragma
(const char *str
)
3180 statement_t
*stmt
= make_statement
(STMT_PRAGMA
);
3185 static statement_t
*make_statement_cppquote
(const char *str
)
3187 statement_t
*stmt
= make_statement
(STMT_CPPQUOTE
);
3192 static statement_t
*make_statement_importlib
(const char *str
)
3194 statement_t
*stmt
= make_statement
(STMT_IMPORTLIB
);
3199 static statement_t
*make_statement_import
(const char *str
)
3201 statement_t
*stmt
= make_statement
(STMT_IMPORT
);
3206 static statement_t
*make_statement_module
(type_t
*type
)
3208 statement_t
*stmt
= make_statement
(STMT_MODULE
);
3209 stmt
->u.type
= type
;
3213 static statement_t
*make_statement_typedef
(declarator_list_t
*decls
, int declonly
)
3215 declarator_t
*decl
, *next
;
3217 type_list_t
**type_list
;
3219 if
(!decls
) return NULL
;
3221 stmt
= make_statement
(STMT_TYPEDEF
);
3222 stmt
->u.type_list
= NULL
;
3223 type_list
= &stmt
->u.type_list
;
3224 stmt
->declonly
= declonly
;
3226 LIST_FOR_EACH_ENTRY_SAFE
( decl
, next
, decls
, declarator_t
, entry
)
3228 var_t
*var
= decl
->var
;
3229 type_t
*type
= find_type_or_error
(current_namespace
, var
->name
);
3230 *type_list
= xmalloc
(sizeof
(type_list_t
));
3231 (*type_list
)->type
= type
;
3232 (*type_list
)->next
= NULL
;
3234 type_list
= &(*type_list
)->next
;
3242 static statement_list_t
*append_statements
(statement_list_t
*l1
, statement_list_t
*l2
)
3245 if
(!l1 || l1
== l2
) return l2
;
3246 list_move_tail
(l1
, l2
);
3250 static attr_list_t
*append_attribs
(attr_list_t
*l1
, attr_list_t
*l2
)
3253 if
(!l1 || l1
== l2
) return l2
;
3254 list_move_tail
(l1
, l2
);
3258 static statement_list_t
*append_statement
(statement_list_t
*list
, statement_t
*stmt
)
3260 if
(!stmt
) return list
;
3263 list
= xmalloc
( sizeof
(*list
) );
3266 list_add_tail
( list
, &stmt
->entry
);
3270 void init_loc_info
(loc_info_t
*i
)
3272 i
->input_name
= input_name ? input_name
: "stdin";
3273 i
->line_number
= line_number
;
3274 i
->near_text
= parser_text
;