5 * Copyright 2002 Ove Kaaven
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * 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;
70 /* are we inside a library block? */
71 static int is_inside_library = FALSE;
73 typedef struct list typelist_t;
79 typelist_t incomplete_types = LIST_INIT(incomplete_types);
81 static void add_incomplete(type_t *t);
82 static void fix_incomplete(void);
84 static str_list_t *append_str(str_list_t *list, char *str);
85 static attr_list_t *append_attr(attr_list_t *list, attr_t *attr);
86 static attr_t *make_attr(enum attr_type type);
87 static attr_t *make_attrv(enum attr_type type, unsigned long val);
88 static attr_t *make_attrp(enum attr_type type, void *val);
89 static expr_t *make_expr(enum expr_type type);
90 static expr_t *make_exprl(enum expr_type type, long val);
91 static expr_t *make_exprd(enum expr_type type, double val);
92 static expr_t *make_exprs(enum expr_type type, char *val);
93 static expr_t *make_exprt(enum expr_type type, type_t *tref, expr_t *expr);
94 static expr_t *make_expr1(enum expr_type type, expr_t *expr);
95 static expr_t *make_expr2(enum expr_type type, expr_t *exp1, expr_t *exp2);
96 static expr_t *make_expr3(enum expr_type type, expr_t *expr1, expr_t *expr2, expr_t *expr3);
97 static type_t *make_type(unsigned char type, type_t *ref);
98 static expr_list_t *append_expr(expr_list_t *list, expr_t *expr);
99 static array_dims_t *append_array(array_dims_t *list, expr_t *expr);
100 static void set_type(var_t *v, type_t *type, const pident_t *pident, array_dims_t *arr, int top);
101 static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface);
102 static ifref_t *make_ifref(type_t *iface);
103 static var_list_t *append_var(var_list_t *list, var_t *var);
104 static var_t *make_var(char *name);
105 static pident_list_t *append_pident(pident_list_t *list, pident_t *p);
106 static pident_t *make_pident(var_t *var);
107 static func_list_t *append_func(func_list_t *list, func_t *func);
108 static func_t *make_func(var_t *def, var_list_t *args);
109 static type_t *make_class(char *name);
110 static type_t *make_safearray(type_t *type);
111 static type_t *make_builtin(char *name);
112 static type_t *make_int(int sign);
114 static type_t *reg_type(type_t *type, const char *name, int t);
115 static type_t *reg_typedefs(type_t *type, var_list_t *names, attr_list_t *attrs);
116 static type_t *find_type(const char *name, int t);
117 static type_t *find_type2(char *name, int t);
118 static type_t *get_type(unsigned char type, char *name, int t);
119 static type_t *get_typev(unsigned char type, var_t *name, int t);
120 static int get_struct_type(var_list_t *fields);
122 static var_t *reg_const(var_t *var);
123 static var_t *find_const(char *name, int f);
125 static void write_libid(const char *name, const attr_list_t *attr);
126 static void write_clsid(type_t *cls);
127 static void write_diid(type_t *iface);
128 static void write_iid(type_t *iface);
130 static int compute_method_indexes(type_t *iface);
131 static char *gen_name(void);
132 static void process_typedefs(var_list_t *names);
133 static void check_arg(var_t *arg);
134 static void check_functions(const type_t *iface);
135 static void check_all_user_types(ifref_list_t *ifaces);
136 static const attr_list_t *check_iface_attrs(const char *name, const attr_list_t *attrs);
137 static attr_list_t *check_function_attrs(const char *name, attr_list_t *attrs);
138 static attr_list_t *check_typedef_attrs(attr_list_t *attrs);
139 static attr_list_t *check_field_attrs(const char *name, attr_list_t *attrs);
140 static const attr_list_t *check_library_attrs(const char *name, const attr_list_t *attrs);
141 static attr_list_t *check_dispiface_attrs(const char *name, attr_list_t *attrs);
142 static const attr_list_t *check_module_attrs(const char *name, const attr_list_t *attrs);
143 static const attr_list_t *check_coclass_attrs(const char *name, const attr_list_t *attrs);
144 const char *get_attr_display_name(enum attr_type type);
145 static void add_explicit_handle_if_necessary(func_t *func);
154 attr_list_t *attr_list;
155 str_list_t *str_list;
157 expr_list_t *expr_list;
158 array_dims_t *array_dims;
161 var_list_t *var_list;
163 pident_list_t *pident_list;
165 func_list_t *func_list;
167 ifref_list_t *ifref_list;
172 interface_info_t ifinfo;
175 %token <str> aIDENTIFIER
176 %token <str> aKNOWNTYPE
177 %token <num> aNUM aHEXNUM
184 %token tAGGREGATABLE tALLOCATE tAPPOBJECT tASYNC tASYNCUUID
185 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
186 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
187 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
188 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
190 %token tDEFAULTCOLLELEM
192 %token tDEFAULTVTABLE
194 %token tDISPINTERFACE
195 %token tDLLNAME tDOUBLE tDUAL
197 %token tENTRY tENUM tERRORSTATUST
198 %token tEXPLICITHANDLE tEXTERN
204 %token tHELPCONTEXT tHELPFILE
205 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
207 %token tHYPER tID tIDEMPOTENT
209 %token tIMMEDIATEBIND
210 %token tIMPLICITHANDLE
211 %token tIMPORT tIMPORTLIB
217 %token tLENGTHIS tLIBRARY
224 %token tNONEXTENSIBLE
225 %token tOBJECT tODL tOLEAUTOMATION
229 %token tPOINTERDEFAULT
231 %token tPROPGET tPROPPUT tPROPPUTREF
235 %token tREADONLY tREF
243 %token tSIZEIS tSIZEOF
247 %token tSTRICTCONTEXTHANDLE
248 %token tSTRING tSTRUCT
249 %token tSWITCH tSWITCHIS tSWITCHTYPE
261 %token tWCHAR tWIREMARSHAL
263 %type <attr> attribute
264 %type <attr_list> m_attributes attributes attrib_list
265 %type <str_list> str_list
266 %type <expr> m_expr expr expr_const
267 %type <expr_list> m_exprs /* exprs expr_list */ expr_list_const
268 %type <array_dims> array array_list
269 %type <ifinfo> interfacehdr
270 %type <type> inherit interface interfacedef interfacedec
271 %type <type> dispinterface dispinterfacehdr dispinterfacedef
272 %type <type> module modulehdr moduledef
273 %type <type> base_type int_std
274 %type <type> enumdef structdef uniondef
276 %type <ifref> coclass_int
277 %type <ifref_list> gbl_statements coclass_ints
278 %type <var> arg field s_field case enum constdef externdef
279 %type <var_list> m_args no_args args fields cases enums enum_list dispint_props
280 %type <var> m_ident t_ident ident
281 %type <pident> pident func_ident direct_ident
282 %type <pident_list> pident_list
284 %type <func_list> int_statements dispint_meths
285 %type <type> coclass coclasshdr coclassdef
286 %type <num> pointer_type version
287 %type <str> libraryhdr callconv
288 %type <uuid> uuid_string
289 %type <num> import_start
298 %right '~' CAST PPTR NEG ADDRESSOF tSIZEOF
299 %left '.' MEMBERPTR '[' ']'
303 input: gbl_statements { fix_incomplete();
304 check_all_user_types($1);
312 gbl_statements: { $$ = NULL; }
313 | gbl_statements interfacedec { $$ = $1; }
314 | gbl_statements interfacedef { $$ = append_ifref( $1, make_ifref($2) ); }
315 | gbl_statements coclass ';' { $$ = $1;
316 reg_type($2, $2->name, 0);
317 if (!parse_only && do_header) write_coclass_forward($2);
319 | gbl_statements coclassdef { $$ = $1;
320 add_typelib_entry($2);
321 reg_type($2, $2->name, 0);
322 if (!parse_only && do_header) write_coclass_forward($2);
324 | gbl_statements moduledef { $$ = $1; add_typelib_entry($2); }
325 | gbl_statements librarydef { $$ = $1; }
326 | gbl_statements statement { $$ = $1; }
330 | imp_statements interfacedec { if (!parse_only) add_typelib_entry($2); }
331 | imp_statements interfacedef { if (!parse_only) add_typelib_entry($2); }
332 | imp_statements coclass ';' { reg_type($2, $2->name, 0); if (!parse_only && do_header) write_coclass_forward($2); }
333 | imp_statements coclassdef { if (!parse_only) add_typelib_entry($2);
334 reg_type($2, $2->name, 0);
335 if (!parse_only && do_header) write_coclass_forward($2);
337 | imp_statements moduledef { if (!parse_only) add_typelib_entry($2); }
338 | imp_statements statement {}
339 | imp_statements importlib {}
340 | imp_statements librarydef {}
343 int_statements: { $$ = NULL; }
344 | int_statements funcdef ';' { $$ = append_func( $1, $2 ); }
345 | int_statements statement { $$ = $1; }
352 statement: constdef ';' { if (!parse_only && do_header) { write_constdef($1); } }
354 | enumdef ';' { if (!parse_only && do_header) {
355 write_type_def_or_decl(header, $1, FALSE, NULL);
356 fprintf(header, ";\n\n");
359 | externdef ';' { if (!parse_only && do_header) { write_externdef($1); } }
361 | structdef ';' { if (!parse_only && do_header) {
362 write_type_def_or_decl(header, $1, FALSE, NULL);
363 fprintf(header, ";\n\n");
367 | uniondef ';' { if (!parse_only && do_header) {
368 write_type_def_or_decl(header, $1, FALSE, NULL);
369 fprintf(header, ";\n\n");
374 cppquote: tCPPQUOTE '(' aSTRING ')' { if (!parse_only && do_header) fprintf(header, "%s\n", $3); }
376 import_start: tIMPORT aSTRING ';' { assert(yychar == YYEMPTY);
378 if (!$$) yychar = aEOF;
382 import: import_start imp_statements aEOF
383 { if ($1) pop_import(); }
386 importlib: tIMPORTLIB '(' aSTRING ')'
387 semicolon_opt { if(!parse_only) add_importlib($3); }
390 libraryhdr: tLIBRARY aIDENTIFIER { $$ = $2; }
392 library_start: attributes libraryhdr '{' { check_library_attrs($2, $1);
393 if (!parse_only) start_typelib($2, $1);
394 if (!parse_only && do_header) write_library($2, $1);
395 if (!parse_only && do_idfile) write_libid($2, $1);
396 is_inside_library = TRUE;
399 librarydef: library_start imp_statements '}'
400 semicolon_opt { if (!parse_only) end_typelib(); is_inside_library = FALSE; }
403 m_args: { $$ = NULL; }
407 no_args: tVOID { $$ = NULL; }
410 args: arg { check_arg($1); $$ = append_var( NULL, $1 ); }
411 | args ',' arg { check_arg($3); $$ = append_var( $1, $3); }
415 /* split into two rules to get bison to resolve a tVOID conflict */
416 arg: attributes type pident array { $$ = $3->var;
418 set_type($$, $2, $3, $4, TRUE);
421 | type pident array { $$ = $2->var;
422 set_type($$, $1, $2, $3, TRUE);
427 array: { $$ = NULL; }
428 | '[' array_list ']' { $$ = $2; }
429 | '[' '*' ']' { $$ = append_array( NULL, make_expr(EXPR_VOID) ); }
432 array_list: m_expr /* size of first dimension is optional */ { $$ = append_array( NULL, $1 ); }
433 | array_list ',' expr { $$ = append_array( $1, $3 ); }
434 | array_list ']' '[' expr { $$ = append_array( $1, $4 ); }
437 m_attributes: { $$ = NULL; }
442 '[' attrib_list ']' { $$ = $2;
444 error_loc("empty attribute lists unsupported\n");
448 attrib_list: attribute { $$ = append_attr( NULL, $1 ); }
449 | attrib_list ',' attribute { $$ = append_attr( $1, $3 ); }
450 | attrib_list ']' '[' attribute { $$ = append_attr( $1, $4 ); }
453 str_list: aSTRING { $$ = append_str( NULL, $1 ); }
454 | str_list ',' aSTRING { $$ = append_str( $1, $3 ); }
457 attribute: { $$ = NULL; }
458 | tAGGREGATABLE { $$ = make_attr(ATTR_AGGREGATABLE); }
459 | tAPPOBJECT { $$ = make_attr(ATTR_APPOBJECT); }
460 | tASYNC { $$ = make_attr(ATTR_ASYNC); }
461 | tAUTOHANDLE { $$ = make_attr(ATTR_AUTO_HANDLE); }
462 | tBINDABLE { $$ = make_attr(ATTR_BINDABLE); }
463 | tBROADCAST { $$ = make_attr(ATTR_BROADCAST); }
464 | tCALLAS '(' ident ')' { $$ = make_attrp(ATTR_CALLAS, $3); }
465 | tCASE '(' expr_list_const ')' { $$ = make_attrp(ATTR_CASE, $3); }
466 | tCONTEXTHANDLE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); }
467 | tCONTEXTHANDLENOSERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
468 | tCONTEXTHANDLESERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
469 | tCONTROL { $$ = make_attr(ATTR_CONTROL); }
470 | tDEFAULT { $$ = make_attr(ATTR_DEFAULT); }
471 | tDEFAULTCOLLELEM { $$ = make_attr(ATTR_DEFAULTCOLLELEM); }
472 | tDEFAULTVALUE '(' expr_const ')' { $$ = make_attrp(ATTR_DEFAULTVALUE_EXPR, $3); }
473 | tDEFAULTVALUE '(' aSTRING ')' { $$ = make_attrp(ATTR_DEFAULTVALUE_STRING, $3); }
474 | tDEFAULTVTABLE { $$ = make_attr(ATTR_DEFAULTVTABLE); }
475 | tDISPLAYBIND { $$ = make_attr(ATTR_DISPLAYBIND); }
476 | tDLLNAME '(' aSTRING ')' { $$ = make_attrp(ATTR_DLLNAME, $3); }
477 | tDUAL { $$ = make_attr(ATTR_DUAL); }
478 | tENDPOINT '(' str_list ')' { $$ = make_attrp(ATTR_ENDPOINT, $3); }
479 | tENTRY '(' aSTRING ')' { $$ = make_attrp(ATTR_ENTRY_STRING, $3); }
480 | tENTRY '(' expr_const ')' { $$ = make_attrp(ATTR_ENTRY_ORDINAL, $3); }
481 | tEXPLICITHANDLE { $$ = make_attr(ATTR_EXPLICIT_HANDLE); }
482 | tHANDLE { $$ = make_attr(ATTR_HANDLE); }
483 | tHELPCONTEXT '(' expr_const ')' { $$ = make_attrp(ATTR_HELPCONTEXT, $3); }
484 | tHELPFILE '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPFILE, $3); }
485 | tHELPSTRING '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRING, $3); }
486 | tHELPSTRINGCONTEXT '(' expr_const ')' { $$ = make_attrp(ATTR_HELPSTRINGCONTEXT, $3); }
487 | tHELPSTRINGDLL '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRINGDLL, $3); }
488 | tHIDDEN { $$ = make_attr(ATTR_HIDDEN); }
489 | tID '(' expr_const ')' { $$ = make_attrp(ATTR_ID, $3); }
490 | tIDEMPOTENT { $$ = make_attr(ATTR_IDEMPOTENT); }
491 | tIIDIS '(' expr ')' { $$ = make_attrp(ATTR_IIDIS, $3); }
492 | tIMMEDIATEBIND { $$ = make_attr(ATTR_IMMEDIATEBIND); }
493 | tIMPLICITHANDLE '(' tHANDLET aIDENTIFIER ')' { $$ = make_attrp(ATTR_IMPLICIT_HANDLE, $4); }
494 | tIN { $$ = make_attr(ATTR_IN); }
495 | tINPUTSYNC { $$ = make_attr(ATTR_INPUTSYNC); }
496 | tLENGTHIS '(' m_exprs ')' { $$ = make_attrp(ATTR_LENGTHIS, $3); }
497 | tLOCAL { $$ = make_attr(ATTR_LOCAL); }
498 | tNONBROWSABLE { $$ = make_attr(ATTR_NONBROWSABLE); }
499 | tNONCREATABLE { $$ = make_attr(ATTR_NONCREATABLE); }
500 | tNONEXTENSIBLE { $$ = make_attr(ATTR_NONEXTENSIBLE); }
501 | tOBJECT { $$ = make_attr(ATTR_OBJECT); }
502 | tODL { $$ = make_attr(ATTR_ODL); }
503 | tOLEAUTOMATION { $$ = make_attr(ATTR_OLEAUTOMATION); }
504 | tOPTIONAL { $$ = make_attr(ATTR_OPTIONAL); }
505 | tOUT { $$ = make_attr(ATTR_OUT); }
506 | tPOINTERDEFAULT '(' pointer_type ')' { $$ = make_attrv(ATTR_POINTERDEFAULT, $3); }
507 | tPROPGET { $$ = make_attr(ATTR_PROPGET); }
508 | tPROPPUT { $$ = make_attr(ATTR_PROPPUT); }
509 | tPROPPUTREF { $$ = make_attr(ATTR_PROPPUTREF); }
510 | tPUBLIC { $$ = make_attr(ATTR_PUBLIC); }
511 | tRANGE '(' expr_const ',' expr_const ')' { expr_list_t *list = append_expr( NULL, $3 );
512 list = append_expr( list, $5 );
513 $$ = make_attrp(ATTR_RANGE, list); }
514 | tREADONLY { $$ = make_attr(ATTR_READONLY); }
515 | tREQUESTEDIT { $$ = make_attr(ATTR_REQUESTEDIT); }
516 | tRESTRICTED { $$ = make_attr(ATTR_RESTRICTED); }
517 | tRETVAL { $$ = make_attr(ATTR_RETVAL); }
518 | tSIZEIS '(' m_exprs ')' { $$ = make_attrp(ATTR_SIZEIS, $3); }
519 | tSOURCE { $$ = make_attr(ATTR_SOURCE); }
520 | tSTRICTCONTEXTHANDLE { $$ = make_attr(ATTR_STRICTCONTEXTHANDLE); }
521 | tSTRING { $$ = make_attr(ATTR_STRING); }
522 | tSWITCHIS '(' expr ')' { $$ = make_attrp(ATTR_SWITCHIS, $3); }
523 | tSWITCHTYPE '(' type ')' { $$ = make_attrp(ATTR_SWITCHTYPE, $3); }
524 | tTRANSMITAS '(' type ')' { $$ = make_attrp(ATTR_TRANSMITAS, $3); }
525 | tUUID '(' uuid_string ')' { $$ = make_attrp(ATTR_UUID, $3); }
526 | tV1ENUM { $$ = make_attr(ATTR_V1ENUM); }
527 | tVARARG { $$ = make_attr(ATTR_VARARG); }
528 | tVERSION '(' version ')' { $$ = make_attrv(ATTR_VERSION, $3); }
529 | tWIREMARSHAL '(' type ')' { $$ = make_attrp(ATTR_WIREMARSHAL, $3); }
530 | pointer_type { $$ = make_attrv(ATTR_POINTERTYPE, $1); }
535 | aSTRING { if (!is_valid_uuid($1))
536 error_loc("invalid UUID: %s\n", $1);
537 $$ = parse_uuid($1); }
540 callconv: tCDECL { $$ = $<str>1; }
541 | tFASTCALL { $$ = $<str>1; }
542 | tPASCAL { $$ = $<str>1; }
543 | tSTDCALL { $$ = $<str>1; }
546 cases: { $$ = NULL; }
547 | cases case { $$ = append_var( $1, $2 ); }
550 case: tCASE expr ':' field { attr_t *a = make_attrp(ATTR_CASE, append_expr( NULL, $2 ));
551 $$ = $4; if (!$$) $$ = make_var(NULL);
552 $$->attrs = append_attr( $$->attrs, a );
554 | tDEFAULT ':' field { attr_t *a = make_attr(ATTR_DEFAULT);
555 $$ = $3; if (!$$) $$ = make_var(NULL);
556 $$->attrs = append_attr( $$->attrs, a );
560 constdef: tCONST type ident '=' expr_const { $$ = reg_const($3);
561 set_type($$, $2, NULL, NULL, FALSE);
566 enums: { $$ = NULL; }
567 | enum_list ',' { $$ = $1; }
571 enum_list: enum { if (!$1->eval)
572 $1->eval = make_exprl(EXPR_NUM, 0 /* default for first enum entry */);
573 $$ = append_var( NULL, $1 );
575 | enum_list ',' enum { if (!$3->eval)
577 var_t *last = LIST_ENTRY( list_tail($$), var_t, entry );
578 $3->eval = make_exprl(EXPR_NUM, last->eval->cval + 1);
580 $$ = append_var( $1, $3 );
584 enum: ident '=' expr_const { $$ = reg_const($1);
586 $$->type = make_int(0);
588 | ident { $$ = reg_const($1);
589 $$->type = make_int(0);
593 enumdef: tENUM t_ident '{' enums '}' { $$ = get_typev(RPC_FC_ENUM16, $2, tsENUM);
594 $$->kind = TKIND_ENUM;
595 $$->fields_or_args = $4;
598 add_typelib_entry($$);
602 m_exprs: m_expr { $$ = append_expr( NULL, $1 ); }
603 | m_exprs ',' m_expr { $$ = append_expr( $1, $3 ); }
607 exprs: { $$ = make_expr(EXPR_VOID); }
612 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
616 m_expr: { $$ = make_expr(EXPR_VOID); }
620 expr: aNUM { $$ = make_exprl(EXPR_NUM, $1); }
621 | aHEXNUM { $$ = make_exprl(EXPR_HEXNUM, $1); }
622 | aDOUBLE { $$ = make_exprd(EXPR_DOUBLE, $1); }
623 | tFALSE { $$ = make_exprl(EXPR_TRUEFALSE, 0); }
624 | tTRUE { $$ = make_exprl(EXPR_TRUEFALSE, 1); }
625 | aIDENTIFIER { $$ = make_exprs(EXPR_IDENTIFIER, $1); }
626 | expr '?' expr ':' expr { $$ = make_expr3(EXPR_COND, $1, $3, $5); }
627 | expr '|' expr { $$ = make_expr2(EXPR_OR , $1, $3); }
628 | expr '&' expr { $$ = make_expr2(EXPR_AND, $1, $3); }
629 | expr '+' expr { $$ = make_expr2(EXPR_ADD, $1, $3); }
630 | expr '-' expr { $$ = make_expr2(EXPR_SUB, $1, $3); }
631 | expr '%' expr { $$ = make_expr2(EXPR_MOD, $1, $3); }
632 | expr '*' expr { $$ = make_expr2(EXPR_MUL, $1, $3); }
633 | expr '/' expr { $$ = make_expr2(EXPR_DIV, $1, $3); }
634 | expr SHL expr { $$ = make_expr2(EXPR_SHL, $1, $3); }
635 | expr SHR expr { $$ = make_expr2(EXPR_SHR, $1, $3); }
636 | '~' expr { $$ = make_expr1(EXPR_NOT, $2); }
637 | '-' expr %prec NEG { $$ = make_expr1(EXPR_NEG, $2); }
638 | '&' expr %prec ADDRESSOF { $$ = make_expr1(EXPR_ADDRESSOF, $2); }
639 | '*' expr %prec PPTR { $$ = make_expr1(EXPR_PPTR, $2); }
640 | expr MEMBERPTR expr { $$ = make_expr2(EXPR_MEMBERPTR, $1, $3); }
641 | expr '.' expr { $$ = make_expr2(EXPR_MEMBER, $1, $3); }
642 | '(' type ')' expr %prec CAST { $$ = make_exprt(EXPR_CAST, $2, $4); }
643 | tSIZEOF '(' type ')' { $$ = make_exprt(EXPR_SIZEOF, $3, NULL); }
644 | expr '[' expr ']' { $$ = make_expr2(EXPR_ARRAY, $1, $3); }
645 | '(' expr ')' { $$ = $2; }
648 expr_list_const: expr_const { $$ = append_expr( NULL, $1 ); }
649 | expr_list_const ',' expr_const { $$ = append_expr( $1, $3 ); }
652 expr_const: expr { $$ = $1;
654 error_loc("expression is not constant\n");
658 externdef: tEXTERN tCONST type ident { $$ = $4;
659 set_type($$, $3, NULL, NULL, FALSE);
663 fields: { $$ = NULL; }
664 | fields field { $$ = append_var( $1, $2 ); }
667 field: s_field ';' { $$ = $1; }
668 | m_attributes uniondef ';' { $$ = make_var(NULL); $$->type = $2; $$->attrs = $1; }
669 | attributes ';' { $$ = make_var(NULL); $$->attrs = $1; }
673 s_field: m_attributes type pident array { $$ = $3->var;
674 $$->attrs = check_field_attrs($$->name, $1);
675 set_type($$, $2, $3, $4, FALSE);
681 m_attributes type pident { var_t *v = $3->var;
682 var_list_t *args = $3->args;
683 v->attrs = check_function_attrs(v->name, $1);
684 set_type(v, $2, $3, NULL, FALSE);
686 $$ = make_func(v, args);
690 m_ident: { $$ = NULL; }
694 t_ident: { $$ = NULL; }
695 | aIDENTIFIER { $$ = make_var($1); }
696 | aKNOWNTYPE { $$ = make_var($1); }
699 ident: aIDENTIFIER { $$ = make_var($1); }
700 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
701 | aKNOWNTYPE { $$ = make_var($<str>1); }
704 base_type: tBYTE { $$ = make_builtin($<str>1); }
705 | tWCHAR { $$ = make_builtin($<str>1); }
707 | tSIGNED int_std { $$ = $2; $$->sign = 1; }
708 | tUNSIGNED int_std { $$ = $2; $$->sign = -1;
710 case RPC_FC_CHAR: break;
711 case RPC_FC_SMALL: $$->type = RPC_FC_USMALL; break;
712 case RPC_FC_SHORT: $$->type = RPC_FC_USHORT; break;
713 case RPC_FC_LONG: $$->type = RPC_FC_ULONG; break;
715 if ($$->name[0] == 'h') /* hyper, as opposed to __int64 */
717 $$ = alias($$, "MIDL_uhyper");
724 | tUNSIGNED { $$ = make_int(-1); }
725 | tFLOAT { $$ = make_builtin($<str>1); }
726 | tSINGLE { $$ = duptype(find_type("float", 0), 1); }
727 | tDOUBLE { $$ = make_builtin($<str>1); }
728 | tBOOLEAN { $$ = make_builtin($<str>1); }
729 | tERRORSTATUST { $$ = make_builtin($<str>1); }
730 | tHANDLET { $$ = make_builtin($<str>1); }
737 int_std: tINT { $$ = make_builtin($<str>1); }
738 | tSHORT m_int { $$ = make_builtin($<str>1); }
739 | tSMALL { $$ = make_builtin($<str>1); }
740 | tLONG m_int { $$ = make_builtin($<str>1); }
741 | tHYPER m_int { $$ = make_builtin($<str>1); }
742 | tINT64 { $$ = make_builtin($<str>1); }
743 | tCHAR { $$ = make_builtin($<str>1); }
746 coclass: tCOCLASS aIDENTIFIER { $$ = make_class($2); }
747 | tCOCLASS aKNOWNTYPE { $$ = find_type($2, 0);
748 if ($$->defined) error_loc("multiple definition error\n");
749 if ($$->kind != TKIND_COCLASS) error_loc("%s was not declared a coclass\n", $2);
753 coclasshdr: attributes coclass { $$ = $2;
754 $$->attrs = check_coclass_attrs($2->name, $1);
755 if (!parse_only && do_header)
757 if (!parse_only && do_idfile)
762 coclassdef: coclasshdr '{' coclass_ints '}' semicolon_opt
769 coclass_ints: { $$ = NULL; }
770 | coclass_ints coclass_int { $$ = append_ifref( $1, $2 ); }
774 m_attributes interfacedec { $$ = make_ifref($2); $$->attrs = $1; }
777 dispinterface: tDISPINTERFACE aIDENTIFIER { $$ = get_type(0, $2, 0); $$->kind = TKIND_DISPATCH; }
778 | tDISPINTERFACE aKNOWNTYPE { $$ = get_type(0, $2, 0); $$->kind = TKIND_DISPATCH; }
781 dispinterfacehdr: attributes dispinterface { attr_t *attrs;
782 is_object_interface = TRUE;
784 if ($$->defined) error_loc("multiple definition error\n");
785 attrs = make_attr(ATTR_DISPINTERFACE);
786 $$->attrs = append_attr( check_dispiface_attrs($2->name, $1), attrs );
787 $$->ref = find_type("IDispatch", 0);
788 if (!$$->ref) error_loc("IDispatch is undefined\n");
790 if (!parse_only && do_header) write_forward($$);
794 dispint_props: tPROPERTIES ':' { $$ = NULL; }
795 | dispint_props s_field ';' { $$ = append_var( $1, $2 ); }
798 dispint_meths: tMETHODS ':' { $$ = NULL; }
799 | dispint_meths funcdef ';' { $$ = append_func( $1, $2 ); }
802 dispinterfacedef: dispinterfacehdr '{'
806 $$->fields_or_args = $3;
808 if (!parse_only && do_header) write_dispinterface($$);
809 if (!parse_only && do_idfile) write_diid($$);
812 '{' interface ';' '}' { $$ = $1;
813 $$->fields_or_args = $3->fields_or_args;
814 $$->funcs = $3->funcs;
815 if (!parse_only && do_header) write_dispinterface($$);
816 if (!parse_only && do_idfile) write_diid($$);
820 inherit: { $$ = NULL; }
821 | ':' aKNOWNTYPE { $$ = find_type2($2, 0); }
824 interface: tINTERFACE aIDENTIFIER { $$ = get_type(RPC_FC_IP, $2, 0); $$->kind = TKIND_INTERFACE; }
825 | tINTERFACE aKNOWNTYPE { $$ = get_type(RPC_FC_IP, $2, 0); $$->kind = TKIND_INTERFACE; }
828 interfacehdr: attributes interface { $$.interface = $2;
829 $$.old_pointer_default = pointer_default;
830 if (is_attr($1, ATTR_POINTERDEFAULT))
831 pointer_default = get_attrv($1, ATTR_POINTERDEFAULT);
832 is_object_interface = is_object($1);
833 if ($2->defined) error_loc("multiple definition error\n");
834 $2->attrs = check_iface_attrs($2->name, $1);
836 if (!parse_only && do_header) write_forward($2);
840 interfacedef: interfacehdr inherit
841 '{' int_statements '}' semicolon_opt { $$ = $1.interface;
845 compute_method_indexes($$);
846 if (!parse_only && do_header) write_interface($$);
847 if (!parse_only && local_stubs) write_locals(local_stubs, $$, TRUE);
848 if (!parse_only && do_idfile) write_iid($$);
849 pointer_default = $1.old_pointer_default;
851 /* MIDL is able to import the definition of a base class from inside the
852 * definition of a derived class, I'll try to support it with this rule */
853 | interfacehdr ':' aIDENTIFIER
854 '{' import int_statements '}'
855 semicolon_opt { $$ = $1.interface;
856 $$->ref = find_type2($3, 0);
857 if (!$$->ref) error_loc("base class '%s' not found in import\n", $3);
859 compute_method_indexes($$);
860 if (!parse_only && do_header) write_interface($$);
861 if (!parse_only && local_stubs) write_locals(local_stubs, $$, TRUE);
862 if (!parse_only && do_idfile) write_iid($$);
863 pointer_default = $1.old_pointer_default;
865 | dispinterfacedef semicolon_opt { $$ = $1; }
869 interface ';' { $$ = $1; if (!parse_only && do_header) write_forward($$); }
870 | dispinterface ';' { $$ = $1; if (!parse_only && do_header) write_forward($$); }
873 module: tMODULE aIDENTIFIER { $$ = make_type(0, NULL); $$->name = $2; $$->kind = TKIND_MODULE; }
874 | tMODULE aKNOWNTYPE { $$ = make_type(0, NULL); $$->name = $2; $$->kind = TKIND_MODULE; }
877 modulehdr: attributes module { $$ = $2;
878 $$->attrs = check_module_attrs($2->name, $1);
882 moduledef: modulehdr '{' int_statements '}'
883 semicolon_opt { $$ = $1;
885 /* FIXME: if (!parse_only && do_header) write_module($$); */
889 pident: '*' pident %prec PPTR { $$ = $2; $$->ptr_level++; }
890 | tCONST pident { $$ = $2; /* FIXME */ }
891 | callconv pident { $$ = $2;
892 if ($$->callconv) parser_warning("multiple calling conventions %s, %s for function %s\n", $$->callconv, $1, $$->var->name);
898 func_ident: direct_ident '(' m_args ')'
905 direct_ident: ident { $$ = make_pident($1); }
906 | '(' pident ')' { $$ = $2; }
907 | func_ident { $$ = $1;
908 $$->func_ptr_level = $$->ptr_level;
914 pident { $$ = append_pident( NULL, $1 ); }
915 | pident_list ',' pident { $$ = append_pident( $1, $3 ); }
919 tREF { $$ = RPC_FC_RP; }
920 | tUNIQUE { $$ = RPC_FC_UP; }
921 | tPTR { $$ = RPC_FC_FP; }
924 structdef: tSTRUCT t_ident '{' fields '}' { $$ = get_typev(RPC_FC_STRUCT, $2, tsSTRUCT);
925 /* overwrite RPC_FC_STRUCT with a more exact type */
926 $$->type = get_struct_type( $4 );
927 $$->kind = TKIND_RECORD;
928 $$->fields_or_args = $4;
931 add_typelib_entry($$);
935 type: tVOID { $$ = duptype(find_type("void", 0), 1); }
936 | aKNOWNTYPE { $$ = find_type($1, 0); }
937 | base_type { $$ = $1; }
938 | tCONST type { $$ = duptype($2, 1); $$->is_const = TRUE; }
939 | enumdef { $$ = $1; }
940 | tENUM aIDENTIFIER { $$ = find_type2($2, tsENUM); }
941 | structdef { $$ = $1; }
942 | tSTRUCT aIDENTIFIER { $$ = get_type(RPC_FC_STRUCT, $2, tsSTRUCT); }
943 | uniondef { $$ = $1; }
944 | tUNION aIDENTIFIER { $$ = find_type2($2, tsUNION); }
945 | tSAFEARRAY '(' type ')' { $$ = make_safearray($3); }
948 typedef: tTYPEDEF m_attributes type pident_list { reg_typedefs($3, $4, check_typedef_attrs($2));
949 process_typedefs($4);
953 uniondef: tUNION t_ident '{' fields '}' { $$ = get_typev(RPC_FC_NON_ENCAPSULATED_UNION, $2, tsUNION);
954 $$->kind = TKIND_UNION;
955 $$->fields_or_args = $4;
959 tSWITCH '(' s_field ')'
960 m_ident '{' cases '}' { var_t *u = $7;
961 $$ = get_typev(RPC_FC_ENCAPSULATED_UNION, $2, tsUNION);
962 $$->kind = TKIND_UNION;
963 if (!u) u = make_var( xstrdup("tagged_union") );
964 u->type = make_type(RPC_FC_NON_ENCAPSULATED_UNION, NULL);
965 u->type->kind = TKIND_UNION;
966 u->type->fields_or_args = $9;
967 u->type->defined = TRUE;
968 $$->fields_or_args = append_var( $$->fields_or_args, $5 );
969 $$->fields_or_args = append_var( $$->fields_or_args, u );
975 aNUM { $$ = MAKEVERSION($1, 0); }
976 | aNUM '.' aNUM { $$ = MAKEVERSION($1, $3); }
981 static void decl_builtin(const char *name, unsigned char type)
983 type_t *t = make_type(type, NULL);
984 t->name = xstrdup(name);
985 reg_type(t, name, 0);
988 static type_t *make_builtin(char *name)
990 /* NAME is strdup'd in the lexer */
991 type_t *t = duptype(find_type(name, 0), 0);
996 static type_t *make_int(int sign)
998 type_t *t = duptype(find_type("int", 0), 1);
1002 t->type = t->type == RPC_FC_LONG ? RPC_FC_ULONG : RPC_FC_USHORT;
1007 void init_types(void)
1009 decl_builtin("void", 0);
1010 decl_builtin("byte", RPC_FC_BYTE);
1011 decl_builtin("wchar_t", RPC_FC_WCHAR);
1012 decl_builtin("int", RPC_FC_LONG); /* win32 */
1013 decl_builtin("short", RPC_FC_SHORT);
1014 decl_builtin("small", RPC_FC_SMALL);
1015 decl_builtin("long", RPC_FC_LONG);
1016 decl_builtin("hyper", RPC_FC_HYPER);
1017 decl_builtin("__int64", RPC_FC_HYPER);
1018 decl_builtin("char", RPC_FC_CHAR);
1019 decl_builtin("float", RPC_FC_FLOAT);
1020 decl_builtin("double", RPC_FC_DOUBLE);
1021 decl_builtin("boolean", RPC_FC_BYTE);
1022 decl_builtin("error_status_t", RPC_FC_ERROR_STATUS_T);
1023 decl_builtin("handle_t", RPC_FC_BIND_PRIMITIVE);
1026 static str_list_t *append_str(str_list_t *list, char *str)
1028 struct str_list_entry_t *entry;
1030 if (!str) return list;
1033 list = xmalloc( sizeof(*list) );
1036 entry = xmalloc( sizeof(*entry) );
1038 list_add_tail( list, &entry->entry );
1042 static attr_list_t *append_attr(attr_list_t *list, attr_t *attr)
1044 attr_t *attr_existing;
1045 if (!attr) return list;
1048 list = xmalloc( sizeof(*list) );
1051 LIST_FOR_EACH_ENTRY(attr_existing, list, attr_t, entry)
1052 if (attr_existing->type == attr->type)
1054 parser_warning("duplicate attribute %s\n", get_attr_display_name(attr->type));
1055 /* use the last attribute, like MIDL does */
1056 list_remove(&attr_existing->entry);
1059 list_add_tail( list, &attr->entry );
1063 static attr_t *make_attr(enum attr_type type)
1065 attr_t *a = xmalloc(sizeof(attr_t));
1071 static attr_t *make_attrv(enum attr_type type, unsigned long val)
1073 attr_t *a = xmalloc(sizeof(attr_t));
1079 static attr_t *make_attrp(enum attr_type type, void *val)
1081 attr_t *a = xmalloc(sizeof(attr_t));
1087 static expr_t *make_expr(enum expr_type type)
1089 expr_t *e = xmalloc(sizeof(expr_t));
1093 e->is_const = FALSE;
1098 static expr_t *make_exprl(enum expr_type type, long val)
1100 expr_t *e = xmalloc(sizeof(expr_t));
1104 e->is_const = FALSE;
1105 /* check for numeric constant */
1106 if (type == EXPR_NUM || type == EXPR_HEXNUM || type == EXPR_TRUEFALSE) {
1107 /* make sure true/false value is valid */
1108 assert(type != EXPR_TRUEFALSE || val == 0 || val == 1);
1115 static expr_t *make_exprd(enum expr_type type, double val)
1117 expr_t *e = xmalloc(sizeof(expr_t));
1126 static expr_t *make_exprs(enum expr_type type, char *val)
1129 e = xmalloc(sizeof(expr_t));
1133 e->is_const = FALSE;
1134 /* check for predefined constants */
1135 if (type == EXPR_IDENTIFIER) {
1136 var_t *c = find_const(val, 0);
1138 e->u.sval = c->name;
1141 e->cval = c->eval->cval;
1147 static expr_t *make_exprt(enum expr_type type, type_t *tref, expr_t *expr)
1150 e = xmalloc(sizeof(expr_t));
1154 e->is_const = FALSE;
1155 /* check for cast of constant expression */
1156 if (type == EXPR_SIZEOF) {
1157 switch (tref->type) {
1174 case RPC_FC_ERROR_STATUS_T:
1185 if (type == EXPR_CAST && expr->is_const) {
1187 e->cval = expr->cval;
1192 static expr_t *make_expr1(enum expr_type type, expr_t *expr)
1195 if (type == EXPR_ADDRESSOF && expr->type != EXPR_IDENTIFIER)
1196 error_loc("address-of operator applied to invalid expression\n");
1197 e = xmalloc(sizeof(expr_t));
1201 e->is_const = FALSE;
1202 /* check for compile-time optimization */
1203 if (expr->is_const) {
1207 e->cval = -expr->cval;
1210 e->cval = ~expr->cval;
1213 e->is_const = FALSE;
1220 static expr_t *make_expr2(enum expr_type type, expr_t *expr1, expr_t *expr2)
1223 e = xmalloc(sizeof(expr_t));
1227 e->is_const = FALSE;
1228 /* check for compile-time optimization */
1229 if (expr1->is_const && expr2->is_const) {
1233 e->cval = expr1->cval + expr2->cval;
1236 e->cval = expr1->cval - expr2->cval;
1239 if (expr2->cval == 0) {
1240 error_loc("divide by zero in expression\n");
1243 e->cval = expr1->cval % expr2->cval;
1246 e->cval = expr1->cval * expr2->cval;
1249 if (expr2->cval == 0) {
1250 error_loc("divide by zero in expression\n");
1253 e->cval = expr1->cval / expr2->cval;
1256 e->cval = expr1->cval | expr2->cval;
1259 e->cval = expr1->cval & expr2->cval;
1262 e->cval = expr1->cval << expr2->cval;
1265 e->cval = expr1->cval >> expr2->cval;
1268 e->is_const = FALSE;
1275 static expr_t *make_expr3(enum expr_type type, expr_t *expr1, expr_t *expr2, expr_t *expr3)
1278 e = xmalloc(sizeof(expr_t));
1283 e->is_const = FALSE;
1284 /* check for compile-time optimization */
1285 if (expr1->is_const && expr2->is_const && expr3->is_const) {
1289 e->cval = expr1->cval ? expr2->cval : expr3->cval;
1292 e->is_const = FALSE;
1299 static expr_list_t *append_expr(expr_list_t *list, expr_t *expr)
1301 if (!expr) return list;
1304 list = xmalloc( sizeof(*list) );
1307 list_add_tail( list, &expr->entry );
1311 static array_dims_t *append_array(array_dims_t *list, expr_t *expr)
1313 if (!expr) return list;
1316 list = xmalloc( sizeof(*list) );
1319 list_add_tail( list, &expr->entry );
1323 static struct list type_pool = LIST_INIT(type_pool);
1330 type_t *alloc_type(void)
1332 type_pool_node_t *node = xmalloc(sizeof *node);
1333 list_add_tail(&type_pool, &node->link);
1337 void set_all_tfswrite(int val)
1339 type_pool_node_t *node;
1340 LIST_FOR_EACH_ENTRY(node, &type_pool, type_pool_node_t, link)
1341 node->data.tfswrite = val;
1344 static type_t *make_type(unsigned char type, type_t *ref)
1346 type_t *t = alloc_type();
1348 t->kind = TKIND_PRIMITIVE;
1354 t->fields_or_args = NULL;
1358 t->length_is = NULL;
1359 t->typestring_offset = 0;
1361 t->declarray = FALSE;
1362 t->ignore = (parse_only != 0);
1363 t->is_const = FALSE;
1367 t->user_types_registered = FALSE;
1368 t->tfswrite = FALSE;
1370 t->typelib_idx = -1;
1374 static void set_type(var_t *v, type_t *type, const pident_t *pident, array_dims_t *arr,
1377 expr_list_t *sizes = get_attrp(v->attrs, ATTR_SIZEIS);
1378 expr_list_t *lengs = get_attrp(v->attrs, ATTR_LENGTHIS);
1379 int ptr_attr = get_attrv(v->attrs, ATTR_POINTERTYPE);
1380 int ptr_type = ptr_attr;
1381 int sizeless, has_varconf;
1383 type_t *atype, **ptype;
1384 int ptr_level = (pident ? pident->ptr_level : 0);
1388 if (!ptr_type && top)
1389 ptr_type = RPC_FC_RP;
1391 for ( ; 0 < ptr_level; --ptr_level)
1393 v->type = make_type(pointer_default, v->type);
1394 if (ptr_level == 1 && ptr_type && !arr)
1396 v->type->type = ptr_type;
1401 if (ptr_type && !arr)
1403 if (is_ptr(v->type))
1405 if (v->type->type != ptr_type)
1407 v->type = duptype(v->type, 1);
1408 v->type->type = ptr_type;
1411 else if (!arr && ptr_attr)
1412 error_loc("%s: pointer attribute applied to non-pointer type\n", v->name);
1415 if (pident && pident->is_func) {
1416 int func_ptr_level = pident->func_ptr_level;
1417 v->type = make_type(RPC_FC_FUNCTION, v->type);
1418 v->type->fields_or_args = pident->args;
1419 if (pident->callconv)
1420 v->type->attrs = append_attr(NULL, make_attrp(ATTR_CALLCONV, pident->callconv));
1421 else if (is_object_interface) {
1422 static char *stdmethodcalltype;
1423 if (!stdmethodcalltype) stdmethodcalltype = strdup("STDMETHODCALLTYPE");
1424 v->type->attrs = append_attr(NULL, make_attrp(ATTR_CALLCONV, stdmethodcalltype));
1426 for (; func_ptr_level > 0; func_ptr_level--)
1427 v->type = make_type(ptr_type, v->type);
1431 if (arr) LIST_FOR_EACH_ENTRY_REV(dim, arr, expr_t, entry)
1434 error_loc("%s: only the first array dimension can be unspecified\n", v->name);
1438 unsigned int align = 0;
1439 size_t size = type_memsize(v->type, &align);
1442 error_loc("%s: array dimension must be positive\n", v->name);
1444 if (0xffffffffuL / size < (unsigned long) dim->cval)
1445 error_loc("%s: total array size is too large\n", v->name);
1446 else if (0xffffuL < size * dim->cval)
1447 v->type = make_type(RPC_FC_LGFARRAY, v->type);
1449 v->type = make_type(RPC_FC_SMFARRAY, v->type);
1454 v->type = make_type(RPC_FC_CARRAY, v->type);
1457 v->type->declarray = TRUE;
1458 v->type->dim = dim->cval;
1462 has_varconf = FALSE;
1463 if (sizes) LIST_FOR_EACH_ENTRY(dim, sizes, expr_t, entry)
1465 if (dim->type != EXPR_VOID)
1468 atype = *ptype = duptype(*ptype, 0);
1470 if (atype->type == RPC_FC_SMFARRAY || atype->type == RPC_FC_LGFARRAY)
1471 error_loc("%s: cannot specify size_is for a fixed sized array\n", v->name);
1473 if (atype->type != RPC_FC_CARRAY && !is_ptr(atype))
1474 error_loc("%s: size_is attribute applied to illegal type\n", v->name);
1476 atype->type = RPC_FC_CARRAY;
1477 atype->size_is = dim;
1480 ptype = &(*ptype)->ref;
1482 error_loc("%s: too many expressions in size_is attribute\n", v->name);
1486 if (lengs) LIST_FOR_EACH_ENTRY(dim, lengs, expr_t, entry)
1488 if (dim->type != EXPR_VOID)
1491 atype = *ptype = duptype(*ptype, 0);
1493 if (atype->type == RPC_FC_SMFARRAY)
1494 atype->type = RPC_FC_SMVARRAY;
1495 else if (atype->type == RPC_FC_LGFARRAY)
1496 atype->type = RPC_FC_LGVARRAY;
1497 else if (atype->type == RPC_FC_CARRAY)
1498 atype->type = RPC_FC_CVARRAY;
1500 error_loc("%s: length_is attribute applied to illegal type\n", v->name);
1502 atype->length_is = dim;
1505 ptype = &(*ptype)->ref;
1507 error_loc("%s: too many expressions in length_is attribute\n", v->name);
1510 if (has_varconf && !last_array(v->type))
1513 for (ptype = &v->type; is_array(*ptype); ptype = &(*ptype)->ref)
1515 *ptype = duptype(*ptype, 0);
1516 (*ptype)->type = RPC_FC_BOGUS_ARRAY;
1520 if (is_array(v->type))
1522 const type_t *rt = v->type->ref;
1523 if (is_user_type(rt))
1524 v->type->type = RPC_FC_BOGUS_ARRAY;
1528 case RPC_FC_BOGUS_STRUCT:
1529 case RPC_FC_NON_ENCAPSULATED_UNION:
1530 case RPC_FC_ENCAPSULATED_UNION:
1532 v->type->type = RPC_FC_BOGUS_ARRAY;
1534 /* FC_RP should be above, but widl overuses these, and will break things. */
1537 if (rt->ref->type == RPC_FC_IP)
1538 v->type->type = RPC_FC_BOGUS_ARRAY;
1544 static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface)
1546 if (!iface) return list;
1549 list = xmalloc( sizeof(*list) );
1552 list_add_tail( list, &iface->entry );
1556 static ifref_t *make_ifref(type_t *iface)
1558 ifref_t *l = xmalloc(sizeof(ifref_t));
1564 static var_list_t *append_var(var_list_t *list, var_t *var)
1566 if (!var) return list;
1569 list = xmalloc( sizeof(*list) );
1572 list_add_tail( list, &var->entry );
1576 static var_t *make_var(char *name)
1578 var_t *v = xmalloc(sizeof(var_t));
1583 v->loc_info.input_name = input_name ? input_name : "stdin";
1584 v->loc_info.line_number = line_number;
1585 v->loc_info.near_text = parser_text;
1589 static pident_list_t *append_pident(pident_list_t *list, pident_t *p)
1591 if (!p) return list;
1593 list = xmalloc(sizeof(*list));
1596 list_add_tail(list, &p->entry);
1600 static pident_t *make_pident(var_t *var)
1602 pident_t *p = xmalloc(sizeof(*p));
1606 p->func_ptr_level = 0;
1612 static func_list_t *append_func(func_list_t *list, func_t *func)
1614 if (!func) return list;
1617 list = xmalloc( sizeof(*list) );
1620 list_add_tail( list, &func->entry );
1624 static func_t *make_func(var_t *def, var_list_t *args)
1626 func_t *f = xmalloc(sizeof(func_t));
1629 f->ignore = parse_only;
1634 static type_t *make_class(char *name)
1636 type_t *c = make_type(0, NULL);
1638 c->kind = TKIND_COCLASS;
1642 static type_t *make_safearray(type_t *type)
1644 type_t *sa = duptype(find_type("SAFEARRAY", 0), 1);
1646 return make_type(pointer_default, sa);
1651 static int hash_ident(const char *name)
1653 const char *p = name;
1655 /* a simple sum hash is probably good enough */
1660 return sum & (HASHMAX-1);
1663 /***** type repository *****/
1672 struct rtype *type_hash[HASHMAX];
1674 static type_t *reg_type(type_t *type, const char *name, int t)
1679 error_loc("registering named type without name\n");
1682 hash = hash_ident(name);
1683 nt = xmalloc(sizeof(struct rtype));
1687 nt->next = type_hash[hash];
1688 type_hash[hash] = nt;
1692 static int is_incomplete(const type_t *t)
1694 return !t->defined && (is_struct(t->type) || is_union(t->type));
1697 static void add_incomplete(type_t *t)
1699 struct typenode *tn = xmalloc(sizeof *tn);
1701 list_add_tail(&incomplete_types, &tn->entry);
1704 static void fix_type(type_t *t)
1706 if (t->kind == TKIND_ALIAS && is_incomplete(t)) {
1707 type_t *ot = t->orig;
1709 t->fields_or_args = ot->fields_or_args;
1710 t->defined = ot->defined;
1714 static void fix_incomplete(void)
1716 struct typenode *tn, *next;
1718 LIST_FOR_EACH_ENTRY_SAFE(tn, next, &incomplete_types, struct typenode, entry) {
1724 static type_t *reg_typedefs(type_t *type, pident_list_t *pidents, attr_list_t *attrs)
1727 const pident_t *pident;
1729 int is_str = is_attr(attrs, ATTR_STRING);
1730 unsigned char ptr_type = get_attrv(attrs, ATTR_POINTERTYPE);
1741 if (c != RPC_FC_CHAR && c != RPC_FC_BYTE && c != RPC_FC_WCHAR)
1743 pident = LIST_ENTRY( list_head( pidents ), const pident_t, entry );
1744 error_loc("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
1749 /* We must generate names for tagless enum, struct or union.
1750 Typedef-ing a tagless enum, struct or union means we want the typedef
1751 to be included in a library whether it has other attributes or not,
1752 hence the public attribute. */
1753 if ((type->kind == TKIND_ENUM || type->kind == TKIND_RECORD
1754 || type->kind == TKIND_UNION) && ! type->name && ! parse_only)
1756 if (! is_attr(attrs, ATTR_PUBLIC))
1757 attrs = append_attr( attrs, make_attr(ATTR_PUBLIC) );
1758 type->name = gen_name();
1761 LIST_FOR_EACH_ENTRY( pident, pidents, const pident_t, entry )
1763 var_t *name = pident->var;
1767 int cptr = pident->ptr_level;
1769 while (cptr > ptrc) {
1770 cur = ptr = make_type(pointer_default, cur);
1774 while (cptr < ptrc) {
1779 if (pident->is_func) {
1780 int func_ptr_level = pident->func_ptr_level;
1781 cur = make_type(RPC_FC_FUNCTION, cur);
1782 cur->fields_or_args = pident->args;
1783 if (pident->callconv)
1784 cur->attrs = append_attr(NULL, make_attrp(ATTR_CALLCONV, pident->callconv));
1785 else if (is_object_interface) {
1786 static char *stdmethodcalltype;
1787 if (!stdmethodcalltype) stdmethodcalltype = strdup("STDMETHODCALLTYPE");
1788 cur->attrs = append_attr(NULL, make_attrp(ATTR_CALLCONV, stdmethodcalltype));
1790 for (; func_ptr_level > 0; func_ptr_level--)
1791 cur = make_type(pointer_default, cur);
1793 cur = alias(cur, name->name);
1798 cur->type = ptr_type;
1800 error_loc("'%s': pointer attribute applied to non-pointer type\n",
1803 else if (is_str && ! is_ptr(cur))
1804 error_loc("'%s': [string] attribute applied to non-pointer type\n",
1807 if (is_incomplete(cur))
1808 add_incomplete(cur);
1809 reg_type(cur, cur->name, 0);
1815 static type_t *find_type(const char *name, int t)
1817 struct rtype *cur = type_hash[hash_ident(name)];
1818 while (cur && (cur->t != t || strcmp(cur->name, name)))
1821 error_loc("type '%s' not found\n", name);
1827 static type_t *find_type2(char *name, int t)
1829 type_t *tp = find_type(name, t);
1834 int is_type(const char *name)
1836 struct rtype *cur = type_hash[hash_ident(name)];
1837 while (cur && (cur->t || strcmp(cur->name, name)))
1839 if (cur) return TRUE;
1843 static type_t *get_type(unsigned char type, char *name, int t)
1845 struct rtype *cur = NULL;
1848 cur = type_hash[hash_ident(name)];
1849 while (cur && (cur->t != t || strcmp(cur->name, name)))
1856 tp = make_type(type, NULL);
1858 if (!name) return tp;
1859 return reg_type(tp, name, t);
1862 static type_t *get_typev(unsigned char type, var_t *name, int t)
1869 return get_type(type, sname, t);
1872 static int get_struct_type(var_list_t *fields)
1874 int has_pointer = 0;
1875 int has_conformance = 0;
1876 int has_variance = 0;
1879 if (get_padding(fields))
1880 return RPC_FC_BOGUS_STRUCT;
1882 if (fields) LIST_FOR_EACH_ENTRY( field, fields, var_t, entry )
1884 type_t *t = field->type;
1886 if (is_user_type(t))
1887 return RPC_FC_BOGUS_STRUCT;
1898 case RPC_FC_ENCAPSULATED_UNION:
1899 case RPC_FC_NON_ENCAPSULATED_UNION:
1900 case RPC_FC_BOGUS_STRUCT:
1901 return RPC_FC_BOGUS_STRUCT;
1908 if (field->type->declarray)
1910 if (is_string_type(field->attrs, field->type))
1912 if (is_conformant_array(field->type))
1913 has_conformance = 1;
1918 if (is_array(field->type->ref))
1919 return RPC_FC_BOGUS_STRUCT;
1921 if (is_conformant_array(field->type))
1923 has_conformance = 1;
1924 if (field->type->declarray && list_next(fields, &field->entry))
1925 error_loc("field '%s' deriving from a conformant array must be the last field in the structure\n",
1928 if (field->type->length_is)
1931 t = field->type->ref;
1937 * RPC_FC_BYTE, RPC_FC_STRUCT, etc
1938 * Simple types don't effect the type of struct.
1939 * A struct containing a simple struct is still a simple struct.
1940 * So long as we can block copy the data, we return RPC_FC_STRUCT.
1942 case 0: /* void pointer */
1952 case RPC_FC_INT3264:
1953 case RPC_FC_UINT3264:
1966 case RPC_FC_CVARRAY:
1967 case RPC_FC_BOGUS_ARRAY:
1972 * Propagate member attributes
1973 * a struct should be at least as complex as its member
1975 case RPC_FC_CVSTRUCT:
1976 has_conformance = 1;
1981 case RPC_FC_CPSTRUCT:
1982 has_conformance = 1;
1983 if (list_next( fields, &field->entry ))
1984 error_loc("field '%s' deriving from a conformant array must be the last field in the structure\n",
1989 case RPC_FC_CSTRUCT:
1990 has_conformance = 1;
1991 if (list_next( fields, &field->entry ))
1992 error_loc("field '%s' deriving from a conformant array must be the last field in the structure\n",
1996 case RPC_FC_PSTRUCT:
2001 error_loc("Unknown struct member %s with type (0x%02x)\n", field->name, t->type);
2002 /* fallthru - treat it as complex */
2004 /* as soon as we see one of these these members, it's bogus... */
2005 case RPC_FC_ENCAPSULATED_UNION:
2006 case RPC_FC_NON_ENCAPSULATED_UNION:
2007 case RPC_FC_BOGUS_STRUCT:
2009 return RPC_FC_BOGUS_STRUCT;
2015 if ( has_conformance )
2016 return RPC_FC_CVSTRUCT;
2018 return RPC_FC_BOGUS_STRUCT;
2020 if( has_conformance && has_pointer )
2021 return RPC_FC_CPSTRUCT;
2022 if( has_conformance )
2023 return RPC_FC_CSTRUCT;
2025 return RPC_FC_PSTRUCT;
2026 return RPC_FC_STRUCT;
2029 /***** constant repository *****/
2034 struct rconst *next;
2037 struct rconst *const_hash[HASHMAX];
2039 static var_t *reg_const(var_t *var)
2044 error_loc("registering constant without name\n");
2047 hash = hash_ident(var->name);
2048 nc = xmalloc(sizeof(struct rconst));
2049 nc->name = var->name;
2051 nc->next = const_hash[hash];
2052 const_hash[hash] = nc;
2056 static var_t *find_const(char *name, int f)
2058 struct rconst *cur = const_hash[hash_ident(name)];
2059 while (cur && strcmp(cur->name, name))
2062 if (f) error_loc("constant '%s' not found\n", name);
2068 static void write_libid(const char *name, const attr_list_t *attr)
2070 const UUID *uuid = get_attrp(attr, ATTR_UUID);
2071 write_guid(idfile, "LIBID", name, uuid);
2074 static void write_clsid(type_t *cls)
2076 const UUID *uuid = get_attrp(cls->attrs, ATTR_UUID);
2077 write_guid(idfile, "CLSID", cls->name, uuid);
2080 static void write_diid(type_t *iface)
2082 const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
2083 write_guid(idfile, "DIID", iface->name, uuid);
2086 static void write_iid(type_t *iface)
2088 const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
2089 write_guid(idfile, "IID", iface->name, uuid);
2092 static int compute_method_indexes(type_t *iface)
2098 idx = compute_method_indexes(iface->ref);
2105 LIST_FOR_EACH_ENTRY( f, iface->funcs, func_t, entry )
2106 if (! is_callas(f->def->attrs))
2112 static char *gen_name(void)
2114 static const char format[] = "__WIDL_%s_generated_name_%08lX";
2115 static unsigned long n = 0;
2116 static const char *file_id;
2122 char *dst = dup_basename(input_name, ".idl");
2126 if (! isalnum((unsigned char) *dst))
2129 size = sizeof format - 7 + strlen(file_id) + 8;
2132 name = xmalloc(size);
2133 sprintf(name, format, file_id, n++);
2137 static void process_typedefs(pident_list_t *pidents)
2139 pident_t *pident, *next;
2141 if (!pidents) return;
2142 LIST_FOR_EACH_ENTRY_SAFE( pident, next, pidents, pident_t, entry )
2144 var_t *var = pident->var;
2145 type_t *type = find_type(var->name, 0);
2147 if (! parse_only && do_header)
2148 write_typedef(type);
2149 if (in_typelib && type->attrs)
2150 add_typelib_entry(type);
2159 unsigned int dce_compatible : 1;
2160 unsigned int acf : 1;
2161 unsigned int on_interface : 1;
2162 unsigned int on_function : 1;
2163 unsigned int on_arg : 1;
2164 unsigned int on_type : 1;
2165 unsigned int on_field : 1;
2166 unsigned int on_library : 1;
2167 unsigned int on_dispinterface : 1;
2168 unsigned int on_module : 1;
2169 unsigned int on_coclass : 1;
2170 const char *display_name;
2173 struct allowed_attr allowed_attr[] =
2175 /* attr { D ACF I Fn ARG T Fi L DI M C <display name> } */
2176 /* ATTR_AGGREGATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "aggregatable" },
2177 /* ATTR_APPOBJECT */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "appobject" },
2178 /* ATTR_ASYNC */ { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, "async" },
2179 /* ATTR_AUTO_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "auto_handle" },
2180 /* ATTR_BINDABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "bindable" },
2181 /* ATTR_BROADCAST */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "broadcast" },
2182 /* ATTR_CALLAS */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "call_as" },
2183 /* ATTR_CALLCONV */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL },
2184 /* ATTR_CASE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "case" },
2185 /* ATTR_CONTEXTHANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "context_handle" },
2186 /* ATTR_CONTROL */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, "control" },
2187 /* ATTR_DEFAULT */ { 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, "default" },
2188 /* ATTR_DEFAULTCOLLELEM */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "defaultcollelem" },
2189 /* ATTR_DEFAULTVALUE_EXPR */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "defaultvalue" },
2190 /* ATTR_DEFAULTVALUE_STRING */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "defaultvalue" },
2191 /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "defaultvtable" },
2192 /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL },
2193 /* ATTR_DISPLAYBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "displaybind" },
2194 /* ATTR_DLLNAME */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, "dllname" },
2195 /* ATTR_DUAL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "dual" },
2196 /* ATTR_ENDPOINT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "endpoint" },
2197 /* ATTR_ENTRY_ORDINAL */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "entry" },
2198 /* ATTR_ENTRY_STRING */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "entry" },
2199 /* ATTR_EXPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "explicit_handle" },
2200 /* ATTR_HANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "handle" },
2201 /* ATTR_HELPCONTEXT */ { 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, "helpcontext" },
2202 /* ATTR_HELPFILE */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpfile" },
2203 /* ATTR_HELPSTRING */ { 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, "helpstring" },
2204 /* ATTR_HELPSTRINGCONTEXT */ { 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, "helpstringcontext" },
2205 /* ATTR_HELPSTRINGDLL */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpstringdll" },
2206 /* ATTR_HIDDEN */ { 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, "hidden" },
2207 /* ATTR_ID */ { 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, "id" },
2208 /* ATTR_IDEMPOTENT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "idempotent" },
2209 /* ATTR_IIDIS */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "iid_is" },
2210 /* ATTR_IMMEDIATEBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "immediatebind" },
2211 /* ATTR_IMPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "implicit_handle" },
2212 /* ATTR_IN */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "in" },
2213 /* ATTR_INPUTSYNC */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inputsync" },
2214 /* ATTR_LENGTHIS */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "length_is" },
2215 /* ATTR_LOCAL */ { 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, "local" },
2216 /* ATTR_NONBROWSABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "nonbrowsable" },
2217 /* ATTR_NONCREATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "noncreatable" },
2218 /* ATTR_NONEXTENSIBLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "nonextensible" },
2219 /* ATTR_OBJECT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "object" },
2220 /* ATTR_ODL */ { 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, "odl" },
2221 /* ATTR_OLEAUTOMATION */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "oleautomation" },
2222 /* ATTR_OPTIONAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "optional" },
2223 /* ATTR_OUT */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "out" },
2224 /* ATTR_POINTERDEFAULT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "pointer_default" },
2225 /* ATTR_POINTERTYPE */ { 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, "ref, unique or ptr" },
2226 /* ATTR_PROPGET */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "propget" },
2227 /* ATTR_PROPPUT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "propput" },
2228 /* ATTR_PROPPUTREF */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "propputref" },
2229 /* ATTR_PUBLIC */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "public" },
2230 /* ATTR_RANGE */ { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, "range" },
2231 /* ATTR_READONLY */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "readonly" },
2232 /* ATTR_REQUESTEDIT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "requestedit" },
2233 /* ATTR_RESTRICTED */ { 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, "restricted" },
2234 /* ATTR_RETVAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "retval" },
2235 /* ATTR_SIZEIS */ { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "size_is" },
2236 /* ATTR_SOURCE */ { 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, "source" },
2237 /* ATTR_STRICTCONTEXTHANDLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "strict_context_handle" },
2238 /* ATTR_STRING */ { 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, "string" },
2239 /* ATTR_SWITCHIS */ { 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "switch_is" },
2240 /* ATTR_SWITCHTYPE */ { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, "switch_type" },
2241 /* ATTR_TRANSMITAS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "transmit_as" },
2242 /* ATTR_UUID */ { 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, "uuid" },
2243 /* ATTR_V1ENUM */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "v1_enum" },
2244 /* ATTR_VARARG */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, "vararg" },
2245 /* ATTR_VERSION */ { 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, "version" },
2246 /* ATTR_WIREMARSHAL */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "wire_marshal" },
2249 const char *get_attr_display_name(enum attr_type type)
2251 return allowed_attr[type].display_name;
2254 static const attr_list_t *check_iface_attrs(const char *name, const attr_list_t *attrs)
2257 if (!attrs) return attrs;
2258 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2260 if (!allowed_attr[attr->type].on_interface)
2261 error_loc("inapplicable attribute %s for interface %s\n",
2262 allowed_attr[attr->type].display_name, name);
2267 static attr_list_t *check_function_attrs(const char *name, attr_list_t *attrs)
2270 if (!attrs) return attrs;
2271 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2273 if (!allowed_attr[attr->type].on_function)
2274 error_loc("inapplicable attribute %s for function %s\n",
2275 allowed_attr[attr->type].display_name, name);
2280 static void check_arg(var_t *arg)
2282 const type_t *t = arg->type;
2285 if (t->type == 0 && ! is_var_ptr(arg))
2286 error_loc("argument '%s' has void type\n", arg->name);
2290 LIST_FOR_EACH_ENTRY(attr, arg->attrs, const attr_t, entry)
2292 if (!allowed_attr[attr->type].on_arg)
2293 error_loc("inapplicable attribute %s for argument %s\n",
2294 allowed_attr[attr->type].display_name, arg->name);
2299 static attr_list_t *check_typedef_attrs(attr_list_t *attrs)
2302 if (!attrs) return attrs;
2303 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2305 if (!allowed_attr[attr->type].on_type)
2306 error_loc("inapplicable attribute %s for typedef\n",
2307 allowed_attr[attr->type].display_name);
2312 static attr_list_t *check_field_attrs(const char *name, attr_list_t *attrs)
2315 if (!attrs) return attrs;
2316 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2318 if (!allowed_attr[attr->type].on_field)
2319 error_loc("inapplicable attribute %s for field %s\n",
2320 allowed_attr[attr->type].display_name, name);
2325 static const attr_list_t *check_library_attrs(const char *name, const attr_list_t *attrs)
2328 if (!attrs) return attrs;
2329 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2331 if (!allowed_attr[attr->type].on_library)
2332 error_loc("inapplicable attribute %s for library %s\n",
2333 allowed_attr[attr->type].display_name, name);
2338 static attr_list_t *check_dispiface_attrs(const char *name, attr_list_t *attrs)
2341 if (!attrs) return attrs;
2342 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2344 if (!allowed_attr[attr->type].on_dispinterface)
2345 error_loc("inapplicable attribute %s for dispinterface %s\n",
2346 allowed_attr[attr->type].display_name, name);
2351 static const attr_list_t *check_module_attrs(const char *name, const attr_list_t *attrs)
2354 if (!attrs) return attrs;
2355 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2357 if (!allowed_attr[attr->type].on_module)
2358 error_loc("inapplicable attribute %s for module %s\n",
2359 allowed_attr[attr->type].display_name, name);
2364 static const attr_list_t *check_coclass_attrs(const char *name, const attr_list_t *attrs)
2367 if (!attrs) return attrs;
2368 LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
2370 if (!allowed_attr[attr->type].on_coclass)
2371 error_loc("inapplicable attribute %s for coclass %s\n",
2372 allowed_attr[attr->type].display_name, name);
2377 static void check_remoting_fields(type_t *type);
2379 /* checks that properties common to fields and arguments are consistent */
2380 static void check_field_common(const char *container_type,
2381 const char *container_name, const var_t *arg)
2383 type_t *type = arg->type;
2384 int is_wire_marshal = 0;
2385 int is_context_handle = 0;
2387 if (is_attr(arg->attrs, ATTR_LENGTHIS) &&
2388 (is_attr(arg->attrs, ATTR_STRING) || is_aliaschain_attr(arg->type, ATTR_STRING)))
2389 error_loc_info(&arg->loc_info,
2390 "string and length_is specified for argument %s are mutually exclusive attributes\n",
2393 /* get fundamental type for the argument */
2396 if (is_attr(type->attrs, ATTR_WIREMARSHAL))
2398 is_wire_marshal = 1;
2401 if (is_attr(type->attrs, ATTR_CONTEXTHANDLE))
2403 is_context_handle = 1;
2406 if (type->kind == TKIND_ALIAS)
2408 else if (is_ptr(type) || is_array(type))
2414 if (type->type == 0 && !is_attr(arg->attrs, ATTR_IIDIS) && !is_wire_marshal && !is_context_handle)
2415 error_loc_info(&arg->loc_info, "parameter \'%s\' of %s \'%s\' cannot derive from void *\n", arg->name, container_type, container_name);
2416 else if (type->type == RPC_FC_FUNCTION)
2417 error_loc_info(&arg->loc_info, "parameter \'%s\' of %s \'%s\' cannot be a function pointer\n", arg->name, container_type, container_name);
2418 else if (!is_wire_marshal && (is_struct(type->type) || is_union(type->type)))
2419 check_remoting_fields(type);
2422 static void check_remoting_fields(type_t *type)
2424 const char *container_type = NULL;
2426 const var_list_t *fields = NULL;
2431 type->checked = TRUE;
2433 if (is_struct(type->type))
2435 fields = type->fields_or_args;
2436 container_type = "structure";
2438 else if (is_union(type->type))
2440 if (type->type == RPC_FC_ENCAPSULATED_UNION)
2442 const var_t *uv = LIST_ENTRY(list_tail(type->fields_or_args), const var_t, entry);
2443 fields = uv->type->fields_or_args;
2446 fields = type->fields_or_args;
2447 container_type = "union";
2450 if (fields) LIST_FOR_EACH_ENTRY( field, type->fields_or_args, const var_t, entry )
2451 if (field->type) check_field_common(container_type, type->name, field);
2454 /* checks that arguments for a function make sense for marshalling and unmarshalling */
2455 static void check_remoting_args(const func_t *func)
2457 const char *funcname = func->def->name;
2460 if (func->args) LIST_FOR_EACH_ENTRY( arg, func->args, const var_t, entry )
2463 const type_t *type = arg->type;
2465 /* get pointer level and fundamental type for the argument */
2468 if (is_attr(type->attrs, ATTR_WIREMARSHAL))
2470 if (is_attr(type->attrs, ATTR_CONTEXTHANDLE))
2472 if (type->kind == TKIND_ALIAS)
2474 else if (is_ptr(type))
2483 /* check that [out] parameters have enough pointer levels */
2484 if (is_attr(arg->attrs, ATTR_OUT))
2486 if (!is_array(type))
2489 error_loc_info(&arg->loc_info, "out parameter \'%s\' of function \'%s\' is not a pointer\n", arg->name, funcname);
2490 if (type->type == RPC_FC_IP && ptr_level == 1)
2491 error_loc_info(&arg->loc_info, "out interface pointer \'%s\' of function \'%s\' is not a double pointer\n", arg->name, funcname);
2495 check_field_common("function", funcname, arg);
2499 static void add_explicit_handle_if_necessary(func_t *func)
2501 const var_t* explicit_handle_var;
2502 const var_t* explicit_generic_handle_var = NULL;
2503 const var_t* context_handle_var = NULL;
2505 /* check for a defined binding handle */
2506 explicit_handle_var = get_explicit_handle_var(func);
2507 if (!explicit_handle_var)
2509 explicit_generic_handle_var = get_explicit_generic_handle_var(func);
2510 if (!explicit_generic_handle_var)
2512 context_handle_var = get_context_handle_var(func);
2513 if (!context_handle_var)
2515 /* no explicit handle specified so add
2516 * "[in] handle_t IDL_handle" as the first parameter to the
2518 var_t *idl_handle = make_var(xstrdup("IDL_handle"));
2519 idl_handle->attrs = append_attr(NULL, make_attr(ATTR_IN));
2520 idl_handle->type = find_type("handle_t", 0);
2521 if (!func->def->type->fields_or_args)
2523 func->def->type->fields_or_args = xmalloc( sizeof(*func->def->type->fields_or_args) );
2524 list_init( func->def->type->fields_or_args );
2526 list_add_head( func->def->type->fields_or_args, &idl_handle->entry );
2527 func->args = func->def->type->fields_or_args;
2533 static void check_functions(const type_t *iface)
2535 if (is_attr(iface->attrs, ATTR_EXPLICIT_HANDLE) && iface->funcs)
2538 LIST_FOR_EACH_ENTRY( func, iface->funcs, func_t, entry )
2539 add_explicit_handle_if_necessary(func);
2541 if (!is_inside_library && !is_attr(iface->attrs, ATTR_LOCAL))
2544 if (iface->funcs) LIST_FOR_EACH_ENTRY( func, iface->funcs, const func_t, entry )
2546 if (!is_attr(func->def->attrs, ATTR_LOCAL))
2547 check_remoting_args(func);
2552 static void check_all_user_types(ifref_list_t *ifrefs)
2554 const ifref_t *ifref;
2557 if (ifrefs) LIST_FOR_EACH_ENTRY(ifref, ifrefs, const ifref_t, entry)
2559 const func_list_t *fs = ifref->iface->funcs;
2560 if (fs) LIST_FOR_EACH_ENTRY(f, fs, const func_t, entry)
2561 check_for_additional_prototype_types(f->args);
2565 int is_valid_uuid(const char *s)
2569 for (i = 0; i < 36; ++i)
2570 if (i == 8 || i == 13 || i == 18 || i == 23)
2576 if (!isxdigit(s[i]))
2579 return s[i] == '\0';