msvcp140_atomic_wait: Add __std_atomic_notify_one_direct implementation.
[wine.git] / tools / widl / parser.y
blob02db99a55b7b57a4105cc661628e0371e0d2f58b
1 %{
2 /*
3 * IDL Compiler
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
23 #include "config.h"
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <stdarg.h>
28 #include <assert.h>
29 #include <ctype.h>
30 #include <string.h>
32 #include "widl.h"
33 #include "utils.h"
34 #include "parser.h"
35 #include "header.h"
36 #include "typelib.h"
37 #include "typegen.h"
38 #include "expr.h"
39 #include "typetree.h"
41 struct _import_t
43 char *name;
44 int import_performed;
47 static str_list_t *append_str(str_list_t *list, char *str);
48 static attr_list_t *append_attr_list(attr_list_t *new_list, attr_list_t *old_list);
49 static decl_spec_t *make_decl_spec(type_t *type, decl_spec_t *left, decl_spec_t *right,
50 enum storage_class stgclass, enum type_qualifier qual, enum function_specifier func_specifier);
51 static attr_t *make_attr(enum attr_type type);
52 static attr_t *make_attrv(enum attr_type type, unsigned int val);
53 static attr_t *make_custom_attr(struct uuid *id, expr_t *pval);
54 static expr_list_t *append_expr(expr_list_t *list, expr_t *expr);
55 static var_t *declare_var(attr_list_t *attrs, decl_spec_t *decl_spec, declarator_t *decl, int top);
56 static var_list_t *set_var_types(attr_list_t *attrs, decl_spec_t *decl_spec, declarator_list_t *decls);
57 static var_list_t *append_var_list(var_list_t *list, var_list_t *vars);
58 static declarator_list_t *append_declarator(declarator_list_t *list, declarator_t *p);
59 static declarator_t *make_declarator(var_t *var);
60 static type_t *make_safearray(type_t *type);
61 static typelib_t *make_library(const char *name, const attr_list_t *attrs);
62 static void append_array(declarator_t *decl, expr_t *expr);
63 static void append_chain_type(declarator_t *decl, type_t *type, enum type_qualifier qual);
64 static void append_chain_callconv(type_t *chain, char *callconv);
65 static warning_list_t *append_warning(warning_list_t *, int);
67 static type_t *reg_typedefs(decl_spec_t *decl_spec, var_list_t *names, attr_list_t *attrs);
68 static type_t *find_type_or_error(struct namespace *parent, const char *name);
69 static struct namespace *find_namespace_or_error(struct namespace *namespace, const char *name);
71 static var_t *reg_const(var_t *var);
73 static void push_namespaces(str_list_t *names);
74 static void pop_namespaces(str_list_t *names);
75 static void push_parameters_namespace(const char *name);
76 static void pop_parameters_namespace(const char *name);
78 static statement_list_t *append_parameterized_type_stmts(statement_list_t *stmts);
79 static void check_arg_attrs(const var_t *arg);
80 static void check_statements(const statement_list_t *stmts, int is_inside_library);
81 static void check_all_user_types(const statement_list_t *stmts);
82 static attr_list_t *check_function_attrs(const char *name, attr_list_t *attrs);
83 static attr_list_t *check_typedef_attrs(attr_list_t *attrs);
84 static attr_list_t *check_enum_attrs(attr_list_t *attrs);
85 static attr_list_t *check_enum_member_attrs(attr_list_t *attrs);
86 static attr_list_t *check_struct_attrs(attr_list_t *attrs);
87 static attr_list_t *check_union_attrs(attr_list_t *attrs);
88 static attr_list_t *check_field_attrs(const char *name, attr_list_t *attrs);
89 static attr_list_t *check_library_attrs(const char *name, attr_list_t *attrs);
90 const char *get_attr_display_name(enum attr_type type);
91 static void add_explicit_handle_if_necessary(const type_t *iface, var_t *func);
93 static void check_async_uuid(type_t *iface);
95 static statement_t *make_statement(enum statement_type type);
96 static statement_t *make_statement_type_decl(type_t *type);
97 static statement_t *make_statement_reference(type_t *type);
98 static statement_t *make_statement_declaration(var_t *var);
99 static statement_t *make_statement_library(typelib_t *typelib);
100 static statement_t *make_statement_pragma(const char *str);
101 static statement_t *make_statement_cppquote(const char *str);
102 static statement_t *make_statement_importlib(const char *str);
103 static statement_t *make_statement_module(type_t *type);
104 static statement_t *make_statement_typedef(var_list_t *names, int declonly);
105 static statement_t *make_statement_import(const char *str);
106 static statement_t *make_statement_parameterized_type(type_t *type, typeref_list_t *params);
107 static statement_t *make_statement_delegate(type_t *ret, var_list_t *args);
108 static statement_list_t *append_statement(statement_list_t *list, statement_t *stmt);
109 static statement_list_t *append_statements(statement_list_t *, statement_list_t *);
110 static attr_list_t *append_attribs(attr_list_t *, attr_list_t *);
112 static struct namespace global_namespace = {
113 NULL, NULL, LIST_INIT(global_namespace.entry), LIST_INIT(global_namespace.children)
116 static struct namespace *current_namespace = &global_namespace;
117 static struct namespace *parameters_namespace = NULL;
118 static statement_list_t *parameterized_type_stmts = NULL;
120 static typelib_t *current_typelib;
124 %define api.prefix {parser_}
126 %union {
127 attr_t *attr;
128 attr_list_t *attr_list;
129 str_list_t *str_list;
130 expr_t *expr;
131 expr_list_t *expr_list;
132 type_t *type;
133 var_t *var;
134 var_list_t *var_list;
135 declarator_t *declarator;
136 declarator_list_t *declarator_list;
137 statement_t *statement;
138 statement_list_t *stmt_list;
139 warning_t *warning;
140 warning_list_t *warning_list;
141 typeref_t *typeref;
142 typeref_list_t *typeref_list;
143 char *str;
144 struct uuid *uuid;
145 unsigned int num;
146 double dbl;
147 typelib_t *typelib;
148 struct _import_t *import;
149 struct _decl_spec_t *declspec;
150 enum storage_class stgclass;
151 enum type_qualifier type_qualifier;
152 enum function_specifier function_specifier;
153 struct namespace *namespace;
156 %token <str> aIDENTIFIER aPRAGMA
157 %token <str> aKNOWNTYPE
158 %token <num> aNUM aHEXNUM
159 %token <dbl> aDOUBLE
160 %token <str> aSTRING aWSTRING aSQSTRING
161 %token <uuid> aUUID
162 %token aEOF aACF
163 %token SHL SHR
164 %token MEMBERPTR
165 %token EQUALITY INEQUALITY
166 %token GREATEREQUAL LESSEQUAL
167 %token LOGICALOR LOGICALAND
168 %token ELLIPSIS
169 %token tACTIVATABLE
170 %token tAGGREGATABLE
171 %token tAGILE
172 %token tALLNODES tALLOCATE tANNOTATION
173 %token tAPICONTRACT
174 %token tAPPOBJECT tASYNC tASYNCUUID
175 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
176 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
177 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
178 %token tCONTEXTHANDLESERIALIZE
179 %token tCONTRACT
180 %token tCONTRACTVERSION
181 %token tCONTROL tCPPQUOTE
182 %token tCUSTOM
183 %token tDECLARE
184 %token tDECODE tDEFAULT tDEFAULTBIND
185 %token tDELEGATE
186 %token tDEFAULTCOLLELEM
187 %token tDEFAULTVALUE
188 %token tDEFAULTVTABLE
189 %token tDISABLECONSISTENCYCHECK tDISPLAYBIND
190 %token tDISPINTERFACE
191 %token tDLLNAME tDONTFREE tDOUBLE tDUAL
192 %token tENABLEALLOCATE tENCODE tENDPOINT
193 %token tENTRY tENUM tERRORSTATUST
194 %token tEVENTADD tEVENTREMOVE
195 %token tEXCLUSIVETO
196 %token tEXPLICITHANDLE tEXTERN
197 %token tFALSE
198 %token tFASTCALL tFAULTSTATUS
199 %token tFLAGS
200 %token tFLOAT tFORCEALLOCATE
201 %token tHANDLE
202 %token tHANDLET
203 %token tHELPCONTEXT tHELPFILE
204 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
205 %token tHIDDEN
206 %token tHYPER tID tIDEMPOTENT
207 %token tIGNORE tIIDIS
208 %token tIMMEDIATEBIND
209 %token tIMPLICITHANDLE
210 %token tIMPORT tIMPORTLIB
211 %token tIN tIN_LINE tINLINE
212 %token tINPUTSYNC
213 %token tINT tINT32 tINT3264 tINT64
214 %token tINTERFACE
215 %token tLCID
216 %token tLENGTHIS tLIBRARY
217 %token tLICENSED tLOCAL
218 %token tLONG
219 %token tMARSHALINGBEHAVIOR
220 %token tMAYBE tMESSAGE
221 %token tMETHODS
222 %token tMODULE
223 %token tMTA
224 %token tNAMESPACE
225 %token tNOCODE tNONBROWSABLE
226 %token tNONCREATABLE
227 %token tNONE
228 %token tNONEXTENSIBLE
229 %token tNOTIFY tNOTIFYFLAG
230 %token tNULL
231 %token tOBJECT tODL tOLEAUTOMATION
232 %token tOPTIMIZE tOPTIONAL
233 %token tOUT
234 %token tOVERLOAD
235 %token tPARTIALIGNORE tPASCAL
236 %token tPOINTERDEFAULT
237 %token tPRAGMA_WARNING
238 %token tPROGID tPROPERTIES
239 %token tPROPGET tPROPPUT tPROPPUTREF
240 %token tPROXY tPTR
241 %token tPUBLIC
242 %token tRANGE
243 %token tREADONLY tREF
244 %token tREGISTER tREPRESENTAS
245 %token tREQUESTEDIT
246 %token tREQUIRES
247 %token tRESTRICTED
248 %token tRETVAL
249 %token tRUNTIMECLASS
250 %token tSAFEARRAY
251 %token tSHORT
252 %token tSIGNED tSINGLENODE
253 %token tSIZEIS tSIZEOF
254 %token tSMALL
255 %token tSOURCE
256 %token tSTANDARD
257 %token tSTATIC
258 %token tSTDCALL
259 %token tSTRICTCONTEXTHANDLE
260 %token tSTRING tSTRUCT
261 %token tSWITCH tSWITCHIS tSWITCHTYPE
262 %token tTHREADING tTRANSMITAS
263 %token tTRUE
264 %token tTYPEDEF
265 %token tUIDEFAULT tUNION
266 %token tUNIQUE
267 %token tUNSIGNED
268 %token tUSESGETLASTERROR tUSERMARSHAL tUUID
269 %token tV1ENUM
270 %token tVARARG
271 %token tVERSION tVIPROGID
272 %token tVOID
273 %token tWCHAR tWIREMARSHAL
274 %token tAPARTMENT tNEUTRAL tSINGLE tFREE tBOTH
276 %type <attr> attribute acf_attribute
277 %type <attr_list> m_attributes attributes attrib_list
278 %type <attr_list> acf_attributes acf_attribute_list
279 %type <attr_list> dispattributes
280 %type <str_list> str_list
281 %type <expr> m_expr expr expr_const expr_int_const array m_bitfield
282 %type <expr_list> m_exprs /* exprs expr_list */ expr_list_int_const
283 %type <expr> contract_req
284 %type <expr> static_attr
285 %type <expr> activatable_attr
286 %type <type> delegatedef
287 %type <stgclass> storage_cls_spec
288 %type <type_qualifier> type_qualifier m_type_qual_list
289 %type <function_specifier> function_specifier
290 %type <declspec> decl_spec unqualified_decl_spec decl_spec_no_type m_decl_spec_no_type
291 %type <type> inherit interface interfacedef
292 %type <type> interfaceref
293 %type <type> dispinterfaceref
294 %type <type> dispinterface dispinterfacedef
295 %type <type> module moduledef
296 %type <str_list> namespacedef
297 %type <type> base_type int_std
298 %type <type> enumdef structdef uniondef typedecl
299 %type <type> type unqualified_type qualified_type
300 %type <type> type_parameter
301 %type <typeref_list> type_parameters
302 %type <type> parameterized_type
303 %type <type> parameterized_type_arg
304 %type <typeref_list> parameterized_type_args
305 %type <typeref> class_interface
306 %type <typeref_list> class_interfaces
307 %type <typeref_list> requires required_types
308 %type <var> arg ne_union_field union_field s_field case enum enum_member declaration
309 %type <var> funcdef
310 %type <var_list> m_args arg_list args dispint_meths
311 %type <var_list> fields ne_union_fields cases enums enum_list dispint_props field
312 %type <var> m_ident ident
313 %type <declarator> declarator direct_declarator init_declarator struct_declarator
314 %type <declarator> m_any_declarator any_declarator any_declarator_no_direct any_direct_declarator
315 %type <declarator> m_abstract_declarator abstract_declarator abstract_declarator_no_direct abstract_direct_declarator
316 %type <declarator_list> declarator_list struct_declarator_list
317 %type <type> coclass coclassdef
318 %type <type> runtimeclass runtimeclass_def
319 %type <type> apicontract apicontract_def
320 %type <num> contract_ver
321 %type <num> pointer_type threading_type marshaling_behavior version
322 %type <str> libraryhdr callconv cppquote importlib import
323 %type <str> typename m_typename
324 %type <uuid> uuid_string
325 %type <import> import_start
326 %type <typelib> library_start librarydef
327 %type <statement> statement typedef pragma_warning
328 %type <stmt_list> gbl_statements imp_statements int_statements
329 %type <stmt_list> decl_block decl_statements
330 %type <stmt_list> imp_decl_block imp_decl_statements
331 %type <warning_list> warnings
332 %type <num> allocate_option_list allocate_option
333 %type <namespace> namespace_pfx
335 %left ','
336 %right '?' ':'
337 %left LOGICALOR
338 %left LOGICALAND
339 %left '|'
340 %left '^'
341 %left '&'
342 %left EQUALITY INEQUALITY
343 %left '<' '>' LESSEQUAL GREATEREQUAL
344 %left SHL SHR
345 %left '-' '+'
346 %left '*' '/' '%'
347 %right '!' '~' CAST PPTR POS NEG ADDRESSOF tSIZEOF
348 %left '.' MEMBERPTR '[' ']'
350 %define parse.error verbose
354 input: gbl_statements m_acf { $1 = append_parameterized_type_stmts($1);
355 check_statements($1, FALSE);
356 check_all_user_types($1);
357 write_header($1);
358 write_id_data($1);
359 write_proxies($1);
360 write_client($1);
361 write_server($1);
362 write_regscript($1);
363 write_typelib_regscript($1);
364 write_dlldata($1);
365 write_local_stubs($1);
369 m_acf: /* empty */ | aACF acf_statements
371 decl_statements: { $$ = NULL; }
372 | decl_statements tINTERFACE qualified_type '<' parameterized_type_args '>' ';'
373 { parameterized_type_stmts = append_statement(parameterized_type_stmts, make_statement_parameterized_type($3, $5));
374 $$ = append_statement($1, make_statement_reference(type_parameterized_type_specialize_declare($3, $5)));
378 decl_block: tDECLARE '{' decl_statements '}' { $$ = $3; }
380 imp_decl_statements: { $$ = NULL; }
381 | imp_decl_statements tINTERFACE qualified_type '<' parameterized_type_args '>' ';'
382 { $$ = append_statement($1, make_statement_reference(type_parameterized_type_specialize_declare($3, $5))); }
385 imp_decl_block: tDECLARE '{' imp_decl_statements '}' { $$ = $3; }
387 gbl_statements: { $$ = NULL; }
388 | gbl_statements namespacedef '{' { push_namespaces($2); } gbl_statements '}'
389 { pop_namespaces($2); $$ = append_statements($1, $5); }
390 | gbl_statements interface ';' { $$ = append_statement($1, make_statement_reference($2)); }
391 | gbl_statements dispinterface ';' { $$ = append_statement($1, make_statement_reference($2)); }
392 | gbl_statements interfacedef { $$ = append_statement($1, make_statement_type_decl($2)); }
393 | gbl_statements delegatedef { $$ = append_statement($1, make_statement_type_decl($2)); }
394 | gbl_statements coclass ';' { $$ = $1;
395 reg_type($2, $2->name, current_namespace, 0);
397 | gbl_statements coclassdef { $$ = append_statement($1, make_statement_type_decl($2));
398 reg_type($2, $2->name, current_namespace, 0);
400 | gbl_statements apicontract ';' { $$ = $1; reg_type($2, $2->name, current_namespace, 0); }
401 | gbl_statements apicontract_def { $$ = append_statement($1, make_statement_type_decl($2));
402 reg_type($2, $2->name, current_namespace, 0); }
403 | gbl_statements runtimeclass ';' { $$ = $1; reg_type($2, $2->name, current_namespace, 0); }
404 | gbl_statements runtimeclass_def { $$ = append_statement($1, make_statement_type_decl($2));
405 reg_type($2, $2->name, current_namespace, 0); }
406 | gbl_statements moduledef { $$ = append_statement($1, make_statement_module($2)); }
407 | gbl_statements librarydef { $$ = append_statement($1, make_statement_library($2)); }
408 | gbl_statements statement { $$ = append_statement($1, $2); }
409 | gbl_statements decl_block { $$ = append_statements($1, $2); }
412 imp_statements: { $$ = NULL; }
413 | imp_statements interface ';' { $$ = append_statement($1, make_statement_reference($2)); }
414 | imp_statements dispinterface ';' { $$ = append_statement($1, make_statement_reference($2)); }
415 | imp_statements namespacedef '{' { push_namespaces($2); } imp_statements '}'
416 { pop_namespaces($2); $$ = append_statements($1, $5); }
417 | imp_statements interfacedef { $$ = append_statement($1, make_statement_type_decl($2)); }
418 | imp_statements delegatedef { $$ = append_statement($1, make_statement_type_decl($2)); }
419 | imp_statements coclass ';' { $$ = $1; reg_type($2, $2->name, current_namespace, 0); }
420 | imp_statements coclassdef { $$ = append_statement($1, make_statement_type_decl($2));
421 reg_type($2, $2->name, current_namespace, 0);
423 | imp_statements apicontract ';' { $$ = $1; reg_type($2, $2->name, current_namespace, 0); }
424 | imp_statements apicontract_def { $$ = append_statement($1, make_statement_type_decl($2));
425 reg_type($2, $2->name, current_namespace, 0); }
426 | imp_statements runtimeclass ';' { $$ = $1; reg_type($2, $2->name, current_namespace, 0); }
427 | imp_statements runtimeclass_def { $$ = append_statement($1, make_statement_type_decl($2));
428 reg_type($2, $2->name, current_namespace, 0); }
429 | imp_statements moduledef { $$ = append_statement($1, make_statement_module($2)); }
430 | imp_statements statement { $$ = append_statement($1, $2); }
431 | imp_statements importlib { $$ = append_statement($1, make_statement_importlib($2)); }
432 | imp_statements librarydef { $$ = append_statement($1, make_statement_library($2)); }
433 | imp_statements imp_decl_block { $$ = append_statements($1, $2); }
436 int_statements: { $$ = NULL; }
437 | int_statements statement { $$ = append_statement($1, $2); }
440 semicolon_opt:
441 | ';'
444 statement:
445 cppquote { $$ = make_statement_cppquote($1); }
446 | typedecl ';' { $$ = make_statement_type_decl($1); }
447 | declaration ';' { $$ = make_statement_declaration($1); }
448 | import { $$ = make_statement_import($1); }
449 | typedef ';' { $$ = $1; }
450 | aPRAGMA { $$ = make_statement_pragma($1); }
451 | pragma_warning { $$ = NULL; }
454 pragma_warning: tPRAGMA_WARNING '(' aIDENTIFIER ':' warnings ')'
456 int result;
457 $$ = NULL;
458 result = do_warning($3, $5);
459 if(!result)
460 error_loc("expected \"disable\", \"enable\" or \"default\"\n");
462 | tPRAGMA_WARNING '(' tDEFAULT ':' warnings ')'
464 $$ = NULL;
465 do_warning("default", $5);
469 warnings:
470 aNUM { $$ = append_warning(NULL, $1); }
471 | warnings aNUM { $$ = append_warning($1, $2); }
474 typedecl:
475 enumdef
476 | tENUM aIDENTIFIER { $$ = type_new_enum($2, current_namespace, FALSE, NULL); }
477 | structdef
478 | tSTRUCT aIDENTIFIER { $$ = type_new_struct($2, current_namespace, FALSE, NULL); }
479 | uniondef
480 | tUNION aIDENTIFIER { $$ = type_new_nonencapsulated_union($2, FALSE, NULL); }
481 | attributes enumdef { $$ = $2; $$->attrs = check_enum_attrs($1); }
482 | attributes structdef { $$ = $2; $$->attrs = check_struct_attrs($1); }
483 | attributes uniondef { $$ = $2; $$->attrs = check_union_attrs($1); }
486 cppquote: tCPPQUOTE '(' aSTRING ')' { $$ = $3; }
488 import_start: tIMPORT aSTRING ';' { $$ = xmalloc(sizeof(struct _import_t));
489 $$->name = $2;
490 $$->import_performed = do_import($2);
491 if (!$$->import_performed) yychar = aEOF;
495 import: import_start imp_statements aEOF { $$ = $1->name;
496 if ($1->import_performed) pop_import();
497 free($1);
501 importlib: tIMPORTLIB '(' aSTRING ')'
502 semicolon_opt { $$ = $3; if(!parse_only) add_importlib($3, current_typelib); }
505 libraryhdr: tLIBRARY typename { $$ = $2; }
507 library_start: attributes libraryhdr '{' { $$ = make_library($2, check_library_attrs($2, $1));
508 if (!parse_only && do_typelib) current_typelib = $$;
511 librarydef: library_start imp_statements '}'
512 semicolon_opt { $$ = $1; $$->stmts = $2; }
515 m_args: { $$ = NULL; }
516 | args
519 arg_list: arg { check_arg_attrs($1); $$ = append_var( NULL, $1 ); }
520 | arg_list ',' arg { check_arg_attrs($3); $$ = append_var( $1, $3 ); }
523 args: arg_list
524 | arg_list ',' ELLIPSIS { $$ = append_var( $1, make_var(xstrdup("...")) ); }
527 /* split into two rules to get bison to resolve a tVOID conflict */
528 arg: attributes decl_spec m_any_declarator { if ($2->stgclass != STG_NONE && $2->stgclass != STG_REGISTER)
529 error_loc("invalid storage class for function parameter\n");
530 $$ = declare_var($1, $2, $3, TRUE);
531 free($2); free($3);
533 | decl_spec m_any_declarator { if ($1->stgclass != STG_NONE && $1->stgclass != STG_REGISTER)
534 error_loc("invalid storage class for function parameter\n");
535 $$ = declare_var(NULL, $1, $2, TRUE);
536 free($1); free($2);
540 array: '[' expr ']' { $$ = $2;
541 if (!$$->is_const || $$->cval <= 0)
542 error_loc("array dimension is not a positive integer constant\n");
544 | '[' '*' ']' { $$ = make_expr(EXPR_VOID); }
545 | '[' ']' { $$ = make_expr(EXPR_VOID); }
548 m_attributes: { $$ = NULL; }
549 | attributes
552 attributes:
553 '[' attrib_list ']' { $$ = $2; }
556 attrib_list: attribute { $$ = append_attr( NULL, $1 ); }
557 | attrib_list ',' attribute { $$ = append_attr( $1, $3 ); }
558 | attrib_list ']' '[' attribute { $$ = append_attr( $1, $4 ); }
561 str_list: aSTRING { $$ = append_str( NULL, $1 ); }
562 | str_list ',' aSTRING { $$ = append_str( $1, $3 ); }
565 marshaling_behavior:
566 tAGILE { $$ = MARSHALING_AGILE; }
567 | tNONE { $$ = MARSHALING_NONE; }
568 | tSTANDARD { $$ = MARSHALING_STANDARD; }
571 contract_ver:
572 aNUM { $$ = MAKEVERSION(0, $1); }
573 | aNUM '.' aNUM { $$ = MAKEVERSION($3, $1); }
576 contract_req: decl_spec ',' contract_ver { if ($1->type->type_type != TYPE_APICONTRACT)
577 error_loc("type %s is not an apicontract\n", $1->type->name);
578 $$ = make_exprl(EXPR_NUM, $3);
579 $$ = make_exprt(EXPR_GTREQL, declare_var(NULL, $1, make_declarator(NULL), 0), $$);
582 static_attr: decl_spec ',' contract_req { if ($1->type->type_type != TYPE_INTERFACE)
583 error_loc("type %s is not an interface\n", $1->type->name);
584 $$ = make_exprt(EXPR_MEMBER, declare_var(NULL, $1, make_declarator(NULL), 0), $3);
587 activatable_attr:
588 decl_spec ',' contract_req { if ($1->type->type_type != TYPE_INTERFACE)
589 error_loc("type %s is not an interface\n", $1->type->name);
590 $$ = make_exprt(EXPR_MEMBER, declare_var(NULL, $1, make_declarator(NULL), 0), $3);
592 | contract_req { $$ = $1; } /* activatable on the default activation factory */
594 attribute: { $$ = NULL; }
595 | tACTIVATABLE '(' activatable_attr ')' { $$ = make_attrp(ATTR_ACTIVATABLE, $3); }
596 | tAGGREGATABLE { $$ = make_attr(ATTR_AGGREGATABLE); }
597 | tANNOTATION '(' aSTRING ')' { $$ = make_attrp(ATTR_ANNOTATION, $3); }
598 | tAPPOBJECT { $$ = make_attr(ATTR_APPOBJECT); }
599 | tASYNC { $$ = make_attr(ATTR_ASYNC); }
600 | tAUTOHANDLE { $$ = make_attr(ATTR_AUTO_HANDLE); }
601 | tBINDABLE { $$ = make_attr(ATTR_BINDABLE); }
602 | tBROADCAST { $$ = make_attr(ATTR_BROADCAST); }
603 | tCALLAS '(' ident ')' { $$ = make_attrp(ATTR_CALLAS, $3); }
604 | tCASE '(' expr_list_int_const ')' { $$ = make_attrp(ATTR_CASE, $3); }
605 | tCODE { $$ = make_attr(ATTR_CODE); }
606 | tCOMMSTATUS { $$ = make_attr(ATTR_COMMSTATUS); }
607 | tCONTEXTHANDLE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); }
608 | tCONTEXTHANDLENOSERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
609 | tCONTEXTHANDLESERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
610 | tCONTRACT '(' contract_req ')' { $$ = make_attrp(ATTR_CONTRACT, $3); }
611 | tCONTRACTVERSION '(' contract_ver ')' { $$ = make_attrv(ATTR_CONTRACTVERSION, $3); }
612 | tCONTROL { $$ = make_attr(ATTR_CONTROL); }
613 | tCUSTOM '(' uuid_string ',' expr_const ')' { $$ = make_custom_attr($3, $5); }
614 | tDECODE { $$ = make_attr(ATTR_DECODE); }
615 | tDEFAULT { $$ = make_attr(ATTR_DEFAULT); }
616 | tDEFAULTBIND { $$ = make_attr(ATTR_DEFAULTBIND); }
617 | tDEFAULTCOLLELEM { $$ = make_attr(ATTR_DEFAULTCOLLELEM); }
618 | tDEFAULTVALUE '(' expr_const ')' { $$ = make_attrp(ATTR_DEFAULTVALUE, $3); }
619 | tDEFAULTVTABLE { $$ = make_attr(ATTR_DEFAULTVTABLE); }
620 | tDISABLECONSISTENCYCHECK { $$ = make_attr(ATTR_DISABLECONSISTENCYCHECK); }
621 | tDISPLAYBIND { $$ = make_attr(ATTR_DISPLAYBIND); }
622 | tDLLNAME '(' aSTRING ')' { $$ = make_attrp(ATTR_DLLNAME, $3); }
623 | tDUAL { $$ = make_attr(ATTR_DUAL); }
624 | tENABLEALLOCATE { $$ = make_attr(ATTR_ENABLEALLOCATE); }
625 | tENCODE { $$ = make_attr(ATTR_ENCODE); }
626 | tENDPOINT '(' str_list ')' { $$ = make_attrp(ATTR_ENDPOINT, $3); }
627 | tENTRY '(' expr_const ')' { $$ = make_attrp(ATTR_ENTRY, $3); }
628 | tEVENTADD { $$ = make_attr(ATTR_EVENTADD); }
629 | tEVENTREMOVE { $$ = make_attr(ATTR_EVENTREMOVE); }
630 | tEXCLUSIVETO '(' decl_spec ')' { if ($3->type->type_type != TYPE_RUNTIMECLASS)
631 error_loc("type %s is not a runtimeclass\n", $3->type->name);
632 $$ = make_attrp(ATTR_EXCLUSIVETO, $3->type); }
633 | tEXPLICITHANDLE { $$ = make_attr(ATTR_EXPLICIT_HANDLE); }
634 | tFAULTSTATUS { $$ = make_attr(ATTR_FAULTSTATUS); }
635 | tFLAGS { $$ = make_attr(ATTR_FLAGS); }
636 | tFORCEALLOCATE { $$ = make_attr(ATTR_FORCEALLOCATE); }
637 | tHANDLE { $$ = make_attr(ATTR_HANDLE); }
638 | tHELPCONTEXT '(' expr_int_const ')' { $$ = make_attrp(ATTR_HELPCONTEXT, $3); }
639 | tHELPFILE '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPFILE, $3); }
640 | tHELPSTRING '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRING, $3); }
641 | tHELPSTRINGCONTEXT '(' expr_int_const ')' { $$ = make_attrp(ATTR_HELPSTRINGCONTEXT, $3); }
642 | tHELPSTRINGDLL '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRINGDLL, $3); }
643 | tHIDDEN { $$ = make_attr(ATTR_HIDDEN); }
644 | tID '(' expr_int_const ')' { $$ = make_attrp(ATTR_ID, $3); }
645 | tIDEMPOTENT { $$ = make_attr(ATTR_IDEMPOTENT); }
646 | tIGNORE { $$ = make_attr(ATTR_IGNORE); }
647 | tIIDIS '(' expr ')' { $$ = make_attrp(ATTR_IIDIS, $3); }
648 | tIMMEDIATEBIND { $$ = make_attr(ATTR_IMMEDIATEBIND); }
649 | tIMPLICITHANDLE '(' arg ')' { $$ = make_attrp(ATTR_IMPLICIT_HANDLE, $3); }
650 | tIN { $$ = make_attr(ATTR_IN); }
651 | tINPUTSYNC { $$ = make_attr(ATTR_INPUTSYNC); }
652 | tLENGTHIS '(' m_exprs ')' { $$ = make_attrp(ATTR_LENGTHIS, $3); }
653 | tLCID '(' expr_int_const ')' { $$ = make_attrp(ATTR_LIBLCID, $3); }
654 | tLCID { $$ = make_attr(ATTR_PARAMLCID); }
655 | tLICENSED { $$ = make_attr(ATTR_LICENSED); }
656 | tLOCAL { $$ = make_attr(ATTR_LOCAL); }
657 | tMARSHALINGBEHAVIOR '(' marshaling_behavior ')'
658 { $$ = make_attrv(ATTR_MARSHALING_BEHAVIOR, $3); }
659 | tMAYBE { $$ = make_attr(ATTR_MAYBE); }
660 | tMESSAGE { $$ = make_attr(ATTR_MESSAGE); }
661 | tNOCODE { $$ = make_attr(ATTR_NOCODE); }
662 | tNONBROWSABLE { $$ = make_attr(ATTR_NONBROWSABLE); }
663 | tNONCREATABLE { $$ = make_attr(ATTR_NONCREATABLE); }
664 | tNONEXTENSIBLE { $$ = make_attr(ATTR_NONEXTENSIBLE); }
665 | tNOTIFY { $$ = make_attr(ATTR_NOTIFY); }
666 | tNOTIFYFLAG { $$ = make_attr(ATTR_NOTIFYFLAG); }
667 | tOBJECT { $$ = make_attr(ATTR_OBJECT); }
668 | tODL { $$ = make_attr(ATTR_ODL); }
669 | tOLEAUTOMATION { $$ = make_attr(ATTR_OLEAUTOMATION); }
670 | tOPTIMIZE '(' aSTRING ')' { $$ = make_attrp(ATTR_OPTIMIZE, $3); }
671 | tOPTIONAL { $$ = make_attr(ATTR_OPTIONAL); }
672 | tOUT { $$ = make_attr(ATTR_OUT); }
673 | tOVERLOAD '(' aSTRING ')' { $$ = make_attrp(ATTR_OVERLOAD, $3); }
674 | tPARTIALIGNORE { $$ = make_attr(ATTR_PARTIALIGNORE); }
675 | tPOINTERDEFAULT '(' pointer_type ')' { $$ = make_attrv(ATTR_POINTERDEFAULT, $3); }
676 | tPROGID '(' aSTRING ')' { $$ = make_attrp(ATTR_PROGID, $3); }
677 | tPROPGET { $$ = make_attr(ATTR_PROPGET); }
678 | tPROPPUT { $$ = make_attr(ATTR_PROPPUT); }
679 | tPROPPUTREF { $$ = make_attr(ATTR_PROPPUTREF); }
680 | tPROXY { $$ = make_attr(ATTR_PROXY); }
681 | tPUBLIC { $$ = make_attr(ATTR_PUBLIC); }
682 | tRANGE '(' expr_int_const ',' expr_int_const ')'
683 { expr_list_t *list = append_expr( NULL, $3 );
684 list = append_expr( list, $5 );
685 $$ = make_attrp(ATTR_RANGE, list); }
686 | tREADONLY { $$ = make_attr(ATTR_READONLY); }
687 | tREPRESENTAS '(' type ')' { $$ = make_attrp(ATTR_REPRESENTAS, $3); }
688 | tREQUESTEDIT { $$ = make_attr(ATTR_REQUESTEDIT); }
689 | tRESTRICTED { $$ = make_attr(ATTR_RESTRICTED); }
690 | tRETVAL { $$ = make_attr(ATTR_RETVAL); }
691 | tSIZEIS '(' m_exprs ')' { $$ = make_attrp(ATTR_SIZEIS, $3); }
692 | tSOURCE { $$ = make_attr(ATTR_SOURCE); }
693 | tSTATIC '(' static_attr ')' { $$ = make_attrp(ATTR_STATIC, $3); }
694 | tSTRICTCONTEXTHANDLE { $$ = make_attr(ATTR_STRICTCONTEXTHANDLE); }
695 | tSTRING { $$ = make_attr(ATTR_STRING); }
696 | tSWITCHIS '(' expr ')' { $$ = make_attrp(ATTR_SWITCHIS, $3); }
697 | tSWITCHTYPE '(' type ')' { $$ = make_attrp(ATTR_SWITCHTYPE, $3); }
698 | tTRANSMITAS '(' type ')' { $$ = make_attrp(ATTR_TRANSMITAS, $3); }
699 | tTHREADING '(' threading_type ')' { $$ = make_attrv(ATTR_THREADING, $3); }
700 | tUIDEFAULT { $$ = make_attr(ATTR_UIDEFAULT); }
701 | tUSESGETLASTERROR { $$ = make_attr(ATTR_USESGETLASTERROR); }
702 | tUSERMARSHAL '(' type ')' { $$ = make_attrp(ATTR_USERMARSHAL, $3); }
703 | tUUID '(' uuid_string ')' { $$ = make_attrp(ATTR_UUID, $3); }
704 | tASYNCUUID '(' uuid_string ')' { $$ = make_attrp(ATTR_ASYNCUUID, $3); }
705 | tV1ENUM { $$ = make_attr(ATTR_V1ENUM); }
706 | tVARARG { $$ = make_attr(ATTR_VARARG); }
707 | tVERSION '(' version ')' { $$ = make_attrv(ATTR_VERSION, $3); }
708 | tVIPROGID '(' aSTRING ')' { $$ = make_attrp(ATTR_VIPROGID, $3); }
709 | tWIREMARSHAL '(' type ')' { $$ = make_attrp(ATTR_WIREMARSHAL, $3); }
710 | pointer_type { $$ = make_attrv(ATTR_POINTERTYPE, $1); }
713 uuid_string:
714 aUUID
715 | aSTRING { if (!is_valid_uuid($1))
716 error_loc("invalid UUID: %s\n", $1);
717 $$ = parse_uuid($1); }
720 callconv: tCDECL { $$ = xstrdup("__cdecl"); }
721 | tFASTCALL { $$ = xstrdup("__fastcall"); }
722 | tPASCAL { $$ = xstrdup("__pascal"); }
723 | tSTDCALL { $$ = xstrdup("__stdcall"); }
726 cases: { $$ = NULL; }
727 | cases case { $$ = append_var( $1, $2 ); }
730 case: tCASE expr_int_const ':' union_field { attr_t *a = make_attrp(ATTR_CASE, append_expr( NULL, $2 ));
731 $$ = $4; if (!$$) $$ = make_var(NULL);
732 $$->attrs = append_attr( $$->attrs, a );
734 | tDEFAULT ':' union_field { attr_t *a = make_attr(ATTR_DEFAULT);
735 $$ = $3; if (!$$) $$ = make_var(NULL);
736 $$->attrs = append_attr( $$->attrs, a );
740 enums: { $$ = NULL; }
741 | enum_list ',' { $$ = $1; }
742 | enum_list
745 enum_list: enum { if (!$1->eval)
746 $1->eval = make_exprl(EXPR_NUM, 0 /* default for first enum entry */);
747 $$ = append_var( NULL, $1 );
749 | enum_list ',' enum { if (!$3->eval)
751 var_t *last = LIST_ENTRY( list_tail($$), var_t, entry );
752 enum expr_type type = EXPR_NUM;
753 if (last->eval->type == EXPR_HEXNUM) type = EXPR_HEXNUM;
754 if (last->eval->cval + 1 < 0) type = EXPR_HEXNUM;
755 $3->eval = make_exprl(type, last->eval->cval + 1);
757 $$ = append_var( $1, $3 );
761 enum_member: m_attributes ident { $$ = $2;
762 $$->attrs = check_enum_member_attrs($1);
766 enum: enum_member '=' expr_int_const { $$ = reg_const($1);
767 $$->eval = $3;
768 $$->declspec.type = type_new_int(TYPE_BASIC_INT, 0);
770 | enum_member { $$ = reg_const($1);
771 $$->declspec.type = type_new_int(TYPE_BASIC_INT, 0);
775 enumdef: tENUM m_typename '{' enums '}' { $$ = type_new_enum($2, current_namespace, TRUE, $4); }
778 m_exprs: m_expr { $$ = append_expr( NULL, $1 ); }
779 | m_exprs ',' m_expr { $$ = append_expr( $1, $3 ); }
782 m_expr: { $$ = make_expr(EXPR_VOID); }
783 | expr
786 expr: aNUM { $$ = make_exprl(EXPR_NUM, $1); }
787 | aHEXNUM { $$ = make_exprl(EXPR_HEXNUM, $1); }
788 | aDOUBLE { $$ = make_exprd(EXPR_DOUBLE, $1); }
789 | tFALSE { $$ = make_exprl(EXPR_TRUEFALSE, 0); }
790 | tNULL { $$ = make_exprl(EXPR_NUM, 0); }
791 | tTRUE { $$ = make_exprl(EXPR_TRUEFALSE, 1); }
792 | aSTRING { $$ = make_exprs(EXPR_STRLIT, $1); }
793 | aWSTRING { $$ = make_exprs(EXPR_WSTRLIT, $1); }
794 | aSQSTRING { $$ = make_exprs(EXPR_CHARCONST, $1); }
795 | aIDENTIFIER { $$ = make_exprs(EXPR_IDENTIFIER, $1); }
796 | expr '?' expr ':' expr { $$ = make_expr3(EXPR_COND, $1, $3, $5); }
797 | expr LOGICALOR expr { $$ = make_expr2(EXPR_LOGOR, $1, $3); }
798 | expr LOGICALAND expr { $$ = make_expr2(EXPR_LOGAND, $1, $3); }
799 | expr '|' expr { $$ = make_expr2(EXPR_OR , $1, $3); }
800 | expr '^' expr { $$ = make_expr2(EXPR_XOR, $1, $3); }
801 | expr '&' expr { $$ = make_expr2(EXPR_AND, $1, $3); }
802 | expr EQUALITY expr { $$ = make_expr2(EXPR_EQUALITY, $1, $3); }
803 | expr INEQUALITY expr { $$ = make_expr2(EXPR_INEQUALITY, $1, $3); }
804 | expr '>' expr { $$ = make_expr2(EXPR_GTR, $1, $3); }
805 | expr '<' expr { $$ = make_expr2(EXPR_LESS, $1, $3); }
806 | expr GREATEREQUAL expr { $$ = make_expr2(EXPR_GTREQL, $1, $3); }
807 | expr LESSEQUAL expr { $$ = make_expr2(EXPR_LESSEQL, $1, $3); }
808 | expr SHL expr { $$ = make_expr2(EXPR_SHL, $1, $3); }
809 | expr SHR expr { $$ = make_expr2(EXPR_SHR, $1, $3); }
810 | expr '+' expr { $$ = make_expr2(EXPR_ADD, $1, $3); }
811 | expr '-' expr { $$ = make_expr2(EXPR_SUB, $1, $3); }
812 | expr '%' expr { $$ = make_expr2(EXPR_MOD, $1, $3); }
813 | expr '*' expr { $$ = make_expr2(EXPR_MUL, $1, $3); }
814 | expr '/' expr { $$ = make_expr2(EXPR_DIV, $1, $3); }
815 | '!' expr { $$ = make_expr1(EXPR_LOGNOT, $2); }
816 | '~' expr { $$ = make_expr1(EXPR_NOT, $2); }
817 | '+' expr %prec POS { $$ = make_expr1(EXPR_POS, $2); }
818 | '-' expr %prec NEG { $$ = make_expr1(EXPR_NEG, $2); }
819 | '&' expr %prec ADDRESSOF { $$ = make_expr1(EXPR_ADDRESSOF, $2); }
820 | '*' expr %prec PPTR { $$ = make_expr1(EXPR_PPTR, $2); }
821 | expr MEMBERPTR aIDENTIFIER { $$ = make_expr2(EXPR_MEMBER, make_expr1(EXPR_PPTR, $1), make_exprs(EXPR_IDENTIFIER, $3)); }
822 | expr '.' aIDENTIFIER { $$ = make_expr2(EXPR_MEMBER, $1, make_exprs(EXPR_IDENTIFIER, $3)); }
823 | '(' unqualified_decl_spec m_abstract_declarator ')' expr %prec CAST
824 { $$ = make_exprt(EXPR_CAST, declare_var(NULL, $2, $3, 0), $5); free($2); free($3); }
825 | tSIZEOF '(' unqualified_decl_spec m_abstract_declarator ')'
826 { $$ = make_exprt(EXPR_SIZEOF, declare_var(NULL, $3, $4, 0), NULL); free($3); free($4); }
827 | expr '[' expr ']' { $$ = make_expr2(EXPR_ARRAY, $1, $3); }
828 | '(' expr ')' { $$ = $2; }
831 expr_list_int_const: expr_int_const { $$ = append_expr( NULL, $1 ); }
832 | expr_list_int_const ',' expr_int_const { $$ = append_expr( $1, $3 ); }
835 expr_int_const: expr { $$ = $1;
836 if (!$$->is_const)
837 error_loc("expression is not an integer constant\n");
841 expr_const: expr { $$ = $1;
842 if (!$$->is_const && $$->type != EXPR_STRLIT && $$->type != EXPR_WSTRLIT)
843 error_loc("expression is not constant\n");
847 fields: { $$ = NULL; }
848 | fields field { $$ = append_var_list($1, $2); }
851 field: m_attributes decl_spec struct_declarator_list ';'
852 { const char *first = LIST_ENTRY(list_head($3), declarator_t, entry)->var->name;
853 check_field_attrs(first, $1);
854 $$ = set_var_types($1, $2, $3);
856 | m_attributes uniondef ';' { var_t *v = make_var(NULL);
857 v->declspec.type = $2; v->attrs = $1;
858 $$ = append_var(NULL, v);
862 ne_union_field:
863 s_field ';' { $$ = $1; }
864 | attributes ';' { $$ = make_var(NULL); $$->attrs = $1; }
867 ne_union_fields: { $$ = NULL; }
868 | ne_union_fields ne_union_field { $$ = append_var( $1, $2 ); }
871 union_field:
872 s_field ';' { $$ = $1; }
873 | ';' { $$ = NULL; }
876 s_field: m_attributes decl_spec declarator { $$ = declare_var(check_field_attrs($3->var->name, $1),
877 $2, $3, FALSE);
878 free($3);
880 | m_attributes structdef { var_t *v = make_var(NULL);
881 v->declspec.type = $2; v->attrs = $1;
882 $$ = v;
886 funcdef: declaration { $$ = $1;
887 if (type_get_type($$->declspec.type) != TYPE_FUNCTION)
888 error_loc("only methods may be declared inside the methods section of a dispinterface\n");
889 check_function_attrs($$->name, $$->attrs);
893 declaration:
894 attributes decl_spec init_declarator
895 { $$ = declare_var($1, $2, $3, FALSE);
896 free($3);
898 | decl_spec init_declarator { $$ = declare_var(NULL, $1, $2, FALSE);
899 free($2);
903 m_ident: { $$ = NULL; }
904 | ident
907 m_typename: { $$ = NULL; }
908 | typename
911 typename: aIDENTIFIER
912 | aKNOWNTYPE
915 ident: typename { $$ = make_var($1); }
918 base_type: tBYTE { $$ = find_type_or_error(NULL, $<str>1); }
919 | tWCHAR { $$ = find_type_or_error(NULL, $<str>1); }
920 | int_std
921 | tSIGNED int_std { $$ = type_new_int(type_basic_get_type($2), -1); }
922 | tUNSIGNED int_std { $$ = type_new_int(type_basic_get_type($2), 1); }
923 | tUNSIGNED { $$ = type_new_int(TYPE_BASIC_INT, 1); }
924 | tFLOAT { $$ = find_type_or_error(NULL, $<str>1); }
925 | tDOUBLE { $$ = find_type_or_error(NULL, $<str>1); }
926 | tBOOLEAN { $$ = find_type_or_error(NULL, $<str>1); }
927 | tERRORSTATUST { $$ = find_type_or_error(NULL, $<str>1); }
928 | tHANDLET { $$ = find_type_or_error(NULL, $<str>1); }
931 m_int:
932 | tINT
935 int_std: tINT { $$ = type_new_int(TYPE_BASIC_INT, 0); }
936 | tSHORT m_int { $$ = type_new_int(TYPE_BASIC_INT16, 0); }
937 | tSMALL { $$ = type_new_int(TYPE_BASIC_INT8, 0); }
938 | tLONG m_int { $$ = type_new_int(TYPE_BASIC_LONG, 0); }
939 | tHYPER m_int { $$ = type_new_int(TYPE_BASIC_HYPER, 0); }
940 | tINT64 { $$ = type_new_int(TYPE_BASIC_INT64, 0); }
941 | tCHAR { $$ = type_new_int(TYPE_BASIC_CHAR, 0); }
942 | tINT32 { $$ = type_new_int(TYPE_BASIC_INT32, 0); }
943 | tINT3264 { $$ = type_new_int(TYPE_BASIC_INT3264, 0); }
946 namespace_pfx:
947 aIDENTIFIER '.' { $$ = find_namespace_or_error(&global_namespace, $1); }
948 | namespace_pfx aIDENTIFIER '.' { $$ = find_namespace_or_error($1, $2); }
951 qualified_type:
952 typename { $$ = find_type_or_error(current_namespace, $1); }
953 | namespace_pfx typename { $$ = find_type_or_error($1, $2); }
956 parameterized_type: qualified_type '<' parameterized_type_args '>'
957 { $$ = find_parameterized_type($1, $3); }
960 parameterized_type_arg:
961 base_type { $$ = $1; }
962 | qualified_type { $$ = $1; }
963 | qualified_type '*' { $$ = type_new_pointer($1); }
964 | parameterized_type { $$ = $1; }
965 | parameterized_type '*' { $$ = type_new_pointer($1); }
968 parameterized_type_args:
969 parameterized_type_arg { $$ = append_typeref(NULL, make_typeref($1)); }
970 | parameterized_type_args ',' parameterized_type_arg
971 { $$ = append_typeref($1, make_typeref($3)); }
974 coclass: tCOCLASS typename { $$ = type_coclass_declare($2); }
977 coclassdef: attributes coclass '{' class_interfaces '}' semicolon_opt
978 { $$ = type_coclass_define($2, $1, $4); }
981 runtimeclass: tRUNTIMECLASS typename { $$ = type_runtimeclass_declare($2, current_namespace); }
984 runtimeclass_def: attributes runtimeclass '{' class_interfaces '}' semicolon_opt
985 { $$ = type_runtimeclass_define($2, $1, $4); }
988 apicontract: tAPICONTRACT typename { $$ = type_apicontract_declare($2, current_namespace); }
991 apicontract_def: attributes apicontract '{' '}' semicolon_opt
992 { $$ = type_apicontract_define($2, $1); }
995 namespacedef: tNAMESPACE aIDENTIFIER { $$ = append_str( NULL, $2 ); }
996 | namespacedef '.' aIDENTIFIER { $$ = append_str( $1, $3 ); }
999 class_interfaces: { $$ = NULL; }
1000 | class_interfaces class_interface { $$ = append_typeref( $1, $2 ); }
1003 class_interface:
1004 m_attributes interfaceref ';' { $$ = make_typeref($2); $$->attrs = $1; }
1005 | m_attributes dispinterfaceref ';' { $$ = make_typeref($2); $$->attrs = $1; }
1008 dispinterface: tDISPINTERFACE typename { $$ = type_dispinterface_declare($2); }
1011 dispattributes: attributes { $$ = append_attr($1, make_attr(ATTR_DISPINTERFACE)); }
1014 dispint_props: tPROPERTIES ':' { $$ = NULL; }
1015 | dispint_props s_field ';' { $$ = append_var( $1, $2 ); }
1018 dispint_meths: tMETHODS ':' { $$ = NULL; }
1019 | dispint_meths funcdef ';' { $$ = append_var( $1, $2 ); }
1022 dispinterfacedef:
1023 dispattributes dispinterface '{' dispint_props dispint_meths '}'
1024 { $$ = type_dispinterface_define($2, $1, $4, $5); }
1025 | dispattributes dispinterface '{' interface ';' '}'
1026 { $$ = type_dispinterface_define_from_iface($2, $1, $4); }
1029 inherit: { $$ = NULL; }
1030 | ':' qualified_type { $$ = $2; }
1031 | ':' parameterized_type { $$ = $2; }
1034 type_parameter: typename { $$ = get_type(TYPE_PARAMETER, $1, parameters_namespace, 0); }
1037 type_parameters:
1038 type_parameter { $$ = append_typeref(NULL, make_typeref($1)); }
1039 | type_parameters ',' type_parameter { $$ = append_typeref($1, make_typeref($3)); }
1042 interface:
1043 tINTERFACE typename { $$ = type_interface_declare($2, current_namespace); }
1044 | tINTERFACE typename '<' { push_parameters_namespace($2); } type_parameters { pop_parameters_namespace($2); } '>'
1045 { $$ = type_parameterized_interface_declare($2, current_namespace, $5); }
1048 delegatedef: m_attributes tDELEGATE type ident '(' m_args ')' semicolon_opt
1049 { $$ = type_delegate_declare($4->name, current_namespace);
1050 $$ = type_delegate_define($$, $1, append_statement(NULL, make_statement_delegate($3, $6)));
1052 | m_attributes tDELEGATE type ident
1053 '<' { push_parameters_namespace($4->name); } type_parameters '>'
1054 '(' m_args ')' { pop_parameters_namespace($4->name); } semicolon_opt
1055 { $$ = type_parameterized_delegate_declare($4->name, current_namespace, $7);
1056 $$ = type_parameterized_delegate_define($$, $1, append_statement(NULL, make_statement_delegate($3, $10)));
1060 required_types:
1061 qualified_type { $$ = append_typeref(NULL, make_typeref($1)); }
1062 | parameterized_type { $$ = append_typeref(NULL, make_typeref($1)); }
1063 | required_types ',' qualified_type { $$ = append_typeref($1, make_typeref($3)); }
1064 | required_types ',' parameterized_type { $$ = append_typeref($1, make_typeref($3)); }
1066 requires: { $$ = NULL; }
1067 | tREQUIRES required_types { $$ = $2; }
1070 interfacedef: attributes interface { if ($2->type_type == TYPE_PARAMETERIZED_TYPE) push_parameters_namespace($2->name); }
1071 inherit requires '{' int_statements '}' semicolon_opt
1072 { if ($2->type_type == TYPE_PARAMETERIZED_TYPE)
1074 $$ = type_parameterized_interface_define($2, $1, $4, $7, $5);
1075 pop_parameters_namespace($2->name);
1077 else
1079 $$ = type_interface_define($2, $1, $4, $7, $5);
1080 check_async_uuid($$);
1083 | dispinterfacedef semicolon_opt { $$ = $1; }
1086 interfaceref:
1087 tINTERFACE typename { $$ = get_type(TYPE_INTERFACE, $2, current_namespace, 0); }
1088 | tINTERFACE namespace_pfx typename { $$ = get_type(TYPE_INTERFACE, $3, $2, 0); }
1091 dispinterfaceref:
1092 tDISPINTERFACE typename { $$ = get_type(TYPE_INTERFACE, $2, current_namespace, 0); }
1095 module: tMODULE typename { $$ = type_module_declare($2); }
1098 moduledef: m_attributes module '{' int_statements '}' semicolon_opt
1099 { $$ = type_module_define($2, $1, $4); }
1102 storage_cls_spec:
1103 tEXTERN { $$ = STG_EXTERN; }
1104 | tSTATIC { $$ = STG_STATIC; }
1105 | tREGISTER { $$ = STG_REGISTER; }
1108 function_specifier:
1109 tINLINE { $$ = FUNCTION_SPECIFIER_INLINE; }
1112 type_qualifier:
1113 tCONST { $$ = TYPE_QUALIFIER_CONST; }
1116 m_type_qual_list: { $$ = 0; }
1117 | m_type_qual_list type_qualifier { $$ = $1 | $2; }
1120 decl_spec: type m_decl_spec_no_type { $$ = make_decl_spec($1, $2, NULL, STG_NONE, 0, 0); }
1121 | decl_spec_no_type type m_decl_spec_no_type
1122 { $$ = make_decl_spec($2, $1, $3, STG_NONE, 0, 0); }
1125 unqualified_decl_spec: unqualified_type m_decl_spec_no_type
1126 { $$ = make_decl_spec($1, $2, NULL, STG_NONE, 0, 0); }
1127 | decl_spec_no_type unqualified_type m_decl_spec_no_type
1128 { $$ = make_decl_spec($2, $1, $3, STG_NONE, 0, 0); }
1131 m_decl_spec_no_type: { $$ = NULL; }
1132 | decl_spec_no_type
1135 decl_spec_no_type:
1136 type_qualifier m_decl_spec_no_type { $$ = make_decl_spec(NULL, $2, NULL, STG_NONE, $1, 0); }
1137 | function_specifier m_decl_spec_no_type { $$ = make_decl_spec(NULL, $2, NULL, STG_NONE, 0, $1); }
1138 | storage_cls_spec m_decl_spec_no_type { $$ = make_decl_spec(NULL, $2, NULL, $1, 0, 0); }
1141 declarator:
1142 '*' m_type_qual_list declarator %prec PPTR
1143 { $$ = $3; append_chain_type($$, type_new_pointer(NULL), $2); }
1144 | callconv declarator { $$ = $2; append_chain_callconv($$->type, $1); }
1145 | direct_declarator
1148 direct_declarator:
1149 ident { $$ = make_declarator($1); }
1150 | '(' declarator ')' { $$ = $2; }
1151 | direct_declarator array { $$ = $1; append_array($$, $2); }
1152 | direct_declarator '(' m_args ')' { $$ = $1; append_chain_type($$, type_new_function($3), 0); }
1155 /* abstract declarator */
1156 abstract_declarator:
1157 '*' m_type_qual_list m_abstract_declarator %prec PPTR
1158 { $$ = $3; append_chain_type($$, type_new_pointer(NULL), $2); }
1159 | callconv m_abstract_declarator { $$ = $2; append_chain_callconv($$->type, $1); }
1160 | abstract_direct_declarator
1163 /* abstract declarator without accepting direct declarator */
1164 abstract_declarator_no_direct:
1165 '*' m_type_qual_list m_any_declarator %prec PPTR
1166 { $$ = $3; append_chain_type($$, type_new_pointer(NULL), $2); }
1167 | callconv m_any_declarator { $$ = $2; append_chain_callconv($$->type, $1); }
1170 /* abstract declarator or empty */
1171 m_abstract_declarator: { $$ = make_declarator(NULL); }
1172 | abstract_declarator
1175 /* abstract direct declarator */
1176 abstract_direct_declarator:
1177 '(' abstract_declarator_no_direct ')' { $$ = $2; }
1178 | abstract_direct_declarator array { $$ = $1; append_array($$, $2); }
1179 | array { $$ = make_declarator(NULL); append_array($$, $1); }
1180 | '(' m_args ')'
1181 { $$ = make_declarator(NULL);
1182 append_chain_type($$, type_new_function($2), 0);
1184 | abstract_direct_declarator '(' m_args ')'
1185 { $$ = $1;
1186 append_chain_type($$, type_new_function($3), 0);
1190 /* abstract or non-abstract declarator */
1191 any_declarator:
1192 '*' m_type_qual_list m_any_declarator %prec PPTR
1193 { $$ = $3; append_chain_type($$, type_new_pointer(NULL), $2); }
1194 | callconv m_any_declarator { $$ = $2; append_chain_callconv($$->type, $1); }
1195 | any_direct_declarator
1198 /* abstract or non-abstract declarator without accepting direct declarator */
1199 any_declarator_no_direct:
1200 '*' m_type_qual_list m_any_declarator %prec PPTR
1201 { $$ = $3; append_chain_type($$, type_new_pointer(NULL), $2); }
1202 | callconv m_any_declarator { $$ = $2; append_chain_callconv($$->type, $1); }
1205 /* abstract or non-abstract declarator or empty */
1206 m_any_declarator: { $$ = make_declarator(NULL); }
1207 | any_declarator
1210 /* abstract or non-abstract direct declarator. note: direct declarators
1211 * aren't accepted inside brackets to avoid ambiguity with the rule for
1212 * function arguments */
1213 any_direct_declarator:
1214 ident { $$ = make_declarator($1); }
1215 | '(' any_declarator_no_direct ')' { $$ = $2; }
1216 | any_direct_declarator array { $$ = $1; append_array($$, $2); }
1217 | array { $$ = make_declarator(NULL); append_array($$, $1); }
1218 | '(' m_args ')'
1219 { $$ = make_declarator(NULL);
1220 append_chain_type($$, type_new_function($2), 0);
1222 | any_direct_declarator '(' m_args ')'
1223 { $$ = $1;
1224 append_chain_type($$, type_new_function($3), 0);
1228 declarator_list:
1229 declarator { $$ = append_declarator( NULL, $1 ); }
1230 | declarator_list ',' declarator { $$ = append_declarator( $1, $3 ); }
1233 m_bitfield: { $$ = NULL; }
1234 | ':' expr_const { $$ = $2; }
1237 struct_declarator: any_declarator m_bitfield { $$ = $1; $$->bits = $2;
1238 if (!$$->bits && !$$->var->name)
1239 error_loc("unnamed fields are not allowed\n");
1243 struct_declarator_list:
1244 struct_declarator { $$ = append_declarator( NULL, $1 ); }
1245 | struct_declarator_list ',' struct_declarator
1246 { $$ = append_declarator( $1, $3 ); }
1249 init_declarator:
1250 declarator { $$ = $1; }
1251 | declarator '=' expr_const { $$ = $1; $1->var->eval = $3; }
1254 threading_type:
1255 tAPARTMENT { $$ = THREADING_APARTMENT; }
1256 | tNEUTRAL { $$ = THREADING_NEUTRAL; }
1257 | tSINGLE { $$ = THREADING_SINGLE; }
1258 | tFREE { $$ = THREADING_FREE; }
1259 | tBOTH { $$ = THREADING_BOTH; }
1260 | tMTA { $$ = THREADING_FREE; }
1263 pointer_type:
1264 tREF { $$ = FC_RP; }
1265 | tUNIQUE { $$ = FC_UP; }
1266 | tPTR { $$ = FC_FP; }
1269 structdef: tSTRUCT m_typename '{' fields '}' { $$ = type_new_struct($2, current_namespace, TRUE, $4); }
1272 unqualified_type:
1273 tVOID { $$ = type_new_void(); }
1274 | base_type { $$ = $1; }
1275 | enumdef { $$ = $1; }
1276 | tENUM aIDENTIFIER { $$ = type_new_enum($2, current_namespace, FALSE, NULL); }
1277 | structdef { $$ = $1; }
1278 | tSTRUCT aIDENTIFIER { $$ = type_new_struct($2, current_namespace, FALSE, NULL); }
1279 | uniondef { $$ = $1; }
1280 | tUNION aIDENTIFIER { $$ = type_new_nonencapsulated_union($2, FALSE, NULL); }
1281 | tSAFEARRAY '(' type ')' { $$ = make_safearray($3); }
1282 | aKNOWNTYPE { $$ = find_type_or_error(current_namespace, $1); }
1285 type:
1286 unqualified_type
1287 | namespace_pfx typename { $$ = find_type_or_error($1, $2); }
1288 | parameterized_type { $$ = $1; }
1291 typedef: m_attributes tTYPEDEF m_attributes decl_spec declarator_list
1292 { $1 = append_attribs($1, $3);
1293 reg_typedefs($4, $5, check_typedef_attrs($1));
1294 $$ = make_statement_typedef($5, !$4->type->defined);
1298 uniondef: tUNION m_typename '{' ne_union_fields '}'
1299 { $$ = type_new_nonencapsulated_union($2, TRUE, $4); }
1300 | tUNION m_typename
1301 tSWITCH '(' s_field ')'
1302 m_ident '{' cases '}' { $$ = type_new_encapsulated_union($2, $5, $7, $9); }
1305 version:
1306 aNUM { $$ = MAKEVERSION($1, 0); }
1307 | aNUM '.' aNUM { $$ = MAKEVERSION($1, $3); }
1308 | aHEXNUM { $$ = $1; }
1311 acf_statements
1312 : /* empty */
1313 | acf_interface acf_statements
1316 acf_int_statements
1317 : /* empty */
1318 | acf_int_statement acf_int_statements
1321 acf_int_statement
1322 : tTYPEDEF acf_attributes aKNOWNTYPE ';'
1323 { type_t *type = find_type_or_error(current_namespace, $3);
1324 type->attrs = append_attr_list(type->attrs, $2);
1328 acf_interface
1329 : acf_attributes tINTERFACE aKNOWNTYPE '{' acf_int_statements '}'
1330 { type_t *iface = find_type_or_error(current_namespace, $3);
1331 if (type_get_type(iface) != TYPE_INTERFACE)
1332 error_loc("%s is not an interface\n", iface->name);
1333 iface->attrs = append_attr_list(iface->attrs, $1);
1337 acf_attributes
1338 : /* empty */ { $$ = NULL; };
1339 | '[' acf_attribute_list ']' { $$ = $2; };
1342 acf_attribute_list
1343 : acf_attribute { $$ = append_attr(NULL, $1); }
1344 | acf_attribute_list ',' acf_attribute { $$ = append_attr($1, $3); }
1347 acf_attribute
1348 : tALLOCATE '(' allocate_option_list ')'
1349 { $$ = make_attrv(ATTR_ALLOCATE, $3); }
1350 | tENCODE { $$ = make_attr(ATTR_ENCODE); }
1351 | tDECODE { $$ = make_attr(ATTR_DECODE); }
1352 | tEXPLICITHANDLE { $$ = make_attr(ATTR_EXPLICIT_HANDLE); }
1355 allocate_option_list
1356 : allocate_option { $$ = $1; }
1357 | allocate_option_list ',' allocate_option
1358 { $$ = $1 | $3; }
1361 allocate_option
1362 : tDONTFREE { $$ = FC_DONT_FREE; }
1363 | tFREE { $$ = 0; }
1364 | tALLNODES { $$ = FC_ALLOCATE_ALL_NODES; }
1365 | tSINGLENODE { $$ = 0; }
1370 static void decl_builtin_basic(const char *name, enum type_basic_type type)
1372 type_t *t = type_new_basic(type);
1373 reg_type(t, name, NULL, 0);
1376 static void decl_builtin_alias(const char *name, type_t *t)
1378 const decl_spec_t ds = {.type = t};
1379 reg_type(type_new_alias(&ds, name), name, NULL, 0);
1382 void init_types(void)
1384 decl_builtin_basic("byte", TYPE_BASIC_BYTE);
1385 decl_builtin_basic("wchar_t", TYPE_BASIC_WCHAR);
1386 decl_builtin_basic("float", TYPE_BASIC_FLOAT);
1387 decl_builtin_basic("double", TYPE_BASIC_DOUBLE);
1388 decl_builtin_basic("error_status_t", TYPE_BASIC_ERROR_STATUS_T);
1389 decl_builtin_basic("handle_t", TYPE_BASIC_HANDLE);
1390 decl_builtin_alias("boolean", type_new_basic(TYPE_BASIC_CHAR));
1393 static str_list_t *append_str(str_list_t *list, char *str)
1395 struct str_list_entry_t *entry;
1397 if (!str) return list;
1398 if (!list)
1400 list = xmalloc( sizeof(*list) );
1401 list_init( list );
1403 entry = xmalloc( sizeof(*entry) );
1404 entry->str = str;
1405 list_add_tail( list, &entry->entry );
1406 return list;
1409 static attr_list_t *move_attr(attr_list_t *dst, attr_list_t *src, enum attr_type type)
1411 attr_t *attr;
1412 if (!src) return dst;
1413 LIST_FOR_EACH_ENTRY(attr, src, attr_t, entry)
1414 if (attr->type == type)
1416 list_remove(&attr->entry);
1417 return append_attr(dst, attr);
1419 return dst;
1422 static attr_list_t *append_attr_list(attr_list_t *new_list, attr_list_t *old_list)
1424 struct list *entry;
1426 if (!old_list) return new_list;
1428 while ((entry = list_head(old_list)))
1430 attr_t *attr = LIST_ENTRY(entry, attr_t, entry);
1431 list_remove(entry);
1432 new_list = append_attr(new_list, attr);
1434 return new_list;
1437 typedef int (*map_attrs_filter_t)(attr_list_t*,const attr_t*);
1439 static attr_list_t *map_attrs(const attr_list_t *list, map_attrs_filter_t filter)
1441 attr_list_t *new_list;
1442 const attr_t *attr;
1443 attr_t *new_attr;
1445 if (!list) return NULL;
1447 new_list = xmalloc( sizeof(*list) );
1448 list_init( new_list );
1449 LIST_FOR_EACH_ENTRY(attr, list, const attr_t, entry)
1451 if (filter && !filter(new_list, attr)) continue;
1452 new_attr = xmalloc(sizeof(*new_attr));
1453 *new_attr = *attr;
1454 list_add_tail(new_list, &new_attr->entry);
1456 return new_list;
1459 static decl_spec_t *make_decl_spec(type_t *type, decl_spec_t *left, decl_spec_t *right,
1460 enum storage_class stgclass, enum type_qualifier qual, enum function_specifier func_specifier)
1462 decl_spec_t *declspec = left ? left : right;
1463 if (!declspec)
1465 declspec = xmalloc(sizeof(*declspec));
1466 declspec->type = NULL;
1467 declspec->stgclass = STG_NONE;
1468 declspec->qualifier = 0;
1469 declspec->func_specifier = 0;
1471 declspec->type = type;
1472 if (left && declspec != left)
1474 if (declspec->stgclass == STG_NONE)
1475 declspec->stgclass = left->stgclass;
1476 else if (left->stgclass != STG_NONE)
1477 error_loc("only one storage class can be specified\n");
1478 declspec->qualifier |= left->qualifier;
1479 declspec->func_specifier |= left->func_specifier;
1480 assert(!left->type);
1481 free(left);
1483 if (right && declspec != right)
1485 if (declspec->stgclass == STG_NONE)
1486 declspec->stgclass = right->stgclass;
1487 else if (right->stgclass != STG_NONE)
1488 error_loc("only one storage class can be specified\n");
1489 declspec->qualifier |= right->qualifier;
1490 declspec->func_specifier |= right->func_specifier;
1491 assert(!right->type);
1492 free(right);
1495 if (declspec->stgclass == STG_NONE)
1496 declspec->stgclass = stgclass;
1497 else if (stgclass != STG_NONE)
1498 error_loc("only one storage class can be specified\n");
1499 declspec->qualifier |= qual;
1500 declspec->func_specifier |= func_specifier;
1502 return declspec;
1505 static attr_t *make_attr(enum attr_type type)
1507 attr_t *a = xmalloc(sizeof(attr_t));
1508 a->type = type;
1509 a->u.ival = 0;
1510 return a;
1513 static attr_t *make_attrv(enum attr_type type, unsigned int val)
1515 attr_t *a = xmalloc(sizeof(attr_t));
1516 a->type = type;
1517 a->u.ival = val;
1518 return a;
1521 attr_t *make_attrp(enum attr_type type, void *val)
1523 attr_t *a = xmalloc(sizeof(attr_t));
1524 a->type = type;
1525 a->u.pval = val;
1526 return a;
1529 static attr_t *make_custom_attr(struct uuid *id, expr_t *pval)
1531 attr_t *a = xmalloc(sizeof(attr_t));
1532 attr_custdata_t *cstdata = xmalloc(sizeof(attr_custdata_t));
1533 a->type = ATTR_CUSTOM;
1534 cstdata->id = *id;
1535 cstdata->pval = pval;
1536 a->u.pval = cstdata;
1537 return a;
1540 static expr_list_t *append_expr(expr_list_t *list, expr_t *expr)
1542 if (!expr) return list;
1543 if (!list)
1545 list = xmalloc( sizeof(*list) );
1546 list_init( list );
1548 list_add_tail( list, &expr->entry );
1549 return list;
1552 static void append_array(declarator_t *decl, expr_t *expr)
1554 type_t *array;
1556 if (!expr)
1557 return;
1559 /* An array is always a reference pointer unless explicitly marked otherwise
1560 * (regardless of what the default pointer attribute is). */
1561 array = type_new_array(NULL, NULL, FALSE, expr->is_const ? expr->cval : 0,
1562 expr->is_const ? NULL : expr, NULL);
1564 append_chain_type(decl, array, 0);
1567 static struct list type_pool = LIST_INIT(type_pool);
1568 typedef struct
1570 type_t data;
1571 struct list link;
1572 } type_pool_node_t;
1574 type_t *alloc_type(void)
1576 type_pool_node_t *node = xmalloc(sizeof *node);
1577 list_add_tail(&type_pool, &node->link);
1578 return &node->data;
1581 void set_all_tfswrite(int val)
1583 type_pool_node_t *node;
1584 LIST_FOR_EACH_ENTRY(node, &type_pool, type_pool_node_t, link)
1585 node->data.tfswrite = val;
1588 void clear_all_offsets(void)
1590 type_pool_node_t *node;
1591 LIST_FOR_EACH_ENTRY(node, &type_pool, type_pool_node_t, link)
1592 node->data.typestring_offset = node->data.ptrdesc = 0;
1595 static void type_function_add_head_arg(type_t *type, var_t *arg)
1597 if (!type->details.function->args)
1599 type->details.function->args = xmalloc( sizeof(*type->details.function->args) );
1600 list_init( type->details.function->args );
1602 list_add_head( type->details.function->args, &arg->entry );
1605 static int is_allowed_range_type(const type_t *type)
1607 switch (type_get_type(type))
1609 case TYPE_ENUM:
1610 return TRUE;
1611 case TYPE_BASIC:
1612 switch (type_basic_get_type(type))
1614 case TYPE_BASIC_INT8:
1615 case TYPE_BASIC_INT16:
1616 case TYPE_BASIC_INT32:
1617 case TYPE_BASIC_INT64:
1618 case TYPE_BASIC_INT:
1619 case TYPE_BASIC_INT3264:
1620 case TYPE_BASIC_LONG:
1621 case TYPE_BASIC_BYTE:
1622 case TYPE_BASIC_CHAR:
1623 case TYPE_BASIC_WCHAR:
1624 case TYPE_BASIC_HYPER:
1625 return TRUE;
1626 case TYPE_BASIC_FLOAT:
1627 case TYPE_BASIC_DOUBLE:
1628 case TYPE_BASIC_ERROR_STATUS_T:
1629 case TYPE_BASIC_HANDLE:
1630 return FALSE;
1632 return FALSE;
1633 default:
1634 return FALSE;
1638 static type_t *get_chain_ref(type_t *type)
1640 if (is_ptr(type))
1641 return type_pointer_get_ref_type(type);
1642 else if (is_array(type))
1643 return type_array_get_element_type(type);
1644 else if (is_func(type))
1645 return type_function_get_rettype(type);
1646 return NULL;
1649 static type_t *get_chain_end(type_t *type)
1651 type_t *inner;
1652 while ((inner = get_chain_ref(type)))
1653 type = inner;
1654 return type;
1657 static void append_chain_type(declarator_t *decl, type_t *type, enum type_qualifier qual)
1659 type_t *chain_type;
1661 if (!decl->type)
1663 decl->type = type;
1664 decl->qualifier = qual;
1665 return;
1667 chain_type = get_chain_end(decl->type);
1669 if (is_ptr(chain_type))
1671 chain_type->details.pointer.ref.type = type;
1672 chain_type->details.pointer.ref.qualifier = qual;
1674 else if (is_array(chain_type))
1676 chain_type->details.array.elem.type = type;
1677 chain_type->details.array.elem.qualifier = qual;
1679 else if (is_func(chain_type))
1681 chain_type->details.function->retval->declspec.type = type;
1682 chain_type->details.function->retval->declspec.qualifier = qual;
1684 else
1685 assert(0);
1687 if (!is_func(chain_type))
1688 type->attrs = move_attr(type->attrs, chain_type->attrs, ATTR_CALLCONV);
1691 static void append_chain_callconv(type_t *chain, char *callconv)
1693 type_t *chain_end;
1695 if (chain && (chain_end = get_chain_end(chain)))
1696 chain_end->attrs = append_attr(chain_end->attrs, make_attrp(ATTR_CALLCONV, callconv));
1697 else
1698 error_loc("calling convention applied to non-function type\n");
1701 static warning_list_t *append_warning(warning_list_t *list, int num)
1703 warning_t *entry;
1705 if(!list)
1707 list = xmalloc( sizeof(*list) );
1708 list_init( list );
1710 entry = xmalloc( sizeof(*entry) );
1711 entry->num = num;
1712 list_add_tail( list, &entry->entry );
1713 return list;
1716 static var_t *declare_var(attr_list_t *attrs, decl_spec_t *decl_spec, declarator_t *decl,
1717 int top)
1719 var_t *v = decl->var;
1720 expr_list_t *sizes = get_attrp(attrs, ATTR_SIZEIS);
1721 expr_list_t *lengs = get_attrp(attrs, ATTR_LENGTHIS);
1722 expr_t *dim;
1723 type_t **ptype;
1724 type_t *type = decl_spec->type;
1726 if (decl_spec->func_specifier & FUNCTION_SPECIFIER_INLINE)
1728 if (!decl || !is_func(decl->type))
1729 error_loc("inline attribute applied to non-function type\n");
1732 /* add type onto the end of the pointers in pident->type */
1733 append_chain_type(decl, type, decl_spec->qualifier);
1734 v->declspec = *decl_spec;
1735 v->declspec.type = decl->type;
1736 v->declspec.qualifier = decl->qualifier;
1737 v->attrs = attrs;
1738 v->declonly = !type->defined;
1740 if (is_attr(type->attrs, ATTR_CALLCONV) && !is_func(type))
1741 error_loc("calling convention applied to non-function type\n");
1743 /* check for pointer attribute being applied to non-pointer, non-array
1744 * type */
1745 if (!is_array(v->declspec.type))
1747 int ptr_attr = get_attrv(v->attrs, ATTR_POINTERTYPE);
1748 const type_t *ptr = NULL;
1749 for (ptr = v->declspec.type; ptr && !ptr_attr; )
1751 ptr_attr = get_attrv(ptr->attrs, ATTR_POINTERTYPE);
1752 if (!ptr_attr && type_is_alias(ptr))
1753 ptr = type_alias_get_aliasee_type(ptr);
1754 else
1755 break;
1757 if (is_ptr(ptr))
1759 if (ptr_attr && ptr_attr != FC_UP &&
1760 type_get_type(type_pointer_get_ref_type(ptr)) == TYPE_INTERFACE)
1761 warning_loc_info(&v->loc_info,
1762 "%s: pointer attribute applied to interface "
1763 "pointer type has no effect\n", v->name);
1764 if (!ptr_attr && top)
1766 /* FIXME: this is a horrible hack to cope with the issue that we
1767 * store an offset to the typeformat string in the type object, but
1768 * two typeformat strings may be written depending on whether the
1769 * pointer is a toplevel parameter or not */
1770 v->declspec.type = duptype(v->declspec.type, 1);
1773 else if (ptr_attr)
1774 error_loc("%s: pointer attribute applied to non-pointer type\n", v->name);
1777 if (is_attr(v->attrs, ATTR_STRING))
1779 type_t *t = type;
1781 if (!is_ptr(v->declspec.type) && !is_array(v->declspec.type))
1782 error_loc("'%s': [string] attribute applied to non-pointer, non-array type\n",
1783 v->name);
1785 for (;;)
1787 if (is_ptr(t))
1788 t = type_pointer_get_ref_type(t);
1789 else if (is_array(t))
1790 t = type_array_get_element_type(t);
1791 else
1792 break;
1795 if (type_get_type(t) != TYPE_BASIC &&
1796 (get_basic_fc(t) != FC_CHAR &&
1797 get_basic_fc(t) != FC_BYTE &&
1798 get_basic_fc(t) != FC_WCHAR))
1800 error_loc("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
1801 v->name);
1805 if (is_attr(v->attrs, ATTR_V1ENUM))
1807 if (type_get_type_detect_alias(v->declspec.type) != TYPE_ENUM)
1808 error_loc("'%s': [v1_enum] attribute applied to non-enum type\n", v->name);
1811 if (is_attr(v->attrs, ATTR_RANGE) && !is_allowed_range_type(v->declspec.type))
1812 error_loc("'%s': [range] attribute applied to non-integer type\n",
1813 v->name);
1815 ptype = &v->declspec.type;
1816 if (sizes) LIST_FOR_EACH_ENTRY(dim, sizes, expr_t, entry)
1818 if (dim->type != EXPR_VOID)
1820 if (is_array(*ptype))
1822 if (!type_array_get_conformance(*ptype) ||
1823 type_array_get_conformance(*ptype)->type != EXPR_VOID)
1824 error_loc("%s: cannot specify size_is for an already sized array\n", v->name);
1825 else
1826 *ptype = type_new_array((*ptype)->name,
1827 type_array_get_element(*ptype), FALSE,
1828 0, dim, NULL);
1830 else if (is_ptr(*ptype))
1831 *ptype = type_new_array((*ptype)->name, type_pointer_get_ref(*ptype), TRUE,
1832 0, dim, NULL);
1833 else
1834 error_loc("%s: size_is attribute applied to illegal type\n", v->name);
1837 if (is_ptr(*ptype))
1838 ptype = &(*ptype)->details.pointer.ref.type;
1839 else if (is_array(*ptype))
1840 ptype = &(*ptype)->details.array.elem.type;
1841 else
1842 error_loc("%s: too many expressions in size_is attribute\n", v->name);
1845 ptype = &v->declspec.type;
1846 if (lengs) LIST_FOR_EACH_ENTRY(dim, lengs, expr_t, entry)
1848 if (dim->type != EXPR_VOID)
1850 if (is_array(*ptype))
1852 *ptype = type_new_array((*ptype)->name,
1853 type_array_get_element(*ptype),
1854 type_array_is_decl_as_ptr(*ptype),
1855 type_array_get_dim(*ptype),
1856 type_array_get_conformance(*ptype), dim);
1858 else
1859 error_loc("%s: length_is attribute applied to illegal type\n", v->name);
1862 if (is_ptr(*ptype))
1863 ptype = &(*ptype)->details.pointer.ref.type;
1864 else if (is_array(*ptype))
1865 ptype = &(*ptype)->details.array.elem.type;
1866 else
1867 error_loc("%s: too many expressions in length_is attribute\n", v->name);
1870 if (decl->bits)
1871 v->declspec.type = type_new_bitfield(v->declspec.type, decl->bits);
1873 return v;
1876 static var_list_t *set_var_types(attr_list_t *attrs, decl_spec_t *decl_spec, declarator_list_t *decls)
1878 declarator_t *decl, *next;
1879 var_list_t *var_list = NULL;
1881 LIST_FOR_EACH_ENTRY_SAFE( decl, next, decls, declarator_t, entry )
1883 var_t *var = declare_var(attrs, decl_spec, decl, 0);
1884 var_list = append_var(var_list, var);
1885 free(decl);
1887 free(decl_spec);
1888 return var_list;
1891 typeref_list_t *append_typeref(typeref_list_t *list, typeref_t *ref)
1893 if (!ref) return list;
1894 if (!list)
1896 list = xmalloc( sizeof(*list) );
1897 list_init( list );
1899 list_add_tail( list, &ref->entry );
1900 return list;
1903 typeref_t *make_typeref(type_t *type)
1905 typeref_t *ref = xmalloc(sizeof(typeref_t));
1906 ref->type = type;
1907 ref->attrs = NULL;
1908 return ref;
1911 var_list_t *append_var(var_list_t *list, var_t *var)
1913 if (!var) return list;
1914 if (!list)
1916 list = xmalloc( sizeof(*list) );
1917 list_init( list );
1919 list_add_tail( list, &var->entry );
1920 return list;
1923 static var_list_t *append_var_list(var_list_t *list, var_list_t *vars)
1925 if (!vars) return list;
1926 if (!list)
1928 list = xmalloc( sizeof(*list) );
1929 list_init( list );
1931 list_move_tail( list, vars );
1932 return list;
1935 var_t *make_var(char *name)
1937 var_t *v = xmalloc(sizeof(var_t));
1938 v->name = name;
1939 init_declspec(&v->declspec, NULL);
1940 v->attrs = NULL;
1941 v->eval = NULL;
1942 init_loc_info(&v->loc_info);
1943 v->declonly = FALSE;
1944 return v;
1947 static var_t *copy_var(var_t *src, char *name, map_attrs_filter_t attr_filter)
1949 var_t *v = xmalloc(sizeof(var_t));
1950 v->name = name;
1951 v->declspec = src->declspec;
1952 v->attrs = map_attrs(src->attrs, attr_filter);
1953 v->eval = src->eval;
1954 v->loc_info = src->loc_info;
1955 return v;
1958 static declarator_list_t *append_declarator(declarator_list_t *list, declarator_t *d)
1960 if (!d) return list;
1961 if (!list) {
1962 list = xmalloc(sizeof(*list));
1963 list_init(list);
1965 list_add_tail(list, &d->entry);
1966 return list;
1969 static declarator_t *make_declarator(var_t *var)
1971 declarator_t *d = xmalloc(sizeof(*d));
1972 d->var = var ? var : make_var(NULL);
1973 d->type = NULL;
1974 d->qualifier = 0;
1975 d->bits = NULL;
1976 return d;
1979 static type_t *make_safearray(type_t *type)
1981 decl_spec_t ds = {.type = type};
1982 ds.type = type_new_alias(&ds, "SAFEARRAY");
1983 return type_new_array(NULL, &ds, TRUE, 0, NULL, NULL);
1986 static typelib_t *make_library(const char *name, const attr_list_t *attrs)
1988 typelib_t *typelib = xmalloc(sizeof(*typelib));
1989 memset(typelib, 0, sizeof(*typelib));
1990 typelib->name = xstrdup(name);
1991 typelib->attrs = attrs;
1992 list_init( &typelib->importlibs );
1993 return typelib;
1996 static int hash_ident(const char *name)
1998 const char *p = name;
1999 int sum = 0;
2000 /* a simple sum hash is probably good enough */
2001 while (*p) {
2002 sum += *p;
2003 p++;
2005 return sum & (HASHMAX-1);
2008 /***** type repository *****/
2010 static struct namespace *find_sub_namespace(struct namespace *namespace, const char *name)
2012 struct namespace *cur;
2014 LIST_FOR_EACH_ENTRY(cur, &namespace->children, struct namespace, entry) {
2015 if(!strcmp(cur->name, name))
2016 return cur;
2019 return NULL;
2022 static void push_namespace(const char *name)
2024 struct namespace *namespace;
2026 namespace = find_sub_namespace(current_namespace, name);
2027 if(!namespace) {
2028 namespace = xmalloc(sizeof(*namespace));
2029 namespace->name = xstrdup(name);
2030 namespace->parent = current_namespace;
2031 list_add_tail(&current_namespace->children, &namespace->entry);
2032 list_init(&namespace->children);
2033 memset(namespace->type_hash, 0, sizeof(namespace->type_hash));
2036 current_namespace = namespace;
2039 static void pop_namespace(const char *name)
2041 assert(!strcmp(current_namespace->name, name) && current_namespace->parent);
2042 current_namespace = current_namespace->parent;
2045 static void push_namespaces(str_list_t *names)
2047 const struct str_list_entry_t *name;
2048 LIST_FOR_EACH_ENTRY(name, names, const struct str_list_entry_t, entry)
2049 push_namespace(name->str);
2052 static void pop_namespaces(str_list_t *names)
2054 const struct str_list_entry_t *name;
2055 LIST_FOR_EACH_ENTRY_REV(name, names, const struct str_list_entry_t, entry)
2056 pop_namespace(name->str);
2059 static void push_parameters_namespace(const char *name)
2061 struct namespace *namespace;
2063 if (!(namespace = find_sub_namespace(current_namespace, name)))
2065 namespace = xmalloc(sizeof(*namespace));
2066 namespace->name = xstrdup(name);
2067 namespace->parent = current_namespace;
2068 list_add_tail(&current_namespace->children, &namespace->entry);
2069 list_init(&namespace->children);
2070 memset(namespace->type_hash, 0, sizeof(namespace->type_hash));
2073 parameters_namespace = namespace;
2076 static void pop_parameters_namespace(const char *name)
2078 assert(!strcmp(parameters_namespace->name, name) && parameters_namespace->parent);
2079 parameters_namespace = NULL;
2082 struct rtype {
2083 const char *name;
2084 type_t *type;
2085 int t;
2086 struct rtype *next;
2089 type_t *reg_type(type_t *type, const char *name, struct namespace *namespace, int t)
2091 struct rtype *nt;
2092 int hash;
2093 if (!name) {
2094 error_loc("registering named type without name\n");
2095 return type;
2097 if (!namespace)
2098 namespace = &global_namespace;
2099 hash = hash_ident(name);
2100 nt = xmalloc(sizeof(struct rtype));
2101 nt->name = name;
2102 if (is_global_namespace(namespace))
2104 type->c_name = name;
2105 type->qualified_name = name;
2107 else
2109 type->c_name = format_namespace(namespace, "__x_", "_C", name, use_abi_namespace ? "ABI" : NULL);
2110 type->qualified_name = format_namespace(namespace, "", "::", name, use_abi_namespace ? "ABI" : NULL);
2112 nt->type = type;
2113 nt->t = t;
2114 nt->next = namespace->type_hash[hash];
2115 namespace->type_hash[hash] = nt;
2116 return type;
2119 static type_t *reg_typedefs(decl_spec_t *decl_spec, declarator_list_t *decls, attr_list_t *attrs)
2121 declarator_t *decl;
2122 type_t *type = decl_spec->type;
2124 if (is_attr(attrs, ATTR_UUID) && !is_attr(attrs, ATTR_PUBLIC))
2125 attrs = append_attr( attrs, make_attr(ATTR_PUBLIC) );
2127 /* We must generate names for tagless enum, struct or union.
2128 Typedef-ing a tagless enum, struct or union means we want the typedef
2129 to be included in a library hence the public attribute. */
2130 if (type_get_type_detect_alias(type) == TYPE_ENUM ||
2131 type_get_type_detect_alias(type) == TYPE_STRUCT ||
2132 type_get_type_detect_alias(type) == TYPE_UNION ||
2133 type_get_type_detect_alias(type) == TYPE_ENCAPSULATED_UNION)
2135 if (!type->name)
2137 type->name = gen_name();
2138 if (!is_attr(attrs, ATTR_PUBLIC))
2139 attrs = append_attr(attrs, make_attr(ATTR_PUBLIC));
2142 /* replace existing attributes when generating a typelib */
2143 if (do_typelib)
2144 type->attrs = attrs;
2147 LIST_FOR_EACH_ENTRY( decl, decls, declarator_t, entry )
2150 if (decl->var->name) {
2151 type_t *cur;
2152 var_t *name;
2154 cur = find_type(decl->var->name, current_namespace, 0);
2157 * MIDL allows shadowing types that are declared in imported files.
2158 * We don't throw an error in this case and instead add a new type
2159 * (which is earlier on the list in hash table, so it will be used
2160 * instead of shadowed type).
2162 * FIXME: We may consider string separated type tables for each input
2163 * for cleaner solution.
2165 if (cur && input_name == cur->loc_info.input_name)
2166 error_loc("%s: redefinition error; original definition was at %s:%d\n",
2167 cur->name, cur->loc_info.input_name,
2168 cur->loc_info.line_number);
2170 name = declare_var(attrs, decl_spec, decl, 0);
2171 cur = type_new_alias(&name->declspec, name->name);
2172 cur->attrs = attrs;
2174 reg_type(cur, cur->name, current_namespace, 0);
2177 return type;
2180 type_t *find_type(const char *name, struct namespace *namespace, int t)
2182 struct rtype *cur;
2184 if(namespace && namespace != &global_namespace) {
2185 for(cur = namespace->type_hash[hash_ident(name)]; cur; cur = cur->next) {
2186 if(cur->t == t && !strcmp(cur->name, name))
2187 return cur->type;
2190 for(cur = global_namespace.type_hash[hash_ident(name)]; cur; cur = cur->next) {
2191 if(cur->t == t && !strcmp(cur->name, name))
2192 return cur->type;
2194 return NULL;
2197 static type_t *find_type_or_error(struct namespace *namespace, const char *name)
2199 type_t *type;
2200 if (!(type = find_type(name, namespace, 0)) &&
2201 !(type = find_type(name, parameters_namespace, 0)))
2203 error_loc("type '%s' not found in %s namespace\n", name, namespace && namespace->name ? namespace->name : "global");
2204 return NULL;
2206 return type;
2209 static struct namespace *find_namespace_or_error(struct namespace *parent, const char *name)
2211 struct namespace *namespace = NULL;
2213 if (!winrt_mode)
2214 error_loc("namespaces are only supported in winrt mode.\n");
2215 else if (!(namespace = find_sub_namespace(parent, name)))
2216 error_loc("namespace '%s' not found in '%s'\n", name, parent->name);
2218 return namespace;
2221 int is_type(const char *name)
2223 return find_type(name, current_namespace, 0) != NULL ||
2224 find_type(name, parameters_namespace, 0);
2227 type_t *get_type(enum type_type type, char *name, struct namespace *namespace, int t)
2229 type_t *tp;
2230 if (!namespace)
2231 namespace = &global_namespace;
2232 if (name) {
2233 tp = find_type(name, namespace, t);
2234 if (tp) {
2235 free(name);
2236 return tp;
2239 tp = make_type(type);
2240 tp->name = name;
2241 tp->namespace = namespace;
2242 if (!name) return tp;
2243 return reg_type(tp, name, namespace, t);
2246 /***** constant repository *****/
2248 struct rconst {
2249 char *name;
2250 var_t *var;
2251 struct rconst *next;
2254 struct rconst *const_hash[HASHMAX];
2256 static var_t *reg_const(var_t *var)
2258 struct rconst *nc;
2259 int hash;
2260 if (!var->name) {
2261 error_loc("registering constant without name\n");
2262 return var;
2264 hash = hash_ident(var->name);
2265 nc = xmalloc(sizeof(struct rconst));
2266 nc->name = var->name;
2267 nc->var = var;
2268 nc->next = const_hash[hash];
2269 const_hash[hash] = nc;
2270 return var;
2273 var_t *find_const(const char *name, int f)
2275 struct rconst *cur = const_hash[hash_ident(name)];
2276 while (cur && strcmp(cur->name, name))
2277 cur = cur->next;
2278 if (!cur) {
2279 if (f) error_loc("constant '%s' not found\n", name);
2280 return NULL;
2282 return cur->var;
2285 char *gen_name(void)
2287 static unsigned long n = 0;
2288 static const char *file_id;
2290 if (! file_id)
2292 char *dst = replace_extension( get_basename(input_idl_name), ".idl", "" );
2293 file_id = dst;
2295 for (; *dst; ++dst)
2296 if (! isalnum((unsigned char) *dst))
2297 *dst = '_';
2299 return strmake("__WIDL_%s_generated_name_%08lX", file_id, n++);
2302 struct allowed_attr
2304 unsigned int dce_compatible : 1;
2305 unsigned int acf : 1;
2306 unsigned int multiple : 1;
2308 unsigned int on_interface : 1;
2309 unsigned int on_function : 1;
2310 unsigned int on_arg : 1;
2311 unsigned int on_type : 1;
2312 unsigned int on_enum : 1;
2313 unsigned int on_enum_member : 1;
2314 unsigned int on_struct : 2;
2315 unsigned int on_union : 1;
2316 unsigned int on_field : 1;
2317 unsigned int on_library : 1;
2318 unsigned int on_dispinterface : 1;
2319 unsigned int on_module : 1;
2320 unsigned int on_coclass : 1;
2321 unsigned int on_apicontract : 1;
2322 unsigned int on_runtimeclass : 1;
2323 const char *display_name;
2326 struct allowed_attr allowed_attr[] =
2328 /* attr { D ACF M I Fn ARG T En Enm St Un Fi L DI M C AC R <display name> } */
2329 /* ATTR_ACTIVATABLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "activatable" },
2330 /* ATTR_AGGREGATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "aggregatable" },
2331 /* ATTR_ALLOCATE */ { 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "allocate" },
2332 /* ATTR_ANNOTATION */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "annotation" },
2333 /* ATTR_APPOBJECT */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "appobject" },
2334 /* ATTR_ASYNC */ { 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "async" },
2335 /* ATTR_ASYNCUUID */ { 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "async_uuid" },
2336 /* ATTR_AUTO_HANDLE */ { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "auto_handle" },
2337 /* ATTR_BINDABLE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "bindable" },
2338 /* ATTR_BROADCAST */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "broadcast" },
2339 /* ATTR_CALLAS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "call_as" },
2340 /* ATTR_CALLCONV */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL },
2341 /* ATTR_CASE */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "case" },
2342 /* ATTR_CODE */ { 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "code" },
2343 /* ATTR_COMMSTATUS */ { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "comm_status" },
2344 /* ATTR_CONTEXTHANDLE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "context_handle" },
2345 /* ATTR_CONTRACT */ { 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, "contract" },
2346 /* ATTR_CONTRACTVERSION */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, "contractversion" },
2347 /* ATTR_CONTROL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, "control" },
2348 /* ATTR_CUSTOM */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, "custom" },
2349 /* ATTR_DECODE */ { 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "decode" },
2350 /* ATTR_DEFAULT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "default" },
2351 /* ATTR_DEFAULTBIND */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultbind" },
2352 /* ATTR_DEFAULTCOLLELEM */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultcollelem" },
2353 /* ATTR_DEFAULTVALUE */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultvalue" },
2354 /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "defaultvtable" },
2355 /* ATTR_DISABLECONSISTENCYCHECK */{ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "disable_consistency_check" },
2356 /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, NULL },
2357 /* ATTR_DISPLAYBIND */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "displaybind" },
2358 /* ATTR_DLLNAME */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "dllname" },
2359 /* ATTR_DUAL */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "dual" },
2360 /* ATTR_ENABLEALLOCATE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "enable_allocate" },
2361 /* ATTR_ENCODE */ { 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "encode" },
2362 /* ATTR_ENDPOINT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "endpoint" },
2363 /* ATTR_ENTRY */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "entry" },
2364 /* ATTR_EVENTADD */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "eventadd" },
2365 /* ATTR_EVENTREMOVE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "eventremove" },
2366 /* ATTR_EXCLUSIVETO */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "exclusive_to" },
2367 /* ATTR_EXPLICIT_HANDLE */ { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "explicit_handle" },
2368 /* ATTR_FAULTSTATUS */ { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "fault_status" },
2369 /* ATTR_FLAGS */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "flags" },
2370 /* ATTR_FORCEALLOCATE */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "force_allocate" },
2371 /* ATTR_HANDLE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "handle" },
2372 /* ATTR_HELPCONTEXT */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "helpcontext" },
2373 /* ATTR_HELPFILE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "helpfile" },
2374 /* ATTR_HELPSTRING */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "helpstring" },
2375 /* ATTR_HELPSTRINGCONTEXT */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "helpstringcontext" },
2376 /* ATTR_HELPSTRINGDLL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "helpstringdll" },
2377 /* ATTR_HIDDEN */ { 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, "hidden" },
2378 /* ATTR_ID */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, "id" },
2379 /* ATTR_IDEMPOTENT */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "idempotent" },
2380 /* ATTR_IGNORE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "ignore" },
2381 /* ATTR_IIDIS */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "iid_is" },
2382 /* ATTR_IMMEDIATEBIND */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "immediatebind" },
2383 /* ATTR_IMPLICIT_HANDLE */ { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "implicit_handle" },
2384 /* ATTR_IN */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "in" },
2385 /* ATTR_INPUTSYNC */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inputsync" },
2386 /* ATTR_LENGTHIS */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "length_is" },
2387 /* ATTR_LIBLCID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "lcid" },
2388 /* ATTR_LICENSED */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "licensed" },
2389 /* ATTR_LOCAL */ { 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "local" },
2390 /* ATTR_MARSHALING_BEHAVIOR */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "marshaling_behavior" },
2391 /* ATTR_MAYBE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "maybe" },
2392 /* ATTR_MESSAGE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "message" },
2393 /* ATTR_NOCODE */ { 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nocode" },
2394 /* ATTR_NONBROWSABLE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonbrowsable" },
2395 /* ATTR_NONCREATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "noncreatable" },
2396 /* ATTR_NONEXTENSIBLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonextensible" },
2397 /* ATTR_NOTIFY */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "notify" },
2398 /* ATTR_NOTIFYFLAG */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "notify_flag" },
2399 /* ATTR_OBJECT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "object" },
2400 /* ATTR_ODL */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "odl" },
2401 /* ATTR_OLEAUTOMATION */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "oleautomation" },
2402 /* ATTR_OPTIMIZE */ { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optimize" },
2403 /* ATTR_OPTIONAL */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optional" },
2404 /* ATTR_OUT */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "out" },
2405 /* ATTR_OVERLOAD */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "overload" },
2406 /* ATTR_PARAMLCID */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "lcid" },
2407 /* ATTR_PARTIALIGNORE */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "partial_ignore" },
2408 /* ATTR_POINTERDEFAULT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "pointer_default" },
2409 /* ATTR_POINTERTYPE */ { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "ref, unique or ptr" },
2410 /* ATTR_PROGID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "progid" },
2411 /* ATTR_PROPGET */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propget" },
2412 /* ATTR_PROPPUT */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propput" },
2413 /* ATTR_PROPPUTREF */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propputref" },
2414 /* ATTR_PROXY */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "proxy" },
2415 /* ATTR_PUBLIC */ { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "public" },
2416 /* ATTR_RANGE */ { 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "range" },
2417 /* ATTR_READONLY */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "readonly" },
2418 /* ATTR_REPRESENTAS */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "represent_as" },
2419 /* ATTR_REQUESTEDIT */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "requestedit" },
2420 /* ATTR_RESTRICTED */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, "restricted" },
2421 /* ATTR_RETVAL */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "retval" },
2422 /* ATTR_SIZEIS */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "size_is" },
2423 /* ATTR_SOURCE */ { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "source" },
2424 /* ATTR_STATIC */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "static" },
2425 /* ATTR_STRICTCONTEXTHANDLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "strict_context_handle" },
2426 /* ATTR_STRING */ { 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "string" },
2427 /* ATTR_SWITCHIS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "switch_is" },
2428 /* ATTR_SWITCHTYPE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "switch_type" },
2429 /* ATTR_THREADING */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, "threading" },
2430 /* ATTR_TRANSMITAS */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "transmit_as" },
2431 /* ATTR_UIDEFAULT */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "uidefault" },
2432 /* ATTR_USESGETLASTERROR */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "usesgetlasterror" },
2433 /* ATTR_USERMARSHAL */ { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "user_marshal" },
2434 /* ATTR_UUID */ { 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, "uuid" },
2435 /* ATTR_V1ENUM */ { 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "v1_enum" },
2436 /* ATTR_VARARG */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "vararg" },
2437 /* ATTR_VERSION */ { 1, 0, 0, 1, 0, 0, 1, 1, 0, 2, 0, 0, 1, 0, 1, 1, 0, 1, "version" },
2438 /* ATTR_VIPROGID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "vi_progid" },
2439 /* ATTR_WIREMARSHAL */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "wire_marshal" },
2442 attr_list_t *append_attr(attr_list_t *list, attr_t *attr)
2444 attr_t *attr_existing;
2445 if (!attr) return list;
2446 if (!list)
2448 list = xmalloc( sizeof(*list) );
2449 list_init( list );
2451 if (!allowed_attr[attr->type].multiple)
2453 LIST_FOR_EACH_ENTRY(attr_existing, list, attr_t, entry)
2454 if (attr_existing->type == attr->type)
2456 parser_warning("duplicate attribute %s\n", get_attr_display_name(attr->type));
2457 /* use the last attribute, like MIDL does */
2458 list_remove(&attr_existing->entry);
2459 break;
2462 list_add_tail( list, &attr->entry );
2463 return list;
2466 const char *get_attr_display_name(enum attr_type type)
2468 return allowed_attr[type].display_name;
2471 attr_list_t *check_interface_attrs(const char *name, attr_list_t *attrs)
2473 const attr_t *attr;
2474 if (!attrs) return attrs;
2475 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2477 if (!allowed_attr[attr->type].on_interface)
2478 error_loc("inapplicable attribute %s for interface %s\n",
2479 allowed_attr[attr->type].display_name, name);
2480 if (attr->type == ATTR_IMPLICIT_HANDLE)
2482 const var_t *var = attr->u.pval;
2483 if (type_get_type( var->declspec.type) == TYPE_BASIC &&
2484 type_basic_get_type( var->declspec.type ) == TYPE_BASIC_HANDLE)
2485 continue;
2486 if (is_aliaschain_attr( var->declspec.type, ATTR_HANDLE ))
2487 continue;
2488 error_loc("attribute %s requires a handle type in interface %s\n",
2489 allowed_attr[attr->type].display_name, name);
2492 return attrs;
2495 static attr_list_t *check_function_attrs(const char *name, attr_list_t *attrs)
2497 const attr_t *attr;
2498 if (!attrs) return attrs;
2499 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2501 if (!allowed_attr[attr->type].on_function)
2502 error_loc("inapplicable attribute %s for function %s\n",
2503 allowed_attr[attr->type].display_name, name);
2505 return attrs;
2508 static void check_arg_attrs(const var_t *arg)
2510 const attr_t *attr;
2512 if (arg->attrs)
2514 LIST_FOR_EACH_ENTRY(attr, arg->attrs, const attr_t, entry)
2516 if (!allowed_attr[attr->type].on_arg)
2517 error_loc("inapplicable attribute %s for argument %s\n",
2518 allowed_attr[attr->type].display_name, arg->name);
2523 static attr_list_t *check_typedef_attrs(attr_list_t *attrs)
2525 const attr_t *attr;
2526 if (!attrs) return attrs;
2527 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2529 if (!allowed_attr[attr->type].on_type)
2530 error_loc("inapplicable attribute %s for typedef\n",
2531 allowed_attr[attr->type].display_name);
2533 return attrs;
2536 static attr_list_t *check_enum_attrs(attr_list_t *attrs)
2538 const attr_t *attr;
2539 if (!attrs) return attrs;
2540 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2542 if (!allowed_attr[attr->type].on_enum)
2543 error_loc("inapplicable attribute %s for enum\n",
2544 allowed_attr[attr->type].display_name);
2546 return attrs;
2549 static attr_list_t *check_enum_member_attrs(attr_list_t *attrs)
2551 const attr_t *attr;
2552 if (!attrs) return attrs;
2553 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2555 if (!allowed_attr[attr->type].on_enum_member)
2556 error_loc("inapplicable attribute %s for enum member\n",
2557 allowed_attr[attr->type].display_name);
2559 return attrs;
2562 static attr_list_t *check_struct_attrs(attr_list_t *attrs)
2564 int mask = winrt_mode ? 3 : 1;
2565 const attr_t *attr;
2566 if (!attrs) return attrs;
2567 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2569 if (!(allowed_attr[attr->type].on_struct & mask))
2570 error_loc("inapplicable attribute %s for struct\n",
2571 allowed_attr[attr->type].display_name);
2573 return attrs;
2576 static attr_list_t *check_union_attrs(attr_list_t *attrs)
2578 const attr_t *attr;
2579 if (!attrs) return attrs;
2580 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2582 if (!allowed_attr[attr->type].on_union)
2583 error_loc("inapplicable attribute %s for union\n",
2584 allowed_attr[attr->type].display_name);
2586 return attrs;
2589 static attr_list_t *check_field_attrs(const char *name, attr_list_t *attrs)
2591 const attr_t *attr;
2592 if (!attrs) return attrs;
2593 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2595 if (!allowed_attr[attr->type].on_field)
2596 error_loc("inapplicable attribute %s for field %s\n",
2597 allowed_attr[attr->type].display_name, name);
2599 return attrs;
2602 static attr_list_t *check_library_attrs(const char *name, attr_list_t *attrs)
2604 const attr_t *attr;
2605 if (!attrs) return attrs;
2606 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2608 if (!allowed_attr[attr->type].on_library)
2609 error_loc("inapplicable attribute %s for library %s\n",
2610 allowed_attr[attr->type].display_name, name);
2612 return attrs;
2615 attr_list_t *check_dispiface_attrs(const char *name, attr_list_t *attrs)
2617 const attr_t *attr;
2618 if (!attrs) return attrs;
2619 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2621 if (!allowed_attr[attr->type].on_dispinterface)
2622 error_loc("inapplicable attribute %s for dispinterface %s\n",
2623 allowed_attr[attr->type].display_name, name);
2625 return attrs;
2628 attr_list_t *check_module_attrs(const char *name, attr_list_t *attrs)
2630 const attr_t *attr;
2631 if (!attrs) return attrs;
2632 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2634 if (!allowed_attr[attr->type].on_module)
2635 error_loc("inapplicable attribute %s for module %s\n",
2636 allowed_attr[attr->type].display_name, name);
2638 return attrs;
2641 attr_list_t *check_coclass_attrs(const char *name, attr_list_t *attrs)
2643 const attr_t *attr;
2644 if (!attrs) return attrs;
2645 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2647 if (!allowed_attr[attr->type].on_coclass)
2648 error_loc("inapplicable attribute %s for coclass %s\n",
2649 allowed_attr[attr->type].display_name, name);
2651 return attrs;
2654 attr_list_t *check_runtimeclass_attrs(const char *name, attr_list_t *attrs)
2656 const attr_t *attr;
2657 if (!attrs) return attrs;
2658 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2659 if (!allowed_attr[attr->type].on_runtimeclass)
2660 error_loc("inapplicable attribute %s for runtimeclass %s\n",
2661 allowed_attr[attr->type].display_name, name);
2662 return attrs;
2665 attr_list_t *check_apicontract_attrs(const char *name, attr_list_t *attrs)
2667 const attr_t *attr;
2668 if (!attrs) return attrs;
2669 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2670 if (!allowed_attr[attr->type].on_apicontract)
2671 error_loc("inapplicable attribute %s for apicontract %s\n",
2672 allowed_attr[attr->type].display_name, name);
2673 return attrs;
2676 static int is_allowed_conf_type(const type_t *type)
2678 switch (type_get_type(type))
2680 case TYPE_ENUM:
2681 return TRUE;
2682 case TYPE_BASIC:
2683 switch (type_basic_get_type(type))
2685 case TYPE_BASIC_INT8:
2686 case TYPE_BASIC_INT16:
2687 case TYPE_BASIC_INT32:
2688 case TYPE_BASIC_INT64:
2689 case TYPE_BASIC_INT:
2690 case TYPE_BASIC_LONG:
2691 case TYPE_BASIC_CHAR:
2692 case TYPE_BASIC_HYPER:
2693 case TYPE_BASIC_BYTE:
2694 case TYPE_BASIC_WCHAR:
2695 return TRUE;
2696 default:
2697 return FALSE;
2699 case TYPE_ALIAS:
2700 /* shouldn't get here because of type_get_type call above */
2701 assert(0);
2702 /* fall through */
2703 case TYPE_STRUCT:
2704 case TYPE_UNION:
2705 case TYPE_ENCAPSULATED_UNION:
2706 case TYPE_ARRAY:
2707 case TYPE_POINTER:
2708 case TYPE_VOID:
2709 case TYPE_MODULE:
2710 case TYPE_COCLASS:
2711 case TYPE_FUNCTION:
2712 case TYPE_INTERFACE:
2713 case TYPE_BITFIELD:
2714 case TYPE_RUNTIMECLASS:
2715 case TYPE_DELEGATE:
2716 return FALSE;
2717 case TYPE_APICONTRACT:
2718 case TYPE_PARAMETERIZED_TYPE:
2719 case TYPE_PARAMETER:
2720 /* not supposed to be here */
2721 assert(0);
2722 break;
2724 return FALSE;
2727 static int is_ptr_guid_type(const type_t *type)
2729 /* first, make sure it is a pointer to something */
2730 if (!is_ptr(type)) return FALSE;
2732 /* second, make sure it is a pointer to something of size sizeof(GUID),
2733 * i.e. 16 bytes */
2734 return (type_memsize(type_pointer_get_ref_type(type)) == 16);
2737 static void check_conformance_expr_list(const char *attr_name, const var_t *arg, const type_t *container_type, expr_list_t *expr_list)
2739 expr_t *dim;
2740 struct expr_loc expr_loc;
2741 expr_loc.v = arg;
2742 expr_loc.attr = attr_name;
2743 if (expr_list) LIST_FOR_EACH_ENTRY(dim, expr_list, expr_t, entry)
2745 if (dim->type != EXPR_VOID)
2747 const type_t *expr_type = expr_resolve_type(&expr_loc, container_type, dim);
2748 if (!is_allowed_conf_type(expr_type))
2749 error_loc_info(&arg->loc_info, "expression must resolve to integral type <= 32bits for attribute %s\n",
2750 attr_name);
2755 static void check_remoting_fields(const var_t *var, type_t *type);
2757 /* checks that properties common to fields and arguments are consistent */
2758 static void check_field_common(const type_t *container_type,
2759 const char *container_name, const var_t *arg)
2761 type_t *type = arg->declspec.type;
2762 int more_to_do;
2763 const char *container_type_name;
2764 const char *var_type;
2766 switch (type_get_type(container_type))
2768 case TYPE_STRUCT:
2769 container_type_name = "struct";
2770 var_type = "field";
2771 break;
2772 case TYPE_UNION:
2773 container_type_name = "union";
2774 var_type = "arm";
2775 break;
2776 case TYPE_ENCAPSULATED_UNION:
2777 container_type_name = "encapsulated union";
2778 var_type = "arm";
2779 break;
2780 case TYPE_FUNCTION:
2781 container_type_name = "function";
2782 var_type = "parameter";
2783 break;
2784 default:
2785 /* should be no other container types */
2786 assert(0);
2787 return;
2790 if (is_attr(arg->attrs, ATTR_LENGTHIS) &&
2791 (is_attr(arg->attrs, ATTR_STRING) || is_aliaschain_attr(arg->declspec.type, ATTR_STRING)))
2792 error_loc_info(&arg->loc_info,
2793 "string and length_is specified for argument %s are mutually exclusive attributes\n",
2794 arg->name);
2796 if (is_attr(arg->attrs, ATTR_SIZEIS))
2798 expr_list_t *size_is_exprs = get_attrp(arg->attrs, ATTR_SIZEIS);
2799 check_conformance_expr_list("size_is", arg, container_type, size_is_exprs);
2801 if (is_attr(arg->attrs, ATTR_LENGTHIS))
2803 expr_list_t *length_is_exprs = get_attrp(arg->attrs, ATTR_LENGTHIS);
2804 check_conformance_expr_list("length_is", arg, container_type, length_is_exprs);
2806 if (is_attr(arg->attrs, ATTR_IIDIS))
2808 struct expr_loc expr_loc;
2809 expr_t *expr = get_attrp(arg->attrs, ATTR_IIDIS);
2810 if (expr->type != EXPR_VOID)
2812 const type_t *expr_type;
2813 expr_loc.v = arg;
2814 expr_loc.attr = "iid_is";
2815 expr_type = expr_resolve_type(&expr_loc, container_type, expr);
2816 if (!expr_type || !is_ptr_guid_type(expr_type))
2817 error_loc_info(&arg->loc_info, "expression must resolve to pointer to GUID type for attribute iid_is\n");
2820 if (is_attr(arg->attrs, ATTR_SWITCHIS))
2822 struct expr_loc expr_loc;
2823 expr_t *expr = get_attrp(arg->attrs, ATTR_SWITCHIS);
2824 if (expr->type != EXPR_VOID)
2826 const type_t *expr_type;
2827 expr_loc.v = arg;
2828 expr_loc.attr = "switch_is";
2829 expr_type = expr_resolve_type(&expr_loc, container_type, expr);
2830 if (!expr_type || !is_allowed_conf_type(expr_type))
2831 error_loc_info(&arg->loc_info, "expression must resolve to integral type <= 32bits for attribute %s\n",
2832 expr_loc.attr);
2838 more_to_do = FALSE;
2840 switch (typegen_detect_type(type, arg->attrs, TDT_IGNORE_STRINGS))
2842 case TGT_STRUCT:
2843 case TGT_UNION:
2844 check_remoting_fields(arg, type);
2845 break;
2846 case TGT_INVALID:
2848 const char *reason = "is invalid";
2849 switch (type_get_type(type))
2851 case TYPE_VOID:
2852 reason = "cannot derive from void *";
2853 break;
2854 case TYPE_FUNCTION:
2855 reason = "cannot be a function pointer";
2856 break;
2857 case TYPE_BITFIELD:
2858 reason = "cannot be a bit-field";
2859 break;
2860 case TYPE_COCLASS:
2861 reason = "cannot be a class";
2862 break;
2863 case TYPE_INTERFACE:
2864 reason = "cannot be a non-pointer to an interface";
2865 break;
2866 case TYPE_MODULE:
2867 reason = "cannot be a module";
2868 break;
2869 default:
2870 break;
2872 error_loc_info(&arg->loc_info, "%s \'%s\' of %s \'%s\' %s\n",
2873 var_type, arg->name, container_type_name, container_name, reason);
2874 break;
2876 case TGT_CTXT_HANDLE:
2877 case TGT_CTXT_HANDLE_POINTER:
2878 if (type_get_type(container_type) != TYPE_FUNCTION)
2879 error_loc_info(&arg->loc_info,
2880 "%s \'%s\' of %s \'%s\' cannot be a context handle\n",
2881 var_type, arg->name, container_type_name,
2882 container_name);
2883 break;
2884 case TGT_STRING:
2886 const type_t *t = type;
2887 while (is_ptr(t))
2888 t = type_pointer_get_ref_type(t);
2889 if (is_aliaschain_attr(t, ATTR_RANGE))
2890 warning_loc_info(&arg->loc_info, "%s: range not verified for a string of ranged types\n", arg->name);
2891 break;
2893 case TGT_POINTER:
2894 type = type_pointer_get_ref_type(type);
2895 more_to_do = TRUE;
2896 break;
2897 case TGT_ARRAY:
2898 type = type_array_get_element_type(type);
2899 more_to_do = TRUE;
2900 break;
2901 case TGT_ENUM:
2902 type = type_get_real_type(type);
2903 if (!type_is_complete(type))
2905 error_loc_info(&arg->loc_info, "undefined type declaration \"enum %s\"\n", type->name);
2907 case TGT_USER_TYPE:
2908 case TGT_IFACE_POINTER:
2909 case TGT_BASIC:
2910 case TGT_RANGE:
2911 /* nothing to do */
2912 break;
2914 } while (more_to_do);
2917 static void check_remoting_fields(const var_t *var, type_t *type)
2919 const var_t *field;
2920 const var_list_t *fields = NULL;
2922 type = type_get_real_type(type);
2924 if (type->checked)
2925 return;
2927 type->checked = TRUE;
2929 if (type_get_type(type) == TYPE_STRUCT)
2931 if (type_is_complete(type))
2932 fields = type_struct_get_fields(type);
2933 else
2934 error_loc_info(&var->loc_info, "undefined type declaration \"struct %s\"\n", type->name);
2936 else if (type_get_type(type) == TYPE_UNION || type_get_type(type) == TYPE_ENCAPSULATED_UNION)
2938 if (type_is_complete(type))
2939 fields = type_union_get_cases(type);
2940 else
2941 error_loc_info(&var->loc_info, "undefined type declaration \"union %s\"\n", type->name);
2944 if (fields) LIST_FOR_EACH_ENTRY( field, fields, const var_t, entry )
2945 if (field->declspec.type) check_field_common(type, type->name, field);
2948 /* checks that arguments for a function make sense for marshalling and unmarshalling */
2949 static void check_remoting_args(const var_t *func)
2951 const char *funcname = func->name;
2952 const var_t *arg;
2954 if (!type_function_get_args(func->declspec.type))
2955 return;
2957 LIST_FOR_EACH_ENTRY( arg, type_function_get_args(func->declspec.type), const var_t, entry )
2959 const type_t *type = arg->declspec.type;
2961 /* check that [out] parameters have enough pointer levels */
2962 if (is_attr(arg->attrs, ATTR_OUT))
2964 switch (typegen_detect_type(type, arg->attrs, TDT_ALL_TYPES))
2966 case TGT_BASIC:
2967 case TGT_ENUM:
2968 case TGT_RANGE:
2969 case TGT_STRUCT:
2970 case TGT_UNION:
2971 case TGT_CTXT_HANDLE:
2972 case TGT_USER_TYPE:
2973 error_loc_info(&arg->loc_info, "out parameter \'%s\' of function \'%s\' is not a pointer\n", arg->name, funcname);
2974 break;
2975 case TGT_IFACE_POINTER:
2976 error_loc_info(&arg->loc_info, "out interface pointer \'%s\' of function \'%s\' is not a double pointer\n", arg->name, funcname);
2977 break;
2978 case TGT_STRING:
2979 if (is_array(type))
2981 /* needs conformance or fixed dimension */
2982 if (type_array_has_conformance(type) &&
2983 type_array_get_conformance(type)->type != EXPR_VOID) break;
2984 if (!type_array_has_conformance(type) && type_array_get_dim(type)) break;
2986 if (is_attr( arg->attrs, ATTR_IN )) break;
2987 error_loc_info(&arg->loc_info, "out parameter \'%s\' of function \'%s\' cannot be an unsized string\n", arg->name, funcname);
2988 break;
2989 case TGT_INVALID:
2990 /* already error'd before we get here */
2991 case TGT_CTXT_HANDLE_POINTER:
2992 case TGT_POINTER:
2993 case TGT_ARRAY:
2994 /* OK */
2995 break;
2999 check_field_common(func->declspec.type, funcname, arg);
3002 if (type_get_type(type_function_get_rettype(func->declspec.type)) != TYPE_VOID)
3004 var_t var;
3005 var = *func;
3006 var.declspec.type = type_function_get_rettype(func->declspec.type);
3007 var.name = xstrdup("return value");
3008 check_field_common(func->declspec.type, funcname, &var);
3009 free(var.name);
3013 static void add_explicit_handle_if_necessary(const type_t *iface, var_t *func)
3015 unsigned char explicit_fc, implicit_fc;
3017 /* check for a defined binding handle */
3018 if (!get_func_handle_var( iface, func, &explicit_fc, &implicit_fc ) || !explicit_fc)
3020 /* no explicit handle specified so add
3021 * "[in] handle_t IDL_handle" as the first parameter to the
3022 * function */
3023 var_t *idl_handle = make_var(xstrdup("IDL_handle"));
3024 idl_handle->attrs = append_attr(NULL, make_attr(ATTR_IN));
3025 idl_handle->declspec.type = find_type_or_error(NULL, "handle_t");
3026 type_function_add_head_arg(func->declspec.type, idl_handle);
3030 static void check_functions(const type_t *iface, int is_inside_library)
3032 const statement_t *stmt;
3033 /* check for duplicates */
3034 if (is_attr(iface->attrs, ATTR_DISPINTERFACE))
3036 var_list_t *methods = type_dispiface_get_methods(iface);
3037 var_t *func, *func_iter;
3039 if (methods) LIST_FOR_EACH_ENTRY( func, methods, var_t, entry )
3041 LIST_FOR_EACH_ENTRY( func_iter, methods, var_t, entry )
3043 if (func == func_iter) break;
3044 if (strcmp(func->name, func_iter->name)) continue;
3045 if (is_attr(func->attrs, ATTR_EVENTADD) != is_attr(func_iter->attrs, ATTR_EVENTADD)) continue;
3046 if (is_attr(func->attrs, ATTR_EVENTREMOVE) != is_attr(func_iter->attrs, ATTR_EVENTREMOVE)) continue;
3047 if (is_attr(func->attrs, ATTR_PROPGET) != is_attr(func_iter->attrs, ATTR_PROPGET)) continue;
3048 if (is_attr(func->attrs, ATTR_PROPPUT) != is_attr(func_iter->attrs, ATTR_PROPPUT)) continue;
3049 if (is_attr(func->attrs, ATTR_PROPPUTREF) != is_attr(func_iter->attrs, ATTR_PROPPUTREF)) continue;
3050 error_loc_info(&func->loc_info, "duplicated function \'%s\'\n", func->name);
3054 if (is_attr(iface->attrs, ATTR_EXPLICIT_HANDLE))
3056 STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
3058 var_t *func = stmt->u.var;
3059 add_explicit_handle_if_necessary(iface, func);
3062 if (!is_inside_library && !is_attr(iface->attrs, ATTR_LOCAL))
3064 STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
3066 const var_t *func = stmt->u.var;
3067 if (!is_attr(func->attrs, ATTR_LOCAL))
3068 check_remoting_args(func);
3073 static int async_iface_attrs(attr_list_t *attrs, const attr_t *attr)
3075 switch(attr->type)
3077 case ATTR_UUID:
3078 return 0;
3079 case ATTR_ASYNCUUID:
3080 append_attr(attrs, make_attrp(ATTR_UUID, attr->u.pval));
3081 return 0;
3082 default:
3083 return 1;
3087 static int arg_in_attrs(attr_list_t *attrs, const attr_t *attr)
3089 return attr->type != ATTR_OUT && attr->type != ATTR_RETVAL;
3092 static int arg_out_attrs(attr_list_t *attrs, const attr_t *attr)
3094 return attr->type != ATTR_IN;
3097 static void check_async_uuid(type_t *iface)
3099 statement_list_t *stmts = NULL;
3100 statement_t *stmt;
3101 type_t *async_iface;
3102 type_t *inherit;
3104 if (!is_attr(iface->attrs, ATTR_ASYNCUUID)) return;
3106 inherit = type_iface_get_inherit(iface);
3107 if (inherit && strcmp(inherit->name, "IUnknown"))
3108 inherit = type_iface_get_async_iface(inherit);
3109 if (!inherit)
3110 error_loc("async_uuid applied to an interface with incompatible parent\n");
3112 async_iface = type_interface_declare(strmake("Async%s", iface->name), iface->namespace);
3114 STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
3116 var_t *begin_func, *finish_func, *func = stmt->u.var, *arg;
3117 var_list_t *begin_args = NULL, *finish_args = NULL, *args;
3119 if (is_attr(func->attrs, ATTR_CALLAS)) continue;
3121 args = type_function_get_args(func->declspec.type);
3122 if (args) LIST_FOR_EACH_ENTRY(arg, args, var_t, entry)
3124 if (is_attr(arg->attrs, ATTR_IN) || !is_attr(arg->attrs, ATTR_OUT))
3125 begin_args = append_var(begin_args, copy_var(arg, xstrdup(arg->name), arg_in_attrs));
3126 if (is_attr(arg->attrs, ATTR_OUT))
3127 finish_args = append_var(finish_args, copy_var(arg, xstrdup(arg->name), arg_out_attrs));
3130 begin_func = copy_var(func, strmake("Begin_%s", func->name), NULL);
3131 begin_func->declspec.type = type_new_function(begin_args);
3132 begin_func->declspec.type->attrs = func->attrs;
3133 begin_func->declspec.type->details.function->retval = func->declspec.type->details.function->retval;
3134 stmts = append_statement(stmts, make_statement_declaration(begin_func));
3136 finish_func = copy_var(func, strmake("Finish_%s", func->name), NULL);
3137 finish_func->declspec.type = type_new_function(finish_args);
3138 finish_func->declspec.type->attrs = func->attrs;
3139 finish_func->declspec.type->details.function->retval = func->declspec.type->details.function->retval;
3140 stmts = append_statement(stmts, make_statement_declaration(finish_func));
3143 type_interface_define(async_iface, map_attrs(iface->attrs, async_iface_attrs), inherit, stmts, NULL);
3144 iface->details.iface->async_iface = async_iface->details.iface->async_iface = async_iface;
3147 static statement_list_t *append_parameterized_type_stmts(statement_list_t *stmts)
3149 statement_t *stmt, *next;
3151 if (stmts && parameterized_type_stmts) LIST_FOR_EACH_ENTRY_SAFE(stmt, next, parameterized_type_stmts, statement_t, entry)
3153 switch(stmt->type)
3155 case STMT_TYPE:
3156 stmt->u.type = type_parameterized_type_specialize_define(stmt->u.type);
3157 stmt->declonly = FALSE;
3158 list_remove(&stmt->entry);
3159 stmts = append_statement(stmts, stmt);
3160 break;
3161 default:
3162 assert(0); /* should not be there */
3163 break;
3167 return stmts;
3170 static void check_statements(const statement_list_t *stmts, int is_inside_library)
3172 const statement_t *stmt;
3174 if (stmts) LIST_FOR_EACH_ENTRY(stmt, stmts, const statement_t, entry)
3176 switch(stmt->type) {
3177 case STMT_LIBRARY:
3178 check_statements(stmt->u.lib->stmts, TRUE);
3179 break;
3180 case STMT_TYPE:
3181 switch(type_get_type(stmt->u.type)) {
3182 case TYPE_INTERFACE:
3183 check_functions(stmt->u.type, is_inside_library);
3184 break;
3185 case TYPE_COCLASS:
3186 if(winrt_mode)
3187 error_loc("coclass is not allowed in Windows Runtime mode\n");
3188 break;
3189 default:
3190 break;
3192 break;
3193 default:
3194 break;
3199 static void check_all_user_types(const statement_list_t *stmts)
3201 const statement_t *stmt;
3202 const var_t *v;
3204 if (stmts) LIST_FOR_EACH_ENTRY(stmt, stmts, const statement_t, entry)
3206 if (stmt->type == STMT_LIBRARY)
3207 check_all_user_types(stmt->u.lib->stmts);
3208 else if (stmt->type == STMT_TYPE && type_get_type(stmt->u.type) == TYPE_INTERFACE &&
3209 !is_local(stmt->u.type->attrs))
3211 const statement_t *stmt_func;
3212 STATEMENTS_FOR_EACH_FUNC(stmt_func, type_iface_get_stmts(stmt->u.type)) {
3213 const var_t *func = stmt_func->u.var;
3214 if (type_function_get_args(func->declspec.type))
3215 LIST_FOR_EACH_ENTRY( v, type_function_get_args(func->declspec.type), const var_t, entry )
3216 check_for_additional_prototype_types(v->declspec.type);
3217 check_for_additional_prototype_types(type_function_get_rettype(func->declspec.type));
3223 int is_valid_uuid(const char *s)
3225 int i;
3227 for (i = 0; i < 36; ++i)
3228 if (i == 8 || i == 13 || i == 18 || i == 23)
3230 if (s[i] != '-')
3231 return FALSE;
3233 else
3234 if (!isxdigit(s[i]))
3235 return FALSE;
3237 return s[i] == '\0';
3240 static statement_t *make_statement(enum statement_type type)
3242 statement_t *stmt = xmalloc(sizeof(*stmt));
3243 stmt->type = type;
3244 return stmt;
3247 static statement_t *make_statement_type_decl(type_t *type)
3249 statement_t *stmt = make_statement(STMT_TYPE);
3250 stmt->u.type = type;
3251 stmt->declonly = !type->defined;
3252 return stmt;
3255 static statement_t *make_statement_reference(type_t *type)
3257 statement_t *stmt = make_statement(STMT_TYPEREF);
3258 stmt->u.type = type;
3259 return stmt;
3262 static statement_t *make_statement_declaration(var_t *var)
3264 statement_t *stmt = make_statement(STMT_DECLARATION);
3265 stmt->u.var = var;
3266 if (var->declspec.stgclass == STG_EXTERN && var->eval)
3267 warning("'%s' initialised and declared extern\n", var->name);
3268 if (is_const_decl(var))
3270 if (var->eval)
3271 reg_const(var);
3273 else if (type_get_type(var->declspec.type) == TYPE_FUNCTION)
3274 check_function_attrs(var->name, var->attrs);
3275 else if (var->declspec.stgclass == STG_NONE || var->declspec.stgclass == STG_REGISTER)
3276 error_loc("instantiation of data is illegal\n");
3277 return stmt;
3280 static statement_t *make_statement_library(typelib_t *typelib)
3282 statement_t *stmt = make_statement(STMT_LIBRARY);
3283 stmt->u.lib = typelib;
3284 return stmt;
3287 static statement_t *make_statement_pragma(const char *str)
3289 statement_t *stmt = make_statement(STMT_PRAGMA);
3290 stmt->u.str = str;
3291 return stmt;
3294 static statement_t *make_statement_cppquote(const char *str)
3296 statement_t *stmt = make_statement(STMT_CPPQUOTE);
3297 stmt->u.str = str;
3298 return stmt;
3301 static statement_t *make_statement_importlib(const char *str)
3303 statement_t *stmt = make_statement(STMT_IMPORTLIB);
3304 stmt->u.str = str;
3305 return stmt;
3308 static statement_t *make_statement_import(const char *str)
3310 statement_t *stmt = make_statement(STMT_IMPORT);
3311 stmt->u.str = str;
3312 return stmt;
3315 static statement_t *make_statement_module(type_t *type)
3317 statement_t *stmt = make_statement(STMT_MODULE);
3318 stmt->u.type = type;
3319 return stmt;
3322 static statement_t *make_statement_typedef(declarator_list_t *decls, int declonly)
3324 declarator_t *decl, *next;
3325 statement_t *stmt;
3327 if (!decls) return NULL;
3329 stmt = make_statement(STMT_TYPEDEF);
3330 stmt->u.type_list = NULL;
3331 stmt->declonly = declonly;
3333 LIST_FOR_EACH_ENTRY_SAFE( decl, next, decls, declarator_t, entry )
3335 var_t *var = decl->var;
3336 type_t *type = find_type_or_error(current_namespace, var->name);
3337 stmt->u.type_list = append_typeref(stmt->u.type_list, make_typeref(type));
3338 free(decl);
3339 free(var);
3342 return stmt;
3345 static statement_t *make_statement_parameterized_type(type_t *type, typeref_list_t *params)
3347 statement_t *stmt = make_statement(STMT_TYPE);
3348 stmt->u.type = type_parameterized_type_specialize_partial(type, params);
3349 return stmt;
3352 static statement_t *make_statement_delegate(type_t *ret, var_list_t *args)
3354 declarator_t *decl = make_declarator(make_var(xstrdup("Invoke")));
3355 decl_spec_t *spec = make_decl_spec(ret, NULL, NULL, STG_NONE, 0, 0);
3356 append_chain_type(decl, type_new_function(args), 0);
3357 return make_statement_declaration(declare_var(NULL, spec, decl, FALSE));
3360 static statement_list_t *append_statements(statement_list_t *l1, statement_list_t *l2)
3362 if (!l2) return l1;
3363 if (!l1 || l1 == l2) return l2;
3364 list_move_tail (l1, l2);
3365 return l1;
3368 static attr_list_t *append_attribs(attr_list_t *l1, attr_list_t *l2)
3370 if (!l2) return l1;
3371 if (!l1 || l1 == l2) return l2;
3372 list_move_tail (l1, l2);
3373 return l1;
3376 static statement_list_t *append_statement(statement_list_t *list, statement_t *stmt)
3378 if (!stmt) return list;
3379 if (!list)
3381 list = xmalloc( sizeof(*list) );
3382 list_init( list );
3384 list_add_tail( list, &stmt->entry );
3385 return list;
3388 void init_loc_info(loc_info_t *i)
3390 i->input_name = input_name ? input_name : "stdin";
3391 i->line_number = line_number;
3392 i->near_text = parser_text;
3395 type_t *find_parameterized_type(type_t *type, typeref_list_t *params)
3397 char *name = format_parameterized_type_name(type, params);
3399 if (parameters_namespace)
3401 assert(type->type_type == TYPE_PARAMETERIZED_TYPE);
3402 type = type_parameterized_type_specialize_partial(type, params);
3404 else if ((type = find_type(name, type->namespace, 0)))
3405 assert(type->type_type != TYPE_PARAMETERIZED_TYPE);
3406 else
3407 error_loc("parameterized type '%s' not declared\n", name);
3409 free(name);
3410 return type;