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 unsigned char pointer_default = RPC_FC_UP;
68 typedef struct list typelist_t;
74 typelist_t incomplete_types = LIST_INIT(incomplete_types);
76 static void add_incomplete(type_t *t);
77 static void fix_incomplete(void);
79 static str_list_t *append_str(str_list_t *list, char *str);
80 static attr_list_t *append_attr(attr_list_t *list, attr_t *attr);
81 static attr_t *make_attr(enum attr_type type);
82 static attr_t *make_attrv(enum attr_type type, unsigned long val);
83 static attr_t *make_attrp(enum attr_type type, void *val);
84 static expr_t *make_expr(enum expr_type type);
85 static expr_t *make_exprl(enum expr_type type, long val);
86 static expr_t *make_exprd(enum expr_type type, double val);
87 static expr_t *make_exprs(enum expr_type type, char *val);
88 static expr_t *make_exprt(enum expr_type type, type_t *tref, expr_t *expr);
89 static expr_t *make_expr1(enum expr_type type, expr_t *expr);
90 static expr_t *make_expr2(enum expr_type type, expr_t *exp1, expr_t *exp2);
91 static expr_t *make_expr3(enum expr_type type, expr_t *expr1, expr_t *expr2, expr_t *expr3);
92 static type_t *make_type(unsigned char type, type_t *ref);
93 static expr_list_t *append_expr(expr_list_t *list, expr_t *expr);
94 static array_dims_t *append_array(array_dims_t *list, expr_t *expr);
95 static void set_type(var_t *v, type_t *type, int ptr_level, array_dims_t *arr, int top);
96 static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface);
97 static ifref_t *make_ifref(type_t *iface);
98 static var_list_t *append_var(var_list_t *list, var_t *var);
99 static var_t *make_var(char *name);
100 static pident_list_t *append_pident(pident_list_t *list, pident_t *p);
101 static pident_t *make_pident(var_t *var);
102 static func_list_t *append_func(func_list_t *list, func_t *func);
103 static func_t *make_func(var_t *def, var_list_t *args);
104 static type_t *make_class(char *name);
105 static type_t *make_safearray(type_t *type);
106 static type_t *make_builtin(char *name);
107 static type_t *make_int(int sign);
109 static type_t *reg_type(type_t *type, const char *name, int t);
110 static type_t *reg_typedefs(type_t *type, var_list_t *names, attr_list_t *attrs);
111 static type_t *find_type(const char *name, int t);
112 static type_t *find_type2(char *name, int t);
113 static type_t *get_type(unsigned char type, char *name, int t);
114 static type_t *get_typev(unsigned char type, var_t *name, int t);
115 static int get_struct_type(var_list_t *fields);
117 static var_t *reg_const(var_t *var);
118 static var_t *find_const(char *name, int f);
120 static void write_libid(const char *name, const attr_list_t *attr);
121 static void write_clsid(type_t *cls);
122 static void write_diid(type_t *iface);
123 static void write_iid(type_t *iface);
125 static int compute_method_indexes(type_t *iface);
126 static char *gen_name(void);
127 static void process_typedefs(var_list_t *names);
128 static void check_arg(var_t *arg);
129 static void check_all_user_types(ifref_list_t *ifaces);
138 attr_list_t *attr_list;
139 str_list_t *str_list;
141 expr_list_t *expr_list;
142 array_dims_t *array_dims;
145 var_list_t *var_list;
147 pident_list_t *pident_list;
149 func_list_t *func_list;
151 ifref_list_t *ifref_list;
156 interface_info_t ifinfo;
159 %token <str> aIDENTIFIER
160 %token <str> aKNOWNTYPE
161 %token <num> aNUM aHEXNUM
167 %token tAGGREGATABLE tALLOCATE tAPPOBJECT tASYNC tASYNCUUID
168 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
169 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
170 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
171 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
173 %token tDEFAULTCOLLELEM
175 %token tDEFAULTVTABLE
177 %token tDISPINTERFACE
178 %token tDLLNAME tDOUBLE tDUAL
180 %token tENTRY tENUM tERRORSTATUST
181 %token tEXPLICITHANDLE tEXTERN
186 %token tHELPCONTEXT tHELPFILE
187 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
189 %token tHYPER tID tIDEMPOTENT
191 %token tIMMEDIATEBIND
192 %token tIMPLICITHANDLE
193 %token tIMPORT tIMPORTLIB
199 %token tLENGTHIS tLIBRARY
206 %token tNONEXTENSIBLE
207 %token tOBJECT tODL tOLEAUTOMATION
210 %token tPOINTERDEFAULT
212 %token tPROPGET tPROPPUT tPROPPUTREF
216 %token tREADONLY tREF
224 %token tSIZEIS tSIZEOF
228 %token tSTRICTCONTEXTHANDLE
229 %token tSTRING tSTRUCT
230 %token tSWITCH tSWITCHIS tSWITCHTYPE
242 %token tWCHAR tWIREMARSHAL
244 %type <attr> attribute
245 %type <attr_list> m_attributes attributes attrib_list
246 %type <str_list> str_list
247 %type <expr> m_expr expr expr_const
248 %type <expr_list> m_exprs /* exprs expr_list */ expr_list_const
249 %type <array_dims> array array_list
250 %type <ifinfo> interfacehdr
251 %type <type> inherit interface interfacedef interfacedec
252 %type <type> dispinterface dispinterfacehdr dispinterfacedef
253 %type <type> module modulehdr moduledef
254 %type <type> base_type int_std
255 %type <type> enumdef structdef uniondef
257 %type <ifref> coclass_int
258 %type <ifref_list> gbl_statements coclass_ints
259 %type <var> arg field s_field case enum constdef externdef
260 %type <var_list> m_args no_args args fields cases enums enum_list dispint_props
261 %type <var> m_ident t_ident ident
262 %type <pident> p_ident pident
263 %type <pident_list> pident_list
265 %type <func_list> int_statements dispint_meths
266 %type <type> coclass coclasshdr coclassdef
267 %type <num> pointer_type version
268 %type <str> libraryhdr
269 %type <uuid> uuid_string
286 input: gbl_statements { fix_incomplete();
287 check_all_user_types($1);
295 gbl_statements: { $$ = NULL; }
296 | gbl_statements interfacedec { $$ = $1; }
297 | gbl_statements interfacedef { $$ = append_ifref( $1, make_ifref($2) ); }
298 | gbl_statements coclass ';' { $$ = $1;
299 reg_type($2, $2->name, 0);
300 if (!parse_only && do_header) write_coclass_forward($2);
302 | gbl_statements coclassdef { $$ = $1;
303 add_typelib_entry($2);
304 reg_type($2, $2->name, 0);
305 if (!parse_only && do_header) write_coclass_forward($2);
307 | gbl_statements moduledef { $$ = $1; add_typelib_entry($2); }
308 | gbl_statements librarydef { $$ = $1; }
309 | gbl_statements statement { $$ = $1; }
313 | imp_statements interfacedec { if (!parse_only) add_typelib_entry($2); }
314 | imp_statements interfacedef { if (!parse_only) add_typelib_entry($2); }
315 | imp_statements coclass ';' { reg_type($2, $2->name, 0); if (!parse_only && do_header) write_coclass_forward($2); }
316 | imp_statements coclassdef { if (!parse_only) add_typelib_entry($2);
317 reg_type($2, $2->name, 0);
318 if (!parse_only && do_header) write_coclass_forward($2);
320 | imp_statements moduledef { if (!parse_only) add_typelib_entry($2); }
321 | imp_statements statement {}
322 | imp_statements importlib {}
325 int_statements: { $$ = NULL; }
326 | int_statements funcdef ';' { $$ = append_func( $1, $2 ); }
327 | int_statements statement { $$ = $1; }
331 | constdef ';' { if (!parse_only && do_header) { write_constdef($1); } }
333 | enumdef ';' { if (!parse_only && do_header) {
334 write_type_def_or_decl(header, $1, FALSE, NULL);
335 fprintf(header, ";\n\n");
338 | externdef ';' { if (!parse_only && do_header) { write_externdef($1); } }
340 | structdef ';' { if (!parse_only && do_header) {
341 write_type_def_or_decl(header, $1, FALSE, NULL);
342 fprintf(header, ";\n\n");
346 | uniondef ';' { if (!parse_only && do_header) {
347 write_type_def_or_decl(header, $1, FALSE, NULL);
348 fprintf(header, ";\n\n");
353 cppquote: tCPPQUOTE '(' aSTRING ')' { if (!parse_only && do_header) fprintf(header, "%s\n", $3); }
355 import_start: tIMPORT aSTRING ';' { assert(yychar == YYEMPTY);
356 if (!do_import($2)) yychar = aEOF; }
358 import: import_start imp_statements aEOF {}
361 importlib: tIMPORTLIB '(' aSTRING ')' { if(!parse_only) add_importlib($3); }
364 libraryhdr: tLIBRARY aIDENTIFIER { $$ = $2; }
366 library_start: attributes libraryhdr '{' { start_typelib($2, $1);
367 if (!parse_only && do_header) write_library($2, $1);
368 if (!parse_only && do_idfile) write_libid($2, $1);
371 librarydef: library_start imp_statements '}' { end_typelib(); }
374 m_args: { $$ = NULL; }
378 no_args: tVOID { $$ = NULL; }
381 args: arg { check_arg($1); $$ = append_var( NULL, $1 ); }
382 | args ',' arg { check_arg($3); $$ = append_var( $1, $3); }
386 /* split into two rules to get bison to resolve a tVOID conflict */
387 arg: attributes type pident array { $$ = $3->var;
389 set_type($$, $2, $3->ptr_level, $4, TRUE);
392 | type pident array { $$ = $2->var;
393 set_type($$, $1, $2->ptr_level, $3, TRUE);
396 | attributes type pident '(' m_args ')' { $$ = $3->var;
398 set_type($$, $2, $3->ptr_level - 1, NULL, TRUE);
402 | type pident '(' m_args ')' { $$ = $2->var;
403 set_type($$, $1, $2->ptr_level - 1, NULL, TRUE);
409 array: { $$ = NULL; }
410 | '[' array_list ']' { $$ = $2; }
411 | '[' '*' ']' { $$ = append_array( NULL, make_expr(EXPR_VOID) ); }
414 array_list: m_expr /* size of first dimension is optional */ { $$ = append_array( NULL, $1 ); }
415 | array_list ',' expr { $$ = append_array( $1, $3 ); }
416 | array_list ']' '[' expr { $$ = append_array( $1, $4 ); }
419 m_attributes: { $$ = NULL; }
424 '[' attrib_list ']' { $$ = $2;
426 error_loc("empty attribute lists unsupported\n");
430 attrib_list: attribute { $$ = append_attr( NULL, $1 ); }
431 | attrib_list ',' attribute { $$ = append_attr( $1, $3 ); }
432 | attrib_list ']' '[' attribute { $$ = append_attr( $1, $4 ); }
435 str_list: aSTRING { $$ = append_str( NULL, $1 ); }
436 | str_list ',' aSTRING { $$ = append_str( $1, $3 ); }
439 attribute: { $$ = NULL; }
440 | tAGGREGATABLE { $$ = make_attr(ATTR_AGGREGATABLE); }
441 | tAPPOBJECT { $$ = make_attr(ATTR_APPOBJECT); }
442 | tASYNC { $$ = make_attr(ATTR_ASYNC); }
443 | tAUTOHANDLE { $$ = make_attr(ATTR_AUTO_HANDLE); }
444 | tBINDABLE { $$ = make_attr(ATTR_BINDABLE); }
445 | tCALLAS '(' ident ')' { $$ = make_attrp(ATTR_CALLAS, $3); }
446 | tCASE '(' expr_list_const ')' { $$ = make_attrp(ATTR_CASE, $3); }
447 | tCONTEXTHANDLE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); }
448 | tCONTEXTHANDLENOSERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
449 | tCONTEXTHANDLESERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
450 | tCONTROL { $$ = make_attr(ATTR_CONTROL); }
451 | tDEFAULT { $$ = make_attr(ATTR_DEFAULT); }
452 | tDEFAULTCOLLELEM { $$ = make_attr(ATTR_DEFAULTCOLLELEM); }
453 | tDEFAULTVALUE '(' expr_const ')' { $$ = make_attrp(ATTR_DEFAULTVALUE_EXPR, $3); }
454 | tDEFAULTVALUE '(' aSTRING ')' { $$ = make_attrp(ATTR_DEFAULTVALUE_STRING, $3); }
455 | tDEFAULTVTABLE { $$ = make_attr(ATTR_DEFAULTVTABLE); }
456 | tDISPLAYBIND { $$ = make_attr(ATTR_DISPLAYBIND); }
457 | tDLLNAME '(' aSTRING ')' { $$ = make_attrp(ATTR_DLLNAME, $3); }
458 | tDUAL { $$ = make_attr(ATTR_DUAL); }
459 | tENDPOINT '(' str_list ')' { $$ = make_attrp(ATTR_ENDPOINT, $3); }
460 | tENTRY '(' aSTRING ')' { $$ = make_attrp(ATTR_ENTRY_STRING, $3); }
461 | tENTRY '(' expr_const ')' { $$ = make_attrp(ATTR_ENTRY_ORDINAL, $3); }
462 | tEXPLICITHANDLE { $$ = make_attr(ATTR_EXPLICIT_HANDLE); }
463 | tHANDLE { $$ = make_attr(ATTR_HANDLE); }
464 | tHELPCONTEXT '(' expr_const ')' { $$ = make_attrp(ATTR_HELPCONTEXT, $3); }
465 | tHELPFILE '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPFILE, $3); }
466 | tHELPSTRING '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRING, $3); }
467 | tHELPSTRINGCONTEXT '(' expr_const ')' { $$ = make_attrp(ATTR_HELPSTRINGCONTEXT, $3); }
468 | tHELPSTRINGDLL '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRINGDLL, $3); }
469 | tHIDDEN { $$ = make_attr(ATTR_HIDDEN); }
470 | tID '(' expr_const ')' { $$ = make_attrp(ATTR_ID, $3); }
471 | tIDEMPOTENT { $$ = make_attr(ATTR_IDEMPOTENT); }
472 | tIIDIS '(' expr ')' { $$ = make_attrp(ATTR_IIDIS, $3); }
473 | tIMMEDIATEBIND { $$ = make_attr(ATTR_IMMEDIATEBIND); }
474 | tIMPLICITHANDLE '(' tHANDLET aIDENTIFIER ')' { $$ = make_attrp(ATTR_IMPLICIT_HANDLE, $4); }
475 | tIN { $$ = make_attr(ATTR_IN); }
476 | tINPUTSYNC { $$ = make_attr(ATTR_INPUTSYNC); }
477 | tLENGTHIS '(' m_exprs ')' { $$ = make_attrp(ATTR_LENGTHIS, $3); }
478 | tLOCAL { $$ = make_attr(ATTR_LOCAL); }
479 | tNONBROWSABLE { $$ = make_attr(ATTR_NONBROWSABLE); }
480 | tNONCREATABLE { $$ = make_attr(ATTR_NONCREATABLE); }
481 | tNONEXTENSIBLE { $$ = make_attr(ATTR_NONEXTENSIBLE); }
482 | tOBJECT { $$ = make_attr(ATTR_OBJECT); }
483 | tODL { $$ = make_attr(ATTR_ODL); }
484 | tOLEAUTOMATION { $$ = make_attr(ATTR_OLEAUTOMATION); }
485 | tOPTIONAL { $$ = make_attr(ATTR_OPTIONAL); }
486 | tOUT { $$ = make_attr(ATTR_OUT); }
487 | tPOINTERDEFAULT '(' pointer_type ')' { $$ = make_attrv(ATTR_POINTERDEFAULT, $3); }
488 | tPROPGET { $$ = make_attr(ATTR_PROPGET); }
489 | tPROPPUT { $$ = make_attr(ATTR_PROPPUT); }
490 | tPROPPUTREF { $$ = make_attr(ATTR_PROPPUTREF); }
491 | tPUBLIC { $$ = make_attr(ATTR_PUBLIC); }
492 | tRANGE '(' expr_const ',' expr_const ')' { expr_list_t *list = append_expr( NULL, $3 );
493 list = append_expr( list, $5 );
494 $$ = make_attrp(ATTR_RANGE, list); }
495 | tREADONLY { $$ = make_attr(ATTR_READONLY); }
496 | tREQUESTEDIT { $$ = make_attr(ATTR_REQUESTEDIT); }
497 | tRESTRICTED { $$ = make_attr(ATTR_RESTRICTED); }
498 | tRETVAL { $$ = make_attr(ATTR_RETVAL); }
499 | tSIZEIS '(' m_exprs ')' { $$ = make_attrp(ATTR_SIZEIS, $3); }
500 | tSOURCE { $$ = make_attr(ATTR_SOURCE); }
501 | tSTRICTCONTEXTHANDLE { $$ = make_attr(ATTR_STRICTCONTEXTHANDLE); }
502 | tSTRING { $$ = make_attr(ATTR_STRING); }
503 | tSWITCHIS '(' expr ')' { $$ = make_attrp(ATTR_SWITCHIS, $3); }
504 | tSWITCHTYPE '(' type ')' { $$ = make_attrp(ATTR_SWITCHTYPE, $3); }
505 | tTRANSMITAS '(' type ')' { $$ = make_attrp(ATTR_TRANSMITAS, $3); }
506 | tUUID '(' uuid_string ')' { $$ = make_attrp(ATTR_UUID, $3); }
507 | tV1ENUM { $$ = make_attr(ATTR_V1ENUM); }
508 | tVARARG { $$ = make_attr(ATTR_VARARG); }
509 | tVERSION '(' version ')' { $$ = make_attrv(ATTR_VERSION, $3); }
510 | tWIREMARSHAL '(' type ')' { $$ = make_attrp(ATTR_WIREMARSHAL, $3); }
511 | pointer_type { $$ = make_attrv(ATTR_POINTERTYPE, $1); }
516 | aSTRING { if (!is_valid_uuid($1))
517 error_loc("invalid UUID: %s\n", $1);
518 $$ = parse_uuid($1); }
525 cases: { $$ = NULL; }
526 | cases case { $$ = append_var( $1, $2 ); }
529 case: tCASE expr ':' field { attr_t *a = make_attrp(ATTR_CASE, append_expr( NULL, $2 ));
530 $$ = $4; if (!$$) $$ = make_var(NULL);
531 $$->attrs = append_attr( $$->attrs, a );
533 | tDEFAULT ':' field { attr_t *a = make_attr(ATTR_DEFAULT);
534 $$ = $3; if (!$$) $$ = make_var(NULL);
535 $$->attrs = append_attr( $$->attrs, a );
539 constdef: tCONST type ident '=' expr_const { $$ = reg_const($3);
540 set_type($$, $2, 0, NULL, FALSE);
545 enums: { $$ = NULL; }
546 | enum_list ',' { $$ = $1; }
550 enum_list: enum { if (!$1->eval)
551 $1->eval = make_exprl(EXPR_NUM, 0 /* default for first enum entry */);
552 $$ = append_var( NULL, $1 );
554 | enum_list ',' enum { if (!$3->eval)
556 var_t *last = LIST_ENTRY( list_tail($$), var_t, entry );
557 $3->eval = make_exprl(EXPR_NUM, last->eval->cval + 1);
559 $$ = append_var( $1, $3 );
563 enum: ident '=' expr_const { $$ = reg_const($1);
565 $$->type = make_int(0);
567 | ident { $$ = reg_const($1);
568 $$->type = make_int(0);
572 enumdef: tENUM t_ident '{' enums '}' { $$ = get_typev(RPC_FC_ENUM16, $2, tsENUM);
573 $$->kind = TKIND_ENUM;
577 add_typelib_entry($$);
581 m_exprs: m_expr { $$ = append_expr( NULL, $1 ); }
582 | m_exprs ',' m_expr { $$ = append_expr( $1, $3 ); }
586 exprs: { $$ = make_expr(EXPR_VOID); }
591 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
595 m_expr: { $$ = make_expr(EXPR_VOID); }
599 expr: aNUM { $$ = make_exprl(EXPR_NUM, $1); }
600 | aHEXNUM { $$ = make_exprl(EXPR_HEXNUM, $1); }
601 | aDOUBLE { $$ = make_exprd(EXPR_DOUBLE, $1); }
602 | tFALSE { $$ = make_exprl(EXPR_TRUEFALSE, 0); }
603 | tTRUE { $$ = make_exprl(EXPR_TRUEFALSE, 1); }
604 | aIDENTIFIER { $$ = make_exprs(EXPR_IDENTIFIER, $1); }
605 | expr '?' expr ':' expr { $$ = make_expr3(EXPR_COND, $1, $3, $5); }
606 | expr '|' expr { $$ = make_expr2(EXPR_OR , $1, $3); }
607 | expr '&' expr { $$ = make_expr2(EXPR_AND, $1, $3); }
608 | expr '+' expr { $$ = make_expr2(EXPR_ADD, $1, $3); }
609 | expr '-' expr { $$ = make_expr2(EXPR_SUB, $1, $3); }
610 | expr '*' expr { $$ = make_expr2(EXPR_MUL, $1, $3); }
611 | expr '/' expr { $$ = make_expr2(EXPR_DIV, $1, $3); }
612 | expr SHL expr { $$ = make_expr2(EXPR_SHL, $1, $3); }
613 | expr SHR expr { $$ = make_expr2(EXPR_SHR, $1, $3); }
614 | '~' expr { $$ = make_expr1(EXPR_NOT, $2); }
615 | '-' expr %prec NEG { $$ = make_expr1(EXPR_NEG, $2); }
616 | '&' expr %prec ADDRESSOF { $$ = make_expr1(EXPR_ADDRESSOF, $2); }
617 | '*' expr %prec PPTR { $$ = make_expr1(EXPR_PPTR, $2); }
618 | '(' type ')' expr %prec CAST { $$ = make_exprt(EXPR_CAST, $2, $4); }
619 | tSIZEOF '(' type ')' { $$ = make_exprt(EXPR_SIZEOF, $3, NULL); }
620 | '(' expr ')' { $$ = $2; }
623 expr_list_const: expr_const { $$ = append_expr( NULL, $1 ); }
624 | expr_list_const ',' expr_const { $$ = append_expr( $1, $3 ); }
627 expr_const: expr { $$ = $1;
629 error_loc("expression is not constant\n");
633 externdef: tEXTERN tCONST type ident { $$ = $4;
634 set_type($$, $3, 0, NULL, FALSE);
638 fields: { $$ = NULL; }
639 | fields field { $$ = append_var( $1, $2 ); }
642 field: s_field ';' { $$ = $1; }
643 | m_attributes uniondef ';' { $$ = make_var(NULL); $$->type = $2; $$->attrs = $1; }
644 | attributes ';' { $$ = make_var(NULL); $$->attrs = $1; }
648 s_field: m_attributes type pident array { $$ = $3->var;
650 set_type($$, $2, $3->ptr_level, $4, FALSE);
656 m_attributes type callconv pident
657 '(' m_args ')' { var_t *v = $4->var;
659 set_type(v, $2, $4->ptr_level, NULL, FALSE);
661 $$ = make_func(v, $6);
662 if (is_attr(v->attrs, ATTR_IN)) {
663 error_loc("inapplicable attribute [in] for function '%s'\n",$$->def->name);
668 m_ident: { $$ = NULL; }
672 t_ident: { $$ = NULL; }
673 | aIDENTIFIER { $$ = make_var($1); }
674 | aKNOWNTYPE { $$ = make_var($1); }
677 ident: aIDENTIFIER { $$ = make_var($1); }
678 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
679 | aKNOWNTYPE { $$ = make_var($<str>1); }
682 base_type: tBYTE { $$ = make_builtin($<str>1); }
683 | tWCHAR { $$ = make_builtin($<str>1); }
685 | tSIGNED int_std { $$ = $2; $$->sign = 1; }
686 | tUNSIGNED int_std { $$ = $2; $$->sign = -1;
688 case RPC_FC_CHAR: break;
689 case RPC_FC_SMALL: $$->type = RPC_FC_USMALL; break;
690 case RPC_FC_SHORT: $$->type = RPC_FC_USHORT; break;
691 case RPC_FC_LONG: $$->type = RPC_FC_ULONG; break;
693 if ($$->name[0] == 'h') /* hyper, as opposed to __int64 */
695 $$ = alias($$, "MIDL_uhyper");
702 | tUNSIGNED { $$ = make_int(-1); }
703 | tFLOAT { $$ = make_builtin($<str>1); }
704 | tSINGLE { $$ = duptype(find_type("float", 0), 1); }
705 | tDOUBLE { $$ = make_builtin($<str>1); }
706 | tBOOLEAN { $$ = make_builtin($<str>1); }
707 | tERRORSTATUST { $$ = make_builtin($<str>1); }
708 | tHANDLET { $$ = make_builtin($<str>1); }
715 int_std: tINT { $$ = make_builtin($<str>1); }
716 | tSHORT m_int { $$ = make_builtin($<str>1); }
717 | tSMALL { $$ = make_builtin($<str>1); }
718 | tLONG m_int { $$ = make_builtin($<str>1); }
719 | tHYPER m_int { $$ = make_builtin($<str>1); }
720 | tINT64 { $$ = make_builtin($<str>1); }
721 | tCHAR { $$ = make_builtin($<str>1); }
724 coclass: tCOCLASS aIDENTIFIER { $$ = make_class($2); }
725 | tCOCLASS aKNOWNTYPE { $$ = find_type($2, 0);
726 if ($$->defined) error_loc("multiple definition error\n");
727 if ($$->kind != TKIND_COCLASS) error_loc("%s was not declared a coclass\n", $2);
731 coclasshdr: attributes coclass { $$ = $2;
733 if (!parse_only && do_header)
735 if (!parse_only && do_idfile)
740 coclassdef: coclasshdr '{' coclass_ints '}' { $$ = $1;
746 coclass_ints: { $$ = NULL; }
747 | coclass_ints coclass_int { $$ = append_ifref( $1, $2 ); }
751 m_attributes interfacedec { $$ = make_ifref($2); $$->attrs = $1; }
754 dispinterface: tDISPINTERFACE aIDENTIFIER { $$ = get_type(0, $2, 0); $$->kind = TKIND_DISPATCH; }
755 | tDISPINTERFACE aKNOWNTYPE { $$ = get_type(0, $2, 0); $$->kind = TKIND_DISPATCH; }
758 dispinterfacehdr: attributes dispinterface { attr_t *attrs;
760 if ($$->defined) error_loc("multiple definition error\n");
761 attrs = make_attr(ATTR_DISPINTERFACE);
762 $$->attrs = append_attr( $1, attrs );
763 $$->ref = find_type("IDispatch", 0);
764 if (!$$->ref) error_loc("IDispatch is undefined\n");
766 if (!parse_only && do_header) write_forward($$);
770 dispint_props: tPROPERTIES ':' { $$ = NULL; }
771 | dispint_props s_field ';' { $$ = append_var( $1, $2 ); }
774 dispint_meths: tMETHODS ':' { $$ = NULL; }
775 | dispint_meths funcdef ';' { $$ = append_func( $1, $2 ); }
778 dispinterfacedef: dispinterfacehdr '{'
784 if (!parse_only && do_header) write_dispinterface($$);
785 if (!parse_only && do_idfile) write_diid($$);
788 '{' interface ';' '}' { $$ = $1;
789 $$->fields = $3->fields;
790 $$->funcs = $3->funcs;
791 if (!parse_only && do_header) write_dispinterface($$);
792 if (!parse_only && do_idfile) write_diid($$);
796 inherit: { $$ = NULL; }
797 | ':' aKNOWNTYPE { $$ = find_type2($2, 0); }
800 interface: tINTERFACE aIDENTIFIER { $$ = get_type(RPC_FC_IP, $2, 0); $$->kind = TKIND_INTERFACE; }
801 | tINTERFACE aKNOWNTYPE { $$ = get_type(RPC_FC_IP, $2, 0); $$->kind = TKIND_INTERFACE; }
804 interfacehdr: attributes interface { $$.interface = $2;
805 $$.old_pointer_default = pointer_default;
806 if (is_attr($1, ATTR_POINTERDEFAULT))
807 pointer_default = get_attrv($1, ATTR_POINTERDEFAULT);
808 if ($2->defined) error_loc("multiple definition error\n");
811 if (!parse_only && do_header) write_forward($2);
815 interfacedef: interfacehdr inherit
816 '{' int_statements '}' { $$ = $1.interface;
819 compute_method_indexes($$);
820 if (!parse_only && do_header) write_interface($$);
821 if (!parse_only && local_stubs) write_locals(local_stubs, $$, TRUE);
822 if (!parse_only && do_idfile) write_iid($$);
823 pointer_default = $1.old_pointer_default;
825 /* MIDL is able to import the definition of a base class from inside the
826 * definition of a derived class, I'll try to support it with this rule */
827 | interfacehdr ':' aIDENTIFIER
828 '{' import int_statements '}' { $$ = $1.interface;
829 $$->ref = find_type2($3, 0);
830 if (!$$->ref) error_loc("base class '%s' not found in import\n", $3);
832 compute_method_indexes($$);
833 if (!parse_only && do_header) write_interface($$);
834 if (!parse_only && local_stubs) write_locals(local_stubs, $$, TRUE);
835 if (!parse_only && do_idfile) write_iid($$);
836 pointer_default = $1.old_pointer_default;
838 | dispinterfacedef { $$ = $1; }
842 interface ';' { $$ = $1; if (!parse_only && do_header) write_forward($$); }
843 | dispinterface ';' { $$ = $1; if (!parse_only && do_header) write_forward($$); }
846 module: tMODULE aIDENTIFIER { $$ = make_type(0, NULL); $$->name = $2; $$->kind = TKIND_MODULE; }
847 | tMODULE aKNOWNTYPE { $$ = make_type(0, NULL); $$->name = $2; $$->kind = TKIND_MODULE; }
850 modulehdr: attributes module { $$ = $2;
855 moduledef: modulehdr '{' int_statements '}' { $$ = $1;
857 /* FIXME: if (!parse_only && do_header) write_module($$); */
861 p_ident: '*' pident %prec PPTR { $$ = $2; $$->ptr_level++; }
862 | tCONST p_ident { $$ = $2; /* FIXME */ }
865 pident: ident { $$ = make_pident($1); }
867 | '(' pident ')' { $$ = $2; }
871 pident { $$ = append_pident( NULL, $1 ); }
872 | pident_list ',' pident { $$ = append_pident( $1, $3 ); }
876 tREF { $$ = RPC_FC_RP; }
877 | tUNIQUE { $$ = RPC_FC_UP; }
878 | tPTR { $$ = RPC_FC_FP; }
881 structdef: tSTRUCT t_ident '{' fields '}' { $$ = get_typev(RPC_FC_STRUCT, $2, tsSTRUCT);
882 /* overwrite RPC_FC_STRUCT with a more exact type */
883 $$->type = get_struct_type( $4 );
884 $$->kind = TKIND_RECORD;
888 add_typelib_entry($$);
892 type: tVOID { $$ = duptype(find_type("void", 0), 1); }
893 | aKNOWNTYPE { $$ = find_type($1, 0); }
894 | base_type { $$ = $1; }
895 | tCONST type { $$ = duptype($2, 1); $$->is_const = TRUE; }
896 | enumdef { $$ = $1; }
897 | tENUM aIDENTIFIER { $$ = find_type2($2, tsENUM); }
898 | structdef { $$ = $1; }
899 | tSTRUCT aIDENTIFIER { $$ = get_type(RPC_FC_STRUCT, $2, tsSTRUCT); }
900 | uniondef { $$ = $1; }
901 | tUNION aIDENTIFIER { $$ = find_type2($2, tsUNION); }
902 | tSAFEARRAY '(' type ')' { $$ = make_safearray($3); }
905 typedef: tTYPEDEF m_attributes type pident_list { reg_typedefs($3, $4, $2);
906 process_typedefs($4);
910 uniondef: tUNION t_ident '{' fields '}' { $$ = get_typev(RPC_FC_NON_ENCAPSULATED_UNION, $2, tsUNION);
911 $$->kind = TKIND_UNION;
916 tSWITCH '(' s_field ')'
917 m_ident '{' cases '}' { var_t *u = $7;
918 $$ = get_typev(RPC_FC_ENCAPSULATED_UNION, $2, tsUNION);
919 $$->kind = TKIND_UNION;
920 if (!u) u = make_var( xstrdup("tagged_union") );
921 u->type = make_type(RPC_FC_NON_ENCAPSULATED_UNION, NULL);
922 u->type->kind = TKIND_UNION;
923 u->type->fields = $9;
924 u->type->defined = TRUE;
925 $$->fields = append_var( $$->fields, $5 );
926 $$->fields = append_var( $$->fields, u );
932 aNUM { $$ = MAKEVERSION($1, 0); }
933 | aNUM '.' aNUM { $$ = MAKEVERSION($1, $3); }
938 static void decl_builtin(const char *name, unsigned char type)
940 type_t *t = make_type(type, NULL);
941 t->name = xstrdup(name);
942 reg_type(t, name, 0);
945 static type_t *make_builtin(char *name)
947 /* NAME is strdup'd in the lexer */
948 type_t *t = duptype(find_type(name, 0), 0);
953 static type_t *make_int(int sign)
955 type_t *t = duptype(find_type("int", 0), 1);
959 t->type = t->type == RPC_FC_LONG ? RPC_FC_ULONG : RPC_FC_USHORT;
964 void init_types(void)
966 decl_builtin("void", 0);
967 decl_builtin("byte", RPC_FC_BYTE);
968 decl_builtin("wchar_t", RPC_FC_WCHAR);
969 decl_builtin("int", RPC_FC_LONG); /* win32 */
970 decl_builtin("short", RPC_FC_SHORT);
971 decl_builtin("small", RPC_FC_SMALL);
972 decl_builtin("long", RPC_FC_LONG);
973 decl_builtin("hyper", RPC_FC_HYPER);
974 decl_builtin("__int64", RPC_FC_HYPER);
975 decl_builtin("char", RPC_FC_CHAR);
976 decl_builtin("float", RPC_FC_FLOAT);
977 decl_builtin("double", RPC_FC_DOUBLE);
978 decl_builtin("boolean", RPC_FC_BYTE);
979 decl_builtin("error_status_t", RPC_FC_ERROR_STATUS_T);
980 decl_builtin("handle_t", RPC_FC_BIND_PRIMITIVE);
983 static str_list_t *append_str(str_list_t *list, char *str)
985 struct str_list_entry_t *entry;
987 if (!str) return list;
990 list = xmalloc( sizeof(*list) );
993 entry = xmalloc( sizeof(*entry) );
995 list_add_tail( list, &entry->entry );
999 static attr_list_t *append_attr(attr_list_t *list, attr_t *attr)
1001 if (!attr) return list;
1004 list = xmalloc( sizeof(*list) );
1007 list_add_tail( list, &attr->entry );
1011 static attr_t *make_attr(enum attr_type type)
1013 attr_t *a = xmalloc(sizeof(attr_t));
1019 static attr_t *make_attrv(enum attr_type type, unsigned long val)
1021 attr_t *a = xmalloc(sizeof(attr_t));
1027 static attr_t *make_attrp(enum attr_type type, void *val)
1029 attr_t *a = xmalloc(sizeof(attr_t));
1035 static expr_t *make_expr(enum expr_type type)
1037 expr_t *e = xmalloc(sizeof(expr_t));
1041 e->is_const = FALSE;
1046 static expr_t *make_exprl(enum expr_type type, long val)
1048 expr_t *e = xmalloc(sizeof(expr_t));
1052 e->is_const = FALSE;
1053 /* check for numeric constant */
1054 if (type == EXPR_NUM || type == EXPR_HEXNUM || type == EXPR_TRUEFALSE) {
1055 /* make sure true/false value is valid */
1056 assert(type != EXPR_TRUEFALSE || val == 0 || val == 1);
1063 static expr_t *make_exprd(enum expr_type type, double val)
1065 expr_t *e = xmalloc(sizeof(expr_t));
1074 static expr_t *make_exprs(enum expr_type type, char *val)
1077 e = xmalloc(sizeof(expr_t));
1081 e->is_const = FALSE;
1082 /* check for predefined constants */
1083 if (type == EXPR_IDENTIFIER) {
1084 var_t *c = find_const(val, 0);
1086 e->u.sval = c->name;
1089 e->cval = c->eval->cval;
1095 static expr_t *make_exprt(enum expr_type type, type_t *tref, expr_t *expr)
1098 e = xmalloc(sizeof(expr_t));
1102 e->is_const = FALSE;
1103 /* check for cast of constant expression */
1104 if (type == EXPR_SIZEOF) {
1105 switch (tref->type) {
1122 case RPC_FC_ERROR_STATUS_T:
1133 if (type == EXPR_CAST && expr->is_const) {
1135 e->cval = expr->cval;
1140 static expr_t *make_expr1(enum expr_type type, expr_t *expr)
1143 if (type == EXPR_ADDRESSOF && expr->type != EXPR_IDENTIFIER)
1144 error("address-of operator applied to invalid expression\n");
1145 e = xmalloc(sizeof(expr_t));
1149 e->is_const = FALSE;
1150 /* check for compile-time optimization */
1151 if (expr->is_const) {
1155 e->cval = -expr->cval;
1158 e->cval = ~expr->cval;
1161 e->is_const = FALSE;
1168 static expr_t *make_expr2(enum expr_type type, expr_t *expr1, expr_t *expr2)
1171 e = xmalloc(sizeof(expr_t));
1175 e->is_const = FALSE;
1176 /* check for compile-time optimization */
1177 if (expr1->is_const && expr2->is_const) {
1181 e->cval = expr1->cval + expr2->cval;
1184 e->cval = expr1->cval - expr2->cval;
1187 e->cval = expr1->cval * expr2->cval;
1190 e->cval = expr1->cval / expr2->cval;
1193 e->cval = expr1->cval | expr2->cval;
1196 e->cval = expr1->cval & expr2->cval;
1199 e->cval = expr1->cval << expr2->cval;
1202 e->cval = expr1->cval >> expr2->cval;
1205 e->is_const = FALSE;
1212 static expr_t *make_expr3(enum expr_type type, expr_t *expr1, expr_t *expr2, expr_t *expr3)
1215 e = xmalloc(sizeof(expr_t));
1220 e->is_const = FALSE;
1221 /* check for compile-time optimization */
1222 if (expr1->is_const && expr2->is_const && expr3->is_const) {
1226 e->cval = expr1->cval ? expr2->cval : expr3->cval;
1229 e->is_const = FALSE;
1236 static expr_list_t *append_expr(expr_list_t *list, expr_t *expr)
1238 if (!expr) return list;
1241 list = xmalloc( sizeof(*list) );
1244 list_add_tail( list, &expr->entry );
1248 static array_dims_t *append_array(array_dims_t *list, expr_t *expr)
1250 if (!expr) return list;
1253 list = xmalloc( sizeof(*list) );
1256 list_add_tail( list, &expr->entry );
1260 static struct list type_pool = LIST_INIT(type_pool);
1267 type_t *alloc_type(void)
1269 type_pool_node_t *node = xmalloc(sizeof *node);
1270 list_add_tail(&type_pool, &node->link);
1274 void set_all_tfswrite(int val)
1276 type_pool_node_t *node;
1277 LIST_FOR_EACH_ENTRY(node, &type_pool, type_pool_node_t, link)
1278 node->data.tfswrite = val;
1281 static type_t *make_type(unsigned char type, type_t *ref)
1283 type_t *t = alloc_type();
1285 t->kind = TKIND_PRIMITIVE;
1295 t->length_is = NULL;
1296 t->typestring_offset = 0;
1298 t->declarray = FALSE;
1299 t->ignore = (parse_only != 0);
1300 t->is_const = FALSE;
1304 t->user_types_registered = FALSE;
1305 t->tfswrite = FALSE;
1306 t->typelib_idx = -1;
1310 static void set_type(var_t *v, type_t *type, int ptr_level, array_dims_t *arr,
1313 expr_list_t *sizes = get_attrp(v->attrs, ATTR_SIZEIS);
1314 expr_list_t *lengs = get_attrp(v->attrs, ATTR_LENGTHIS);
1315 int ptr_attr = get_attrv(v->attrs, ATTR_POINTERTYPE);
1316 int ptr_type = ptr_attr;
1317 int sizeless, has_varconf;
1319 type_t *atype, **ptype;
1323 if (!ptr_type && top)
1324 ptr_type = RPC_FC_RP;
1326 for ( ; 0 < ptr_level; --ptr_level)
1328 v->type = make_type(pointer_default, v->type);
1329 if (ptr_level == 1 && ptr_type && !arr)
1331 v->type->type = ptr_type;
1336 if (ptr_type && !arr)
1338 if (is_ptr(v->type))
1340 if (v->type->type != ptr_type)
1342 v->type = duptype(v->type, 1);
1343 v->type->type = ptr_type;
1346 else if (!arr && ptr_attr)
1347 error("%s: pointer attribute applied to non-pointer type\n", v->name);
1351 if (arr) LIST_FOR_EACH_ENTRY_REV(dim, arr, expr_t, entry)
1354 error("%s: only the first array dimension can be unspecified\n", v->name);
1358 unsigned int align = 0;
1359 size_t size = type_memsize(v->type, &align);
1362 error("%s: array dimension must be positive\n", v->name);
1364 if (0xffffffffuL / size < (unsigned long) dim->cval)
1365 error("%s: total array size is too large\n", v->name);
1366 else if (0xffffuL < size * dim->cval)
1367 v->type = make_type(RPC_FC_LGFARRAY, v->type);
1369 v->type = make_type(RPC_FC_SMFARRAY, v->type);
1374 v->type = make_type(RPC_FC_CARRAY, v->type);
1377 v->type->declarray = TRUE;
1378 v->type->dim = dim->cval;
1382 has_varconf = FALSE;
1383 if (sizes) LIST_FOR_EACH_ENTRY(dim, sizes, expr_t, entry)
1385 if (dim->type != EXPR_VOID)
1388 atype = *ptype = duptype(*ptype, 0);
1390 if (atype->type == RPC_FC_SMFARRAY || atype->type == RPC_FC_LGFARRAY)
1391 error("%s: cannot specify size_is for a fixed sized array\n", v->name);
1393 if (atype->type != RPC_FC_CARRAY && !is_ptr(atype))
1394 error("%s: size_is attribute applied to illegal type\n", v->name);
1396 atype->type = RPC_FC_CARRAY;
1397 atype->size_is = dim;
1400 ptype = &(*ptype)->ref;
1402 error("%s: too many expressions in size_is attribute\n", v->name);
1406 if (lengs) LIST_FOR_EACH_ENTRY(dim, lengs, expr_t, entry)
1408 if (dim->type != EXPR_VOID)
1411 atype = *ptype = duptype(*ptype, 0);
1413 if (atype->type == RPC_FC_SMFARRAY)
1414 atype->type = RPC_FC_SMVARRAY;
1415 else if (atype->type == RPC_FC_LGFARRAY)
1416 atype->type = RPC_FC_LGVARRAY;
1417 else if (atype->type == RPC_FC_CARRAY)
1418 atype->type = RPC_FC_CVARRAY;
1420 error("%s: length_is attribute applied to illegal type\n", v->name);
1422 atype->length_is = dim;
1425 ptype = &(*ptype)->ref;
1427 error("%s: too many expressions in length_is attribute\n", v->name);
1430 if (has_varconf && !last_array(v->type))
1433 for (ptype = &v->type; is_array(*ptype); ptype = &(*ptype)->ref)
1435 *ptype = duptype(*ptype, 0);
1436 (*ptype)->type = RPC_FC_BOGUS_ARRAY;
1440 if (is_array(v->type))
1442 const type_t *rt = v->type->ref;
1443 if (is_user_type(rt))
1444 v->type->type = RPC_FC_BOGUS_ARRAY;
1448 case RPC_FC_BOGUS_STRUCT:
1449 case RPC_FC_NON_ENCAPSULATED_UNION:
1450 case RPC_FC_ENCAPSULATED_UNION:
1452 v->type->type = RPC_FC_BOGUS_ARRAY;
1454 /* FC_RP should be above, but widl overuses these, and will break things. */
1457 if (rt->ref->type == RPC_FC_IP)
1458 v->type->type = RPC_FC_BOGUS_ARRAY;
1464 static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface)
1466 if (!iface) return list;
1469 list = xmalloc( sizeof(*list) );
1472 list_add_tail( list, &iface->entry );
1476 static ifref_t *make_ifref(type_t *iface)
1478 ifref_t *l = xmalloc(sizeof(ifref_t));
1484 static var_list_t *append_var(var_list_t *list, var_t *var)
1486 if (!var) return list;
1489 list = xmalloc( sizeof(*list) );
1492 list_add_tail( list, &var->entry );
1496 static var_t *make_var(char *name)
1498 var_t *v = xmalloc(sizeof(var_t));
1507 static pident_list_t *append_pident(pident_list_t *list, pident_t *p)
1509 if (!p) return list;
1511 list = xmalloc(sizeof(*list));
1514 list_add_tail(list, &p->entry);
1518 static pident_t *make_pident(var_t *var)
1520 pident_t *p = xmalloc(sizeof(*p));
1526 static func_list_t *append_func(func_list_t *list, func_t *func)
1528 if (!func) return list;
1531 list = xmalloc( sizeof(*list) );
1534 list_add_tail( list, &func->entry );
1538 static func_t *make_func(var_t *def, var_list_t *args)
1540 func_t *f = xmalloc(sizeof(func_t));
1543 f->ignore = parse_only;
1548 static type_t *make_class(char *name)
1550 type_t *c = make_type(0, NULL);
1552 c->kind = TKIND_COCLASS;
1556 static type_t *make_safearray(type_t *type)
1558 type_t *sa = duptype(find_type("SAFEARRAY", 0), 1);
1560 return make_type(pointer_default, sa);
1565 static int hash_ident(const char *name)
1567 const char *p = name;
1569 /* a simple sum hash is probably good enough */
1574 return sum & (HASHMAX-1);
1577 /***** type repository *****/
1586 struct rtype *type_hash[HASHMAX];
1588 static type_t *reg_type(type_t *type, const char *name, int t)
1593 error_loc("registering named type without name\n");
1596 hash = hash_ident(name);
1597 nt = xmalloc(sizeof(struct rtype));
1601 nt->next = type_hash[hash];
1602 type_hash[hash] = nt;
1606 static int is_incomplete(const type_t *t)
1608 return !t->defined && (is_struct(t->type) || is_union(t->type));
1611 static void add_incomplete(type_t *t)
1613 struct typenode *tn = xmalloc(sizeof *tn);
1615 list_add_tail(&incomplete_types, &tn->entry);
1618 static void fix_type(type_t *t)
1620 if (t->kind == TKIND_ALIAS && is_incomplete(t)) {
1621 type_t *ot = t->orig;
1623 t->fields = ot->fields;
1624 t->defined = ot->defined;
1628 static void fix_incomplete(void)
1630 struct typenode *tn, *next;
1632 LIST_FOR_EACH_ENTRY_SAFE(tn, next, &incomplete_types, struct typenode, entry) {
1638 static type_t *reg_typedefs(type_t *type, pident_list_t *pidents, attr_list_t *attrs)
1641 const pident_t *pident;
1643 int is_str = is_attr(attrs, ATTR_STRING);
1644 unsigned char ptr_type = get_attrv(attrs, ATTR_POINTERTYPE);
1655 if (c != RPC_FC_CHAR && c != RPC_FC_BYTE && c != RPC_FC_WCHAR)
1657 pident = LIST_ENTRY( list_head( pidents ), const pident_t, entry );
1658 error_loc("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
1663 /* We must generate names for tagless enum, struct or union.
1664 Typedef-ing a tagless enum, struct or union means we want the typedef
1665 to be included in a library whether it has other attributes or not,
1666 hence the public attribute. */
1667 if ((type->kind == TKIND_ENUM || type->kind == TKIND_RECORD
1668 || type->kind == TKIND_UNION) && ! type->name && ! parse_only)
1670 if (! is_attr(attrs, ATTR_PUBLIC))
1671 attrs = append_attr( attrs, make_attr(ATTR_PUBLIC) );
1672 type->name = gen_name();
1675 LIST_FOR_EACH_ENTRY( pident, pidents, const pident_t, entry )
1677 var_t *name = pident->var;
1681 int cptr = pident->ptr_level;
1683 while (cptr > ptrc) {
1684 cur = ptr = make_type(pointer_default, cur);
1688 while (cptr < ptrc) {
1693 cur = alias(cur, name->name);
1698 cur->type = ptr_type;
1700 error_loc("'%s': pointer attribute applied to non-pointer type\n",
1703 else if (is_str && ! is_ptr(cur))
1704 error_loc("'%s': [string] attribute applied to non-pointer type\n",
1707 if (is_incomplete(cur))
1708 add_incomplete(cur);
1709 reg_type(cur, cur->name, 0);
1715 static type_t *find_type(const char *name, int t)
1717 struct rtype *cur = type_hash[hash_ident(name)];
1718 while (cur && (cur->t != t || strcmp(cur->name, name)))
1721 error_loc("type '%s' not found\n", name);
1727 static type_t *find_type2(char *name, int t)
1729 type_t *tp = find_type(name, t);
1734 int is_type(const char *name)
1736 struct rtype *cur = type_hash[hash_ident(name)];
1737 while (cur && (cur->t || strcmp(cur->name, name)))
1739 if (cur) return TRUE;
1743 static type_t *get_type(unsigned char type, char *name, int t)
1745 struct rtype *cur = NULL;
1748 cur = type_hash[hash_ident(name)];
1749 while (cur && (cur->t != t || strcmp(cur->name, name)))
1756 tp = make_type(type, NULL);
1758 if (!name) return tp;
1759 return reg_type(tp, name, t);
1762 static type_t *get_typev(unsigned char type, var_t *name, int t)
1769 return get_type(type, sname, t);
1772 static int get_struct_type(var_list_t *fields)
1774 int has_pointer = 0;
1775 int has_conformance = 0;
1776 int has_variance = 0;
1779 if (get_padding(fields))
1780 return RPC_FC_BOGUS_STRUCT;
1782 if (fields) LIST_FOR_EACH_ENTRY( field, fields, var_t, entry )
1784 type_t *t = field->type;
1786 if (is_user_type(t))
1787 return RPC_FC_BOGUS_STRUCT;
1798 case RPC_FC_ENCAPSULATED_UNION:
1799 case RPC_FC_NON_ENCAPSULATED_UNION:
1800 case RPC_FC_BOGUS_STRUCT:
1801 return RPC_FC_BOGUS_STRUCT;
1808 if (field->type->declarray)
1810 if (is_string_type(field->attrs, field->type))
1812 if (is_conformant_array(field->type))
1813 has_conformance = 1;
1818 if (is_array(field->type->ref))
1819 return RPC_FC_BOGUS_STRUCT;
1821 if (is_conformant_array(field->type))
1823 has_conformance = 1;
1824 if (field->type->declarray && list_next(fields, &field->entry))
1825 error_loc("field '%s' deriving from a conformant array must be the last field in the structure\n",
1828 if (field->type->length_is)
1831 t = field->type->ref;
1837 * RPC_FC_BYTE, RPC_FC_STRUCT, etc
1838 * Simple types don't effect the type of struct.
1839 * A struct containing a simple struct is still a simple struct.
1840 * So long as we can block copy the data, we return RPC_FC_STRUCT.
1842 case 0: /* void pointer */
1852 case RPC_FC_INT3264:
1853 case RPC_FC_UINT3264:
1867 case RPC_FC_CVARRAY:
1868 case RPC_FC_BOGUS_ARRAY:
1873 * Propagate member attributes
1874 * a struct should be at least as complex as its member
1876 case RPC_FC_CVSTRUCT:
1877 has_conformance = 1;
1882 case RPC_FC_CPSTRUCT:
1883 has_conformance = 1;
1884 if (list_next( fields, &field->entry ))
1885 error_loc("field '%s' deriving from a conformant array must be the last field in the structure\n",
1890 case RPC_FC_CSTRUCT:
1891 has_conformance = 1;
1892 if (list_next( fields, &field->entry ))
1893 error_loc("field '%s' deriving from a conformant array must be the last field in the structure\n",
1897 case RPC_FC_PSTRUCT:
1902 error_loc("Unknown struct member %s with type (0x%02x)\n", field->name, t->type);
1903 /* fallthru - treat it as complex */
1905 /* as soon as we see one of these these members, it's bogus... */
1906 case RPC_FC_ENCAPSULATED_UNION:
1907 case RPC_FC_NON_ENCAPSULATED_UNION:
1908 case RPC_FC_BOGUS_STRUCT:
1909 return RPC_FC_BOGUS_STRUCT;
1915 if ( has_conformance )
1916 return RPC_FC_CVSTRUCT;
1918 return RPC_FC_BOGUS_STRUCT;
1920 if( has_conformance && has_pointer )
1921 return RPC_FC_CPSTRUCT;
1922 if( has_conformance )
1923 return RPC_FC_CSTRUCT;
1925 return RPC_FC_PSTRUCT;
1926 return RPC_FC_STRUCT;
1929 /***** constant repository *****/
1934 struct rconst *next;
1937 struct rconst *const_hash[HASHMAX];
1939 static var_t *reg_const(var_t *var)
1944 error_loc("registering constant without name\n");
1947 hash = hash_ident(var->name);
1948 nc = xmalloc(sizeof(struct rconst));
1949 nc->name = var->name;
1951 nc->next = const_hash[hash];
1952 const_hash[hash] = nc;
1956 static var_t *find_const(char *name, int f)
1958 struct rconst *cur = const_hash[hash_ident(name)];
1959 while (cur && strcmp(cur->name, name))
1962 if (f) error_loc("constant '%s' not found\n", name);
1968 static void write_libid(const char *name, const attr_list_t *attr)
1970 const UUID *uuid = get_attrp(attr, ATTR_UUID);
1971 write_guid(idfile, "LIBID", name, uuid);
1974 static void write_clsid(type_t *cls)
1976 const UUID *uuid = get_attrp(cls->attrs, ATTR_UUID);
1977 write_guid(idfile, "CLSID", cls->name, uuid);
1980 static void write_diid(type_t *iface)
1982 const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
1983 write_guid(idfile, "DIID", iface->name, uuid);
1986 static void write_iid(type_t *iface)
1988 const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
1989 write_guid(idfile, "IID", iface->name, uuid);
1992 static int compute_method_indexes(type_t *iface)
1998 idx = compute_method_indexes(iface->ref);
2005 LIST_FOR_EACH_ENTRY( f, iface->funcs, func_t, entry )
2006 if (! is_callas(f->def->attrs))
2012 static char *gen_name(void)
2014 static const char format[] = "__WIDL_%s_generated_name_%08lX";
2015 static unsigned long n = 0;
2016 static const char *file_id;
2022 char *dst = dup_basename(input_name, ".idl");
2026 if (! isalnum((unsigned char) *dst))
2029 size = sizeof format - 7 + strlen(file_id) + 8;
2032 name = xmalloc(size);
2033 sprintf(name, format, file_id, n++);
2037 static void process_typedefs(pident_list_t *pidents)
2039 pident_t *pident, *next;
2041 if (!pidents) return;
2042 LIST_FOR_EACH_ENTRY_SAFE( pident, next, pidents, pident_t, entry )
2044 var_t *var = pident->var;
2045 type_t *type = find_type(var->name, 0);
2047 if (! parse_only && do_header)
2048 write_typedef(type);
2049 if (in_typelib && type->attrs)
2050 add_typelib_entry(type);
2057 static void check_arg(var_t *arg)
2059 type_t *t = arg->type;
2061 if (t->type == 0 && ! is_var_ptr(arg))
2062 error_loc("argument '%s' has void type\n", arg->name);
2065 static void check_all_user_types(ifref_list_t *ifrefs)
2067 const ifref_t *ifref;
2070 if (ifrefs) LIST_FOR_EACH_ENTRY(ifref, ifrefs, const ifref_t, entry)
2072 const func_list_t *fs = ifref->iface->funcs;
2073 if (fs) LIST_FOR_EACH_ENTRY(f, fs, const func_t, entry)
2074 check_for_user_types_and_context_handles(f->args);
2078 int is_valid_uuid(const char *s)
2082 for (i = 0; i < 36; ++i)
2083 if (i == 8 || i == 13 || i == 18 || i == 23)
2089 if (!isxdigit(s[i]))
2092 return s[i] == '\0';