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
44 /* Berkeley yacc (byacc) doesn't seem to know about these */
45 /* Some *BSD supplied versions do define these though */
47 # define YYEMPTY (-1) /* Empty lookahead value of yychar */
50 # define YYLEX yylex()
53 #elif defined(YYBISON)
54 /* Bison was used for original development */
55 /* #define YYEMPTY -2 */
56 /* #define YYLEX yylex() */
59 /* No yacc we know yet */
60 # if !defined(YYEMPTY) || !defined(YYLEX)
61 # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
62 # elif defined(__GNUC__) /* gcc defines the #warning directive */
63 # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
64 /* #else we just take a chance that it works... */
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_exprs(enum expr_type type, char *val);
87 static expr_t *make_exprt(enum expr_type type, type_t *tref, expr_t *expr);
88 static expr_t *make_expr1(enum expr_type type, expr_t *expr);
89 static expr_t *make_expr2(enum expr_type type, expr_t *exp1, expr_t *exp2);
90 static expr_t *make_expr3(enum expr_type type, expr_t *expr1, expr_t *expr2, expr_t *expr3);
91 static type_t *make_type(unsigned char type, type_t *ref);
92 static expr_list_t *append_expr(expr_list_t *list, expr_t *expr);
93 static array_dims_t *append_array(array_dims_t *list, expr_t *expr);
94 static void set_type(var_t *v, type_t *type, int ptr_level, array_dims_t *arr);
95 static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface);
96 static ifref_t *make_ifref(type_t *iface);
97 static var_list_t *append_var(var_list_t *list, var_t *var);
98 static var_t *make_var(char *name);
99 static pident_list_t *append_pident(pident_list_t *list, pident_t *p);
100 static pident_t *make_pident(var_t *var);
101 static func_list_t *append_func(func_list_t *list, func_t *func);
102 static func_t *make_func(var_t *def, var_list_t *args);
103 static type_t *make_class(char *name);
104 static type_t *make_safearray(type_t *type);
105 static type_t *make_builtin(char *name);
106 static type_t *make_int(int sign);
108 static type_t *reg_type(type_t *type, const char *name, int t);
109 static type_t *reg_typedefs(type_t *type, var_list_t *names, attr_list_t *attrs);
110 static type_t *find_type(const char *name, int t);
111 static type_t *find_type2(char *name, int t);
112 static type_t *get_type(unsigned char type, char *name, int t);
113 static type_t *get_typev(unsigned char type, var_t *name, int t);
114 static int get_struct_type(var_list_t *fields);
116 static var_t *reg_const(var_t *var);
117 static var_t *find_const(char *name, int f);
119 static void write_libid(const char *name, const attr_list_t *attr);
120 static void write_clsid(type_t *cls);
121 static void write_diid(type_t *iface);
122 static void write_iid(type_t *iface);
124 static int compute_method_indexes(type_t *iface);
125 static char *gen_name(void);
126 static void process_typedefs(var_list_t *names);
127 static void check_arg(var_t *arg);
136 attr_list_t *attr_list;
137 str_list_t *str_list;
139 expr_list_t *expr_list;
140 array_dims_t *array_dims;
143 var_list_t *var_list;
145 pident_list_t *pident_list;
147 func_list_t *func_list;
149 ifref_list_t *ifref_list;
155 %token <str> aIDENTIFIER
156 %token <str> aKNOWNTYPE
157 %token <num> aNUM aHEXNUM
162 %token tAGGREGATABLE tALLOCATE tAPPOBJECT tASYNC tASYNCUUID
163 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
164 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
165 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
166 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
168 %token tDEFAULTCOLLELEM
170 %token tDEFAULTVTABLE
172 %token tDISPINTERFACE
173 %token tDLLNAME tDOUBLE tDUAL
175 %token tENTRY tENUM tERRORSTATUST
176 %token tEXPLICITHANDLE tEXTERN
181 %token tHELPCONTEXT tHELPFILE
182 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
184 %token tHYPER tID tIDEMPOTENT
186 %token tIMMEDIATEBIND
187 %token tIMPLICITHANDLE
188 %token tIMPORT tIMPORTLIB
194 %token tLENGTHIS tLIBRARY
201 %token tNONEXTENSIBLE
202 %token tOBJECT tODL tOLEAUTOMATION
205 %token tPOINTERDEFAULT
207 %token tPROPGET tPROPPUT tPROPPUTREF
211 %token tREADONLY tREF
219 %token tSIZEIS tSIZEOF
223 %token tSTRING tSTRUCT
224 %token tSWITCH tSWITCHIS tSWITCHTYPE
236 %token tWCHAR tWIREMARSHAL
238 %type <attr> attribute
239 %type <attr_list> m_attributes attributes attrib_list
240 %type <str_list> str_list
241 %type <expr> m_expr expr expr_const
242 %type <expr_list> m_exprs /* exprs expr_list */ expr_list_const
243 %type <array_dims> array array_list
244 %type <type> inherit interface interfacehdr interfacedef interfacedec
245 %type <type> dispinterface dispinterfacehdr dispinterfacedef
246 %type <type> module modulehdr moduledef
247 %type <type> base_type int_std
248 %type <type> enumdef structdef uniondef
250 %type <ifref> coclass_int
251 %type <ifref_list> gbl_statements coclass_ints
252 %type <var> arg field s_field case enum constdef externdef
253 %type <var_list> m_args no_args args fields cases enums enum_list dispint_props
254 %type <var> m_ident t_ident ident
255 %type <pident> p_ident pident
256 %type <pident_list> pident_list
258 %type <func_list> int_statements dispint_meths
259 %type <type> coclass coclasshdr coclassdef
260 %type <num> pointer_type version
261 %type <str> libraryhdr
277 input: gbl_statements { fix_incomplete();
284 gbl_statements: { $$ = NULL; }
285 | gbl_statements interfacedec { $$ = $1; }
286 | gbl_statements interfacedef { $$ = append_ifref( $1, make_ifref($2) ); }
287 | gbl_statements coclass ';' { $$ = $1;
288 reg_type($2, $2->name, 0);
289 if (!parse_only && do_header) write_coclass_forward($2);
291 | gbl_statements coclassdef { $$ = $1;
292 add_typelib_entry($2);
293 reg_type($2, $2->name, 0);
294 if (!parse_only && do_header) write_coclass_forward($2);
296 | gbl_statements moduledef { $$ = $1; add_typelib_entry($2); }
297 | gbl_statements librarydef { $$ = $1; }
298 | gbl_statements statement { $$ = $1; }
302 | imp_statements interfacedec { if (!parse_only) add_typelib_entry($2); }
303 | imp_statements interfacedef { if (!parse_only) add_typelib_entry($2); }
304 | imp_statements coclass ';' { reg_type($2, $2->name, 0); if (!parse_only && do_header) write_coclass_forward($2); }
305 | imp_statements coclassdef { if (!parse_only) add_typelib_entry($2);
306 reg_type($2, $2->name, 0);
307 if (!parse_only && do_header) write_coclass_forward($2);
309 | imp_statements moduledef { if (!parse_only) add_typelib_entry($2); }
310 | imp_statements statement {}
311 | imp_statements importlib {}
314 int_statements: { $$ = NULL; }
315 | int_statements funcdef ';' { $$ = append_func( $1, $2 ); }
316 | int_statements statement { $$ = $1; }
320 | constdef ';' { if (!parse_only && do_header) { write_constdef($1); } }
322 | enumdef ';' { if (!parse_only && do_header) {
323 write_type(header, $1, FALSE, NULL);
324 fprintf(header, ";\n\n");
327 | externdef ';' { if (!parse_only && do_header) { write_externdef($1); } }
329 | structdef ';' { if (!parse_only && do_header) {
330 write_type(header, $1, FALSE, NULL);
331 fprintf(header, ";\n\n");
335 | uniondef ';' { if (!parse_only && do_header) {
336 write_type(header, $1, FALSE, NULL);
337 fprintf(header, ";\n\n");
342 cppquote: tCPPQUOTE '(' aSTRING ')' { if (!parse_only && do_header) fprintf(header, "%s\n", $3); }
344 import_start: tIMPORT aSTRING ';' { assert(yychar == YYEMPTY);
345 if (!do_import($2)) yychar = aEOF; }
347 import: import_start imp_statements aEOF {}
350 importlib: tIMPORTLIB '(' aSTRING ')' { if(!parse_only) add_importlib($3); }
353 libraryhdr: tLIBRARY aIDENTIFIER { $$ = $2; }
355 library_start: attributes libraryhdr '{' { start_typelib($2, $1);
356 if (!parse_only && do_header) write_library($2, $1);
357 if (!parse_only && do_idfile) write_libid($2, $1);
360 librarydef: library_start imp_statements '}' { end_typelib(); }
363 m_args: { $$ = NULL; }
367 no_args: tVOID { $$ = NULL; }
370 args: arg { check_arg($1); $$ = append_var( NULL, $1 ); }
371 | args ',' arg { check_arg($3); $$ = append_var( $1, $3); }
375 /* split into two rules to get bison to resolve a tVOID conflict */
376 arg: attributes type pident array { $$ = $3->var;
378 set_type($$, $2, $3->ptr_level, $4);
381 | type pident array { $$ = $2->var;
382 set_type($$, $1, $2->ptr_level, $3);
385 | attributes type pident '(' m_args ')' { $$ = $3->var;
387 set_type($$, $2, $3->ptr_level - 1, NULL);
391 | type pident '(' m_args ')' { $$ = $2->var;
392 set_type($$, $1, $2->ptr_level - 1, NULL);
398 array: { $$ = NULL; }
399 | '[' array_list ']' { $$ = $2; }
400 | '[' '*' ']' { $$ = append_array( NULL, make_expr(EXPR_VOID) ); }
403 array_list: m_expr /* size of first dimension is optional */ { $$ = append_array( NULL, $1 ); }
404 | array_list ',' expr { $$ = append_array( $1, $3 ); }
405 | array_list ']' '[' expr { $$ = append_array( $1, $4 ); }
408 m_attributes: { $$ = NULL; }
413 '[' attrib_list ']' { $$ = $2;
415 yyerror("empty attribute lists unsupported");
419 attrib_list: attribute { $$ = append_attr( NULL, $1 ); }
420 | attrib_list ',' attribute { $$ = append_attr( $1, $3 ); }
421 | attrib_list ']' '[' attribute { $$ = append_attr( $1, $4 ); }
424 str_list: aSTRING { $$ = append_str( NULL, $1 ); }
425 | str_list ',' aSTRING { $$ = append_str( $1, $3 ); }
428 attribute: { $$ = NULL; }
429 | tAGGREGATABLE { $$ = make_attr(ATTR_AGGREGATABLE); }
430 | tAPPOBJECT { $$ = make_attr(ATTR_APPOBJECT); }
431 | tASYNC { $$ = make_attr(ATTR_ASYNC); }
432 | tAUTOHANDLE { $$ = make_attr(ATTR_AUTO_HANDLE); }
433 | tBINDABLE { $$ = make_attr(ATTR_BINDABLE); }
434 | tCALLAS '(' ident ')' { $$ = make_attrp(ATTR_CALLAS, $3); }
435 | tCASE '(' expr_list_const ')' { $$ = make_attrp(ATTR_CASE, $3); }
436 | tCONTEXTHANDLE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); }
437 | tCONTEXTHANDLENOSERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
438 | tCONTEXTHANDLESERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
439 | tCONTROL { $$ = make_attr(ATTR_CONTROL); }
440 | tDEFAULT { $$ = make_attr(ATTR_DEFAULT); }
441 | tDEFAULTCOLLELEM { $$ = make_attr(ATTR_DEFAULTCOLLELEM); }
442 | tDEFAULTVALUE '(' expr_const ')' { $$ = make_attrp(ATTR_DEFAULTVALUE_EXPR, $3); }
443 | tDEFAULTVALUE '(' aSTRING ')' { $$ = make_attrp(ATTR_DEFAULTVALUE_STRING, $3); }
444 | tDEFAULTVTABLE { $$ = make_attr(ATTR_DEFAULTVTABLE); }
445 | tDISPLAYBIND { $$ = make_attr(ATTR_DISPLAYBIND); }
446 | tDLLNAME '(' aSTRING ')' { $$ = make_attrp(ATTR_DLLNAME, $3); }
447 | tDUAL { $$ = make_attr(ATTR_DUAL); }
448 | tENDPOINT '(' str_list ')' { $$ = make_attrp(ATTR_ENDPOINT, $3); }
449 | tENTRY '(' aSTRING ')' { $$ = make_attrp(ATTR_ENTRY_STRING, $3); }
450 | tENTRY '(' expr_const ')' { $$ = make_attrp(ATTR_ENTRY_ORDINAL, $3); }
451 | tEXPLICITHANDLE { $$ = make_attr(ATTR_EXPLICIT_HANDLE); }
452 | tHANDLE { $$ = make_attr(ATTR_HANDLE); }
453 | tHELPCONTEXT '(' expr_const ')' { $$ = make_attrp(ATTR_HELPCONTEXT, $3); }
454 | tHELPFILE '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPFILE, $3); }
455 | tHELPSTRING '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRING, $3); }
456 | tHELPSTRINGCONTEXT '(' expr_const ')' { $$ = make_attrp(ATTR_HELPSTRINGCONTEXT, $3); }
457 | tHELPSTRINGDLL '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRINGDLL, $3); }
458 | tHIDDEN { $$ = make_attr(ATTR_HIDDEN); }
459 | tID '(' expr_const ')' { $$ = make_attrp(ATTR_ID, $3); }
460 | tIDEMPOTENT { $$ = make_attr(ATTR_IDEMPOTENT); }
461 | tIIDIS '(' ident ')' { $$ = make_attrp(ATTR_IIDIS, $3); }
462 | tIMMEDIATEBIND { $$ = make_attr(ATTR_IMMEDIATEBIND); }
463 | tIMPLICITHANDLE '(' tHANDLET aIDENTIFIER ')' { $$ = make_attrp(ATTR_IMPLICIT_HANDLE, $4); }
464 | tIN { $$ = make_attr(ATTR_IN); }
465 | tINPUTSYNC { $$ = make_attr(ATTR_INPUTSYNC); }
466 | tLENGTHIS '(' m_exprs ')' { $$ = make_attrp(ATTR_LENGTHIS, $3); }
467 | tLOCAL { $$ = make_attr(ATTR_LOCAL); }
468 | tNONBROWSABLE { $$ = make_attr(ATTR_NONBROWSABLE); }
469 | tNONCREATABLE { $$ = make_attr(ATTR_NONCREATABLE); }
470 | tNONEXTENSIBLE { $$ = make_attr(ATTR_NONEXTENSIBLE); }
471 | tOBJECT { $$ = make_attr(ATTR_OBJECT); }
472 | tODL { $$ = make_attr(ATTR_ODL); }
473 | tOLEAUTOMATION { $$ = make_attr(ATTR_OLEAUTOMATION); }
474 | tOPTIONAL { $$ = make_attr(ATTR_OPTIONAL); }
475 | tOUT { $$ = make_attr(ATTR_OUT); }
476 | tPOINTERDEFAULT '(' pointer_type ')' { $$ = make_attrv(ATTR_POINTERDEFAULT, $3); }
477 | tPROPGET { $$ = make_attr(ATTR_PROPGET); }
478 | tPROPPUT { $$ = make_attr(ATTR_PROPPUT); }
479 | tPROPPUTREF { $$ = make_attr(ATTR_PROPPUTREF); }
480 | tPUBLIC { $$ = make_attr(ATTR_PUBLIC); }
481 | tRANGE '(' expr_const ',' expr_const ')' { expr_list_t *list = append_expr( NULL, $3 );
482 list = append_expr( list, $5 );
483 $$ = make_attrp(ATTR_RANGE, list); }
484 | tREADONLY { $$ = make_attr(ATTR_READONLY); }
485 | tREQUESTEDIT { $$ = make_attr(ATTR_REQUESTEDIT); }
486 | tRESTRICTED { $$ = make_attr(ATTR_RESTRICTED); }
487 | tRETVAL { $$ = make_attr(ATTR_RETVAL); }
488 | tSIZEIS '(' m_exprs ')' { $$ = make_attrp(ATTR_SIZEIS, $3); }
489 | tSOURCE { $$ = make_attr(ATTR_SOURCE); }
490 | tSTRING { $$ = make_attr(ATTR_STRING); }
491 | tSWITCHIS '(' expr ')' { $$ = make_attrp(ATTR_SWITCHIS, $3); }
492 | tSWITCHTYPE '(' type ')' { $$ = make_attrp(ATTR_SWITCHTYPE, $3); }
493 | tTRANSMITAS '(' type ')' { $$ = make_attrp(ATTR_TRANSMITAS, $3); }
494 | tUUID '(' aUUID ')' { $$ = make_attrp(ATTR_UUID, $3); }
495 | tV1ENUM { $$ = make_attr(ATTR_V1ENUM); }
496 | tVARARG { $$ = make_attr(ATTR_VARARG); }
497 | tVERSION '(' version ')' { $$ = make_attrv(ATTR_VERSION, $3); }
498 | tWIREMARSHAL '(' type ')' { $$ = make_attrp(ATTR_WIREMARSHAL, $3); }
499 | pointer_type { $$ = make_attrv(ATTR_POINTERTYPE, $1); }
506 cases: { $$ = NULL; }
507 | cases case { $$ = append_var( $1, $2 ); }
510 case: tCASE expr ':' field { attr_t *a = make_attrp(ATTR_CASE, $2);
511 $$ = $4; if (!$$) $$ = make_var(NULL);
512 $$->attrs = append_attr( $$->attrs, a );
514 | tDEFAULT ':' field { attr_t *a = make_attr(ATTR_DEFAULT);
515 $$ = $3; if (!$$) $$ = make_var(NULL);
516 $$->attrs = append_attr( $$->attrs, a );
520 constdef: tCONST type ident '=' expr_const { $$ = reg_const($3);
521 set_type($$, $2, 0, NULL);
526 enums: { $$ = NULL; }
527 | enum_list ',' { $$ = $1; }
531 enum_list: enum { if (!$1->eval)
532 $1->eval = make_exprl(EXPR_NUM, 0 /* default for first enum entry */);
533 $$ = append_var( NULL, $1 );
535 | enum_list ',' enum { if (!$3->eval)
537 var_t *last = LIST_ENTRY( list_tail($$), var_t, entry );
538 $3->eval = make_exprl(EXPR_NUM, last->eval->cval + 1);
540 $$ = append_var( $1, $3 );
544 enum: ident '=' expr_const { $$ = reg_const($1);
546 $$->type = make_int(0);
548 | ident { $$ = reg_const($1);
549 $$->type = make_int(0);
553 enumdef: tENUM t_ident '{' enums '}' { $$ = get_typev(RPC_FC_ENUM16, $2, tsENUM);
554 $$->kind = TKIND_ENUM;
558 add_typelib_entry($$);
562 m_exprs: m_expr { $$ = append_expr( NULL, $1 ); }
563 | m_exprs ',' m_expr { $$ = append_expr( $1, $3 ); }
567 exprs: { $$ = make_expr(EXPR_VOID); }
572 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
576 m_expr: { $$ = make_expr(EXPR_VOID); }
580 expr: aNUM { $$ = make_exprl(EXPR_NUM, $1); }
581 | aHEXNUM { $$ = make_exprl(EXPR_HEXNUM, $1); }
582 | tFALSE { $$ = make_exprl(EXPR_TRUEFALSE, 0); }
583 | tTRUE { $$ = make_exprl(EXPR_TRUEFALSE, 1); }
584 | aIDENTIFIER { $$ = make_exprs(EXPR_IDENTIFIER, $1); }
585 | expr '?' expr ':' expr { $$ = make_expr3(EXPR_COND, $1, $3, $5); }
586 | expr '|' expr { $$ = make_expr2(EXPR_OR , $1, $3); }
587 | expr '&' expr { $$ = make_expr2(EXPR_AND, $1, $3); }
588 | expr '+' expr { $$ = make_expr2(EXPR_ADD, $1, $3); }
589 | expr '-' expr { $$ = make_expr2(EXPR_SUB, $1, $3); }
590 | expr '*' expr { $$ = make_expr2(EXPR_MUL, $1, $3); }
591 | expr '/' expr { $$ = make_expr2(EXPR_DIV, $1, $3); }
592 | expr SHL expr { $$ = make_expr2(EXPR_SHL, $1, $3); }
593 | expr SHR expr { $$ = make_expr2(EXPR_SHR, $1, $3); }
594 | '~' expr { $$ = make_expr1(EXPR_NOT, $2); }
595 | '-' expr %prec NEG { $$ = make_expr1(EXPR_NEG, $2); }
596 | '*' expr %prec PPTR { $$ = make_expr1(EXPR_PPTR, $2); }
597 | '(' type ')' expr %prec CAST { $$ = make_exprt(EXPR_CAST, $2, $4); }
598 | tSIZEOF '(' type ')' { $$ = make_exprt(EXPR_SIZEOF, $3, NULL); }
599 | '(' expr ')' { $$ = $2; }
602 expr_list_const: expr_const { $$ = append_expr( NULL, $1 ); }
603 | expr_list_const ',' expr_const { $$ = append_expr( $1, $3 ); }
606 expr_const: expr { $$ = $1;
608 yyerror("expression is not constant");
612 externdef: tEXTERN tCONST type ident { $$ = $4;
613 set_type($$, $3, 0, NULL);
617 fields: { $$ = NULL; }
618 | fields field { $$ = append_var( $1, $2 ); }
621 field: s_field ';' { $$ = $1; }
622 | m_attributes uniondef ';' { $$ = make_var(NULL); $$->type = $2; $$->attrs = $1; }
623 | attributes ';' { $$ = make_var(NULL); $$->attrs = $1; }
627 s_field: m_attributes type pident array { $$ = $3->var;
629 set_type($$, $2, $3->ptr_level, $4);
635 m_attributes type callconv pident
636 '(' m_args ')' { var_t *v = $4->var;
638 set_type(v, $2, $4->ptr_level, NULL);
640 $$ = make_func(v, $6);
641 if (is_attr(v->attrs, ATTR_IN)) {
642 yyerror("inapplicable attribute [in] for function '%s'",$$->def->name);
647 m_ident: { $$ = NULL; }
651 t_ident: { $$ = NULL; }
652 | aIDENTIFIER { $$ = make_var($1); }
653 | aKNOWNTYPE { $$ = make_var($1); }
656 ident: aIDENTIFIER { $$ = make_var($1); }
657 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
658 | aKNOWNTYPE { $$ = make_var($<str>1); }
661 base_type: tBYTE { $$ = make_builtin($<str>1); }
662 | tWCHAR { $$ = make_builtin($<str>1); }
664 | tSIGNED int_std { $$ = $2; $$->sign = 1; }
665 | tUNSIGNED int_std { $$ = $2; $$->sign = -1;
667 case RPC_FC_CHAR: break;
668 case RPC_FC_SMALL: $$->type = RPC_FC_USMALL; break;
669 case RPC_FC_SHORT: $$->type = RPC_FC_USHORT; break;
670 case RPC_FC_LONG: $$->type = RPC_FC_ULONG; break;
672 if ($$->name[0] == 'h') /* hyper, as opposed to __int64 */
674 $$ = alias($$, "MIDL_uhyper");
681 | tUNSIGNED { $$ = make_int(-1); }
682 | tFLOAT { $$ = make_builtin($<str>1); }
683 | tSINGLE { $$ = duptype(find_type("float", 0), 1); }
684 | tDOUBLE { $$ = make_builtin($<str>1); }
685 | tBOOLEAN { $$ = make_builtin($<str>1); }
686 | tERRORSTATUST { $$ = make_builtin($<str>1); }
687 | tHANDLET { $$ = make_builtin($<str>1); }
694 int_std: tINT { $$ = make_builtin($<str>1); }
695 | tSHORT m_int { $$ = make_builtin($<str>1); }
696 | tSMALL { $$ = make_builtin($<str>1); }
697 | tLONG m_int { $$ = make_builtin($<str>1); }
698 | tHYPER m_int { $$ = make_builtin($<str>1); }
699 | tINT64 { $$ = make_builtin($<str>1); }
700 | tCHAR { $$ = make_builtin($<str>1); }
703 coclass: tCOCLASS aIDENTIFIER { $$ = make_class($2); }
704 | tCOCLASS aKNOWNTYPE { $$ = find_type($2, 0);
705 if ($$->defined) yyerror("multiple definition error");
706 if ($$->kind != TKIND_COCLASS) yyerror("%s was not declared a coclass", $2);
710 coclasshdr: attributes coclass { $$ = $2;
712 if (!parse_only && do_header)
714 if (!parse_only && do_idfile)
719 coclassdef: coclasshdr '{' coclass_ints '}' { $$ = $1;
725 coclass_ints: { $$ = NULL; }
726 | coclass_ints coclass_int { $$ = append_ifref( $1, $2 ); }
730 m_attributes interfacedec { $$ = make_ifref($2); $$->attrs = $1; }
733 dispinterface: tDISPINTERFACE aIDENTIFIER { $$ = get_type(0, $2, 0); $$->kind = TKIND_DISPATCH; }
734 | tDISPINTERFACE aKNOWNTYPE { $$ = get_type(0, $2, 0); $$->kind = TKIND_DISPATCH; }
737 dispinterfacehdr: attributes dispinterface { attr_t *attrs;
739 if ($$->defined) yyerror("multiple definition error");
740 attrs = make_attr(ATTR_DISPINTERFACE);
741 $$->attrs = append_attr( $1, attrs );
742 $$->ref = find_type("IDispatch", 0);
743 if (!$$->ref) yyerror("IDispatch is undefined");
745 if (!parse_only && do_header) write_forward($$);
749 dispint_props: tPROPERTIES ':' { $$ = NULL; }
750 | dispint_props s_field ';' { $$ = append_var( $1, $2 ); }
753 dispint_meths: tMETHODS ':' { $$ = NULL; }
754 | dispint_meths funcdef ';' { $$ = append_func( $1, $2 ); }
757 dispinterfacedef: dispinterfacehdr '{'
763 if (!parse_only && do_header) write_dispinterface($$);
764 if (!parse_only && do_idfile) write_diid($$);
767 '{' interface ';' '}' { $$ = $1;
768 $$->fields = $3->fields;
769 $$->funcs = $3->funcs;
770 if (!parse_only && do_header) write_dispinterface($$);
771 if (!parse_only && do_idfile) write_diid($$);
775 inherit: { $$ = NULL; }
776 | ':' aKNOWNTYPE { $$ = find_type2($2, 0); }
779 interface: tINTERFACE aIDENTIFIER { $$ = get_type(RPC_FC_IP, $2, 0); $$->kind = TKIND_INTERFACE; }
780 | tINTERFACE aKNOWNTYPE { $$ = get_type(RPC_FC_IP, $2, 0); $$->kind = TKIND_INTERFACE; }
783 interfacehdr: attributes interface { $$ = $2;
784 if ($$->defined) yyerror("multiple definition error");
787 if (!parse_only && do_header) write_forward($$);
791 interfacedef: interfacehdr inherit
792 '{' int_statements '}' { $$ = $1;
795 compute_method_indexes($$);
796 if (!parse_only && do_header) write_interface($$);
797 if (!parse_only && do_idfile) write_iid($$);
799 /* MIDL is able to import the definition of a base class from inside the
800 * definition of a derived class, I'll try to support it with this rule */
801 | interfacehdr ':' aIDENTIFIER
802 '{' import int_statements '}' { $$ = $1;
803 $$->ref = find_type2($3, 0);
804 if (!$$->ref) yyerror("base class '%s' not found in import", $3);
806 compute_method_indexes($$);
807 if (!parse_only && do_header) write_interface($$);
808 if (!parse_only && do_idfile) write_iid($$);
810 | dispinterfacedef { $$ = $1; }
814 interface ';' { $$ = $1; if (!parse_only && do_header) write_forward($$); }
815 | dispinterface ';' { $$ = $1; if (!parse_only && do_header) write_forward($$); }
818 module: tMODULE aIDENTIFIER { $$ = make_type(0, NULL); $$->name = $2; $$->kind = TKIND_MODULE; }
819 | tMODULE aKNOWNTYPE { $$ = make_type(0, NULL); $$->name = $2; $$->kind = TKIND_MODULE; }
822 modulehdr: attributes module { $$ = $2;
827 moduledef: modulehdr '{' int_statements '}' { $$ = $1;
829 /* FIXME: if (!parse_only && do_header) write_module($$); */
833 p_ident: '*' pident %prec PPTR { $$ = $2; $$->ptr_level++; }
834 | tCONST p_ident { $$ = $2; /* FIXME */ }
837 pident: ident { $$ = make_pident($1); }
839 | '(' pident ')' { $$ = $2; }
843 pident { $$ = append_pident( NULL, $1 ); }
844 | pident_list ',' pident { $$ = append_pident( $1, $3 ); }
848 tREF { $$ = RPC_FC_RP; }
849 | tUNIQUE { $$ = RPC_FC_UP; }
850 | tPTR { $$ = RPC_FC_FP; }
853 structdef: tSTRUCT t_ident '{' fields '}' { $$ = get_typev(RPC_FC_STRUCT, $2, tsSTRUCT);
854 /* overwrite RPC_FC_STRUCT with a more exact type */
855 $$->type = get_struct_type( $4 );
856 $$->kind = TKIND_RECORD;
860 add_typelib_entry($$);
864 type: tVOID { $$ = duptype(find_type("void", 0), 1); }
865 | aKNOWNTYPE { $$ = find_type($1, 0); }
866 | base_type { $$ = $1; }
867 | tCONST type { $$ = duptype($2, 1); $$->is_const = TRUE; }
868 | enumdef { $$ = $1; }
869 | tENUM aIDENTIFIER { $$ = find_type2($2, tsENUM); }
870 | structdef { $$ = $1; }
871 | tSTRUCT aIDENTIFIER { $$ = get_type(RPC_FC_STRUCT, $2, tsSTRUCT); }
872 | uniondef { $$ = $1; }
873 | tUNION aIDENTIFIER { $$ = find_type2($2, tsUNION); }
874 | tSAFEARRAY '(' type ')' { $$ = make_safearray($3); }
877 typedef: tTYPEDEF m_attributes type pident_list { reg_typedefs($3, $4, $2);
878 process_typedefs($4);
882 uniondef: tUNION t_ident '{' fields '}' { $$ = get_typev(RPC_FC_NON_ENCAPSULATED_UNION, $2, tsUNION);
883 $$->kind = TKIND_UNION;
888 tSWITCH '(' s_field ')'
889 m_ident '{' cases '}' { var_t *u = $7;
890 $$ = get_typev(RPC_FC_ENCAPSULATED_UNION, $2, tsUNION);
891 $$->kind = TKIND_UNION;
892 if (!u) u = make_var( xstrdup("tagged_union") );
893 u->type = make_type(RPC_FC_NON_ENCAPSULATED_UNION, NULL);
894 u->type->kind = TKIND_UNION;
895 u->type->fields = $9;
896 u->type->defined = TRUE;
897 $$->fields = append_var( $$->fields, $5 );
898 $$->fields = append_var( $$->fields, u );
904 aNUM { $$ = MAKELONG($1, 0); }
905 | aNUM '.' aNUM { $$ = MAKELONG($1, $3); }
910 static void decl_builtin(const char *name, unsigned char type)
912 type_t *t = make_type(type, NULL);
913 t->name = xstrdup(name);
914 reg_type(t, name, 0);
917 static type_t *make_builtin(char *name)
919 /* NAME is strdup'd in the lexer */
920 type_t *t = duptype(find_type(name, 0), 0);
925 static type_t *make_int(int sign)
927 type_t *t = duptype(find_type("int", 0), 1);
931 t->type = t->type == RPC_FC_LONG ? RPC_FC_ULONG : RPC_FC_USHORT;
936 void init_types(void)
938 decl_builtin("void", 0);
939 decl_builtin("byte", RPC_FC_BYTE);
940 decl_builtin("wchar_t", RPC_FC_WCHAR);
941 decl_builtin("int", RPC_FC_LONG); /* win32 */
942 decl_builtin("short", RPC_FC_SHORT);
943 decl_builtin("small", RPC_FC_SMALL);
944 decl_builtin("long", RPC_FC_LONG);
945 decl_builtin("hyper", RPC_FC_HYPER);
946 decl_builtin("__int64", RPC_FC_HYPER);
947 decl_builtin("char", RPC_FC_CHAR);
948 decl_builtin("float", RPC_FC_FLOAT);
949 decl_builtin("double", RPC_FC_DOUBLE);
950 decl_builtin("boolean", RPC_FC_BYTE);
951 decl_builtin("error_status_t", RPC_FC_ERROR_STATUS_T);
952 decl_builtin("handle_t", RPC_FC_BIND_PRIMITIVE);
955 static str_list_t *append_str(str_list_t *list, char *str)
957 struct str_list_entry_t *entry;
959 if (!str) return list;
962 list = xmalloc( sizeof(*list) );
965 entry = xmalloc( sizeof(*entry) );
967 list_add_tail( list, &entry->entry );
971 static attr_list_t *append_attr(attr_list_t *list, attr_t *attr)
973 if (!attr) return list;
976 list = xmalloc( sizeof(*list) );
979 list_add_tail( list, &attr->entry );
983 static attr_t *make_attr(enum attr_type type)
985 attr_t *a = xmalloc(sizeof(attr_t));
991 static attr_t *make_attrv(enum attr_type type, unsigned long val)
993 attr_t *a = xmalloc(sizeof(attr_t));
999 static attr_t *make_attrp(enum attr_type type, void *val)
1001 attr_t *a = xmalloc(sizeof(attr_t));
1007 static expr_t *make_expr(enum expr_type type)
1009 expr_t *e = xmalloc(sizeof(expr_t));
1013 e->is_const = FALSE;
1017 static expr_t *make_exprl(enum expr_type type, long val)
1019 expr_t *e = xmalloc(sizeof(expr_t));
1023 e->is_const = FALSE;
1024 /* check for numeric constant */
1025 if (type == EXPR_NUM || type == EXPR_HEXNUM || type == EXPR_TRUEFALSE) {
1026 /* make sure true/false value is valid */
1027 assert(type != EXPR_TRUEFALSE || val == 0 || val == 1);
1034 static expr_t *make_exprs(enum expr_type type, char *val)
1037 e = xmalloc(sizeof(expr_t));
1041 e->is_const = FALSE;
1042 /* check for predefined constants */
1043 if (type == EXPR_IDENTIFIER) {
1044 var_t *c = find_const(val, 0);
1046 e->u.sval = c->name;
1049 e->cval = c->eval->cval;
1055 static expr_t *make_exprt(enum expr_type type, type_t *tref, expr_t *expr)
1058 e = xmalloc(sizeof(expr_t));
1062 e->is_const = FALSE;
1063 /* check for cast of constant expression */
1064 if (type == EXPR_SIZEOF) {
1065 switch (tref->type) {
1082 case RPC_FC_ERROR_STATUS_T:
1093 if (type == EXPR_CAST && expr->is_const) {
1095 e->cval = expr->cval;
1100 static expr_t *make_expr1(enum expr_type type, expr_t *expr)
1103 e = xmalloc(sizeof(expr_t));
1107 e->is_const = FALSE;
1108 /* check for compile-time optimization */
1109 if (expr->is_const) {
1113 e->cval = -expr->cval;
1116 e->cval = ~expr->cval;
1119 e->is_const = FALSE;
1126 static expr_t *make_expr2(enum expr_type type, expr_t *expr1, expr_t *expr2)
1129 e = xmalloc(sizeof(expr_t));
1133 e->is_const = FALSE;
1134 /* check for compile-time optimization */
1135 if (expr1->is_const && expr2->is_const) {
1139 e->cval = expr1->cval + expr2->cval;
1142 e->cval = expr1->cval - expr2->cval;
1145 e->cval = expr1->cval * expr2->cval;
1148 e->cval = expr1->cval / expr2->cval;
1151 e->cval = expr1->cval | expr2->cval;
1154 e->cval = expr1->cval & expr2->cval;
1157 e->cval = expr1->cval << expr2->cval;
1160 e->cval = expr1->cval >> expr2->cval;
1163 e->is_const = FALSE;
1170 static expr_t *make_expr3(enum expr_type type, expr_t *expr1, expr_t *expr2, expr_t *expr3)
1173 e = xmalloc(sizeof(expr_t));
1178 e->is_const = FALSE;
1179 /* check for compile-time optimization */
1180 if (expr1->is_const && expr2->is_const && expr3->is_const) {
1184 e->cval = expr1->cval ? expr2->cval : expr3->cval;
1187 e->is_const = FALSE;
1194 static expr_list_t *append_expr(expr_list_t *list, expr_t *expr)
1196 if (!expr) return list;
1199 list = xmalloc( sizeof(*list) );
1202 list_add_tail( list, &expr->entry );
1206 static array_dims_t *append_array(array_dims_t *list, expr_t *expr)
1208 if (!expr) return list;
1211 list = xmalloc( sizeof(*list) );
1214 list_add_tail( list, &expr->entry );
1218 static type_t *make_type(unsigned char type, type_t *ref)
1220 type_t *t = xmalloc(sizeof(type_t));
1222 t->kind = TKIND_PRIMITIVE;
1232 t->length_is = NULL;
1233 t->typestring_offset = 0;
1234 t->declarray = FALSE;
1235 t->ignore = (parse_only != 0);
1236 t->is_const = FALSE;
1240 t->user_types_registered = FALSE;
1241 t->tfswrite = FALSE;
1242 t->typelib_idx = -1;
1246 static void set_type(var_t *v, type_t *type, int ptr_level, array_dims_t *arr)
1248 expr_list_t *sizes = get_attrp(v->attrs, ATTR_SIZEIS);
1249 expr_list_t *lengs = get_attrp(v->attrs, ATTR_LENGTHIS);
1250 int sizeless, has_varconf;
1252 type_t *atype, **ptype;
1256 for ( ; 0 < ptr_level; --ptr_level)
1257 v->type = make_type(RPC_FC_RP, v->type);
1260 if (arr) LIST_FOR_EACH_ENTRY_REV(dim, arr, expr_t, entry)
1263 error("%s: only the first array dimension can be unspecified\n", v->name);
1267 unsigned int align = 0;
1268 size_t size = type_memsize(v->type, &align);
1271 error("%s: array dimension must be positive\n", v->name);
1273 if (0xffffffffuL / size < (unsigned long) dim->cval)
1274 error("%s: total array size is too large", v->name);
1275 else if (0xffffuL < size * dim->cval)
1276 v->type = make_type(RPC_FC_LGFARRAY, v->type);
1278 v->type = make_type(RPC_FC_SMFARRAY, v->type);
1283 v->type = make_type(RPC_FC_CARRAY, v->type);
1286 v->type->declarray = TRUE;
1287 v->type->dim = dim->cval;
1291 has_varconf = FALSE;
1292 if (sizes) LIST_FOR_EACH_ENTRY(dim, sizes, expr_t, entry)
1294 if (dim->type != EXPR_VOID)
1297 atype = *ptype = duptype(*ptype, 0);
1299 if (atype->type == RPC_FC_SMFARRAY || atype->type == RPC_FC_LGFARRAY)
1300 error("%s: cannot specify size_is for a fixed sized array\n", v->name);
1302 if (atype->type != RPC_FC_CARRAY && !is_ptr(atype))
1303 error("%s: size_is attribute applied to illegal type\n", v->name);
1305 atype->type = RPC_FC_CARRAY;
1306 atype->size_is = dim;
1309 ptype = &(*ptype)->ref;
1311 error("%s: too many expressions in size_is attribute\n", v->name);
1315 if (lengs) LIST_FOR_EACH_ENTRY(dim, lengs, expr_t, entry)
1317 if (dim->type != EXPR_VOID)
1320 atype = *ptype = duptype(*ptype, 0);
1322 if (atype->type == RPC_FC_SMFARRAY)
1323 atype->type = RPC_FC_SMVARRAY;
1324 else if (atype->type == RPC_FC_LGFARRAY)
1325 atype->type = RPC_FC_LGVARRAY;
1326 else if (atype->type == RPC_FC_CARRAY)
1327 atype->type = RPC_FC_CVARRAY;
1329 error("%s: length_is attribute applied to illegal type\n", v->name);
1331 atype->length_is = dim;
1334 ptype = &(*ptype)->ref;
1336 error("%s: too many expressions in length_is attribute\n", v->name);
1339 if (has_varconf && !last_array(v->type))
1342 for (ptype = &v->type; is_array(*ptype); ptype = &(*ptype)->ref)
1344 *ptype = duptype(*ptype, 0);
1345 (*ptype)->type = RPC_FC_BOGUS_ARRAY;
1350 static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface)
1352 if (!iface) return list;
1355 list = xmalloc( sizeof(*list) );
1358 list_add_tail( list, &iface->entry );
1362 static ifref_t *make_ifref(type_t *iface)
1364 ifref_t *l = xmalloc(sizeof(ifref_t));
1370 static var_list_t *append_var(var_list_t *list, var_t *var)
1372 if (!var) return list;
1375 list = xmalloc( sizeof(*list) );
1378 list_add_tail( list, &var->entry );
1382 static var_t *make_var(char *name)
1384 var_t *v = xmalloc(sizeof(var_t));
1393 static pident_list_t *append_pident(pident_list_t *list, pident_t *p)
1395 if (!p) return list;
1397 list = xmalloc(sizeof(*list));
1400 list_add_tail(list, &p->entry);
1404 static pident_t *make_pident(var_t *var)
1406 pident_t *p = xmalloc(sizeof(*p));
1412 static func_list_t *append_func(func_list_t *list, func_t *func)
1414 if (!func) return list;
1417 list = xmalloc( sizeof(*list) );
1420 list_add_tail( list, &func->entry );
1424 static func_t *make_func(var_t *def, var_list_t *args)
1426 func_t *f = xmalloc(sizeof(func_t));
1429 f->ignore = parse_only;
1434 static type_t *make_class(char *name)
1436 type_t *c = make_type(0, NULL);
1438 c->kind = TKIND_COCLASS;
1442 static type_t *make_safearray(type_t *type)
1444 type_t *sa = duptype(find_type("SAFEARRAY", 0), 1);
1446 return make_type(RPC_FC_FP, sa);
1451 static int hash_ident(const char *name)
1453 const char *p = name;
1455 /* a simple sum hash is probably good enough */
1460 return sum & (HASHMAX-1);
1463 /***** type repository *****/
1472 struct rtype *type_hash[HASHMAX];
1474 static type_t *reg_type(type_t *type, const char *name, int t)
1479 yyerror("registering named type without name");
1482 hash = hash_ident(name);
1483 nt = xmalloc(sizeof(struct rtype));
1487 nt->next = type_hash[hash];
1488 type_hash[hash] = nt;
1492 static int is_incomplete(const type_t *t)
1494 return !t->defined && (is_struct(t->type) || is_union(t->type));
1497 static void add_incomplete(type_t *t)
1499 struct typenode *tn = xmalloc(sizeof *tn);
1501 list_add_tail(&incomplete_types, &tn->entry);
1504 static void fix_type(type_t *t)
1506 if (t->kind == TKIND_ALIAS && is_incomplete(t)) {
1507 type_t *ot = t->orig;
1509 t->fields = ot->fields;
1510 t->defined = ot->defined;
1514 static void fix_incomplete(void)
1516 struct typenode *tn, *next;
1518 LIST_FOR_EACH_ENTRY_SAFE(tn, next, &incomplete_types, struct typenode, entry) {
1524 static type_t *reg_typedefs(type_t *type, pident_list_t *pidents, attr_list_t *attrs)
1527 const pident_t *pident;
1529 int is_str = is_attr(attrs, ATTR_STRING);
1530 unsigned char ptr_type = get_attrv(attrs, ATTR_POINTERTYPE);
1541 if (c != RPC_FC_CHAR && c != RPC_FC_BYTE && c != RPC_FC_WCHAR)
1543 pident = LIST_ENTRY( list_head( pidents ), const pident_t, entry );
1544 yyerror("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays",
1549 /* We must generate names for tagless enum, struct or union.
1550 Typedef-ing a tagless enum, struct or union means we want the typedef
1551 to be included in a library whether it has other attributes or not,
1552 hence the public attribute. */
1553 if ((type->kind == TKIND_ENUM || type->kind == TKIND_RECORD
1554 || type->kind == TKIND_UNION) && ! type->name && ! parse_only)
1556 if (! is_attr(attrs, ATTR_PUBLIC))
1557 attrs = append_attr( attrs, make_attr(ATTR_PUBLIC) );
1558 type->name = gen_name();
1561 LIST_FOR_EACH_ENTRY( pident, pidents, const pident_t, entry )
1563 var_t *name = pident->var;
1567 int cptr = pident->ptr_level;
1569 while (cptr > ptrc) {
1570 cur = ptr = make_type(RPC_FC_RP, cur);
1574 while (cptr < ptrc) {
1579 cur = alias(cur, name->name);
1584 cur->type = ptr_type;
1586 yyerror("'%s': pointer attribute applied to non-pointer type",
1589 else if (is_str && ! is_ptr(cur))
1590 yyerror("'%s': [string] attribute applied to non-pointer type",
1593 if (is_incomplete(cur))
1594 add_incomplete(cur);
1595 reg_type(cur, cur->name, 0);
1601 static type_t *find_type(const char *name, int t)
1603 struct rtype *cur = type_hash[hash_ident(name)];
1604 while (cur && (cur->t != t || strcmp(cur->name, name)))
1607 yyerror("type '%s' not found", name);
1613 static type_t *find_type2(char *name, int t)
1615 type_t *tp = find_type(name, t);
1620 int is_type(const char *name)
1622 struct rtype *cur = type_hash[hash_ident(name)];
1623 while (cur && (cur->t || strcmp(cur->name, name)))
1625 if (cur) return TRUE;
1629 static type_t *get_type(unsigned char type, char *name, int t)
1631 struct rtype *cur = NULL;
1634 cur = type_hash[hash_ident(name)];
1635 while (cur && (cur->t != t || strcmp(cur->name, name)))
1642 tp = make_type(type, NULL);
1644 if (!name) return tp;
1645 return reg_type(tp, name, t);
1648 static type_t *get_typev(unsigned char type, var_t *name, int t)
1655 return get_type(type, sname, t);
1658 static int get_struct_type(var_list_t *fields)
1660 int has_pointer = 0;
1661 int has_conformance = 0;
1662 int has_variance = 0;
1665 if (fields) LIST_FOR_EACH_ENTRY( field, fields, var_t, entry )
1667 type_t *t = field->type;
1669 if (is_ptr(field->type))
1675 if (field->type->declarray)
1677 if (is_string_type(field->attrs, field->type))
1679 has_conformance = 1;
1684 if (is_array(field->type->ref))
1685 return RPC_FC_BOGUS_STRUCT;
1687 if (is_conformant_array(field->type))
1689 has_conformance = 1;
1690 if (field->type->declarray && list_next(fields, &field->entry))
1691 yyerror("field '%s' deriving from a conformant array must be the last field in the structure",
1694 if (field->type->length_is)
1697 t = field->type->ref;
1703 * RPC_FC_BYTE, RPC_FC_STRUCT, etc
1704 * Simple types don't effect the type of struct.
1705 * A struct containing a simple struct is still a simple struct.
1706 * So long as we can block copy the data, we return RPC_FC_STRUCT.
1708 case 0: /* void pointer */
1718 case RPC_FC_INT3264:
1719 case RPC_FC_UINT3264:
1733 case RPC_FC_CVARRAY:
1738 * Propagate member attributes
1739 * a struct should be at least as complex as its member
1741 case RPC_FC_CVSTRUCT:
1742 has_conformance = 1;
1747 case RPC_FC_CPSTRUCT:
1748 has_conformance = 1;
1749 if (list_next( fields, &field->entry ))
1750 yyerror("field '%s' deriving from a conformant array must be the last field in the structure",
1755 case RPC_FC_CSTRUCT:
1756 has_conformance = 1;
1757 if (list_next( fields, &field->entry ))
1758 yyerror("field '%s' deriving from a conformant array must be the last field in the structure",
1762 case RPC_FC_PSTRUCT:
1767 fprintf(stderr,"Unknown struct member %s with type (0x%02x)\n",
1768 field->name, t->type);
1769 /* fallthru - treat it as complex */
1771 /* as soon as we see one of these these members, it's bogus... */
1773 case RPC_FC_ENCAPSULATED_UNION:
1774 case RPC_FC_NON_ENCAPSULATED_UNION:
1775 case RPC_FC_TRANSMIT_AS:
1776 case RPC_FC_REPRESENT_AS:
1778 case RPC_FC_EMBEDDED_COMPLEX:
1779 case RPC_FC_BOGUS_STRUCT:
1780 return RPC_FC_BOGUS_STRUCT;
1786 if ( has_conformance )
1787 return RPC_FC_CVSTRUCT;
1789 return RPC_FC_BOGUS_STRUCT;
1791 if( has_conformance && has_pointer )
1792 return RPC_FC_CPSTRUCT;
1793 if( has_conformance )
1794 return RPC_FC_CSTRUCT;
1796 return RPC_FC_PSTRUCT;
1797 return RPC_FC_STRUCT;
1800 /***** constant repository *****/
1805 struct rconst *next;
1808 struct rconst *const_hash[HASHMAX];
1810 static var_t *reg_const(var_t *var)
1815 yyerror("registering constant without name");
1818 hash = hash_ident(var->name);
1819 nc = xmalloc(sizeof(struct rconst));
1820 nc->name = var->name;
1822 nc->next = const_hash[hash];
1823 const_hash[hash] = nc;
1827 static var_t *find_const(char *name, int f)
1829 struct rconst *cur = const_hash[hash_ident(name)];
1830 while (cur && strcmp(cur->name, name))
1833 if (f) yyerror("constant '%s' not found", name);
1839 static void write_libid(const char *name, const attr_list_t *attr)
1841 const UUID *uuid = get_attrp(attr, ATTR_UUID);
1842 write_guid(idfile, "LIBID", name, uuid);
1845 static void write_clsid(type_t *cls)
1847 const UUID *uuid = get_attrp(cls->attrs, ATTR_UUID);
1848 write_guid(idfile, "CLSID", cls->name, uuid);
1851 static void write_diid(type_t *iface)
1853 const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
1854 write_guid(idfile, "DIID", iface->name, uuid);
1857 static void write_iid(type_t *iface)
1859 const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
1860 write_guid(idfile, "IID", iface->name, uuid);
1863 static int compute_method_indexes(type_t *iface)
1869 idx = compute_method_indexes(iface->ref);
1876 LIST_FOR_EACH_ENTRY( f, iface->funcs, func_t, entry )
1877 if (! is_callas(f->def->attrs))
1883 static char *gen_name(void)
1885 static const char format[] = "__WIDL_%s_generated_name_%08lX";
1886 static unsigned long n = 0;
1887 static const char *file_id;
1893 char *dst = dup_basename(input_name, ".idl");
1897 if (! isalnum((unsigned char) *dst))
1900 size = sizeof format - 7 + strlen(file_id) + 8;
1903 name = xmalloc(size);
1904 sprintf(name, format, file_id, n++);
1908 static void process_typedefs(pident_list_t *pidents)
1910 pident_t *pident, *next;
1912 if (!pidents) return;
1913 LIST_FOR_EACH_ENTRY_SAFE( pident, next, pidents, pident_t, entry )
1915 var_t *var = pident->var;
1916 type_t *type = find_type(var->name, 0);
1918 if (! parse_only && do_header)
1919 write_typedef(type);
1920 if (in_typelib && type->attrs)
1921 add_typelib_entry(type);
1928 static void check_arg(var_t *arg)
1930 type_t *t = arg->type;
1932 if (t->type == 0 && ! is_var_ptr(arg))
1933 yyerror("argument '%s' has void type", arg->name);