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 expr_t
*make_expr3
(enum expr_type type
, expr_t
*exp1
, expr_t
*exp2
, expr_t
*exp3
);
76 static type_t
*make_type
(BYTE type
, type_t
*ref
);
77 static typeref_t
*make_tref
(char *name
, type_t
*ref
);
78 static typeref_t
*uniq_tref
(typeref_t
*ref
);
79 static type_t
*type_ref
(typeref_t
*ref
);
80 static void set_type
(var_t
*v
, typeref_t
*ref
, expr_t
*arr
);
81 static ifref_t
*make_ifref
(type_t
*iface
);
82 static var_t
*make_var
(char *name
);
83 static func_t
*make_func
(var_t
*def
, var_t
*args
);
84 static class_t
*make_class
(char *name
);
86 static type_t
*reg_type
(type_t
*type
, char *name
, int t
);
87 static type_t
*reg_types
(type_t
*type
, var_t
*names
, int t
);
88 static type_t
*find_type
(char *name
, int t
);
89 static type_t
*find_type2
(char *name
, int t
);
90 static type_t
*get_type
(BYTE type
, char *name
, int t
);
91 static type_t
*get_typev
(BYTE type
, var_t
*name
, int t
);
93 static var_t
*reg_const
(var_t
*var
);
94 static var_t
*find_const
(char *name
, int f
);
100 static type_t std_bool
= { "boolean" };
101 static type_t std_int
= { "int" };
102 static type_t std_int64
= { "__int64" };
103 static type_t std_uhyper
= { "MIDL_uhyper" };
120 %token
<str
> aIDENTIFIER
121 %token
<str
> aKNOWNTYPE
122 %token
<num
> aNUM aHEXNUM
127 %token tAGGREGATABLE tALLOCATE tAPPOBJECT tARRAYS tASYNC tASYNCUUID
128 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
129 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
130 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
131 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
133 %token tDISPINTERFACE
134 %token tDLLNAME tDOUBLE tDUAL
135 %token tENTRY tENUM tERRORSTATUST
141 %token tHYPER tID tIDEMPOTENT
143 %token tIMPORT tIMPORTLIB
144 %token tIN tINCLUDE tINLINE
148 %token tLENGTHIS tLIBRARY
153 %token tOBJECT tODL tOLEAUTOMATION
155 %token tPOINTERDEFAULT
158 %token tREADONLY tREF
162 %token tSIZEIS tSIZEOF
165 %token tSTRING tSTRUCT
166 %token tSWITCH tSWITCHIS tSWITCHTYPE
175 %token tWCHAR tWIREMARSHAL
180 %type
<attr
> m_attributes attributes attrib_list attribute
181 %type
<expr
> m_exprs
/* exprs expr_list */ m_expr expr expr_list_const expr_const
182 %type
<expr
> array array_list
183 %type
<type
> inherit interface interfacehdr interfacedef interfacedec
184 %type
<type
> dispinterface dispinterfacehdr dispinterfacedef
185 %type
<type
> module modulehdr moduledef
186 %type
<type
> base_type int_std
187 %type
<type
> enumdef structdef typedef uniondef
188 %type
<ifref
> gbl_statements coclass_ints coclass_int
190 %type
<var
> m_args no_args args arg
191 %type
<var
> fields field s_field cases case enums enum_list
enum constdef externdef
192 %type
<var
> m_ident t_ident ident p_ident pident pident_list
193 %type
<var
> dispint_props
194 %type
<func
> funcdef int_statements
195 %type
<func
> dispint_meths
196 %type
<clas
> coclass coclasshdr coclassdef
197 %type
<num
> pointer_type version
198 %type
<str
> libraryhdr
213 input: gbl_statements
{ write_proxies
($1); }
216 gbl_statements: { $$
= NULL
; }
217 | gbl_statements interfacedec
{ $$
= $1; }
218 | gbl_statements interfacedef
{ $$
= make_ifref
($2); LINK
($$
, $1); }
219 | gbl_statements coclassdef
{ $$
= $1; add_coclass
($2); }
220 | gbl_statements moduledef
{ $$
= $1; add_module
($2); }
221 | gbl_statements librarydef
{ $$
= $1; }
222 | gbl_statements statement
{ $$
= $1; }
226 | imp_statements interfacedec
{ if
(!parse_only
) add_interface
($2); }
227 | imp_statements interfacedef
{ if
(!parse_only
) add_interface
($2); }
228 | imp_statements coclassdef
{ if
(!parse_only
) add_coclass
($2); }
229 | imp_statements moduledef
{ if
(!parse_only
) add_module
($2); }
230 | imp_statements statement
{}
233 int_statements: { $$
= NULL
; }
234 | int_statements funcdef
';' { $$
= $2; LINK
($$
, $1); }
235 | int_statements statement
{ $$
= $1; }
239 | constdef
';' { if
(!parse_only
) { write_constdef
($1); } }
241 | enumdef
';' { if
(!parse_only
) { write_type
(header
, $1, NULL
, NULL
); fprintf
(header
, ";\n\n"); } }
242 | externdef
';' { if
(!parse_only
) { write_externdef
($1); } }
244 | structdef
';' { if
(!parse_only
) { write_type
(header
, $1, NULL
, NULL
); fprintf
(header
, ";\n\n"); } }
246 | uniondef
';' { if
(!parse_only
) { write_type
(header
, $1, NULL
, NULL
); fprintf
(header
, ";\n\n"); } }
249 cppquote: tCPPQUOTE
'(' aSTRING
')' { if
(!parse_only
) fprintf
(header
, "%s\n", $3); }
251 import_start: tIMPORT aSTRING
';' { assert
(yychar == YYEMPTY
);
252 if
(!do_import
($2)) yychar = aEOF
; }
254 import: import_start imp_statements aEOF
{}
257 libraryhdr: tLIBRARY aIDENTIFIER
{ $$
= $2; }
259 library_start: attributes libraryhdr
'{' { start_typelib
($2, $1); }
261 librarydef: library_start imp_statements
'}' { end_typelib
(); }
264 m_args: { $$
= NULL
; }
268 no_args: tVOID
{ $$
= NULL
; }
272 | args
',' arg
{ LINK
($3, $1); $$
= $3; }
276 /* split into two rules to get bison to resolve a tVOID conflict */
277 arg: attributes type pident array
{ $$
= $3;
278 set_type
($$
, $2, $4);
281 | type pident array
{ $$
= $2;
282 set_type
($$
, $1, $3);
284 | attributes type pident
'(' m_args
')' { $$
= $3;
286 set_type
($$
, $2, NULL
);
290 | type pident
'(' m_args
')' { $$
= $2;
292 set_type
($$
, $1, NULL
);
297 array: { $$
= NULL
; }
298 |
'[' array_list
']' { $$
= $2; }
299 |
'[' '*' ']' { $$
= make_expr
(EXPR_VOID
); }
302 array_list: m_expr
/* size of first dimension is optional */
303 | array_list
',' expr
{ LINK
($3, $1); $$
= $3; }
304 | array_list
']' '[' expr
{ LINK
($4, $1); $$
= $4; }
307 m_attributes: { $$
= NULL
; }
312 '[' attrib_list
']' { $$
= $2; }
315 attrib_list: attribute
316 | attrib_list
',' attribute
{ LINK
($3, $1); $$
= $3; }
317 | attrib_list
']' '[' attribute
{ LINK
($4, $1); $$
= $4; }
321 tASYNC
{ $$
= make_attr
(ATTR_ASYNC
); }
322 | tCALLAS
'(' ident
')' { $$
= make_attrp
(ATTR_CALLAS
, $3); }
323 | tCASE
'(' expr_list_const
')' { $$
= make_attrp
(ATTR_CASE
, $3); }
324 | tCONTEXTHANDLE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); }
325 | tCONTEXTHANDLENOSERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
326 | tCONTEXTHANDLESERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
327 | tDEFAULT
{ $$
= make_attr
(ATTR_DEFAULT
); }
328 | tDLLNAME
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DLLNAME
, $3); }
329 | tDUAL
{ $$
= make_attr
(ATTR_DUAL
); }
330 | tENTRY
'(' aSTRING
')' { $$
= make_attrp
(ATTR_ENTRY_STRING
, $3); }
331 | tENTRY
'(' expr_const
')' { $$
= make_attrp
(ATTR_ENTRY_ORDINAL
, $3); }
332 | tHANDLE
{ $$
= make_attr
(ATTR_HANDLE
); }
333 | tHELPSTRING
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRING
, $3); }
334 | tID
'(' expr_const
')' { $$
= make_attrp
(ATTR_ID
, $3); }
335 | tIDEMPOTENT
{ $$
= make_attr
(ATTR_IDEMPOTENT
); }
336 | tIIDIS
'(' ident
')' { $$
= make_attrp
(ATTR_IIDIS
, $3); }
337 | tIN
{ $$
= make_attr
(ATTR_IN
); }
338 | tINPUTSYNC
{ $$
= make_attr
(ATTR_INPUTSYNC
); }
339 | tLENGTHIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_LENGTHIS
, $3); }
340 | tLOCAL
{ $$
= make_attr
(ATTR_LOCAL
); }
341 | tOBJECT
{ $$
= make_attr
(ATTR_OBJECT
); }
342 | tODL
{ $$
= make_attr
(ATTR_ODL
); }
343 | tOLEAUTOMATION
{ $$
= make_attr
(ATTR_OLEAUTOMATION
); }
344 | tOUT
{ $$
= make_attr
(ATTR_OUT
); }
345 | tPOINTERDEFAULT
'(' pointer_type
')' { $$
= make_attrv
(ATTR_POINTERDEFAULT
, $3); }
346 | tPUBLIC
{ $$
= make_attr
(ATTR_PUBLIC
); }
347 | tREADONLY
{ $$
= make_attr
(ATTR_READONLY
); }
348 | tRETVAL
{ $$
= make_attr
(ATTR_RETVAL
); }
349 | tSIZEIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_SIZEIS
, $3); }
350 | tSOURCE
{ $$
= make_attr
(ATTR_SOURCE
); }
351 | tSTRING
{ $$
= make_attr
(ATTR_STRING
); }
352 | tSWITCHIS
'(' expr
')' { $$
= make_attrp
(ATTR_SWITCHIS
, $3); }
353 | tSWITCHTYPE
'(' type
')' { $$
= make_attrp
(ATTR_SWITCHTYPE
, type_ref
($3)); }
354 | tUUID
'(' aUUID
')' { $$
= make_attrp
(ATTR_UUID
, $3); }
355 | tV1ENUM
{ $$
= make_attr
(ATTR_V1ENUM
); }
356 | tVERSION
'(' version
')' { $$
= make_attrv
(ATTR_VERSION
, $3); }
357 | tWIREMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_WIREMARSHAL
, type_ref
($3)); }
358 | pointer_type
{ $$
= make_attrv
(ATTR_POINTERTYPE
, $1); }
365 cases: { $$
= NULL
; }
366 | cases case
{ if
($2) { LINK
($2, $1); $$
= $2; }
371 case: tCASE expr
':' field
{ attr_t
*a
= make_attrp
(ATTR_CASE
, $2);
372 $$
= $4; if
(!$$
) $$
= make_var
(NULL
);
373 LINK
(a
, $$
->attrs
); $$
->attrs
= a
;
375 | tDEFAULT
':' field
{ attr_t
*a
= make_attr
(ATTR_DEFAULT
);
376 $$
= $3; if
(!$$
) $$
= make_var
(NULL
);
377 LINK
(a
, $$
->attrs
); $$
->attrs
= a
;
381 constdef: tCONST type ident
'=' expr_const
{ $$
= reg_const
($3);
382 set_type
($$
, $2, NULL
);
388 enums: { $$
= NULL
; }
389 | enum_list
',' { $$
= $1; }
394 | enum_list
',' enum { LINK
($3, $1); $$
= $3;
396 $3->lval
= $1->lval
+ 1;
400 enum: ident
'=' expr_const
{ $$
= reg_const
($1);
404 | ident
{ $$
= reg_const
($1);
405 $$
->lval
= 0; /* default for first enum entry */
409 enumdef: tENUM t_ident
'{' enums
'}' { $$
= get_typev
(RPC_FC_ENUM16
, $2, tsENUM
);
416 | m_exprs
',' m_expr
{ LINK
($3, $1); $$
= $3; }
420 exprs: { $$ = make_expr(EXPR_VOID); }
425 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
429 m_expr: { $$
= make_expr
(EXPR_VOID
); }
433 expr: aNUM
{ $$
= make_exprl
(EXPR_NUM
, $1); }
434 | aHEXNUM
{ $$
= make_exprl
(EXPR_HEXNUM
, $1); }
435 | aIDENTIFIER
{ $$
= make_exprs
(EXPR_IDENTIFIER
, $1); }
436 | expr
'?' expr
':' expr
{ $$
= make_expr3
(EXPR_COND
, $1, $3, $5); }
437 | expr
'|' expr
{ $$
= make_expr2
(EXPR_OR
, $1, $3); }
438 | expr
'&' expr
{ $$
= make_expr2
(EXPR_AND
, $1, $3); }
439 | expr
'+' expr
{ $$
= make_expr2
(EXPR_ADD
, $1, $3); }
440 | expr
'-' expr
{ $$
= make_expr2
(EXPR_SUB
, $1, $3); }
441 | expr
'*' expr
{ $$
= make_expr2
(EXPR_MUL
, $1, $3); }
442 | expr
'/' expr
{ $$
= make_expr2
(EXPR_DIV
, $1, $3); }
443 | expr SHL expr
{ $$
= make_expr2
(EXPR_SHL
, $1, $3); }
444 | expr SHR expr
{ $$
= make_expr2
(EXPR_SHR
, $1, $3); }
445 |
'~' expr
{ $$
= make_expr1
(EXPR_NOT
, $2); }
446 |
'-' expr %prec NEG
{ $$
= make_expr1
(EXPR_NEG
, $2); }
447 |
'*' expr %prec PPTR
{ $$
= make_expr1
(EXPR_PPTR
, $2); }
448 |
'(' type
')' expr %prec CAST
{ $$
= make_exprt
(EXPR_CAST
, $2, $4); }
449 | tSIZEOF
'(' type
')' { $$
= make_exprt
(EXPR_SIZEOF
, $3, NULL
); }
450 |
'(' expr
')' { $$
= $2; }
453 expr_list_const: expr_const
454 | expr_list_const
',' expr_const
{ LINK
($3, $1); $$
= $3; }
457 expr_const: expr
{ $$
= $1;
458 if
(!$$
->is_const
) yyerror("expression is not constant\n");
462 externdef: tEXTERN tCONST type ident
{ $$
= $4;
463 set_type
($$
, $3, NULL
);
467 fields: { $$
= NULL
; }
468 | fields field
{ if
($2) { LINK
($2, $1); $$
= $2; }
473 field: s_field
';' { $$
= $1; }
474 | m_attributes uniondef
';' { $$
= make_var
(NULL
); $$
->type
= $2; $$
->attrs
= $1; }
475 | attributes
';' { $$
= make_var
(NULL
); $$
->attrs
= $1; }
479 s_field: m_attributes type pident array
{ $$
= $3; set_type
($$
, $2, $4); $$
->attrs
= $1; }
483 m_attributes type callconv pident
484 '(' m_args
')' { set_type
($4, $2, NULL
);
486 $$
= make_func
($4, $6);
490 m_ident: { $$
= NULL
; }
494 t_ident: { $$
= NULL
; }
495 | aIDENTIFIER
{ $$
= make_var
($1); }
496 | aKNOWNTYPE
{ $$
= make_var
($1); }
499 ident: aIDENTIFIER
{ $$
= make_var
($1); }
500 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
501 | tID
{ $$
= make_var
($
<str
>1); }
502 | tRETVAL
{ $$
= make_var
($
<str
>1); }
503 | tVERSION
{ $$
= make_var
($
<str
>1); }
506 base_type: tBYTE
{ $$
= make_type
(RPC_FC_BYTE
, NULL
); }
507 | tWCHAR
{ $$
= make_type
(RPC_FC_WCHAR
, NULL
); }
509 | tSIGNED int_std
{ $$
= $2; $$
->sign
= 1; }
510 | tUNSIGNED int_std
{ $$
= $2; $$
->sign
= -1;
512 case RPC_FC_SMALL
: $$
->type
= RPC_FC_USMALL
; break
;
513 case RPC_FC_SHORT
: $$
->type
= RPC_FC_USHORT
; break
;
514 case RPC_FC_LONG
: $$
->type
= RPC_FC_ULONG
; break
;
516 if
(!$$
->ref
) { $$
->ref
= &std_uhyper
; $$
->sign
= 0; }
521 | tFLOAT
{ $$
= make_type
(RPC_FC_FLOAT
, NULL
); }
522 | tDOUBLE
{ $$
= make_type
(RPC_FC_DOUBLE
, NULL
); }
523 | tBOOLEAN
{ $$
= make_type
(RPC_FC_BYTE
, &std_bool
); /* ? */ }
524 | tERRORSTATUST
{ $$
= make_type
(RPC_FC_ERROR_STATUS_T
, NULL
); }
525 | tHANDLET
{ $$
= make_type
(RPC_FC_BIND_PRIMITIVE
, NULL
); /* ? */ }
532 int_std: tINT
{ $$
= make_type
(RPC_FC_LONG
, &std_int
); } /* win32 only */
533 | tSHORT m_int
{ $$
= make_type
(RPC_FC_SHORT
, NULL
); }
534 | tLONG m_int
{ $$
= make_type
(RPC_FC_LONG
, NULL
); }
535 | tHYPER m_int
{ $$
= make_type
(RPC_FC_HYPER
, NULL
); }
536 | tINT64
{ $$
= make_type
(RPC_FC_HYPER
, &std_int64
); }
537 | tCHAR
{ $$
= make_type
(RPC_FC_CHAR
, NULL
); }
540 coclass: tCOCLASS aIDENTIFIER
{ $$
= make_class
($2); }
541 | tCOCLASS aKNOWNTYPE
{ $$
= make_class
($2); }
544 coclasshdr: attributes coclass
{ $$
= $2;
549 coclassdef: coclasshdr
'{' coclass_ints
'}' { $$
= $1;
554 coclass_ints: { $$
= NULL
; }
555 | coclass_ints coclass_int
{ LINK
($2, $1); $$
= $2; }
559 m_attributes interfacedec
{ $$
= make_ifref
($2); $$
->attrs
= $1; }
562 dispinterface: tDISPINTERFACE aIDENTIFIER
{ $$
= get_type
(0, $2, 0); }
563 | tDISPINTERFACE aKNOWNTYPE
{ $$
= get_type
(0, $2, 0); }
566 dispinterfacehdr: attributes dispinterface
{ $$
= $2;
567 if
($$
->defined
) yyerror("multiple definition error\n");
569 /* $$->attrs = make_attr(ATTR_DISPINTERFACE); */
570 /* LINK($$->attrs, $1); */
571 $$
->ref
= find_type
("IDispatch", 0);
572 if
(!$$
->ref
) yyerror("IDispatch is undefined\n");
574 if
(!parse_only
) write_forward
($$
);
578 dispint_props: tPROPERTIES
':' { $$
= NULL
; }
579 | dispint_props s_field
';' { LINK
($2, $1); $$
= $2; }
582 dispint_meths: tMETHODS
':' { $$
= NULL
; }
583 | dispint_meths funcdef
';' { LINK
($2, $1); $$
= $2; }
586 dispinterfacedef: dispinterfacehdr
'{'
592 if
(!parse_only
) write_interface
($$
);
594 /* FIXME: not sure how to handle this yet
595 | dispinterfacehdr '{' interface '}' { $$ = $1;
596 if (!parse_only) write_interface($$);
601 inherit: { $$
= NULL
; }
602 |
':' aKNOWNTYPE
{ $$
= find_type2
($2, 0); }
605 interface: tINTERFACE aIDENTIFIER
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
606 | tINTERFACE aKNOWNTYPE
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
609 interfacehdr: attributes interface
{ $$
= $2;
610 if
($$
->defined
) yyerror("multiple definition error\n");
613 if
(!parse_only
) write_forward
($$
);
617 interfacedef: interfacehdr inherit
618 '{' int_statements
'}' { $$
= $1;
621 if
(!parse_only
) write_interface
($$
);
623 /* MIDL is able to import the definition of a base class from inside the
624 * definition of a derived class, I'll try to support it with this rule */
625 | interfacehdr
':' aIDENTIFIER
626 '{' import int_statements
'}' { $$
= $1;
627 $$
->ref
= find_type2
($3, 0);
628 if
(!$$
->ref
) yyerror("base class %s not found in import\n", $3);
630 if
(!parse_only
) write_interface
($$
);
632 | dispinterfacedef
{ $$
= $1; }
636 interface
';' { $$
= $1; if
(!parse_only
) write_forward
($$
); }
637 | dispinterface
';' { $$
= $1; if
(!parse_only
) write_forward
($$
); }
640 module: tMODULE aIDENTIFIER
{ $$
= make_type
(0, NULL
); $$
->name
= $2; }
641 | tMODULE aKNOWNTYPE
{ $$
= make_type
(0, NULL
); $$
->name
= $2; }
644 modulehdr: attributes module
{ $$
= $2;
649 moduledef: modulehdr
'{' int_statements
'}' { $$
= $1;
651 /* FIXME: if (!parse_only) write_module($$); */
655 p_ident: '*' pident %prec PPTR
{ $$
= $2; $$
->ptr_level
++; }
656 | tCONST p_ident
{ $$
= $2; /* FIXME */ }
661 |
'(' pident
')' { $$
= $2; }
666 | pident_list
',' pident
{ LINK
($3, $1); $$
= $3; }
670 tREF
{ $$
= RPC_FC_RP
; }
671 | tUNIQUE
{ $$
= RPC_FC_UP
; }
674 structdef: tSTRUCT t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_STRUCT
, $2, tsSTRUCT
);
680 type: tVOID
{ $$
= make_tref
(NULL
, make_type
(0, NULL
)); }
681 | aKNOWNTYPE
{ $$
= make_tref
($1, find_type
($1, 0)); }
682 | base_type
{ $$
= make_tref
(NULL
, $1); }
683 | tCONST type
{ $$
= uniq_tref
($2); $$
->ref
->is_const
= TRUE
; }
684 | enumdef
{ $$
= make_tref
(NULL
, $1); }
685 | tENUM aIDENTIFIER
{ $$
= make_tref
(NULL
, find_type2
($2, tsENUM
)); }
686 | structdef
{ $$
= make_tref
(NULL
, $1); }
687 | tSTRUCT aIDENTIFIER
{ $$
= make_tref
(NULL
, get_type
(RPC_FC_STRUCT
, $2, tsSTRUCT
)); }
688 | uniondef
{ $$
= make_tref
(NULL
, $1); }
689 | tUNION aIDENTIFIER
{ $$
= make_tref
(NULL
, find_type2
($2, tsUNION
)); }
692 typedef: tTYPEDEF m_attributes type pident_list
{ typeref_t
*tref
= uniq_tref
($3);
693 $4->tname
= tref
->name
;
697 if
(!parse_only
) write_typedef
($$
, $4);
698 reg_types
($$
, $4, 0);
702 uniondef: tUNION t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_NON_ENCAPSULATED_UNION
, $2, tsUNION
);
707 tSWITCH
'(' s_field
')'
708 m_ident
'{' cases
'}' { var_t
*u
= $7;
709 $$
= get_typev
(RPC_FC_ENCAPSULATED_UNION
, $2, tsUNION
);
710 if
(!u
) u
= make_var
("tagged_union");
711 u
->type
= make_type
(RPC_FC_NON_ENCAPSULATED_UNION
, NULL
);
712 u
->type
->fields
= $9;
713 u
->type
->defined
= TRUE
;
714 LINK
(u
, $5); $$
->fields
= u
;
720 aNUM
{ $$
= MAKELONG
($1, 0); }
721 | aNUM
'.' aNUM
{ $$
= MAKELONG
($1, $3); }
726 static attr_t
*make_attr
(enum attr_type type
)
728 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
735 static attr_t
*make_attrv
(enum attr_type type
, DWORD val
)
737 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
744 static attr_t
*make_attrp
(enum attr_type type
, void *val
)
746 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
753 static expr_t
*make_expr
(enum expr_type type
)
755 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
764 static expr_t
*make_exprl
(enum expr_type type
, long val
)
766 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
772 /* check for numeric constant */
773 if
(type
== EXPR_NUM || type
== EXPR_HEXNUM
) {
780 static expr_t
*make_exprs
(enum expr_type type
, char *val
)
783 e
= xmalloc
(sizeof
(expr_t
));
789 /* check for predefined constants */
790 if
(type
== EXPR_IDENTIFIER
) {
791 var_t
*c
= find_const
(val
, 0);
802 static expr_t
*make_exprt
(enum expr_type type
, typeref_t
*tref
, expr_t
*expr
)
805 e
= xmalloc
(sizeof
(expr_t
));
811 /* check for cast of constant expression */
812 if
(type
== EXPR_CAST
&& expr
->is_const
) {
814 e
->cval
= expr
->cval
;
819 static expr_t
*make_expr1
(enum expr_type type
, expr_t
*expr
)
822 e
= xmalloc
(sizeof
(expr_t
));
828 /* check for compile-time optimization */
829 if
(expr
->is_const
) {
833 e
->cval
= -expr
->cval
;
836 e
->cval
= ~expr
->cval
;
846 static expr_t
*make_expr2
(enum expr_type type
, expr_t
*expr1
, expr_t
*expr2
)
849 e
= xmalloc
(sizeof
(expr_t
));
855 /* check for compile-time optimization */
856 if
(expr1
->is_const
&& expr2
->is_const
) {
860 e
->cval
= expr1
->cval
+ expr2
->cval
;
863 e
->cval
= expr1
->cval
- expr2
->cval
;
866 e
->cval
= expr1
->cval
* expr2
->cval
;
869 e
->cval
= expr1
->cval
/ expr2
->cval
;
872 e
->cval
= expr1
->cval | expr2
->cval
;
875 e
->cval
= expr1
->cval
& expr2
->cval
;
878 e
->cval
= expr1
->cval
<< expr2
->cval
;
881 e
->cval
= expr1
->cval
>> expr2
->cval
;
891 static expr_t
*make_expr3
(enum expr_type type
, expr_t
*expr1
, expr_t
*expr2
, expr_t
*expr3
)
894 e
= xmalloc
(sizeof
(expr_t
));
901 /* check for compile-time optimization */
902 if
(expr1
->is_const
&& expr2
->is_const
&& expr3
->is_const
) {
906 e
->cval
= expr1
->cval ? expr2
->cval
: expr3
->cval
;
916 static type_t
*make_type
(BYTE type
, type_t
*ref
)
918 type_t
*t
= xmalloc
(sizeof
(type_t
));
926 t
->ignore
= parse_only
;
935 static typeref_t
*make_tref
(char *name
, type_t
*ref
)
937 typeref_t
*t
= xmalloc
(sizeof
(typeref_t
));
940 t
->uniq
= ref ?
0 : 1;
944 static typeref_t
*uniq_tref
(typeref_t
*ref
)
948 if
(t
->uniq
) return t
;
949 tp
= make_type
(0, t
->ref
);
957 static type_t
*type_ref
(typeref_t
*ref
)
959 type_t
*t
= ref
->ref
;
960 if
(ref
->name
) free
(ref
->name
);
965 static void set_type
(var_t
*v
, typeref_t
*ref
, expr_t
*arr
)
968 v
->tname
= ref
->name
;
974 static ifref_t
*make_ifref
(type_t
*iface
)
976 ifref_t
*l
= xmalloc
(sizeof
(ifref_t
));
983 static var_t
*make_var
(char *name
)
985 var_t
*v
= xmalloc
(sizeof
(var_t
));
998 static func_t
*make_func
(var_t
*def
, var_t
*args
)
1000 func_t
*f
= xmalloc
(sizeof
(func_t
));
1003 f
->ignore
= parse_only
;
1009 static class_t
*make_class
(char *name
)
1011 class_t
*c
= xmalloc
(sizeof
(class_t
));
1021 static int hash_ident
(const char *name
)
1023 const char *p
= name
;
1025 /* a simple sum hash is probably good enough */
1030 return sum
& (HASHMAX
-1);
1033 /***** type repository *****/
1042 struct rtype
*type_hash
[HASHMAX
];
1044 static type_t
*reg_type
(type_t
*type
, char *name
, int t
)
1049 yyerror("registering named type without name\n");
1052 hash
= hash_ident
(name
);
1053 nt
= xmalloc
(sizeof
(struct rtype
));
1057 nt
->next
= type_hash
[hash
];
1058 type_hash
[hash
] = nt
;
1062 static type_t
*reg_types
(type_t
*type
, var_t
*names
, int t
)
1068 var_t
*next
= NEXT_LINK
(names
);
1071 int cptr
= names
->ptr_level
;
1073 while
(cptr
> ptrc
) {
1074 cur
= ptr
= make_type
(RPC_FC_FP
, cur
); /* FIXME: pointer type from attrs? */
1078 while
(cptr
< ptrc
) {
1083 reg_type
(cur
, names
->name
, t
);
1091 static type_t
*find_type
(char *name
, int t
)
1093 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
1094 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
1097 yyerror("type %s not found\n", name
);
1103 static type_t
*find_type2
(char *name
, int t
)
1105 type_t
*tp
= find_type
(name
, t
);
1110 int is_type
(const char *name
)
1112 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
1113 while
(cur
&& (cur
->t || strcmp
(cur
->name
, name
)))
1115 if
(cur
) return TRUE
;
1119 static type_t
*get_type
(BYTE type
, char *name
, int t
)
1121 struct rtype
*cur
= NULL
;
1124 cur
= type_hash
[hash_ident
(name
)];
1125 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
1132 tp
= make_type
(type
, NULL
);
1134 if
(!name
) return tp
;
1135 return reg_type
(tp
, name
, t
);
1138 static type_t
*get_typev
(BYTE type
, var_t
*name
, int t
)
1145 return get_type
(type
, sname
, t
);
1148 /***** constant repository *****/
1153 struct rconst
*next
;
1156 struct rconst
*const_hash
[HASHMAX
];
1158 static var_t
*reg_const
(var_t
*var
)
1163 yyerror("registering constant without name\n");
1166 hash
= hash_ident
(var
->name
);
1167 nc
= xmalloc
(sizeof
(struct rconst
));
1168 nc
->name
= var
->name
;
1170 nc
->next
= const_hash
[hash
];
1171 const_hash
[hash
] = nc
;
1175 static var_t
*find_const
(char *name
, int f
)
1177 struct rconst
*cur
= const_hash
[hash_ident
(name
)];
1178 while
(cur
&& strcmp
(cur
->name
, name
))
1181 if
(f
) yyerror("constant %s not found\n", name
);