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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 static attr_t *make_attr(enum attr_type type);
67 static attr_t *make_attrv(enum attr_type type, DWORD val);
68 static attr_t *make_attrp(enum attr_type type, void *val);
69 static expr_t *make_expr(enum expr_type type);
70 static expr_t *make_exprl(enum expr_type type, long val);
71 static expr_t *make_exprs(enum expr_type type, char *val);
72 static expr_t *make_exprt(enum expr_type type, typeref_t *tref, expr_t *expr);
73 static expr_t *make_expr1(enum expr_type type, expr_t *expr);
74 static expr_t *make_expr2(enum expr_type type, expr_t *exp1, expr_t *exp2);
75 static type_t *make_type(BYTE type, type_t *ref);
76 static typeref_t *make_tref(char *name, type_t *ref);
77 static typeref_t *uniq_tref(typeref_t *ref);
78 static type_t *type_ref(typeref_t *ref);
79 static void set_type(var_t *v, typeref_t *ref, expr_t *arr);
80 static ifref_t *make_ifref(type_t *iface);
81 static var_t *make_var(char *name);
82 static func_t *make_func(var_t *def, var_t *args);
83 static class_t *make_class(char *name);
85 static type_t *reg_type(type_t *type, char *name, int t);
86 static type_t *reg_types(type_t *type, var_t *names, int t);
87 static type_t *find_type(char *name, int t);
88 static type_t *find_type2(char *name, int t);
89 static type_t *get_type(BYTE type, char *name, int t);
90 static type_t *get_typev(BYTE type, var_t *name, int t);
92 static var_t *reg_const(var_t *var);
93 static var_t *find_const(char *name, int f);
99 static type_t std_bool = { "boolean" };
100 static type_t std_int = { "int" };
101 static type_t std_int64 = { "__int64" };
102 static type_t std_uhyper = { "MIDL_uhyper" };
119 %token <str> aIDENTIFIER
120 %token <str> aKNOWNTYPE
121 %token <num> aNUM aHEXNUM
126 %token tAGGREGATABLE tALLOCATE tAPPOBJECT tARRAYS tASYNC tASYNCUUID
127 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
128 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
129 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
130 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
132 %token tDISPINTERFACE
133 %token tDLLNAME tDOUBLE tDUAL
134 %token tENTRY tENUM tERRORSTATUST
139 %token tHYPER tID tIDEMPOTENT
141 %token tIMPORT tIMPORTLIB
142 %token tIN tINCLUDE tINLINE
146 %token tLENGTHIS tLIBRARY
151 %token tOBJECT tODL tOLEAUTOMATION
153 %token tPOINTERDEFAULT
156 %token tREADONLY tREF
160 %token tSIZEIS tSIZEOF
163 %token tSTRING tSTRUCT
164 %token tSWITCH tSWITCHIS tSWITCHTYPE
173 %token tWCHAR tWIREMARSHAL
178 %type <attr> m_attributes attributes attrib_list attribute
179 %type <expr> m_exprs /* exprs expr_list */ m_expr expr expr_list_const expr_const
180 %type <expr> array array_list
181 %type <type> inherit interface interfacehdr interfacedef interfacedec
182 %type <type> dispinterface dispinterfacehdr dispinterfacedef
183 %type <type> module modulehdr moduledef
184 %type <type> base_type int_std
185 %type <type> enumdef structdef typedef uniondef
186 %type <ifref> gbl_statements coclass_ints coclass_int
188 %type <var> m_args no_args args arg
189 %type <var> fields field s_field cases case enums enum_list enum constdef externdef
190 %type <var> m_ident t_ident ident p_ident pident pident_list
191 %type <var> dispint_props
192 %type <func> funcdef int_statements
193 %type <func> dispint_meths
194 %type <clas> coclass coclasshdr coclassdef
195 %type <num> pointer_type version
196 %type <str> libraryhdr
211 input: gbl_statements { write_proxies($1); }
214 gbl_statements: { $$ = NULL; }
215 | gbl_statements interfacedec { $$ = $1; }
216 | gbl_statements interfacedef { $$ = make_ifref($2); LINK($$, $1); }
217 | gbl_statements coclassdef { $$ = $1; add_coclass($2); }
218 | gbl_statements moduledef { $$ = $1; add_module($2); }
219 | gbl_statements librarydef { $$ = $1; }
220 | gbl_statements statement { $$ = $1; }
224 | imp_statements interfacedec { if (!parse_only) add_interface($2); }
225 | imp_statements interfacedef { if (!parse_only) add_interface($2); }
226 | imp_statements coclassdef { if (!parse_only) add_coclass($2); }
227 | imp_statements moduledef { if (!parse_only) add_module($2); }
228 | imp_statements statement {}
231 int_statements: { $$ = NULL; }
232 | int_statements funcdef ';' { $$ = $2; LINK($$, $1); }
233 | int_statements statement { $$ = $1; }
237 | constdef ';' { if (!parse_only) { write_constdef($1); } }
239 | enumdef ';' { if (!parse_only) { write_type(header, $1, NULL, NULL); fprintf(header, ";\n\n"); } }
240 | externdef ';' { if (!parse_only) { write_externdef($1); } }
242 | structdef ';' { if (!parse_only) { write_type(header, $1, NULL, NULL); fprintf(header, ";\n\n"); } }
244 | uniondef ';' { if (!parse_only) { write_type(header, $1, NULL, NULL); fprintf(header, ";\n\n"); } }
247 cppquote: tCPPQUOTE '(' aSTRING ')' { if (!parse_only) fprintf(header, "%s\n", $3); }
249 import_start: tIMPORT aSTRING ';' { assert(yychar == YYEMPTY);
250 if (!do_import($2)) yychar = aEOF; }
252 import: import_start imp_statements aEOF {}
255 libraryhdr: tLIBRARY aIDENTIFIER { $$ = $2; }
257 library_start: attributes libraryhdr '{' { start_typelib($2, $1); }
259 librarydef: library_start imp_statements '}' { end_typelib(); }
262 m_args: { $$ = NULL; }
266 no_args: tVOID { $$ = NULL; }
270 | args ',' arg { LINK($3, $1); $$ = $3; }
274 /* split into two rules to get bison to resolve a tVOID conflict */
275 arg: attributes type pident array { $$ = $3;
276 set_type($$, $2, $4);
279 | type pident array { $$ = $2;
280 set_type($$, $1, $3);
282 | attributes type pident '(' m_args ')' { $$ = $3;
284 set_type($$, $2, NULL);
288 | type pident '(' m_args ')' { $$ = $2;
290 set_type($$, $1, NULL);
295 array: { $$ = NULL; }
296 | '[' array_list ']' { $$ = $2; }
297 | '[' '*' ']' { $$ = make_expr(EXPR_VOID); }
300 array_list: m_expr /* size of first dimension is optional */
301 | array_list ',' expr { LINK($3, $1); $$ = $3; }
302 | array_list ']' '[' expr { LINK($4, $1); $$ = $4; }
305 m_attributes: { $$ = NULL; }
310 '[' attrib_list ']' { $$ = $2; }
313 attrib_list: attribute
314 | attrib_list ',' attribute { LINK($3, $1); $$ = $3; }
315 | attrib_list ']' '[' attribute { LINK($4, $1); $$ = $4; }
319 tASYNC { $$ = make_attr(ATTR_ASYNC); }
320 | tCALLAS '(' ident ')' { $$ = make_attrp(ATTR_CALLAS, $3); }
321 | tCASE '(' expr_list_const ')' { $$ = make_attrp(ATTR_CASE, $3); }
322 | tCONTEXTHANDLE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); }
323 | tCONTEXTHANDLENOSERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
324 | tCONTEXTHANDLESERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
325 | tDEFAULT { $$ = make_attr(ATTR_DEFAULT); }
326 | tDLLNAME '(' aSTRING ')' { $$ = make_attrp(ATTR_DLLNAME, $3); }
327 | tDUAL { $$ = make_attr(ATTR_DUAL); }
328 | tENTRY '(' aSTRING ')' { $$ = make_attrp(ATTR_ENTRY_STRING, $3); }
329 | tENTRY '(' expr_const ')' { $$ = make_attrp(ATTR_ENTRY_ORDINAL, $3); }
330 | tHELPSTRING '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRING, $3); }
331 | tID '(' expr_const ')' { $$ = make_attrp(ATTR_ID, $3); }
332 | tIDEMPOTENT { $$ = make_attr(ATTR_IDEMPOTENT); }
333 | tIIDIS '(' ident ')' { $$ = make_attrp(ATTR_IIDIS, $3); }
334 | tIN { $$ = make_attr(ATTR_IN); }
335 | tINPUTSYNC { $$ = make_attr(ATTR_INPUTSYNC); }
336 | tLENGTHIS '(' m_exprs ')' { $$ = make_attrp(ATTR_LENGTHIS, $3); }
337 | tLOCAL { $$ = make_attr(ATTR_LOCAL); }
338 | tOBJECT { $$ = make_attr(ATTR_OBJECT); }
339 | tODL { $$ = make_attr(ATTR_ODL); }
340 | tOLEAUTOMATION { $$ = make_attr(ATTR_OLEAUTOMATION); }
341 | tOUT { $$ = make_attr(ATTR_OUT); }
342 | tPOINTERDEFAULT '(' pointer_type ')' { $$ = make_attrv(ATTR_POINTERDEFAULT, $3); }
343 | tPUBLIC { $$ = make_attr(ATTR_PUBLIC); }
344 | tREADONLY { $$ = make_attr(ATTR_READONLY); }
345 | tRETVAL { $$ = make_attr(ATTR_RETVAL); }
346 | tSIZEIS '(' m_exprs ')' { $$ = make_attrp(ATTR_SIZEIS, $3); }
347 | tSOURCE { $$ = make_attr(ATTR_SOURCE); }
348 | tSTRING { $$ = make_attr(ATTR_STRING); }
349 | tSWITCHIS '(' expr ')' { $$ = make_attrp(ATTR_SWITCHIS, $3); }
350 | tSWITCHTYPE '(' type ')' { $$ = make_attrp(ATTR_SWITCHTYPE, type_ref($3)); }
351 | tUUID '(' aUUID ')' { $$ = make_attrp(ATTR_UUID, $3); }
352 | tV1ENUM { $$ = make_attr(ATTR_V1ENUM); }
353 | tVERSION '(' version ')' { $$ = make_attrv(ATTR_VERSION, $3); }
354 | tWIREMARSHAL '(' type ')' { $$ = make_attrp(ATTR_WIREMARSHAL, type_ref($3)); }
355 | pointer_type { $$ = make_attrv(ATTR_POINTERTYPE, $1); }
362 cases: { $$ = NULL; }
363 | cases case { if ($2) { LINK($2, $1); $$ = $2; }
368 case: tCASE expr ':' field { attr_t *a = make_attrp(ATTR_CASE, $2);
369 $$ = $4; if (!$$) $$ = make_var(NULL);
370 LINK(a, $$->attrs); $$->attrs = a;
372 | tDEFAULT ':' field { attr_t *a = make_attr(ATTR_DEFAULT);
373 $$ = $3; if (!$$) $$ = make_var(NULL);
374 LINK(a, $$->attrs); $$->attrs = a;
378 constdef: tCONST type ident '=' expr_const { $$ = reg_const($3);
379 set_type($$, $2, NULL);
385 enums: { $$ = NULL; }
386 | enum_list ',' { $$ = $1; }
391 | enum_list ',' enum { LINK($3, $1); $$ = $3;
393 $3->lval = $1->lval + 1;
397 enum: ident '=' expr_const { $$ = reg_const($1);
401 | ident { $$ = reg_const($1);
402 $$->lval = 0; /* default for first enum entry */
406 enumdef: tENUM t_ident '{' enums '}' { $$ = get_typev(RPC_FC_ENUM16, $2, tsENUM);
413 | m_exprs ',' m_expr { LINK($3, $1); $$ = $3; }
417 exprs: { $$ = make_expr(EXPR_VOID); }
422 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
426 m_expr: { $$ = make_expr(EXPR_VOID); }
430 expr: aNUM { $$ = make_exprl(EXPR_NUM, $1); }
431 | aHEXNUM { $$ = make_exprl(EXPR_HEXNUM, $1); }
432 | aIDENTIFIER { $$ = make_exprs(EXPR_IDENTIFIER, $1); }
433 | expr '|' expr { $$ = make_expr2(EXPR_OR , $1, $3); }
434 | expr '&' expr { $$ = make_expr2(EXPR_AND, $1, $3); }
435 | expr '+' expr { $$ = make_expr2(EXPR_ADD, $1, $3); }
436 | expr '-' expr { $$ = make_expr2(EXPR_SUB, $1, $3); }
437 | expr '*' expr { $$ = make_expr2(EXPR_MUL, $1, $3); }
438 | expr '/' expr { $$ = make_expr2(EXPR_DIV, $1, $3); }
439 | expr SHL expr { $$ = make_expr2(EXPR_SHL, $1, $3); }
440 | expr SHR expr { $$ = make_expr2(EXPR_SHR, $1, $3); }
441 | '~' expr { $$ = make_expr1(EXPR_NOT, $2); }
442 | '-' expr %prec NEG { $$ = make_expr1(EXPR_NEG, $2); }
443 | '*' expr %prec PPTR { $$ = make_expr1(EXPR_PPTR, $2); }
444 | '(' type ')' expr %prec CAST { $$ = make_exprt(EXPR_CAST, $2, $4); }
445 | tSIZEOF '(' type ')' { $$ = make_exprt(EXPR_SIZEOF, $3, NULL); }
446 | '(' expr ')' { $$ = $2; }
449 expr_list_const: expr_const
450 | expr_list_const ',' expr_const { LINK($3, $1); $$ = $3; }
453 expr_const: expr { $$ = $1;
454 if (!$$->is_const) yyerror("expression is not constant\n");
458 externdef: tEXTERN tCONST type ident { $$ = $4;
459 set_type($$, $3, NULL);
463 fields: { $$ = NULL; }
464 | fields field { if ($2) { LINK($2, $1); $$ = $2; }
469 field: s_field ';' { $$ = $1; }
470 | m_attributes uniondef ';' { $$ = make_var(NULL); $$->type = $2; $$->attrs = $1; }
471 | attributes ';' { $$ = make_var(NULL); $$->attrs = $1; }
475 s_field: m_attributes type pident array { $$ = $3; set_type($$, $2, $4); $$->attrs = $1; }
479 m_attributes type callconv pident
480 '(' m_args ')' { set_type($4, $2, NULL);
482 $$ = make_func($4, $6);
486 m_ident: { $$ = NULL; }
490 t_ident: { $$ = NULL; }
491 | aIDENTIFIER { $$ = make_var($1); }
492 | aKNOWNTYPE { $$ = make_var($1); }
495 ident: aIDENTIFIER { $$ = make_var($1); }
496 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
497 | tID { $$ = make_var($<str>1); }
498 | tRETVAL { $$ = make_var($<str>1); }
499 | tVERSION { $$ = make_var($<str>1); }
502 base_type: tBYTE { $$ = make_type(RPC_FC_BYTE, NULL); }
503 | tWCHAR { $$ = make_type(RPC_FC_WCHAR, NULL); }
505 | tSIGNED int_std { $$ = $2; $$->sign = 1; }
506 | tUNSIGNED int_std { $$ = $2; $$->sign = -1;
508 case RPC_FC_SMALL: $$->type = RPC_FC_USMALL; break;
509 case RPC_FC_SHORT: $$->type = RPC_FC_USHORT; break;
510 case RPC_FC_LONG: $$->type = RPC_FC_ULONG; break;
512 if (!$$->ref) { $$->ref = &std_uhyper; $$->sign = 0; }
517 | tFLOAT { $$ = make_type(RPC_FC_FLOAT, NULL); }
518 | tDOUBLE { $$ = make_type(RPC_FC_DOUBLE, NULL); }
519 | tBOOLEAN { $$ = make_type(RPC_FC_BYTE, &std_bool); /* ? */ }
520 | tERRORSTATUST { $$ = make_type(RPC_FC_ERROR_STATUS_T, NULL); }
521 | tHANDLET { $$ = make_type(RPC_FC_BIND_PRIMITIVE, NULL); /* ? */ }
528 int_std: tINT { $$ = make_type(RPC_FC_LONG, &std_int); } /* win32 only */
529 | tSHORT m_int { $$ = make_type(RPC_FC_SHORT, NULL); }
530 | tLONG m_int { $$ = make_type(RPC_FC_LONG, NULL); }
531 | tHYPER m_int { $$ = make_type(RPC_FC_HYPER, NULL); }
532 | tINT64 { $$ = make_type(RPC_FC_HYPER, &std_int64); }
533 | tCHAR { $$ = make_type(RPC_FC_CHAR, NULL); }
536 coclass: tCOCLASS aIDENTIFIER { $$ = make_class($2); }
537 | tCOCLASS aKNOWNTYPE { $$ = make_class($2); }
540 coclasshdr: attributes coclass { $$ = $2;
545 coclassdef: coclasshdr '{' coclass_ints '}' { $$ = $1;
550 coclass_ints: { $$ = NULL; }
551 | coclass_ints coclass_int { LINK($2, $1); $$ = $2; }
555 m_attributes interfacedec { $$ = make_ifref($2); $$->attrs = $1; }
558 dispinterface: tDISPINTERFACE aIDENTIFIER { $$ = get_type(0, $2, 0); }
559 | tDISPINTERFACE aKNOWNTYPE { $$ = get_type(0, $2, 0); }
562 dispinterfacehdr: attributes dispinterface { $$ = $2;
563 if ($$->defined) yyerror("multiple definition error\n");
565 /* $$->attrs = make_attr(ATTR_DISPINTERFACE); */
566 /* LINK($$->attrs, $1); */
567 $$->ref = find_type("IDispatch", 0);
568 if (!$$->ref) yyerror("IDispatch is undefined\n");
570 if (!parse_only) write_forward($$);
574 dispint_props: tPROPERTIES ':' { $$ = NULL; }
575 | dispint_props s_field ';' { LINK($2, $1); $$ = $2; }
578 dispint_meths: tMETHODS ':' { $$ = NULL; }
579 | dispint_meths funcdef ';' { LINK($2, $1); $$ = $2; }
582 dispinterfacedef: dispinterfacehdr '{'
588 if (!parse_only) write_interface($$);
590 /* FIXME: not sure how to handle this yet
591 | dispinterfacehdr '{' interface '}' { $$ = $1;
592 if (!parse_only) write_interface($$);
597 inherit: { $$ = NULL; }
598 | ':' aKNOWNTYPE { $$ = find_type2($2, 0); }
601 interface: tINTERFACE aIDENTIFIER { $$ = get_type(RPC_FC_IP, $2, 0); }
602 | tINTERFACE aKNOWNTYPE { $$ = get_type(RPC_FC_IP, $2, 0); }
605 interfacehdr: attributes interface { $$ = $2;
606 if ($$->defined) yyerror("multiple definition error\n");
609 if (!parse_only) write_forward($$);
613 interfacedef: interfacehdr inherit
614 '{' int_statements '}' { $$ = $1;
617 if (!parse_only) write_interface($$);
619 /* MIDL is able to import the definition of a base class from inside the
620 * definition of a derived class, I'll try to support it with this rule */
621 | interfacehdr ':' aIDENTIFIER
622 '{' import int_statements '}' { $$ = $1;
623 $$->ref = find_type2($3, 0);
624 if (!$$->ref) yyerror("base class %s not found in import\n", $3);
626 if (!parse_only) write_interface($$);
628 | dispinterfacedef { $$ = $1; }
632 interface ';' { $$ = $1; if (!parse_only) write_forward($$); }
633 | dispinterface ';' { $$ = $1; if (!parse_only) write_forward($$); }
636 module: tMODULE aIDENTIFIER { $$ = make_type(0, NULL); $$->name = $2; }
637 | tMODULE aKNOWNTYPE { $$ = make_type(0, NULL); $$->name = $2; }
640 modulehdr: attributes module { $$ = $2;
645 moduledef: modulehdr '{' int_statements '}' { $$ = $1;
647 /* FIXME: if (!parse_only) write_module($$); */
651 p_ident: '*' pident %prec PPTR { $$ = $2; $$->ptr_level++; }
652 | tCONST p_ident { $$ = $2; /* FIXME */ }
657 | '(' pident ')' { $$ = $2; }
662 | pident_list ',' pident { LINK($3, $1); $$ = $3; }
666 tREF { $$ = RPC_FC_RP; }
667 | tUNIQUE { $$ = RPC_FC_UP; }
670 structdef: tSTRUCT t_ident '{' fields '}' { $$ = get_typev(RPC_FC_STRUCT, $2, tsSTRUCT);
676 type: tVOID { $$ = make_tref(NULL, make_type(0, NULL)); }
677 | aKNOWNTYPE { $$ = make_tref($1, find_type($1, 0)); }
678 | base_type { $$ = make_tref(NULL, $1); }
679 | tCONST type { $$ = uniq_tref($2); $$->ref->is_const = TRUE; }
680 | enumdef { $$ = make_tref(NULL, $1); }
681 | tENUM aIDENTIFIER { $$ = make_tref(NULL, find_type2($2, tsENUM)); }
682 | structdef { $$ = make_tref(NULL, $1); }
683 | tSTRUCT aIDENTIFIER { $$ = make_tref(NULL, get_type(RPC_FC_STRUCT, $2, tsSTRUCT)); }
684 | uniondef { $$ = make_tref(NULL, $1); }
685 | tUNION aIDENTIFIER { $$ = make_tref(NULL, find_type2($2, tsUNION)); }
688 typedef: tTYPEDEF m_attributes type pident_list { typeref_t *tref = uniq_tref($3);
689 $4->tname = tref->name;
693 if (!parse_only) write_typedef($$, $4);
694 reg_types($$, $4, 0);
698 uniondef: tUNION t_ident '{' fields '}' { $$ = get_typev(RPC_FC_NON_ENCAPSULATED_UNION, $2, tsUNION);
703 tSWITCH '(' s_field ')'
704 m_ident '{' cases '}' { var_t *u = $7;
705 $$ = get_typev(RPC_FC_ENCAPSULATED_UNION, $2, tsUNION);
706 if (!u) u = make_var("tagged_union");
707 u->type = make_type(RPC_FC_NON_ENCAPSULATED_UNION, NULL);
708 u->type->fields = $9;
709 u->type->defined = TRUE;
710 LINK(u, $5); $$->fields = u;
716 aNUM { $$ = MAKELONG($1, 0); }
717 | aNUM '.' aNUM { $$ = MAKELONG($1, $3); }
722 static attr_t *make_attr(enum attr_type type)
724 attr_t *a = xmalloc(sizeof(attr_t));
731 static attr_t *make_attrv(enum attr_type type, DWORD val)
733 attr_t *a = xmalloc(sizeof(attr_t));
740 static attr_t *make_attrp(enum attr_type type, void *val)
742 attr_t *a = xmalloc(sizeof(attr_t));
749 static expr_t *make_expr(enum expr_type type)
751 expr_t *e = xmalloc(sizeof(expr_t));
760 static expr_t *make_exprl(enum expr_type type, long val)
762 expr_t *e = xmalloc(sizeof(expr_t));
768 /* check for numeric constant */
769 if (type == EXPR_NUM || type == EXPR_HEXNUM) {
776 static expr_t *make_exprs(enum expr_type type, char *val)
779 e = xmalloc(sizeof(expr_t));
785 /* check for predefined constants */
786 if (type == EXPR_IDENTIFIER) {
787 var_t *c = find_const(val, 0);
798 static expr_t *make_exprt(enum expr_type type, typeref_t *tref, expr_t *expr)
801 e = xmalloc(sizeof(expr_t));
807 /* check for cast of constant expression */
808 if (type == EXPR_CAST && expr->is_const) {
810 e->cval = expr->cval;
815 static expr_t *make_expr1(enum expr_type type, expr_t *expr)
818 e = xmalloc(sizeof(expr_t));
824 /* check for compile-time optimization */
825 if (expr->is_const) {
829 e->cval = -expr->cval;
832 e->cval = ~expr->cval;
842 static expr_t *make_expr2(enum expr_type type, expr_t *expr1, expr_t *expr2)
845 e = xmalloc(sizeof(expr_t));
851 /* check for compile-time optimization */
852 if (expr1->is_const && expr2->is_const) {
856 e->cval = expr1->cval + expr2->cval;
859 e->cval = expr1->cval - expr2->cval;
862 e->cval = expr1->cval * expr2->cval;
865 e->cval = expr1->cval / expr2->cval;
868 e->cval = expr1->cval | expr2->cval;
871 e->cval = expr1->cval & expr2->cval;
874 e->cval = expr1->cval << expr2->cval;
877 e->cval = expr1->cval >> expr2->cval;
887 static type_t *make_type(BYTE type, type_t *ref)
889 type_t *t = xmalloc(sizeof(type_t));
897 t->ignore = parse_only;
906 static typeref_t *make_tref(char *name, type_t *ref)
908 typeref_t *t = xmalloc(sizeof(typeref_t));
911 t->uniq = ref ? 0 : 1;
915 static typeref_t *uniq_tref(typeref_t *ref)
919 if (t->uniq) return t;
920 tp = make_type(0, t->ref);
928 static type_t *type_ref(typeref_t *ref)
930 type_t *t = ref->ref;
931 if (ref->name) free(ref->name);
936 static void set_type(var_t *v, typeref_t *ref, expr_t *arr)
939 v->tname = ref->name;
945 static ifref_t *make_ifref(type_t *iface)
947 ifref_t *l = xmalloc(sizeof(ifref_t));
954 static var_t *make_var(char *name)
956 var_t *v = xmalloc(sizeof(var_t));
969 static func_t *make_func(var_t *def, var_t *args)
971 func_t *f = xmalloc(sizeof(func_t));
974 f->ignore = parse_only;
980 static class_t *make_class(char *name)
982 class_t *c = xmalloc(sizeof(class_t));
992 static int hash_ident(const char *name)
994 const char *p = name;
996 /* a simple sum hash is probably good enough */
1001 return sum & (HASHMAX-1);
1004 /***** type repository *****/
1013 struct rtype *type_hash[HASHMAX];
1015 static type_t *reg_type(type_t *type, char *name, int t)
1020 yyerror("registering named type without name\n");
1023 hash = hash_ident(name);
1024 nt = xmalloc(sizeof(struct rtype));
1028 nt->next = type_hash[hash];
1029 type_hash[hash] = nt;
1033 static type_t *reg_types(type_t *type, var_t *names, int t)
1039 var_t *next = NEXT_LINK(names);
1042 int cptr = names->ptr_level;
1044 while (cptr > ptrc) {
1045 cur = ptr = make_type(RPC_FC_FP, cur); /* FIXME: pointer type from attrs? */
1049 while (cptr < ptrc) {
1054 reg_type(cur, names->name, t);
1062 static type_t *find_type(char *name, int t)
1064 struct rtype *cur = type_hash[hash_ident(name)];
1065 while (cur && (cur->t != t || strcmp(cur->name, name)))
1068 yyerror("type %s not found\n", name);
1074 static type_t *find_type2(char *name, int t)
1076 type_t *tp = find_type(name, t);
1081 int is_type(const char *name)
1083 struct rtype *cur = type_hash[hash_ident(name)];
1084 while (cur && (cur->t || strcmp(cur->name, name)))
1086 if (cur) return TRUE;
1090 static type_t *get_type(BYTE type, char *name, int t)
1092 struct rtype *cur = NULL;
1095 cur = type_hash[hash_ident(name)];
1096 while (cur && (cur->t != t || strcmp(cur->name, name)))
1103 tp = make_type(type, NULL);
1105 if (!name) return tp;
1106 return reg_type(tp, name, t);
1109 static type_t *get_typev(BYTE type, var_t *name, int t)
1116 return get_type(type, sname, t);
1119 /***** constant repository *****/
1124 struct rconst *next;
1127 struct rconst *const_hash[HASHMAX];
1129 static var_t *reg_const(var_t *var)
1134 yyerror("registering constant without name\n");
1137 hash = hash_ident(var->name);
1138 nc = xmalloc(sizeof(struct rconst));
1139 nc->name = var->name;
1141 nc->next = const_hash[hash];
1142 const_hash[hash] = nc;
1146 static var_t *find_const(char *name, int f)
1148 struct rconst *cur = const_hash[hash_ident(name)];
1149 while (cur && strcmp(cur->name, name))
1152 if (f) yyerror("constant %s not found\n", name);