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 unsigned char pointer_default = RPC_FC_UP;
70 typedef struct list typelist_t;
76 typelist_t incomplete_types = LIST_INIT(incomplete_types);
78 static void add_incomplete(type_t *t);
79 static void fix_incomplete(void);
81 static str_list_t *append_str(str_list_t *list, char *str);
82 static attr_list_t *append_attr(attr_list_t *list, attr_t *attr);
83 static attr_t *make_attr(enum attr_type type);
84 static attr_t *make_attrv(enum attr_type type, unsigned long val);
85 static attr_t *make_attrp(enum attr_type type, void *val);
86 static expr_t *make_expr(enum expr_type type);
87 static expr_t *make_exprl(enum expr_type type, long val);
88 static expr_t *make_exprd(enum expr_type type, double val);
89 static expr_t *make_exprs(enum expr_type type, char *val);
90 static expr_t *make_exprt(enum expr_type type, type_t *tref, expr_t *expr);
91 static expr_t *make_expr1(enum expr_type type, expr_t *expr);
92 static expr_t *make_expr2(enum expr_type type, expr_t *exp1, expr_t *exp2);
93 static expr_t *make_expr3(enum expr_type type, expr_t *expr1, expr_t *expr2, expr_t *expr3);
94 static type_t *make_type(unsigned char type, type_t *ref);
95 static expr_list_t *append_expr(expr_list_t *list, expr_t *expr);
96 static array_dims_t *append_array(array_dims_t *list, expr_t *expr);
97 static void set_type(var_t *v, type_t *type, int ptr_level, array_dims_t *arr, int top);
98 static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface);
99 static ifref_t *make_ifref(type_t *iface);
100 static var_list_t *append_var(var_list_t *list, var_t *var);
101 static var_t *make_var(char *name);
102 static pident_list_t *append_pident(pident_list_t *list, pident_t *p);
103 static pident_t *make_pident(var_t *var);
104 static func_list_t *append_func(func_list_t *list, func_t *func);
105 static func_t *make_func(var_t *def, var_list_t *args);
106 static type_t *make_class(char *name);
107 static type_t *make_safearray(type_t *type);
108 static type_t *make_builtin(char *name);
109 static type_t *make_int(int sign);
111 static type_t *reg_type(type_t *type, const char *name, int t);
112 static type_t *reg_typedefs(type_t *type, var_list_t *names, attr_list_t *attrs);
113 static type_t *find_type(const char *name, int t);
114 static type_t *find_type2(char *name, int t);
115 static type_t *get_type(unsigned char type, char *name, int t);
116 static type_t *get_typev(unsigned char type, var_t *name, int t);
117 static int get_struct_type(var_list_t *fields);
119 static var_t *reg_const(var_t *var);
120 static var_t *find_const(char *name, int f);
122 static void write_libid(const char *name, const attr_list_t *attr);
123 static void write_clsid(type_t *cls);
124 static void write_diid(type_t *iface);
125 static void write_iid(type_t *iface);
127 static int compute_method_indexes(type_t *iface);
128 static char *gen_name(void);
129 static void process_typedefs(var_list_t *names);
130 static void check_arg(var_t *arg);
131 static void check_all_user_types(ifref_list_t *ifaces);
140 attr_list_t *attr_list;
141 str_list_t *str_list;
143 expr_list_t *expr_list;
144 array_dims_t *array_dims;
147 var_list_t *var_list;
149 pident_list_t *pident_list;
151 func_list_t *func_list;
153 ifref_list_t *ifref_list;
160 %token <str> aIDENTIFIER
161 %token <str> aKNOWNTYPE
162 %token <num> aNUM aHEXNUM
168 %token tAGGREGATABLE tALLOCATE tAPPOBJECT tASYNC tASYNCUUID
169 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
170 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
171 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
172 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
174 %token tDEFAULTCOLLELEM
176 %token tDEFAULTVTABLE
178 %token tDISPINTERFACE
179 %token tDLLNAME tDOUBLE tDUAL
181 %token tENTRY tENUM tERRORSTATUST
182 %token tEXPLICITHANDLE tEXTERN
187 %token tHELPCONTEXT tHELPFILE
188 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
190 %token tHYPER tID tIDEMPOTENT
192 %token tIMMEDIATEBIND
193 %token tIMPLICITHANDLE
194 %token tIMPORT tIMPORTLIB
200 %token tLENGTHIS tLIBRARY
207 %token tNONEXTENSIBLE
208 %token tOBJECT tODL tOLEAUTOMATION
211 %token tPOINTERDEFAULT
213 %token tPROPGET tPROPPUT tPROPPUTREF
217 %token tREADONLY tREF
225 %token tSIZEIS tSIZEOF
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 <type> inherit interface interfacehdr interfacedef interfacedec
251 %type <type> dispinterface dispinterfacehdr dispinterfacedef
252 %type <type> module modulehdr moduledef
253 %type <type> base_type int_std
254 %type <type> enumdef structdef uniondef
256 %type <ifref> coclass_int
257 %type <ifref_list> gbl_statements coclass_ints
258 %type <var> arg field s_field case enum constdef externdef
259 %type <var_list> m_args no_args args fields cases enums enum_list dispint_props
260 %type <var> m_ident t_ident ident
261 %type <pident> p_ident pident
262 %type <pident_list> pident_list
264 %type <func_list> int_statements dispint_meths
265 %type <type> coclass coclasshdr coclassdef
266 %type <num> pointer_type version
267 %type <str> libraryhdr
283 input: gbl_statements { fix_incomplete();
284 check_all_user_types($1);
291 gbl_statements: { $$ = NULL; }
292 | gbl_statements interfacedec { $$ = $1; }
293 | gbl_statements interfacedef { $$ = append_ifref( $1, make_ifref($2) ); }
294 | gbl_statements coclass ';' { $$ = $1;
295 reg_type($2, $2->name, 0);
296 if (!parse_only && do_header) write_coclass_forward($2);
298 | gbl_statements coclassdef { $$ = $1;
299 add_typelib_entry($2);
300 reg_type($2, $2->name, 0);
301 if (!parse_only && do_header) write_coclass_forward($2);
303 | gbl_statements moduledef { $$ = $1; add_typelib_entry($2); }
304 | gbl_statements librarydef { $$ = $1; }
305 | gbl_statements statement { $$ = $1; }
309 | imp_statements interfacedec { if (!parse_only) add_typelib_entry($2); }
310 | imp_statements interfacedef { if (!parse_only) add_typelib_entry($2); }
311 | imp_statements coclass ';' { reg_type($2, $2->name, 0); if (!parse_only && do_header) write_coclass_forward($2); }
312 | imp_statements coclassdef { if (!parse_only) add_typelib_entry($2);
313 reg_type($2, $2->name, 0);
314 if (!parse_only && do_header) write_coclass_forward($2);
316 | imp_statements moduledef { if (!parse_only) add_typelib_entry($2); }
317 | imp_statements statement {}
318 | imp_statements importlib {}
321 int_statements: { $$ = NULL; }
322 | int_statements funcdef ';' { $$ = append_func( $1, $2 ); }
323 | int_statements statement { $$ = $1; }
327 | constdef ';' { if (!parse_only && do_header) { write_constdef($1); } }
329 | enumdef ';' { if (!parse_only && do_header) {
330 write_type_def_or_decl(header, $1, FALSE, NULL);
331 fprintf(header, ";\n\n");
334 | externdef ';' { if (!parse_only && do_header) { write_externdef($1); } }
336 | structdef ';' { if (!parse_only && do_header) {
337 write_type_def_or_decl(header, $1, FALSE, NULL);
338 fprintf(header, ";\n\n");
342 | uniondef ';' { if (!parse_only && do_header) {
343 write_type_def_or_decl(header, $1, FALSE, NULL);
344 fprintf(header, ";\n\n");
349 cppquote: tCPPQUOTE '(' aSTRING ')' { if (!parse_only && do_header) fprintf(header, "%s\n", $3); }
351 import_start: tIMPORT aSTRING ';' { assert(yychar == YYEMPTY);
352 if (!do_import($2)) yychar = aEOF; }
354 import: import_start imp_statements aEOF {}
357 importlib: tIMPORTLIB '(' aSTRING ')' { if(!parse_only) add_importlib($3); }
360 libraryhdr: tLIBRARY aIDENTIFIER { $$ = $2; }
362 library_start: attributes libraryhdr '{' { start_typelib($2, $1);
363 if (!parse_only && do_header) write_library($2, $1);
364 if (!parse_only && do_idfile) write_libid($2, $1);
367 librarydef: library_start imp_statements '}' { end_typelib(); }
370 m_args: { $$ = NULL; }
374 no_args: tVOID { $$ = NULL; }
377 args: arg { check_arg($1); $$ = append_var( NULL, $1 ); }
378 | args ',' arg { check_arg($3); $$ = append_var( $1, $3); }
382 /* split into two rules to get bison to resolve a tVOID conflict */
383 arg: attributes type pident array { $$ = $3->var;
385 set_type($$, $2, $3->ptr_level, $4, TRUE);
388 | type pident array { $$ = $2->var;
389 set_type($$, $1, $2->ptr_level, $3, TRUE);
392 | attributes type pident '(' m_args ')' { $$ = $3->var;
394 set_type($$, $2, $3->ptr_level - 1, NULL, TRUE);
398 | type pident '(' m_args ')' { $$ = $2->var;
399 set_type($$, $1, $2->ptr_level - 1, NULL, TRUE);
405 array: { $$ = NULL; }
406 | '[' array_list ']' { $$ = $2; }
407 | '[' '*' ']' { $$ = append_array( NULL, make_expr(EXPR_VOID) ); }
410 array_list: m_expr /* size of first dimension is optional */ { $$ = append_array( NULL, $1 ); }
411 | array_list ',' expr { $$ = append_array( $1, $3 ); }
412 | array_list ']' '[' expr { $$ = append_array( $1, $4 ); }
415 m_attributes: { $$ = NULL; }
420 '[' attrib_list ']' { $$ = $2;
422 yyerror("empty attribute lists unsupported");
426 attrib_list: attribute { $$ = append_attr( NULL, $1 ); }
427 | attrib_list ',' attribute { $$ = append_attr( $1, $3 ); }
428 | attrib_list ']' '[' attribute { $$ = append_attr( $1, $4 ); }
431 str_list: aSTRING { $$ = append_str( NULL, $1 ); }
432 | str_list ',' aSTRING { $$ = append_str( $1, $3 ); }
435 attribute: { $$ = NULL; }
436 | tAGGREGATABLE { $$ = make_attr(ATTR_AGGREGATABLE); }
437 | tAPPOBJECT { $$ = make_attr(ATTR_APPOBJECT); }
438 | tASYNC { $$ = make_attr(ATTR_ASYNC); }
439 | tAUTOHANDLE { $$ = make_attr(ATTR_AUTO_HANDLE); }
440 | tBINDABLE { $$ = make_attr(ATTR_BINDABLE); }
441 | tCALLAS '(' ident ')' { $$ = make_attrp(ATTR_CALLAS, $3); }
442 | tCASE '(' expr_list_const ')' { $$ = make_attrp(ATTR_CASE, $3); }
443 | tCONTEXTHANDLE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); }
444 | tCONTEXTHANDLENOSERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
445 | tCONTEXTHANDLESERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
446 | tCONTROL { $$ = make_attr(ATTR_CONTROL); }
447 | tDEFAULT { $$ = make_attr(ATTR_DEFAULT); }
448 | tDEFAULTCOLLELEM { $$ = make_attr(ATTR_DEFAULTCOLLELEM); }
449 | tDEFAULTVALUE '(' expr_const ')' { $$ = make_attrp(ATTR_DEFAULTVALUE_EXPR, $3); }
450 | tDEFAULTVALUE '(' aSTRING ')' { $$ = make_attrp(ATTR_DEFAULTVALUE_STRING, $3); }
451 | tDEFAULTVTABLE { $$ = make_attr(ATTR_DEFAULTVTABLE); }
452 | tDISPLAYBIND { $$ = make_attr(ATTR_DISPLAYBIND); }
453 | tDLLNAME '(' aSTRING ')' { $$ = make_attrp(ATTR_DLLNAME, $3); }
454 | tDUAL { $$ = make_attr(ATTR_DUAL); }
455 | tENDPOINT '(' str_list ')' { $$ = make_attrp(ATTR_ENDPOINT, $3); }
456 | tENTRY '(' aSTRING ')' { $$ = make_attrp(ATTR_ENTRY_STRING, $3); }
457 | tENTRY '(' expr_const ')' { $$ = make_attrp(ATTR_ENTRY_ORDINAL, $3); }
458 | tEXPLICITHANDLE { $$ = make_attr(ATTR_EXPLICIT_HANDLE); }
459 | tHANDLE { $$ = make_attr(ATTR_HANDLE); }
460 | tHELPCONTEXT '(' expr_const ')' { $$ = make_attrp(ATTR_HELPCONTEXT, $3); }
461 | tHELPFILE '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPFILE, $3); }
462 | tHELPSTRING '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRING, $3); }
463 | tHELPSTRINGCONTEXT '(' expr_const ')' { $$ = make_attrp(ATTR_HELPSTRINGCONTEXT, $3); }
464 | tHELPSTRINGDLL '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRINGDLL, $3); }
465 | tHIDDEN { $$ = make_attr(ATTR_HIDDEN); }
466 | tID '(' expr_const ')' { $$ = make_attrp(ATTR_ID, $3); }
467 | tIDEMPOTENT { $$ = make_attr(ATTR_IDEMPOTENT); }
468 | tIIDIS '(' ident ')' { $$ = make_attrp(ATTR_IIDIS, $3); }
469 | tIMMEDIATEBIND { $$ = make_attr(ATTR_IMMEDIATEBIND); }
470 | tIMPLICITHANDLE '(' tHANDLET aIDENTIFIER ')' { $$ = make_attrp(ATTR_IMPLICIT_HANDLE, $4); }
471 | tIN { $$ = make_attr(ATTR_IN); }
472 | tINPUTSYNC { $$ = make_attr(ATTR_INPUTSYNC); }
473 | tLENGTHIS '(' m_exprs ')' { $$ = make_attrp(ATTR_LENGTHIS, $3); }
474 | tLOCAL { $$ = make_attr(ATTR_LOCAL); }
475 | tNONBROWSABLE { $$ = make_attr(ATTR_NONBROWSABLE); }
476 | tNONCREATABLE { $$ = make_attr(ATTR_NONCREATABLE); }
477 | tNONEXTENSIBLE { $$ = make_attr(ATTR_NONEXTENSIBLE); }
478 | tOBJECT { $$ = make_attr(ATTR_OBJECT); }
479 | tODL { $$ = make_attr(ATTR_ODL); }
480 | tOLEAUTOMATION { $$ = make_attr(ATTR_OLEAUTOMATION); }
481 | tOPTIONAL { $$ = make_attr(ATTR_OPTIONAL); }
482 | tOUT { $$ = make_attr(ATTR_OUT); }
483 | tPOINTERDEFAULT '(' pointer_type ')' { $$ = make_attrv(ATTR_POINTERDEFAULT, $3); }
484 | tPROPGET { $$ = make_attr(ATTR_PROPGET); }
485 | tPROPPUT { $$ = make_attr(ATTR_PROPPUT); }
486 | tPROPPUTREF { $$ = make_attr(ATTR_PROPPUTREF); }
487 | tPUBLIC { $$ = make_attr(ATTR_PUBLIC); }
488 | tRANGE '(' expr_const ',' expr_const ')' { expr_list_t *list = append_expr( NULL, $3 );
489 list = append_expr( list, $5 );
490 $$ = make_attrp(ATTR_RANGE, list); }
491 | tREADONLY { $$ = make_attr(ATTR_READONLY); }
492 | tREQUESTEDIT { $$ = make_attr(ATTR_REQUESTEDIT); }
493 | tRESTRICTED { $$ = make_attr(ATTR_RESTRICTED); }
494 | tRETVAL { $$ = make_attr(ATTR_RETVAL); }
495 | tSIZEIS '(' m_exprs ')' { $$ = make_attrp(ATTR_SIZEIS, $3); }
496 | tSOURCE { $$ = make_attr(ATTR_SOURCE); }
497 | tSTRING { $$ = make_attr(ATTR_STRING); }
498 | tSWITCHIS '(' expr ')' { $$ = make_attrp(ATTR_SWITCHIS, $3); }
499 | tSWITCHTYPE '(' type ')' { $$ = make_attrp(ATTR_SWITCHTYPE, $3); }
500 | tTRANSMITAS '(' type ')' { $$ = make_attrp(ATTR_TRANSMITAS, $3); }
501 | tUUID '(' aUUID ')' { $$ = make_attrp(ATTR_UUID, $3); }
502 | tV1ENUM { $$ = make_attr(ATTR_V1ENUM); }
503 | tVARARG { $$ = make_attr(ATTR_VARARG); }
504 | tVERSION '(' version ')' { $$ = make_attrv(ATTR_VERSION, $3); }
505 | tWIREMARSHAL '(' type ')' { $$ = make_attrp(ATTR_WIREMARSHAL, $3); }
506 | pointer_type { $$ = make_attrv(ATTR_POINTERTYPE, $1); }
513 cases: { $$ = NULL; }
514 | cases case { $$ = append_var( $1, $2 ); }
517 case: tCASE expr ':' field { attr_t *a = make_attrp(ATTR_CASE, append_expr( NULL, $2 ));
518 $$ = $4; if (!$$) $$ = make_var(NULL);
519 $$->attrs = append_attr( $$->attrs, a );
521 | tDEFAULT ':' field { attr_t *a = make_attr(ATTR_DEFAULT);
522 $$ = $3; if (!$$) $$ = make_var(NULL);
523 $$->attrs = append_attr( $$->attrs, a );
527 constdef: tCONST type ident '=' expr_const { $$ = reg_const($3);
528 set_type($$, $2, 0, NULL, FALSE);
533 enums: { $$ = NULL; }
534 | enum_list ',' { $$ = $1; }
538 enum_list: enum { if (!$1->eval)
539 $1->eval = make_exprl(EXPR_NUM, 0 /* default for first enum entry */);
540 $$ = append_var( NULL, $1 );
542 | enum_list ',' enum { if (!$3->eval)
544 var_t *last = LIST_ENTRY( list_tail($$), var_t, entry );
545 $3->eval = make_exprl(EXPR_NUM, last->eval->cval + 1);
547 $$ = append_var( $1, $3 );
551 enum: ident '=' expr_const { $$ = reg_const($1);
553 $$->type = make_int(0);
555 | ident { $$ = reg_const($1);
556 $$->type = make_int(0);
560 enumdef: tENUM t_ident '{' enums '}' { $$ = get_typev(RPC_FC_ENUM16, $2, tsENUM);
561 $$->kind = TKIND_ENUM;
565 add_typelib_entry($$);
569 m_exprs: m_expr { $$ = append_expr( NULL, $1 ); }
570 | m_exprs ',' m_expr { $$ = append_expr( $1, $3 ); }
574 exprs: { $$ = make_expr(EXPR_VOID); }
579 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
583 m_expr: { $$ = make_expr(EXPR_VOID); }
587 expr: aNUM { $$ = make_exprl(EXPR_NUM, $1); }
588 | aHEXNUM { $$ = make_exprl(EXPR_HEXNUM, $1); }
589 | aDOUBLE { $$ = make_exprd(EXPR_DOUBLE, $1); }
590 | tFALSE { $$ = make_exprl(EXPR_TRUEFALSE, 0); }
591 | tTRUE { $$ = make_exprl(EXPR_TRUEFALSE, 1); }
592 | aIDENTIFIER { $$ = make_exprs(EXPR_IDENTIFIER, $1); }
593 | expr '?' expr ':' expr { $$ = make_expr3(EXPR_COND, $1, $3, $5); }
594 | expr '|' expr { $$ = make_expr2(EXPR_OR , $1, $3); }
595 | expr '&' expr { $$ = make_expr2(EXPR_AND, $1, $3); }
596 | expr '+' expr { $$ = make_expr2(EXPR_ADD, $1, $3); }
597 | expr '-' expr { $$ = make_expr2(EXPR_SUB, $1, $3); }
598 | expr '*' expr { $$ = make_expr2(EXPR_MUL, $1, $3); }
599 | expr '/' expr { $$ = make_expr2(EXPR_DIV, $1, $3); }
600 | expr SHL expr { $$ = make_expr2(EXPR_SHL, $1, $3); }
601 | expr SHR expr { $$ = make_expr2(EXPR_SHR, $1, $3); }
602 | '~' expr { $$ = make_expr1(EXPR_NOT, $2); }
603 | '-' expr %prec NEG { $$ = make_expr1(EXPR_NEG, $2); }
604 | '*' expr %prec PPTR { $$ = make_expr1(EXPR_PPTR, $2); }
605 | '(' type ')' expr %prec CAST { $$ = make_exprt(EXPR_CAST, $2, $4); }
606 | tSIZEOF '(' type ')' { $$ = make_exprt(EXPR_SIZEOF, $3, NULL); }
607 | '(' expr ')' { $$ = $2; }
610 expr_list_const: expr_const { $$ = append_expr( NULL, $1 ); }
611 | expr_list_const ',' expr_const { $$ = append_expr( $1, $3 ); }
614 expr_const: expr { $$ = $1;
616 yyerror("expression is not constant");
620 externdef: tEXTERN tCONST type ident { $$ = $4;
621 set_type($$, $3, 0, NULL, FALSE);
625 fields: { $$ = NULL; }
626 | fields field { $$ = append_var( $1, $2 ); }
629 field: s_field ';' { $$ = $1; }
630 | m_attributes uniondef ';' { $$ = make_var(NULL); $$->type = $2; $$->attrs = $1; }
631 | attributes ';' { $$ = make_var(NULL); $$->attrs = $1; }
635 s_field: m_attributes type pident array { $$ = $3->var;
637 set_type($$, $2, $3->ptr_level, $4, FALSE);
643 m_attributes type callconv pident
644 '(' m_args ')' { var_t *v = $4->var;
646 set_type(v, $2, $4->ptr_level, NULL, FALSE);
648 $$ = make_func(v, $6);
649 if (is_attr(v->attrs, ATTR_IN)) {
650 yyerror("inapplicable attribute [in] for function '%s'",$$->def->name);
655 m_ident: { $$ = NULL; }
659 t_ident: { $$ = NULL; }
660 | aIDENTIFIER { $$ = make_var($1); }
661 | aKNOWNTYPE { $$ = make_var($1); }
664 ident: aIDENTIFIER { $$ = make_var($1); }
665 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
666 | aKNOWNTYPE { $$ = make_var($<str>1); }
669 base_type: tBYTE { $$ = make_builtin($<str>1); }
670 | tWCHAR { $$ = make_builtin($<str>1); }
672 | tSIGNED int_std { $$ = $2; $$->sign = 1; }
673 | tUNSIGNED int_std { $$ = $2; $$->sign = -1;
675 case RPC_FC_CHAR: break;
676 case RPC_FC_SMALL: $$->type = RPC_FC_USMALL; break;
677 case RPC_FC_SHORT: $$->type = RPC_FC_USHORT; break;
678 case RPC_FC_LONG: $$->type = RPC_FC_ULONG; break;
680 if ($$->name[0] == 'h') /* hyper, as opposed to __int64 */
682 $$ = alias($$, "MIDL_uhyper");
689 | tUNSIGNED { $$ = make_int(-1); }
690 | tFLOAT { $$ = make_builtin($<str>1); }
691 | tSINGLE { $$ = duptype(find_type("float", 0), 1); }
692 | tDOUBLE { $$ = make_builtin($<str>1); }
693 | tBOOLEAN { $$ = make_builtin($<str>1); }
694 | tERRORSTATUST { $$ = make_builtin($<str>1); }
695 | tHANDLET { $$ = make_builtin($<str>1); }
702 int_std: tINT { $$ = make_builtin($<str>1); }
703 | tSHORT m_int { $$ = make_builtin($<str>1); }
704 | tSMALL { $$ = make_builtin($<str>1); }
705 | tLONG m_int { $$ = make_builtin($<str>1); }
706 | tHYPER m_int { $$ = make_builtin($<str>1); }
707 | tINT64 { $$ = make_builtin($<str>1); }
708 | tCHAR { $$ = make_builtin($<str>1); }
711 coclass: tCOCLASS aIDENTIFIER { $$ = make_class($2); }
712 | tCOCLASS aKNOWNTYPE { $$ = find_type($2, 0);
713 if ($$->defined) yyerror("multiple definition error");
714 if ($$->kind != TKIND_COCLASS) yyerror("%s was not declared a coclass", $2);
718 coclasshdr: attributes coclass { $$ = $2;
720 if (!parse_only && do_header)
722 if (!parse_only && do_idfile)
727 coclassdef: coclasshdr '{' coclass_ints '}' { $$ = $1;
733 coclass_ints: { $$ = NULL; }
734 | coclass_ints coclass_int { $$ = append_ifref( $1, $2 ); }
738 m_attributes interfacedec { $$ = make_ifref($2); $$->attrs = $1; }
741 dispinterface: tDISPINTERFACE aIDENTIFIER { $$ = get_type(0, $2, 0); $$->kind = TKIND_DISPATCH; }
742 | tDISPINTERFACE aKNOWNTYPE { $$ = get_type(0, $2, 0); $$->kind = TKIND_DISPATCH; }
745 dispinterfacehdr: attributes dispinterface { attr_t *attrs;
747 if ($$->defined) yyerror("multiple definition error");
748 attrs = make_attr(ATTR_DISPINTERFACE);
749 $$->attrs = append_attr( $1, attrs );
750 $$->ref = find_type("IDispatch", 0);
751 if (!$$->ref) yyerror("IDispatch is undefined");
753 if (!parse_only && do_header) write_forward($$);
757 dispint_props: tPROPERTIES ':' { $$ = NULL; }
758 | dispint_props s_field ';' { $$ = append_var( $1, $2 ); }
761 dispint_meths: tMETHODS ':' { $$ = NULL; }
762 | dispint_meths funcdef ';' { $$ = append_func( $1, $2 ); }
765 dispinterfacedef: dispinterfacehdr '{'
771 if (!parse_only && do_header) write_dispinterface($$);
772 if (!parse_only && do_idfile) write_diid($$);
775 '{' interface ';' '}' { $$ = $1;
776 $$->fields = $3->fields;
777 $$->funcs = $3->funcs;
778 if (!parse_only && do_header) write_dispinterface($$);
779 if (!parse_only && do_idfile) write_diid($$);
783 inherit: { $$ = NULL; }
784 | ':' aKNOWNTYPE { $$ = find_type2($2, 0); }
787 interface: tINTERFACE aIDENTIFIER { $$ = get_type(RPC_FC_IP, $2, 0); $$->kind = TKIND_INTERFACE; }
788 | tINTERFACE aKNOWNTYPE { $$ = get_type(RPC_FC_IP, $2, 0); $$->kind = TKIND_INTERFACE; }
791 interfacehdr: attributes interface { $$ = $2;
792 if ($$->defined) yyerror("multiple definition error");
795 if (!parse_only && do_header) write_forward($$);
799 interfacedef: interfacehdr inherit
800 '{' int_statements '}' { $$ = $1;
803 compute_method_indexes($$);
804 if (!parse_only && do_header) write_interface($$);
805 if (!parse_only && do_idfile) write_iid($$);
807 /* MIDL is able to import the definition of a base class from inside the
808 * definition of a derived class, I'll try to support it with this rule */
809 | interfacehdr ':' aIDENTIFIER
810 '{' import int_statements '}' { $$ = $1;
811 $$->ref = find_type2($3, 0);
812 if (!$$->ref) yyerror("base class '%s' not found in import", $3);
814 compute_method_indexes($$);
815 if (!parse_only && do_header) write_interface($$);
816 if (!parse_only && do_idfile) write_iid($$);
818 | dispinterfacedef { $$ = $1; }
822 interface ';' { $$ = $1; if (!parse_only && do_header) write_forward($$); }
823 | dispinterface ';' { $$ = $1; if (!parse_only && do_header) write_forward($$); }
826 module: tMODULE aIDENTIFIER { $$ = make_type(0, NULL); $$->name = $2; $$->kind = TKIND_MODULE; }
827 | tMODULE aKNOWNTYPE { $$ = make_type(0, NULL); $$->name = $2; $$->kind = TKIND_MODULE; }
830 modulehdr: attributes module { $$ = $2;
835 moduledef: modulehdr '{' int_statements '}' { $$ = $1;
837 /* FIXME: if (!parse_only && do_header) write_module($$); */
841 p_ident: '*' pident %prec PPTR { $$ = $2; $$->ptr_level++; }
842 | tCONST p_ident { $$ = $2; /* FIXME */ }
845 pident: ident { $$ = make_pident($1); }
847 | '(' pident ')' { $$ = $2; }
851 pident { $$ = append_pident( NULL, $1 ); }
852 | pident_list ',' pident { $$ = append_pident( $1, $3 ); }
856 tREF { $$ = RPC_FC_RP; }
857 | tUNIQUE { $$ = RPC_FC_UP; }
858 | tPTR { $$ = RPC_FC_FP; }
861 structdef: tSTRUCT t_ident '{' fields '}' { $$ = get_typev(RPC_FC_STRUCT, $2, tsSTRUCT);
862 /* overwrite RPC_FC_STRUCT with a more exact type */
863 $$->type = get_struct_type( $4 );
864 $$->kind = TKIND_RECORD;
868 add_typelib_entry($$);
872 type: tVOID { $$ = duptype(find_type("void", 0), 1); }
873 | aKNOWNTYPE { $$ = find_type($1, 0); }
874 | base_type { $$ = $1; }
875 | tCONST type { $$ = duptype($2, 1); $$->is_const = TRUE; }
876 | enumdef { $$ = $1; }
877 | tENUM aIDENTIFIER { $$ = find_type2($2, tsENUM); }
878 | structdef { $$ = $1; }
879 | tSTRUCT aIDENTIFIER { $$ = get_type(RPC_FC_STRUCT, $2, tsSTRUCT); }
880 | uniondef { $$ = $1; }
881 | tUNION aIDENTIFIER { $$ = find_type2($2, tsUNION); }
882 | tSAFEARRAY '(' type ')' { $$ = make_safearray($3); }
885 typedef: tTYPEDEF m_attributes type pident_list { reg_typedefs($3, $4, $2);
886 process_typedefs($4);
890 uniondef: tUNION t_ident '{' fields '}' { $$ = get_typev(RPC_FC_NON_ENCAPSULATED_UNION, $2, tsUNION);
891 $$->kind = TKIND_UNION;
896 tSWITCH '(' s_field ')'
897 m_ident '{' cases '}' { var_t *u = $7;
898 $$ = get_typev(RPC_FC_ENCAPSULATED_UNION, $2, tsUNION);
899 $$->kind = TKIND_UNION;
900 if (!u) u = make_var( xstrdup("tagged_union") );
901 u->type = make_type(RPC_FC_NON_ENCAPSULATED_UNION, NULL);
902 u->type->kind = TKIND_UNION;
903 u->type->fields = $9;
904 u->type->defined = TRUE;
905 $$->fields = append_var( $$->fields, $5 );
906 $$->fields = append_var( $$->fields, u );
912 aNUM { $$ = MAKELONG($1, 0); }
913 | aNUM '.' aNUM { $$ = MAKELONG($1, $3); }
918 static void decl_builtin(const char *name, unsigned char type)
920 type_t *t = make_type(type, NULL);
921 t->name = xstrdup(name);
922 reg_type(t, name, 0);
925 static type_t *make_builtin(char *name)
927 /* NAME is strdup'd in the lexer */
928 type_t *t = duptype(find_type(name, 0), 0);
933 static type_t *make_int(int sign)
935 type_t *t = duptype(find_type("int", 0), 1);
939 t->type = t->type == RPC_FC_LONG ? RPC_FC_ULONG : RPC_FC_USHORT;
944 void init_types(void)
946 decl_builtin("void", 0);
947 decl_builtin("byte", RPC_FC_BYTE);
948 decl_builtin("wchar_t", RPC_FC_WCHAR);
949 decl_builtin("int", RPC_FC_LONG); /* win32 */
950 decl_builtin("short", RPC_FC_SHORT);
951 decl_builtin("small", RPC_FC_SMALL);
952 decl_builtin("long", RPC_FC_LONG);
953 decl_builtin("hyper", RPC_FC_HYPER);
954 decl_builtin("__int64", RPC_FC_HYPER);
955 decl_builtin("char", RPC_FC_CHAR);
956 decl_builtin("float", RPC_FC_FLOAT);
957 decl_builtin("double", RPC_FC_DOUBLE);
958 decl_builtin("boolean", RPC_FC_BYTE);
959 decl_builtin("error_status_t", RPC_FC_ERROR_STATUS_T);
960 decl_builtin("handle_t", RPC_FC_BIND_PRIMITIVE);
963 static str_list_t *append_str(str_list_t *list, char *str)
965 struct str_list_entry_t *entry;
967 if (!str) return list;
970 list = xmalloc( sizeof(*list) );
973 entry = xmalloc( sizeof(*entry) );
975 list_add_tail( list, &entry->entry );
979 static attr_list_t *append_attr(attr_list_t *list, attr_t *attr)
981 if (!attr) return list;
984 list = xmalloc( sizeof(*list) );
987 list_add_tail( list, &attr->entry );
991 static attr_t *make_attr(enum attr_type type)
993 attr_t *a = xmalloc(sizeof(attr_t));
999 static attr_t *make_attrv(enum attr_type type, unsigned long val)
1001 attr_t *a = xmalloc(sizeof(attr_t));
1007 static attr_t *make_attrp(enum attr_type type, void *val)
1009 attr_t *a = xmalloc(sizeof(attr_t));
1015 static expr_t *make_expr(enum expr_type type)
1017 expr_t *e = xmalloc(sizeof(expr_t));
1021 e->is_const = FALSE;
1026 static expr_t *make_exprl(enum expr_type type, long val)
1028 expr_t *e = xmalloc(sizeof(expr_t));
1032 e->is_const = FALSE;
1033 /* check for numeric constant */
1034 if (type == EXPR_NUM || type == EXPR_HEXNUM || type == EXPR_TRUEFALSE) {
1035 /* make sure true/false value is valid */
1036 assert(type != EXPR_TRUEFALSE || val == 0 || val == 1);
1043 static expr_t *make_exprd(enum expr_type type, double val)
1045 expr_t *e = xmalloc(sizeof(expr_t));
1054 static expr_t *make_exprs(enum expr_type type, char *val)
1057 e = xmalloc(sizeof(expr_t));
1061 e->is_const = FALSE;
1062 /* check for predefined constants */
1063 if (type == EXPR_IDENTIFIER) {
1064 var_t *c = find_const(val, 0);
1066 e->u.sval = c->name;
1069 e->cval = c->eval->cval;
1075 static expr_t *make_exprt(enum expr_type type, type_t *tref, expr_t *expr)
1078 e = xmalloc(sizeof(expr_t));
1082 e->is_const = FALSE;
1083 /* check for cast of constant expression */
1084 if (type == EXPR_SIZEOF) {
1085 switch (tref->type) {
1102 case RPC_FC_ERROR_STATUS_T:
1113 if (type == EXPR_CAST && expr->is_const) {
1115 e->cval = expr->cval;
1120 static expr_t *make_expr1(enum expr_type type, expr_t *expr)
1123 e = xmalloc(sizeof(expr_t));
1127 e->is_const = FALSE;
1128 /* check for compile-time optimization */
1129 if (expr->is_const) {
1133 e->cval = -expr->cval;
1136 e->cval = ~expr->cval;
1139 e->is_const = FALSE;
1146 static expr_t *make_expr2(enum expr_type type, expr_t *expr1, expr_t *expr2)
1149 e = xmalloc(sizeof(expr_t));
1153 e->is_const = FALSE;
1154 /* check for compile-time optimization */
1155 if (expr1->is_const && expr2->is_const) {
1159 e->cval = expr1->cval + expr2->cval;
1162 e->cval = expr1->cval - expr2->cval;
1165 e->cval = expr1->cval * expr2->cval;
1168 e->cval = expr1->cval / expr2->cval;
1171 e->cval = expr1->cval | expr2->cval;
1174 e->cval = expr1->cval & expr2->cval;
1177 e->cval = expr1->cval << expr2->cval;
1180 e->cval = expr1->cval >> expr2->cval;
1183 e->is_const = FALSE;
1190 static expr_t *make_expr3(enum expr_type type, expr_t *expr1, expr_t *expr2, expr_t *expr3)
1193 e = xmalloc(sizeof(expr_t));
1198 e->is_const = FALSE;
1199 /* check for compile-time optimization */
1200 if (expr1->is_const && expr2->is_const && expr3->is_const) {
1204 e->cval = expr1->cval ? expr2->cval : expr3->cval;
1207 e->is_const = FALSE;
1214 static expr_list_t *append_expr(expr_list_t *list, expr_t *expr)
1216 if (!expr) return list;
1219 list = xmalloc( sizeof(*list) );
1222 list_add_tail( list, &expr->entry );
1226 static array_dims_t *append_array(array_dims_t *list, expr_t *expr)
1228 if (!expr) return list;
1231 list = xmalloc( sizeof(*list) );
1234 list_add_tail( list, &expr->entry );
1238 static type_t *make_type(unsigned char type, type_t *ref)
1240 type_t *t = xmalloc(sizeof(type_t));
1242 t->kind = TKIND_PRIMITIVE;
1252 t->length_is = NULL;
1253 t->typestring_offset = 0;
1255 t->declarray = FALSE;
1256 t->ignore = (parse_only != 0);
1257 t->is_const = FALSE;
1261 t->user_types_registered = FALSE;
1262 t->tfswrite = FALSE;
1263 t->typelib_idx = -1;
1267 static void set_type(var_t *v, type_t *type, int ptr_level, array_dims_t *arr,
1270 expr_list_t *sizes = get_attrp(v->attrs, ATTR_SIZEIS);
1271 expr_list_t *lengs = get_attrp(v->attrs, ATTR_LENGTHIS);
1272 int ptr_attr = get_attrv(v->attrs, ATTR_POINTERTYPE);
1273 int ptr_type = ptr_attr;
1274 int sizeless, has_varconf;
1276 type_t *atype, **ptype;
1280 if (!ptr_type && top)
1281 ptr_type = RPC_FC_RP;
1283 for ( ; 0 < ptr_level; --ptr_level)
1285 v->type = make_type(pointer_default, v->type);
1286 if (ptr_level == 1 && ptr_type && !arr)
1288 v->type->type = ptr_type;
1295 if (is_ptr(v->type))
1297 if (v->type->type != ptr_type)
1299 v->type = duptype(v->type, 1);
1300 v->type->type = ptr_type;
1303 else if (!arr && ptr_attr)
1304 error("%s: pointer attribute applied to non-pointer type\n", v->name);
1308 if (arr) LIST_FOR_EACH_ENTRY_REV(dim, arr, expr_t, entry)
1311 error("%s: only the first array dimension can be unspecified\n", v->name);
1315 unsigned int align = 0;
1316 size_t size = type_memsize(v->type, &align);
1319 error("%s: array dimension must be positive\n", v->name);
1321 if (0xffffffffuL / size < (unsigned long) dim->cval)
1322 error("%s: total array size is too large\n", v->name);
1323 else if (0xffffuL < size * dim->cval)
1324 v->type = make_type(RPC_FC_LGFARRAY, v->type);
1326 v->type = make_type(RPC_FC_SMFARRAY, v->type);
1331 v->type = make_type(RPC_FC_CARRAY, v->type);
1334 v->type->declarray = TRUE;
1335 v->type->dim = dim->cval;
1339 has_varconf = FALSE;
1340 if (sizes) LIST_FOR_EACH_ENTRY(dim, sizes, expr_t, entry)
1342 if (dim->type != EXPR_VOID)
1345 atype = *ptype = duptype(*ptype, 0);
1347 if (atype->type == RPC_FC_SMFARRAY || atype->type == RPC_FC_LGFARRAY)
1348 error("%s: cannot specify size_is for a fixed sized array\n", v->name);
1350 if (atype->type != RPC_FC_CARRAY && !is_ptr(atype))
1351 error("%s: size_is attribute applied to illegal type\n", v->name);
1353 atype->type = RPC_FC_CARRAY;
1354 atype->size_is = dim;
1357 ptype = &(*ptype)->ref;
1359 error("%s: too many expressions in size_is attribute\n", v->name);
1363 if (lengs) LIST_FOR_EACH_ENTRY(dim, lengs, expr_t, entry)
1365 if (dim->type != EXPR_VOID)
1368 atype = *ptype = duptype(*ptype, 0);
1370 if (atype->type == RPC_FC_SMFARRAY)
1371 atype->type = RPC_FC_SMVARRAY;
1372 else if (atype->type == RPC_FC_LGFARRAY)
1373 atype->type = RPC_FC_LGVARRAY;
1374 else if (atype->type == RPC_FC_CARRAY)
1375 atype->type = RPC_FC_CVARRAY;
1377 error("%s: length_is attribute applied to illegal type\n", v->name);
1379 atype->length_is = dim;
1382 ptype = &(*ptype)->ref;
1384 error("%s: too many expressions in length_is attribute\n", v->name);
1387 if (has_varconf && !last_array(v->type))
1390 for (ptype = &v->type; is_array(*ptype); ptype = &(*ptype)->ref)
1392 *ptype = duptype(*ptype, 0);
1393 (*ptype)->type = RPC_FC_BOGUS_ARRAY;
1397 if (is_array(v->type))
1399 const type_t *rt = v->type->ref;
1402 case RPC_FC_BOGUS_STRUCT:
1403 case RPC_FC_NON_ENCAPSULATED_UNION:
1404 case RPC_FC_ENCAPSULATED_UNION:
1406 v->type->type = RPC_FC_BOGUS_ARRAY;
1408 /* FC_RP should be above, but widl overuses these, and will break things. */
1411 if (rt->ref->type == RPC_FC_IP)
1412 v->type->type = RPC_FC_BOGUS_ARRAY;
1415 if (is_user_type(rt))
1416 v->type->type = RPC_FC_BOGUS_ARRAY;
1421 static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface)
1423 if (!iface) return list;
1426 list = xmalloc( sizeof(*list) );
1429 list_add_tail( list, &iface->entry );
1433 static ifref_t *make_ifref(type_t *iface)
1435 ifref_t *l = xmalloc(sizeof(ifref_t));
1441 static var_list_t *append_var(var_list_t *list, var_t *var)
1443 if (!var) return list;
1446 list = xmalloc( sizeof(*list) );
1449 list_add_tail( list, &var->entry );
1453 static var_t *make_var(char *name)
1455 var_t *v = xmalloc(sizeof(var_t));
1464 static pident_list_t *append_pident(pident_list_t *list, pident_t *p)
1466 if (!p) return list;
1468 list = xmalloc(sizeof(*list));
1471 list_add_tail(list, &p->entry);
1475 static pident_t *make_pident(var_t *var)
1477 pident_t *p = xmalloc(sizeof(*p));
1483 static func_list_t *append_func(func_list_t *list, func_t *func)
1485 if (!func) return list;
1488 list = xmalloc( sizeof(*list) );
1491 list_add_tail( list, &func->entry );
1495 static func_t *make_func(var_t *def, var_list_t *args)
1497 func_t *f = xmalloc(sizeof(func_t));
1500 f->ignore = parse_only;
1505 static type_t *make_class(char *name)
1507 type_t *c = make_type(0, NULL);
1509 c->kind = TKIND_COCLASS;
1513 static type_t *make_safearray(type_t *type)
1515 type_t *sa = duptype(find_type("SAFEARRAY", 0), 1);
1517 return make_type(pointer_default, sa);
1522 static int hash_ident(const char *name)
1524 const char *p = name;
1526 /* a simple sum hash is probably good enough */
1531 return sum & (HASHMAX-1);
1534 /***** type repository *****/
1543 struct rtype *type_hash[HASHMAX];
1545 static type_t *reg_type(type_t *type, const char *name, int t)
1550 yyerror("registering named type without name");
1553 hash = hash_ident(name);
1554 nt = xmalloc(sizeof(struct rtype));
1558 nt->next = type_hash[hash];
1559 type_hash[hash] = nt;
1563 static int is_incomplete(const type_t *t)
1565 return !t->defined && (is_struct(t->type) || is_union(t->type));
1568 static void add_incomplete(type_t *t)
1570 struct typenode *tn = xmalloc(sizeof *tn);
1572 list_add_tail(&incomplete_types, &tn->entry);
1575 static void fix_type(type_t *t)
1577 if (t->kind == TKIND_ALIAS && is_incomplete(t)) {
1578 type_t *ot = t->orig;
1580 t->fields = ot->fields;
1581 t->defined = ot->defined;
1585 static void fix_incomplete(void)
1587 struct typenode *tn, *next;
1589 LIST_FOR_EACH_ENTRY_SAFE(tn, next, &incomplete_types, struct typenode, entry) {
1595 static type_t *reg_typedefs(type_t *type, pident_list_t *pidents, attr_list_t *attrs)
1598 const pident_t *pident;
1600 int is_str = is_attr(attrs, ATTR_STRING);
1601 unsigned char ptr_type = get_attrv(attrs, ATTR_POINTERTYPE);
1612 if (c != RPC_FC_CHAR && c != RPC_FC_BYTE && c != RPC_FC_WCHAR)
1614 pident = LIST_ENTRY( list_head( pidents ), const pident_t, entry );
1615 yyerror("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays",
1620 /* We must generate names for tagless enum, struct or union.
1621 Typedef-ing a tagless enum, struct or union means we want the typedef
1622 to be included in a library whether it has other attributes or not,
1623 hence the public attribute. */
1624 if ((type->kind == TKIND_ENUM || type->kind == TKIND_RECORD
1625 || type->kind == TKIND_UNION) && ! type->name && ! parse_only)
1627 if (! is_attr(attrs, ATTR_PUBLIC))
1628 attrs = append_attr( attrs, make_attr(ATTR_PUBLIC) );
1629 type->name = gen_name();
1632 LIST_FOR_EACH_ENTRY( pident, pidents, const pident_t, entry )
1634 var_t *name = pident->var;
1638 int cptr = pident->ptr_level;
1640 while (cptr > ptrc) {
1641 cur = ptr = make_type(pointer_default, cur);
1645 while (cptr < ptrc) {
1650 cur = alias(cur, name->name);
1655 cur->type = ptr_type;
1657 yyerror("'%s': pointer attribute applied to non-pointer type",
1660 else if (is_str && ! is_ptr(cur))
1661 yyerror("'%s': [string] attribute applied to non-pointer type",
1664 if (is_incomplete(cur))
1665 add_incomplete(cur);
1666 reg_type(cur, cur->name, 0);
1672 static type_t *find_type(const char *name, int t)
1674 struct rtype *cur = type_hash[hash_ident(name)];
1675 while (cur && (cur->t != t || strcmp(cur->name, name)))
1678 yyerror("type '%s' not found", name);
1684 static type_t *find_type2(char *name, int t)
1686 type_t *tp = find_type(name, t);
1691 int is_type(const char *name)
1693 struct rtype *cur = type_hash[hash_ident(name)];
1694 while (cur && (cur->t || strcmp(cur->name, name)))
1696 if (cur) return TRUE;
1700 static type_t *get_type(unsigned char type, char *name, int t)
1702 struct rtype *cur = NULL;
1705 cur = type_hash[hash_ident(name)];
1706 while (cur && (cur->t != t || strcmp(cur->name, name)))
1713 tp = make_type(type, NULL);
1715 if (!name) return tp;
1716 return reg_type(tp, name, t);
1719 static type_t *get_typev(unsigned char type, var_t *name, int t)
1726 return get_type(type, sname, t);
1729 static int get_struct_type(var_list_t *fields)
1731 int has_pointer = 0;
1732 int has_conformance = 0;
1733 int has_variance = 0;
1736 if (get_padding(fields))
1737 return RPC_FC_BOGUS_STRUCT;
1739 if (fields) LIST_FOR_EACH_ENTRY( field, fields, var_t, entry )
1741 type_t *t = field->type;
1752 case RPC_FC_ENCAPSULATED_UNION:
1753 case RPC_FC_NON_ENCAPSULATED_UNION:
1754 case RPC_FC_BOGUS_STRUCT:
1755 return RPC_FC_BOGUS_STRUCT;
1762 if (field->type->declarray)
1764 if (is_string_type(field->attrs, field->type))
1766 if (is_conformant_array(field->type))
1767 has_conformance = 1;
1772 if (is_array(field->type->ref))
1773 return RPC_FC_BOGUS_STRUCT;
1775 if (is_conformant_array(field->type))
1777 has_conformance = 1;
1778 if (field->type->declarray && list_next(fields, &field->entry))
1779 yyerror("field '%s' deriving from a conformant array must be the last field in the structure",
1782 if (field->type->length_is)
1785 t = field->type->ref;
1791 * RPC_FC_BYTE, RPC_FC_STRUCT, etc
1792 * Simple types don't effect the type of struct.
1793 * A struct containing a simple struct is still a simple struct.
1794 * So long as we can block copy the data, we return RPC_FC_STRUCT.
1796 case 0: /* void pointer */
1806 case RPC_FC_INT3264:
1807 case RPC_FC_UINT3264:
1821 case RPC_FC_CVARRAY:
1826 * Propagate member attributes
1827 * a struct should be at least as complex as its member
1829 case RPC_FC_CVSTRUCT:
1830 has_conformance = 1;
1835 case RPC_FC_CPSTRUCT:
1836 has_conformance = 1;
1837 if (list_next( fields, &field->entry ))
1838 yyerror("field '%s' deriving from a conformant array must be the last field in the structure",
1843 case RPC_FC_CSTRUCT:
1844 has_conformance = 1;
1845 if (list_next( fields, &field->entry ))
1846 yyerror("field '%s' deriving from a conformant array must be the last field in the structure",
1850 case RPC_FC_PSTRUCT:
1855 fprintf(stderr,"Unknown struct member %s with type (0x%02x)\n",
1856 field->name, t->type);
1857 /* fallthru - treat it as complex */
1859 /* as soon as we see one of these these members, it's bogus... */
1861 case RPC_FC_ENCAPSULATED_UNION:
1862 case RPC_FC_NON_ENCAPSULATED_UNION:
1863 case RPC_FC_TRANSMIT_AS:
1864 case RPC_FC_REPRESENT_AS:
1866 case RPC_FC_EMBEDDED_COMPLEX:
1867 case RPC_FC_BOGUS_STRUCT:
1868 case RPC_FC_BOGUS_ARRAY:
1869 return RPC_FC_BOGUS_STRUCT;
1875 if ( has_conformance )
1876 return RPC_FC_CVSTRUCT;
1878 return RPC_FC_BOGUS_STRUCT;
1880 if( has_conformance && has_pointer )
1881 return RPC_FC_CPSTRUCT;
1882 if( has_conformance )
1883 return RPC_FC_CSTRUCT;
1885 return RPC_FC_PSTRUCT;
1886 return RPC_FC_STRUCT;
1889 /***** constant repository *****/
1894 struct rconst *next;
1897 struct rconst *const_hash[HASHMAX];
1899 static var_t *reg_const(var_t *var)
1904 yyerror("registering constant without name");
1907 hash = hash_ident(var->name);
1908 nc = xmalloc(sizeof(struct rconst));
1909 nc->name = var->name;
1911 nc->next = const_hash[hash];
1912 const_hash[hash] = nc;
1916 static var_t *find_const(char *name, int f)
1918 struct rconst *cur = const_hash[hash_ident(name)];
1919 while (cur && strcmp(cur->name, name))
1922 if (f) yyerror("constant '%s' not found", name);
1928 static void write_libid(const char *name, const attr_list_t *attr)
1930 const UUID *uuid = get_attrp(attr, ATTR_UUID);
1931 write_guid(idfile, "LIBID", name, uuid);
1934 static void write_clsid(type_t *cls)
1936 const UUID *uuid = get_attrp(cls->attrs, ATTR_UUID);
1937 write_guid(idfile, "CLSID", cls->name, uuid);
1940 static void write_diid(type_t *iface)
1942 const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
1943 write_guid(idfile, "DIID", iface->name, uuid);
1946 static void write_iid(type_t *iface)
1948 const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
1949 write_guid(idfile, "IID", iface->name, uuid);
1952 static int compute_method_indexes(type_t *iface)
1958 idx = compute_method_indexes(iface->ref);
1965 LIST_FOR_EACH_ENTRY( f, iface->funcs, func_t, entry )
1966 if (! is_callas(f->def->attrs))
1972 static char *gen_name(void)
1974 static const char format[] = "__WIDL_%s_generated_name_%08lX";
1975 static unsigned long n = 0;
1976 static const char *file_id;
1982 char *dst = dup_basename(input_name, ".idl");
1986 if (! isalnum((unsigned char) *dst))
1989 size = sizeof format - 7 + strlen(file_id) + 8;
1992 name = xmalloc(size);
1993 sprintf(name, format, file_id, n++);
1997 static void process_typedefs(pident_list_t *pidents)
1999 pident_t *pident, *next;
2001 if (!pidents) return;
2002 LIST_FOR_EACH_ENTRY_SAFE( pident, next, pidents, pident_t, entry )
2004 var_t *var = pident->var;
2005 type_t *type = find_type(var->name, 0);
2007 if (! parse_only && do_header)
2008 write_typedef(type);
2009 if (in_typelib && type->attrs)
2010 add_typelib_entry(type);
2017 static void check_arg(var_t *arg)
2019 type_t *t = arg->type;
2021 if (t->type == 0 && ! is_var_ptr(arg))
2022 yyerror("argument '%s' has void type", arg->name);
2025 static void check_all_user_types(ifref_list_t *ifrefs)
2027 const ifref_t *ifref;
2030 if (ifrefs) LIST_FOR_EACH_ENTRY(ifref, ifrefs, const ifref_t, entry)
2032 const func_list_t *fs = ifref->iface->funcs;
2033 if (fs) LIST_FOR_EACH_ENTRY(f, fs, const func_t, entry)
2034 check_for_user_types_and_context_handles(f->args);