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
43 /* Berkeley yacc (byacc) doesn't seem to know about these */
44 /* Some *BSD supplied versions do define these though */
46 # define YYEMPTY (-1) /* Empty lookahead value of yychar */
49 # define YYLEX yylex()
52 #elif defined(YYBISON)
53 /* Bison was used for original development */
54 /* #define YYEMPTY -2 */
55 /* #define YYLEX yylex() */
58 /* No yacc we know yet */
59 # if !defined(YYEMPTY) || !defined(YYLEX)
60 # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
61 # elif defined(__GNUC__) /* gcc defines the #warning directive */
62 # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
63 /* #else we just take a chance that it works... */
67 static attr_t
*make_attr
(enum attr_type type
);
68 static attr_t
*make_attrv
(enum attr_type type
, unsigned long val
);
69 static attr_t
*make_attrp
(enum attr_type type
, void *val
);
70 static expr_t
*make_expr
(enum expr_type type
);
71 static expr_t
*make_exprl
(enum expr_type type
, long val
);
72 static expr_t
*make_exprs
(enum expr_type type
, char *val
);
73 static expr_t
*make_exprt
(enum expr_type type
, typeref_t
*tref
, expr_t
*expr
);
74 static expr_t
*make_expr1
(enum expr_type type
, expr_t
*expr
);
75 static expr_t
*make_expr2
(enum expr_type type
, expr_t
*exp1
, expr_t
*exp2
);
76 static expr_t
*make_expr3
(enum expr_type type
, expr_t
*expr1
, expr_t
*expr2
, expr_t
*expr3
);
77 static type_t
*make_type
(unsigned char type
, type_t
*ref
);
78 static typeref_t
*make_tref
(char *name
, type_t
*ref
);
79 static typeref_t
*uniq_tref
(typeref_t
*ref
);
80 static type_t
*type_ref
(typeref_t
*ref
);
81 static void set_type
(var_t
*v
, typeref_t
*ref
, expr_t
*arr
);
82 static ifref_t
*make_ifref
(type_t
*iface
);
83 static var_t
*make_var
(char *name
);
84 static func_t
*make_func
(var_t
*def
, var_t
*args
);
85 static class_t
*make_class
(char *name
);
87 static type_t
*reg_type
(type_t
*type
, char *name
, int t
);
88 static type_t
*reg_types
(type_t
*type
, var_t
*names
, int t
);
89 static type_t
*find_type
(const char *name
, int t
);
90 static type_t
*find_type2
(char *name
, int t
);
91 static type_t
*get_type
(unsigned char type
, char *name
, int t
);
92 static type_t
*get_typev
(unsigned char type
, var_t
*name
, int t
);
93 static int get_struct_type
(var_t
*fields
);
95 static var_t
*reg_const
(var_t
*var
);
96 static var_t
*find_const
(char *name
, int f
);
102 static type_t std_bool
= { "boolean" };
103 static type_t std_int
= { "int" };
104 static type_t std_int64
= { "__int64" };
105 static type_t std_uhyper
= { "MIDL_uhyper" };
122 %token
<str
> aIDENTIFIER
123 %token
<str
> aKNOWNTYPE
124 %token
<num
> aNUM aHEXNUM
129 %token tAGGREGATABLE tALLOCATE tAPPOBJECT tARRAYS tASYNC tASYNCUUID
130 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
131 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
132 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
133 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
137 %token tDISPINTERFACE
138 %token tDLLNAME tDOUBLE tDUAL
140 %token tENTRY tENUM tERRORSTATUST
141 %token tEXPLICITHANDLE tEXTERN
145 %token tHELPCONTEXT tHELPFILE
146 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
148 %token tHYPER tID tIDEMPOTENT
150 %token tIMPLICITHANDLE
151 %token tIMPORT tIMPORTLIB
152 %token tIN tINCLUDE tINLINE
156 %token tLENGTHIS tLIBRARY
162 %token tOBJECT tODL tOLEAUTOMATION
165 %token tPOINTERDEFAULT
167 %token tPROPGET tPROPPUT tPROPPUTREF
171 %token tREADONLY tREF
177 %token tSIZEIS tSIZEOF
181 %token tSTRING tSTRUCT
182 %token tSWITCH tSWITCHIS tSWITCHTYPE
193 %token tWCHAR tWIREMARSHAL
198 %type
<attr
> m_attributes attributes attrib_list attribute
199 %type
<expr
> m_exprs
/* exprs expr_list */ m_expr expr expr_list_const expr_const
200 %type
<expr
> array array_list
201 %type
<type
> inherit interface interfacehdr interfacedef interfacedec
202 %type
<type
> dispinterface dispinterfacehdr dispinterfacedef
203 %type
<type
> module modulehdr moduledef
204 %type
<type
> base_type int_std
205 %type
<type
> enumdef structdef typedef uniondef
206 %type
<ifref
> gbl_statements coclass_ints coclass_int
208 %type
<var
> m_args no_args args arg
209 %type
<var
> fields field s_field cases case enums enum_list
enum constdef externdef
210 %type
<var
> m_ident t_ident ident p_ident pident pident_list
211 %type
<var
> dispint_props
212 %type
<func
> funcdef int_statements
213 %type
<func
> dispint_meths
214 %type
<clas
> coclass coclasshdr coclassdef
215 %type
<num
> pointer_type version
216 %type
<str
> libraryhdr
232 input: gbl_statements
{ write_proxies
($1); write_client
($1); write_server
($1); }
235 gbl_statements: { $$
= NULL
; }
236 | gbl_statements interfacedec
{ $$
= $1; }
237 | gbl_statements interfacedef
{ $$
= make_ifref
($2); LINK
($$
, $1); }
238 | gbl_statements coclassdef
{ $$
= $1; add_coclass
($2); }
239 | gbl_statements moduledef
{ $$
= $1; add_module
($2); }
240 | gbl_statements librarydef
{ $$
= $1; }
241 | gbl_statements statement
{ $$
= $1; }
245 | imp_statements interfacedec
{ if
(!parse_only
) add_interface
($2); }
246 | imp_statements interfacedef
{ if
(!parse_only
) add_interface
($2); }
247 | imp_statements coclassdef
{ if
(!parse_only
) add_coclass
($2); }
248 | imp_statements moduledef
{ if
(!parse_only
) add_module
($2); }
249 | imp_statements statement
{}
252 int_statements: { $$
= NULL
; }
253 | int_statements funcdef
';' { $$
= $2; LINK
($$
, $1); }
254 | int_statements statement
{ $$
= $1; }
258 | constdef
';' { if
(!parse_only
&& do_header
) { write_constdef
($1); } }
260 | enumdef
';' { if
(!parse_only
&& do_header
) { write_type
(header
, $1, NULL
, NULL
); fprintf
(header
, ";\n\n"); } }
261 | externdef
';' { if
(!parse_only
&& do_header
) { write_externdef
($1); } }
263 | structdef
';' { if
(!parse_only
&& do_header
) { write_type
(header
, $1, NULL
, NULL
); fprintf
(header
, ";\n\n"); } }
265 | uniondef
';' { if
(!parse_only
&& do_header
) { write_type
(header
, $1, NULL
, NULL
); fprintf
(header
, ";\n\n"); } }
268 cppquote: tCPPQUOTE
'(' aSTRING
')' { if
(!parse_only
&& do_header
) fprintf
(header
, "%s\n", $3); }
270 import_start: tIMPORT aSTRING
';' { assert
(yychar == YYEMPTY
);
271 if
(!do_import
($2)) yychar = aEOF
; }
273 import: import_start imp_statements aEOF
{}
276 libraryhdr: tLIBRARY aIDENTIFIER
{ $$
= $2; }
278 library_start: attributes libraryhdr
'{' { start_typelib
($2, $1);
279 if
(!parse_only
&& do_header
) write_library
($2, $1); }
281 librarydef: library_start imp_statements
'}' { end_typelib
(); }
284 m_args: { $$
= NULL
; }
288 no_args: tVOID
{ $$
= NULL
; }
292 | args
',' arg
{ LINK
($3, $1); $$
= $3; }
296 /* split into two rules to get bison to resolve a tVOID conflict */
297 arg: attributes type pident array
{ $$
= $3;
298 set_type
($$
, $2, $4);
301 | type pident array
{ $$
= $2;
302 set_type
($$
, $1, $3);
304 | attributes type pident
'(' m_args
')' { $$
= $3;
306 set_type
($$
, $2, NULL
);
310 | type pident
'(' m_args
')' { $$
= $2;
312 set_type
($$
, $1, NULL
);
317 array: { $$
= NULL
; }
318 |
'[' array_list
']' { $$
= $2; }
319 |
'[' '*' ']' { $$
= make_expr
(EXPR_VOID
); }
322 array_list: m_expr
/* size of first dimension is optional */
323 | array_list
',' expr
{ LINK
($3, $1); $$
= $3; }
324 | array_list
']' '[' expr
{ LINK
($4, $1); $$
= $4; }
327 m_attributes: { $$
= NULL
; }
332 '[' attrib_list
']' { $$
= $2; }
335 attrib_list: attribute
336 | attrib_list
',' attribute
{ LINK
($3, $1); $$
= $3; }
337 | attrib_list
']' '[' attribute
{ LINK
($4, $1); $$
= $4; }
341 tASYNC
{ $$
= make_attr
(ATTR_ASYNC
); }
342 | tAUTOHANDLE
{ $$
= make_attr
(ATTR_AUTO_HANDLE
); }
343 | tBINDABLE
{ $$
= make_attr
(ATTR_BINDABLE
); }
344 | tCALLAS
'(' ident
')' { $$
= make_attrp
(ATTR_CALLAS
, $3); }
345 | tCASE
'(' expr_list_const
')' { $$
= make_attrp
(ATTR_CASE
, $3); }
346 | tCONTEXTHANDLE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); }
347 | tCONTEXTHANDLENOSERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
348 | tCONTEXTHANDLESERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
349 | tCONTROL
{ $$
= make_attr
(ATTR_CONTROL
); }
350 | tDEFAULT
{ $$
= make_attr
(ATTR_DEFAULT
); }
351 | tDEFAULTVALUE
'(' expr_const
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE_EXPR
, $3); }
352 | tDEFAULTVALUE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE_STRING
, $3); }
353 | tDISPLAYBIND
{ $$
= make_attr
(ATTR_DISPLAYBIND
); }
354 | tDLLNAME
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DLLNAME
, $3); }
355 | tDUAL
{ $$
= make_attr
(ATTR_DUAL
); }
356 | tENDPOINT
'(' aSTRING
')' { $$
= make_attrp
(ATTR_ENDPOINT
, $3); }
357 | tENTRY
'(' aSTRING
')' { $$
= make_attrp
(ATTR_ENTRY_STRING
, $3); }
358 | tENTRY
'(' expr_const
')' { $$
= make_attrp
(ATTR_ENTRY_ORDINAL
, $3); }
359 | tEXPLICITHANDLE
{ $$
= make_attr
(ATTR_EXPLICIT_HANDLE
); }
360 | tHANDLE
{ $$
= make_attr
(ATTR_HANDLE
); }
361 | tHELPCONTEXT
'(' expr_const
')' { $$
= make_attrp
(ATTR_HELPCONTEXT
, $3); }
362 | tHELPFILE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPFILE
, $3); }
363 | tHELPSTRING
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRING
, $3); }
364 | tHELPSTRINGCONTEXT
'(' expr_const
')' { $$
= make_attrp
(ATTR_HELPSTRINGCONTEXT
, $3); }
365 | tHELPSTRINGDLL
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRINGDLL
, $3); }
366 | tHIDDEN
{ $$
= make_attr
(ATTR_HIDDEN
); }
367 | tID
'(' expr_const
')' { $$
= make_attrp
(ATTR_ID
, $3); }
368 | tIDEMPOTENT
{ $$
= make_attr
(ATTR_IDEMPOTENT
); }
369 | tIIDIS
'(' ident
')' { $$
= make_attrp
(ATTR_IIDIS
, $3); }
370 | tIMPLICITHANDLE
'(' tHANDLET aIDENTIFIER
')' { $$
= make_attrp
(ATTR_IMPLICIT_HANDLE
, $4); }
371 | tIN
{ $$
= make_attr
(ATTR_IN
); }
372 | tINPUTSYNC
{ $$
= make_attr
(ATTR_INPUTSYNC
); }
373 | tLENGTHIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_LENGTHIS
, $3); }
374 | tLOCAL
{ $$
= make_attr
(ATTR_LOCAL
); }
375 | tNONCREATABLE
{ $$
= make_attr
(ATTR_NONCREATABLE
); }
376 | tOBJECT
{ $$
= make_attr
(ATTR_OBJECT
); }
377 | tODL
{ $$
= make_attr
(ATTR_ODL
); }
378 | tOLEAUTOMATION
{ $$
= make_attr
(ATTR_OLEAUTOMATION
); }
379 | tOPTIONAL
{ $$
= make_attr
(ATTR_OPTIONAL
); }
380 | tOUT
{ $$
= make_attr
(ATTR_OUT
); }
381 | tPOINTERDEFAULT
'(' pointer_type
')' { $$
= make_attrv
(ATTR_POINTERDEFAULT
, $3); }
382 | tPROPGET
{ $$
= make_attr
(ATTR_PROPGET
); }
383 | tPROPPUT
{ $$
= make_attr
(ATTR_PROPPUT
); }
384 | tPROPPUTREF
{ $$
= make_attr
(ATTR_PROPPUTREF
); }
385 | tPUBLIC
{ $$
= make_attr
(ATTR_PUBLIC
); }
386 | tRANGE
'(' expr_const
',' expr_const
')' { LINK
($5, $3); $$
= make_attrp
(ATTR_RANGE
, $5); }
387 | tREADONLY
{ $$
= make_attr
(ATTR_READONLY
); }
388 | tRESTRICTED
{ $$
= make_attr
(ATTR_RESTRICTED
); }
389 | tRETVAL
{ $$
= make_attr
(ATTR_RETVAL
); }
390 | tSIZEIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_SIZEIS
, $3); }
391 | tSOURCE
{ $$
= make_attr
(ATTR_SOURCE
); }
392 | tSTRING
{ $$
= make_attr
(ATTR_STRING
); }
393 | tSWITCHIS
'(' expr
')' { $$
= make_attrp
(ATTR_SWITCHIS
, $3); }
394 | tSWITCHTYPE
'(' type
')' { $$
= make_attrp
(ATTR_SWITCHTYPE
, type_ref
($3)); }
395 | tTRANSMITAS
'(' type
')' { $$
= make_attrp
(ATTR_TRANSMITAS
, type_ref
($3)); }
396 | tUUID
'(' aUUID
')' { $$
= make_attrp
(ATTR_UUID
, $3); }
397 | tV1ENUM
{ $$
= make_attr
(ATTR_V1ENUM
); }
398 | tVARARG
{ $$
= make_attr
(ATTR_VARARG
); }
399 | tVERSION
'(' version
')' { $$
= make_attrv
(ATTR_VERSION
, $3); }
400 | tWIREMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_WIREMARSHAL
, type_ref
($3)); }
401 | pointer_type
{ $$
= make_attrv
(ATTR_POINTERTYPE
, $1); }
408 cases: { $$
= NULL
; }
409 | cases case
{ if
($2) { LINK
($2, $1); $$
= $2; }
414 case: tCASE expr
':' field
{ attr_t
*a
= make_attrp
(ATTR_CASE
, $2);
415 $$
= $4; if
(!$$
) $$
= make_var
(NULL
);
416 LINK
(a
, $$
->attrs
); $$
->attrs
= a
;
418 | tDEFAULT
':' field
{ attr_t
*a
= make_attr
(ATTR_DEFAULT
);
419 $$
= $3; if
(!$$
) $$
= make_var
(NULL
);
420 LINK
(a
, $$
->attrs
); $$
->attrs
= a
;
424 constdef: tCONST type ident
'=' expr_const
{ $$
= reg_const
($3);
425 set_type
($$
, $2, NULL
);
431 enums: { $$
= NULL
; }
432 | enum_list
',' { $$
= $1; }
437 | enum_list
',' enum { LINK
($3, $1); $$
= $3;
439 $3->lval
= $1->lval
+ 1;
443 enum: ident
'=' expr_const
{ $$
= reg_const
($1);
446 $$
->type
= make_type
(RPC_FC_LONG
, &std_int
);
448 | ident
{ $$
= reg_const
($1);
449 $$
->lval
= 0; /* default for first enum entry */
450 $$
->type
= make_type
(RPC_FC_LONG
, &std_int
);
454 enumdef: tENUM t_ident
'{' enums
'}' { $$
= get_typev
(RPC_FC_ENUM16
, $2, tsENUM
);
463 | m_exprs
',' m_expr
{ LINK
($3, $1); $$
= $3; }
467 exprs: { $$ = make_expr(EXPR_VOID); }
472 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
476 m_expr: { $$
= make_expr
(EXPR_VOID
); }
480 expr: aNUM
{ $$
= make_exprl
(EXPR_NUM
, $1); }
481 | aHEXNUM
{ $$
= make_exprl
(EXPR_HEXNUM
, $1); }
482 | aIDENTIFIER
{ $$
= make_exprs
(EXPR_IDENTIFIER
, $1); }
483 | expr
'?' expr
':' expr
{ $$
= make_expr3
(EXPR_COND
, $1, $3, $5); }
484 | expr
'|' expr
{ $$
= make_expr2
(EXPR_OR
, $1, $3); }
485 | expr
'&' expr
{ $$
= make_expr2
(EXPR_AND
, $1, $3); }
486 | expr
'+' expr
{ $$
= make_expr2
(EXPR_ADD
, $1, $3); }
487 | expr
'-' expr
{ $$
= make_expr2
(EXPR_SUB
, $1, $3); }
488 | expr
'*' expr
{ $$
= make_expr2
(EXPR_MUL
, $1, $3); }
489 | expr
'/' expr
{ $$
= make_expr2
(EXPR_DIV
, $1, $3); }
490 | expr SHL expr
{ $$
= make_expr2
(EXPR_SHL
, $1, $3); }
491 | expr SHR expr
{ $$
= make_expr2
(EXPR_SHR
, $1, $3); }
492 |
'~' expr
{ $$
= make_expr1
(EXPR_NOT
, $2); }
493 |
'-' expr %prec NEG
{ $$
= make_expr1
(EXPR_NEG
, $2); }
494 |
'*' expr %prec PPTR
{ $$
= make_expr1
(EXPR_PPTR
, $2); }
495 |
'(' type
')' expr %prec CAST
{ $$
= make_exprt
(EXPR_CAST
, $2, $4); }
496 | tSIZEOF
'(' type
')' { $$
= make_exprt
(EXPR_SIZEOF
, $3, NULL
); }
497 |
'(' expr
')' { $$
= $2; }
500 expr_list_const: expr_const
501 | expr_list_const
',' expr_const
{ LINK
($3, $1); $$
= $3; }
504 expr_const: expr
{ $$
= $1;
506 yyerror("expression is not constant\n");
510 externdef: tEXTERN tCONST type ident
{ $$
= $4;
511 set_type
($$
, $3, NULL
);
515 fields: { $$
= NULL
; }
516 | fields field
{ if
($2) { LINK
($2, $1); $$
= $2; }
521 field: s_field
';' { $$
= $1; }
522 | m_attributes uniondef
';' { $$
= make_var
(NULL
); $$
->type
= $2; $$
->attrs
= $1; }
523 | attributes
';' { $$
= make_var
(NULL
); $$
->attrs
= $1; }
527 s_field: m_attributes type pident array
{ $$
= $3; set_type
($$
, $2, $4); $$
->attrs
= $1; }
531 m_attributes type callconv pident
532 '(' m_args
')' { set_type
($4, $2, NULL
);
534 $$
= make_func
($4, $6);
535 if
(is_attr
($4->attrs
, ATTR_IN
)) {
536 yyerror("Inapplicable attribute");
541 m_ident: { $$
= NULL
; }
545 t_ident: { $$
= NULL
; }
546 | aIDENTIFIER
{ $$
= make_var
($1); }
547 | aKNOWNTYPE
{ $$
= make_var
($1); }
550 ident: aIDENTIFIER
{ $$
= make_var
($1); }
551 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
552 | aKNOWNTYPE
{ $$
= make_var
($
<str
>1); }
553 | tASYNC
{ $$
= make_var
($
<str
>1); }
554 | tID
{ $$
= make_var
($
<str
>1); }
555 | tRANGE
{ $$
= make_var
($
<str
>1); }
556 | tRETVAL
{ $$
= make_var
($
<str
>1); }
557 | tVERSION
{ $$
= make_var
($
<str
>1); }
560 base_type: tBYTE
{ $$
= make_type
(RPC_FC_BYTE
, NULL
); }
561 | tWCHAR
{ $$
= make_type
(RPC_FC_WCHAR
, NULL
); }
563 | tSIGNED int_std
{ $$
= $2; $$
->sign
= 1; }
564 | tUNSIGNED int_std
{ $$
= $2; $$
->sign
= -1;
566 case RPC_FC_CHAR
: $$
->type
= RPC_FC_BYTE
; $$
->sign
= 0; break
;
567 case RPC_FC_SMALL
: $$
->type
= RPC_FC_USMALL
; break
;
568 case RPC_FC_SHORT
: $$
->type
= RPC_FC_USHORT
; break
;
569 case RPC_FC_LONG
: $$
->type
= RPC_FC_ULONG
; break
;
571 if
(!$$
->ref
) { $$
->ref
= &std_uhyper
; $$
->sign
= 0; }
576 | tUNSIGNED
{ $$
= make_type
(RPC_FC_ULONG
, &std_int
); $$
->sign
= -1; }
577 | tFLOAT
{ $$
= make_type
(RPC_FC_FLOAT
, NULL
); }
578 | tSINGLE
{ $$
= make_type
(RPC_FC_FLOAT
, NULL
); }
579 | tDOUBLE
{ $$
= make_type
(RPC_FC_DOUBLE
, NULL
); }
580 | tBOOLEAN
{ $$
= make_type
(RPC_FC_BYTE
, &std_bool
); /* ? */ }
581 | tERRORSTATUST
{ $$
= make_type
(RPC_FC_ERROR_STATUS_T
, NULL
); }
582 | tHANDLET
{ $$
= make_type
(RPC_FC_BIND_PRIMITIVE
, NULL
); /* ? */ }
589 int_std: tINT
{ $$
= make_type
(RPC_FC_LONG
, &std_int
); } /* win32 only */
590 | tSHORT m_int
{ $$
= make_type
(RPC_FC_SHORT
, NULL
); }
591 | tSMALL
{ $$
= make_type
(RPC_FC_SMALL
, NULL
); }
592 | tLONG m_int
{ $$
= make_type
(RPC_FC_LONG
, NULL
); }
593 | tHYPER m_int
{ $$
= make_type
(RPC_FC_HYPER
, NULL
); }
594 | tINT64
{ $$
= make_type
(RPC_FC_HYPER
, &std_int64
); }
595 | tCHAR
{ $$
= make_type
(RPC_FC_CHAR
, NULL
); }
598 coclass: tCOCLASS aIDENTIFIER
{ $$
= make_class
($2); }
599 | tCOCLASS aKNOWNTYPE
{ $$
= make_class
($2); }
602 coclasshdr: attributes coclass
{ $$
= $2;
604 if
(!parse_only
&& do_header
)
609 coclassdef: coclasshdr
'{' coclass_ints
'}' { $$
= $1;
614 coclass_ints: { $$
= NULL
; }
615 | coclass_ints coclass_int
{ LINK
($2, $1); $$
= $2; }
619 m_attributes interfacedec
{ $$
= make_ifref
($2); $$
->attrs
= $1; }
622 dispinterface: tDISPINTERFACE aIDENTIFIER
{ $$
= get_type
(0, $2, 0); }
623 | tDISPINTERFACE aKNOWNTYPE
{ $$
= get_type
(0, $2, 0); }
626 dispinterfacehdr: attributes dispinterface
{ $$
= $2;
627 if
($$
->defined
) yyerror("multiple definition error\n");
629 $$
->attrs
= make_attr
(ATTR_DISPINTERFACE
);
631 $$
->ref
= find_type
("IDispatch", 0);
632 if
(!$$
->ref
) yyerror("IDispatch is undefined\n");
634 if
(!parse_only
&& do_header
) write_forward
($$
);
638 dispint_props: tPROPERTIES
':' { $$
= NULL
; }
639 | dispint_props s_field
';' { LINK
($2, $1); $$
= $2; }
642 dispint_meths: tMETHODS
':' { $$
= NULL
; }
643 | dispint_meths funcdef
';' { LINK
($2, $1); $$
= $2; }
646 dispinterfacedef: dispinterfacehdr
'{'
652 if
(!parse_only
&& do_header
) write_dispinterface
($$
);
654 /* FIXME: not sure how to handle this yet
655 | dispinterfacehdr '{' interface '}' { $$ = $1;
656 if (!parse_only && do_header) write_interface($$);
661 inherit: { $$
= NULL
; }
662 |
':' aKNOWNTYPE
{ $$
= find_type2
($2, 0); }
665 interface: tINTERFACE aIDENTIFIER
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
666 | tINTERFACE aKNOWNTYPE
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
669 interfacehdr: attributes interface
{ $$
= $2;
670 if
($$
->defined
) yyerror("multiple definition error\n");
673 if
(!parse_only
&& do_header
) write_forward
($$
);
677 interfacedef: interfacehdr inherit
678 '{' int_statements
'}' { $$
= $1;
681 if
(!parse_only
&& do_header
) write_interface
($$
);
683 /* MIDL is able to import the definition of a base class from inside the
684 * definition of a derived class, I'll try to support it with this rule */
685 | interfacehdr
':' aIDENTIFIER
686 '{' import int_statements
'}' { $$
= $1;
687 $$
->ref
= find_type2
($3, 0);
688 if
(!$$
->ref
) yyerror("base class %s not found in import\n", $3);
690 if
(!parse_only
&& do_header
) write_interface
($$
);
692 | dispinterfacedef
{ $$
= $1; }
696 interface
';' { $$
= $1; if
(!parse_only
&& do_header
) write_forward
($$
); }
697 | dispinterface
';' { $$
= $1; if
(!parse_only
&& do_header
) write_forward
($$
); }
700 module: tMODULE aIDENTIFIER
{ $$
= make_type
(0, NULL
); $$
->name
= $2; }
701 | tMODULE aKNOWNTYPE
{ $$
= make_type
(0, NULL
); $$
->name
= $2; }
704 modulehdr: attributes module
{ $$
= $2;
709 moduledef: modulehdr
'{' int_statements
'}' { $$
= $1;
711 /* FIXME: if (!parse_only && do_header) write_module($$); */
715 p_ident: '*' pident %prec PPTR
{ $$
= $2; $$
->ptr_level
++; }
716 | tCONST p_ident
{ $$
= $2; /* FIXME */ }
721 |
'(' pident
')' { $$
= $2; }
726 | pident_list
',' pident
{ LINK
($3, $1); $$
= $3; }
730 tREF
{ $$
= RPC_FC_RP
; }
731 | tUNIQUE
{ $$
= RPC_FC_UP
; }
732 | tPTR
{ $$
= RPC_FC_FP
; }
735 structdef: tSTRUCT t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_STRUCT
, $2, tsSTRUCT
);
736 /* overwrite RPC_FC_STRUCT with a more exact type */
737 $$
->type
= get_struct_type
( $4 );
745 type: tVOID
{ $$
= make_tref
(NULL
, make_type
(0, NULL
)); }
746 | aKNOWNTYPE
{ $$
= make_tref
($1, find_type
($1, 0)); }
747 | base_type
{ $$
= make_tref
(NULL
, $1); }
748 | tCONST type
{ $$
= uniq_tref
($2); $$
->ref
->is_const
= TRUE
; }
749 | enumdef
{ $$
= make_tref
(NULL
, $1); }
750 | tENUM aIDENTIFIER
{ $$
= make_tref
(NULL
, find_type2
($2, tsENUM
)); }
751 | structdef
{ $$
= make_tref
(NULL
, $1); }
752 | tSTRUCT aIDENTIFIER
{ $$
= make_tref
(NULL
, get_type
(RPC_FC_STRUCT
, $2, tsSTRUCT
)); }
753 | uniondef
{ $$
= make_tref
(NULL
, $1); }
754 | tUNION aIDENTIFIER
{ $$
= make_tref
(NULL
, find_type2
($2, tsUNION
)); }
757 typedef: tTYPEDEF m_attributes type pident_list
{ typeref_t
*tref
= uniq_tref
($3);
758 $4->tname
= tref
->name
;
762 if
(!parse_only
&& do_header
)
763 write_typedef
($$
, $4);
764 if
(in_typelib
&& $$
->attrs
)
766 reg_types
($$
, $4, 0);
770 uniondef: tUNION t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_NON_ENCAPSULATED_UNION
, $2, tsUNION
);
775 tSWITCH
'(' s_field
')'
776 m_ident
'{' cases
'}' { var_t
*u
= $7;
777 $$
= get_typev
(RPC_FC_ENCAPSULATED_UNION
, $2, tsUNION
);
778 if
(!u
) u
= make_var
("tagged_union");
779 u
->type
= make_type
(RPC_FC_NON_ENCAPSULATED_UNION
, NULL
);
780 u
->type
->fields
= $9;
781 u
->type
->defined
= TRUE
;
782 LINK
(u
, $5); $$
->fields
= u
;
788 aNUM
{ $$
= MAKELONG
($1, 0); }
789 | aNUM
'.' aNUM
{ $$
= MAKELONG
($1, $3); }
794 static attr_t
*make_attr
(enum attr_type type
)
796 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
803 static attr_t
*make_attrv
(enum attr_type type
, unsigned long val
)
805 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
812 static attr_t
*make_attrp
(enum attr_type type
, void *val
)
814 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
821 static expr_t
*make_expr
(enum expr_type type
)
823 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
832 static expr_t
*make_exprl
(enum expr_type type
, long val
)
834 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
840 /* check for numeric constant */
841 if
(type
== EXPR_NUM || type
== EXPR_HEXNUM
) {
848 static expr_t
*make_exprs
(enum expr_type type
, char *val
)
851 e
= xmalloc
(sizeof
(expr_t
));
857 /* check for predefined constants */
858 if
(type
== EXPR_IDENTIFIER
) {
859 var_t
*c
= find_const
(val
, 0);
870 static expr_t
*make_exprt
(enum expr_type type
, typeref_t
*tref
, expr_t
*expr
)
873 e
= xmalloc
(sizeof
(expr_t
));
879 /* check for cast of constant expression */
880 if
(type
== EXPR_CAST
&& expr
->is_const
) {
882 e
->cval
= expr
->cval
;
887 static expr_t
*make_expr1
(enum expr_type type
, expr_t
*expr
)
890 e
= xmalloc
(sizeof
(expr_t
));
896 /* check for compile-time optimization */
897 if
(expr
->is_const
) {
901 e
->cval
= -expr
->cval
;
904 e
->cval
= ~expr
->cval
;
914 static expr_t
*make_expr2
(enum expr_type type
, expr_t
*expr1
, expr_t
*expr2
)
917 e
= xmalloc
(sizeof
(expr_t
));
923 /* check for compile-time optimization */
924 if
(expr1
->is_const
&& expr2
->is_const
) {
928 e
->cval
= expr1
->cval
+ expr2
->cval
;
931 e
->cval
= expr1
->cval
- expr2
->cval
;
934 e
->cval
= expr1
->cval
* expr2
->cval
;
937 e
->cval
= expr1
->cval
/ expr2
->cval
;
940 e
->cval
= expr1
->cval | expr2
->cval
;
943 e
->cval
= expr1
->cval
& expr2
->cval
;
946 e
->cval
= expr1
->cval
<< expr2
->cval
;
949 e
->cval
= expr1
->cval
>> expr2
->cval
;
959 static expr_t
*make_expr3
(enum expr_type type
, expr_t
*expr1
, expr_t
*expr2
, expr_t
*expr3
)
962 e
= xmalloc
(sizeof
(expr_t
));
969 /* check for compile-time optimization */
970 if
(expr1
->is_const
&& expr2
->is_const
&& expr3
->is_const
) {
974 e
->cval
= expr1
->cval ? expr2
->cval
: expr3
->cval
;
984 static type_t
*make_type
(unsigned char type
, type_t
*ref
)
986 type_t
*t
= xmalloc
(sizeof
(type_t
));
994 t
->ignore
= parse_only
;
1004 static typeref_t
*make_tref
(char *name
, type_t
*ref
)
1006 typeref_t
*t
= xmalloc
(sizeof
(typeref_t
));
1009 t
->uniq
= ref ?
0 : 1;
1013 static typeref_t
*uniq_tref
(typeref_t
*ref
)
1017 if
(t
->uniq
) return t
;
1018 tp
= make_type
(0, t
->ref
);
1026 static type_t
*type_ref
(typeref_t
*ref
)
1028 type_t
*t
= ref
->ref
;
1029 if
(ref
->name
) free
(ref
->name
);
1034 static void set_type
(var_t
*v
, typeref_t
*ref
, expr_t
*arr
)
1037 v
->tname
= ref
->name
;
1043 static ifref_t
*make_ifref
(type_t
*iface
)
1045 ifref_t
*l
= xmalloc
(sizeof
(ifref_t
));
1052 static var_t
*make_var
(char *name
)
1054 var_t
*v
= xmalloc
(sizeof
(var_t
));
1067 static func_t
*make_func
(var_t
*def
, var_t
*args
)
1069 func_t
*f
= xmalloc
(sizeof
(func_t
));
1072 f
->ignore
= parse_only
;
1078 static class_t
*make_class
(char *name
)
1080 class_t
*c
= xmalloc
(sizeof
(class_t
));
1090 static int hash_ident
(const char *name
)
1092 const char *p
= name
;
1094 /* a simple sum hash is probably good enough */
1099 return sum
& (HASHMAX
-1);
1102 /***** type repository *****/
1111 struct rtype
*type_hash
[HASHMAX
];
1113 static type_t
*reg_type
(type_t
*type
, char *name
, int t
)
1118 yyerror("registering named type without name\n");
1121 hash
= hash_ident
(name
);
1122 nt
= xmalloc
(sizeof
(struct rtype
));
1126 nt
->next
= type_hash
[hash
];
1127 type_hash
[hash
] = nt
;
1131 /* determine pointer type from attrs */
1132 static unsigned char get_pointer_type
( type_t
*type
)
1135 if
(is_attr
( type
->attrs
, ATTR_STRING
))
1138 while
( t
->type
== 0 && t
->ref
)
1143 return RPC_FC_C_CSTRING
;
1145 return RPC_FC_C_WSTRING
;
1148 t
= get_attrv
( type
->attrs
, ATTR_POINTERTYPE
);
1153 static type_t
*reg_types
(type_t
*type
, var_t
*names
, int t
)
1159 var_t
*next
= NEXT_LINK
(names
);
1162 int cptr
= names
->ptr_level
;
1164 while
(cptr
> ptrc
) {
1165 int t
= get_pointer_type
( cur
);
1166 cur
= ptr
= make_type
(t
, cur
);
1170 while
(cptr
< ptrc
) {
1175 reg_type
(cur
, names
->name
, t
);
1183 static type_t
*find_type
(const char *name
, int t
)
1185 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
1186 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
1189 yyerror("type %s not found\n", name
);
1195 static type_t
*find_type2
(char *name
, int t
)
1197 type_t
*tp
= find_type
(name
, t
);
1202 int is_type
(const char *name
)
1204 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
1205 while
(cur
&& (cur
->t || strcmp
(cur
->name
, name
)))
1207 if
(cur
) return TRUE
;
1211 static type_t
*get_type
(unsigned char type
, char *name
, int t
)
1213 struct rtype
*cur
= NULL
;
1216 cur
= type_hash
[hash_ident
(name
)];
1217 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
1224 tp
= make_type
(type
, NULL
);
1226 if
(!name
) return tp
;
1227 return reg_type
(tp
, name
, t
);
1230 static type_t
*get_typev
(unsigned char type
, var_t
*name
, int t
)
1237 return get_type
(type
, sname
, t
);
1240 static int get_struct_type
(var_t
*field
)
1242 int has_pointer
= 0;
1243 int has_conformant_array
= 0;
1244 int has_conformant_string
= 0;
1248 type_t
*t
= field
->type
;
1250 /* get the base type */
1251 while
( (t
->type
== 0) && t
->ref
)
1257 * RPC_FC_BYTE, RPC_FC_STRUCT, etc
1258 * Simple types don't effect the type of struct.
1259 * A struct containing a simple struct is still a simple struct.
1260 * So long as we can block copy the data, we return RPC_FC_STRUCT.
1262 case
0: /* void pointer */
1272 case RPC_FC_INT3264
:
1273 case RPC_FC_UINT3264
:
1287 has_conformant_array
= 1;
1289 case RPC_FC_C_CSTRING
:
1290 case RPC_FC_C_WSTRING
:
1291 has_conformant_string
= 1;
1295 * Propagate member attributes
1296 * a struct should be at least as complex as its member
1298 case RPC_FC_CVSTRUCT
:
1299 has_conformant_string
= 1;
1303 case RPC_FC_CPSTRUCT
:
1304 has_conformant_array
= 1;
1308 case RPC_FC_CSTRUCT
:
1309 has_conformant_array
= 1;
1312 case RPC_FC_PSTRUCT
:
1317 fprintf
(stderr
,"Unknown struct member %s with type (0x%02x)\n",
1318 field
->name
, t
->type
);
1319 /* fallthru - treat it as complex */
1321 /* as soon as we see one of these these members, it's bogus... */
1323 case RPC_FC_ENCAPSULATED_UNION
:
1324 case RPC_FC_NON_ENCAPSULATED_UNION
:
1325 case RPC_FC_TRANSMIT_AS
:
1326 case RPC_FC_REPRESENT_AS
:
1328 case RPC_FC_EMBEDDED_COMPLEX
:
1329 case RPC_FC_BOGUS_STRUCT
:
1330 return RPC_FC_BOGUS_STRUCT
;
1332 field
= NEXT_LINK
(field
);
1335 if
( has_conformant_string
&& has_pointer
)
1336 return RPC_FC_CVSTRUCT
;
1337 if
( has_conformant_array
&& has_pointer
)
1338 return RPC_FC_CPSTRUCT
;
1339 if
( has_conformant_array
)
1340 return RPC_FC_CSTRUCT
;
1342 return RPC_FC_PSTRUCT
;
1343 return RPC_FC_STRUCT
;
1346 /***** constant repository *****/
1351 struct rconst
*next
;
1354 struct rconst
*const_hash
[HASHMAX
];
1356 static var_t
*reg_const
(var_t
*var
)
1361 yyerror("registering constant without name\n");
1364 hash
= hash_ident
(var
->name
);
1365 nc
= xmalloc
(sizeof
(struct rconst
));
1366 nc
->name
= var
->name
;
1368 nc
->next
= const_hash
[hash
];
1369 const_hash
[hash
] = nc
;
1373 static var_t
*find_const
(char *name
, int f
)
1375 struct rconst
*cur
= const_hash
[hash_ident
(name
)];
1376 while
(cur
&& strcmp
(cur
->name
, name
))
1379 if
(f
) yyerror("constant %s not found\n", name
);