widl: Add async_uuid attribute base support in parser.
[wine.git] / tools / widl / parser.y
blob5751598d291e7fa7a699c927f666b0219ed1a8ff
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 static unsigned char pointer_default = RPC_FC_UP;
43 typedef struct list typelist_t;
44 struct typenode {
45 type_t *type;
46 struct list entry;
49 struct _import_t
51 char *name;
52 int import_performed;
55 typedef struct _decl_spec_t
57 type_t *type;
58 attr_list_t *attrs;
59 enum storage_class stgclass;
60 } decl_spec_t;
62 typelist_t incomplete_types = LIST_INIT(incomplete_types);
64 static void fix_incomplete(void);
65 static void fix_incomplete_types(type_t *complete_type);
67 static str_list_t *append_str(str_list_t *list, char *str);
68 static attr_list_t *append_attr(attr_list_t *list, attr_t *attr);
69 static attr_list_t *append_attr_list(attr_list_t *new_list, attr_list_t *old_list);
70 static decl_spec_t *make_decl_spec(type_t *type, decl_spec_t *left, decl_spec_t *right, attr_t *attr, enum storage_class stgclass);
71 static attr_t *make_attr(enum attr_type type);
72 static attr_t *make_attrv(enum attr_type type, unsigned int val);
73 static attr_t *make_attrp(enum attr_type type, void *val);
74 static expr_list_t *append_expr(expr_list_t *list, expr_t *expr);
75 static array_dims_t *append_array(array_dims_t *list, expr_t *expr);
76 static var_t *declare_var(attr_list_t *attrs, decl_spec_t *decl_spec, const declarator_t *decl, int top);
77 static var_list_t *set_var_types(attr_list_t *attrs, decl_spec_t *decl_spec, declarator_list_t *decls);
78 static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface);
79 static ifref_t *make_ifref(type_t *iface);
80 static var_list_t *append_var_list(var_list_t *list, var_list_t *vars);
81 static declarator_list_t *append_declarator(declarator_list_t *list, declarator_t *p);
82 static declarator_t *make_declarator(var_t *var);
83 static type_t *make_safearray(type_t *type);
84 static typelib_t *make_library(const char *name, const attr_list_t *attrs);
85 static type_t *append_ptrchain_type(type_t *ptrchain, type_t *type);
87 static type_t *reg_typedefs(decl_spec_t *decl_spec, var_list_t *names, attr_list_t *attrs);
88 static type_t *find_type_or_error(const char *name, int t);
89 static type_t *find_type_or_error2(char *name, int t);
91 static var_t *reg_const(var_t *var);
93 static char *gen_name(void);
94 static void check_arg_attrs(const var_t *arg);
95 static void check_statements(const statement_list_t *stmts, int is_inside_library);
96 static void check_all_user_types(const statement_list_t *stmts);
97 static attr_list_t *check_iface_attrs(const char *name, attr_list_t *attrs);
98 static attr_list_t *check_function_attrs(const char *name, attr_list_t *attrs);
99 static attr_list_t *check_typedef_attrs(attr_list_t *attrs);
100 static attr_list_t *check_enum_attrs(attr_list_t *attrs);
101 static attr_list_t *check_struct_attrs(attr_list_t *attrs);
102 static attr_list_t *check_union_attrs(attr_list_t *attrs);
103 static attr_list_t *check_field_attrs(const char *name, attr_list_t *attrs);
104 static attr_list_t *check_library_attrs(const char *name, attr_list_t *attrs);
105 static attr_list_t *check_dispiface_attrs(const char *name, attr_list_t *attrs);
106 static attr_list_t *check_module_attrs(const char *name, attr_list_t *attrs);
107 static attr_list_t *check_coclass_attrs(const char *name, attr_list_t *attrs);
108 const char *get_attr_display_name(enum attr_type type);
109 static void add_explicit_handle_if_necessary(const type_t *iface, var_t *func);
110 static void check_def(const type_t *t);
112 static statement_t *make_statement(enum statement_type type);
113 static statement_t *make_statement_type_decl(type_t *type);
114 static statement_t *make_statement_reference(type_t *type);
115 static statement_t *make_statement_declaration(var_t *var);
116 static statement_t *make_statement_library(typelib_t *typelib);
117 static statement_t *make_statement_cppquote(const char *str);
118 static statement_t *make_statement_importlib(const char *str);
119 static statement_t *make_statement_module(type_t *type);
120 static statement_t *make_statement_typedef(var_list_t *names);
121 static statement_t *make_statement_import(const char *str);
122 static statement_t *make_statement_typedef(var_list_t *names);
123 static statement_list_t *append_statement(statement_list_t *list, statement_t *stmt);
124 static statement_list_t *append_statements(statement_list_t *, statement_list_t *);
125 static attr_list_t *append_attribs(attr_list_t *, attr_list_t *);
128 %union {
129 attr_t *attr;
130 attr_list_t *attr_list;
131 str_list_t *str_list;
132 expr_t *expr;
133 expr_list_t *expr_list;
134 array_dims_t *array_dims;
135 type_t *type;
136 var_t *var;
137 var_list_t *var_list;
138 declarator_t *declarator;
139 declarator_list_t *declarator_list;
140 statement_t *statement;
141 statement_list_t *stmt_list;
142 ifref_t *ifref;
143 ifref_list_t *ifref_list;
144 char *str;
145 UUID *uuid;
146 unsigned int num;
147 double dbl;
148 interface_info_t ifinfo;
149 typelib_t *typelib;
150 struct _import_t *import;
151 struct _decl_spec_t *declspec;
152 enum storage_class stgclass;
155 %token <str> aIDENTIFIER
156 %token <str> aKNOWNTYPE
157 %token <num> aNUM aHEXNUM
158 %token <dbl> aDOUBLE
159 %token <str> aSTRING aWSTRING aSQSTRING
160 %token <uuid> aUUID
161 %token aEOF
162 %token SHL SHR
163 %token MEMBERPTR
164 %token EQUALITY INEQUALITY
165 %token GREATEREQUAL LESSEQUAL
166 %token LOGICALOR LOGICALAND
167 %token ELLIPSIS
168 %token tAGGREGATABLE tALLOCATE tANNOTATION tAPPOBJECT tASYNC tASYNCUUID
169 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
170 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
171 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
172 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
173 %token tDECODE tDEFAULT tDEFAULTBIND
174 %token tDEFAULTCOLLELEM
175 %token tDEFAULTVALUE
176 %token tDEFAULTVTABLE
177 %token tDISABLECONSISTENCYCHECK tDISPLAYBIND
178 %token tDISPINTERFACE
179 %token tDLLNAME tDOUBLE tDUAL
180 %token tENABLEALLOCATE tENCODE tENDPOINT
181 %token tENTRY tENUM tERRORSTATUST
182 %token tEXPLICITHANDLE tEXTERN
183 %token tFALSE
184 %token tFASTCALL tFAULTSTATUS
185 %token tFLOAT tFORCEALLOCATE
186 %token tHANDLE
187 %token tHANDLET
188 %token tHELPCONTEXT tHELPFILE
189 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
190 %token tHIDDEN
191 %token tHYPER tID tIDEMPOTENT
192 %token tIGNORE tIIDIS
193 %token tIMMEDIATEBIND
194 %token tIMPLICITHANDLE
195 %token tIMPORT tIMPORTLIB
196 %token tIN tIN_LINE tINLINE
197 %token tINPUTSYNC
198 %token tINT tINT3264 tINT64
199 %token tINTERFACE
200 %token tLCID
201 %token tLENGTHIS tLIBRARY
202 %token tLICENSED tLOCAL
203 %token tLONG
204 %token tMAYBE tMESSAGE
205 %token tMETHODS
206 %token tMODULE
207 %token tNAMESPACE
208 %token tNOCODE tNONBROWSABLE
209 %token tNONCREATABLE
210 %token tNONEXTENSIBLE
211 %token tNOTIFY tNOTIFYFLAG
212 %token tNULL
213 %token tOBJECT tODL tOLEAUTOMATION
214 %token tOPTIMIZE tOPTIONAL
215 %token tOUT
216 %token tPARTIALIGNORE tPASCAL
217 %token tPOINTERDEFAULT
218 %token tPROGID tPROPERTIES
219 %token tPROPGET tPROPPUT tPROPPUTREF
220 %token tPROXY tPTR
221 %token tPUBLIC
222 %token tRANGE
223 %token tREADONLY tREF
224 %token tREGISTER tREPRESENTAS
225 %token tREQUESTEDIT
226 %token tRESTRICTED
227 %token tRETVAL
228 %token tSAFEARRAY
229 %token tSHORT
230 %token tSIGNED
231 %token tSIZEIS tSIZEOF
232 %token tSMALL
233 %token tSOURCE
234 %token tSTATIC
235 %token tSTDCALL
236 %token tSTRICTCONTEXTHANDLE
237 %token tSTRING tSTRUCT
238 %token tSWITCH tSWITCHIS tSWITCHTYPE
239 %token tTHREADING tTRANSMITAS
240 %token tTRUE
241 %token tTYPEDEF
242 %token tUIDEFAULT tUNION
243 %token tUNIQUE
244 %token tUNSIGNED
245 %token tUSESGETLASTERROR tUSERMARSHAL tUUID
246 %token tV1ENUM
247 %token tVARARG
248 %token tVERSION tVIPROGID
249 %token tVOID
250 %token tWCHAR tWIREMARSHAL
251 %token tAPARTMENT tNEUTRAL tSINGLE tFREE tBOTH
253 %type <attr> attribute type_qualifier function_specifier
254 %type <attr_list> m_attributes attributes attrib_list m_type_qual_list
255 %type <str_list> str_list
256 %type <expr> m_expr expr expr_const expr_int_const array m_bitfield
257 %type <expr_list> m_exprs /* exprs expr_list */ expr_list_int_const
258 %type <ifinfo> interfacehdr
259 %type <stgclass> storage_cls_spec
260 %type <declspec> decl_spec decl_spec_no_type m_decl_spec_no_type
261 %type <type> inherit interface interfacedef interfacedec
262 %type <type> dispinterface dispinterfacehdr dispinterfacedef
263 %type <type> module modulehdr moduledef
264 %type <type> namespacedef
265 %type <type> base_type int_std
266 %type <type> enumdef structdef uniondef typedecl
267 %type <type> type
268 %type <ifref> coclass_int
269 %type <ifref_list> coclass_ints
270 %type <var> arg ne_union_field union_field s_field case enum declaration
271 %type <var> funcdef
272 %type <var_list> m_args arg_list args dispint_meths
273 %type <var_list> fields ne_union_fields cases enums enum_list dispint_props field
274 %type <var> m_ident ident
275 %type <declarator> declarator direct_declarator init_declarator struct_declarator
276 %type <declarator> m_any_declarator any_declarator any_declarator_no_direct any_direct_declarator
277 %type <declarator> m_abstract_declarator abstract_declarator abstract_declarator_no_direct abstract_direct_declarator
278 %type <declarator_list> declarator_list struct_declarator_list
279 %type <type> coclass coclasshdr coclassdef
280 %type <num> pointer_type threading_type version
281 %type <str> libraryhdr callconv cppquote importlib import t_ident
282 %type <uuid> uuid_string
283 %type <import> import_start
284 %type <typelib> library_start librarydef
285 %type <statement> statement typedef
286 %type <stmt_list> gbl_statements imp_statements int_statements
288 %left ','
289 %right '?' ':'
290 %left LOGICALOR
291 %left LOGICALAND
292 %left '|'
293 %left '^'
294 %left '&'
295 %left EQUALITY INEQUALITY
296 %left '<' '>' LESSEQUAL GREATEREQUAL
297 %left SHL SHR
298 %left '-' '+'
299 %left '*' '/' '%'
300 %right '!' '~' CAST PPTR POS NEG ADDRESSOF tSIZEOF
301 %left '.' MEMBERPTR '[' ']'
303 %error-verbose
307 input: gbl_statements { fix_incomplete();
308 check_statements($1, FALSE);
309 check_all_user_types($1);
310 write_header($1);
311 write_id_data($1);
312 write_proxies($1);
313 write_client($1);
314 write_server($1);
315 write_regscript($1);
316 write_dlldata($1);
317 write_local_stubs($1);
321 gbl_statements: { $$ = NULL; }
322 | gbl_statements namespacedef '{' gbl_statements '}'
323 { $$ = append_statements($1, $4); }
324 | gbl_statements interfacedec { $$ = append_statement($1, make_statement_reference($2)); }
325 | gbl_statements interfacedef { $$ = append_statement($1, make_statement_type_decl($2)); }
326 | gbl_statements coclass ';' { $$ = $1;
327 reg_type($2, $2->name, 0);
329 | gbl_statements coclassdef { $$ = append_statement($1, make_statement_type_decl($2));
330 reg_type($2, $2->name, 0);
332 | gbl_statements moduledef { $$ = append_statement($1, make_statement_module($2)); }
333 | gbl_statements librarydef { $$ = append_statement($1, make_statement_library($2)); }
334 | gbl_statements statement { $$ = append_statement($1, $2); }
337 imp_statements: { $$ = NULL; }
338 | imp_statements interfacedec { $$ = append_statement($1, make_statement_reference($2)); }
339 | imp_statements namespacedef '{' imp_statements '}'
340 { $$ = append_statements($1, $4); }
341 | imp_statements interfacedef { $$ = append_statement($1, make_statement_type_decl($2)); }
342 | imp_statements coclass ';' { $$ = $1; reg_type($2, $2->name, 0); }
343 | imp_statements coclassdef { $$ = append_statement($1, make_statement_type_decl($2));
344 reg_type($2, $2->name, 0);
346 | imp_statements moduledef { $$ = append_statement($1, make_statement_module($2)); }
347 | imp_statements statement { $$ = append_statement($1, $2); }
348 | imp_statements importlib { $$ = append_statement($1, make_statement_importlib($2)); }
349 | imp_statements librarydef { $$ = append_statement($1, make_statement_library($2)); }
352 int_statements: { $$ = NULL; }
353 | int_statements statement { $$ = append_statement($1, $2); }
356 semicolon_opt:
357 | ';'
360 statement:
361 cppquote { $$ = make_statement_cppquote($1); }
362 | typedecl ';' { $$ = make_statement_type_decl($1); }
363 | declaration ';' { $$ = make_statement_declaration($1); }
364 | import { $$ = make_statement_import($1); }
365 | typedef ';' { $$ = $1; }
368 typedecl:
369 enumdef
370 | tENUM aIDENTIFIER { $$ = type_new_enum($2, FALSE, NULL); }
371 | structdef
372 | tSTRUCT aIDENTIFIER { $$ = type_new_struct($2, FALSE, NULL); }
373 | uniondef
374 | tUNION aIDENTIFIER { $$ = type_new_nonencapsulated_union($2, FALSE, NULL); }
375 | attributes enumdef { $$ = $2; $$->attrs = check_enum_attrs($1); }
376 | attributes structdef { $$ = $2; $$->attrs = check_struct_attrs($1); }
377 | attributes uniondef { $$ = $2; $$->attrs = check_union_attrs($1); }
380 cppquote: tCPPQUOTE '(' aSTRING ')' { $$ = $3; }
382 import_start: tIMPORT aSTRING ';' { assert(yychar == YYEMPTY);
383 $$ = xmalloc(sizeof(struct _import_t));
384 $$->name = $2;
385 $$->import_performed = do_import($2);
386 if (!$$->import_performed) yychar = aEOF;
390 import: import_start imp_statements aEOF { $$ = $1->name;
391 if ($1->import_performed) pop_import();
392 free($1);
396 importlib: tIMPORTLIB '(' aSTRING ')'
397 semicolon_opt { $$ = $3; if(!parse_only) add_importlib($3); }
400 libraryhdr: tLIBRARY aIDENTIFIER { $$ = $2; }
402 library_start: attributes libraryhdr '{' { $$ = make_library($2, check_library_attrs($2, $1));
403 if (!parse_only) start_typelib($$);
406 librarydef: library_start imp_statements '}'
407 semicolon_opt { $$ = $1;
408 $$->stmts = $2;
409 if (!parse_only) end_typelib();
413 m_args: { $$ = NULL; }
414 | args
417 arg_list: arg { check_arg_attrs($1); $$ = append_var( NULL, $1 ); }
418 | arg_list ',' arg { check_arg_attrs($3); $$ = append_var( $1, $3 ); }
421 args: arg_list
422 | arg_list ',' ELLIPSIS { $$ = append_var( $1, make_var(strdup("...")) ); }
425 /* split into two rules to get bison to resolve a tVOID conflict */
426 arg: attributes decl_spec m_any_declarator { if ($2->stgclass != STG_NONE && $2->stgclass != STG_REGISTER)
427 error_loc("invalid storage class for function parameter\n");
428 $$ = declare_var($1, $2, $3, TRUE);
429 free($2); free($3);
431 | decl_spec m_any_declarator { if ($1->stgclass != STG_NONE && $1->stgclass != STG_REGISTER)
432 error_loc("invalid storage class for function parameter\n");
433 $$ = declare_var(NULL, $1, $2, TRUE);
434 free($1); free($2);
438 array: '[' expr ']' { $$ = $2;
439 if (!$$->is_const)
440 error_loc("array dimension is not an integer constant\n");
442 | '[' '*' ']' { $$ = make_expr(EXPR_VOID); }
443 | '[' ']' { $$ = make_expr(EXPR_VOID); }
446 m_attributes: { $$ = NULL; }
447 | attributes
450 attributes:
451 '[' attrib_list ']' { $$ = $2; }
454 attrib_list: attribute { $$ = append_attr( NULL, $1 ); }
455 | attrib_list ',' attribute { $$ = append_attr( $1, $3 ); }
456 | attrib_list ']' '[' attribute { $$ = append_attr( $1, $4 ); }
459 str_list: aSTRING { $$ = append_str( NULL, $1 ); }
460 | str_list ',' aSTRING { $$ = append_str( $1, $3 ); }
463 attribute: { $$ = NULL; }
464 | tAGGREGATABLE { $$ = make_attr(ATTR_AGGREGATABLE); }
465 | tANNOTATION '(' aSTRING ')' { $$ = make_attrp(ATTR_ANNOTATION, $3); }
466 | tAPPOBJECT { $$ = make_attr(ATTR_APPOBJECT); }
467 | tASYNC { $$ = make_attr(ATTR_ASYNC); }
468 | tAUTOHANDLE { $$ = make_attr(ATTR_AUTO_HANDLE); }
469 | tBINDABLE { $$ = make_attr(ATTR_BINDABLE); }
470 | tBROADCAST { $$ = make_attr(ATTR_BROADCAST); }
471 | tCALLAS '(' ident ')' { $$ = make_attrp(ATTR_CALLAS, $3); }
472 | tCASE '(' expr_list_int_const ')' { $$ = make_attrp(ATTR_CASE, $3); }
473 | tCODE { $$ = make_attr(ATTR_CODE); }
474 | tCOMMSTATUS { $$ = make_attr(ATTR_COMMSTATUS); }
475 | tCONTEXTHANDLE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); }
476 | tCONTEXTHANDLENOSERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
477 | tCONTEXTHANDLESERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
478 | tCONTROL { $$ = make_attr(ATTR_CONTROL); }
479 | tDECODE { $$ = make_attr(ATTR_DECODE); }
480 | tDEFAULT { $$ = make_attr(ATTR_DEFAULT); }
481 | tDEFAULTBIND { $$ = make_attr(ATTR_DEFAULTBIND); }
482 | tDEFAULTCOLLELEM { $$ = make_attr(ATTR_DEFAULTCOLLELEM); }
483 | tDEFAULTVALUE '(' expr_const ')' { $$ = make_attrp(ATTR_DEFAULTVALUE, $3); }
484 | tDEFAULTVTABLE { $$ = make_attr(ATTR_DEFAULTVTABLE); }
485 | tDISABLECONSISTENCYCHECK { $$ = make_attr(ATTR_DISABLECONSISTENCYCHECK); }
486 | tDISPLAYBIND { $$ = make_attr(ATTR_DISPLAYBIND); }
487 | tDLLNAME '(' aSTRING ')' { $$ = make_attrp(ATTR_DLLNAME, $3); }
488 | tDUAL { $$ = make_attr(ATTR_DUAL); }
489 | tENABLEALLOCATE { $$ = make_attr(ATTR_ENABLEALLOCATE); }
490 | tENCODE { $$ = make_attr(ATTR_ENCODE); }
491 | tENDPOINT '(' str_list ')' { $$ = make_attrp(ATTR_ENDPOINT, $3); }
492 | tENTRY '(' expr_const ')' { $$ = make_attrp(ATTR_ENTRY, $3); }
493 | tEXPLICITHANDLE { $$ = make_attr(ATTR_EXPLICIT_HANDLE); }
494 | tFAULTSTATUS { $$ = make_attr(ATTR_FAULTSTATUS); }
495 | tFORCEALLOCATE { $$ = make_attr(ATTR_FORCEALLOCATE); }
496 | tHANDLE { $$ = make_attr(ATTR_HANDLE); }
497 | tHELPCONTEXT '(' expr_int_const ')' { $$ = make_attrp(ATTR_HELPCONTEXT, $3); }
498 | tHELPFILE '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPFILE, $3); }
499 | tHELPSTRING '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRING, $3); }
500 | tHELPSTRINGCONTEXT '(' expr_int_const ')' { $$ = make_attrp(ATTR_HELPSTRINGCONTEXT, $3); }
501 | tHELPSTRINGDLL '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRINGDLL, $3); }
502 | tHIDDEN { $$ = make_attr(ATTR_HIDDEN); }
503 | tID '(' expr_int_const ')' { $$ = make_attrp(ATTR_ID, $3); }
504 | tIDEMPOTENT { $$ = make_attr(ATTR_IDEMPOTENT); }
505 | tIGNORE { $$ = make_attr(ATTR_IGNORE); }
506 | tIIDIS '(' expr ')' { $$ = make_attrp(ATTR_IIDIS, $3); }
507 | tIMMEDIATEBIND { $$ = make_attr(ATTR_IMMEDIATEBIND); }
508 | tIMPLICITHANDLE '(' arg ')' { $$ = make_attrp(ATTR_IMPLICIT_HANDLE, $3); }
509 | tIN { $$ = make_attr(ATTR_IN); }
510 | tINPUTSYNC { $$ = make_attr(ATTR_INPUTSYNC); }
511 | tLENGTHIS '(' m_exprs ')' { $$ = make_attrp(ATTR_LENGTHIS, $3); }
512 | tLCID '(' expr_int_const ')' { $$ = make_attrp(ATTR_LIBLCID, $3); }
513 | tLCID { $$ = make_attr(ATTR_PARAMLCID); }
514 | tLICENSED { $$ = make_attr(ATTR_LICENSED); }
515 | tLOCAL { $$ = make_attr(ATTR_LOCAL); }
516 | tMAYBE { $$ = make_attr(ATTR_MAYBE); }
517 | tMESSAGE { $$ = make_attr(ATTR_MESSAGE); }
518 | tNOCODE { $$ = make_attr(ATTR_NOCODE); }
519 | tNONBROWSABLE { $$ = make_attr(ATTR_NONBROWSABLE); }
520 | tNONCREATABLE { $$ = make_attr(ATTR_NONCREATABLE); }
521 | tNONEXTENSIBLE { $$ = make_attr(ATTR_NONEXTENSIBLE); }
522 | tNOTIFY { $$ = make_attr(ATTR_NOTIFY); }
523 | tNOTIFYFLAG { $$ = make_attr(ATTR_NOTIFYFLAG); }
524 | tOBJECT { $$ = make_attr(ATTR_OBJECT); }
525 | tODL { $$ = make_attr(ATTR_ODL); }
526 | tOLEAUTOMATION { $$ = make_attr(ATTR_OLEAUTOMATION); }
527 | tOPTIMIZE '(' aSTRING ')' { $$ = make_attrp(ATTR_OPTIMIZE, $3); }
528 | tOPTIONAL { $$ = make_attr(ATTR_OPTIONAL); }
529 | tOUT { $$ = make_attr(ATTR_OUT); }
530 | tPARTIALIGNORE { $$ = make_attr(ATTR_PARTIALIGNORE); }
531 | tPOINTERDEFAULT '(' pointer_type ')' { $$ = make_attrv(ATTR_POINTERDEFAULT, $3); }
532 | tPROGID '(' aSTRING ')' { $$ = make_attrp(ATTR_PROGID, $3); }
533 | tPROPGET { $$ = make_attr(ATTR_PROPGET); }
534 | tPROPPUT { $$ = make_attr(ATTR_PROPPUT); }
535 | tPROPPUTREF { $$ = make_attr(ATTR_PROPPUTREF); }
536 | tPROXY { $$ = make_attr(ATTR_PROXY); }
537 | tPUBLIC { $$ = make_attr(ATTR_PUBLIC); }
538 | tRANGE '(' expr_int_const ',' expr_int_const ')'
539 { expr_list_t *list = append_expr( NULL, $3 );
540 list = append_expr( list, $5 );
541 $$ = make_attrp(ATTR_RANGE, list); }
542 | tREADONLY { $$ = make_attr(ATTR_READONLY); }
543 | tREPRESENTAS '(' type ')' { $$ = make_attrp(ATTR_REPRESENTAS, $3); }
544 | tREQUESTEDIT { $$ = make_attr(ATTR_REQUESTEDIT); }
545 | tRESTRICTED { $$ = make_attr(ATTR_RESTRICTED); }
546 | tRETVAL { $$ = make_attr(ATTR_RETVAL); }
547 | tSIZEIS '(' m_exprs ')' { $$ = make_attrp(ATTR_SIZEIS, $3); }
548 | tSOURCE { $$ = make_attr(ATTR_SOURCE); }
549 | tSTRICTCONTEXTHANDLE { $$ = make_attr(ATTR_STRICTCONTEXTHANDLE); }
550 | tSTRING { $$ = make_attr(ATTR_STRING); }
551 | tSWITCHIS '(' expr ')' { $$ = make_attrp(ATTR_SWITCHIS, $3); }
552 | tSWITCHTYPE '(' type ')' { $$ = make_attrp(ATTR_SWITCHTYPE, $3); }
553 | tTRANSMITAS '(' type ')' { $$ = make_attrp(ATTR_TRANSMITAS, $3); }
554 | tTHREADING '(' threading_type ')' { $$ = make_attrv(ATTR_THREADING, $3); }
555 | tUIDEFAULT { $$ = make_attr(ATTR_UIDEFAULT); }
556 | tUSESGETLASTERROR { $$ = make_attr(ATTR_USESGETLASTERROR); }
557 | tUSERMARSHAL '(' type ')' { $$ = make_attrp(ATTR_USERMARSHAL, $3); }
558 | tUUID '(' uuid_string ')' { $$ = make_attrp(ATTR_UUID, $3); }
559 | tASYNCUUID '(' uuid_string ')' { $$ = make_attrp(ATTR_ASYNCUUID, $3); }
560 | tV1ENUM { $$ = make_attr(ATTR_V1ENUM); }
561 | tVARARG { $$ = make_attr(ATTR_VARARG); }
562 | tVERSION '(' version ')' { $$ = make_attrv(ATTR_VERSION, $3); }
563 | tVIPROGID '(' aSTRING ')' { $$ = make_attrp(ATTR_VIPROGID, $3); }
564 | tWIREMARSHAL '(' type ')' { $$ = make_attrp(ATTR_WIREMARSHAL, $3); }
565 | pointer_type { $$ = make_attrv(ATTR_POINTERTYPE, $1); }
568 uuid_string:
569 aUUID
570 | aSTRING { if (!is_valid_uuid($1))
571 error_loc("invalid UUID: %s\n", $1);
572 $$ = parse_uuid($1); }
575 callconv: tCDECL { $$ = xstrdup("__cdecl"); }
576 | tFASTCALL { $$ = xstrdup("__fastcall"); }
577 | tPASCAL { $$ = xstrdup("__pascal"); }
578 | tSTDCALL { $$ = xstrdup("__stdcall"); }
581 cases: { $$ = NULL; }
582 | cases case { $$ = append_var( $1, $2 ); }
585 case: tCASE expr_int_const ':' union_field { attr_t *a = make_attrp(ATTR_CASE, append_expr( NULL, $2 ));
586 $$ = $4; if (!$$) $$ = make_var(NULL);
587 $$->attrs = append_attr( $$->attrs, a );
589 | tDEFAULT ':' union_field { attr_t *a = make_attr(ATTR_DEFAULT);
590 $$ = $3; if (!$$) $$ = make_var(NULL);
591 $$->attrs = append_attr( $$->attrs, a );
595 enums: { $$ = NULL; }
596 | enum_list ',' { $$ = $1; }
597 | enum_list
600 enum_list: enum { if (!$1->eval)
601 $1->eval = make_exprl(EXPR_NUM, 0 /* default for first enum entry */);
602 $$ = append_var( NULL, $1 );
604 | enum_list ',' enum { if (!$3->eval)
606 var_t *last = LIST_ENTRY( list_tail($$), var_t, entry );
607 enum expr_type type = EXPR_NUM;
608 if (last->eval->type == EXPR_HEXNUM) type = EXPR_HEXNUM;
609 if (last->eval->cval + 1 < 0) type = EXPR_HEXNUM;
610 $3->eval = make_exprl(type, last->eval->cval + 1);
612 $$ = append_var( $1, $3 );
616 enum: ident '=' expr_int_const { $$ = reg_const($1);
617 $$->eval = $3;
618 $$->type = type_new_int(TYPE_BASIC_INT, 0);
620 | ident { $$ = reg_const($1);
621 $$->type = type_new_int(TYPE_BASIC_INT, 0);
625 enumdef: tENUM t_ident '{' enums '}' { $$ = type_new_enum($2, TRUE, $4); }
628 m_exprs: m_expr { $$ = append_expr( NULL, $1 ); }
629 | m_exprs ',' m_expr { $$ = append_expr( $1, $3 ); }
632 m_expr: { $$ = make_expr(EXPR_VOID); }
633 | expr
636 expr: aNUM { $$ = make_exprl(EXPR_NUM, $1); }
637 | aHEXNUM { $$ = make_exprl(EXPR_HEXNUM, $1); }
638 | aDOUBLE { $$ = make_exprd(EXPR_DOUBLE, $1); }
639 | tFALSE { $$ = make_exprl(EXPR_TRUEFALSE, 0); }
640 | tNULL { $$ = make_exprl(EXPR_NUM, 0); }
641 | tTRUE { $$ = make_exprl(EXPR_TRUEFALSE, 1); }
642 | aSTRING { $$ = make_exprs(EXPR_STRLIT, $1); }
643 | aWSTRING { $$ = make_exprs(EXPR_WSTRLIT, $1); }
644 | aSQSTRING { $$ = make_exprs(EXPR_CHARCONST, $1); }
645 | aIDENTIFIER { $$ = make_exprs(EXPR_IDENTIFIER, $1); }
646 | expr '?' expr ':' expr { $$ = make_expr3(EXPR_COND, $1, $3, $5); }
647 | expr LOGICALOR expr { $$ = make_expr2(EXPR_LOGOR, $1, $3); }
648 | expr LOGICALAND expr { $$ = make_expr2(EXPR_LOGAND, $1, $3); }
649 | expr '|' expr { $$ = make_expr2(EXPR_OR , $1, $3); }
650 | expr '^' expr { $$ = make_expr2(EXPR_XOR, $1, $3); }
651 | expr '&' expr { $$ = make_expr2(EXPR_AND, $1, $3); }
652 | expr EQUALITY expr { $$ = make_expr2(EXPR_EQUALITY, $1, $3); }
653 | expr INEQUALITY expr { $$ = make_expr2(EXPR_INEQUALITY, $1, $3); }
654 | expr '>' expr { $$ = make_expr2(EXPR_GTR, $1, $3); }
655 | expr '<' expr { $$ = make_expr2(EXPR_LESS, $1, $3); }
656 | expr GREATEREQUAL expr { $$ = make_expr2(EXPR_GTREQL, $1, $3); }
657 | expr LESSEQUAL expr { $$ = make_expr2(EXPR_LESSEQL, $1, $3); }
658 | expr SHL expr { $$ = make_expr2(EXPR_SHL, $1, $3); }
659 | expr SHR expr { $$ = make_expr2(EXPR_SHR, $1, $3); }
660 | expr '+' expr { $$ = make_expr2(EXPR_ADD, $1, $3); }
661 | expr '-' expr { $$ = make_expr2(EXPR_SUB, $1, $3); }
662 | expr '%' expr { $$ = make_expr2(EXPR_MOD, $1, $3); }
663 | expr '*' expr { $$ = make_expr2(EXPR_MUL, $1, $3); }
664 | expr '/' expr { $$ = make_expr2(EXPR_DIV, $1, $3); }
665 | '!' expr { $$ = make_expr1(EXPR_LOGNOT, $2); }
666 | '~' expr { $$ = make_expr1(EXPR_NOT, $2); }
667 | '+' expr %prec POS { $$ = make_expr1(EXPR_POS, $2); }
668 | '-' expr %prec NEG { $$ = make_expr1(EXPR_NEG, $2); }
669 | '&' expr %prec ADDRESSOF { $$ = make_expr1(EXPR_ADDRESSOF, $2); }
670 | '*' expr %prec PPTR { $$ = make_expr1(EXPR_PPTR, $2); }
671 | expr MEMBERPTR aIDENTIFIER { $$ = make_expr2(EXPR_MEMBER, make_expr1(EXPR_PPTR, $1), make_exprs(EXPR_IDENTIFIER, $3)); }
672 | expr '.' aIDENTIFIER { $$ = make_expr2(EXPR_MEMBER, $1, make_exprs(EXPR_IDENTIFIER, $3)); }
673 | '(' decl_spec m_abstract_declarator ')' expr %prec CAST
674 { $$ = make_exprt(EXPR_CAST, declare_var(NULL, $2, $3, 0), $5); free($2); free($3); }
675 | tSIZEOF '(' decl_spec m_abstract_declarator ')'
676 { $$ = make_exprt(EXPR_SIZEOF, declare_var(NULL, $3, $4, 0), NULL); free($3); free($4); }
677 | expr '[' expr ']' { $$ = make_expr2(EXPR_ARRAY, $1, $3); }
678 | '(' expr ')' { $$ = $2; }
681 expr_list_int_const: expr_int_const { $$ = append_expr( NULL, $1 ); }
682 | expr_list_int_const ',' expr_int_const { $$ = append_expr( $1, $3 ); }
685 expr_int_const: expr { $$ = $1;
686 if (!$$->is_const)
687 error_loc("expression is not an integer constant\n");
691 expr_const: expr { $$ = $1;
692 if (!$$->is_const && $$->type != EXPR_STRLIT && $$->type != EXPR_WSTRLIT)
693 error_loc("expression is not constant\n");
697 fields: { $$ = NULL; }
698 | fields field { $$ = append_var_list($1, $2); }
701 field: m_attributes decl_spec struct_declarator_list ';'
702 { const char *first = LIST_ENTRY(list_head($3), declarator_t, entry)->var->name;
703 check_field_attrs(first, $1);
704 $$ = set_var_types($1, $2, $3);
706 | m_attributes uniondef ';' { var_t *v = make_var(NULL);
707 v->type = $2; v->attrs = $1;
708 $$ = append_var(NULL, v);
712 ne_union_field:
713 s_field ';' { $$ = $1; }
714 | attributes ';' { $$ = make_var(NULL); $$->attrs = $1; }
717 ne_union_fields: { $$ = NULL; }
718 | ne_union_fields ne_union_field { $$ = append_var( $1, $2 ); }
721 union_field:
722 s_field ';' { $$ = $1; }
723 | ';' { $$ = NULL; }
726 s_field: m_attributes decl_spec declarator { $$ = declare_var(check_field_attrs($3->var->name, $1),
727 $2, $3, FALSE);
728 free($3);
730 | m_attributes structdef { var_t *v = make_var(NULL);
731 v->type = $2; v->attrs = $1;
732 $$ = v;
736 funcdef: declaration { $$ = $1;
737 if (type_get_type($$->type) != TYPE_FUNCTION)
738 error_loc("only methods may be declared inside the methods section of a dispinterface\n");
739 check_function_attrs($$->name, $$->attrs);
743 declaration:
744 attributes decl_spec init_declarator
745 { $$ = declare_var($1, $2, $3, FALSE);
746 free($3);
748 | decl_spec init_declarator { $$ = declare_var(NULL, $1, $2, FALSE);
749 free($2);
753 m_ident: { $$ = NULL; }
754 | ident
757 t_ident: { $$ = NULL; }
758 | aIDENTIFIER { $$ = $1; }
759 | aKNOWNTYPE { $$ = $1; }
762 ident: aIDENTIFIER { $$ = make_var($1); }
763 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
764 | aKNOWNTYPE { $$ = make_var($<str>1); }
767 base_type: tBYTE { $$ = find_type_or_error($<str>1, 0); }
768 | tWCHAR { $$ = find_type_or_error($<str>1, 0); }
769 | int_std
770 | tSIGNED int_std { $$ = type_new_int(type_basic_get_type($2), -1); }
771 | tUNSIGNED int_std { $$ = type_new_int(type_basic_get_type($2), 1); }
772 | tUNSIGNED { $$ = type_new_int(TYPE_BASIC_INT, 1); }
773 | tFLOAT { $$ = find_type_or_error($<str>1, 0); }
774 | tDOUBLE { $$ = find_type_or_error($<str>1, 0); }
775 | tBOOLEAN { $$ = find_type_or_error($<str>1, 0); }
776 | tERRORSTATUST { $$ = find_type_or_error($<str>1, 0); }
777 | tHANDLET { $$ = find_type_or_error($<str>1, 0); }
780 m_int:
781 | tINT
784 int_std: tINT { $$ = type_new_int(TYPE_BASIC_INT, 0); }
785 | tSHORT m_int { $$ = type_new_int(TYPE_BASIC_INT16, 0); }
786 | tSMALL { $$ = type_new_int(TYPE_BASIC_INT8, 0); }
787 | tLONG m_int { $$ = type_new_int(TYPE_BASIC_INT32, 0); }
788 | tHYPER m_int { $$ = type_new_int(TYPE_BASIC_HYPER, 0); }
789 | tINT64 { $$ = type_new_int(TYPE_BASIC_INT64, 0); }
790 | tCHAR { $$ = type_new_int(TYPE_BASIC_CHAR, 0); }
791 | tINT3264 { $$ = type_new_int(TYPE_BASIC_INT3264, 0); }
794 coclass: tCOCLASS aIDENTIFIER { $$ = type_new_coclass($2); }
795 | tCOCLASS aKNOWNTYPE { $$ = find_type($2, 0);
796 if (type_get_type_detect_alias($$) != TYPE_COCLASS)
797 error_loc("%s was not declared a coclass at %s:%d\n",
798 $2, $$->loc_info.input_name,
799 $$->loc_info.line_number);
803 coclasshdr: attributes coclass { $$ = $2;
804 check_def($$);
805 $$->attrs = check_coclass_attrs($2->name, $1);
809 coclassdef: coclasshdr '{' coclass_ints '}' semicolon_opt
810 { $$ = type_coclass_define($1, $3); }
813 namespacedef: tNAMESPACE aIDENTIFIER { $$ = NULL; }
816 coclass_ints: { $$ = NULL; }
817 | coclass_ints coclass_int { $$ = append_ifref( $1, $2 ); }
820 coclass_int:
821 m_attributes interfacedec { $$ = make_ifref($2); $$->attrs = $1; }
824 dispinterface: tDISPINTERFACE aIDENTIFIER { $$ = get_type(TYPE_INTERFACE, $2, 0); }
825 | tDISPINTERFACE aKNOWNTYPE { $$ = get_type(TYPE_INTERFACE, $2, 0); }
828 dispinterfacehdr: attributes dispinterface { attr_t *attrs;
829 $$ = $2;
830 check_def($$);
831 attrs = make_attr(ATTR_DISPINTERFACE);
832 $$->attrs = append_attr( check_dispiface_attrs($2->name, $1), attrs );
833 $$->defined = TRUE;
837 dispint_props: tPROPERTIES ':' { $$ = NULL; }
838 | dispint_props s_field ';' { $$ = append_var( $1, $2 ); }
841 dispint_meths: tMETHODS ':' { $$ = NULL; }
842 | dispint_meths funcdef ';' { $$ = append_var( $1, $2 ); }
845 dispinterfacedef: dispinterfacehdr '{'
846 dispint_props
847 dispint_meths
848 '}' { $$ = $1;
849 type_dispinterface_define($$, $3, $4);
851 | dispinterfacehdr
852 '{' interface ';' '}' { $$ = $1;
853 type_dispinterface_define_from_iface($$, $3);
857 inherit: { $$ = NULL; }
858 | ':' aKNOWNTYPE { $$ = find_type_or_error2($2, 0); }
861 interface: tINTERFACE aIDENTIFIER { $$ = get_type(TYPE_INTERFACE, $2, 0); }
862 | tINTERFACE aKNOWNTYPE { $$ = get_type(TYPE_INTERFACE, $2, 0); }
865 interfacehdr: attributes interface { $$.interface = $2;
866 $$.old_pointer_default = pointer_default;
867 if (is_attr($1, ATTR_POINTERDEFAULT))
868 pointer_default = get_attrv($1, ATTR_POINTERDEFAULT);
869 check_def($2);
870 $2->attrs = check_iface_attrs($2->name, $1);
871 $2->defined = TRUE;
875 interfacedef: interfacehdr inherit
876 '{' int_statements '}' semicolon_opt { $$ = $1.interface;
877 if($$ == $2)
878 error_loc("Interface can't inherit from itself\n");
879 type_interface_define($$, $2, $4);
880 pointer_default = $1.old_pointer_default;
882 /* MIDL is able to import the definition of a base class from inside the
883 * definition of a derived class, I'll try to support it with this rule */
884 | interfacehdr ':' aIDENTIFIER
885 '{' import int_statements '}'
886 semicolon_opt { $$ = $1.interface;
887 type_interface_define($$, find_type_or_error2($3, 0), $6);
888 pointer_default = $1.old_pointer_default;
890 | dispinterfacedef semicolon_opt { $$ = $1; }
893 interfacedec:
894 interface ';' { $$ = $1; }
895 | dispinterface ';' { $$ = $1; }
898 module: tMODULE aIDENTIFIER { $$ = type_new_module($2); }
899 | tMODULE aKNOWNTYPE { $$ = type_new_module($2); }
902 modulehdr: attributes module { $$ = $2;
903 $$->attrs = check_module_attrs($2->name, $1);
907 moduledef: modulehdr '{' int_statements '}'
908 semicolon_opt { $$ = $1;
909 type_module_define($$, $3);
913 storage_cls_spec:
914 tEXTERN { $$ = STG_EXTERN; }
915 | tSTATIC { $$ = STG_STATIC; }
916 | tREGISTER { $$ = STG_REGISTER; }
919 function_specifier:
920 tINLINE { $$ = make_attr(ATTR_INLINE); }
923 type_qualifier:
924 tCONST { $$ = make_attr(ATTR_CONST); }
927 m_type_qual_list: { $$ = NULL; }
928 | m_type_qual_list type_qualifier { $$ = append_attr($1, $2); }
931 decl_spec: type m_decl_spec_no_type { $$ = make_decl_spec($1, $2, NULL, NULL, STG_NONE); }
932 | decl_spec_no_type type m_decl_spec_no_type
933 { $$ = make_decl_spec($2, $1, $3, NULL, STG_NONE); }
936 m_decl_spec_no_type: { $$ = NULL; }
937 | decl_spec_no_type
940 decl_spec_no_type:
941 type_qualifier m_decl_spec_no_type { $$ = make_decl_spec(NULL, $2, NULL, $1, STG_NONE); }
942 | function_specifier m_decl_spec_no_type { $$ = make_decl_spec(NULL, $2, NULL, $1, STG_NONE); }
943 | storage_cls_spec m_decl_spec_no_type { $$ = make_decl_spec(NULL, $2, NULL, NULL, $1); }
946 declarator:
947 '*' m_type_qual_list declarator %prec PPTR
948 { $$ = $3; $$->type = append_ptrchain_type($$->type, type_new_pointer(pointer_default, NULL, $2)); }
949 | callconv declarator { $$ = $2; if ($$->func_type) $$->func_type->attrs = append_attr($$->func_type->attrs, make_attrp(ATTR_CALLCONV, $1));
950 else if ($$->type) $$->type->attrs = append_attr($$->type->attrs, make_attrp(ATTR_CALLCONV, $1)); }
951 | direct_declarator
954 direct_declarator:
955 ident { $$ = make_declarator($1); }
956 | '(' declarator ')' { $$ = $2; }
957 | direct_declarator array { $$ = $1; $$->array = append_array($$->array, $2); }
958 | direct_declarator '(' m_args ')' { $$ = $1;
959 $$->func_type = append_ptrchain_type($$->type, type_new_function($3));
960 $$->type = NULL;
964 /* abstract declarator */
965 abstract_declarator:
966 '*' m_type_qual_list m_abstract_declarator %prec PPTR
967 { $$ = $3; $$->type = append_ptrchain_type($$->type, type_new_pointer(pointer_default, NULL, $2)); }
968 | callconv m_abstract_declarator { $$ = $2; if ($$->func_type) $$->func_type->attrs = append_attr($$->func_type->attrs, make_attrp(ATTR_CALLCONV, $1));
969 else if ($$->type) $$->type->attrs = append_attr($$->type->attrs, make_attrp(ATTR_CALLCONV, $1)); }
970 | abstract_direct_declarator
973 /* abstract declarator without accepting direct declarator */
974 abstract_declarator_no_direct:
975 '*' m_type_qual_list m_any_declarator %prec PPTR
976 { $$ = $3; $$->type = append_ptrchain_type($$->type, type_new_pointer(pointer_default, NULL, $2)); }
977 | callconv m_any_declarator { $$ = $2; if ($$->func_type) $$->func_type->attrs = append_attr($$->func_type->attrs, make_attrp(ATTR_CALLCONV, $1));
978 else if ($$->type) $$->type->attrs = append_attr($$->type->attrs, make_attrp(ATTR_CALLCONV, $1)); }
981 /* abstract declarator or empty */
982 m_abstract_declarator: { $$ = make_declarator(NULL); }
983 | abstract_declarator
986 /* abstract direct declarator */
987 abstract_direct_declarator:
988 '(' abstract_declarator_no_direct ')' { $$ = $2; }
989 | abstract_direct_declarator array { $$ = $1; $$->array = append_array($$->array, $2); }
990 | array { $$ = make_declarator(NULL); $$->array = append_array($$->array, $1); }
991 | '(' m_args ')'
992 { $$ = make_declarator(NULL);
993 $$->func_type = append_ptrchain_type($$->type, type_new_function($2));
994 $$->type = NULL;
996 | abstract_direct_declarator '(' m_args ')'
997 { $$ = $1;
998 $$->func_type = append_ptrchain_type($$->type, type_new_function($3));
999 $$->type = NULL;
1003 /* abstract or non-abstract declarator */
1004 any_declarator:
1005 '*' m_type_qual_list m_any_declarator %prec PPTR
1006 { $$ = $3; $$->type = append_ptrchain_type($$->type, type_new_pointer(pointer_default, NULL, $2)); }
1007 | callconv m_any_declarator { $$ = $2; $$->type->attrs = append_attr($$->type->attrs, make_attrp(ATTR_CALLCONV, $1)); }
1008 | any_direct_declarator
1011 /* abstract or non-abstract declarator without accepting direct declarator */
1012 any_declarator_no_direct:
1013 '*' m_type_qual_list m_any_declarator %prec PPTR
1014 { $$ = $3; $$->type = append_ptrchain_type($$->type, type_new_pointer(pointer_default, NULL, $2)); }
1015 | callconv m_any_declarator { $$ = $2; $$->type->attrs = append_attr($$->type->attrs, make_attrp(ATTR_CALLCONV, $1)); }
1018 /* abstract or non-abstract declarator or empty */
1019 m_any_declarator: { $$ = make_declarator(NULL); }
1020 | any_declarator
1023 /* abstract or non-abstract direct declarator. note: direct declarators
1024 * aren't accepted inside brackets to avoid ambiguity with the rule for
1025 * function arguments */
1026 any_direct_declarator:
1027 ident { $$ = make_declarator($1); }
1028 | '(' any_declarator_no_direct ')' { $$ = $2; }
1029 | any_direct_declarator array { $$ = $1; $$->array = append_array($$->array, $2); }
1030 | array { $$ = make_declarator(NULL); $$->array = append_array($$->array, $1); }
1031 | '(' m_args ')'
1032 { $$ = make_declarator(NULL);
1033 $$->func_type = append_ptrchain_type($$->type, type_new_function($2));
1034 $$->type = NULL;
1036 | any_direct_declarator '(' m_args ')'
1037 { $$ = $1;
1038 $$->func_type = append_ptrchain_type($$->type, type_new_function($3));
1039 $$->type = NULL;
1043 declarator_list:
1044 declarator { $$ = append_declarator( NULL, $1 ); }
1045 | declarator_list ',' declarator { $$ = append_declarator( $1, $3 ); }
1048 m_bitfield: { $$ = NULL; }
1049 | ':' expr_const { $$ = $2; }
1052 struct_declarator: any_declarator m_bitfield { $$ = $1; $$->bits = $2;
1053 if (!$$->bits && !$$->var->name)
1054 error_loc("unnamed fields are not allowed\n");
1058 struct_declarator_list:
1059 struct_declarator { $$ = append_declarator( NULL, $1 ); }
1060 | struct_declarator_list ',' struct_declarator
1061 { $$ = append_declarator( $1, $3 ); }
1064 init_declarator:
1065 declarator { $$ = $1; }
1066 | declarator '=' expr_const { $$ = $1; $1->var->eval = $3; }
1069 threading_type:
1070 tAPARTMENT { $$ = THREADING_APARTMENT; }
1071 | tNEUTRAL { $$ = THREADING_NEUTRAL; }
1072 | tSINGLE { $$ = THREADING_SINGLE; }
1073 | tFREE { $$ = THREADING_FREE; }
1074 | tBOTH { $$ = THREADING_BOTH; }
1077 pointer_type:
1078 tREF { $$ = RPC_FC_RP; }
1079 | tUNIQUE { $$ = RPC_FC_UP; }
1080 | tPTR { $$ = RPC_FC_FP; }
1083 structdef: tSTRUCT t_ident '{' fields '}' { $$ = type_new_struct($2, TRUE, $4); }
1086 type: tVOID { $$ = type_new_void(); }
1087 | aKNOWNTYPE { $$ = find_type_or_error($1, 0); }
1088 | base_type { $$ = $1; }
1089 | enumdef { $$ = $1; }
1090 | tENUM aIDENTIFIER { $$ = type_new_enum($2, FALSE, NULL); }
1091 | structdef { $$ = $1; }
1092 | tSTRUCT aIDENTIFIER { $$ = type_new_struct($2, FALSE, NULL); }
1093 | uniondef { $$ = $1; }
1094 | tUNION aIDENTIFIER { $$ = type_new_nonencapsulated_union($2, FALSE, NULL); }
1095 | tSAFEARRAY '(' type ')' { $$ = make_safearray($3); }
1098 typedef: m_attributes tTYPEDEF m_attributes decl_spec declarator_list
1099 { $1 = append_attribs($1, $3);
1100 reg_typedefs($4, $5, check_typedef_attrs($1));
1101 $$ = make_statement_typedef($5);
1105 uniondef: tUNION t_ident '{' ne_union_fields '}'
1106 { $$ = type_new_nonencapsulated_union($2, TRUE, $4); }
1107 | tUNION t_ident
1108 tSWITCH '(' s_field ')'
1109 m_ident '{' cases '}' { $$ = type_new_encapsulated_union($2, $5, $7, $9); }
1112 version:
1113 aNUM { $$ = MAKEVERSION($1, 0); }
1114 | aNUM '.' aNUM { $$ = MAKEVERSION($1, $3); }
1115 | aHEXNUM { $$ = $1; }
1120 static void decl_builtin_basic(const char *name, enum type_basic_type type)
1122 type_t *t = type_new_basic(type);
1123 reg_type(t, name, 0);
1126 static void decl_builtin_alias(const char *name, type_t *t)
1128 reg_type(type_new_alias(t, name), name, 0);
1131 void init_types(void)
1133 decl_builtin_basic("byte", TYPE_BASIC_BYTE);
1134 decl_builtin_basic("wchar_t", TYPE_BASIC_WCHAR);
1135 decl_builtin_basic("float", TYPE_BASIC_FLOAT);
1136 decl_builtin_basic("double", TYPE_BASIC_DOUBLE);
1137 decl_builtin_basic("error_status_t", TYPE_BASIC_ERROR_STATUS_T);
1138 decl_builtin_basic("handle_t", TYPE_BASIC_HANDLE);
1139 decl_builtin_alias("boolean", type_new_basic(TYPE_BASIC_BYTE));
1142 static str_list_t *append_str(str_list_t *list, char *str)
1144 struct str_list_entry_t *entry;
1146 if (!str) return list;
1147 if (!list)
1149 list = xmalloc( sizeof(*list) );
1150 list_init( list );
1152 entry = xmalloc( sizeof(*entry) );
1153 entry->str = str;
1154 list_add_tail( list, &entry->entry );
1155 return list;
1158 static attr_list_t *append_attr(attr_list_t *list, attr_t *attr)
1160 attr_t *attr_existing;
1161 if (!attr) return list;
1162 if (!list)
1164 list = xmalloc( sizeof(*list) );
1165 list_init( list );
1167 LIST_FOR_EACH_ENTRY(attr_existing, list, attr_t, entry)
1168 if (attr_existing->type == attr->type)
1170 parser_warning("duplicate attribute %s\n", get_attr_display_name(attr->type));
1171 /* use the last attribute, like MIDL does */
1172 list_remove(&attr_existing->entry);
1173 break;
1175 list_add_tail( list, &attr->entry );
1176 return list;
1179 static attr_list_t *move_attr(attr_list_t *dst, attr_list_t *src, enum attr_type type)
1181 attr_t *attr;
1182 if (!src) return dst;
1183 LIST_FOR_EACH_ENTRY(attr, src, attr_t, entry)
1184 if (attr->type == type)
1186 list_remove(&attr->entry);
1187 return append_attr(dst, attr);
1189 return dst;
1192 static attr_list_t *append_attr_list(attr_list_t *new_list, attr_list_t *old_list)
1194 struct list *entry;
1196 if (!old_list) return new_list;
1198 while ((entry = list_head(old_list)))
1200 attr_t *attr = LIST_ENTRY(entry, attr_t, entry);
1201 list_remove(entry);
1202 new_list = append_attr(new_list, attr);
1204 return new_list;
1207 static attr_list_t *dupattrs(const attr_list_t *list)
1209 attr_list_t *new_list;
1210 const attr_t *attr;
1212 if (!list) return NULL;
1214 new_list = xmalloc( sizeof(*list) );
1215 list_init( new_list );
1216 LIST_FOR_EACH_ENTRY(attr, list, const attr_t, entry)
1218 attr_t *new_attr = xmalloc(sizeof(*new_attr));
1219 *new_attr = *attr;
1220 list_add_tail(new_list, &new_attr->entry);
1222 return new_list;
1225 static decl_spec_t *make_decl_spec(type_t *type, decl_spec_t *left, decl_spec_t *right, attr_t *attr, enum storage_class stgclass)
1227 decl_spec_t *declspec = left ? left : right;
1228 if (!declspec)
1230 declspec = xmalloc(sizeof(*declspec));
1231 declspec->type = NULL;
1232 declspec->attrs = NULL;
1233 declspec->stgclass = STG_NONE;
1235 declspec->type = type;
1236 if (left && declspec != left)
1238 declspec->attrs = append_attr_list(declspec->attrs, left->attrs);
1239 if (declspec->stgclass == STG_NONE)
1240 declspec->stgclass = left->stgclass;
1241 else if (left->stgclass != STG_NONE)
1242 error_loc("only one storage class can be specified\n");
1243 assert(!left->type);
1244 free(left);
1246 if (right && declspec != right)
1248 declspec->attrs = append_attr_list(declspec->attrs, right->attrs);
1249 if (declspec->stgclass == STG_NONE)
1250 declspec->stgclass = right->stgclass;
1251 else if (right->stgclass != STG_NONE)
1252 error_loc("only one storage class can be specified\n");
1253 assert(!right->type);
1254 free(right);
1257 declspec->attrs = append_attr(declspec->attrs, attr);
1258 if (declspec->stgclass == STG_NONE)
1259 declspec->stgclass = stgclass;
1260 else if (stgclass != STG_NONE)
1261 error_loc("only one storage class can be specified\n");
1263 /* apply attributes to type */
1264 if (type && declspec->attrs)
1266 attr_list_t *attrs;
1267 declspec->type = duptype(type, 1);
1268 attrs = dupattrs(type->attrs);
1269 declspec->type->attrs = append_attr_list(attrs, declspec->attrs);
1270 declspec->attrs = NULL;
1273 return declspec;
1276 static attr_t *make_attr(enum attr_type type)
1278 attr_t *a = xmalloc(sizeof(attr_t));
1279 a->type = type;
1280 a->u.ival = 0;
1281 return a;
1284 static attr_t *make_attrv(enum attr_type type, unsigned int val)
1286 attr_t *a = xmalloc(sizeof(attr_t));
1287 a->type = type;
1288 a->u.ival = val;
1289 return a;
1292 static attr_t *make_attrp(enum attr_type type, void *val)
1294 attr_t *a = xmalloc(sizeof(attr_t));
1295 a->type = type;
1296 a->u.pval = val;
1297 return a;
1300 static expr_list_t *append_expr(expr_list_t *list, expr_t *expr)
1302 if (!expr) return list;
1303 if (!list)
1305 list = xmalloc( sizeof(*list) );
1306 list_init( list );
1308 list_add_tail( list, &expr->entry );
1309 return list;
1312 static array_dims_t *append_array(array_dims_t *list, expr_t *expr)
1314 if (!expr) return list;
1315 if (!list)
1317 list = xmalloc( sizeof(*list) );
1318 list_init( list );
1320 list_add_tail( list, &expr->entry );
1321 return list;
1324 static struct list type_pool = LIST_INIT(type_pool);
1325 typedef struct
1327 type_t data;
1328 struct list link;
1329 } type_pool_node_t;
1331 type_t *alloc_type(void)
1333 type_pool_node_t *node = xmalloc(sizeof *node);
1334 list_add_tail(&type_pool, &node->link);
1335 return &node->data;
1338 void set_all_tfswrite(int val)
1340 type_pool_node_t *node;
1341 LIST_FOR_EACH_ENTRY(node, &type_pool, type_pool_node_t, link)
1342 node->data.tfswrite = val;
1345 void clear_all_offsets(void)
1347 type_pool_node_t *node;
1348 LIST_FOR_EACH_ENTRY(node, &type_pool, type_pool_node_t, link)
1349 node->data.typestring_offset = node->data.ptrdesc = 0;
1352 static void type_function_add_head_arg(type_t *type, var_t *arg)
1354 if (!type->details.function->args)
1356 type->details.function->args = xmalloc( sizeof(*type->details.function->args) );
1357 list_init( type->details.function->args );
1359 list_add_head( type->details.function->args, &arg->entry );
1362 static int is_allowed_range_type(const type_t *type)
1364 switch (type_get_type(type))
1366 case TYPE_ENUM:
1367 return TRUE;
1368 case TYPE_BASIC:
1369 switch (type_basic_get_type(type))
1371 case TYPE_BASIC_INT8:
1372 case TYPE_BASIC_INT16:
1373 case TYPE_BASIC_INT32:
1374 case TYPE_BASIC_INT64:
1375 case TYPE_BASIC_INT:
1376 case TYPE_BASIC_INT3264:
1377 case TYPE_BASIC_BYTE:
1378 case TYPE_BASIC_CHAR:
1379 case TYPE_BASIC_WCHAR:
1380 case TYPE_BASIC_HYPER:
1381 return TRUE;
1382 case TYPE_BASIC_FLOAT:
1383 case TYPE_BASIC_DOUBLE:
1384 case TYPE_BASIC_ERROR_STATUS_T:
1385 case TYPE_BASIC_HANDLE:
1386 return FALSE;
1388 return FALSE;
1389 default:
1390 return FALSE;
1394 static type_t *append_ptrchain_type(type_t *ptrchain, type_t *type)
1396 type_t *ptrchain_type;
1397 if (!ptrchain)
1398 return type;
1399 for (ptrchain_type = ptrchain; type_pointer_get_ref(ptrchain_type); ptrchain_type = type_pointer_get_ref(ptrchain_type))
1401 assert(ptrchain_type->type_type == TYPE_POINTER);
1402 ptrchain_type->details.pointer.ref = type;
1403 return ptrchain;
1406 static var_t *declare_var(attr_list_t *attrs, decl_spec_t *decl_spec, const declarator_t *decl,
1407 int top)
1409 var_t *v = decl->var;
1410 expr_list_t *sizes = get_attrp(attrs, ATTR_SIZEIS);
1411 expr_list_t *lengs = get_attrp(attrs, ATTR_LENGTHIS);
1412 int sizeless;
1413 expr_t *dim;
1414 type_t **ptype;
1415 array_dims_t *arr = decl ? decl->array : NULL;
1416 type_t *func_type = decl ? decl->func_type : NULL;
1417 type_t *type = decl_spec->type;
1419 if (is_attr(type->attrs, ATTR_INLINE))
1421 if (!func_type)
1422 error_loc("inline attribute applied to non-function type\n");
1423 else
1425 type_t *t;
1426 /* move inline attribute from return type node to function node */
1427 for (t = func_type; is_ptr(t); t = type_pointer_get_ref(t))
1429 t->attrs = move_attr(t->attrs, type->attrs, ATTR_INLINE);
1433 /* add type onto the end of the pointers in pident->type */
1434 v->type = append_ptrchain_type(decl ? decl->type : NULL, type);
1435 v->stgclass = decl_spec->stgclass;
1436 v->attrs = attrs;
1438 /* check for pointer attribute being applied to non-pointer, non-array
1439 * type */
1440 if (!arr)
1442 int ptr_attr = get_attrv(v->attrs, ATTR_POINTERTYPE);
1443 const type_t *ptr = NULL;
1444 /* pointer attributes on the left side of the type belong to the function
1445 * pointer, if one is being declared */
1446 type_t **pt = func_type ? &func_type : &v->type;
1447 for (ptr = *pt; ptr && !ptr_attr; )
1449 ptr_attr = get_attrv(ptr->attrs, ATTR_POINTERTYPE);
1450 if (!ptr_attr && type_is_alias(ptr))
1451 ptr = type_alias_get_aliasee(ptr);
1452 else
1453 break;
1455 if (is_ptr(ptr))
1457 if (ptr_attr && ptr_attr != RPC_FC_UP &&
1458 type_get_type(type_pointer_get_ref(ptr)) == TYPE_INTERFACE)
1459 warning_loc_info(&v->loc_info,
1460 "%s: pointer attribute applied to interface "
1461 "pointer type has no effect\n", v->name);
1462 if (!ptr_attr && top && (*pt)->details.pointer.def_fc != RPC_FC_RP)
1464 /* FIXME: this is a horrible hack to cope with the issue that we
1465 * store an offset to the typeformat string in the type object, but
1466 * two typeformat strings may be written depending on whether the
1467 * pointer is a toplevel parameter or not */
1468 *pt = duptype(*pt, 1);
1471 else if (ptr_attr)
1472 error_loc("%s: pointer attribute applied to non-pointer type\n", v->name);
1475 if (is_attr(v->attrs, ATTR_STRING))
1477 type_t *t = type;
1479 if (!is_ptr(v->type) && !arr)
1480 error_loc("'%s': [string] attribute applied to non-pointer, non-array type\n",
1481 v->name);
1483 while (is_ptr(t))
1484 t = type_pointer_get_ref(t);
1486 if (type_get_type(t) != TYPE_BASIC &&
1487 (get_basic_fc(t) != RPC_FC_CHAR &&
1488 get_basic_fc(t) != RPC_FC_BYTE &&
1489 get_basic_fc(t) != RPC_FC_WCHAR))
1491 error_loc("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
1492 v->name);
1496 if (is_attr(v->attrs, ATTR_V1ENUM))
1498 if (type_get_type_detect_alias(v->type) != TYPE_ENUM)
1499 error_loc("'%s': [v1_enum] attribute applied to non-enum type\n", v->name);
1502 if (is_attr(v->attrs, ATTR_RANGE) && !is_allowed_range_type(v->type))
1503 error_loc("'%s': [range] attribute applied to non-integer type\n",
1504 v->name);
1506 ptype = &v->type;
1507 sizeless = FALSE;
1508 if (arr) LIST_FOR_EACH_ENTRY_REV(dim, arr, expr_t, entry)
1510 if (sizeless)
1511 error_loc("%s: only the first array dimension can be unspecified\n", v->name);
1513 if (dim->is_const)
1515 if (dim->cval <= 0)
1516 error_loc("%s: array dimension must be positive\n", v->name);
1518 /* FIXME: should use a type_memsize that allows us to pass in a pointer size */
1519 if (0)
1521 unsigned int size = type_memsize(v->type);
1523 if (0xffffffffu / size < dim->cval)
1524 error_loc("%s: total array size is too large\n", v->name);
1527 else
1528 sizeless = TRUE;
1530 *ptype = type_new_array(NULL, *ptype, FALSE,
1531 dim->is_const ? dim->cval : 0,
1532 dim->is_const ? NULL : dim, NULL,
1533 pointer_default);
1536 ptype = &v->type;
1537 if (sizes) LIST_FOR_EACH_ENTRY(dim, sizes, expr_t, entry)
1539 if (dim->type != EXPR_VOID)
1541 if (is_array(*ptype))
1543 if (!type_array_get_conformance(*ptype) ||
1544 type_array_get_conformance(*ptype)->type != EXPR_VOID)
1545 error_loc("%s: cannot specify size_is for an already sized array\n", v->name);
1546 else
1547 *ptype = type_new_array((*ptype)->name,
1548 type_array_get_element(*ptype), FALSE,
1549 0, dim, NULL, 0);
1551 else if (is_ptr(*ptype))
1552 *ptype = type_new_array((*ptype)->name, type_pointer_get_ref(*ptype), TRUE,
1553 0, dim, NULL, pointer_default);
1554 else
1555 error_loc("%s: size_is attribute applied to illegal type\n", v->name);
1558 if (is_ptr(*ptype))
1559 ptype = &(*ptype)->details.pointer.ref;
1560 else if (is_array(*ptype))
1561 ptype = &(*ptype)->details.array.elem;
1562 else
1563 error_loc("%s: too many expressions in size_is attribute\n", v->name);
1566 ptype = &v->type;
1567 if (lengs) LIST_FOR_EACH_ENTRY(dim, lengs, expr_t, entry)
1569 if (dim->type != EXPR_VOID)
1571 if (is_array(*ptype))
1573 *ptype = type_new_array((*ptype)->name,
1574 type_array_get_element(*ptype),
1575 type_array_is_decl_as_ptr(*ptype),
1576 type_array_get_dim(*ptype),
1577 type_array_get_conformance(*ptype),
1578 dim, type_array_get_ptr_default_fc(*ptype));
1580 else
1581 error_loc("%s: length_is attribute applied to illegal type\n", v->name);
1584 if (is_ptr(*ptype))
1585 ptype = &(*ptype)->details.pointer.ref;
1586 else if (is_array(*ptype))
1587 ptype = &(*ptype)->details.array.elem;
1588 else
1589 error_loc("%s: too many expressions in length_is attribute\n", v->name);
1592 /* v->type is currently pointing to the type on the left-side of the
1593 * declaration, so we need to fix this up so that it is the return type of the
1594 * function and make v->type point to the function side of the declaration */
1595 if (func_type)
1597 type_t *ft, *t;
1598 type_t *return_type = v->type;
1599 v->type = func_type;
1600 for (ft = v->type; is_ptr(ft); ft = type_pointer_get_ref(ft))
1602 assert(type_get_type_detect_alias(ft) == TYPE_FUNCTION);
1603 ft->details.function->retval = make_var(xstrdup("_RetVal"));
1604 ft->details.function->retval->type = return_type;
1605 /* move calling convention attribute, if present, from pointer nodes to
1606 * function node */
1607 for (t = v->type; is_ptr(t); t = type_pointer_get_ref(t))
1608 ft->attrs = move_attr(ft->attrs, t->attrs, ATTR_CALLCONV);
1610 else
1612 type_t *t;
1613 for (t = v->type; is_ptr(t); t = type_pointer_get_ref(t))
1614 if (is_attr(t->attrs, ATTR_CALLCONV))
1615 error_loc("calling convention applied to non-function-pointer type\n");
1618 if (decl->bits)
1619 v->type = type_new_bitfield(v->type, decl->bits);
1621 return v;
1624 static var_list_t *set_var_types(attr_list_t *attrs, decl_spec_t *decl_spec, declarator_list_t *decls)
1626 declarator_t *decl, *next;
1627 var_list_t *var_list = NULL;
1629 LIST_FOR_EACH_ENTRY_SAFE( decl, next, decls, declarator_t, entry )
1631 var_t *var = declare_var(attrs, decl_spec, decl, 0);
1632 var_list = append_var(var_list, var);
1633 free(decl);
1635 free(decl_spec);
1636 return var_list;
1639 static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface)
1641 if (!iface) return list;
1642 if (!list)
1644 list = xmalloc( sizeof(*list) );
1645 list_init( list );
1647 list_add_tail( list, &iface->entry );
1648 return list;
1651 static ifref_t *make_ifref(type_t *iface)
1653 ifref_t *l = xmalloc(sizeof(ifref_t));
1654 l->iface = iface;
1655 l->attrs = NULL;
1656 return l;
1659 var_list_t *append_var(var_list_t *list, var_t *var)
1661 if (!var) return list;
1662 if (!list)
1664 list = xmalloc( sizeof(*list) );
1665 list_init( list );
1667 list_add_tail( list, &var->entry );
1668 return list;
1671 static var_list_t *append_var_list(var_list_t *list, var_list_t *vars)
1673 if (!vars) return list;
1674 if (!list)
1676 list = xmalloc( sizeof(*list) );
1677 list_init( list );
1679 list_move_tail( list, vars );
1680 return list;
1683 var_t *make_var(char *name)
1685 var_t *v = xmalloc(sizeof(var_t));
1686 v->name = name;
1687 v->type = NULL;
1688 v->attrs = NULL;
1689 v->eval = NULL;
1690 v->stgclass = STG_NONE;
1691 init_loc_info(&v->loc_info);
1692 return v;
1695 static declarator_list_t *append_declarator(declarator_list_t *list, declarator_t *d)
1697 if (!d) return list;
1698 if (!list) {
1699 list = xmalloc(sizeof(*list));
1700 list_init(list);
1702 list_add_tail(list, &d->entry);
1703 return list;
1706 static declarator_t *make_declarator(var_t *var)
1708 declarator_t *d = xmalloc(sizeof(*d));
1709 d->var = var ? var : make_var(NULL);
1710 d->type = NULL;
1711 d->func_type = NULL;
1712 d->array = NULL;
1713 d->bits = NULL;
1714 return d;
1717 static type_t *make_safearray(type_t *type)
1719 return type_new_array(NULL, type_new_alias(type, "SAFEARRAY"), TRUE, 0,
1720 NULL, NULL, RPC_FC_RP);
1723 static typelib_t *make_library(const char *name, const attr_list_t *attrs)
1725 typelib_t *typelib = xmalloc(sizeof(*typelib));
1726 typelib->name = xstrdup(name);
1727 typelib->attrs = attrs;
1728 list_init( &typelib->importlibs );
1729 return typelib;
1732 #define HASHMAX 64
1734 static int hash_ident(const char *name)
1736 const char *p = name;
1737 int sum = 0;
1738 /* a simple sum hash is probably good enough */
1739 while (*p) {
1740 sum += *p;
1741 p++;
1743 return sum & (HASHMAX-1);
1746 /***** type repository *****/
1748 struct rtype {
1749 const char *name;
1750 type_t *type;
1751 int t;
1752 struct rtype *next;
1755 struct rtype *type_hash[HASHMAX];
1757 type_t *reg_type(type_t *type, const char *name, int t)
1759 struct rtype *nt;
1760 int hash;
1761 if (!name) {
1762 error_loc("registering named type without name\n");
1763 return type;
1765 hash = hash_ident(name);
1766 nt = xmalloc(sizeof(struct rtype));
1767 nt->name = name;
1768 nt->type = type;
1769 nt->t = t;
1770 nt->next = type_hash[hash];
1771 type_hash[hash] = nt;
1772 if ((t == tsSTRUCT || t == tsUNION))
1773 fix_incomplete_types(type);
1774 return type;
1777 static int is_incomplete(const type_t *t)
1779 return !t->defined &&
1780 (type_get_type_detect_alias(t) == TYPE_STRUCT ||
1781 type_get_type_detect_alias(t) == TYPE_UNION ||
1782 type_get_type_detect_alias(t) == TYPE_ENCAPSULATED_UNION);
1785 void add_incomplete(type_t *t)
1787 struct typenode *tn = xmalloc(sizeof *tn);
1788 tn->type = t;
1789 list_add_tail(&incomplete_types, &tn->entry);
1792 static void fix_type(type_t *t)
1794 if (type_is_alias(t) && is_incomplete(t)) {
1795 type_t *ot = type_alias_get_aliasee(t);
1796 fix_type(ot);
1797 if (type_get_type_detect_alias(ot) == TYPE_STRUCT ||
1798 type_get_type_detect_alias(ot) == TYPE_UNION ||
1799 type_get_type_detect_alias(ot) == TYPE_ENCAPSULATED_UNION)
1800 t->details.structure = ot->details.structure;
1801 t->defined = ot->defined;
1805 static void fix_incomplete(void)
1807 struct typenode *tn, *next;
1809 LIST_FOR_EACH_ENTRY_SAFE(tn, next, &incomplete_types, struct typenode, entry) {
1810 fix_type(tn->type);
1811 list_remove(&tn->entry);
1812 free(tn);
1816 static void fix_incomplete_types(type_t *complete_type)
1818 struct typenode *tn, *next;
1820 LIST_FOR_EACH_ENTRY_SAFE(tn, next, &incomplete_types, struct typenode, entry)
1822 if (type_is_equal(complete_type, tn->type))
1824 tn->type->details.structure = complete_type->details.structure;
1825 list_remove(&tn->entry);
1826 free(tn);
1831 static type_t *reg_typedefs(decl_spec_t *decl_spec, declarator_list_t *decls, attr_list_t *attrs)
1833 const declarator_t *decl;
1834 type_t *type = decl_spec->type;
1836 /* We must generate names for tagless enum, struct or union.
1837 Typedef-ing a tagless enum, struct or union means we want the typedef
1838 to be included in a library hence the public attribute. */
1839 if ((type_get_type_detect_alias(type) == TYPE_ENUM ||
1840 type_get_type_detect_alias(type) == TYPE_STRUCT ||
1841 type_get_type_detect_alias(type) == TYPE_UNION ||
1842 type_get_type_detect_alias(type) == TYPE_ENCAPSULATED_UNION) &&
1843 !type->name && !parse_only)
1845 if (! is_attr(attrs, ATTR_PUBLIC) && ! is_attr (attrs, ATTR_HIDDEN))
1846 attrs = append_attr( attrs, make_attr(ATTR_PUBLIC) );
1847 type->name = gen_name();
1849 else if (is_attr(attrs, ATTR_UUID) && !is_attr(attrs, ATTR_PUBLIC)
1850 && !is_attr(attrs, ATTR_HIDDEN))
1851 attrs = append_attr( attrs, make_attr(ATTR_PUBLIC) );
1853 LIST_FOR_EACH_ENTRY( decl, decls, const declarator_t, entry )
1856 if (decl->var->name) {
1857 type_t *cur;
1858 var_t *name;
1860 cur = find_type(decl->var->name, 0);
1863 * MIDL allows shadowing types that are declared in imported files.
1864 * We don't throw an error in this case and instead add a new type
1865 * (which is earlier on the list in hash table, so it will be used
1866 * instead of shadowed type).
1868 * FIXME: We may consider string separated type tables for each input
1869 * for cleaner solution.
1871 if (cur && input_name == cur->loc_info.input_name)
1872 error_loc("%s: redefinition error; original definition was at %s:%d\n",
1873 cur->name, cur->loc_info.input_name,
1874 cur->loc_info.line_number);
1876 name = declare_var(attrs, decl_spec, decl, 0);
1877 cur = type_new_alias(name->type, name->name);
1878 cur->attrs = attrs;
1880 if (is_incomplete(cur))
1881 add_incomplete(cur);
1882 reg_type(cur, cur->name, 0);
1885 return type;
1888 type_t *find_type(const char *name, int t)
1890 struct rtype *cur = type_hash[hash_ident(name)];
1891 while (cur && (cur->t != t || strcmp(cur->name, name)))
1892 cur = cur->next;
1893 return cur ? cur->type : NULL;
1896 static type_t *find_type_or_error(const char *name, int t)
1898 type_t *type = find_type(name, t);
1899 if (!type) {
1900 error_loc("type '%s' not found\n", name);
1901 return NULL;
1903 return type;
1906 static type_t *find_type_or_error2(char *name, int t)
1908 type_t *tp = find_type_or_error(name, t);
1909 free(name);
1910 return tp;
1913 int is_type(const char *name)
1915 return find_type(name, 0) != NULL;
1918 type_t *get_type(enum type_type type, char *name, int t)
1920 type_t *tp;
1921 if (name) {
1922 tp = find_type(name, t);
1923 if (tp) {
1924 free(name);
1925 return tp;
1928 tp = make_type(type);
1929 tp->name = name;
1930 if (!name) return tp;
1931 return reg_type(tp, name, t);
1934 /***** constant repository *****/
1936 struct rconst {
1937 char *name;
1938 var_t *var;
1939 struct rconst *next;
1942 struct rconst *const_hash[HASHMAX];
1944 static var_t *reg_const(var_t *var)
1946 struct rconst *nc;
1947 int hash;
1948 if (!var->name) {
1949 error_loc("registering constant without name\n");
1950 return var;
1952 hash = hash_ident(var->name);
1953 nc = xmalloc(sizeof(struct rconst));
1954 nc->name = var->name;
1955 nc->var = var;
1956 nc->next = const_hash[hash];
1957 const_hash[hash] = nc;
1958 return var;
1961 var_t *find_const(const char *name, int f)
1963 struct rconst *cur = const_hash[hash_ident(name)];
1964 while (cur && strcmp(cur->name, name))
1965 cur = cur->next;
1966 if (!cur) {
1967 if (f) error_loc("constant '%s' not found\n", name);
1968 return NULL;
1970 return cur->var;
1973 static char *gen_name(void)
1975 static const char format[] = "__WIDL_%s_generated_name_%08lX";
1976 static unsigned long n = 0;
1977 static const char *file_id;
1978 static size_t size;
1979 char *name;
1981 if (! file_id)
1983 char *dst = dup_basename(input_name, ".idl");
1984 file_id = dst;
1986 for (; *dst; ++dst)
1987 if (! isalnum((unsigned char) *dst))
1988 *dst = '_';
1990 size = sizeof format - 7 + strlen(file_id) + 8;
1993 name = xmalloc(size);
1994 sprintf(name, format, file_id, n++);
1995 return name;
1998 struct allowed_attr
2000 unsigned int dce_compatible : 1;
2001 unsigned int acf : 1;
2002 unsigned int on_interface : 1;
2003 unsigned int on_function : 1;
2004 unsigned int on_arg : 1;
2005 unsigned int on_type : 1;
2006 unsigned int on_enum : 1;
2007 unsigned int on_struct : 1;
2008 unsigned int on_union : 1;
2009 unsigned int on_field : 1;
2010 unsigned int on_library : 1;
2011 unsigned int on_dispinterface : 1;
2012 unsigned int on_module : 1;
2013 unsigned int on_coclass : 1;
2014 const char *display_name;
2017 struct allowed_attr allowed_attr[] =
2019 /* attr { D ACF I Fn ARG T En St Un Fi L DI M C <display name> } */
2020 /* ATTR_AGGREGATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "aggregatable" },
2021 /* ATTR_ANNOTATION */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "annotation" },
2022 /* ATTR_APPOBJECT */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "appobject" },
2023 /* ATTR_ASYNC */ { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "async" },
2024 /* ATTR_ASYNCUUID */ { 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "async_uuid" },
2025 /* ATTR_AUTO_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "auto_handle" },
2026 /* ATTR_BINDABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "bindable" },
2027 /* ATTR_BROADCAST */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "broadcast" },
2028 /* ATTR_CALLAS */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "call_as" },
2029 /* ATTR_CALLCONV */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL },
2030 /* ATTR_CASE */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "case" },
2031 /* ATTR_CODE */ { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "code" },
2032 /* ATTR_COMMSTATUS */ { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "comm_status" },
2033 /* ATTR_CONST */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "const" },
2034 /* ATTR_CONTEXTHANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "context_handle" },
2035 /* ATTR_CONTROL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, "control" },
2036 /* ATTR_DECODE */ { 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "decode" },
2037 /* ATTR_DEFAULT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, "default" },
2038 /* ATTR_DEFAULTBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultbind" },
2039 /* ATTR_DEFAULTCOLLELEM */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultcollelem" },
2040 /* ATTR_DEFAULTVALUE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultvalue" },
2041 /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "defaultvtable" },
2042 /* ATTR_DISABLECONSISTENCYCHECK */{ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "disable_consistency_check" },
2043 /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL },
2044 /* ATTR_DISPLAYBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "displaybind" },
2045 /* ATTR_DLLNAME */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, "dllname" },
2046 /* ATTR_DUAL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "dual" },
2047 /* ATTR_ENABLEALLOCATE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "enable_allocate" },
2048 /* ATTR_ENCODE */ { 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "encode" },
2049 /* ATTR_ENDPOINT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "endpoint" },
2050 /* ATTR_ENTRY */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "entry" },
2051 /* ATTR_EXPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "explicit_handle" },
2052 /* ATTR_FAULTSTATUS */ { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "fault_status" },
2053 /* ATTR_FORCEALLOCATE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "force_allocate" },
2054 /* ATTR_HANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "handle" },
2055 /* ATTR_HELPCONTEXT */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpcontext" },
2056 /* ATTR_HELPFILE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpfile" },
2057 /* ATTR_HELPSTRING */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpstring" },
2058 /* ATTR_HELPSTRINGCONTEXT */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpstringcontext" },
2059 /* ATTR_HELPSTRINGDLL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpstringdll" },
2060 /* ATTR_HIDDEN */ { 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, "hidden" },
2061 /* ATTR_ID */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, "id" },
2062 /* ATTR_IDEMPOTENT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "idempotent" },
2063 /* ATTR_IGNORE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "ignore" },
2064 /* ATTR_IIDIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "iid_is" },
2065 /* ATTR_IMMEDIATEBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "immediatebind" },
2066 /* ATTR_IMPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "implicit_handle" },
2067 /* ATTR_IN */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "in" },
2068 /* ATTR_INLINE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inline" },
2069 /* ATTR_INPUTSYNC */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inputsync" },
2070 /* ATTR_LENGTHIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "length_is" },
2071 /* ATTR_LIBLCID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "lcid" },
2072 /* ATTR_LICENSED */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "licensed" },
2073 /* ATTR_LOCAL */ { 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "local" },
2074 /* ATTR_MAYBE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "maybe" },
2075 /* ATTR_MESSAGE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "message" },
2076 /* ATTR_NOCODE */ { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nocode" },
2077 /* ATTR_NONBROWSABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonbrowsable" },
2078 /* ATTR_NONCREATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "noncreatable" },
2079 /* ATTR_NONEXTENSIBLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonextensible" },
2080 /* ATTR_NOTIFY */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "notify" },
2081 /* ATTR_NOTIFYFLAG */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "notify_flag" },
2082 /* ATTR_OBJECT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "object" },
2083 /* ATTR_ODL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "odl" },
2084 /* ATTR_OLEAUTOMATION */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "oleautomation" },
2085 /* ATTR_OPTIMIZE */ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optimize" },
2086 /* ATTR_OPTIONAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optional" },
2087 /* ATTR_OUT */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "out" },
2088 /* ATTR_PARAMLCID */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "lcid" },
2089 /* ATTR_PARTIALIGNORE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "partial_ignore" },
2090 /* ATTR_POINTERDEFAULT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "pointer_default" },
2091 /* ATTR_POINTERTYPE */ { 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, "ref, unique or ptr" },
2092 /* ATTR_PROGID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "progid" },
2093 /* ATTR_PROPGET */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propget" },
2094 /* ATTR_PROPPUT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propput" },
2095 /* ATTR_PROPPUTREF */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propputref" },
2096 /* ATTR_PROXY */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "proxy" },
2097 /* ATTR_PUBLIC */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "public" },
2098 /* ATTR_RANGE */ { 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, "range" },
2099 /* ATTR_READONLY */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "readonly" },
2100 /* ATTR_REPRESENTAS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "represent_as" },
2101 /* ATTR_REQUESTEDIT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "requestedit" },
2102 /* ATTR_RESTRICTED */ { 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, "restricted" },
2103 /* ATTR_RETVAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "retval" },
2104 /* ATTR_SIZEIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "size_is" },
2105 /* ATTR_SOURCE */ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "source" },
2106 /* ATTR_STRICTCONTEXTHANDLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "strict_context_handle" },
2107 /* ATTR_STRING */ { 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, "string" },
2108 /* ATTR_SWITCHIS */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "switch_is" },
2109 /* ATTR_SWITCHTYPE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, "switch_type" },
2110 /* ATTR_THREADING */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "threading" },
2111 /* ATTR_TRANSMITAS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "transmit_as" },
2112 /* ATTR_UIDEFAULT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "uidefault" },
2113 /* ATTR_USESGETLASTERROR */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "usesgetlasterror" },
2114 /* ATTR_USERMARSHAL */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "user_marshal" },
2115 /* ATTR_UUID */ { 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "uuid" },
2116 /* ATTR_V1ENUM */ { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, "v1_enum" },
2117 /* ATTR_VARARG */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "vararg" },
2118 /* ATTR_VERSION */ { 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, "version" },
2119 /* ATTR_VIPROGID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "vi_progid" },
2120 /* ATTR_WIREMARSHAL */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "wire_marshal" },
2123 const char *get_attr_display_name(enum attr_type type)
2125 return allowed_attr[type].display_name;
2128 static attr_list_t *check_iface_attrs(const char *name, attr_list_t *attrs)
2130 const attr_t *attr;
2131 if (!attrs) return attrs;
2132 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2134 if (!allowed_attr[attr->type].on_interface)
2135 error_loc("inapplicable attribute %s for interface %s\n",
2136 allowed_attr[attr->type].display_name, name);
2137 if (attr->type == ATTR_IMPLICIT_HANDLE)
2139 const var_t *var = attr->u.pval;
2140 if (type_get_type( var->type) == TYPE_BASIC &&
2141 type_basic_get_type( var->type ) == TYPE_BASIC_HANDLE)
2142 continue;
2143 if (is_aliaschain_attr( var->type, ATTR_HANDLE ))
2144 continue;
2145 error_loc("attribute %s requires a handle type in interface %s\n",
2146 allowed_attr[attr->type].display_name, name);
2149 return attrs;
2152 static attr_list_t *check_function_attrs(const char *name, attr_list_t *attrs)
2154 const attr_t *attr;
2155 if (!attrs) return attrs;
2156 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2158 if (!allowed_attr[attr->type].on_function)
2159 error_loc("inapplicable attribute %s for function %s\n",
2160 allowed_attr[attr->type].display_name, name);
2162 return attrs;
2165 static void check_arg_attrs(const var_t *arg)
2167 const attr_t *attr;
2169 if (arg->attrs)
2171 LIST_FOR_EACH_ENTRY(attr, arg->attrs, const attr_t, entry)
2173 if (!allowed_attr[attr->type].on_arg)
2174 error_loc("inapplicable attribute %s for argument %s\n",
2175 allowed_attr[attr->type].display_name, arg->name);
2180 static attr_list_t *check_typedef_attrs(attr_list_t *attrs)
2182 const attr_t *attr;
2183 if (!attrs) return attrs;
2184 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2186 if (!allowed_attr[attr->type].on_type)
2187 error_loc("inapplicable attribute %s for typedef\n",
2188 allowed_attr[attr->type].display_name);
2190 return attrs;
2193 static attr_list_t *check_enum_attrs(attr_list_t *attrs)
2195 const attr_t *attr;
2196 if (!attrs) return attrs;
2197 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2199 if (!allowed_attr[attr->type].on_enum)
2200 error_loc("inapplicable attribute %s for enum\n",
2201 allowed_attr[attr->type].display_name);
2203 return attrs;
2206 static attr_list_t *check_struct_attrs(attr_list_t *attrs)
2208 const attr_t *attr;
2209 if (!attrs) return attrs;
2210 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2212 if (!allowed_attr[attr->type].on_struct)
2213 error_loc("inapplicable attribute %s for struct\n",
2214 allowed_attr[attr->type].display_name);
2216 return attrs;
2219 static attr_list_t *check_union_attrs(attr_list_t *attrs)
2221 const attr_t *attr;
2222 if (!attrs) return attrs;
2223 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2225 if (!allowed_attr[attr->type].on_union)
2226 error_loc("inapplicable attribute %s for union\n",
2227 allowed_attr[attr->type].display_name);
2229 return attrs;
2232 static attr_list_t *check_field_attrs(const char *name, attr_list_t *attrs)
2234 const attr_t *attr;
2235 if (!attrs) return attrs;
2236 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2238 if (!allowed_attr[attr->type].on_field)
2239 error_loc("inapplicable attribute %s for field %s\n",
2240 allowed_attr[attr->type].display_name, name);
2242 return attrs;
2245 static attr_list_t *check_library_attrs(const char *name, attr_list_t *attrs)
2247 const attr_t *attr;
2248 if (!attrs) return attrs;
2249 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2251 if (!allowed_attr[attr->type].on_library)
2252 error_loc("inapplicable attribute %s for library %s\n",
2253 allowed_attr[attr->type].display_name, name);
2255 return attrs;
2258 static attr_list_t *check_dispiface_attrs(const char *name, attr_list_t *attrs)
2260 const attr_t *attr;
2261 if (!attrs) return attrs;
2262 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2264 if (!allowed_attr[attr->type].on_dispinterface)
2265 error_loc("inapplicable attribute %s for dispinterface %s\n",
2266 allowed_attr[attr->type].display_name, name);
2268 return attrs;
2271 static attr_list_t *check_module_attrs(const char *name, attr_list_t *attrs)
2273 const attr_t *attr;
2274 if (!attrs) return attrs;
2275 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2277 if (!allowed_attr[attr->type].on_module)
2278 error_loc("inapplicable attribute %s for module %s\n",
2279 allowed_attr[attr->type].display_name, name);
2281 return attrs;
2284 static attr_list_t *check_coclass_attrs(const char *name, attr_list_t *attrs)
2286 const attr_t *attr;
2287 if (!attrs) return attrs;
2288 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2290 if (!allowed_attr[attr->type].on_coclass)
2291 error_loc("inapplicable attribute %s for coclass %s\n",
2292 allowed_attr[attr->type].display_name, name);
2294 return attrs;
2297 static int is_allowed_conf_type(const type_t *type)
2299 switch (type_get_type(type))
2301 case TYPE_ENUM:
2302 return TRUE;
2303 case TYPE_BASIC:
2304 switch (type_basic_get_type(type))
2306 case TYPE_BASIC_INT8:
2307 case TYPE_BASIC_INT16:
2308 case TYPE_BASIC_INT32:
2309 case TYPE_BASIC_INT64:
2310 case TYPE_BASIC_INT:
2311 case TYPE_BASIC_CHAR:
2312 case TYPE_BASIC_HYPER:
2313 case TYPE_BASIC_BYTE:
2314 case TYPE_BASIC_WCHAR:
2315 return TRUE;
2316 default:
2317 return FALSE;
2319 case TYPE_ALIAS:
2320 /* shouldn't get here because of type_get_type call above */
2321 assert(0);
2322 /* fall through */
2323 case TYPE_STRUCT:
2324 case TYPE_UNION:
2325 case TYPE_ENCAPSULATED_UNION:
2326 case TYPE_ARRAY:
2327 case TYPE_POINTER:
2328 case TYPE_VOID:
2329 case TYPE_MODULE:
2330 case TYPE_COCLASS:
2331 case TYPE_FUNCTION:
2332 case TYPE_INTERFACE:
2333 case TYPE_BITFIELD:
2334 return FALSE;
2336 return FALSE;
2339 static int is_ptr_guid_type(const type_t *type)
2341 /* first, make sure it is a pointer to something */
2342 if (!is_ptr(type)) return FALSE;
2344 /* second, make sure it is a pointer to something of size sizeof(GUID),
2345 * i.e. 16 bytes */
2346 return (type_memsize(type_pointer_get_ref(type)) == 16);
2349 static void check_conformance_expr_list(const char *attr_name, const var_t *arg, const type_t *container_type, expr_list_t *expr_list)
2351 expr_t *dim;
2352 struct expr_loc expr_loc;
2353 expr_loc.v = arg;
2354 expr_loc.attr = attr_name;
2355 if (expr_list) LIST_FOR_EACH_ENTRY(dim, expr_list, expr_t, entry)
2357 if (dim->type != EXPR_VOID)
2359 const type_t *expr_type = expr_resolve_type(&expr_loc, container_type, dim);
2360 if (!is_allowed_conf_type(expr_type))
2361 error_loc_info(&arg->loc_info, "expression must resolve to integral type <= 32bits for attribute %s\n",
2362 attr_name);
2367 static void check_remoting_fields(const var_t *var, type_t *type);
2369 /* checks that properties common to fields and arguments are consistent */
2370 static void check_field_common(const type_t *container_type,
2371 const char *container_name, const var_t *arg)
2373 type_t *type = arg->type;
2374 int more_to_do;
2375 const char *container_type_name;
2376 const char *var_type;
2378 switch (type_get_type(container_type))
2380 case TYPE_STRUCT:
2381 container_type_name = "struct";
2382 var_type = "field";
2383 break;
2384 case TYPE_UNION:
2385 container_type_name = "union";
2386 var_type = "arm";
2387 break;
2388 case TYPE_ENCAPSULATED_UNION:
2389 container_type_name = "encapsulated union";
2390 var_type = "arm";
2391 break;
2392 case TYPE_FUNCTION:
2393 container_type_name = "function";
2394 var_type = "parameter";
2395 break;
2396 default:
2397 /* should be no other container types */
2398 assert(0);
2399 return;
2402 if (is_attr(arg->attrs, ATTR_LENGTHIS) &&
2403 (is_attr(arg->attrs, ATTR_STRING) || is_aliaschain_attr(arg->type, ATTR_STRING)))
2404 error_loc_info(&arg->loc_info,
2405 "string and length_is specified for argument %s are mutually exclusive attributes\n",
2406 arg->name);
2408 if (is_attr(arg->attrs, ATTR_SIZEIS))
2410 expr_list_t *size_is_exprs = get_attrp(arg->attrs, ATTR_SIZEIS);
2411 check_conformance_expr_list("size_is", arg, container_type, size_is_exprs);
2413 if (is_attr(arg->attrs, ATTR_LENGTHIS))
2415 expr_list_t *length_is_exprs = get_attrp(arg->attrs, ATTR_LENGTHIS);
2416 check_conformance_expr_list("length_is", arg, container_type, length_is_exprs);
2418 if (is_attr(arg->attrs, ATTR_IIDIS))
2420 struct expr_loc expr_loc;
2421 expr_t *expr = get_attrp(arg->attrs, ATTR_IIDIS);
2422 if (expr->type != EXPR_VOID)
2424 const type_t *expr_type;
2425 expr_loc.v = arg;
2426 expr_loc.attr = "iid_is";
2427 expr_type = expr_resolve_type(&expr_loc, container_type, expr);
2428 if (!expr_type || !is_ptr_guid_type(expr_type))
2429 error_loc_info(&arg->loc_info, "expression must resolve to pointer to GUID type for attribute iid_is\n");
2432 if (is_attr(arg->attrs, ATTR_SWITCHIS))
2434 struct expr_loc expr_loc;
2435 expr_t *expr = get_attrp(arg->attrs, ATTR_SWITCHIS);
2436 if (expr->type != EXPR_VOID)
2438 const type_t *expr_type;
2439 expr_loc.v = arg;
2440 expr_loc.attr = "switch_is";
2441 expr_type = expr_resolve_type(&expr_loc, container_type, expr);
2442 if (!expr_type || !is_allowed_conf_type(expr_type))
2443 error_loc_info(&arg->loc_info, "expression must resolve to integral type <= 32bits for attribute %s\n",
2444 expr_loc.attr);
2450 more_to_do = FALSE;
2452 switch (typegen_detect_type(type, arg->attrs, TDT_IGNORE_STRINGS))
2454 case TGT_STRUCT:
2455 case TGT_UNION:
2456 check_remoting_fields(arg, type);
2457 break;
2458 case TGT_INVALID:
2460 const char *reason = "is invalid";
2461 switch (type_get_type(type))
2463 case TYPE_VOID:
2464 reason = "cannot derive from void *";
2465 break;
2466 case TYPE_FUNCTION:
2467 reason = "cannot be a function pointer";
2468 break;
2469 case TYPE_BITFIELD:
2470 reason = "cannot be a bit-field";
2471 break;
2472 case TYPE_COCLASS:
2473 reason = "cannot be a class";
2474 break;
2475 case TYPE_INTERFACE:
2476 reason = "cannot be a non-pointer to an interface";
2477 break;
2478 case TYPE_MODULE:
2479 reason = "cannot be a module";
2480 break;
2481 default:
2482 break;
2484 error_loc_info(&arg->loc_info, "%s \'%s\' of %s \'%s\' %s\n",
2485 var_type, arg->name, container_type_name, container_name, reason);
2486 break;
2488 case TGT_CTXT_HANDLE:
2489 case TGT_CTXT_HANDLE_POINTER:
2490 if (type_get_type(container_type) != TYPE_FUNCTION)
2491 error_loc_info(&arg->loc_info,
2492 "%s \'%s\' of %s \'%s\' cannot be a context handle\n",
2493 var_type, arg->name, container_type_name,
2494 container_name);
2495 break;
2496 case TGT_STRING:
2498 const type_t *t = type;
2499 while (is_ptr(t))
2500 t = type_pointer_get_ref(t);
2501 if (is_aliaschain_attr(t, ATTR_RANGE))
2502 warning_loc_info(&arg->loc_info, "%s: range not verified for a string of ranged types\n", arg->name);
2503 break;
2505 case TGT_POINTER:
2506 type = type_pointer_get_ref(type);
2507 more_to_do = TRUE;
2508 break;
2509 case TGT_ARRAY:
2510 type = type_array_get_element(type);
2511 more_to_do = TRUE;
2512 break;
2513 case TGT_USER_TYPE:
2514 case TGT_IFACE_POINTER:
2515 case TGT_BASIC:
2516 case TGT_ENUM:
2517 case TGT_RANGE:
2518 /* nothing to do */
2519 break;
2521 } while (more_to_do);
2524 static void check_remoting_fields(const var_t *var, type_t *type)
2526 const var_t *field;
2527 const var_list_t *fields = NULL;
2529 type = type_get_real_type(type);
2531 if (type->checked)
2532 return;
2534 type->checked = TRUE;
2536 if (type_get_type(type) == TYPE_STRUCT)
2538 if (type_is_complete(type))
2539 fields = type_struct_get_fields(type);
2540 else
2541 error_loc_info(&var->loc_info, "undefined type declaration %s\n", type->name);
2543 else if (type_get_type(type) == TYPE_UNION || type_get_type(type) == TYPE_ENCAPSULATED_UNION)
2544 fields = type_union_get_cases(type);
2546 if (fields) LIST_FOR_EACH_ENTRY( field, fields, const var_t, entry )
2547 if (field->type) check_field_common(type, type->name, field);
2550 /* checks that arguments for a function make sense for marshalling and unmarshalling */
2551 static void check_remoting_args(const var_t *func)
2553 const char *funcname = func->name;
2554 const var_t *arg;
2556 if (func->type->details.function->args) LIST_FOR_EACH_ENTRY( arg, func->type->details.function->args, const var_t, entry )
2558 const type_t *type = arg->type;
2560 /* check that [out] parameters have enough pointer levels */
2561 if (is_attr(arg->attrs, ATTR_OUT))
2563 switch (typegen_detect_type(type, arg->attrs, TDT_ALL_TYPES))
2565 case TGT_BASIC:
2566 case TGT_ENUM:
2567 case TGT_RANGE:
2568 case TGT_STRUCT:
2569 case TGT_UNION:
2570 case TGT_CTXT_HANDLE:
2571 case TGT_USER_TYPE:
2572 error_loc_info(&arg->loc_info, "out parameter \'%s\' of function \'%s\' is not a pointer\n", arg->name, funcname);
2573 break;
2574 case TGT_IFACE_POINTER:
2575 error_loc_info(&arg->loc_info, "out interface pointer \'%s\' of function \'%s\' is not a double pointer\n", arg->name, funcname);
2576 break;
2577 case TGT_STRING:
2578 if (is_array(type))
2580 /* needs conformance or fixed dimension */
2581 if (type_array_has_conformance(type) &&
2582 type_array_get_conformance(type)->type != EXPR_VOID) break;
2583 if (!type_array_has_conformance(type) && type_array_get_dim(type)) break;
2585 if (is_attr( arg->attrs, ATTR_IN )) break;
2586 error_loc_info(&arg->loc_info, "out parameter \'%s\' of function \'%s\' cannot be an unsized string\n", arg->name, funcname);
2587 break;
2588 case TGT_INVALID:
2589 /* already error'd before we get here */
2590 case TGT_CTXT_HANDLE_POINTER:
2591 case TGT_POINTER:
2592 case TGT_ARRAY:
2593 /* OK */
2594 break;
2598 check_field_common(func->type, funcname, arg);
2601 if (type_get_type(type_function_get_rettype(func->type)) != TYPE_VOID)
2603 var_t var;
2604 var = *func;
2605 var.type = type_function_get_rettype(func->type);
2606 var.name = xstrdup("return value");
2607 check_field_common(func->type, funcname, &var);
2608 free(var.name);
2612 static void add_explicit_handle_if_necessary(const type_t *iface, var_t *func)
2614 unsigned char explicit_fc, implicit_fc;
2616 /* check for a defined binding handle */
2617 if (!get_func_handle_var( iface, func, &explicit_fc, &implicit_fc ) || !explicit_fc)
2619 /* no explicit handle specified so add
2620 * "[in] handle_t IDL_handle" as the first parameter to the
2621 * function */
2622 var_t *idl_handle = make_var(xstrdup("IDL_handle"));
2623 idl_handle->attrs = append_attr(NULL, make_attr(ATTR_IN));
2624 idl_handle->type = find_type_or_error("handle_t", 0);
2625 type_function_add_head_arg(func->type, idl_handle);
2629 static void check_functions(const type_t *iface, int is_inside_library)
2631 const statement_t *stmt;
2632 if (is_attr(iface->attrs, ATTR_EXPLICIT_HANDLE))
2634 STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
2636 var_t *func = stmt->u.var;
2637 add_explicit_handle_if_necessary(iface, func);
2640 if (!is_inside_library && !is_attr(iface->attrs, ATTR_LOCAL))
2642 STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
2644 const var_t *func = stmt->u.var;
2645 if (!is_attr(func->attrs, ATTR_LOCAL))
2646 check_remoting_args(func);
2651 static void check_statements(const statement_list_t *stmts, int is_inside_library)
2653 const statement_t *stmt;
2655 if (stmts) LIST_FOR_EACH_ENTRY(stmt, stmts, const statement_t, entry)
2657 if (stmt->type == STMT_LIBRARY)
2658 check_statements(stmt->u.lib->stmts, TRUE);
2659 else if (stmt->type == STMT_TYPE && type_get_type(stmt->u.type) == TYPE_INTERFACE)
2660 check_functions(stmt->u.type, is_inside_library);
2664 static void check_all_user_types(const statement_list_t *stmts)
2666 const statement_t *stmt;
2668 if (stmts) LIST_FOR_EACH_ENTRY(stmt, stmts, const statement_t, entry)
2670 if (stmt->type == STMT_LIBRARY)
2671 check_all_user_types(stmt->u.lib->stmts);
2672 else if (stmt->type == STMT_TYPE && type_get_type(stmt->u.type) == TYPE_INTERFACE &&
2673 !is_local(stmt->u.type->attrs))
2675 const statement_t *stmt_func;
2676 STATEMENTS_FOR_EACH_FUNC(stmt_func, type_iface_get_stmts(stmt->u.type)) {
2677 const var_t *func = stmt_func->u.var;
2678 check_for_additional_prototype_types(func->type->details.function->args);
2684 int is_valid_uuid(const char *s)
2686 int i;
2688 for (i = 0; i < 36; ++i)
2689 if (i == 8 || i == 13 || i == 18 || i == 23)
2691 if (s[i] != '-')
2692 return FALSE;
2694 else
2695 if (!isxdigit(s[i]))
2696 return FALSE;
2698 return s[i] == '\0';
2701 static statement_t *make_statement(enum statement_type type)
2703 statement_t *stmt = xmalloc(sizeof(*stmt));
2704 stmt->type = type;
2705 return stmt;
2708 static statement_t *make_statement_type_decl(type_t *type)
2710 statement_t *stmt = make_statement(STMT_TYPE);
2711 stmt->u.type = type;
2712 return stmt;
2715 static statement_t *make_statement_reference(type_t *type)
2717 statement_t *stmt = make_statement(STMT_TYPEREF);
2718 stmt->u.type = type;
2719 return stmt;
2722 static statement_t *make_statement_declaration(var_t *var)
2724 statement_t *stmt = make_statement(STMT_DECLARATION);
2725 stmt->u.var = var;
2726 if (var->stgclass == STG_EXTERN && var->eval)
2727 warning("'%s' initialised and declared extern\n", var->name);
2728 if (is_const_decl(var))
2730 if (var->eval)
2731 reg_const(var);
2733 else if (type_get_type(var->type) == TYPE_FUNCTION)
2734 check_function_attrs(var->name, var->attrs);
2735 else if (var->stgclass == STG_NONE || var->stgclass == STG_REGISTER)
2736 error_loc("instantiation of data is illegal\n");
2737 return stmt;
2740 static statement_t *make_statement_library(typelib_t *typelib)
2742 statement_t *stmt = make_statement(STMT_LIBRARY);
2743 stmt->u.lib = typelib;
2744 return stmt;
2747 static statement_t *make_statement_cppquote(const char *str)
2749 statement_t *stmt = make_statement(STMT_CPPQUOTE);
2750 stmt->u.str = str;
2751 return stmt;
2754 static statement_t *make_statement_importlib(const char *str)
2756 statement_t *stmt = make_statement(STMT_IMPORTLIB);
2757 stmt->u.str = str;
2758 return stmt;
2761 static statement_t *make_statement_import(const char *str)
2763 statement_t *stmt = make_statement(STMT_IMPORT);
2764 stmt->u.str = str;
2765 return stmt;
2768 static statement_t *make_statement_module(type_t *type)
2770 statement_t *stmt = make_statement(STMT_MODULE);
2771 stmt->u.type = type;
2772 return stmt;
2775 static statement_t *make_statement_typedef(declarator_list_t *decls)
2777 declarator_t *decl, *next;
2778 statement_t *stmt;
2779 type_list_t **type_list;
2781 if (!decls) return NULL;
2783 stmt = make_statement(STMT_TYPEDEF);
2784 stmt->u.type_list = NULL;
2785 type_list = &stmt->u.type_list;
2787 LIST_FOR_EACH_ENTRY_SAFE( decl, next, decls, declarator_t, entry )
2789 var_t *var = decl->var;
2790 type_t *type = find_type_or_error(var->name, 0);
2791 *type_list = xmalloc(sizeof(type_list_t));
2792 (*type_list)->type = type;
2793 (*type_list)->next = NULL;
2795 type_list = &(*type_list)->next;
2796 free(decl);
2797 free(var);
2800 return stmt;
2803 static statement_list_t *append_statements(statement_list_t *l1, statement_list_t *l2)
2805 if (!l2) return l1;
2806 if (!l1 || l1 == l2) return l2;
2807 list_move_tail (l1, l2);
2808 return l1;
2811 static attr_list_t *append_attribs(attr_list_t *l1, attr_list_t *l2)
2813 if (!l2) return l1;
2814 if (!l1 || l1 == l2) return l2;
2815 list_move_tail (l1, l2);
2816 return l1;
2819 static statement_list_t *append_statement(statement_list_t *list, statement_t *stmt)
2821 if (!stmt) return list;
2822 if (!list)
2824 list = xmalloc( sizeof(*list) );
2825 list_init( list );
2827 list_add_tail( list, &stmt->entry );
2828 return list;
2831 void init_loc_info(loc_info_t *i)
2833 i->input_name = input_name ? input_name : "stdin";
2834 i->line_number = line_number;
2835 i->near_text = parser_text;
2838 static void check_def(const type_t *t)
2840 if (t->defined)
2841 error_loc("%s: redefinition error; original definition was at %s:%d\n",
2842 t->name, t->loc_info.input_name, t->loc_info.line_number);