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
42 /* Berkeley yacc (byacc) doesn't seem to know about these */
43 /* Some *BSD supplied versions do define these though */
45 # define YYEMPTY (-1) /* Empty lookahead value of yychar */
48 # define YYLEX yylex()
51 #elif defined(YYBISON)
52 /* Bison was used for original development */
53 /* #define YYEMPTY -2 */
54 /* #define YYLEX yylex() */
57 /* No yacc we know yet */
58 # if !defined(YYEMPTY) || !defined(YYLEX)
59 # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
60 # elif defined(__GNUC__) /* gcc defines the #warning directive */
61 # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
62 /* #else we just take a chance that it works... */
66 #define YYERROR_VERBOSE
68 unsigned char pointer_default = RPC_FC_UP;
69 static int is_object_interface = FALSE;
71 typedef struct list typelist_t;
83 typedef struct _decl_spec_t
87 enum storage_class stgclass;
90 typelist_t incomplete_types = LIST_INIT(incomplete_types);
92 static void add_incomplete(type_t *t);
93 static void fix_incomplete(void);
94 static void fix_incomplete_types(type_t *complete_type);
96 static str_list_t *append_str(str_list_t *list, char *str);
97 static attr_list_t *append_attr(attr_list_t *list, attr_t *attr);
98 static attr_list_t *append_attr_list(attr_list_t *new_list, attr_list_t *old_list);
99 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);
100 static attr_t *make_attr(enum attr_type type);
101 static attr_t *make_attrv(enum attr_type type, unsigned long val);
102 static attr_t *make_attrp(enum attr_type type, void *val);
103 static expr_list_t *append_expr(expr_list_t *list, expr_t *expr);
104 static array_dims_t *append_array(array_dims_t *list, expr_t *expr);
105 static void set_type(var_t *v, decl_spec_t *decl_spec, const declarator_t *decl, int top);
106 static var_list_t *set_var_types(attr_list_t *attrs, decl_spec_t *decl_spec, declarator_list_t *decls);
107 static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface);
108 static ifref_t *make_ifref(type_t *iface);
109 static var_list_t *append_var(var_list_t *list, var_t *var);
110 static var_list_t *append_var_list(var_list_t *list, var_list_t *vars);
111 static var_t *make_var(char *name);
112 static declarator_list_t *append_declarator(declarator_list_t *list, declarator_t *p);
113 static declarator_t *make_declarator(var_t *var);
114 static func_list_t *append_func(func_list_t *list, func_t *func);
115 static func_t *make_func(var_t *def);
116 static type_t *make_class(char *name);
117 static type_t *make_safearray(type_t *type);
118 static type_t *make_builtin(char *name);
119 static type_t *make_int(int sign);
120 static typelib_t *make_library(const char *name, const attr_list_t *attrs);
121 static type_t *append_ptrchain_type(type_t *ptrchain, type_t *type);
123 static type_t *type_new_enum(char *name, var_list_t *enums);
124 static type_t *type_new_struct(char *name, int defined, var_list_t *fields);
125 static type_t *type_new_nonencapsulated_union(char *name, var_list_t *fields);
126 static type_t *type_new_encapsulated_union(char *name, var_t *switch_field, var_t *union_field, var_list_t *cases);
128 static type_t *reg_type(type_t *type, const char *name, int t);
129 static type_t *reg_typedefs(decl_spec_t *decl_spec, var_list_t *names, attr_list_t *attrs);
130 static type_t *find_type_or_error(const char *name, int t);
131 static type_t *find_type_or_error2(char *name, int t);
132 static type_t *get_type(unsigned char type, char *name, int t);
134 static var_t *reg_const(var_t *var);
136 static char *gen_name(void);
137 static void check_arg(var_t *arg);
138 static void check_statements(const statement_list_t *stmts, int is_inside_library);
139 static void check_all_user_types(const statement_list_t *stmts);
140 static attr_list_t *check_iface_attrs(const char *name, attr_list_t *attrs);
141 static attr_list_t *check_function_attrs(const char *name, attr_list_t *attrs);
142 static attr_list_t *check_typedef_attrs(attr_list_t *attrs);
143 static attr_list_t *check_enum_attrs(attr_list_t *attrs);
144 static attr_list_t *check_struct_attrs(attr_list_t *attrs);
145 static attr_list_t *check_union_attrs(attr_list_t *attrs);
146 static attr_list_t *check_field_attrs(const char *name, attr_list_t *attrs);
147 static attr_list_t *check_library_attrs(const char *name, attr_list_t *attrs);
148 static attr_list_t *check_dispiface_attrs(const char *name, attr_list_t *attrs);
149 static attr_list_t *check_module_attrs(const char *name, attr_list_t *attrs);
150 static attr_list_t *check_coclass_attrs(const char *name, attr_list_t *attrs);
151 const char *get_attr_display_name(enum attr_type type);
152 static void add_explicit_handle_if_necessary(var_t *func);
153 static void check_def(const type_t *t);
155 static statement_t *make_statement(enum statement_type type);
156 static statement_t *make_statement_type_decl(type_t *type);
157 static statement_t *make_statement_reference(type_t *type);
158 static statement_t *make_statement_declaration(var_t *var);
159 static statement_t *make_statement_library(typelib_t *typelib);
160 static statement_t *make_statement_cppquote(const char *str);
161 static statement_t *make_statement_importlib(const char *str);
162 static statement_t *make_statement_module(type_t *type);
163 static statement_t *make_statement_typedef(var_list_t *names);
164 static statement_t *make_statement_import(const char *str);
165 static statement_t *make_statement_typedef(var_list_t *names);
166 static statement_list_t *append_statement(statement_list_t *list, statement_t *stmt);
175 attr_list_t *attr_list;
176 str_list_t *str_list;
178 expr_list_t *expr_list;
179 array_dims_t *array_dims;
182 var_list_t *var_list;
183 declarator_t *declarator;
184 declarator_list_t *declarator_list;
186 func_list_t *func_list;
187 statement_t *statement;
188 statement_list_t *stmt_list;
190 ifref_list_t *ifref_list;
195 interface_info_t ifinfo;
197 struct _import_t *import;
198 struct _decl_spec_t *declspec;
199 enum storage_class stgclass;
202 %token <str> aIDENTIFIER
203 %token <str> aKNOWNTYPE
204 %token <num> aNUM aHEXNUM
206 %token <str> aSTRING aWSTRING
211 %token EQUALITY INEQUALITY
212 %token GREATEREQUAL LESSEQUAL
213 %token LOGICALOR LOGICALAND
214 %token tAGGREGATABLE tALLOCATE tAPPOBJECT tASYNC tASYNCUUID
215 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
216 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
217 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
218 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
220 %token tDEFAULTCOLLELEM
222 %token tDEFAULTVTABLE
224 %token tDISPINTERFACE
225 %token tDLLNAME tDOUBLE tDUAL
227 %token tENTRY tENUM tERRORSTATUST
228 %token tEXPLICITHANDLE tEXTERN
234 %token tHELPCONTEXT tHELPFILE
235 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
237 %token tHYPER tID tIDEMPOTENT
239 %token tIMMEDIATEBIND
240 %token tIMPLICITHANDLE
241 %token tIMPORT tIMPORTLIB
242 %token tIN tIN_LINE tINLINE
247 %token tLENGTHIS tLIBRARY
254 %token tNONEXTENSIBLE
256 %token tOBJECT tODL tOLEAUTOMATION
260 %token tPOINTERDEFAULT
262 %token tPROPGET tPROPPUT tPROPPUTREF
266 %token tREADONLY tREF
275 %token tSIZEIS tSIZEOF
280 %token tSTRICTCONTEXTHANDLE
281 %token tSTRING tSTRUCT
282 %token tSWITCH tSWITCHIS tSWITCHTYPE
294 %token tWCHAR tWIREMARSHAL
296 %type <attr> attribute type_qualifier function_specifier
297 %type <attr_list> m_attributes attributes attrib_list m_type_qual_list
298 %type <str_list> str_list
299 %type <expr> m_expr expr expr_const expr_int_const array
300 %type <expr_list> m_exprs /* exprs expr_list */ expr_list_int_const
301 %type <ifinfo> interfacehdr
302 %type <stgclass> storage_cls_spec
303 %type <declspec> decl_spec decl_spec_no_type m_decl_spec_no_type
304 %type <type> inherit interface interfacedef interfacedec
305 %type <type> dispinterface dispinterfacehdr dispinterfacedef
306 %type <type> module modulehdr moduledef
307 %type <type> base_type int_std
308 %type <type> enumdef structdef uniondef typedecl
310 %type <ifref> coclass_int
311 %type <ifref_list> coclass_ints
312 %type <var> arg ne_union_field union_field s_field case enum declaration
313 %type <var_list> m_args no_args args fields ne_union_fields cases enums enum_list dispint_props field
314 %type <var> m_ident ident
315 %type <declarator> declarator direct_declarator init_declarator
316 %type <declarator_list> declarator_list
318 %type <type> coclass coclasshdr coclassdef
319 %type <num> pointer_type version
320 %type <str> libraryhdr callconv cppquote importlib import t_ident
321 %type <uuid> uuid_string
322 %type <import> import_start
323 %type <typelib> library_start librarydef
324 %type <statement> statement typedef
325 %type <stmt_list> gbl_statements imp_statements int_statements dispint_meths
334 %left EQUALITY INEQUALITY
335 %left '<' '>' LESSEQUAL GREATEREQUAL
339 %right '!' '~' CAST PPTR POS NEG ADDRESSOF tSIZEOF
340 %left '.' MEMBERPTR '[' ']'
344 input: gbl_statements { fix_incomplete();
345 check_statements($1, FALSE);
346 check_all_user_types($1);
353 write_local_stubs($1);
357 gbl_statements: { $$ = NULL; }
358 | gbl_statements interfacedec { $$ = append_statement($1, make_statement_reference($2)); }
359 | gbl_statements interfacedef { $$ = append_statement($1, make_statement_type_decl($2)); }
360 | gbl_statements coclass ';' { $$ = $1;
361 reg_type($2, $2->name, 0);
363 | gbl_statements coclassdef { $$ = append_statement($1, make_statement_type_decl($2));
364 reg_type($2, $2->name, 0);
366 | gbl_statements moduledef { $$ = append_statement($1, make_statement_module($2)); }
367 | gbl_statements librarydef { $$ = append_statement($1, make_statement_library($2)); }
368 | gbl_statements statement { $$ = append_statement($1, $2); }
371 imp_statements: { $$ = NULL; }
372 | imp_statements interfacedec { $$ = append_statement($1, make_statement_reference($2)); }
373 | imp_statements interfacedef { $$ = append_statement($1, make_statement_type_decl($2)); }
374 | imp_statements coclass ';' { $$ = $1; reg_type($2, $2->name, 0); }
375 | imp_statements coclassdef { $$ = append_statement($1, make_statement_type_decl($2));
376 reg_type($2, $2->name, 0);
378 | imp_statements moduledef { $$ = append_statement($1, make_statement_module($2)); }
379 | imp_statements statement { $$ = append_statement($1, $2); }
380 | imp_statements importlib { $$ = append_statement($1, make_statement_importlib($2)); }
381 | imp_statements librarydef { $$ = append_statement($1, make_statement_library($2)); }
384 int_statements: { $$ = NULL; }
385 | int_statements statement { $$ = append_statement($1, $2); }
393 cppquote { $$ = make_statement_cppquote($1); }
394 | typedecl ';' { $$ = make_statement_type_decl($1); }
395 | declaration ';' { $$ = make_statement_declaration($1); }
396 | import { $$ = make_statement_import($1); }
397 | typedef ';' { $$ = $1; }
404 | attributes enumdef { $$ = $2; $$->attrs = check_enum_attrs($1); }
405 | attributes structdef { $$ = $2; $$->attrs = check_struct_attrs($1); }
406 | attributes uniondef { $$ = $2; $$->attrs = check_union_attrs($1); }
409 cppquote: tCPPQUOTE '(' aSTRING ')' { $$ = $3; }
411 import_start: tIMPORT aSTRING ';' { assert(yychar == YYEMPTY);
412 $$ = xmalloc(sizeof(struct _import_t));
414 $$->import_performed = do_import($2);
415 if (!$$->import_performed) yychar = aEOF;
419 import: import_start imp_statements aEOF { $$ = $1->name;
420 if ($1->import_performed) pop_import();
425 importlib: tIMPORTLIB '(' aSTRING ')'
426 semicolon_opt { $$ = $3; if(!parse_only) add_importlib($3); }
429 libraryhdr: tLIBRARY aIDENTIFIER { $$ = $2; }
431 library_start: attributes libraryhdr '{' { $$ = make_library($2, check_library_attrs($2, $1));
432 if (!parse_only) start_typelib($$);
435 librarydef: library_start imp_statements '}'
436 semicolon_opt { $$ = $1;
438 if (!parse_only) end_typelib();
442 m_args: { $$ = NULL; }
446 no_args: tVOID { $$ = NULL; }
449 args: arg { check_arg($1); $$ = append_var( NULL, $1 ); }
450 | args ',' arg { check_arg($3); $$ = append_var( $1, $3); }
454 /* split into two rules to get bison to resolve a tVOID conflict */
455 arg: attributes decl_spec declarator { $$ = $3->var;
457 if ($2->stgclass != STG_NONE && $2->stgclass != STG_REGISTER)
458 error_loc("invalid storage class for function parameter\n");
459 set_type($$, $2, $3, TRUE);
462 | decl_spec declarator { $$ = $2->var;
463 if ($1->stgclass != STG_NONE && $1->stgclass != STG_REGISTER)
464 error_loc("invalid storage class for function parameter\n");
465 set_type($$, $1, $2, TRUE);
470 array: '[' m_expr ']' { $$ = $2; }
471 | '[' '*' ']' { $$ = make_expr(EXPR_VOID); }
474 m_attributes: { $$ = NULL; }
479 '[' attrib_list ']' { $$ = $2; }
482 attrib_list: attribute { $$ = append_attr( NULL, $1 ); }
483 | attrib_list ',' attribute { $$ = append_attr( $1, $3 ); }
484 | attrib_list ']' '[' attribute { $$ = append_attr( $1, $4 ); }
487 str_list: aSTRING { $$ = append_str( NULL, $1 ); }
488 | str_list ',' aSTRING { $$ = append_str( $1, $3 ); }
491 attribute: { $$ = NULL; }
492 | tAGGREGATABLE { $$ = make_attr(ATTR_AGGREGATABLE); }
493 | tAPPOBJECT { $$ = make_attr(ATTR_APPOBJECT); }
494 | tASYNC { $$ = make_attr(ATTR_ASYNC); }
495 | tAUTOHANDLE { $$ = make_attr(ATTR_AUTO_HANDLE); }
496 | tBINDABLE { $$ = make_attr(ATTR_BINDABLE); }
497 | tBROADCAST { $$ = make_attr(ATTR_BROADCAST); }
498 | tCALLAS '(' ident ')' { $$ = make_attrp(ATTR_CALLAS, $3); }
499 | tCASE '(' expr_list_int_const ')' { $$ = make_attrp(ATTR_CASE, $3); }
500 | tCONTEXTHANDLE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); }
501 | tCONTEXTHANDLENOSERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
502 | tCONTEXTHANDLESERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
503 | tCONTROL { $$ = make_attr(ATTR_CONTROL); }
504 | tDEFAULT { $$ = make_attr(ATTR_DEFAULT); }
505 | tDEFAULTCOLLELEM { $$ = make_attr(ATTR_DEFAULTCOLLELEM); }
506 | tDEFAULTVALUE '(' expr_const ')' { $$ = make_attrp(ATTR_DEFAULTVALUE, $3); }
507 | tDEFAULTVTABLE { $$ = make_attr(ATTR_DEFAULTVTABLE); }
508 | tDISPLAYBIND { $$ = make_attr(ATTR_DISPLAYBIND); }
509 | tDLLNAME '(' aSTRING ')' { $$ = make_attrp(ATTR_DLLNAME, $3); }
510 | tDUAL { $$ = make_attr(ATTR_DUAL); }
511 | tENDPOINT '(' str_list ')' { $$ = make_attrp(ATTR_ENDPOINT, $3); }
512 | tENTRY '(' expr_const ')' { $$ = make_attrp(ATTR_ENTRY, $3); }
513 | tEXPLICITHANDLE { $$ = make_attr(ATTR_EXPLICIT_HANDLE); }
514 | tHANDLE { $$ = make_attr(ATTR_HANDLE); }
515 | tHELPCONTEXT '(' expr_int_const ')' { $$ = make_attrp(ATTR_HELPCONTEXT, $3); }
516 | tHELPFILE '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPFILE, $3); }
517 | tHELPSTRING '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRING, $3); }
518 | tHELPSTRINGCONTEXT '(' expr_int_const ')' { $$ = make_attrp(ATTR_HELPSTRINGCONTEXT, $3); }
519 | tHELPSTRINGDLL '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRINGDLL, $3); }
520 | tHIDDEN { $$ = make_attr(ATTR_HIDDEN); }
521 | tID '(' expr_int_const ')' { $$ = make_attrp(ATTR_ID, $3); }
522 | tIDEMPOTENT { $$ = make_attr(ATTR_IDEMPOTENT); }
523 | tIIDIS '(' expr ')' { $$ = make_attrp(ATTR_IIDIS, $3); }
524 | tIMMEDIATEBIND { $$ = make_attr(ATTR_IMMEDIATEBIND); }
525 | tIMPLICITHANDLE '(' tHANDLET aIDENTIFIER ')' { $$ = make_attrp(ATTR_IMPLICIT_HANDLE, $4); }
526 | tIN { $$ = make_attr(ATTR_IN); }
527 | tINPUTSYNC { $$ = make_attr(ATTR_INPUTSYNC); }
528 | tLENGTHIS '(' m_exprs ')' { $$ = make_attrp(ATTR_LENGTHIS, $3); }
529 | tLCID '(' expr_int_const ')' { $$ = make_attrp(ATTR_LIBLCID, $3); }
530 | tLOCAL { $$ = make_attr(ATTR_LOCAL); }
531 | tNONBROWSABLE { $$ = make_attr(ATTR_NONBROWSABLE); }
532 | tNONCREATABLE { $$ = make_attr(ATTR_NONCREATABLE); }
533 | tNONEXTENSIBLE { $$ = make_attr(ATTR_NONEXTENSIBLE); }
534 | tOBJECT { $$ = make_attr(ATTR_OBJECT); }
535 | tODL { $$ = make_attr(ATTR_ODL); }
536 | tOLEAUTOMATION { $$ = make_attr(ATTR_OLEAUTOMATION); }
537 | tOPTIONAL { $$ = make_attr(ATTR_OPTIONAL); }
538 | tOUT { $$ = make_attr(ATTR_OUT); }
539 | tPOINTERDEFAULT '(' pointer_type ')' { $$ = make_attrv(ATTR_POINTERDEFAULT, $3); }
540 | tPROPGET { $$ = make_attr(ATTR_PROPGET); }
541 | tPROPPUT { $$ = make_attr(ATTR_PROPPUT); }
542 | tPROPPUTREF { $$ = make_attr(ATTR_PROPPUTREF); }
543 | tPUBLIC { $$ = make_attr(ATTR_PUBLIC); }
544 | tRANGE '(' expr_int_const ',' expr_int_const ')'
545 { expr_list_t *list = append_expr( NULL, $3 );
546 list = append_expr( list, $5 );
547 $$ = make_attrp(ATTR_RANGE, list); }
548 | tREADONLY { $$ = make_attr(ATTR_READONLY); }
549 | tREQUESTEDIT { $$ = make_attr(ATTR_REQUESTEDIT); }
550 | tRESTRICTED { $$ = make_attr(ATTR_RESTRICTED); }
551 | tRETVAL { $$ = make_attr(ATTR_RETVAL); }
552 | tSIZEIS '(' m_exprs ')' { $$ = make_attrp(ATTR_SIZEIS, $3); }
553 | tSOURCE { $$ = make_attr(ATTR_SOURCE); }
554 | tSTRICTCONTEXTHANDLE { $$ = make_attr(ATTR_STRICTCONTEXTHANDLE); }
555 | tSTRING { $$ = make_attr(ATTR_STRING); }
556 | tSWITCHIS '(' expr ')' { $$ = make_attrp(ATTR_SWITCHIS, $3); }
557 | tSWITCHTYPE '(' type ')' { $$ = make_attrp(ATTR_SWITCHTYPE, $3); }
558 | tTRANSMITAS '(' type ')' { $$ = make_attrp(ATTR_TRANSMITAS, $3); }
559 | tUUID '(' uuid_string ')' { $$ = make_attrp(ATTR_UUID, $3); }
560 | tV1ENUM { $$ = make_attr(ATTR_V1ENUM); }
561 | tVARARG { $$ = make_attr(ATTR_VARARG); }
562 | tVERSION '(' version ')' { $$ = make_attrv(ATTR_VERSION, $3); }
563 | tWIREMARSHAL '(' type ')' { $$ = make_attrp(ATTR_WIREMARSHAL, $3); }
564 | pointer_type { $$ = make_attrv(ATTR_POINTERTYPE, $1); }
569 | aSTRING { if (!is_valid_uuid($1))
570 error_loc("invalid UUID: %s\n", $1);
571 $$ = parse_uuid($1); }
574 callconv: tCDECL { $$ = $<str>1; }
575 | tFASTCALL { $$ = $<str>1; }
576 | tPASCAL { $$ = $<str>1; }
577 | tSTDCALL { $$ = $<str>1; }
580 cases: { $$ = NULL; }
581 | cases case { $$ = append_var( $1, $2 ); }
584 case: tCASE expr_int_const ':' union_field { attr_t *a = make_attrp(ATTR_CASE, append_expr( NULL, $2 ));
585 $$ = $4; if (!$$) $$ = make_var(NULL);
586 $$->attrs = append_attr( $$->attrs, a );
588 | tDEFAULT ':' union_field { attr_t *a = make_attr(ATTR_DEFAULT);
589 $$ = $3; if (!$$) $$ = make_var(NULL);
590 $$->attrs = append_attr( $$->attrs, a );
594 enums: { $$ = NULL; }
595 | enum_list ',' { $$ = $1; }
599 enum_list: enum { if (!$1->eval)
600 $1->eval = make_exprl(EXPR_NUM, 0 /* default for first enum entry */);
601 $$ = append_var( NULL, $1 );
603 | enum_list ',' enum { if (!$3->eval)
605 var_t *last = LIST_ENTRY( list_tail($$), var_t, entry );
606 $3->eval = make_exprl(EXPR_NUM, last->eval->cval + 1);
608 $$ = append_var( $1, $3 );
612 enum: ident '=' expr_int_const { $$ = reg_const($1);
614 $$->type = make_int(0);
616 | ident { $$ = reg_const($1);
617 $$->type = make_int(0);
621 enumdef: tENUM t_ident '{' enums '}' { $$ = type_new_enum($2, $4); }
624 m_exprs: m_expr { $$ = append_expr( NULL, $1 ); }
625 | m_exprs ',' m_expr { $$ = append_expr( $1, $3 ); }
629 exprs: { $$ = make_expr(EXPR_VOID); }
634 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
638 m_expr: { $$ = make_expr(EXPR_VOID); }
642 expr: aNUM { $$ = make_exprl(EXPR_NUM, $1); }
643 | aHEXNUM { $$ = make_exprl(EXPR_HEXNUM, $1); }
644 | aDOUBLE { $$ = make_exprd(EXPR_DOUBLE, $1); }
645 | tFALSE { $$ = make_exprl(EXPR_TRUEFALSE, 0); }
646 | tNULL { $$ = make_exprl(EXPR_NUM, 0); }
647 | tTRUE { $$ = make_exprl(EXPR_TRUEFALSE, 1); }
648 | aSTRING { $$ = make_exprs(EXPR_STRLIT, $1); }
649 | aWSTRING { $$ = make_exprs(EXPR_WSTRLIT, $1); }
650 | aIDENTIFIER { $$ = make_exprs(EXPR_IDENTIFIER, $1); }
651 | expr '?' expr ':' expr { $$ = make_expr3(EXPR_COND, $1, $3, $5); }
652 | expr LOGICALOR expr { $$ = make_expr2(EXPR_LOGOR, $1, $3); }
653 | expr LOGICALAND expr { $$ = make_expr2(EXPR_LOGAND, $1, $3); }
654 | expr '|' expr { $$ = make_expr2(EXPR_OR , $1, $3); }
655 | expr '^' expr { $$ = make_expr2(EXPR_XOR, $1, $3); }
656 | expr '&' expr { $$ = make_expr2(EXPR_AND, $1, $3); }
657 | expr EQUALITY expr { $$ = make_expr2(EXPR_EQUALITY, $1, $3); }
658 | expr INEQUALITY expr { $$ = make_expr2(EXPR_INEQUALITY, $1, $3); }
659 | expr '>' expr { $$ = make_expr2(EXPR_GTR, $1, $3); }
660 | expr '<' expr { $$ = make_expr2(EXPR_LESS, $1, $3); }
661 | expr GREATEREQUAL expr { $$ = make_expr2(EXPR_GTREQL, $1, $3); }
662 | expr LESSEQUAL expr { $$ = make_expr2(EXPR_LESSEQL, $1, $3); }
663 | expr SHL expr { $$ = make_expr2(EXPR_SHL, $1, $3); }
664 | expr SHR expr { $$ = make_expr2(EXPR_SHR, $1, $3); }
665 | expr '+' expr { $$ = make_expr2(EXPR_ADD, $1, $3); }
666 | expr '-' expr { $$ = make_expr2(EXPR_SUB, $1, $3); }
667 | expr '%' expr { $$ = make_expr2(EXPR_MOD, $1, $3); }
668 | expr '*' expr { $$ = make_expr2(EXPR_MUL, $1, $3); }
669 | expr '/' expr { $$ = make_expr2(EXPR_DIV, $1, $3); }
670 | '!' expr { $$ = make_expr1(EXPR_LOGNOT, $2); }
671 | '~' expr { $$ = make_expr1(EXPR_NOT, $2); }
672 | '+' expr %prec POS { $$ = make_expr1(EXPR_POS, $2); }
673 | '-' expr %prec NEG { $$ = make_expr1(EXPR_NEG, $2); }
674 | '&' expr %prec ADDRESSOF { $$ = make_expr1(EXPR_ADDRESSOF, $2); }
675 | '*' expr %prec PPTR { $$ = make_expr1(EXPR_PPTR, $2); }
676 | expr MEMBERPTR aIDENTIFIER { $$ = make_expr2(EXPR_MEMBER, make_expr1(EXPR_PPTR, $1), make_exprs(EXPR_IDENTIFIER, $3)); }
677 | expr '.' aIDENTIFIER { $$ = make_expr2(EXPR_MEMBER, $1, make_exprs(EXPR_IDENTIFIER, $3)); }
678 | '(' type ')' expr %prec CAST { $$ = make_exprt(EXPR_CAST, $2, $4); }
679 | tSIZEOF '(' type ')' { $$ = make_exprt(EXPR_SIZEOF, $3, NULL); }
680 | expr '[' expr ']' { $$ = make_expr2(EXPR_ARRAY, $1, $3); }
681 | '(' expr ')' { $$ = $2; }
684 expr_list_int_const: expr_int_const { $$ = append_expr( NULL, $1 ); }
685 | expr_list_int_const ',' expr_int_const { $$ = append_expr( $1, $3 ); }
688 expr_int_const: expr { $$ = $1;
690 error_loc("expression is not an integer constant\n");
694 expr_const: expr { $$ = $1;
695 if (!$$->is_const && $$->type != EXPR_STRLIT && $$->type != EXPR_WSTRLIT)
696 error_loc("expression is not constant\n");
700 fields: { $$ = NULL; }
701 | fields field { $$ = append_var_list($1, $2); }
704 field: m_attributes decl_spec declarator_list ';'
705 { const char *first = LIST_ENTRY(list_head($3), declarator_t, entry)->var->name;
706 check_field_attrs(first, $1);
707 $$ = set_var_types($1, $2, $3);
709 | m_attributes uniondef ';' { var_t *v = make_var(NULL);
710 v->type = $2; v->attrs = $1;
711 $$ = append_var(NULL, v);
716 s_field ';' { $$ = $1; }
717 | attributes ';' { $$ = make_var(NULL); $$->attrs = $1; }
720 ne_union_fields: { $$ = NULL; }
721 | ne_union_fields ne_union_field { $$ = append_var( $1, $2 ); }
725 s_field ';' { $$ = $1; }
729 s_field: m_attributes decl_spec declarator { $$ = $3->var;
730 $$->attrs = check_field_attrs($$->name, $1);
731 set_type($$, $2, $3, FALSE);
737 m_attributes decl_spec declarator { var_t *v = $3->var;
738 v->attrs = check_function_attrs(v->name, $1);
739 set_type(v, $2, $3, FALSE);
746 attributes decl_spec init_declarator
749 set_type($$, $2, $3, FALSE);
752 | decl_spec init_declarator { $$ = $2->var;
753 set_type($$, $1, $2, FALSE);
758 m_ident: { $$ = NULL; }
762 t_ident: { $$ = NULL; }
763 | aIDENTIFIER { $$ = $1; }
764 | aKNOWNTYPE { $$ = $1; }
767 ident: aIDENTIFIER { $$ = make_var($1); }
768 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
769 | aKNOWNTYPE { $$ = make_var($<str>1); }
772 base_type: tBYTE { $$ = make_builtin($<str>1); }
773 | tWCHAR { $$ = make_builtin($<str>1); }
775 | tSIGNED int_std { $$ = $2; $$->sign = 1; }
776 | tUNSIGNED int_std { $$ = $2; $$->sign = -1;
778 case RPC_FC_CHAR: break;
779 case RPC_FC_SMALL: $$->type = RPC_FC_USMALL; break;
780 case RPC_FC_SHORT: $$->type = RPC_FC_USHORT; break;
781 case RPC_FC_LONG: $$->type = RPC_FC_ULONG; break;
783 if ($$->name[0] == 'h') /* hyper, as opposed to __int64 */
785 $$ = type_new_alias($$, "MIDL_uhyper");
792 | tUNSIGNED { $$ = make_int(-1); }
793 | tFLOAT { $$ = make_builtin($<str>1); }
794 | tSINGLE { $$ = find_type("float", 0); }
795 | tDOUBLE { $$ = make_builtin($<str>1); }
796 | tBOOLEAN { $$ = make_builtin($<str>1); }
797 | tERRORSTATUST { $$ = make_builtin($<str>1); }
798 | tHANDLET { $$ = make_builtin($<str>1); }
805 int_std: tINT { $$ = make_builtin($<str>1); }
806 | tSHORT m_int { $$ = make_builtin($<str>1); }
807 | tSMALL { $$ = make_builtin($<str>1); }
808 | tLONG m_int { $$ = make_builtin($<str>1); }
809 | tHYPER m_int { $$ = make_builtin($<str>1); }
810 | tINT64 { $$ = make_builtin($<str>1); }
811 | tCHAR { $$ = make_builtin($<str>1); }
814 coclass: tCOCLASS aIDENTIFIER { $$ = make_class($2); }
815 | tCOCLASS aKNOWNTYPE { $$ = find_type($2, 0);
816 if (type_get_type_detect_alias($$) != TYPE_COCLASS)
817 error_loc("%s was not declared a coclass at %s:%d\n",
818 $2, $$->loc_info.input_name,
819 $$->loc_info.line_number);
823 coclasshdr: attributes coclass { $$ = $2;
825 $$->attrs = check_coclass_attrs($2->name, $1);
829 coclassdef: coclasshdr '{' coclass_ints '}' semicolon_opt
830 { $$ = type_coclass_define($1, $3); }
833 coclass_ints: { $$ = NULL; }
834 | coclass_ints coclass_int { $$ = append_ifref( $1, $2 ); }
838 m_attributes interfacedec { $$ = make_ifref($2); $$->attrs = $1; }
841 dispinterface: tDISPINTERFACE aIDENTIFIER { $$ = get_type(RPC_FC_IP, $2, 0); }
842 | tDISPINTERFACE aKNOWNTYPE { $$ = get_type(RPC_FC_IP, $2, 0); }
845 dispinterfacehdr: attributes dispinterface { attr_t *attrs;
846 is_object_interface = TRUE;
849 attrs = make_attr(ATTR_DISPINTERFACE);
850 $$->attrs = append_attr( check_dispiface_attrs($2->name, $1), attrs );
855 dispint_props: tPROPERTIES ':' { $$ = NULL; }
856 | dispint_props s_field ';' { $$ = append_var( $1, $2 ); }
859 dispint_meths: tMETHODS ':' { $$ = NULL; }
860 | dispint_meths funcdef ';' { $$ = append_func( $1, $2 ); }
863 dispinterfacedef: dispinterfacehdr '{'
867 type_dispinterface_define($$, $3, $4);
870 '{' interface ';' '}' { $$ = $1;
871 type_dispinterface_define_from_iface($$, $3);
875 inherit: { $$ = NULL; }
876 | ':' aKNOWNTYPE { $$ = find_type_or_error2($2, 0); }
879 interface: tINTERFACE aIDENTIFIER { $$ = get_type(RPC_FC_IP, $2, 0); }
880 | tINTERFACE aKNOWNTYPE { $$ = get_type(RPC_FC_IP, $2, 0); }
883 interfacehdr: attributes interface { $$.interface = $2;
884 $$.old_pointer_default = pointer_default;
885 if (is_attr($1, ATTR_POINTERDEFAULT))
886 pointer_default = get_attrv($1, ATTR_POINTERDEFAULT);
887 is_object_interface = is_object($1);
889 $2->attrs = check_iface_attrs($2->name, $1);
894 interfacedef: interfacehdr inherit
895 '{' int_statements '}' semicolon_opt { $$ = $1.interface;
896 type_interface_define($$, $2, $4);
897 pointer_default = $1.old_pointer_default;
899 /* MIDL is able to import the definition of a base class from inside the
900 * definition of a derived class, I'll try to support it with this rule */
901 | interfacehdr ':' aIDENTIFIER
902 '{' import int_statements '}'
903 semicolon_opt { $$ = $1.interface;
904 type_interface_define($$, find_type_or_error2($3, 0), $6);
905 pointer_default = $1.old_pointer_default;
907 | dispinterfacedef semicolon_opt { $$ = $1; }
911 interface ';' { $$ = $1; }
912 | dispinterface ';' { $$ = $1; }
915 module: tMODULE aIDENTIFIER { $$ = type_new_module($2); }
916 | tMODULE aKNOWNTYPE { $$ = type_new_module($2); }
919 modulehdr: attributes module { $$ = $2;
920 $$->attrs = check_module_attrs($2->name, $1);
924 moduledef: modulehdr '{' int_statements '}'
925 semicolon_opt { $$ = $1;
926 type_module_define($$, $3);
931 tEXTERN { $$ = STG_EXTERN; }
932 | tSTATIC { $$ = STG_STATIC; }
933 | tREGISTER { $$ = STG_REGISTER; }
937 tINLINE { $$ = make_attr(ATTR_INLINE); }
941 tCONST { $$ = make_attr(ATTR_CONST); }
944 m_type_qual_list: { $$ = NULL; }
945 | m_type_qual_list type_qualifier { $$ = append_attr($1, $2); }
948 decl_spec: type m_decl_spec_no_type { $$ = make_decl_spec($1, $2, NULL, NULL, STG_NONE); }
949 | decl_spec_no_type type m_decl_spec_no_type
950 { $$ = make_decl_spec($2, $1, $3, NULL, STG_NONE); }
953 m_decl_spec_no_type: { $$ = NULL; }
958 type_qualifier m_decl_spec_no_type { $$ = make_decl_spec(NULL, $2, NULL, $1, STG_NONE); }
959 | function_specifier m_decl_spec_no_type { $$ = make_decl_spec(NULL, $2, NULL, $1, STG_NONE); }
960 | storage_cls_spec m_decl_spec_no_type { $$ = make_decl_spec(NULL, $2, NULL, NULL, $1); }
964 '*' m_type_qual_list declarator %prec PPTR
965 { $$ = $3; $$->type = append_ptrchain_type($$->type, type_new_pointer(NULL, $2)); }
966 | callconv declarator { $$ = $2; $$->type->attrs = append_attr($$->type->attrs, make_attrp(ATTR_CALLCONV, $1)); }
971 ident { $$ = make_declarator($1); }
972 | '(' declarator ')' { $$ = $2; }
973 | direct_declarator array { $$ = $1; $$->array = append_array($$->array, $2); }
974 | direct_declarator '(' m_args ')' { $$ = $1;
975 $$->func_type = append_ptrchain_type($$->type, type_new_function($3));
981 declarator { $$ = append_declarator( NULL, $1 ); }
982 | declarator_list ',' declarator { $$ = append_declarator( $1, $3 ); }
986 declarator { $$ = $1; }
987 | declarator '=' expr_const { $$ = $1; $1->var->eval = $3; }
991 tREF { $$ = RPC_FC_RP; }
992 | tUNIQUE { $$ = RPC_FC_UP; }
993 | tPTR { $$ = RPC_FC_FP; }
996 structdef: tSTRUCT t_ident '{' fields '}' { $$ = type_new_struct($2, TRUE, $4); }
999 type: tVOID { $$ = find_type_or_error("void", 0); }
1000 | aKNOWNTYPE { $$ = find_type_or_error($1, 0); }
1001 | base_type { $$ = $1; }
1002 | enumdef { $$ = $1; }
1003 | tENUM aIDENTIFIER { $$ = find_type_or_error2($2, tsENUM); }
1004 | structdef { $$ = $1; }
1005 | tSTRUCT aIDENTIFIER { $$ = type_new_struct($2, FALSE, NULL); }
1006 | uniondef { $$ = $1; }
1007 | tUNION aIDENTIFIER { $$ = find_type_or_error2($2, tsUNION); }
1008 | tSAFEARRAY '(' type ')' { $$ = make_safearray($3); }
1011 typedef: tTYPEDEF m_attributes decl_spec declarator_list
1012 { reg_typedefs($3, $4, check_typedef_attrs($2));
1013 $$ = make_statement_typedef($4);
1017 uniondef: tUNION t_ident '{' ne_union_fields '}'
1018 { $$ = type_new_nonencapsulated_union($2, $4); }
1020 tSWITCH '(' s_field ')'
1021 m_ident '{' cases '}' { $$ = type_new_encapsulated_union($2, $5, $7, $9); }
1025 aNUM { $$ = MAKEVERSION($1, 0); }
1026 | aNUM '.' aNUM { $$ = MAKEVERSION($1, $3); }
1031 static void decl_builtin(const char *name, unsigned char type)
1033 type_t *t = make_type(type, NULL);
1034 t->name = xstrdup(name);
1035 reg_type(t, name, 0);
1038 static type_t *make_builtin(char *name)
1040 /* NAME is strdup'd in the lexer */
1041 type_t *t = duptype(find_type_or_error(name, 0), 0);
1046 static type_t *make_int(int sign)
1048 type_t *t = duptype(find_type_or_error("int", 0), 1);
1052 t->type = t->type == RPC_FC_LONG ? RPC_FC_ULONG : RPC_FC_USHORT;
1057 void init_types(void)
1059 decl_builtin("void", 0);
1060 decl_builtin("byte", RPC_FC_BYTE);
1061 decl_builtin("wchar_t", RPC_FC_WCHAR);
1062 decl_builtin("int", RPC_FC_LONG); /* win32 */
1063 decl_builtin("short", RPC_FC_SHORT);
1064 decl_builtin("small", RPC_FC_SMALL);
1065 decl_builtin("long", RPC_FC_LONG);
1066 decl_builtin("hyper", RPC_FC_HYPER);
1067 decl_builtin("__int64", RPC_FC_HYPER);
1068 decl_builtin("char", RPC_FC_CHAR);
1069 decl_builtin("float", RPC_FC_FLOAT);
1070 decl_builtin("double", RPC_FC_DOUBLE);
1071 decl_builtin("boolean", RPC_FC_BYTE);
1072 decl_builtin("error_status_t", RPC_FC_ERROR_STATUS_T);
1073 decl_builtin("handle_t", RPC_FC_BIND_PRIMITIVE);
1076 static str_list_t *append_str(str_list_t *list, char *str)
1078 struct str_list_entry_t *entry;
1080 if (!str) return list;
1083 list = xmalloc( sizeof(*list) );
1086 entry = xmalloc( sizeof(*entry) );
1088 list_add_tail( list, &entry->entry );
1092 static attr_list_t *append_attr(attr_list_t *list, attr_t *attr)
1094 attr_t *attr_existing;
1095 if (!attr) return list;
1098 list = xmalloc( sizeof(*list) );
1101 LIST_FOR_EACH_ENTRY(attr_existing, list, attr_t, entry)
1102 if (attr_existing->type == attr->type)
1104 parser_warning("duplicate attribute %s\n", get_attr_display_name(attr->type));
1105 /* use the last attribute, like MIDL does */
1106 list_remove(&attr_existing->entry);
1109 list_add_tail( list, &attr->entry );
1113 static attr_list_t *move_attr(attr_list_t *dst, attr_list_t *src, enum attr_type type)
1116 if (!src) return dst;
1117 LIST_FOR_EACH_ENTRY(attr, src, attr_t, entry)
1118 if (attr->type == type)
1120 list_remove(&attr->entry);
1121 return append_attr(dst, attr);
1126 static attr_list_t *append_attr_list(attr_list_t *new_list, attr_list_t *old_list)
1130 if (!old_list) return new_list;
1132 while ((entry = list_head(old_list)))
1134 attr_t *attr = LIST_ENTRY(entry, attr_t, entry);
1136 new_list = append_attr(new_list, attr);
1141 static attr_list_t *dupattrs(const attr_list_t *list)
1143 attr_list_t *new_list;
1146 if (!list) return NULL;
1148 new_list = xmalloc( sizeof(*list) );
1149 list_init( new_list );
1150 LIST_FOR_EACH_ENTRY(attr, list, const attr_t, entry)
1152 attr_t *new_attr = xmalloc(sizeof(*new_attr));
1154 list_add_tail(new_list, &new_attr->entry);
1159 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)
1161 decl_spec_t *declspec = left ? left : right;
1164 declspec = xmalloc(sizeof(*declspec));
1165 declspec->type = NULL;
1166 declspec->attrs = NULL;
1167 declspec->stgclass = STG_NONE;
1169 declspec->type = type;
1170 if (left && declspec != left)
1172 declspec->attrs = append_attr_list(declspec->attrs, left->attrs);
1173 if (declspec->stgclass == STG_NONE)
1174 declspec->stgclass = left->stgclass;
1175 else if (left->stgclass != STG_NONE)
1176 error_loc("only one storage class can be specified\n");
1177 assert(!left->type);
1180 if (right && declspec != right)
1182 declspec->attrs = append_attr_list(declspec->attrs, right->attrs);
1183 if (declspec->stgclass == STG_NONE)
1184 declspec->stgclass = right->stgclass;
1185 else if (right->stgclass != STG_NONE)
1186 error_loc("only one storage class can be specified\n");
1187 assert(!right->type);
1191 declspec->attrs = append_attr(declspec->attrs, attr);
1192 if (declspec->stgclass == STG_NONE)
1193 declspec->stgclass = stgclass;
1194 else if (stgclass != STG_NONE)
1195 error_loc("only one storage class can be specified\n");
1197 /* apply attributes to type */
1198 if (type && declspec->attrs)
1201 declspec->type = duptype(type, 1);
1202 attrs = dupattrs(type->attrs);
1203 declspec->type->attrs = append_attr_list(attrs, declspec->attrs);
1204 declspec->attrs = NULL;
1210 static attr_t *make_attr(enum attr_type type)
1212 attr_t *a = xmalloc(sizeof(attr_t));
1218 static attr_t *make_attrv(enum attr_type type, unsigned long val)
1220 attr_t *a = xmalloc(sizeof(attr_t));
1226 static attr_t *make_attrp(enum attr_type type, void *val)
1228 attr_t *a = xmalloc(sizeof(attr_t));
1234 static expr_list_t *append_expr(expr_list_t *list, expr_t *expr)
1236 if (!expr) return list;
1239 list = xmalloc( sizeof(*list) );
1242 list_add_tail( list, &expr->entry );
1246 static array_dims_t *append_array(array_dims_t *list, expr_t *expr)
1248 if (!expr) return list;
1251 list = xmalloc( sizeof(*list) );
1254 list_add_tail( list, &expr->entry );
1258 static struct list type_pool = LIST_INIT(type_pool);
1265 type_t *alloc_type(void)
1267 type_pool_node_t *node = xmalloc(sizeof *node);
1268 list_add_tail(&type_pool, &node->link);
1272 void set_all_tfswrite(int val)
1274 type_pool_node_t *node;
1275 LIST_FOR_EACH_ENTRY(node, &type_pool, type_pool_node_t, link)
1276 node->data.tfswrite = val;
1279 void clear_all_offsets(void)
1281 type_pool_node_t *node;
1282 LIST_FOR_EACH_ENTRY(node, &type_pool, type_pool_node_t, link)
1283 node->data.typestring_offset = node->data.ptrdesc = 0;
1286 type_t *make_type(unsigned char type, type_t *ref)
1288 type_t *t = alloc_type();
1294 memset(&t->details, 0, sizeof(t->details));
1295 t->typestring_offset = 0;
1297 t->declarray = FALSE;
1298 t->ignore = (parse_only != 0);
1302 t->user_types_registered = FALSE;
1303 t->tfswrite = FALSE;
1305 t->is_alias = FALSE;
1306 t->typelib_idx = -1;
1307 init_loc_info(&t->loc_info);
1311 static type_t *type_new_enum(char *name, var_list_t *enums)
1313 type_t *t = get_type(RPC_FC_ENUM16, name, tsENUM);
1316 t->details.enumeration = xmalloc(sizeof(*t->details.enumeration));
1317 t->details.enumeration->enums = enums;
1320 t->details.enumeration = NULL;
1325 static type_t *type_new_struct(char *name, int defined, var_list_t *fields)
1327 type_t *tag_type = name ? find_type(name, tsSTRUCT) : NULL;
1328 type_t *t = make_type(RPC_FC_STRUCT, NULL);
1330 if (defined || (tag_type && tag_type->details.structure))
1332 if (tag_type && tag_type->details.structure)
1334 t->details.structure = tag_type->details.structure;
1335 t->type = tag_type->type;
1339 t->details.structure = xmalloc(sizeof(*t->details.structure));
1340 t->details.structure->fields = fields;
1347 reg_type(t, name, tsSTRUCT);
1354 static type_t *type_new_nonencapsulated_union(char *name, var_list_t *fields)
1356 type_t *t = get_type(RPC_FC_NON_ENCAPSULATED_UNION, name, tsUNION);
1357 t->details.structure = xmalloc(sizeof(*t->details.structure));
1358 t->details.structure->fields = fields;
1363 static type_t *type_new_encapsulated_union(char *name, var_t *switch_field, var_t *union_field, var_list_t *cases)
1365 type_t *t = get_type(RPC_FC_ENCAPSULATED_UNION, name, tsUNION);
1366 if (!union_field) union_field = make_var( xstrdup("tagged_union") );
1367 union_field->type = make_type(RPC_FC_NON_ENCAPSULATED_UNION, NULL);
1368 union_field->type->details.structure = xmalloc(sizeof(*union_field->type->details.structure));
1369 union_field->type->details.structure->fields = cases;
1370 union_field->type->defined = TRUE;
1371 t->details.structure = xmalloc(sizeof(*t->details.structure));
1372 t->details.structure->fields = append_var( NULL, switch_field );
1373 t->details.structure->fields = append_var( t->details.structure->fields, union_field );
1378 static void type_function_add_head_arg(type_t *type, var_t *arg)
1380 if (!type->details.function->args)
1382 type->details.function->args = xmalloc( sizeof(*type->details.function->args) );
1383 list_init( type->details.function->args );
1385 list_add_head( type->details.function->args, &arg->entry );
1388 static type_t *append_ptrchain_type(type_t *ptrchain, type_t *type)
1390 type_t *ptrchain_type;
1393 for (ptrchain_type = ptrchain; ptrchain_type->ref; ptrchain_type = ptrchain_type->ref)
1395 ptrchain_type->ref = type;
1399 static void set_type(var_t *v, decl_spec_t *decl_spec, const declarator_t *decl,
1402 expr_list_t *sizes = get_attrp(v->attrs, ATTR_SIZEIS);
1403 expr_list_t *lengs = get_attrp(v->attrs, ATTR_LENGTHIS);
1407 array_dims_t *arr = decl ? decl->array : NULL;
1408 type_t *func_type = decl ? decl->func_type : NULL;
1409 type_t *type = decl_spec->type;
1411 if (is_attr(type->attrs, ATTR_INLINE))
1414 error_loc("inline attribute applied to non-function type\n");
1418 /* move inline attribute from return type node to function node */
1419 for (t = func_type; is_ptr(t); t = type_pointer_get_ref(t))
1421 t->attrs = move_attr(t->attrs, type->attrs, ATTR_INLINE);
1425 /* add type onto the end of the pointers in pident->type */
1426 v->type = append_ptrchain_type(decl ? decl->type : NULL, type);
1427 v->stgclass = decl_spec->stgclass;
1429 /* the highest level of pointer specified should default to the var's ptr attr
1430 * or (RPC_FC_RP if not specified and it's a top level ptr), not
1431 * pointer_default so we need to fix that up here */
1434 int ptr_attr = get_attrv(v->attrs, ATTR_POINTERTYPE);
1435 const type_t *ptr = NULL;
1436 /* pointer attributes on the left side of the type belong to the function
1437 * pointer, if one is being declared */
1438 type_t **pt = func_type ? &func_type : &v->type;
1439 for (ptr = *pt; ptr && !ptr_attr; )
1441 ptr_attr = get_attrv(ptr->attrs, ATTR_POINTERTYPE);
1442 if (!ptr_attr && type_is_alias(ptr))
1443 ptr = type_alias_get_aliasee(ptr);
1447 if (ptr && is_ptr(ptr) && (ptr_attr || top))
1450 ptr_attr = RPC_FC_RP;
1451 if (ptr_attr != (*pt)->type)
1453 /* create new type to avoid changing original type */
1454 /* FIXME: this is a horrible hack - we might be changing the pointer
1455 * type of an alias here, so we also need corresponding hacks in
1456 * get_pointer_fc to handle this. The type of pointer that the type
1457 * ends up having is context sensitive and so we shouldn't be
1458 * setting it here, but rather determining it when it is used. */
1459 *pt = duptype(*pt, 1);
1460 (*pt)->type = ptr_attr;
1464 error_loc("%s: pointer attribute applied to non-pointer type\n", v->name);
1467 if (is_attr(v->attrs, ATTR_STRING) && !is_ptr(v->type) && !arr)
1468 error_loc("'%s': [string] attribute applied to non-pointer, non-array type\n",
1471 if (is_attr(v->attrs, ATTR_V1ENUM))
1473 if (type_get_type_detect_alias(v->type) == TYPE_ENUM)
1474 v->type->type = RPC_FC_ENUM32;
1476 error_loc("'%s': [v1_enum] attribute applied to non-enum type\n", v->name);
1481 if (arr) LIST_FOR_EACH_ENTRY_REV(dim, arr, expr_t, entry)
1484 error_loc("%s: only the first array dimension can be unspecified\n", v->name);
1489 error_loc("%s: array dimension must be positive\n", v->name);
1491 /* FIXME: should use a type_memsize that allows us to pass in a pointer size */
1494 unsigned int align = 0;
1495 unsigned int size = type_memsize(v->type, &align);
1497 if (0xffffffffu / size < dim->cval)
1498 error_loc("%s: total array size is too large\n", v->name);
1504 *ptype = type_new_array(NULL, *ptype, TRUE,
1505 dim->is_const ? dim->cval : 0,
1506 dim->is_const ? NULL : dim, NULL);
1510 if (sizes) LIST_FOR_EACH_ENTRY(dim, sizes, expr_t, entry)
1512 if (dim->type != EXPR_VOID)
1514 if (is_array(*ptype))
1516 if (type_array_get_conformance(*ptype)->is_const)
1517 error_loc("%s: cannot specify size_is for a fixed sized array\n", v->name);
1519 *ptype = type_new_array((*ptype)->name,
1520 type_array_get_element(*ptype), TRUE,
1523 else if (is_ptr(*ptype))
1524 *ptype = type_new_array((*ptype)->name, type_pointer_get_ref(*ptype), FALSE,
1527 error_loc("%s: size_is attribute applied to illegal type\n", v->name);
1530 ptype = &(*ptype)->ref;
1532 error_loc("%s: too many expressions in size_is attribute\n", v->name);
1536 if (lengs) LIST_FOR_EACH_ENTRY(dim, lengs, expr_t, entry)
1538 if (dim->type != EXPR_VOID)
1540 if (is_array(*ptype))
1542 *ptype = type_new_array((*ptype)->name,
1543 type_array_get_element(*ptype),
1544 (*ptype)->declarray,
1545 type_array_get_dim(*ptype),
1546 type_array_get_conformance(*ptype),
1550 error_loc("%s: length_is attribute applied to illegal type\n", v->name);
1553 ptype = &(*ptype)->ref;
1555 error_loc("%s: too many expressions in length_is attribute\n", v->name);
1558 /* v->type is currently pointing to the type on the left-side of the
1559 * declaration, so we need to fix this up so that it is the return type of the
1560 * function and make v->type point to the function side of the declaration */
1564 type_t *return_type = v->type;
1565 v->type = func_type;
1566 for (ft = v->type; is_ptr(ft); ft = type_pointer_get_ref(ft))
1568 assert(type_get_type_detect_alias(ft) == TYPE_FUNCTION);
1569 ft->ref = return_type;
1570 /* move calling convention attribute, if present, from pointer nodes to
1572 for (t = v->type; is_ptr(t); t = type_pointer_get_ref(t))
1573 ft->attrs = move_attr(ft->attrs, t->attrs, ATTR_CALLCONV);
1574 if (is_object_interface && !is_attr(ft->attrs, ATTR_CALLCONV))
1576 static char *stdmethodcalltype;
1577 if (!stdmethodcalltype) stdmethodcalltype = strdup("STDMETHODCALLTYPE");
1578 ft->attrs = append_attr(NULL, make_attrp(ATTR_CALLCONV, stdmethodcalltype));
1584 for (t = v->type; is_ptr(t); t = type_pointer_get_ref(t))
1585 if (is_attr(t->attrs, ATTR_CALLCONV))
1586 error_loc("calling convention applied to non-function-pointer type\n");
1590 static var_list_t *set_var_types(attr_list_t *attrs, decl_spec_t *decl_spec, declarator_list_t *decls)
1592 declarator_t *decl, *next;
1593 var_list_t *var_list = NULL;
1595 LIST_FOR_EACH_ENTRY_SAFE( decl, next, decls, declarator_t, entry )
1597 var_t *var = decl->var;
1600 set_type(var, decl_spec, decl, 0);
1601 var_list = append_var(var_list, var);
1607 static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface)
1609 if (!iface) return list;
1612 list = xmalloc( sizeof(*list) );
1615 list_add_tail( list, &iface->entry );
1619 static ifref_t *make_ifref(type_t *iface)
1621 ifref_t *l = xmalloc(sizeof(ifref_t));
1627 static var_list_t *append_var(var_list_t *list, var_t *var)
1629 if (!var) return list;
1632 list = xmalloc( sizeof(*list) );
1635 list_add_tail( list, &var->entry );
1639 static var_list_t *append_var_list(var_list_t *list, var_list_t *vars)
1641 if (!vars) return list;
1644 list = xmalloc( sizeof(*list) );
1647 list_move_tail( list, vars );
1651 static var_t *make_var(char *name)
1653 var_t *v = xmalloc(sizeof(var_t));
1658 v->stgclass = STG_NONE;
1659 init_loc_info(&v->loc_info);
1663 static declarator_list_t *append_declarator(declarator_list_t *list, declarator_t *d)
1665 if (!d) return list;
1667 list = xmalloc(sizeof(*list));
1670 list_add_tail(list, &d->entry);
1674 static declarator_t *make_declarator(var_t *var)
1676 declarator_t *d = xmalloc(sizeof(*d));
1679 d->func_type = NULL;
1684 static func_list_t *append_func(func_list_t *list, func_t *func)
1686 if (!func) return list;
1689 list = xmalloc( sizeof(*list) );
1692 list_add_tail( list, &func->entry );
1696 static func_t *make_func(var_t *def)
1698 func_t *f = xmalloc(sizeof(func_t));
1703 static type_t *make_class(char *name)
1705 type_t *c = make_type(RPC_FC_COCLASS, NULL);
1710 static type_t *make_safearray(type_t *type)
1712 type_t *sa = find_type_or_error("SAFEARRAY", 0);
1714 return make_type(pointer_default, sa);
1717 static typelib_t *make_library(const char *name, const attr_list_t *attrs)
1719 typelib_t *typelib = xmalloc(sizeof(*typelib));
1720 typelib->name = xstrdup(name);
1721 typelib->filename = NULL;
1722 typelib->attrs = attrs;
1723 list_init( &typelib->importlibs );
1729 static int hash_ident(const char *name)
1731 const char *p = name;
1733 /* a simple sum hash is probably good enough */
1738 return sum & (HASHMAX-1);
1741 /***** type repository *****/
1750 struct rtype *type_hash[HASHMAX];
1752 static type_t *reg_type(type_t *type, const char *name, int t)
1757 error_loc("registering named type without name\n");
1760 hash = hash_ident(name);
1761 nt = xmalloc(sizeof(struct rtype));
1765 nt->next = type_hash[hash];
1766 type_hash[hash] = nt;
1767 if ((t == tsSTRUCT || t == tsUNION))
1768 fix_incomplete_types(type);
1772 static int is_incomplete(const type_t *t)
1774 return !t->defined &&
1775 (type_get_type_detect_alias(t) == TYPE_STRUCT ||
1776 type_get_type_detect_alias(t) == TYPE_UNION ||
1777 type_get_type_detect_alias(t) == TYPE_ENCAPSULATED_UNION);
1780 static void add_incomplete(type_t *t)
1782 struct typenode *tn = xmalloc(sizeof *tn);
1784 list_add_tail(&incomplete_types, &tn->entry);
1787 static void fix_type(type_t *t)
1789 if (type_is_alias(t) && is_incomplete(t)) {
1790 type_t *ot = type_alias_get_aliasee(t);
1792 if (type_get_type_detect_alias(ot) == TYPE_STRUCT ||
1793 type_get_type_detect_alias(ot) == TYPE_UNION ||
1794 type_get_type_detect_alias(ot) == TYPE_ENCAPSULATED_UNION)
1795 t->details.structure = ot->details.structure;
1796 t->defined = ot->defined;
1800 static void fix_incomplete(void)
1802 struct typenode *tn, *next;
1804 LIST_FOR_EACH_ENTRY_SAFE(tn, next, &incomplete_types, struct typenode, entry) {
1806 list_remove(&tn->entry);
1811 static void fix_incomplete_types(type_t *complete_type)
1813 struct typenode *tn, *next;
1815 LIST_FOR_EACH_ENTRY_SAFE(tn, next, &incomplete_types, struct typenode, entry)
1817 if (type_is_equal(complete_type, tn->type))
1819 tn->type->details.structure = complete_type->details.structure;
1820 list_remove(&tn->entry);
1826 static type_t *reg_typedefs(decl_spec_t *decl_spec, declarator_list_t *decls, attr_list_t *attrs)
1828 const declarator_t *decl;
1829 int is_str = is_attr(attrs, ATTR_STRING);
1830 type_t *type = decl_spec->type;
1834 type_t *t = decl_spec->type;
1837 t = type_pointer_get_ref(t);
1839 if (type_get_type(t) != TYPE_BASIC &&
1840 (type_basic_get_fc(t) != RPC_FC_CHAR &&
1841 type_basic_get_fc(t) != RPC_FC_BYTE &&
1842 type_basic_get_fc(t) != RPC_FC_WCHAR))
1844 decl = LIST_ENTRY( list_head( decls ), const declarator_t, entry );
1845 error_loc("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
1850 /* We must generate names for tagless enum, struct or union.
1851 Typedef-ing a tagless enum, struct or union means we want the typedef
1852 to be included in a library hence the public attribute. */
1853 if ((type_get_type_detect_alias(type) == TYPE_ENUM ||
1854 type_get_type_detect_alias(type) == TYPE_STRUCT ||
1855 type_get_type_detect_alias(type) == TYPE_UNION ||
1856 type_get_type_detect_alias(type) == TYPE_ENCAPSULATED_UNION) &&
1857 !type->name && !parse_only)
1859 if (! is_attr(attrs, ATTR_PUBLIC))
1860 attrs = append_attr( attrs, make_attr(ATTR_PUBLIC) );
1861 type->name = gen_name();
1863 else if (is_attr(attrs, ATTR_UUID) && !is_attr(attrs, ATTR_PUBLIC))
1864 attrs = append_attr( attrs, make_attr(ATTR_PUBLIC) );
1866 LIST_FOR_EACH_ENTRY( decl, decls, const declarator_t, entry )
1868 var_t *name = decl->var;
1873 cur = find_type(name->name, 0);
1875 error_loc("%s: redefinition error; original definition was at %s:%d\n",
1876 cur->name, cur->loc_info.input_name,
1877 cur->loc_info.line_number);
1879 /* set the attributes to allow set_type to do some checks on them */
1880 name->attrs = attrs;
1881 set_type(name, decl_spec, decl, 0);
1882 cur = type_new_alias(name->type, name->name);
1885 if (is_incomplete(cur))
1886 add_incomplete(cur);
1887 reg_type(cur, cur->name, 0);
1893 type_t *find_type(const char *name, int t)
1895 struct rtype *cur = type_hash[hash_ident(name)];
1896 while (cur && (cur->t != t || strcmp(cur->name, name)))
1898 return cur ? cur->type : NULL;
1901 static type_t *find_type_or_error(const char *name, int t)
1903 type_t *type = find_type(name, t);
1905 error_loc("type '%s' not found\n", name);
1911 static type_t *find_type_or_error2(char *name, int t)
1913 type_t *tp = find_type_or_error(name, t);
1918 int is_type(const char *name)
1920 return find_type(name, 0) != NULL;
1923 static type_t *get_type(unsigned char type, char *name, int t)
1927 tp = find_type(name, t);
1933 tp = make_type(type, NULL);
1935 if (!name) return tp;
1936 return reg_type(tp, name, t);
1939 /***** constant repository *****/
1944 struct rconst *next;
1947 struct rconst *const_hash[HASHMAX];
1949 static var_t *reg_const(var_t *var)
1954 error_loc("registering constant without name\n");
1957 hash = hash_ident(var->name);
1958 nc = xmalloc(sizeof(struct rconst));
1959 nc->name = var->name;
1961 nc->next = const_hash[hash];
1962 const_hash[hash] = nc;
1966 var_t *find_const(const char *name, int f)
1968 struct rconst *cur = const_hash[hash_ident(name)];
1969 while (cur && strcmp(cur->name, name))
1972 if (f) error_loc("constant '%s' not found\n", name);
1978 static char *gen_name(void)
1980 static const char format[] = "__WIDL_%s_generated_name_%08lX";
1981 static unsigned long n = 0;
1982 static const char *file_id;
1988 char *dst = dup_basename(input_name, ".idl");
1992 if (! isalnum((unsigned char) *dst))
1995 size = sizeof format - 7 + strlen(file_id) + 8;
1998 name = xmalloc(size);
1999 sprintf(name, format, file_id, n++);
2005 unsigned int dce_compatible : 1;
2006 unsigned int acf : 1;
2007 unsigned int on_interface : 1;
2008 unsigned int on_function : 1;
2009 unsigned int on_arg : 1;
2010 unsigned int on_type : 1;
2011 unsigned int on_enum : 1;
2012 unsigned int on_struct : 1;
2013 unsigned int on_union : 1;
2014 unsigned int on_field : 1;
2015 unsigned int on_library : 1;
2016 unsigned int on_dispinterface : 1;
2017 unsigned int on_module : 1;
2018 unsigned int on_coclass : 1;
2019 const char *display_name;
2022 struct allowed_attr allowed_attr[] =
2024 /* attr { D ACF I Fn ARG T En St Un Fi L DI M C <display name> } */
2025 /* ATTR_AGGREGATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "aggregatable" },
2026 /* ATTR_APPOBJECT */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "appobject" },
2027 /* ATTR_ASYNC */ { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "async" },
2028 /* ATTR_AUTO_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "auto_handle" },
2029 /* ATTR_BINDABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "bindable" },
2030 /* ATTR_BROADCAST */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "broadcast" },
2031 /* ATTR_CALLAS */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "call_as" },
2032 /* ATTR_CALLCONV */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL },
2033 /* ATTR_CASE */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "case" },
2034 /* ATTR_CONST */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "const" },
2035 /* ATTR_CONTEXTHANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "context_handle" },
2036 /* ATTR_CONTROL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, "control" },
2037 /* ATTR_DEFAULT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, "default" },
2038 /* ATTR_DEFAULTCOLLELEM */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultcollelem" },
2039 /* ATTR_DEFAULTVALUE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultvalue" },
2040 /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "defaultvtable" },
2041 /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL },
2042 /* ATTR_DISPLAYBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "displaybind" },
2043 /* ATTR_DLLNAME */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, "dllname" },
2044 /* ATTR_DUAL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "dual" },
2045 /* ATTR_ENDPOINT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "endpoint" },
2046 /* ATTR_ENTRY */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "entry" },
2047 /* ATTR_EXPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "explicit_handle" },
2048 /* ATTR_HANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "handle" },
2049 /* ATTR_HELPCONTEXT */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpcontext" },
2050 /* ATTR_HELPFILE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpfile" },
2051 /* ATTR_HELPSTRING */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpstring" },
2052 /* ATTR_HELPSTRINGCONTEXT */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpstringcontext" },
2053 /* ATTR_HELPSTRINGDLL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpstringdll" },
2054 /* ATTR_HIDDEN */ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, "hidden" },
2055 /* ATTR_ID */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "id" },
2056 /* ATTR_IDEMPOTENT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "idempotent" },
2057 /* ATTR_IIDIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "iid_is" },
2058 /* ATTR_IMMEDIATEBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "immediatebind" },
2059 /* ATTR_IMPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "implicit_handle" },
2060 /* ATTR_IN */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "in" },
2061 /* ATTR_INLINE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inline" },
2062 /* ATTR_INPUTSYNC */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inputsync" },
2063 /* ATTR_LENGTHIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "length_is" },
2064 /* ATTR_LIBLCID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "lcid" },
2065 /* ATTR_LOCAL */ { 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "local" },
2066 /* ATTR_NONBROWSABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonbrowsable" },
2067 /* ATTR_NONCREATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "noncreatable" },
2068 /* ATTR_NONEXTENSIBLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonextensible" },
2069 /* ATTR_OBJECT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "object" },
2070 /* ATTR_ODL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "odl" },
2071 /* ATTR_OLEAUTOMATION */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "oleautomation" },
2072 /* ATTR_OPTIONAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optional" },
2073 /* ATTR_OUT */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "out" },
2074 /* ATTR_POINTERDEFAULT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "pointer_default" },
2075 /* ATTR_POINTERTYPE */ { 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, "ref, unique or ptr" },
2076 /* ATTR_PROPGET */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propget" },
2077 /* ATTR_PROPPUT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propput" },
2078 /* ATTR_PROPPUTREF */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propputref" },
2079 /* ATTR_PUBLIC */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "public" },
2080 /* ATTR_RANGE */ { 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, "range" },
2081 /* ATTR_READONLY */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "readonly" },
2082 /* ATTR_REQUESTEDIT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "requestedit" },
2083 /* ATTR_RESTRICTED */ { 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, "restricted" },
2084 /* ATTR_RETVAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "retval" },
2085 /* ATTR_SIZEIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "size_is" },
2086 /* ATTR_SOURCE */ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "source" },
2087 /* ATTR_STRICTCONTEXTHANDLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "strict_context_handle" },
2088 /* ATTR_STRING */ { 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, "string" },
2089 /* ATTR_SWITCHIS */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "switch_is" },
2090 /* ATTR_SWITCHTYPE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, "switch_type" },
2091 /* ATTR_TRANSMITAS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "transmit_as" },
2092 /* ATTR_UUID */ { 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "uuid" },
2093 /* ATTR_V1ENUM */ { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, "v1_enum" },
2094 /* ATTR_VARARG */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "vararg" },
2095 /* ATTR_VERSION */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "version" },
2096 /* ATTR_WIREMARSHAL */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "wire_marshal" },
2099 const char *get_attr_display_name(enum attr_type type)
2101 return allowed_attr[type].display_name;
2104 static attr_list_t *check_iface_attrs(const char *name, attr_list_t *attrs)
2107 if (!attrs) return attrs;
2108 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2110 if (!allowed_attr[attr->type].on_interface)
2111 error_loc("inapplicable attribute %s for interface %s\n",
2112 allowed_attr[attr->type].display_name, name);
2117 static attr_list_t *check_function_attrs(const char *name, attr_list_t *attrs)
2120 if (!attrs) return attrs;
2121 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2123 if (!allowed_attr[attr->type].on_function)
2124 error_loc("inapplicable attribute %s for function %s\n",
2125 allowed_attr[attr->type].display_name, name);
2130 static void check_arg(var_t *arg)
2132 const type_t *t = arg->type;
2135 if (type_get_type(t) == TYPE_VOID)
2136 error_loc("argument '%s' has void type\n", arg->name);
2140 LIST_FOR_EACH_ENTRY(attr, arg->attrs, const attr_t, entry)
2142 if (!allowed_attr[attr->type].on_arg)
2143 error_loc("inapplicable attribute %s for argument %s\n",
2144 allowed_attr[attr->type].display_name, arg->name);
2149 static attr_list_t *check_typedef_attrs(attr_list_t *attrs)
2152 if (!attrs) return attrs;
2153 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2155 if (!allowed_attr[attr->type].on_type)
2156 error_loc("inapplicable attribute %s for typedef\n",
2157 allowed_attr[attr->type].display_name);
2162 static attr_list_t *check_enum_attrs(attr_list_t *attrs)
2165 if (!attrs) return attrs;
2166 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2168 if (!allowed_attr[attr->type].on_enum)
2169 error_loc("inapplicable attribute %s for enum\n",
2170 allowed_attr[attr->type].display_name);
2175 static attr_list_t *check_struct_attrs(attr_list_t *attrs)
2178 if (!attrs) return attrs;
2179 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2181 if (!allowed_attr[attr->type].on_struct)
2182 error_loc("inapplicable attribute %s for struct\n",
2183 allowed_attr[attr->type].display_name);
2188 static attr_list_t *check_union_attrs(attr_list_t *attrs)
2191 if (!attrs) return attrs;
2192 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2194 if (!allowed_attr[attr->type].on_union)
2195 error_loc("inapplicable attribute %s for union\n",
2196 allowed_attr[attr->type].display_name);
2201 static attr_list_t *check_field_attrs(const char *name, attr_list_t *attrs)
2204 if (!attrs) return attrs;
2205 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2207 if (!allowed_attr[attr->type].on_field)
2208 error_loc("inapplicable attribute %s for field %s\n",
2209 allowed_attr[attr->type].display_name, name);
2214 static attr_list_t *check_library_attrs(const char *name, attr_list_t *attrs)
2217 if (!attrs) return attrs;
2218 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2220 if (!allowed_attr[attr->type].on_library)
2221 error_loc("inapplicable attribute %s for library %s\n",
2222 allowed_attr[attr->type].display_name, name);
2227 static attr_list_t *check_dispiface_attrs(const char *name, attr_list_t *attrs)
2230 if (!attrs) return attrs;
2231 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2233 if (!allowed_attr[attr->type].on_dispinterface)
2234 error_loc("inapplicable attribute %s for dispinterface %s\n",
2235 allowed_attr[attr->type].display_name, name);
2240 static attr_list_t *check_module_attrs(const char *name, attr_list_t *attrs)
2243 if (!attrs) return attrs;
2244 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2246 if (!allowed_attr[attr->type].on_module)
2247 error_loc("inapplicable attribute %s for module %s\n",
2248 allowed_attr[attr->type].display_name, name);
2253 static attr_list_t *check_coclass_attrs(const char *name, attr_list_t *attrs)
2256 if (!attrs) return attrs;
2257 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2259 if (!allowed_attr[attr->type].on_coclass)
2260 error_loc("inapplicable attribute %s for coclass %s\n",
2261 allowed_attr[attr->type].display_name, name);
2266 static int is_allowed_conf_type(const type_t *type)
2268 switch (type_get_type(type))
2273 switch (type_basic_get_fc(type))
2284 case RPC_FC_ERROR_STATUS_T:
2290 /* shouldn't get here because of type_get_type call above */
2295 case TYPE_ENCAPSULATED_UNION:
2302 case TYPE_INTERFACE:
2308 static int is_ptr_guid_type(const type_t *type)
2310 unsigned int align = 0;
2312 /* first, make sure it is a pointer to something */
2313 if (!is_ptr(type)) return FALSE;
2315 /* second, make sure it is a pointer to something of size sizeof(GUID),
2317 return (type_memsize(type_pointer_get_ref(type), &align) == 16);
2320 static void check_conformance_expr_list(const char *attr_name, const var_t *arg, const type_t *container_type, expr_list_t *expr_list)
2323 struct expr_loc expr_loc;
2325 expr_loc.attr = attr_name;
2326 if (expr_list) LIST_FOR_EACH_ENTRY(dim, expr_list, expr_t, entry)
2328 if (dim->type != EXPR_VOID)
2330 const type_t *expr_type = expr_resolve_type(&expr_loc, container_type, dim);
2331 if (!is_allowed_conf_type(expr_type))
2332 error_loc_info(&arg->loc_info, "expression must resolve to integral type <= 32bits for attribute %s\n",
2338 static void check_remoting_fields(const var_t *var, type_t *type);
2340 /* checks that properties common to fields and arguments are consistent */
2341 static void check_field_common(const type_t *container_type,
2342 const char *container_name, const var_t *arg)
2344 type_t *type = arg->type;
2346 const char *container_type_name = NULL;
2348 switch (type_get_type_detect_alias(type))
2351 container_type_name = "struct";
2354 container_type_name = "union";
2356 case TYPE_ENCAPSULATED_UNION:
2357 container_type_name = "encapsulated union";
2360 container_type_name = "function";
2366 if (is_attr(arg->attrs, ATTR_LENGTHIS) &&
2367 (is_attr(arg->attrs, ATTR_STRING) || is_aliaschain_attr(arg->type, ATTR_STRING)))
2368 error_loc_info(&arg->loc_info,
2369 "string and length_is specified for argument %s are mutually exclusive attributes\n",
2372 if (is_attr(arg->attrs, ATTR_SIZEIS))
2374 expr_list_t *size_is_exprs = get_attrp(arg->attrs, ATTR_SIZEIS);
2375 check_conformance_expr_list("size_is", arg, container_type, size_is_exprs);
2377 if (is_attr(arg->attrs, ATTR_LENGTHIS))
2379 expr_list_t *length_is_exprs = get_attrp(arg->attrs, ATTR_LENGTHIS);
2380 check_conformance_expr_list("length_is", arg, container_type, length_is_exprs);
2382 if (is_attr(arg->attrs, ATTR_IIDIS))
2384 struct expr_loc expr_loc;
2385 expr_t *expr = get_attrp(arg->attrs, ATTR_IIDIS);
2386 if (expr->type != EXPR_VOID)
2388 const type_t *expr_type;
2390 expr_loc.attr = "iid_is";
2391 expr_type = expr_resolve_type(&expr_loc, container_type, expr);
2392 if (!expr_type || !is_ptr_guid_type(expr_type))
2393 error_loc_info(&arg->loc_info, "expression must resolve to pointer to GUID type for attribute iid_is\n");
2396 if (is_attr(arg->attrs, ATTR_SWITCHIS))
2398 struct expr_loc expr_loc;
2399 expr_t *expr = get_attrp(arg->attrs, ATTR_SWITCHIS);
2400 if (expr->type != EXPR_VOID)
2402 const type_t *expr_type;
2404 expr_loc.attr = "switch_is";
2405 expr_type = expr_resolve_type(&expr_loc, container_type, expr);
2406 if (!expr_type || !is_allowed_conf_type(expr_type))
2407 error_loc_info(&arg->loc_info, "expression must resolve to integral type <= 32bits for attribute %s\n",
2416 switch (typegen_detect_type(type, arg->attrs, TDT_IGNORE_STRINGS))
2420 check_remoting_fields(arg, type);
2423 switch (type_get_type(type))
2426 error_loc_info(&arg->loc_info, "parameter \'%s\' of %s \'%s\' cannot derive from void *\n",
2427 arg->name, container_type_name, container_name);
2430 error_loc_info(&arg->loc_info, "parameter \'%s\' of %s \'%s\' cannot be a function pointer\n",
2431 arg->name, container_type_name, container_name);
2434 case TYPE_INTERFACE:
2441 case TGT_CTXT_HANDLE:
2442 case TGT_CTXT_HANDLE_POINTER:
2446 type = type_pointer_get_ref(type);
2450 type = type_array_get_element(type);
2455 case TGT_IFACE_POINTER:
2461 } while (more_to_do);
2464 static void check_remoting_fields(const var_t *var, type_t *type)
2467 const var_list_t *fields = NULL;
2469 type = type_get_real_type(type);
2474 type->checked = TRUE;
2476 if (type_get_type(type) == TYPE_STRUCT)
2478 if (type_is_complete(type))
2479 fields = type_struct_get_fields(type);
2481 error_loc_info(&var->loc_info, "undefined type declaration %s\n", type->name);
2483 else if (type_get_type(type) == TYPE_UNION || type_get_type(type) == TYPE_ENCAPSULATED_UNION)
2484 fields = type_union_get_cases(type);
2486 if (fields) LIST_FOR_EACH_ENTRY( field, fields, const var_t, entry )
2487 if (field->type) check_field_common(type, type->name, field);
2490 /* checks that arguments for a function make sense for marshalling and unmarshalling */
2491 static void check_remoting_args(const var_t *func)
2493 const char *funcname = func->name;
2496 if (func->type->details.function->args) LIST_FOR_EACH_ENTRY( arg, func->type->details.function->args, const var_t, entry )
2498 const type_t *type = arg->type;
2500 /* check that [out] parameters have enough pointer levels */
2501 if (is_attr(arg->attrs, ATTR_OUT))
2503 switch (typegen_detect_type(type, arg->attrs, TDT_ALL_TYPES))
2509 case TGT_CTXT_HANDLE:
2511 error_loc_info(&arg->loc_info, "out parameter \'%s\' of function \'%s\' is not a pointer\n", arg->name, funcname);
2513 case TGT_IFACE_POINTER:
2514 error_loc_info(&arg->loc_info, "out interface pointer \'%s\' of function \'%s\' is not a double pointer\n", arg->name, funcname);
2517 if (!is_array(type))
2523 /* already error'd before we get here */
2524 case TGT_CTXT_HANDLE_POINTER:
2532 check_field_common(func->type, funcname, arg);
2536 static void add_explicit_handle_if_necessary(var_t *func)
2538 const var_t* explicit_handle_var;
2539 const var_t* explicit_generic_handle_var = NULL;
2540 const var_t* context_handle_var = NULL;
2542 /* check for a defined binding handle */
2543 explicit_handle_var = get_explicit_handle_var(func);
2544 if (!explicit_handle_var)
2546 explicit_generic_handle_var = get_explicit_generic_handle_var(func);
2547 if (!explicit_generic_handle_var)
2549 context_handle_var = get_context_handle_var(func);
2550 if (!context_handle_var)
2552 /* no explicit handle specified so add
2553 * "[in] handle_t IDL_handle" as the first parameter to the
2555 var_t *idl_handle = make_var(xstrdup("IDL_handle"));
2556 idl_handle->attrs = append_attr(NULL, make_attr(ATTR_IN));
2557 idl_handle->type = find_type_or_error("handle_t", 0);
2558 type_function_add_head_arg(func->type, idl_handle);
2564 static void check_functions(const type_t *iface, int is_inside_library)
2566 const statement_t *stmt;
2567 if (is_attr(iface->attrs, ATTR_EXPLICIT_HANDLE))
2569 STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
2571 var_t *func = stmt->u.var;
2572 add_explicit_handle_if_necessary(func);
2575 if (!is_inside_library && !is_attr(iface->attrs, ATTR_LOCAL))
2577 STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
2579 const var_t *func = stmt->u.var;
2580 if (!is_attr(func->attrs, ATTR_LOCAL))
2581 check_remoting_args(func);
2586 static void check_statements(const statement_list_t *stmts, int is_inside_library)
2588 const statement_t *stmt;
2590 if (stmts) LIST_FOR_EACH_ENTRY(stmt, stmts, const statement_t, entry)
2592 if (stmt->type == STMT_LIBRARY)
2593 check_statements(stmt->u.lib->stmts, TRUE);
2594 else if (stmt->type == STMT_TYPE && type_get_type(stmt->u.type) == TYPE_INTERFACE)
2595 check_functions(stmt->u.type, is_inside_library);
2599 static void check_all_user_types(const statement_list_t *stmts)
2601 const statement_t *stmt;
2603 if (stmts) LIST_FOR_EACH_ENTRY(stmt, stmts, const statement_t, entry)
2605 if (stmt->type == STMT_LIBRARY)
2606 check_all_user_types(stmt->u.lib->stmts);
2607 else if (stmt->type == STMT_TYPE && type_get_type(stmt->u.type) == TYPE_INTERFACE &&
2608 !is_local(stmt->u.type->attrs))
2610 const statement_t *stmt_func;
2611 STATEMENTS_FOR_EACH_FUNC(stmt_func, type_iface_get_stmts(stmt->u.type)) {
2612 const var_t *func = stmt_func->u.var;
2613 check_for_additional_prototype_types(func->type->details.function->args);
2619 int is_valid_uuid(const char *s)
2623 for (i = 0; i < 36; ++i)
2624 if (i == 8 || i == 13 || i == 18 || i == 23)
2630 if (!isxdigit(s[i]))
2633 return s[i] == '\0';
2636 static statement_t *make_statement(enum statement_type type)
2638 statement_t *stmt = xmalloc(sizeof(*stmt));
2643 static statement_t *make_statement_type_decl(type_t *type)
2645 statement_t *stmt = make_statement(STMT_TYPE);
2646 stmt->u.type = type;
2650 static statement_t *make_statement_reference(type_t *type)
2652 statement_t *stmt = make_statement(STMT_TYPEREF);
2653 stmt->u.type = type;
2657 static statement_t *make_statement_declaration(var_t *var)
2659 statement_t *stmt = make_statement(STMT_DECLARATION);
2661 if (var->stgclass == STG_EXTERN && var->eval)
2662 warning("'%s' initialised and declared extern\n", var->name);
2663 if (is_const_decl(var))
2668 else if ((var->stgclass == STG_NONE || var->stgclass == STG_REGISTER) &&
2669 type_get_type(var->type) != TYPE_FUNCTION)
2670 error_loc("instantiation of data is illegal\n");
2674 static statement_t *make_statement_library(typelib_t *typelib)
2676 statement_t *stmt = make_statement(STMT_LIBRARY);
2677 stmt->u.lib = typelib;
2681 static statement_t *make_statement_cppquote(const char *str)
2683 statement_t *stmt = make_statement(STMT_CPPQUOTE);
2688 static statement_t *make_statement_importlib(const char *str)
2690 statement_t *stmt = make_statement(STMT_IMPORTLIB);
2695 static statement_t *make_statement_import(const char *str)
2697 statement_t *stmt = make_statement(STMT_IMPORT);
2702 static statement_t *make_statement_module(type_t *type)
2704 statement_t *stmt = make_statement(STMT_MODULE);
2705 stmt->u.type = type;
2709 static statement_t *make_statement_typedef(declarator_list_t *decls)
2711 declarator_t *decl, *next;
2713 type_list_t **type_list;
2715 if (!decls) return NULL;
2717 stmt = make_statement(STMT_TYPEDEF);
2718 stmt->u.type_list = NULL;
2719 type_list = &stmt->u.type_list;
2721 LIST_FOR_EACH_ENTRY_SAFE( decl, next, decls, declarator_t, entry )
2723 var_t *var = decl->var;
2724 type_t *type = find_type_or_error(var->name, 0);
2725 *type_list = xmalloc(sizeof(type_list_t));
2726 (*type_list)->type = type;
2727 (*type_list)->next = NULL;
2729 type_list = &(*type_list)->next;
2737 static statement_list_t *append_statement(statement_list_t *list, statement_t *stmt)
2739 if (!stmt) return list;
2742 list = xmalloc( sizeof(*list) );
2745 list_add_tail( list, &stmt->entry );
2749 void init_loc_info(loc_info_t *i)
2751 i->input_name = input_name ? input_name : "stdin";
2752 i->line_number = line_number;
2753 i->near_text = parser_text;
2756 static void check_def(const type_t *t)
2759 error_loc("%s: redefinition error; original definition was at %s:%d\n",
2760 t->name, t->loc_info.input_name, t->loc_info.line_number);