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
41 static unsigned char pointer_default
= RPC_FC_UP
;
43 typedef
struct list typelist_t
;
55 typedef
struct _decl_spec_t
59 enum storage_class stgclass
;
62 typelist_t incomplete_types
= LIST_INIT
(incomplete_types
);
64 static void fix_incomplete
(void);
65 static void fix_incomplete_types
(type_t
*complete_type
);
67 static str_list_t
*append_str
(str_list_t
*list
, char *str
);
68 static attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
);
69 static attr_list_t
*append_attr_list
(attr_list_t
*new_list
, attr_list_t
*old_list
);
70 static decl_spec_t
*make_decl_spec
(type_t
*type
, decl_spec_t
*left
, decl_spec_t
*right
, attr_t
*attr
, enum storage_class stgclass
);
71 static attr_t
*make_attr
(enum attr_type type
);
72 static attr_t
*make_attrv
(enum attr_type type
, unsigned int val
);
73 static attr_t
*make_attrp
(enum attr_type type
, void *val
);
74 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
);
75 static array_dims_t
*append_array
(array_dims_t
*list
, expr_t
*expr
);
76 static var_t
*declare_var
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, const declarator_t
*decl
, int top
);
77 static var_list_t
*set_var_types
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_list_t
*decls
);
78 static ifref_list_t
*append_ifref
(ifref_list_t
*list
, ifref_t
*iface
);
79 static ifref_t
*make_ifref
(type_t
*iface
);
80 static var_list_t
*append_var_list
(var_list_t
*list
, var_list_t
*vars
);
81 static declarator_list_t
*append_declarator
(declarator_list_t
*list
, declarator_t
*p
);
82 static declarator_t
*make_declarator
(var_t
*var
);
83 static type_t
*make_safearray
(type_t
*type
);
84 static typelib_t
*make_library
(const char *name
, const attr_list_t
*attrs
);
85 static type_t
*append_ptrchain_type
(type_t
*ptrchain
, type_t
*type
);
86 static warning_list_t
*append_warning
(warning_list_t
*, int);
88 static type_t
*reg_typedefs
(decl_spec_t
*decl_spec
, var_list_t
*names
, attr_list_t
*attrs
);
89 static type_t
*find_type_or_error
(const char *name
, int t
);
90 static type_t
*find_type_or_error2
(char *name
, int t
);
92 static var_t
*reg_const
(var_t
*var
);
94 static void push_namespace
(const char *name
);
95 static void pop_namespace
(const char *name
);
97 static char *gen_name
(void);
98 static void check_arg_attrs
(const var_t
*arg
);
99 static void check_statements
(const statement_list_t
*stmts
, int is_inside_library
);
100 static void check_all_user_types
(const statement_list_t
*stmts
);
101 static attr_list_t
*check_iface_attrs
(const char *name
, attr_list_t
*attrs
);
102 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
);
103 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
);
104 static attr_list_t
*check_enum_attrs
(attr_list_t
*attrs
);
105 static attr_list_t
*check_struct_attrs
(attr_list_t
*attrs
);
106 static attr_list_t
*check_union_attrs
(attr_list_t
*attrs
);
107 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
);
108 static attr_list_t
*check_library_attrs
(const char *name
, attr_list_t
*attrs
);
109 static attr_list_t
*check_dispiface_attrs
(const char *name
, attr_list_t
*attrs
);
110 static attr_list_t
*check_module_attrs
(const char *name
, attr_list_t
*attrs
);
111 static attr_list_t
*check_coclass_attrs
(const char *name
, attr_list_t
*attrs
);
112 const char *get_attr_display_name
(enum attr_type type
);
113 static void add_explicit_handle_if_necessary
(const type_t
*iface
, var_t
*func
);
114 static void check_def
(const type_t
*t
);
116 static statement_t
*make_statement
(enum statement_type type
);
117 static statement_t
*make_statement_type_decl
(type_t
*type
);
118 static statement_t
*make_statement_reference
(type_t
*type
);
119 static statement_t
*make_statement_declaration
(var_t
*var
);
120 static statement_t
*make_statement_library
(typelib_t
*typelib
);
121 static statement_t
*make_statement_pragma
(const char *str
);
122 static statement_t
*make_statement_cppquote
(const char *str
);
123 static statement_t
*make_statement_importlib
(const char *str
);
124 static statement_t
*make_statement_module
(type_t
*type
);
125 static statement_t
*make_statement_typedef
(var_list_t
*names
);
126 static statement_t
*make_statement_import
(const char *str
);
127 static statement_list_t
*append_statement
(statement_list_t
*list
, statement_t
*stmt
);
128 static statement_list_t
*append_statements
(statement_list_t
*, statement_list_t
*);
129 static attr_list_t
*append_attribs
(attr_list_t
*, attr_list_t
*);
131 static struct namespace global_namespace
= {
132 NULL
, NULL
, LIST_INIT
(global_namespace.entry
), LIST_INIT
(global_namespace.children
)
135 static struct namespace
*current_namespace
= &global_namespace
;
140 attr_list_t
*attr_list
;
141 str_list_t
*str_list
;
143 expr_list_t
*expr_list
;
144 array_dims_t
*array_dims
;
147 var_list_t
*var_list
;
148 declarator_t
*declarator
;
149 declarator_list_t
*declarator_list
;
150 statement_t
*statement
;
151 statement_list_t
*stmt_list
;
153 warning_list_t
*warning_list
;
155 ifref_list_t
*ifref_list
;
160 interface_info_t ifinfo
;
162 struct _import_t
*import
;
163 struct _decl_spec_t
*declspec
;
164 enum storage_class stgclass
;
167 %token
<str
> aIDENTIFIER aPRAGMA
168 %token
<str
> aKNOWNTYPE
169 %token
<num
> aNUM aHEXNUM
171 %token
<str
> aSTRING aWSTRING aSQSTRING
176 %token EQUALITY INEQUALITY
177 %token GREATEREQUAL LESSEQUAL
178 %token LOGICALOR LOGICALAND
180 %token tAGGREGATABLE tALLOCATE tANNOTATION tAPPOBJECT tASYNC tASYNCUUID
181 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
182 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
183 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
184 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
185 %token tDECODE tDEFAULT tDEFAULTBIND
186 %token tDEFAULTCOLLELEM
188 %token tDEFAULTVTABLE
189 %token tDISABLECONSISTENCYCHECK tDISPLAYBIND
190 %token tDISPINTERFACE
191 %token tDLLNAME tDOUBLE tDUAL
192 %token tENABLEALLOCATE tENCODE tENDPOINT
193 %token tENTRY tENUM tERRORSTATUST
194 %token tEXPLICITHANDLE tEXTERN
196 %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 tINT3264 tINT64
213 %token tLENGTHIS tLIBRARY
214 %token tLICENSED tLOCAL
216 %token tMAYBE tMESSAGE
220 %token tNOCODE tNONBROWSABLE
222 %token tNONEXTENSIBLE
223 %token tNOTIFY tNOTIFYFLAG
225 %token tOBJECT tODL tOLEAUTOMATION
226 %token tOPTIMIZE tOPTIONAL
228 %token tPARTIALIGNORE tPASCAL
229 %token tPOINTERDEFAULT
230 %token tPRAGMA_WARNING
231 %token tPROGID tPROPERTIES
232 %token tPROPGET tPROPPUT tPROPPUTREF
236 %token tREADONLY tREF
237 %token tREGISTER tREPRESENTAS
244 %token tSIZEIS tSIZEOF
249 %token tSTRICTCONTEXTHANDLE
250 %token tSTRING tSTRUCT
251 %token tSWITCH tSWITCHIS tSWITCHTYPE
252 %token tTHREADING tTRANSMITAS
255 %token tUIDEFAULT tUNION
258 %token tUSESGETLASTERROR tUSERMARSHAL tUUID
261 %token tVERSION tVIPROGID
263 %token tWCHAR tWIREMARSHAL
264 %token tAPARTMENT tNEUTRAL tSINGLE tFREE tBOTH
266 %type
<attr
> attribute type_qualifier function_specifier
267 %type
<attr_list
> m_attributes attributes attrib_list m_type_qual_list
268 %type
<str_list
> str_list
269 %type
<expr
> m_expr expr expr_const expr_int_const array m_bitfield
270 %type
<expr_list
> m_exprs
/* exprs expr_list */ expr_list_int_const
271 %type
<ifinfo
> interfacehdr
272 %type
<stgclass
> storage_cls_spec
273 %type
<declspec
> decl_spec decl_spec_no_type m_decl_spec_no_type
274 %type
<type
> inherit interface interfacedef interfacedec
275 %type
<type
> dispinterface dispinterfacehdr dispinterfacedef
276 %type
<type
> module modulehdr moduledef
277 %type
<str
> namespacedef
278 %type
<type
> base_type int_std
279 %type
<type
> enumdef structdef uniondef typedecl
281 %type
<ifref
> coclass_int
282 %type
<ifref_list
> coclass_ints
283 %type
<var
> arg ne_union_field union_field s_field case
enum declaration
285 %type
<var_list
> m_args arg_list args dispint_meths
286 %type
<var_list
> fields ne_union_fields cases enums enum_list dispint_props field
287 %type
<var
> m_ident ident
288 %type
<declarator
> declarator direct_declarator init_declarator struct_declarator
289 %type
<declarator
> m_any_declarator any_declarator any_declarator_no_direct any_direct_declarator
290 %type
<declarator
> m_abstract_declarator abstract_declarator abstract_declarator_no_direct abstract_direct_declarator
291 %type
<declarator_list
> declarator_list struct_declarator_list
292 %type
<type
> coclass coclasshdr coclassdef
293 %type
<num
> pointer_type threading_type version
294 %type
<str
> libraryhdr callconv cppquote importlib import t_ident
295 %type
<uuid
> uuid_string
296 %type
<import
> import_start
297 %type
<typelib
> library_start librarydef
298 %type
<statement
> statement typedef pragma_warning
299 %type
<stmt_list
> gbl_statements imp_statements int_statements
300 %type
<warning_list
> warnings
309 %left EQUALITY INEQUALITY
310 %left
'<' '>' LESSEQUAL GREATEREQUAL
314 %right
'!' '~' CAST PPTR POS NEG ADDRESSOF tSIZEOF
315 %left
'.' MEMBERPTR
'[' ']'
321 input: gbl_statements
{ fix_incomplete
();
322 check_statements
($1, FALSE
);
323 check_all_user_types
($1);
331 write_local_stubs
($1);
335 gbl_statements: { $$
= NULL
; }
336 | gbl_statements namespacedef
'{' { push_namespace
($2); } gbl_statements
'}'
337 { pop_namespace
($2); $$
= append_statements
($1, $5); }
338 | gbl_statements interfacedec
{ $$
= append_statement
($1, make_statement_reference
($2)); }
339 | gbl_statements interfacedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); }
340 | gbl_statements coclass
';' { $$
= $1;
341 reg_type
($2, $2->name
, current_namespace
, 0);
343 | gbl_statements coclassdef
{ $$
= append_statement
($1, make_statement_type_decl
($2));
344 reg_type
($2, $2->name
, current_namespace
, 0);
346 | gbl_statements moduledef
{ $$
= append_statement
($1, make_statement_module
($2)); }
347 | gbl_statements librarydef
{ $$
= append_statement
($1, make_statement_library
($2)); }
348 | gbl_statements statement
{ $$
= append_statement
($1, $2); }
351 imp_statements: { $$
= NULL
; }
352 | imp_statements interfacedec
{ $$
= append_statement
($1, make_statement_reference
($2)); }
353 | imp_statements namespacedef
'{' { push_namespace
($2); } imp_statements
'}'
354 { pop_namespace
($2); $$
= append_statements
($1, $5); }
355 | imp_statements interfacedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); }
356 | imp_statements coclass
';' { $$
= $1; reg_type
($2, $2->name
, current_namespace
, 0); }
357 | imp_statements coclassdef
{ $$
= append_statement
($1, make_statement_type_decl
($2));
358 reg_type
($2, $2->name
, current_namespace
, 0);
360 | imp_statements moduledef
{ $$
= append_statement
($1, make_statement_module
($2)); }
361 | imp_statements statement
{ $$
= append_statement
($1, $2); }
362 | imp_statements importlib
{ $$
= append_statement
($1, make_statement_importlib
($2)); }
363 | imp_statements librarydef
{ $$
= append_statement
($1, make_statement_library
($2)); }
366 int_statements: { $$
= NULL
; }
367 | int_statements statement
{ $$
= append_statement
($1, $2); }
375 cppquote
{ $$
= make_statement_cppquote
($1); }
376 | typedecl
';' { $$
= make_statement_type_decl
($1); }
377 | declaration
';' { $$
= make_statement_declaration
($1); }
378 | import
{ $$
= make_statement_import
($1); }
379 | typedef
';' { $$
= $1; }
380 | aPRAGMA
{ $$
= make_statement_pragma
($1); }
381 | pragma_warning
{ $$
= NULL
; }
384 pragma_warning: tPRAGMA_WARNING
'(' aIDENTIFIER
':' warnings
')'
388 result
= do_warning
($3, $5);
390 error_loc
("expected \"disable\" or \"enable\"\n");
395 aNUM
{ $$
= append_warning
(NULL
, $1); }
396 | warnings aNUM
{ $$
= append_warning
($1, $2); }
401 | tENUM aIDENTIFIER
{ $$
= type_new_enum
($2, current_namespace
, FALSE
, NULL
); }
403 | tSTRUCT aIDENTIFIER
{ $$
= type_new_struct
($2, current_namespace
, FALSE
, NULL
); }
405 | tUNION aIDENTIFIER
{ $$
= type_new_nonencapsulated_union
($2, FALSE
, NULL
); }
406 | attributes enumdef
{ $$
= $2; $$
->attrs
= check_enum_attrs
($1); }
407 | attributes structdef
{ $$
= $2; $$
->attrs
= check_struct_attrs
($1); }
408 | attributes uniondef
{ $$
= $2; $$
->attrs
= check_union_attrs
($1); }
411 cppquote: tCPPQUOTE
'(' aSTRING
')' { $$
= $3; }
413 import_start: tIMPORT aSTRING
';' { assert
(yychar == YYEMPTY
);
414 $$
= xmalloc
(sizeof
(struct _import_t
));
416 $$
->import_performed
= do_import
($2);
417 if
(!$$
->import_performed
) yychar = aEOF
;
421 import: import_start imp_statements aEOF
{ $$
= $1->name
;
422 if
($1->import_performed
) pop_import
();
427 importlib: tIMPORTLIB
'(' aSTRING
')'
428 semicolon_opt
{ $$
= $3; if
(!parse_only
) add_importlib
($3); }
431 libraryhdr: tLIBRARY aIDENTIFIER
{ $$
= $2; }
433 library_start: attributes libraryhdr
'{' { $$
= make_library
($2, check_library_attrs
($2, $1));
434 if
(!parse_only
) start_typelib
($$
);
437 librarydef: library_start imp_statements
'}'
438 semicolon_opt
{ $$
= $1;
440 if
(!parse_only
) end_typelib
();
444 m_args: { $$
= NULL
; }
448 arg_list: arg
{ check_arg_attrs
($1); $$
= append_var
( NULL
, $1 ); }
449 | arg_list
',' arg
{ check_arg_attrs
($3); $$
= append_var
( $1, $3 ); }
453 | arg_list
',' ELLIPSIS
{ $$
= append_var
( $1, make_var
(strdup
("...")) ); }
456 /* split into two rules to get bison to resolve a tVOID conflict */
457 arg: attributes decl_spec m_any_declarator
{ if
($2->stgclass
!= STG_NONE
&& $2->stgclass
!= STG_REGISTER
)
458 error_loc
("invalid storage class for function parameter\n");
459 $$
= declare_var
($1, $2, $3, TRUE
);
462 | decl_spec m_any_declarator
{ if
($1->stgclass
!= STG_NONE
&& $1->stgclass
!= STG_REGISTER
)
463 error_loc
("invalid storage class for function parameter\n");
464 $$
= declare_var
(NULL
, $1, $2, TRUE
);
469 array: '[' expr
']' { $$
= $2;
471 error_loc
("array dimension is not an integer constant\n");
473 |
'[' '*' ']' { $$
= make_expr
(EXPR_VOID
); }
474 |
'[' ']' { $$
= make_expr
(EXPR_VOID
); }
477 m_attributes: { $$
= NULL
; }
482 '[' attrib_list
']' { $$
= $2; }
485 attrib_list: attribute
{ $$
= append_attr
( NULL
, $1 ); }
486 | attrib_list
',' attribute
{ $$
= append_attr
( $1, $3 ); }
487 | attrib_list
']' '[' attribute
{ $$
= append_attr
( $1, $4 ); }
490 str_list: aSTRING
{ $$
= append_str
( NULL
, $1 ); }
491 | str_list
',' aSTRING
{ $$
= append_str
( $1, $3 ); }
494 attribute: { $$
= NULL
; }
495 | tAGGREGATABLE
{ $$
= make_attr
(ATTR_AGGREGATABLE
); }
496 | tANNOTATION
'(' aSTRING
')' { $$
= make_attrp
(ATTR_ANNOTATION
, $3); }
497 | tAPPOBJECT
{ $$
= make_attr
(ATTR_APPOBJECT
); }
498 | tASYNC
{ $$
= make_attr
(ATTR_ASYNC
); }
499 | tAUTOHANDLE
{ $$
= make_attr
(ATTR_AUTO_HANDLE
); }
500 | tBINDABLE
{ $$
= make_attr
(ATTR_BINDABLE
); }
501 | tBROADCAST
{ $$
= make_attr
(ATTR_BROADCAST
); }
502 | tCALLAS
'(' ident
')' { $$
= make_attrp
(ATTR_CALLAS
, $3); }
503 | tCASE
'(' expr_list_int_const
')' { $$
= make_attrp
(ATTR_CASE
, $3); }
504 | tCODE
{ $$
= make_attr
(ATTR_CODE
); }
505 | tCOMMSTATUS
{ $$
= make_attr
(ATTR_COMMSTATUS
); }
506 | tCONTEXTHANDLE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); }
507 | tCONTEXTHANDLENOSERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
508 | tCONTEXTHANDLESERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
509 | tCONTROL
{ $$
= make_attr
(ATTR_CONTROL
); }
510 | tDECODE
{ $$
= make_attr
(ATTR_DECODE
); }
511 | tDEFAULT
{ $$
= make_attr
(ATTR_DEFAULT
); }
512 | tDEFAULTBIND
{ $$
= make_attr
(ATTR_DEFAULTBIND
); }
513 | tDEFAULTCOLLELEM
{ $$
= make_attr
(ATTR_DEFAULTCOLLELEM
); }
514 | tDEFAULTVALUE
'(' expr_const
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE
, $3); }
515 | tDEFAULTVTABLE
{ $$
= make_attr
(ATTR_DEFAULTVTABLE
); }
516 | tDISABLECONSISTENCYCHECK
{ $$
= make_attr
(ATTR_DISABLECONSISTENCYCHECK
); }
517 | tDISPLAYBIND
{ $$
= make_attr
(ATTR_DISPLAYBIND
); }
518 | tDLLNAME
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DLLNAME
, $3); }
519 | tDUAL
{ $$
= make_attr
(ATTR_DUAL
); }
520 | tENABLEALLOCATE
{ $$
= make_attr
(ATTR_ENABLEALLOCATE
); }
521 | tENCODE
{ $$
= make_attr
(ATTR_ENCODE
); }
522 | tENDPOINT
'(' str_list
')' { $$
= make_attrp
(ATTR_ENDPOINT
, $3); }
523 | tENTRY
'(' expr_const
')' { $$
= make_attrp
(ATTR_ENTRY
, $3); }
524 | tEXPLICITHANDLE
{ $$
= make_attr
(ATTR_EXPLICIT_HANDLE
); }
525 | tFAULTSTATUS
{ $$
= make_attr
(ATTR_FAULTSTATUS
); }
526 | tFORCEALLOCATE
{ $$
= make_attr
(ATTR_FORCEALLOCATE
); }
527 | tHANDLE
{ $$
= make_attr
(ATTR_HANDLE
); }
528 | tHELPCONTEXT
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_HELPCONTEXT
, $3); }
529 | tHELPFILE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPFILE
, $3); }
530 | tHELPSTRING
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRING
, $3); }
531 | tHELPSTRINGCONTEXT
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_HELPSTRINGCONTEXT
, $3); }
532 | tHELPSTRINGDLL
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRINGDLL
, $3); }
533 | tHIDDEN
{ $$
= make_attr
(ATTR_HIDDEN
); }
534 | tID
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_ID
, $3); }
535 | tIDEMPOTENT
{ $$
= make_attr
(ATTR_IDEMPOTENT
); }
536 | tIGNORE
{ $$
= make_attr
(ATTR_IGNORE
); }
537 | tIIDIS
'(' expr
')' { $$
= make_attrp
(ATTR_IIDIS
, $3); }
538 | tIMMEDIATEBIND
{ $$
= make_attr
(ATTR_IMMEDIATEBIND
); }
539 | tIMPLICITHANDLE
'(' arg
')' { $$
= make_attrp
(ATTR_IMPLICIT_HANDLE
, $3); }
540 | tIN
{ $$
= make_attr
(ATTR_IN
); }
541 | tINPUTSYNC
{ $$
= make_attr
(ATTR_INPUTSYNC
); }
542 | tLENGTHIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_LENGTHIS
, $3); }
543 | tLCID
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_LIBLCID
, $3); }
544 | tLCID
{ $$
= make_attr
(ATTR_PARAMLCID
); }
545 | tLICENSED
{ $$
= make_attr
(ATTR_LICENSED
); }
546 | tLOCAL
{ $$
= make_attr
(ATTR_LOCAL
); }
547 | tMAYBE
{ $$
= make_attr
(ATTR_MAYBE
); }
548 | tMESSAGE
{ $$
= make_attr
(ATTR_MESSAGE
); }
549 | tNOCODE
{ $$
= make_attr
(ATTR_NOCODE
); }
550 | tNONBROWSABLE
{ $$
= make_attr
(ATTR_NONBROWSABLE
); }
551 | tNONCREATABLE
{ $$
= make_attr
(ATTR_NONCREATABLE
); }
552 | tNONEXTENSIBLE
{ $$
= make_attr
(ATTR_NONEXTENSIBLE
); }
553 | tNOTIFY
{ $$
= make_attr
(ATTR_NOTIFY
); }
554 | tNOTIFYFLAG
{ $$
= make_attr
(ATTR_NOTIFYFLAG
); }
555 | tOBJECT
{ $$
= make_attr
(ATTR_OBJECT
); }
556 | tODL
{ $$
= make_attr
(ATTR_ODL
); }
557 | tOLEAUTOMATION
{ $$
= make_attr
(ATTR_OLEAUTOMATION
); }
558 | tOPTIMIZE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_OPTIMIZE
, $3); }
559 | tOPTIONAL
{ $$
= make_attr
(ATTR_OPTIONAL
); }
560 | tOUT
{ $$
= make_attr
(ATTR_OUT
); }
561 | tPARTIALIGNORE
{ $$
= make_attr
(ATTR_PARTIALIGNORE
); }
562 | tPOINTERDEFAULT
'(' pointer_type
')' { $$
= make_attrv
(ATTR_POINTERDEFAULT
, $3); }
563 | tPROGID
'(' aSTRING
')' { $$
= make_attrp
(ATTR_PROGID
, $3); }
564 | tPROPGET
{ $$
= make_attr
(ATTR_PROPGET
); }
565 | tPROPPUT
{ $$
= make_attr
(ATTR_PROPPUT
); }
566 | tPROPPUTREF
{ $$
= make_attr
(ATTR_PROPPUTREF
); }
567 | tPROXY
{ $$
= make_attr
(ATTR_PROXY
); }
568 | tPUBLIC
{ $$
= make_attr
(ATTR_PUBLIC
); }
569 | tRANGE
'(' expr_int_const
',' expr_int_const
')'
570 { expr_list_t
*list
= append_expr
( NULL
, $3 );
571 list
= append_expr
( list
, $5 );
572 $$
= make_attrp
(ATTR_RANGE
, list
); }
573 | tREADONLY
{ $$
= make_attr
(ATTR_READONLY
); }
574 | tREPRESENTAS
'(' type
')' { $$
= make_attrp
(ATTR_REPRESENTAS
, $3); }
575 | tREQUESTEDIT
{ $$
= make_attr
(ATTR_REQUESTEDIT
); }
576 | tRESTRICTED
{ $$
= make_attr
(ATTR_RESTRICTED
); }
577 | tRETVAL
{ $$
= make_attr
(ATTR_RETVAL
); }
578 | tSIZEIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_SIZEIS
, $3); }
579 | tSOURCE
{ $$
= make_attr
(ATTR_SOURCE
); }
580 | tSTRICTCONTEXTHANDLE
{ $$
= make_attr
(ATTR_STRICTCONTEXTHANDLE
); }
581 | tSTRING
{ $$
= make_attr
(ATTR_STRING
); }
582 | tSWITCHIS
'(' expr
')' { $$
= make_attrp
(ATTR_SWITCHIS
, $3); }
583 | tSWITCHTYPE
'(' type
')' { $$
= make_attrp
(ATTR_SWITCHTYPE
, $3); }
584 | tTRANSMITAS
'(' type
')' { $$
= make_attrp
(ATTR_TRANSMITAS
, $3); }
585 | tTHREADING
'(' threading_type
')' { $$
= make_attrv
(ATTR_THREADING
, $3); }
586 | tUIDEFAULT
{ $$
= make_attr
(ATTR_UIDEFAULT
); }
587 | tUSESGETLASTERROR
{ $$
= make_attr
(ATTR_USESGETLASTERROR
); }
588 | tUSERMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_USERMARSHAL
, $3); }
589 | tUUID
'(' uuid_string
')' { $$
= make_attrp
(ATTR_UUID
, $3); }
590 | tASYNCUUID
'(' uuid_string
')' { $$
= make_attrp
(ATTR_ASYNCUUID
, $3); }
591 | tV1ENUM
{ $$
= make_attr
(ATTR_V1ENUM
); }
592 | tVARARG
{ $$
= make_attr
(ATTR_VARARG
); }
593 | tVERSION
'(' version
')' { $$
= make_attrv
(ATTR_VERSION
, $3); }
594 | tVIPROGID
'(' aSTRING
')' { $$
= make_attrp
(ATTR_VIPROGID
, $3); }
595 | tWIREMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_WIREMARSHAL
, $3); }
596 | pointer_type
{ $$
= make_attrv
(ATTR_POINTERTYPE
, $1); }
601 | aSTRING
{ if
(!is_valid_uuid
($1))
602 error_loc
("invalid UUID: %s\n", $1);
603 $$
= parse_uuid
($1); }
606 callconv: tCDECL
{ $$
= xstrdup
("__cdecl"); }
607 | tFASTCALL
{ $$
= xstrdup
("__fastcall"); }
608 | tPASCAL
{ $$
= xstrdup
("__pascal"); }
609 | tSTDCALL
{ $$
= xstrdup
("__stdcall"); }
612 cases: { $$
= NULL
; }
613 | cases case
{ $$
= append_var
( $1, $2 ); }
616 case: tCASE expr_int_const
':' union_field
{ attr_t
*a
= make_attrp
(ATTR_CASE
, append_expr
( NULL
, $2 ));
617 $$
= $4; if
(!$$
) $$
= make_var
(NULL
);
618 $$
->attrs
= append_attr
( $$
->attrs
, a
);
620 | tDEFAULT
':' union_field
{ attr_t
*a
= make_attr
(ATTR_DEFAULT
);
621 $$
= $3; if
(!$$
) $$
= make_var
(NULL
);
622 $$
->attrs
= append_attr
( $$
->attrs
, a
);
626 enums: { $$
= NULL
; }
627 | enum_list
',' { $$
= $1; }
631 enum_list: enum { if
(!$1->eval
)
632 $1->eval
= make_exprl
(EXPR_NUM
, 0 /* default for first enum entry */);
633 $$
= append_var
( NULL
, $1 );
635 | enum_list
',' enum { if
(!$3->eval
)
637 var_t
*last
= LIST_ENTRY
( list_tail
($$
), var_t
, entry
);
638 enum expr_type type
= EXPR_NUM
;
639 if
(last
->eval
->type
== EXPR_HEXNUM
) type
= EXPR_HEXNUM
;
640 if
(last
->eval
->cval
+ 1 < 0) type
= EXPR_HEXNUM
;
641 $3->eval
= make_exprl
(type
, last
->eval
->cval
+ 1);
643 $$
= append_var
( $1, $3 );
647 enum: ident
'=' expr_int_const
{ $$
= reg_const
($1);
649 $$
->type
= type_new_int
(TYPE_BASIC_INT
, 0);
651 | ident
{ $$
= reg_const
($1);
652 $$
->type
= type_new_int
(TYPE_BASIC_INT
, 0);
656 enumdef: tENUM t_ident
'{' enums
'}' { $$
= type_new_enum
($2, current_namespace
, TRUE
, $4); }
659 m_exprs: m_expr
{ $$
= append_expr
( NULL
, $1 ); }
660 | m_exprs
',' m_expr
{ $$
= append_expr
( $1, $3 ); }
663 m_expr: { $$
= make_expr
(EXPR_VOID
); }
667 expr: aNUM
{ $$
= make_exprl
(EXPR_NUM
, $1); }
668 | aHEXNUM
{ $$
= make_exprl
(EXPR_HEXNUM
, $1); }
669 | aDOUBLE
{ $$
= make_exprd
(EXPR_DOUBLE
, $1); }
670 | tFALSE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 0); }
671 | tNULL
{ $$
= make_exprl
(EXPR_NUM
, 0); }
672 | tTRUE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 1); }
673 | aSTRING
{ $$
= make_exprs
(EXPR_STRLIT
, $1); }
674 | aWSTRING
{ $$
= make_exprs
(EXPR_WSTRLIT
, $1); }
675 | aSQSTRING
{ $$
= make_exprs
(EXPR_CHARCONST
, $1); }
676 | aIDENTIFIER
{ $$
= make_exprs
(EXPR_IDENTIFIER
, $1); }
677 | expr
'?' expr
':' expr
{ $$
= make_expr3
(EXPR_COND
, $1, $3, $5); }
678 | expr LOGICALOR expr
{ $$
= make_expr2
(EXPR_LOGOR
, $1, $3); }
679 | expr LOGICALAND expr
{ $$
= make_expr2
(EXPR_LOGAND
, $1, $3); }
680 | expr
'|' expr
{ $$
= make_expr2
(EXPR_OR
, $1, $3); }
681 | expr
'^' expr
{ $$
= make_expr2
(EXPR_XOR
, $1, $3); }
682 | expr
'&' expr
{ $$
= make_expr2
(EXPR_AND
, $1, $3); }
683 | expr EQUALITY expr
{ $$
= make_expr2
(EXPR_EQUALITY
, $1, $3); }
684 | expr INEQUALITY expr
{ $$
= make_expr2
(EXPR_INEQUALITY
, $1, $3); }
685 | expr
'>' expr
{ $$
= make_expr2
(EXPR_GTR
, $1, $3); }
686 | expr
'<' expr
{ $$
= make_expr2
(EXPR_LESS
, $1, $3); }
687 | expr GREATEREQUAL expr
{ $$
= make_expr2
(EXPR_GTREQL
, $1, $3); }
688 | expr LESSEQUAL expr
{ $$
= make_expr2
(EXPR_LESSEQL
, $1, $3); }
689 | expr SHL expr
{ $$
= make_expr2
(EXPR_SHL
, $1, $3); }
690 | expr SHR expr
{ $$
= make_expr2
(EXPR_SHR
, $1, $3); }
691 | expr
'+' expr
{ $$
= make_expr2
(EXPR_ADD
, $1, $3); }
692 | expr
'-' expr
{ $$
= make_expr2
(EXPR_SUB
, $1, $3); }
693 | expr
'%' expr
{ $$
= make_expr2
(EXPR_MOD
, $1, $3); }
694 | expr
'*' expr
{ $$
= make_expr2
(EXPR_MUL
, $1, $3); }
695 | expr
'/' expr
{ $$
= make_expr2
(EXPR_DIV
, $1, $3); }
696 |
'!' expr
{ $$
= make_expr1
(EXPR_LOGNOT
, $2); }
697 |
'~' expr
{ $$
= make_expr1
(EXPR_NOT
, $2); }
698 |
'+' expr %prec POS
{ $$
= make_expr1
(EXPR_POS
, $2); }
699 |
'-' expr %prec NEG
{ $$
= make_expr1
(EXPR_NEG
, $2); }
700 |
'&' expr %prec ADDRESSOF
{ $$
= make_expr1
(EXPR_ADDRESSOF
, $2); }
701 |
'*' expr %prec PPTR
{ $$
= make_expr1
(EXPR_PPTR
, $2); }
702 | expr MEMBERPTR aIDENTIFIER
{ $$
= make_expr2
(EXPR_MEMBER
, make_expr1
(EXPR_PPTR
, $1), make_exprs
(EXPR_IDENTIFIER
, $3)); }
703 | expr
'.' aIDENTIFIER
{ $$
= make_expr2
(EXPR_MEMBER
, $1, make_exprs
(EXPR_IDENTIFIER
, $3)); }
704 |
'(' decl_spec m_abstract_declarator
')' expr %prec CAST
705 { $$
= make_exprt
(EXPR_CAST
, declare_var
(NULL
, $2, $3, 0), $5); free
($2); free
($3); }
706 | tSIZEOF
'(' decl_spec m_abstract_declarator
')'
707 { $$
= make_exprt
(EXPR_SIZEOF
, declare_var
(NULL
, $3, $4, 0), NULL
); free
($3); free
($4); }
708 | expr
'[' expr
']' { $$
= make_expr2
(EXPR_ARRAY
, $1, $3); }
709 |
'(' expr
')' { $$
= $2; }
712 expr_list_int_const: expr_int_const
{ $$
= append_expr
( NULL
, $1 ); }
713 | expr_list_int_const
',' expr_int_const
{ $$
= append_expr
( $1, $3 ); }
716 expr_int_const: expr
{ $$
= $1;
718 error_loc
("expression is not an integer constant\n");
722 expr_const: expr
{ $$
= $1;
723 if
(!$$
->is_const
&& $$
->type
!= EXPR_STRLIT
&& $$
->type
!= EXPR_WSTRLIT
)
724 error_loc
("expression is not constant\n");
728 fields: { $$
= NULL
; }
729 | fields field
{ $$
= append_var_list
($1, $2); }
732 field: m_attributes decl_spec struct_declarator_list
';'
733 { const char *first
= LIST_ENTRY
(list_head
($3), declarator_t
, entry
)->var
->name
;
734 check_field_attrs
(first
, $1);
735 $$
= set_var_types
($1, $2, $3);
737 | m_attributes uniondef
';' { var_t
*v
= make_var
(NULL
);
738 v
->type
= $2; v
->attrs
= $1;
739 $$
= append_var
(NULL
, v
);
744 s_field
';' { $$
= $1; }
745 | attributes
';' { $$
= make_var
(NULL
); $$
->attrs
= $1; }
748 ne_union_fields: { $$
= NULL
; }
749 | ne_union_fields ne_union_field
{ $$
= append_var
( $1, $2 ); }
753 s_field
';' { $$
= $1; }
757 s_field: m_attributes decl_spec declarator
{ $$
= declare_var
(check_field_attrs
($3->var
->name
, $1),
761 | m_attributes structdef
{ var_t
*v
= make_var
(NULL
);
762 v
->type
= $2; v
->attrs
= $1;
767 funcdef: declaration
{ $$
= $1;
768 if
(type_get_type
($$
->type
) != TYPE_FUNCTION
)
769 error_loc
("only methods may be declared inside the methods section of a dispinterface\n");
770 check_function_attrs
($$
->name
, $$
->attrs
);
775 attributes decl_spec init_declarator
776 { $$
= declare_var
($1, $2, $3, FALSE
);
779 | decl_spec init_declarator
{ $$
= declare_var
(NULL
, $1, $2, FALSE
);
784 m_ident: { $$
= NULL
; }
788 t_ident: { $$
= NULL
; }
789 | aIDENTIFIER
{ $$
= $1; }
790 | aKNOWNTYPE
{ $$
= $1; }
793 ident: aIDENTIFIER
{ $$
= make_var
($1); }
794 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
795 | aKNOWNTYPE
{ $$
= make_var
($
<str
>1); }
798 base_type: tBYTE
{ $$
= find_type_or_error
($
<str
>1, 0); }
799 | tWCHAR
{ $$
= find_type_or_error
($
<str
>1, 0); }
801 | tSIGNED int_std
{ $$
= type_new_int
(type_basic_get_type
($2), -1); }
802 | tUNSIGNED int_std
{ $$
= type_new_int
(type_basic_get_type
($2), 1); }
803 | tUNSIGNED
{ $$
= type_new_int
(TYPE_BASIC_INT
, 1); }
804 | tFLOAT
{ $$
= find_type_or_error
($
<str
>1, 0); }
805 | tDOUBLE
{ $$
= find_type_or_error
($
<str
>1, 0); }
806 | tBOOLEAN
{ $$
= find_type_or_error
($
<str
>1, 0); }
807 | tERRORSTATUST
{ $$
= find_type_or_error
($
<str
>1, 0); }
808 | tHANDLET
{ $$
= find_type_or_error
($
<str
>1, 0); }
815 int_std: tINT
{ $$
= type_new_int
(TYPE_BASIC_INT
, 0); }
816 | tSHORT m_int
{ $$
= type_new_int
(TYPE_BASIC_INT16
, 0); }
817 | tSMALL
{ $$
= type_new_int
(TYPE_BASIC_INT8
, 0); }
818 | tLONG m_int
{ $$
= type_new_int
(TYPE_BASIC_INT32
, 0); }
819 | tHYPER m_int
{ $$
= type_new_int
(TYPE_BASIC_HYPER
, 0); }
820 | tINT64
{ $$
= type_new_int
(TYPE_BASIC_INT64
, 0); }
821 | tCHAR
{ $$
= type_new_int
(TYPE_BASIC_CHAR
, 0); }
822 | tINT3264
{ $$
= type_new_int
(TYPE_BASIC_INT3264
, 0); }
825 coclass: tCOCLASS aIDENTIFIER
{ $$
= type_new_coclass
($2); }
826 | tCOCLASS aKNOWNTYPE
{ $$
= find_type
($2, NULL
, 0);
827 if
(type_get_type_detect_alias
($$
) != TYPE_COCLASS
)
828 error_loc
("%s was not declared a coclass at %s:%d\n",
829 $2, $$
->loc_info.input_name
,
830 $$
->loc_info.line_number
);
834 coclasshdr: attributes coclass
{ $$
= $2;
836 $$
->attrs
= check_coclass_attrs
($2->name
, $1);
840 coclassdef: coclasshdr
'{' coclass_ints
'}' semicolon_opt
841 { $$
= type_coclass_define
($1, $3); }
844 namespacedef: tNAMESPACE aIDENTIFIER
{ $$
= $2; }
847 coclass_ints: { $$
= NULL
; }
848 | coclass_ints coclass_int
{ $$
= append_ifref
( $1, $2 ); }
852 m_attributes interfacedec
{ $$
= make_ifref
($2); $$
->attrs
= $1; }
855 dispinterface: tDISPINTERFACE aIDENTIFIER
{ $$
= get_type
(TYPE_INTERFACE
, $2, current_namespace
, 0); }
856 | tDISPINTERFACE aKNOWNTYPE
{ $$
= get_type
(TYPE_INTERFACE
, $2, current_namespace
, 0); }
859 dispinterfacehdr: attributes dispinterface
{ attr_t
*attrs
;
862 attrs
= make_attr
(ATTR_DISPINTERFACE
);
863 $$
->attrs
= append_attr
( check_dispiface_attrs
($2->name
, $1), attrs
);
868 dispint_props: tPROPERTIES
':' { $$
= NULL
; }
869 | dispint_props s_field
';' { $$
= append_var
( $1, $2 ); }
872 dispint_meths: tMETHODS
':' { $$
= NULL
; }
873 | dispint_meths funcdef
';' { $$
= append_var
( $1, $2 ); }
876 dispinterfacedef: dispinterfacehdr
'{'
880 type_dispinterface_define
($$
, $3, $4);
883 '{' interface
';' '}' { $$
= $1;
884 type_dispinterface_define_from_iface
($$
, $3);
888 inherit: { $$
= NULL
; }
889 |
':' aKNOWNTYPE
{ $$
= find_type_or_error2
($2, 0); }
892 interface: tINTERFACE aIDENTIFIER
{ $$
= get_type
(TYPE_INTERFACE
, $2, current_namespace
, 0); }
893 | tINTERFACE aKNOWNTYPE
{ $$
= get_type
(TYPE_INTERFACE
, $2, current_namespace
, 0); }
896 interfacehdr: attributes interface
{ $$.interface
= $2;
897 $$.old_pointer_default
= pointer_default
;
898 if
(is_attr
($1, ATTR_POINTERDEFAULT
))
899 pointer_default
= get_attrv
($1, ATTR_POINTERDEFAULT
);
901 $2->attrs
= check_iface_attrs
($2->name
, $1);
906 interfacedef: interfacehdr inherit
907 '{' int_statements
'}' semicolon_opt
{ $$
= $1.interface
;
909 error_loc
("Interface can't inherit from itself\n");
910 type_interface_define
($$
, $2, $4);
911 pointer_default
= $1.old_pointer_default
;
913 /* MIDL is able to import the definition of a base class from inside the
914 * definition of a derived class, I'll try to support it with this rule */
915 | interfacehdr
':' aIDENTIFIER
916 '{' import int_statements
'}'
917 semicolon_opt
{ $$
= $1.interface
;
918 type_interface_define
($$
, find_type_or_error2
($3, 0), $6);
919 pointer_default
= $1.old_pointer_default
;
921 | dispinterfacedef semicolon_opt
{ $$
= $1; }
925 interface
';' { $$
= $1; }
926 | dispinterface
';' { $$
= $1; }
929 module: tMODULE aIDENTIFIER
{ $$
= type_new_module
($2); }
930 | tMODULE aKNOWNTYPE
{ $$
= type_new_module
($2); }
933 modulehdr: attributes module
{ $$
= $2;
934 $$
->attrs
= check_module_attrs
($2->name
, $1);
938 moduledef: modulehdr
'{' int_statements
'}'
939 semicolon_opt
{ $$
= $1;
940 type_module_define
($$
, $3);
945 tEXTERN
{ $$
= STG_EXTERN
; }
946 | tSTATIC
{ $$
= STG_STATIC
; }
947 | tREGISTER
{ $$
= STG_REGISTER
; }
951 tINLINE
{ $$
= make_attr
(ATTR_INLINE
); }
955 tCONST
{ $$
= make_attr
(ATTR_CONST
); }
958 m_type_qual_list: { $$
= NULL
; }
959 | m_type_qual_list type_qualifier
{ $$
= append_attr
($1, $2); }
962 decl_spec: type m_decl_spec_no_type
{ $$
= make_decl_spec
($1, $2, NULL
, NULL
, STG_NONE
); }
963 | decl_spec_no_type type m_decl_spec_no_type
964 { $$
= make_decl_spec
($2, $1, $3, NULL
, STG_NONE
); }
967 m_decl_spec_no_type: { $$
= NULL
; }
972 type_qualifier m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, $1, STG_NONE
); }
973 | function_specifier m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, $1, STG_NONE
); }
974 | storage_cls_spec m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, NULL
, $1); }
978 '*' m_type_qual_list declarator %prec PPTR
979 { $$
= $3; $$
->type
= append_ptrchain_type
($$
->type
, type_new_pointer
(pointer_default
, NULL
, $2)); }
980 | callconv declarator
{ $$
= $2; if
($$
->func_type
) $$
->func_type
->attrs
= append_attr
($$
->func_type
->attrs
, make_attrp
(ATTR_CALLCONV
, $1));
981 else if
($$
->type
) $$
->type
->attrs
= append_attr
($$
->type
->attrs
, make_attrp
(ATTR_CALLCONV
, $1)); }
986 ident
{ $$
= make_declarator
($1); }
987 |
'(' declarator
')' { $$
= $2; }
988 | direct_declarator array
{ $$
= $1; $$
->array
= append_array
($$
->array
, $2); }
989 | direct_declarator
'(' m_args
')' { $$
= $1;
990 $$
->func_type
= append_ptrchain_type
($$
->type
, type_new_function
($3));
995 /* abstract declarator */
997 '*' m_type_qual_list m_abstract_declarator %prec PPTR
998 { $$
= $3; $$
->type
= append_ptrchain_type
($$
->type
, type_new_pointer
(pointer_default
, NULL
, $2)); }
999 | callconv m_abstract_declarator
{ $$
= $2; if
($$
->func_type
) $$
->func_type
->attrs
= append_attr
($$
->func_type
->attrs
, make_attrp
(ATTR_CALLCONV
, $1));
1000 else if
($$
->type
) $$
->type
->attrs
= append_attr
($$
->type
->attrs
, make_attrp
(ATTR_CALLCONV
, $1)); }
1001 | abstract_direct_declarator
1004 /* abstract declarator without accepting direct declarator */
1005 abstract_declarator_no_direct:
1006 '*' m_type_qual_list m_any_declarator %prec PPTR
1007 { $$
= $3; $$
->type
= append_ptrchain_type
($$
->type
, type_new_pointer
(pointer_default
, NULL
, $2)); }
1008 | callconv m_any_declarator
{ $$
= $2; if
($$
->func_type
) $$
->func_type
->attrs
= append_attr
($$
->func_type
->attrs
, make_attrp
(ATTR_CALLCONV
, $1));
1009 else if
($$
->type
) $$
->type
->attrs
= append_attr
($$
->type
->attrs
, make_attrp
(ATTR_CALLCONV
, $1)); }
1012 /* abstract declarator or empty */
1013 m_abstract_declarator: { $$
= make_declarator
(NULL
); }
1014 | abstract_declarator
1017 /* abstract direct declarator */
1018 abstract_direct_declarator:
1019 '(' abstract_declarator_no_direct
')' { $$
= $2; }
1020 | abstract_direct_declarator array
{ $$
= $1; $$
->array
= append_array
($$
->array
, $2); }
1021 | array
{ $$
= make_declarator
(NULL
); $$
->array
= append_array
($$
->array
, $1); }
1023 { $$
= make_declarator
(NULL
);
1024 $$
->func_type
= append_ptrchain_type
($$
->type
, type_new_function
($2));
1027 | abstract_direct_declarator
'(' m_args
')'
1029 $$
->func_type
= append_ptrchain_type
($$
->type
, type_new_function
($3));
1034 /* abstract or non-abstract declarator */
1036 '*' m_type_qual_list m_any_declarator %prec PPTR
1037 { $$
= $3; $$
->type
= append_ptrchain_type
($$
->type
, type_new_pointer
(pointer_default
, NULL
, $2)); }
1038 | callconv m_any_declarator
{ $$
= $2; $$
->type
->attrs
= append_attr
($$
->type
->attrs
, make_attrp
(ATTR_CALLCONV
, $1)); }
1039 | any_direct_declarator
1042 /* abstract or non-abstract declarator without accepting direct declarator */
1043 any_declarator_no_direct:
1044 '*' m_type_qual_list m_any_declarator %prec PPTR
1045 { $$
= $3; $$
->type
= append_ptrchain_type
($$
->type
, type_new_pointer
(pointer_default
, NULL
, $2)); }
1046 | callconv m_any_declarator
{ $$
= $2; $$
->type
->attrs
= append_attr
($$
->type
->attrs
, make_attrp
(ATTR_CALLCONV
, $1)); }
1049 /* abstract or non-abstract declarator or empty */
1050 m_any_declarator: { $$
= make_declarator
(NULL
); }
1054 /* abstract or non-abstract direct declarator. note: direct declarators
1055 * aren't accepted inside brackets to avoid ambiguity with the rule for
1056 * function arguments */
1057 any_direct_declarator:
1058 ident
{ $$
= make_declarator
($1); }
1059 |
'(' any_declarator_no_direct
')' { $$
= $2; }
1060 | any_direct_declarator array
{ $$
= $1; $$
->array
= append_array
($$
->array
, $2); }
1061 | array
{ $$
= make_declarator
(NULL
); $$
->array
= append_array
($$
->array
, $1); }
1063 { $$
= make_declarator
(NULL
);
1064 $$
->func_type
= append_ptrchain_type
($$
->type
, type_new_function
($2));
1067 | any_direct_declarator
'(' m_args
')'
1069 $$
->func_type
= append_ptrchain_type
($$
->type
, type_new_function
($3));
1075 declarator
{ $$
= append_declarator
( NULL
, $1 ); }
1076 | declarator_list
',' declarator
{ $$
= append_declarator
( $1, $3 ); }
1079 m_bitfield: { $$
= NULL
; }
1080 |
':' expr_const
{ $$
= $2; }
1083 struct_declarator: any_declarator m_bitfield
{ $$
= $1; $$
->bits
= $2;
1084 if
(!$$
->bits
&& !$$
->var
->name
)
1085 error_loc
("unnamed fields are not allowed\n");
1089 struct_declarator_list:
1090 struct_declarator
{ $$
= append_declarator
( NULL
, $1 ); }
1091 | struct_declarator_list
',' struct_declarator
1092 { $$
= append_declarator
( $1, $3 ); }
1096 declarator
{ $$
= $1; }
1097 | declarator
'=' expr_const
{ $$
= $1; $1->var
->eval
= $3; }
1101 tAPARTMENT
{ $$
= THREADING_APARTMENT
; }
1102 | tNEUTRAL
{ $$
= THREADING_NEUTRAL
; }
1103 | tSINGLE
{ $$
= THREADING_SINGLE
; }
1104 | tFREE
{ $$
= THREADING_FREE
; }
1105 | tBOTH
{ $$
= THREADING_BOTH
; }
1109 tREF
{ $$
= RPC_FC_RP
; }
1110 | tUNIQUE
{ $$
= RPC_FC_UP
; }
1111 | tPTR
{ $$
= RPC_FC_FP
; }
1114 structdef: tSTRUCT t_ident
'{' fields
'}' { $$
= type_new_struct
($2, current_namespace
, TRUE
, $4); }
1117 type: tVOID
{ $$
= type_new_void
(); }
1118 | aKNOWNTYPE
{ $$
= find_type_or_error
($1, 0); }
1119 | base_type
{ $$
= $1; }
1120 | enumdef
{ $$
= $1; }
1121 | tENUM aIDENTIFIER
{ $$
= type_new_enum
($2, current_namespace
, FALSE
, NULL
); }
1122 | structdef
{ $$
= $1; }
1123 | tSTRUCT aIDENTIFIER
{ $$
= type_new_struct
($2, current_namespace
, FALSE
, NULL
); }
1124 | uniondef
{ $$
= $1; }
1125 | tUNION aIDENTIFIER
{ $$
= type_new_nonencapsulated_union
($2, FALSE
, NULL
); }
1126 | tSAFEARRAY
'(' type
')' { $$
= make_safearray
($3); }
1129 typedef: m_attributes tTYPEDEF m_attributes decl_spec declarator_list
1130 { $1 = append_attribs
($1, $3);
1131 reg_typedefs
($4, $5, check_typedef_attrs
($1));
1132 $$
= make_statement_typedef
($5);
1136 uniondef: tUNION t_ident
'{' ne_union_fields
'}'
1137 { $$
= type_new_nonencapsulated_union
($2, TRUE
, $4); }
1139 tSWITCH
'(' s_field
')'
1140 m_ident
'{' cases
'}' { $$
= type_new_encapsulated_union
($2, $5, $7, $9); }
1144 aNUM
{ $$
= MAKEVERSION
($1, 0); }
1145 | aNUM
'.' aNUM
{ $$
= MAKEVERSION
($1, $3); }
1146 | aHEXNUM
{ $$
= $1; }
1151 static void decl_builtin_basic
(const char *name
, enum type_basic_type type
)
1153 type_t
*t
= type_new_basic
(type
);
1154 reg_type
(t
, name
, NULL
, 0);
1157 static void decl_builtin_alias
(const char *name
, type_t
*t
)
1159 reg_type
(type_new_alias
(t
, name
), name
, NULL
, 0);
1162 void init_types
(void)
1164 decl_builtin_basic
("byte", TYPE_BASIC_BYTE
);
1165 decl_builtin_basic
("wchar_t", TYPE_BASIC_WCHAR
);
1166 decl_builtin_basic
("float", TYPE_BASIC_FLOAT
);
1167 decl_builtin_basic
("double", TYPE_BASIC_DOUBLE
);
1168 decl_builtin_basic
("error_status_t", TYPE_BASIC_ERROR_STATUS_T
);
1169 decl_builtin_basic
("handle_t", TYPE_BASIC_HANDLE
);
1170 decl_builtin_alias
("boolean", type_new_basic
(TYPE_BASIC_BYTE
));
1173 static str_list_t
*append_str
(str_list_t
*list
, char *str
)
1175 struct str_list_entry_t
*entry
;
1177 if
(!str
) return list
;
1180 list
= xmalloc
( sizeof
(*list
) );
1183 entry
= xmalloc
( sizeof
(*entry
) );
1185 list_add_tail
( list
, &entry
->entry
);
1189 static attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
)
1191 attr_t
*attr_existing
;
1192 if
(!attr
) return list
;
1195 list
= xmalloc
( sizeof
(*list
) );
1198 LIST_FOR_EACH_ENTRY
(attr_existing
, list
, attr_t
, entry
)
1199 if
(attr_existing
->type
== attr
->type
)
1201 parser_warning
("duplicate attribute %s\n", get_attr_display_name
(attr
->type
));
1202 /* use the last attribute, like MIDL does */
1203 list_remove
(&attr_existing
->entry
);
1206 list_add_tail
( list
, &attr
->entry
);
1210 static attr_list_t
*move_attr
(attr_list_t
*dst
, attr_list_t
*src
, enum attr_type type
)
1213 if
(!src
) return dst
;
1214 LIST_FOR_EACH_ENTRY
(attr
, src
, attr_t
, entry
)
1215 if
(attr
->type
== type
)
1217 list_remove
(&attr
->entry
);
1218 return append_attr
(dst
, attr
);
1223 static attr_list_t
*append_attr_list
(attr_list_t
*new_list
, attr_list_t
*old_list
)
1227 if
(!old_list
) return new_list
;
1229 while
((entry
= list_head
(old_list
)))
1231 attr_t
*attr
= LIST_ENTRY
(entry
, attr_t
, entry
);
1233 new_list
= append_attr
(new_list
, attr
);
1238 static attr_list_t
*dupattrs
(const attr_list_t
*list
)
1240 attr_list_t
*new_list
;
1243 if
(!list
) return NULL
;
1245 new_list
= xmalloc
( sizeof
(*list
) );
1246 list_init
( new_list
);
1247 LIST_FOR_EACH_ENTRY
(attr
, list
, const attr_t
, entry
)
1249 attr_t
*new_attr
= xmalloc
(sizeof
(*new_attr
));
1251 list_add_tail
(new_list
, &new_attr
->entry
);
1256 static decl_spec_t
*make_decl_spec
(type_t
*type
, decl_spec_t
*left
, decl_spec_t
*right
, attr_t
*attr
, enum storage_class stgclass
)
1258 decl_spec_t
*declspec
= left ? left
: right
;
1261 declspec
= xmalloc
(sizeof
(*declspec
));
1262 declspec
->type
= NULL
;
1263 declspec
->attrs
= NULL
;
1264 declspec
->stgclass
= STG_NONE
;
1266 declspec
->type
= type
;
1267 if
(left
&& declspec
!= left
)
1269 declspec
->attrs
= append_attr_list
(declspec
->attrs
, left
->attrs
);
1270 if
(declspec
->stgclass
== STG_NONE
)
1271 declspec
->stgclass
= left
->stgclass
;
1272 else if
(left
->stgclass
!= STG_NONE
)
1273 error_loc
("only one storage class can be specified\n");
1274 assert
(!left
->type
);
1277 if
(right
&& declspec
!= right
)
1279 declspec
->attrs
= append_attr_list
(declspec
->attrs
, right
->attrs
);
1280 if
(declspec
->stgclass
== STG_NONE
)
1281 declspec
->stgclass
= right
->stgclass
;
1282 else if
(right
->stgclass
!= STG_NONE
)
1283 error_loc
("only one storage class can be specified\n");
1284 assert
(!right
->type
);
1288 declspec
->attrs
= append_attr
(declspec
->attrs
, attr
);
1289 if
(declspec
->stgclass
== STG_NONE
)
1290 declspec
->stgclass
= stgclass
;
1291 else if
(stgclass
!= STG_NONE
)
1292 error_loc
("only one storage class can be specified\n");
1294 /* apply attributes to type */
1295 if
(type
&& declspec
->attrs
)
1298 declspec
->type
= duptype
(type
, 1);
1299 attrs
= dupattrs
(type
->attrs
);
1300 declspec
->type
->attrs
= append_attr_list
(attrs
, declspec
->attrs
);
1301 declspec
->attrs
= NULL
;
1307 static attr_t
*make_attr
(enum attr_type type
)
1309 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1315 static attr_t
*make_attrv
(enum attr_type type
, unsigned int val
)
1317 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1323 static attr_t
*make_attrp
(enum attr_type type
, void *val
)
1325 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1331 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
)
1333 if
(!expr
) return list
;
1336 list
= xmalloc
( sizeof
(*list
) );
1339 list_add_tail
( list
, &expr
->entry
);
1343 static array_dims_t
*append_array
(array_dims_t
*list
, expr_t
*expr
)
1345 if
(!expr
) return list
;
1348 list
= xmalloc
( sizeof
(*list
) );
1351 list_add_tail
( list
, &expr
->entry
);
1355 static struct list type_pool
= LIST_INIT
(type_pool
);
1362 type_t
*alloc_type
(void)
1364 type_pool_node_t
*node
= xmalloc
(sizeof
*node
);
1365 list_add_tail
(&type_pool
, &node
->link
);
1369 void set_all_tfswrite
(int val
)
1371 type_pool_node_t
*node
;
1372 LIST_FOR_EACH_ENTRY
(node
, &type_pool
, type_pool_node_t
, link
)
1373 node
->data.tfswrite
= val
;
1376 void clear_all_offsets
(void)
1378 type_pool_node_t
*node
;
1379 LIST_FOR_EACH_ENTRY
(node
, &type_pool
, type_pool_node_t
, link
)
1380 node
->data.typestring_offset
= node
->data.ptrdesc
= 0;
1383 static void type_function_add_head_arg
(type_t
*type
, var_t
*arg
)
1385 if
(!type
->details.function
->args
)
1387 type
->details.function
->args
= xmalloc
( sizeof
(*type
->details.function
->args
) );
1388 list_init
( type
->details.function
->args
);
1390 list_add_head
( type
->details.function
->args
, &arg
->entry
);
1393 static int is_allowed_range_type
(const type_t
*type
)
1395 switch
(type_get_type
(type
))
1400 switch
(type_basic_get_type
(type
))
1402 case TYPE_BASIC_INT8
:
1403 case TYPE_BASIC_INT16
:
1404 case TYPE_BASIC_INT32
:
1405 case TYPE_BASIC_INT64
:
1406 case TYPE_BASIC_INT
:
1407 case TYPE_BASIC_INT3264
:
1408 case TYPE_BASIC_BYTE
:
1409 case TYPE_BASIC_CHAR
:
1410 case TYPE_BASIC_WCHAR
:
1411 case TYPE_BASIC_HYPER
:
1413 case TYPE_BASIC_FLOAT
:
1414 case TYPE_BASIC_DOUBLE
:
1415 case TYPE_BASIC_ERROR_STATUS_T
:
1416 case TYPE_BASIC_HANDLE
:
1425 static type_t
*append_ptrchain_type
(type_t
*ptrchain
, type_t
*type
)
1427 type_t
*ptrchain_type
;
1430 for
(ptrchain_type
= ptrchain
; type_pointer_get_ref
(ptrchain_type
); ptrchain_type
= type_pointer_get_ref
(ptrchain_type
))
1432 assert
(ptrchain_type
->type_type
== TYPE_POINTER
);
1433 ptrchain_type
->details.pointer.ref
= type
;
1437 static warning_list_t
*append_warning
(warning_list_t
*list
, int num
)
1443 list
= xmalloc
( sizeof
(*list
) );
1446 entry
= xmalloc
( sizeof
(*entry
) );
1448 list_add_tail
( list
, &entry
->entry
);
1452 static var_t
*declare_var
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, const declarator_t
*decl
,
1455 var_t
*v
= decl
->var
;
1456 expr_list_t
*sizes
= get_attrp
(attrs
, ATTR_SIZEIS
);
1457 expr_list_t
*lengs
= get_attrp
(attrs
, ATTR_LENGTHIS
);
1461 array_dims_t
*arr
= decl ? decl
->array
: NULL
;
1462 type_t
*func_type
= decl ? decl
->func_type
: NULL
;
1463 type_t
*type
= decl_spec
->type
;
1465 if
(is_attr
(type
->attrs
, ATTR_INLINE
))
1468 error_loc
("inline attribute applied to non-function type\n");
1472 /* move inline attribute from return type node to function node */
1473 for
(t
= func_type
; is_ptr
(t
); t
= type_pointer_get_ref
(t
))
1475 t
->attrs
= move_attr
(t
->attrs
, type
->attrs
, ATTR_INLINE
);
1479 /* add type onto the end of the pointers in pident->type */
1480 v
->type
= append_ptrchain_type
(decl ? decl
->type
: NULL
, type
);
1481 v
->stgclass
= decl_spec
->stgclass
;
1484 /* check for pointer attribute being applied to non-pointer, non-array
1488 int ptr_attr
= get_attrv
(v
->attrs
, ATTR_POINTERTYPE
);
1489 const type_t
*ptr
= NULL
;
1490 /* pointer attributes on the left side of the type belong to the function
1491 * pointer, if one is being declared */
1492 type_t
**pt
= func_type ?
&func_type
: &v
->type
;
1493 for
(ptr
= *pt
; ptr
&& !ptr_attr
; )
1495 ptr_attr
= get_attrv
(ptr
->attrs
, ATTR_POINTERTYPE
);
1496 if
(!ptr_attr
&& type_is_alias
(ptr
))
1497 ptr
= type_alias_get_aliasee
(ptr
);
1503 if
(ptr_attr
&& ptr_attr
!= RPC_FC_UP
&&
1504 type_get_type
(type_pointer_get_ref
(ptr
)) == TYPE_INTERFACE
)
1505 warning_loc_info
(&v
->loc_info
,
1506 "%s: pointer attribute applied to interface "
1507 "pointer type has no effect\n", v
->name
);
1508 if
(!ptr_attr
&& top
&& (*pt
)->details.pointer.def_fc
!= RPC_FC_RP
)
1510 /* FIXME: this is a horrible hack to cope with the issue that we
1511 * store an offset to the typeformat string in the type object, but
1512 * two typeformat strings may be written depending on whether the
1513 * pointer is a toplevel parameter or not */
1514 *pt
= duptype
(*pt
, 1);
1518 error_loc
("%s: pointer attribute applied to non-pointer type\n", v
->name
);
1521 if
(is_attr
(v
->attrs
, ATTR_STRING
))
1525 if
(!is_ptr
(v
->type
) && !arr
)
1526 error_loc
("'%s': [string] attribute applied to non-pointer, non-array type\n",
1530 t
= type_pointer_get_ref
(t
);
1532 if
(type_get_type
(t
) != TYPE_BASIC
&&
1533 (get_basic_fc
(t
) != RPC_FC_CHAR
&&
1534 get_basic_fc
(t
) != RPC_FC_BYTE
&&
1535 get_basic_fc
(t
) != RPC_FC_WCHAR
))
1537 error_loc
("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
1542 if
(is_attr
(v
->attrs
, ATTR_V1ENUM
))
1544 if
(type_get_type_detect_alias
(v
->type
) != TYPE_ENUM
)
1545 error_loc
("'%s': [v1_enum] attribute applied to non-enum type\n", v
->name
);
1548 if
(is_attr
(v
->attrs
, ATTR_RANGE
) && !is_allowed_range_type
(v
->type
))
1549 error_loc
("'%s': [range] attribute applied to non-integer type\n",
1554 if
(arr
) LIST_FOR_EACH_ENTRY_REV
(dim
, arr
, expr_t
, entry
)
1557 error_loc
("%s: only the first array dimension can be unspecified\n", v
->name
);
1562 error_loc
("%s: array dimension must be positive\n", v
->name
);
1564 /* FIXME: should use a type_memsize that allows us to pass in a pointer size */
1567 unsigned int size
= type_memsize
(v
->type
);
1569 if
(0xffffffffu
/ size
< dim
->cval
)
1570 error_loc
("%s: total array size is too large\n", v
->name
);
1576 *ptype
= type_new_array
(NULL
, *ptype
, FALSE
,
1577 dim
->is_const ? dim
->cval
: 0,
1578 dim
->is_const ? NULL
: dim
, NULL
,
1583 if
(sizes
) LIST_FOR_EACH_ENTRY
(dim
, sizes
, expr_t
, entry
)
1585 if
(dim
->type
!= EXPR_VOID
)
1587 if
(is_array
(*ptype
))
1589 if
(!type_array_get_conformance
(*ptype
) ||
1590 type_array_get_conformance
(*ptype
)->type
!= EXPR_VOID
)
1591 error_loc
("%s: cannot specify size_is for an already sized array\n", v
->name
);
1593 *ptype
= type_new_array
((*ptype
)->name
,
1594 type_array_get_element
(*ptype
), FALSE
,
1597 else if
(is_ptr
(*ptype
))
1598 *ptype
= type_new_array
((*ptype
)->name
, type_pointer_get_ref
(*ptype
), TRUE
,
1599 0, dim
, NULL
, pointer_default
);
1601 error_loc
("%s: size_is attribute applied to illegal type\n", v
->name
);
1605 ptype
= &(*ptype
)->details.pointer.ref
;
1606 else if
(is_array
(*ptype
))
1607 ptype
= &(*ptype
)->details.array.elem
;
1609 error_loc
("%s: too many expressions in size_is attribute\n", v
->name
);
1613 if
(lengs
) LIST_FOR_EACH_ENTRY
(dim
, lengs
, expr_t
, entry
)
1615 if
(dim
->type
!= EXPR_VOID
)
1617 if
(is_array
(*ptype
))
1619 *ptype
= type_new_array
((*ptype
)->name
,
1620 type_array_get_element
(*ptype
),
1621 type_array_is_decl_as_ptr
(*ptype
),
1622 type_array_get_dim
(*ptype
),
1623 type_array_get_conformance
(*ptype
),
1624 dim
, type_array_get_ptr_default_fc
(*ptype
));
1627 error_loc
("%s: length_is attribute applied to illegal type\n", v
->name
);
1631 ptype
= &(*ptype
)->details.pointer.ref
;
1632 else if
(is_array
(*ptype
))
1633 ptype
= &(*ptype
)->details.array.elem
;
1635 error_loc
("%s: too many expressions in length_is attribute\n", v
->name
);
1638 /* v->type is currently pointing to the type on the left-side of the
1639 * declaration, so we need to fix this up so that it is the return type of the
1640 * function and make v->type point to the function side of the declaration */
1644 type_t
*return_type
= v
->type
;
1645 v
->type
= func_type
;
1646 for
(ft
= v
->type
; is_ptr
(ft
); ft
= type_pointer_get_ref
(ft
))
1648 assert
(type_get_type_detect_alias
(ft
) == TYPE_FUNCTION
);
1649 ft
->details.function
->retval
= make_var
(xstrdup
("_RetVal"));
1650 ft
->details.function
->retval
->type
= return_type
;
1651 /* move calling convention attribute, if present, from pointer nodes to
1653 for
(t
= v
->type
; is_ptr
(t
); t
= type_pointer_get_ref
(t
))
1654 ft
->attrs
= move_attr
(ft
->attrs
, t
->attrs
, ATTR_CALLCONV
);
1659 for
(t
= v
->type
; is_ptr
(t
); t
= type_pointer_get_ref
(t
))
1660 if
(is_attr
(t
->attrs
, ATTR_CALLCONV
))
1661 error_loc
("calling convention applied to non-function-pointer type\n");
1665 v
->type
= type_new_bitfield
(v
->type
, decl
->bits
);
1670 static var_list_t
*set_var_types
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_list_t
*decls
)
1672 declarator_t
*decl
, *next
;
1673 var_list_t
*var_list
= NULL
;
1675 LIST_FOR_EACH_ENTRY_SAFE
( decl
, next
, decls
, declarator_t
, entry
)
1677 var_t
*var
= declare_var
(attrs
, decl_spec
, decl
, 0);
1678 var_list
= append_var
(var_list
, var
);
1685 static ifref_list_t
*append_ifref
(ifref_list_t
*list
, ifref_t
*iface
)
1687 if
(!iface
) return list
;
1690 list
= xmalloc
( sizeof
(*list
) );
1693 list_add_tail
( list
, &iface
->entry
);
1697 static ifref_t
*make_ifref
(type_t
*iface
)
1699 ifref_t
*l
= xmalloc
(sizeof
(ifref_t
));
1705 var_list_t
*append_var
(var_list_t
*list
, var_t
*var
)
1707 if
(!var
) return list
;
1710 list
= xmalloc
( sizeof
(*list
) );
1713 list_add_tail
( list
, &var
->entry
);
1717 static var_list_t
*append_var_list
(var_list_t
*list
, var_list_t
*vars
)
1719 if
(!vars
) return list
;
1722 list
= xmalloc
( sizeof
(*list
) );
1725 list_move_tail
( list
, vars
);
1729 var_t
*make_var
(char *name
)
1731 var_t
*v
= xmalloc
(sizeof
(var_t
));
1736 v
->stgclass
= STG_NONE
;
1737 init_loc_info
(&v
->loc_info
);
1741 static declarator_list_t
*append_declarator
(declarator_list_t
*list
, declarator_t
*d
)
1743 if
(!d
) return list
;
1745 list
= xmalloc
(sizeof
(*list
));
1748 list_add_tail
(list
, &d
->entry
);
1752 static declarator_t
*make_declarator
(var_t
*var
)
1754 declarator_t
*d
= xmalloc
(sizeof
(*d
));
1755 d
->var
= var ? var
: make_var
(NULL
);
1757 d
->func_type
= NULL
;
1763 static type_t
*make_safearray
(type_t
*type
)
1765 return type_new_array
(NULL
, type_new_alias
(type
, "SAFEARRAY"), TRUE
, 0,
1766 NULL
, NULL
, RPC_FC_RP
);
1769 static typelib_t
*make_library
(const char *name
, const attr_list_t
*attrs
)
1771 typelib_t
*typelib
= xmalloc
(sizeof
(*typelib
));
1772 typelib
->name
= xstrdup
(name
);
1773 typelib
->attrs
= attrs
;
1774 list_init
( &typelib
->importlibs
);
1778 static int hash_ident
(const char *name
)
1780 const char *p
= name
;
1782 /* a simple sum hash is probably good enough */
1787 return sum
& (HASHMAX
-1);
1790 /***** type repository *****/
1792 static struct namespace
*find_sub_namespace
(struct namespace
*namespace
, const char *name
)
1794 struct namespace
*cur
;
1796 LIST_FOR_EACH_ENTRY
(cur
, &namespace
->children
, struct namespace
, entry
) {
1797 if
(!strcmp
(cur
->name
, name
))
1804 static void push_namespace
(const char *name
)
1806 struct namespace
*namespace
;
1808 namespace
= find_sub_namespace
(current_namespace
, name
);
1810 namespace
= xmalloc
(sizeof
(*namespace
));
1811 namespace
->name
= xstrdup
(name
);
1812 namespace
->parent
= current_namespace
;
1813 list_add_tail
(¤t_namespace
->children
, &namespace
->entry
);
1814 list_init
(&namespace
->children
);
1815 memset
(namespace
->type_hash
, 0, sizeof
(namespace
->type_hash
));
1818 current_namespace
= namespace
;
1821 static void pop_namespace
(const char *name
)
1823 assert
(!strcmp
(current_namespace
->name
, name
) && current_namespace
->parent
);
1824 current_namespace
= current_namespace
->parent
;
1834 type_t
*reg_type
(type_t
*type
, const char *name
, struct namespace
*namespace
, int t
)
1839 error_loc
("registering named type without name\n");
1843 namespace
= &global_namespace
;
1844 hash
= hash_ident
(name
);
1845 nt
= xmalloc
(sizeof
(struct rtype
));
1847 if
(is_global_namespace
(namespace
))
1848 type
->c_name
= name
;
1850 type
->c_name
= format_namespace
(namespace
, "__x_", "_C", name
);
1853 nt
->next
= namespace
->type_hash
[hash
];
1854 namespace
->type_hash
[hash
] = nt
;
1855 if
((t
== tsSTRUCT || t
== tsUNION
))
1856 fix_incomplete_types
(type
);
1860 static int is_incomplete
(const type_t
*t
)
1862 return
!t
->defined
&&
1863 (type_get_type_detect_alias
(t
) == TYPE_STRUCT ||
1864 type_get_type_detect_alias
(t
) == TYPE_UNION ||
1865 type_get_type_detect_alias
(t
) == TYPE_ENCAPSULATED_UNION
);
1868 void add_incomplete
(type_t
*t
)
1870 struct typenode
*tn
= xmalloc
(sizeof
*tn
);
1872 list_add_tail
(&incomplete_types
, &tn
->entry
);
1875 static void fix_type
(type_t
*t
)
1877 if
(type_is_alias
(t
) && is_incomplete
(t
)) {
1878 type_t
*ot
= type_alias_get_aliasee
(t
);
1880 if
(type_get_type_detect_alias
(ot
) == TYPE_STRUCT ||
1881 type_get_type_detect_alias
(ot
) == TYPE_UNION ||
1882 type_get_type_detect_alias
(ot
) == TYPE_ENCAPSULATED_UNION
)
1883 t
->details.structure
= ot
->details.structure
;
1884 t
->defined
= ot
->defined
;
1888 static void fix_incomplete
(void)
1890 struct typenode
*tn
, *next
;
1892 LIST_FOR_EACH_ENTRY_SAFE
(tn
, next
, &incomplete_types
, struct typenode
, entry
) {
1894 list_remove
(&tn
->entry
);
1899 static void fix_incomplete_types
(type_t
*complete_type
)
1901 struct typenode
*tn
, *next
;
1903 LIST_FOR_EACH_ENTRY_SAFE
(tn
, next
, &incomplete_types
, struct typenode
, entry
)
1905 if
(type_is_equal
(complete_type
, tn
->type
))
1907 tn
->type
->details.structure
= complete_type
->details.structure
;
1908 list_remove
(&tn
->entry
);
1914 static type_t
*reg_typedefs
(decl_spec_t
*decl_spec
, declarator_list_t
*decls
, attr_list_t
*attrs
)
1916 const declarator_t
*decl
;
1917 type_t
*type
= decl_spec
->type
;
1919 if
(is_attr
(attrs
, ATTR_UUID
) && !is_attr
(attrs
, ATTR_PUBLIC
))
1920 attrs
= append_attr
( attrs
, make_attr
(ATTR_PUBLIC
) );
1922 /* We must generate names for tagless enum, struct or union.
1923 Typedef-ing a tagless enum, struct or union means we want the typedef
1924 to be included in a library hence the public attribute. */
1925 if
(type_get_type_detect_alias
(type
) == TYPE_ENUM ||
1926 type_get_type_detect_alias
(type
) == TYPE_STRUCT ||
1927 type_get_type_detect_alias
(type
) == TYPE_UNION ||
1928 type_get_type_detect_alias
(type
) == TYPE_ENCAPSULATED_UNION
)
1931 type
->name
= gen_name
();
1933 /* replace existing attributes when generating a typelib */
1935 type
->attrs
= attrs
;
1938 LIST_FOR_EACH_ENTRY
( decl
, decls
, const declarator_t
, entry
)
1941 if
(decl
->var
->name
) {
1945 cur
= find_type
(decl
->var
->name
, current_namespace
, 0);
1948 * MIDL allows shadowing types that are declared in imported files.
1949 * We don't throw an error in this case and instead add a new type
1950 * (which is earlier on the list in hash table, so it will be used
1951 * instead of shadowed type).
1953 * FIXME: We may consider string separated type tables for each input
1954 * for cleaner solution.
1956 if
(cur
&& input_name
== cur
->loc_info.input_name
)
1957 error_loc
("%s: redefinition error; original definition was at %s:%d\n",
1958 cur
->name
, cur
->loc_info.input_name
,
1959 cur
->loc_info.line_number
);
1961 name
= declare_var
(attrs
, decl_spec
, decl
, 0);
1962 cur
= type_new_alias
(name
->type
, name
->name
);
1965 if
(is_incomplete
(cur
))
1966 add_incomplete
(cur
);
1967 reg_type
(cur
, cur
->name
, current_namespace
, 0);
1973 type_t
*find_type
(const char *name
, struct namespace
*namespace
, int t
)
1977 if
(namespace
&& namespace
!= &global_namespace
) {
1978 for
(cur
= namespace
->type_hash
[hash_ident
(name
)]; cur
; cur
= cur
->next
) {
1979 if
(cur
->t
== t
&& !strcmp
(cur
->name
, name
))
1983 for
(cur
= global_namespace.type_hash
[hash_ident
(name
)]; cur
; cur
= cur
->next
) {
1984 if
(cur
->t
== t
&& !strcmp
(cur
->name
, name
))
1990 static type_t
*find_type_or_error
(const char *name
, int t
)
1992 type_t
*type
= find_type
(name
, NULL
, t
);
1994 error_loc
("type '%s' not found\n", name
);
2000 static type_t
*find_type_or_error2
(char *name
, int t
)
2002 type_t
*tp
= find_type_or_error
(name
, t
);
2007 int is_type
(const char *name
)
2009 return find_type
(name
, current_namespace
, 0) != NULL
;
2012 type_t
*get_type
(enum type_type type
, char *name
, struct namespace
*namespace
, int t
)
2016 namespace
= &global_namespace
;
2018 tp
= find_type
(name
, namespace
, t
);
2024 tp
= make_type
(type
);
2026 tp
->namespace
= namespace
;
2027 if
(!name
) return tp
;
2028 return reg_type
(tp
, name
, namespace
, t
);
2031 /***** constant repository *****/
2036 struct rconst
*next
;
2039 struct rconst
*const_hash
[HASHMAX
];
2041 static var_t
*reg_const
(var_t
*var
)
2046 error_loc
("registering constant without name\n");
2049 hash
= hash_ident
(var
->name
);
2050 nc
= xmalloc
(sizeof
(struct rconst
));
2051 nc
->name
= var
->name
;
2053 nc
->next
= const_hash
[hash
];
2054 const_hash
[hash
] = nc
;
2058 var_t
*find_const
(const char *name
, int f
)
2060 struct rconst
*cur
= const_hash
[hash_ident
(name
)];
2061 while
(cur
&& strcmp
(cur
->name
, name
))
2064 if
(f
) error_loc
("constant '%s' not found\n", name
);
2070 static char *gen_name
(void)
2072 static const char format
[] = "__WIDL_%s_generated_name_%08lX";
2073 static unsigned long n
= 0;
2074 static const char *file_id
;
2080 char *dst
= dup_basename
(input_idl_name
, ".idl");
2084 if
(! isalnum
((unsigned char) *dst
))
2087 size
= sizeof format
- 7 + strlen
(file_id
) + 8;
2090 name
= xmalloc
(size
);
2091 sprintf
(name
, format
, file_id
, n
++);
2097 unsigned int dce_compatible
: 1;
2098 unsigned int acf
: 1;
2099 unsigned int on_interface
: 1;
2100 unsigned int on_function
: 1;
2101 unsigned int on_arg
: 1;
2102 unsigned int on_type
: 1;
2103 unsigned int on_enum
: 1;
2104 unsigned int on_struct
: 2;
2105 unsigned int on_union
: 1;
2106 unsigned int on_field
: 1;
2107 unsigned int on_library
: 1;
2108 unsigned int on_dispinterface
: 1;
2109 unsigned int on_module
: 1;
2110 unsigned int on_coclass
: 1;
2111 const char *display_name
;
2114 struct allowed_attr allowed_attr
[] =
2116 /* attr { D ACF I Fn ARG T En St Un Fi L DI M C <display name> } */
2117 /* ATTR_AGGREGATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "aggregatable" },
2118 /* ATTR_ANNOTATION */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "annotation" },
2119 /* ATTR_APPOBJECT */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "appobject" },
2120 /* ATTR_ASYNC */ { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "async" },
2121 /* ATTR_ASYNCUUID */ { 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "async_uuid" },
2122 /* ATTR_AUTO_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "auto_handle" },
2123 /* ATTR_BINDABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "bindable" },
2124 /* ATTR_BROADCAST */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "broadcast" },
2125 /* ATTR_CALLAS */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "call_as" },
2126 /* ATTR_CALLCONV */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
},
2127 /* ATTR_CASE */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "case" },
2128 /* ATTR_CODE */ { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "code" },
2129 /* ATTR_COMMSTATUS */ { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "comm_status" },
2130 /* ATTR_CONST */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "const" },
2131 /* ATTR_CONTEXTHANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "context_handle" },
2132 /* ATTR_CONTROL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, "control" },
2133 /* ATTR_DECODE */ { 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "decode" },
2134 /* ATTR_DEFAULT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, "default" },
2135 /* ATTR_DEFAULTBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultbind" },
2136 /* ATTR_DEFAULTCOLLELEM */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultcollelem" },
2137 /* ATTR_DEFAULTVALUE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultvalue" },
2138 /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "defaultvtable" },
2139 /* ATTR_DISABLECONSISTENCYCHECK */{ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "disable_consistency_check" },
2140 /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
},
2141 /* ATTR_DISPLAYBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "displaybind" },
2142 /* ATTR_DLLNAME */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, "dllname" },
2143 /* ATTR_DUAL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "dual" },
2144 /* ATTR_ENABLEALLOCATE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "enable_allocate" },
2145 /* ATTR_ENCODE */ { 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "encode" },
2146 /* ATTR_ENDPOINT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "endpoint" },
2147 /* ATTR_ENTRY */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "entry" },
2148 /* ATTR_EXPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "explicit_handle" },
2149 /* ATTR_FAULTSTATUS */ { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "fault_status" },
2150 /* ATTR_FORCEALLOCATE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "force_allocate" },
2151 /* ATTR_HANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "handle" },
2152 /* ATTR_HELPCONTEXT */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpcontext" },
2153 /* ATTR_HELPFILE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpfile" },
2154 /* ATTR_HELPSTRING */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpstring" },
2155 /* ATTR_HELPSTRINGCONTEXT */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpstringcontext" },
2156 /* ATTR_HELPSTRINGDLL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpstringdll" },
2157 /* ATTR_HIDDEN */ { 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, "hidden" },
2158 /* ATTR_ID */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, "id" },
2159 /* ATTR_IDEMPOTENT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "idempotent" },
2160 /* ATTR_IGNORE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "ignore" },
2161 /* ATTR_IIDIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "iid_is" },
2162 /* ATTR_IMMEDIATEBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "immediatebind" },
2163 /* ATTR_IMPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "implicit_handle" },
2164 /* ATTR_IN */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "in" },
2165 /* ATTR_INLINE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inline" },
2166 /* ATTR_INPUTSYNC */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inputsync" },
2167 /* ATTR_LENGTHIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "length_is" },
2168 /* ATTR_LIBLCID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "lcid" },
2169 /* ATTR_LICENSED */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "licensed" },
2170 /* ATTR_LOCAL */ { 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "local" },
2171 /* ATTR_MAYBE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "maybe" },
2172 /* ATTR_MESSAGE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "message" },
2173 /* ATTR_NOCODE */ { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nocode" },
2174 /* ATTR_NONBROWSABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonbrowsable" },
2175 /* ATTR_NONCREATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "noncreatable" },
2176 /* ATTR_NONEXTENSIBLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonextensible" },
2177 /* ATTR_NOTIFY */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "notify" },
2178 /* ATTR_NOTIFYFLAG */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "notify_flag" },
2179 /* ATTR_OBJECT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "object" },
2180 /* ATTR_ODL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "odl" },
2181 /* ATTR_OLEAUTOMATION */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "oleautomation" },
2182 /* ATTR_OPTIMIZE */ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optimize" },
2183 /* ATTR_OPTIONAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optional" },
2184 /* ATTR_OUT */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "out" },
2185 /* ATTR_PARAMLCID */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "lcid" },
2186 /* ATTR_PARTIALIGNORE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "partial_ignore" },
2187 /* ATTR_POINTERDEFAULT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "pointer_default" },
2188 /* ATTR_POINTERTYPE */ { 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, "ref, unique or ptr" },
2189 /* ATTR_PROGID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "progid" },
2190 /* ATTR_PROPGET */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propget" },
2191 /* ATTR_PROPPUT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propput" },
2192 /* ATTR_PROPPUTREF */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propputref" },
2193 /* ATTR_PROXY */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "proxy" },
2194 /* ATTR_PUBLIC */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "public" },
2195 /* ATTR_RANGE */ { 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, "range" },
2196 /* ATTR_READONLY */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "readonly" },
2197 /* ATTR_REPRESENTAS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "represent_as" },
2198 /* ATTR_REQUESTEDIT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "requestedit" },
2199 /* ATTR_RESTRICTED */ { 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, "restricted" },
2200 /* ATTR_RETVAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "retval" },
2201 /* ATTR_SIZEIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "size_is" },
2202 /* ATTR_SOURCE */ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "source" },
2203 /* ATTR_STRICTCONTEXTHANDLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "strict_context_handle" },
2204 /* ATTR_STRING */ { 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, "string" },
2205 /* ATTR_SWITCHIS */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "switch_is" },
2206 /* ATTR_SWITCHTYPE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, "switch_type" },
2207 /* ATTR_THREADING */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "threading" },
2208 /* ATTR_TRANSMITAS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "transmit_as" },
2209 /* ATTR_UIDEFAULT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "uidefault" },
2210 /* ATTR_USESGETLASTERROR */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "usesgetlasterror" },
2211 /* ATTR_USERMARSHAL */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "user_marshal" },
2212 /* ATTR_UUID */ { 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, "uuid" },
2213 /* ATTR_V1ENUM */ { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, "v1_enum" },
2214 /* ATTR_VARARG */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "vararg" },
2215 /* ATTR_VERSION */ { 1, 0, 1, 0, 0, 1, 1, 2, 0, 0, 1, 0, 0, 1, "version" },
2216 /* ATTR_VIPROGID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "vi_progid" },
2217 /* ATTR_WIREMARSHAL */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "wire_marshal" },
2220 const char *get_attr_display_name
(enum attr_type type
)
2222 return allowed_attr
[type
].display_name
;
2225 static attr_list_t
*check_iface_attrs
(const char *name
, attr_list_t
*attrs
)
2228 if
(!attrs
) return attrs
;
2229 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2231 if
(!allowed_attr
[attr
->type
].on_interface
)
2232 error_loc
("inapplicable attribute %s for interface %s\n",
2233 allowed_attr
[attr
->type
].display_name
, name
);
2234 if
(attr
->type
== ATTR_IMPLICIT_HANDLE
)
2236 const var_t
*var
= attr
->u.pval
;
2237 if
(type_get_type
( var
->type
) == TYPE_BASIC
&&
2238 type_basic_get_type
( var
->type
) == TYPE_BASIC_HANDLE
)
2240 if
(is_aliaschain_attr
( var
->type
, ATTR_HANDLE
))
2242 error_loc
("attribute %s requires a handle type in interface %s\n",
2243 allowed_attr
[attr
->type
].display_name
, name
);
2249 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
)
2252 if
(!attrs
) return attrs
;
2253 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2255 if
(!allowed_attr
[attr
->type
].on_function
)
2256 error_loc
("inapplicable attribute %s for function %s\n",
2257 allowed_attr
[attr
->type
].display_name
, name
);
2262 static void check_arg_attrs
(const var_t
*arg
)
2268 LIST_FOR_EACH_ENTRY
(attr
, arg
->attrs
, const attr_t
, entry
)
2270 if
(!allowed_attr
[attr
->type
].on_arg
)
2271 error_loc
("inapplicable attribute %s for argument %s\n",
2272 allowed_attr
[attr
->type
].display_name
, arg
->name
);
2277 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
)
2280 if
(!attrs
) return attrs
;
2281 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2283 if
(!allowed_attr
[attr
->type
].on_type
)
2284 error_loc
("inapplicable attribute %s for typedef\n",
2285 allowed_attr
[attr
->type
].display_name
);
2290 static attr_list_t
*check_enum_attrs
(attr_list_t
*attrs
)
2293 if
(!attrs
) return attrs
;
2294 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2296 if
(!allowed_attr
[attr
->type
].on_enum
)
2297 error_loc
("inapplicable attribute %s for enum\n",
2298 allowed_attr
[attr
->type
].display_name
);
2303 static attr_list_t
*check_struct_attrs
(attr_list_t
*attrs
)
2305 int mask
= winrt_mode ?
3 : 1;
2307 if
(!attrs
) return attrs
;
2308 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2310 if
(!(allowed_attr
[attr
->type
].on_struct
& mask
))
2311 error_loc
("inapplicable attribute %s for struct\n",
2312 allowed_attr
[attr
->type
].display_name
);
2317 static attr_list_t
*check_union_attrs
(attr_list_t
*attrs
)
2320 if
(!attrs
) return attrs
;
2321 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2323 if
(!allowed_attr
[attr
->type
].on_union
)
2324 error_loc
("inapplicable attribute %s for union\n",
2325 allowed_attr
[attr
->type
].display_name
);
2330 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
)
2333 if
(!attrs
) return attrs
;
2334 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2336 if
(!allowed_attr
[attr
->type
].on_field
)
2337 error_loc
("inapplicable attribute %s for field %s\n",
2338 allowed_attr
[attr
->type
].display_name
, name
);
2343 static attr_list_t
*check_library_attrs
(const char *name
, attr_list_t
*attrs
)
2346 if
(!attrs
) return attrs
;
2347 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2349 if
(!allowed_attr
[attr
->type
].on_library
)
2350 error_loc
("inapplicable attribute %s for library %s\n",
2351 allowed_attr
[attr
->type
].display_name
, name
);
2356 static attr_list_t
*check_dispiface_attrs
(const char *name
, attr_list_t
*attrs
)
2359 if
(!attrs
) return attrs
;
2360 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2362 if
(!allowed_attr
[attr
->type
].on_dispinterface
)
2363 error_loc
("inapplicable attribute %s for dispinterface %s\n",
2364 allowed_attr
[attr
->type
].display_name
, name
);
2369 static attr_list_t
*check_module_attrs
(const char *name
, attr_list_t
*attrs
)
2372 if
(!attrs
) return attrs
;
2373 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2375 if
(!allowed_attr
[attr
->type
].on_module
)
2376 error_loc
("inapplicable attribute %s for module %s\n",
2377 allowed_attr
[attr
->type
].display_name
, name
);
2382 static attr_list_t
*check_coclass_attrs
(const char *name
, attr_list_t
*attrs
)
2385 if
(!attrs
) return attrs
;
2386 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2388 if
(!allowed_attr
[attr
->type
].on_coclass
)
2389 error_loc
("inapplicable attribute %s for coclass %s\n",
2390 allowed_attr
[attr
->type
].display_name
, name
);
2395 static int is_allowed_conf_type
(const type_t
*type
)
2397 switch
(type_get_type
(type
))
2402 switch
(type_basic_get_type
(type
))
2404 case TYPE_BASIC_INT8
:
2405 case TYPE_BASIC_INT16
:
2406 case TYPE_BASIC_INT32
:
2407 case TYPE_BASIC_INT64
:
2408 case TYPE_BASIC_INT
:
2409 case TYPE_BASIC_CHAR
:
2410 case TYPE_BASIC_HYPER
:
2411 case TYPE_BASIC_BYTE
:
2412 case TYPE_BASIC_WCHAR
:
2418 /* shouldn't get here because of type_get_type call above */
2423 case TYPE_ENCAPSULATED_UNION
:
2430 case TYPE_INTERFACE
:
2437 static int is_ptr_guid_type
(const type_t
*type
)
2439 /* first, make sure it is a pointer to something */
2440 if
(!is_ptr
(type
)) return FALSE
;
2442 /* second, make sure it is a pointer to something of size sizeof(GUID),
2444 return
(type_memsize
(type_pointer_get_ref
(type
)) == 16);
2447 static void check_conformance_expr_list
(const char *attr_name
, const var_t
*arg
, const type_t
*container_type
, expr_list_t
*expr_list
)
2450 struct expr_loc expr_loc
;
2452 expr_loc.attr
= attr_name
;
2453 if
(expr_list
) LIST_FOR_EACH_ENTRY
(dim
, expr_list
, expr_t
, entry
)
2455 if
(dim
->type
!= EXPR_VOID
)
2457 const type_t
*expr_type
= expr_resolve_type
(&expr_loc
, container_type
, dim
);
2458 if
(!is_allowed_conf_type
(expr_type
))
2459 error_loc_info
(&arg
->loc_info
, "expression must resolve to integral type <= 32bits for attribute %s\n",
2465 static void check_remoting_fields
(const var_t
*var
, type_t
*type
);
2467 /* checks that properties common to fields and arguments are consistent */
2468 static void check_field_common
(const type_t
*container_type
,
2469 const char *container_name
, const var_t
*arg
)
2471 type_t
*type
= arg
->type
;
2473 const char *container_type_name
;
2474 const char *var_type
;
2476 switch
(type_get_type
(container_type
))
2479 container_type_name
= "struct";
2483 container_type_name
= "union";
2486 case TYPE_ENCAPSULATED_UNION
:
2487 container_type_name
= "encapsulated union";
2491 container_type_name
= "function";
2492 var_type
= "parameter";
2495 /* should be no other container types */
2500 if
(is_attr
(arg
->attrs
, ATTR_LENGTHIS
) &&
2501 (is_attr
(arg
->attrs
, ATTR_STRING
) || is_aliaschain_attr
(arg
->type
, ATTR_STRING
)))
2502 error_loc_info
(&arg
->loc_info
,
2503 "string and length_is specified for argument %s are mutually exclusive attributes\n",
2506 if
(is_attr
(arg
->attrs
, ATTR_SIZEIS
))
2508 expr_list_t
*size_is_exprs
= get_attrp
(arg
->attrs
, ATTR_SIZEIS
);
2509 check_conformance_expr_list
("size_is", arg
, container_type
, size_is_exprs
);
2511 if
(is_attr
(arg
->attrs
, ATTR_LENGTHIS
))
2513 expr_list_t
*length_is_exprs
= get_attrp
(arg
->attrs
, ATTR_LENGTHIS
);
2514 check_conformance_expr_list
("length_is", arg
, container_type
, length_is_exprs
);
2516 if
(is_attr
(arg
->attrs
, ATTR_IIDIS
))
2518 struct expr_loc expr_loc
;
2519 expr_t
*expr
= get_attrp
(arg
->attrs
, ATTR_IIDIS
);
2520 if
(expr
->type
!= EXPR_VOID
)
2522 const type_t
*expr_type
;
2524 expr_loc.attr
= "iid_is";
2525 expr_type
= expr_resolve_type
(&expr_loc
, container_type
, expr
);
2526 if
(!expr_type ||
!is_ptr_guid_type
(expr_type
))
2527 error_loc_info
(&arg
->loc_info
, "expression must resolve to pointer to GUID type for attribute iid_is\n");
2530 if
(is_attr
(arg
->attrs
, ATTR_SWITCHIS
))
2532 struct expr_loc expr_loc
;
2533 expr_t
*expr
= get_attrp
(arg
->attrs
, ATTR_SWITCHIS
);
2534 if
(expr
->type
!= EXPR_VOID
)
2536 const type_t
*expr_type
;
2538 expr_loc.attr
= "switch_is";
2539 expr_type
= expr_resolve_type
(&expr_loc
, container_type
, expr
);
2540 if
(!expr_type ||
!is_allowed_conf_type
(expr_type
))
2541 error_loc_info
(&arg
->loc_info
, "expression must resolve to integral type <= 32bits for attribute %s\n",
2550 switch
(typegen_detect_type
(type
, arg
->attrs
, TDT_IGNORE_STRINGS
))
2554 check_remoting_fields
(arg
, type
);
2558 const char *reason
= "is invalid";
2559 switch
(type_get_type
(type
))
2562 reason
= "cannot derive from void *";
2565 reason
= "cannot be a function pointer";
2568 reason
= "cannot be a bit-field";
2571 reason
= "cannot be a class";
2573 case TYPE_INTERFACE
:
2574 reason
= "cannot be a non-pointer to an interface";
2577 reason
= "cannot be a module";
2582 error_loc_info
(&arg
->loc_info
, "%s \'%s\' of %s \'%s\' %s\n",
2583 var_type
, arg
->name
, container_type_name
, container_name
, reason
);
2586 case TGT_CTXT_HANDLE
:
2587 case TGT_CTXT_HANDLE_POINTER
:
2588 if
(type_get_type
(container_type
) != TYPE_FUNCTION
)
2589 error_loc_info
(&arg
->loc_info
,
2590 "%s \'%s\' of %s \'%s\' cannot be a context handle\n",
2591 var_type
, arg
->name
, container_type_name
,
2596 const type_t
*t
= type
;
2598 t
= type_pointer_get_ref
(t
);
2599 if
(is_aliaschain_attr
(t
, ATTR_RANGE
))
2600 warning_loc_info
(&arg
->loc_info
, "%s: range not verified for a string of ranged types\n", arg
->name
);
2604 type
= type_pointer_get_ref
(type
);
2608 type
= type_array_get_element
(type
);
2612 case TGT_IFACE_POINTER
:
2619 } while
(more_to_do
);
2622 static void check_remoting_fields
(const var_t
*var
, type_t
*type
)
2625 const var_list_t
*fields
= NULL
;
2627 type
= type_get_real_type
(type
);
2632 type
->checked
= TRUE
;
2634 if
(type_get_type
(type
) == TYPE_STRUCT
)
2636 if
(type_is_complete
(type
))
2637 fields
= type_struct_get_fields
(type
);
2639 error_loc_info
(&var
->loc_info
, "undefined type declaration %s\n", type
->name
);
2641 else if
(type_get_type
(type
) == TYPE_UNION || type_get_type
(type
) == TYPE_ENCAPSULATED_UNION
)
2642 fields
= type_union_get_cases
(type
);
2644 if
(fields
) LIST_FOR_EACH_ENTRY
( field
, fields
, const var_t
, entry
)
2645 if
(field
->type
) check_field_common
(type
, type
->name
, field
);
2648 /* checks that arguments for a function make sense for marshalling and unmarshalling */
2649 static void check_remoting_args
(const var_t
*func
)
2651 const char *funcname
= func
->name
;
2654 if
(func
->type
->details.function
->args
) LIST_FOR_EACH_ENTRY
( arg
, func
->type
->details.function
->args
, const var_t
, entry
)
2656 const type_t
*type
= arg
->type
;
2658 /* check that [out] parameters have enough pointer levels */
2659 if
(is_attr
(arg
->attrs
, ATTR_OUT
))
2661 switch
(typegen_detect_type
(type
, arg
->attrs
, TDT_ALL_TYPES
))
2668 case TGT_CTXT_HANDLE
:
2670 error_loc_info
(&arg
->loc_info
, "out parameter \'%s\' of function \'%s\' is not a pointer\n", arg
->name
, funcname
);
2672 case TGT_IFACE_POINTER
:
2673 error_loc_info
(&arg
->loc_info
, "out interface pointer \'%s\' of function \'%s\' is not a double pointer\n", arg
->name
, funcname
);
2678 /* needs conformance or fixed dimension */
2679 if
(type_array_has_conformance
(type
) &&
2680 type_array_get_conformance
(type
)->type
!= EXPR_VOID
) break
;
2681 if
(!type_array_has_conformance
(type
) && type_array_get_dim
(type
)) break
;
2683 if
(is_attr
( arg
->attrs
, ATTR_IN
)) break
;
2684 error_loc_info
(&arg
->loc_info
, "out parameter \'%s\' of function \'%s\' cannot be an unsized string\n", arg
->name
, funcname
);
2687 /* already error'd before we get here */
2688 case TGT_CTXT_HANDLE_POINTER
:
2696 check_field_common
(func
->type
, funcname
, arg
);
2699 if
(type_get_type
(type_function_get_rettype
(func
->type
)) != TYPE_VOID
)
2703 var.type
= type_function_get_rettype
(func
->type
);
2704 var.name
= xstrdup
("return value");
2705 check_field_common
(func
->type
, funcname
, &var
);
2710 static void add_explicit_handle_if_necessary
(const type_t
*iface
, var_t
*func
)
2712 unsigned char explicit_fc
, implicit_fc
;
2714 /* check for a defined binding handle */
2715 if
(!get_func_handle_var
( iface
, func
, &explicit_fc
, &implicit_fc
) ||
!explicit_fc
)
2717 /* no explicit handle specified so add
2718 * "[in] handle_t IDL_handle" as the first parameter to the
2720 var_t
*idl_handle
= make_var
(xstrdup
("IDL_handle"));
2721 idl_handle
->attrs
= append_attr
(NULL
, make_attr
(ATTR_IN
));
2722 idl_handle
->type
= find_type_or_error
("handle_t", 0);
2723 type_function_add_head_arg
(func
->type
, idl_handle
);
2727 static void check_functions
(const type_t
*iface
, int is_inside_library
)
2729 const statement_t
*stmt
;
2730 if
(is_attr
(iface
->attrs
, ATTR_EXPLICIT_HANDLE
))
2732 STATEMENTS_FOR_EACH_FUNC
( stmt
, type_iface_get_stmts
(iface
) )
2734 var_t
*func
= stmt
->u.var
;
2735 add_explicit_handle_if_necessary
(iface
, func
);
2738 if
(!is_inside_library
&& !is_attr
(iface
->attrs
, ATTR_LOCAL
))
2740 STATEMENTS_FOR_EACH_FUNC
( stmt
, type_iface_get_stmts
(iface
) )
2742 const var_t
*func
= stmt
->u.var
;
2743 if
(!is_attr
(func
->attrs
, ATTR_LOCAL
))
2744 check_remoting_args
(func
);
2749 static void check_statements
(const statement_list_t
*stmts
, int is_inside_library
)
2751 const statement_t
*stmt
;
2753 if
(stmts
) LIST_FOR_EACH_ENTRY
(stmt
, stmts
, const statement_t
, entry
)
2755 switch
(stmt
->type
) {
2757 check_statements
(stmt
->u.lib
->stmts
, TRUE
);
2760 switch
(type_get_type
(stmt
->u.type
)) {
2761 case TYPE_INTERFACE
:
2762 check_functions
(stmt
->u.type
, is_inside_library
);
2766 error_loc
("coclass is not allowed in Windows Runtime mode\n");
2778 static void check_all_user_types
(const statement_list_t
*stmts
)
2780 const statement_t
*stmt
;
2782 if
(stmts
) LIST_FOR_EACH_ENTRY
(stmt
, stmts
, const statement_t
, entry
)
2784 if
(stmt
->type
== STMT_LIBRARY
)
2785 check_all_user_types
(stmt
->u.lib
->stmts
);
2786 else if
(stmt
->type
== STMT_TYPE
&& type_get_type
(stmt
->u.type
) == TYPE_INTERFACE
&&
2787 !is_local
(stmt
->u.type
->attrs
))
2789 const statement_t
*stmt_func
;
2790 STATEMENTS_FOR_EACH_FUNC
(stmt_func
, type_iface_get_stmts
(stmt
->u.type
)) {
2791 const var_t
*func
= stmt_func
->u.var
;
2792 check_for_additional_prototype_types
(func
->type
->details.function
->args
);
2798 int is_valid_uuid
(const char *s
)
2802 for
(i
= 0; i
< 36; ++i
)
2803 if
(i
== 8 || i
== 13 || i
== 18 || i
== 23)
2809 if
(!isxdigit
(s
[i
]))
2812 return s
[i
] == '\0';
2815 static statement_t
*make_statement
(enum statement_type type
)
2817 statement_t
*stmt
= xmalloc
(sizeof
(*stmt
));
2822 static statement_t
*make_statement_type_decl
(type_t
*type
)
2824 statement_t
*stmt
= make_statement
(STMT_TYPE
);
2825 stmt
->u.type
= type
;
2829 static statement_t
*make_statement_reference
(type_t
*type
)
2831 statement_t
*stmt
= make_statement
(STMT_TYPEREF
);
2832 stmt
->u.type
= type
;
2836 static statement_t
*make_statement_declaration
(var_t
*var
)
2838 statement_t
*stmt
= make_statement
(STMT_DECLARATION
);
2840 if
(var
->stgclass
== STG_EXTERN
&& var
->eval
)
2841 warning
("'%s' initialised and declared extern\n", var
->name
);
2842 if
(is_const_decl
(var
))
2847 else if
(type_get_type
(var
->type
) == TYPE_FUNCTION
)
2848 check_function_attrs
(var
->name
, var
->attrs
);
2849 else if
(var
->stgclass
== STG_NONE || var
->stgclass
== STG_REGISTER
)
2850 error_loc
("instantiation of data is illegal\n");
2854 static statement_t
*make_statement_library
(typelib_t
*typelib
)
2856 statement_t
*stmt
= make_statement
(STMT_LIBRARY
);
2857 stmt
->u.lib
= typelib
;
2861 static statement_t
*make_statement_pragma
(const char *str
)
2863 statement_t
*stmt
= make_statement
(STMT_PRAGMA
);
2868 static statement_t
*make_statement_cppquote
(const char *str
)
2870 statement_t
*stmt
= make_statement
(STMT_CPPQUOTE
);
2875 static statement_t
*make_statement_importlib
(const char *str
)
2877 statement_t
*stmt
= make_statement
(STMT_IMPORTLIB
);
2882 static statement_t
*make_statement_import
(const char *str
)
2884 statement_t
*stmt
= make_statement
(STMT_IMPORT
);
2889 static statement_t
*make_statement_module
(type_t
*type
)
2891 statement_t
*stmt
= make_statement
(STMT_MODULE
);
2892 stmt
->u.type
= type
;
2896 static statement_t
*make_statement_typedef
(declarator_list_t
*decls
)
2898 declarator_t
*decl
, *next
;
2900 type_list_t
**type_list
;
2902 if
(!decls
) return NULL
;
2904 stmt
= make_statement
(STMT_TYPEDEF
);
2905 stmt
->u.type_list
= NULL
;
2906 type_list
= &stmt
->u.type_list
;
2908 LIST_FOR_EACH_ENTRY_SAFE
( decl
, next
, decls
, declarator_t
, entry
)
2910 var_t
*var
= decl
->var
;
2911 type_t
*type
= find_type_or_error
(var
->name
, 0);
2912 *type_list
= xmalloc
(sizeof
(type_list_t
));
2913 (*type_list
)->type
= type
;
2914 (*type_list
)->next
= NULL
;
2916 type_list
= &(*type_list
)->next
;
2924 static statement_list_t
*append_statements
(statement_list_t
*l1
, statement_list_t
*l2
)
2927 if
(!l1 || l1
== l2
) return l2
;
2928 list_move_tail
(l1
, l2
);
2932 static attr_list_t
*append_attribs
(attr_list_t
*l1
, attr_list_t
*l2
)
2935 if
(!l1 || l1
== l2
) return l2
;
2936 list_move_tail
(l1
, l2
);
2940 static statement_list_t
*append_statement
(statement_list_t
*list
, statement_t
*stmt
)
2942 if
(!stmt
) return list
;
2945 list
= xmalloc
( sizeof
(*list
) );
2948 list_add_tail
( list
, &stmt
->entry
);
2952 void init_loc_info
(loc_info_t
*i
)
2954 i
->input_name
= input_name ? input_name
: "stdin";
2955 i
->line_number
= line_number
;
2956 i
->near_text
= parser_text
;
2959 static void check_def
(const type_t
*t
)
2962 error_loc
("%s: redefinition error; original definition was at %s:%d\n",
2963 t
->name
, t
->loc_info.input_name
, t
->loc_info.line_number
);