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
136 %token tDISPINTERFACE
137 %token tDLLNAME tDOUBLE tDUAL
139 %token tENTRY tENUM tERRORSTATUST
140 %token tEXPLICITHANDLE tEXTERN
144 %token tHELPCONTEXT tHELPFILE
145 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
147 %token tHYPER tID tIDEMPOTENT
149 %token tIMPLICITHANDLE
150 %token tIMPORT tIMPORTLIB
151 %token tIN tINCLUDE tINLINE
155 %token tLENGTHIS tLIBRARY
161 %token tOBJECT tODL tOLEAUTOMATION
164 %token tPOINTERDEFAULT
166 %token tPROPGET tPROPPUT tPROPPUTREF
170 %token tREADONLY tREF
176 %token tSIZEIS tSIZEOF
180 %token tSTRING tSTRUCT
181 %token tSWITCH tSWITCHIS tSWITCHTYPE
192 %token tWCHAR tWIREMARSHAL
197 %type
<attr
> m_attributes attributes attrib_list attribute
198 %type
<expr
> m_exprs
/* exprs expr_list */ m_expr expr expr_list_const expr_const
199 %type
<expr
> array array_list
200 %type
<type
> inherit interface interfacehdr interfacedef interfacedec
201 %type
<type
> dispinterface dispinterfacehdr dispinterfacedef
202 %type
<type
> module modulehdr moduledef
203 %type
<type
> base_type int_std
204 %type
<type
> enumdef structdef typedef uniondef
205 %type
<ifref
> gbl_statements coclass_ints coclass_int
207 %type
<var
> m_args no_args args arg
208 %type
<var
> fields field s_field cases case enums enum_list
enum constdef externdef
209 %type
<var
> m_ident t_ident ident p_ident pident pident_list
210 %type
<var
> dispint_props
211 %type
<func
> funcdef int_statements
212 %type
<func
> dispint_meths
213 %type
<clas
> coclass coclasshdr coclassdef
214 %type
<num
> pointer_type version
215 %type
<str
> libraryhdr
231 input: gbl_statements
{ write_proxies
($1); write_client
($1); write_server
($1); }
234 gbl_statements: { $$
= NULL
; }
235 | gbl_statements interfacedec
{ $$
= $1; }
236 | gbl_statements interfacedef
{ $$
= make_ifref
($2); LINK
($$
, $1); }
237 | gbl_statements coclassdef
{ $$
= $1; add_coclass
($2); }
238 | gbl_statements moduledef
{ $$
= $1; add_module
($2); }
239 | gbl_statements librarydef
{ $$
= $1; }
240 | gbl_statements statement
{ $$
= $1; }
244 | imp_statements interfacedec
{ if
(!parse_only
) add_interface
($2); }
245 | imp_statements interfacedef
{ if
(!parse_only
) add_interface
($2); }
246 | imp_statements coclassdef
{ if
(!parse_only
) add_coclass
($2); }
247 | imp_statements moduledef
{ if
(!parse_only
) add_module
($2); }
248 | imp_statements statement
{}
251 int_statements: { $$
= NULL
; }
252 | int_statements funcdef
';' { $$
= $2; LINK
($$
, $1); }
253 | int_statements statement
{ $$
= $1; }
257 | constdef
';' { if
(!parse_only
&& do_header
) { write_constdef
($1); } }
259 | enumdef
';' { if
(!parse_only
&& do_header
) { write_type
(header
, $1, NULL
, NULL
); fprintf
(header
, ";\n\n"); } }
260 | externdef
';' { if
(!parse_only
&& do_header
) { write_externdef
($1); } }
262 | structdef
';' { if
(!parse_only
&& do_header
) { write_type
(header
, $1, NULL
, NULL
); fprintf
(header
, ";\n\n"); } }
264 | uniondef
';' { if
(!parse_only
&& do_header
) { write_type
(header
, $1, NULL
, NULL
); fprintf
(header
, ";\n\n"); } }
267 cppquote: tCPPQUOTE
'(' aSTRING
')' { if
(!parse_only
&& do_header
) fprintf
(header
, "%s\n", $3); }
269 import_start: tIMPORT aSTRING
';' { assert
(yychar == YYEMPTY
);
270 if
(!do_import
($2)) yychar = aEOF
; }
272 import: import_start imp_statements aEOF
{}
275 libraryhdr: tLIBRARY aIDENTIFIER
{ $$
= $2; }
277 library_start: attributes libraryhdr
'{' { start_typelib
($2, $1);
278 if
(!parse_only
&& do_header
) write_library
($2, $1); }
280 librarydef: library_start imp_statements
'}' { end_typelib
(); }
283 m_args: { $$
= NULL
; }
287 no_args: tVOID
{ $$
= NULL
; }
291 | args
',' arg
{ LINK
($3, $1); $$
= $3; }
295 /* split into two rules to get bison to resolve a tVOID conflict */
296 arg: attributes type pident array
{ $$
= $3;
297 set_type
($$
, $2, $4);
300 | type pident array
{ $$
= $2;
301 set_type
($$
, $1, $3);
303 | attributes type pident
'(' m_args
')' { $$
= $3;
305 set_type
($$
, $2, NULL
);
309 | type pident
'(' m_args
')' { $$
= $2;
311 set_type
($$
, $1, NULL
);
316 array: { $$
= NULL
; }
317 |
'[' array_list
']' { $$
= $2; }
318 |
'[' '*' ']' { $$
= make_expr
(EXPR_VOID
); }
321 array_list: m_expr
/* size of first dimension is optional */
322 | array_list
',' expr
{ LINK
($3, $1); $$
= $3; }
323 | array_list
']' '[' expr
{ LINK
($4, $1); $$
= $4; }
326 m_attributes: { $$
= NULL
; }
331 '[' attrib_list
']' { $$
= $2; }
334 attrib_list: attribute
335 | attrib_list
',' attribute
{ LINK
($3, $1); $$
= $3; }
336 | attrib_list
']' '[' attribute
{ LINK
($4, $1); $$
= $4; }
340 tASYNC
{ $$
= make_attr
(ATTR_ASYNC
); }
341 | tAUTOHANDLE
{ $$
= make_attr
(ATTR_AUTO_HANDLE
); }
342 | tCALLAS
'(' ident
')' { $$
= make_attrp
(ATTR_CALLAS
, $3); }
343 | tCASE
'(' expr_list_const
')' { $$
= make_attrp
(ATTR_CASE
, $3); }
344 | tCONTEXTHANDLE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); }
345 | tCONTEXTHANDLENOSERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
346 | tCONTEXTHANDLESERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
347 | tCONTROL
{ $$
= make_attr
(ATTR_CONTROL
); }
348 | tDEFAULT
{ $$
= make_attr
(ATTR_DEFAULT
); }
349 | tDEFAULTVALUE
'(' expr_const
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE_EXPR
, $3); }
350 | tDEFAULTVALUE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE_STRING
, $3); }
351 | tDLLNAME
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DLLNAME
, $3); }
352 | tDUAL
{ $$
= make_attr
(ATTR_DUAL
); }
353 | tENDPOINT
'(' aSTRING
')' { $$
= make_attrp
(ATTR_ENDPOINT
, $3); }
354 | tENTRY
'(' aSTRING
')' { $$
= make_attrp
(ATTR_ENTRY_STRING
, $3); }
355 | tENTRY
'(' expr_const
')' { $$
= make_attrp
(ATTR_ENTRY_ORDINAL
, $3); }
356 | tEXPLICITHANDLE
{ $$
= make_attr
(ATTR_EXPLICIT_HANDLE
); }
357 | tHANDLE
{ $$
= make_attr
(ATTR_HANDLE
); }
358 | tHELPCONTEXT
'(' expr_const
')' { $$
= make_attrp
(ATTR_HELPCONTEXT
, $3); }
359 | tHELPFILE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPFILE
, $3); }
360 | tHELPSTRING
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRING
, $3); }
361 | tHELPSTRINGCONTEXT
'(' expr_const
')' { $$
= make_attrp
(ATTR_HELPSTRINGCONTEXT
, $3); }
362 | tHELPSTRINGDLL
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRINGDLL
, $3); }
363 | tHIDDEN
{ $$
= make_attr
(ATTR_HIDDEN
); }
364 | tID
'(' expr_const
')' { $$
= make_attrp
(ATTR_ID
, $3); }
365 | tIDEMPOTENT
{ $$
= make_attr
(ATTR_IDEMPOTENT
); }
366 | tIIDIS
'(' ident
')' { $$
= make_attrp
(ATTR_IIDIS
, $3); }
367 | tIMPLICITHANDLE
'(' tHANDLET aIDENTIFIER
')' { $$
= make_attrp
(ATTR_IMPLICIT_HANDLE
, $4); }
368 | tIN
{ $$
= make_attr
(ATTR_IN
); }
369 | tINPUTSYNC
{ $$
= make_attr
(ATTR_INPUTSYNC
); }
370 | tLENGTHIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_LENGTHIS
, $3); }
371 | tLOCAL
{ $$
= make_attr
(ATTR_LOCAL
); }
372 | tNONCREATABLE
{ $$
= make_attr
(ATTR_NONCREATABLE
); }
373 | tOBJECT
{ $$
= make_attr
(ATTR_OBJECT
); }
374 | tODL
{ $$
= make_attr
(ATTR_ODL
); }
375 | tOLEAUTOMATION
{ $$
= make_attr
(ATTR_OLEAUTOMATION
); }
376 | tOPTIONAL
{ $$
= make_attr
(ATTR_OPTIONAL
); }
377 | tOUT
{ $$
= make_attr
(ATTR_OUT
); }
378 | tPOINTERDEFAULT
'(' pointer_type
')' { $$
= make_attrv
(ATTR_POINTERDEFAULT
, $3); }
379 | tPROPGET
{ $$
= make_attr
(ATTR_PROPGET
); }
380 | tPROPPUT
{ $$
= make_attr
(ATTR_PROPPUT
); }
381 | tPROPPUTREF
{ $$
= make_attr
(ATTR_PROPPUTREF
); }
382 | tPUBLIC
{ $$
= make_attr
(ATTR_PUBLIC
); }
383 | tRANGE
'(' expr_const
',' expr_const
')' { LINK
($5, $3); $$
= make_attrp
(ATTR_RANGE
, $5); }
384 | tREADONLY
{ $$
= make_attr
(ATTR_READONLY
); }
385 | tRESTRICTED
{ $$
= make_attr
(ATTR_RESTRICTED
); }
386 | tRETVAL
{ $$
= make_attr
(ATTR_RETVAL
); }
387 | tSIZEIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_SIZEIS
, $3); }
388 | tSOURCE
{ $$
= make_attr
(ATTR_SOURCE
); }
389 | tSTRING
{ $$
= make_attr
(ATTR_STRING
); }
390 | tSWITCHIS
'(' expr
')' { $$
= make_attrp
(ATTR_SWITCHIS
, $3); }
391 | tSWITCHTYPE
'(' type
')' { $$
= make_attrp
(ATTR_SWITCHTYPE
, type_ref
($3)); }
392 | tTRANSMITAS
'(' type
')' { $$
= make_attrp
(ATTR_TRANSMITAS
, type_ref
($3)); }
393 | tUUID
'(' aUUID
')' { $$
= make_attrp
(ATTR_UUID
, $3); }
394 | tV1ENUM
{ $$
= make_attr
(ATTR_V1ENUM
); }
395 | tVARARG
{ $$
= make_attr
(ATTR_VARARG
); }
396 | tVERSION
'(' version
')' { $$
= make_attrv
(ATTR_VERSION
, $3); }
397 | tWIREMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_WIREMARSHAL
, type_ref
($3)); }
398 | pointer_type
{ $$
= make_attrv
(ATTR_POINTERTYPE
, $1); }
405 cases: { $$
= NULL
; }
406 | cases case
{ if
($2) { LINK
($2, $1); $$
= $2; }
411 case: tCASE expr
':' field
{ attr_t
*a
= make_attrp
(ATTR_CASE
, $2);
412 $$
= $4; if
(!$$
) $$
= make_var
(NULL
);
413 LINK
(a
, $$
->attrs
); $$
->attrs
= a
;
415 | tDEFAULT
':' field
{ attr_t
*a
= make_attr
(ATTR_DEFAULT
);
416 $$
= $3; if
(!$$
) $$
= make_var
(NULL
);
417 LINK
(a
, $$
->attrs
); $$
->attrs
= a
;
421 constdef: tCONST type ident
'=' expr_const
{ $$
= reg_const
($3);
422 set_type
($$
, $2, NULL
);
428 enums: { $$
= NULL
; }
429 | enum_list
',' { $$
= $1; }
434 | enum_list
',' enum { LINK
($3, $1); $$
= $3;
436 $3->lval
= $1->lval
+ 1;
440 enum: ident
'=' expr_const
{ $$
= reg_const
($1);
443 $$
->type
= make_type
(RPC_FC_LONG
, &std_int
);
445 | ident
{ $$
= reg_const
($1);
446 $$
->lval
= 0; /* default for first enum entry */
447 $$
->type
= make_type
(RPC_FC_LONG
, &std_int
);
451 enumdef: tENUM t_ident
'{' enums
'}' { $$
= get_typev
(RPC_FC_ENUM16
, $2, tsENUM
);
460 | m_exprs
',' m_expr
{ LINK
($3, $1); $$
= $3; }
464 exprs: { $$ = make_expr(EXPR_VOID); }
469 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
473 m_expr: { $$
= make_expr
(EXPR_VOID
); }
477 expr: aNUM
{ $$
= make_exprl
(EXPR_NUM
, $1); }
478 | aHEXNUM
{ $$
= make_exprl
(EXPR_HEXNUM
, $1); }
479 | aIDENTIFIER
{ $$
= make_exprs
(EXPR_IDENTIFIER
, $1); }
480 | expr
'?' expr
':' expr %prec COND
{ $$
= make_expr3
(EXPR_COND
, $1, $3, $5); }
481 | expr
'|' expr
{ $$
= make_expr2
(EXPR_OR
, $1, $3); }
482 | expr
'&' expr
{ $$
= make_expr2
(EXPR_AND
, $1, $3); }
483 | expr
'+' expr
{ $$
= make_expr2
(EXPR_ADD
, $1, $3); }
484 | expr
'-' expr
{ $$
= make_expr2
(EXPR_SUB
, $1, $3); }
485 | expr
'*' expr
{ $$
= make_expr2
(EXPR_MUL
, $1, $3); }
486 | expr
'/' expr
{ $$
= make_expr2
(EXPR_DIV
, $1, $3); }
487 | expr SHL expr
{ $$
= make_expr2
(EXPR_SHL
, $1, $3); }
488 | expr SHR expr
{ $$
= make_expr2
(EXPR_SHR
, $1, $3); }
489 |
'~' expr
{ $$
= make_expr1
(EXPR_NOT
, $2); }
490 |
'-' expr %prec NEG
{ $$
= make_expr1
(EXPR_NEG
, $2); }
491 |
'*' expr %prec PPTR
{ $$
= make_expr1
(EXPR_PPTR
, $2); }
492 |
'(' type
')' expr %prec CAST
{ $$
= make_exprt
(EXPR_CAST
, $2, $4); }
493 | tSIZEOF
'(' type
')' { $$
= make_exprt
(EXPR_SIZEOF
, $3, NULL
); }
494 |
'(' expr
')' { $$
= $2; }
497 expr_list_const: expr_const
498 | expr_list_const
',' expr_const
{ LINK
($3, $1); $$
= $3; }
501 expr_const: expr
{ $$
= $1;
503 yyerror("expression is not constant\n");
507 externdef: tEXTERN tCONST type ident
{ $$
= $4;
508 set_type
($$
, $3, NULL
);
512 fields: { $$
= NULL
; }
513 | fields field
{ if
($2) { LINK
($2, $1); $$
= $2; }
518 field: s_field
';' { $$
= $1; }
519 | m_attributes uniondef
';' { $$
= make_var
(NULL
); $$
->type
= $2; $$
->attrs
= $1; }
520 | attributes
';' { $$
= make_var
(NULL
); $$
->attrs
= $1; }
524 s_field: m_attributes type pident array
{ $$
= $3; set_type
($$
, $2, $4); $$
->attrs
= $1; }
528 m_attributes type callconv pident
529 '(' m_args
')' { set_type
($4, $2, NULL
);
531 $$
= make_func
($4, $6);
532 if
(is_attr
($4->attrs
, ATTR_IN
)) {
533 yyerror("Inapplicable attribute");
538 m_ident: { $$
= NULL
; }
542 t_ident: { $$
= NULL
; }
543 | aIDENTIFIER
{ $$
= make_var
($1); }
544 | aKNOWNTYPE
{ $$
= make_var
($1); }
547 ident: aIDENTIFIER
{ $$
= make_var
($1); }
548 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
549 | aKNOWNTYPE
{ $$
= make_var
($
<str
>1); }
550 | tASYNC
{ $$
= make_var
($
<str
>1); }
551 | tID
{ $$
= make_var
($
<str
>1); }
552 | tRANGE
{ $$
= make_var
($
<str
>1); }
553 | tRETVAL
{ $$
= make_var
($
<str
>1); }
554 | tVERSION
{ $$
= make_var
($
<str
>1); }
557 base_type: tBYTE
{ $$
= make_type
(RPC_FC_BYTE
, NULL
); }
558 | tWCHAR
{ $$
= make_type
(RPC_FC_WCHAR
, NULL
); }
560 | tSIGNED int_std
{ $$
= $2; $$
->sign
= 1; }
561 | tUNSIGNED int_std
{ $$
= $2; $$
->sign
= -1;
563 case RPC_FC_CHAR
: $$
->type
= RPC_FC_BYTE
; $$
->sign
= 0; break
;
564 case RPC_FC_SMALL
: $$
->type
= RPC_FC_USMALL
; break
;
565 case RPC_FC_SHORT
: $$
->type
= RPC_FC_USHORT
; break
;
566 case RPC_FC_LONG
: $$
->type
= RPC_FC_ULONG
; break
;
568 if
(!$$
->ref
) { $$
->ref
= &std_uhyper
; $$
->sign
= 0; }
573 | tUNSIGNED
{ $$
= make_type
(RPC_FC_ULONG
, &std_int
); $$
->sign
= -1; }
574 | tFLOAT
{ $$
= make_type
(RPC_FC_FLOAT
, NULL
); }
575 | tSINGLE
{ $$
= make_type
(RPC_FC_FLOAT
, NULL
); }
576 | tDOUBLE
{ $$
= make_type
(RPC_FC_DOUBLE
, NULL
); }
577 | tBOOLEAN
{ $$
= make_type
(RPC_FC_BYTE
, &std_bool
); /* ? */ }
578 | tERRORSTATUST
{ $$
= make_type
(RPC_FC_ERROR_STATUS_T
, NULL
); }
579 | tHANDLET
{ $$
= make_type
(RPC_FC_BIND_PRIMITIVE
, NULL
); /* ? */ }
586 int_std: tINT
{ $$
= make_type
(RPC_FC_LONG
, &std_int
); } /* win32 only */
587 | tSHORT m_int
{ $$
= make_type
(RPC_FC_SHORT
, NULL
); }
588 | tSMALL
{ $$
= make_type
(RPC_FC_SHORT
, NULL
); }
589 | tLONG m_int
{ $$
= make_type
(RPC_FC_LONG
, NULL
); }
590 | tHYPER m_int
{ $$
= make_type
(RPC_FC_HYPER
, NULL
); }
591 | tINT64
{ $$
= make_type
(RPC_FC_HYPER
, &std_int64
); }
592 | tCHAR
{ $$
= make_type
(RPC_FC_CHAR
, NULL
); }
595 coclass: tCOCLASS aIDENTIFIER
{ $$
= make_class
($2); }
596 | tCOCLASS aKNOWNTYPE
{ $$
= make_class
($2); }
599 coclasshdr: attributes coclass
{ $$
= $2;
601 if
(!parse_only
&& do_header
) write_coclass
($$
);
605 coclassdef: coclasshdr
'{' coclass_ints
'}' { $$
= $1;
610 coclass_ints: { $$
= NULL
; }
611 | coclass_ints coclass_int
{ LINK
($2, $1); $$
= $2; }
615 m_attributes interfacedec
{ $$
= make_ifref
($2); $$
->attrs
= $1; }
618 dispinterface: tDISPINTERFACE aIDENTIFIER
{ $$
= get_type
(0, $2, 0); }
619 | tDISPINTERFACE aKNOWNTYPE
{ $$
= get_type
(0, $2, 0); }
622 dispinterfacehdr: attributes dispinterface
{ $$
= $2;
623 if
($$
->defined
) yyerror("multiple definition error\n");
625 $$
->attrs
= make_attr
(ATTR_DISPINTERFACE
);
627 $$
->ref
= find_type
("IDispatch", 0);
628 if
(!$$
->ref
) yyerror("IDispatch is undefined\n");
630 if
(!parse_only
&& do_header
) write_forward
($$
);
634 dispint_props: tPROPERTIES
':' { $$
= NULL
; }
635 | dispint_props s_field
';' { LINK
($2, $1); $$
= $2; }
638 dispint_meths: tMETHODS
':' { $$
= NULL
; }
639 | dispint_meths funcdef
';' { LINK
($2, $1); $$
= $2; }
642 dispinterfacedef: dispinterfacehdr
'{'
648 if
(!parse_only
&& do_header
) write_dispinterface
($$
);
650 /* FIXME: not sure how to handle this yet
651 | dispinterfacehdr '{' interface '}' { $$ = $1;
652 if (!parse_only && do_header) write_interface($$);
657 inherit: { $$
= NULL
; }
658 |
':' aKNOWNTYPE
{ $$
= find_type2
($2, 0); }
661 interface: tINTERFACE aIDENTIFIER
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
662 | tINTERFACE aKNOWNTYPE
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
665 interfacehdr: attributes interface
{ $$
= $2;
666 if
($$
->defined
) yyerror("multiple definition error\n");
669 if
(!parse_only
&& do_header
) write_forward
($$
);
673 interfacedef: interfacehdr inherit
674 '{' int_statements
'}' { $$
= $1;
677 if
(!parse_only
&& do_header
) write_interface
($$
);
679 /* MIDL is able to import the definition of a base class from inside the
680 * definition of a derived class, I'll try to support it with this rule */
681 | interfacehdr
':' aIDENTIFIER
682 '{' import int_statements
'}' { $$
= $1;
683 $$
->ref
= find_type2
($3, 0);
684 if
(!$$
->ref
) yyerror("base class %s not found in import\n", $3);
686 if
(!parse_only
&& do_header
) write_interface
($$
);
688 | dispinterfacedef
{ $$
= $1; }
692 interface
';' { $$
= $1; if
(!parse_only
&& do_header
) write_forward
($$
); }
693 | dispinterface
';' { $$
= $1; if
(!parse_only
&& do_header
) write_forward
($$
); }
696 module: tMODULE aIDENTIFIER
{ $$
= make_type
(0, NULL
); $$
->name
= $2; }
697 | tMODULE aKNOWNTYPE
{ $$
= make_type
(0, NULL
); $$
->name
= $2; }
700 modulehdr: attributes module
{ $$
= $2;
705 moduledef: modulehdr
'{' int_statements
'}' { $$
= $1;
707 /* FIXME: if (!parse_only && do_header) write_module($$); */
711 p_ident: '*' pident %prec PPTR
{ $$
= $2; $$
->ptr_level
++; }
712 | tCONST p_ident
{ $$
= $2; /* FIXME */ }
717 |
'(' pident
')' { $$
= $2; }
722 | pident_list
',' pident
{ LINK
($3, $1); $$
= $3; }
726 tREF
{ $$
= RPC_FC_RP
; }
727 | tUNIQUE
{ $$
= RPC_FC_UP
; }
728 | tPTR
{ $$
= RPC_FC_FP
; }
731 structdef: tSTRUCT t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_STRUCT
, $2, tsSTRUCT
);
732 /* overwrite RPC_FC_STRUCT with a more exact type */
733 $$
->type
= get_struct_type
( $4 );
741 type: tVOID
{ $$
= make_tref
(NULL
, make_type
(0, NULL
)); }
742 | aKNOWNTYPE
{ $$
= make_tref
($1, find_type
($1, 0)); }
743 | base_type
{ $$
= make_tref
(NULL
, $1); }
744 | tCONST type
{ $$
= uniq_tref
($2); $$
->ref
->is_const
= TRUE
; }
745 | enumdef
{ $$
= make_tref
(NULL
, $1); }
746 | tENUM aIDENTIFIER
{ $$
= make_tref
(NULL
, find_type2
($2, tsENUM
)); }
747 | structdef
{ $$
= make_tref
(NULL
, $1); }
748 | tSTRUCT aIDENTIFIER
{ $$
= make_tref
(NULL
, get_type
(RPC_FC_STRUCT
, $2, tsSTRUCT
)); }
749 | uniondef
{ $$
= make_tref
(NULL
, $1); }
750 | tUNION aIDENTIFIER
{ $$
= make_tref
(NULL
, find_type2
($2, tsUNION
)); }
753 typedef: tTYPEDEF m_attributes type pident_list
{ typeref_t
*tref
= uniq_tref
($3);
754 $4->tname
= tref
->name
;
758 if
(!parse_only
&& do_header
) write_typedef
($$
, $4);
759 if
(in_typelib
&& $$
->attrs
)
761 reg_types
($$
, $4, 0);
765 uniondef: tUNION t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_NON_ENCAPSULATED_UNION
, $2, tsUNION
);
770 tSWITCH
'(' s_field
')'
771 m_ident
'{' cases
'}' { var_t
*u
= $7;
772 $$
= get_typev
(RPC_FC_ENCAPSULATED_UNION
, $2, tsUNION
);
773 if
(!u
) u
= make_var
("tagged_union");
774 u
->type
= make_type
(RPC_FC_NON_ENCAPSULATED_UNION
, NULL
);
775 u
->type
->fields
= $9;
776 u
->type
->defined
= TRUE
;
777 LINK
(u
, $5); $$
->fields
= u
;
783 aNUM
{ $$
= MAKELONG
($1, 0); }
784 | aNUM
'.' aNUM
{ $$
= MAKELONG
($1, $3); }
789 static attr_t
*make_attr
(enum attr_type type
)
791 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
798 static attr_t
*make_attrv
(enum attr_type type
, unsigned long val
)
800 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
807 static attr_t
*make_attrp
(enum attr_type type
, void *val
)
809 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
816 static expr_t
*make_expr
(enum expr_type type
)
818 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
827 static expr_t
*make_exprl
(enum expr_type type
, long val
)
829 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
835 /* check for numeric constant */
836 if
(type
== EXPR_NUM || type
== EXPR_HEXNUM
) {
843 static expr_t
*make_exprs
(enum expr_type type
, char *val
)
846 e
= xmalloc
(sizeof
(expr_t
));
852 /* check for predefined constants */
853 if
(type
== EXPR_IDENTIFIER
) {
854 var_t
*c
= find_const
(val
, 0);
865 static expr_t
*make_exprt
(enum expr_type type
, typeref_t
*tref
, expr_t
*expr
)
868 e
= xmalloc
(sizeof
(expr_t
));
874 /* check for cast of constant expression */
875 if
(type
== EXPR_CAST
&& expr
->is_const
) {
877 e
->cval
= expr
->cval
;
882 static expr_t
*make_expr1
(enum expr_type type
, expr_t
*expr
)
885 e
= xmalloc
(sizeof
(expr_t
));
891 /* check for compile-time optimization */
892 if
(expr
->is_const
) {
896 e
->cval
= -expr
->cval
;
899 e
->cval
= ~expr
->cval
;
909 static expr_t
*make_expr2
(enum expr_type type
, expr_t
*expr1
, expr_t
*expr2
)
912 e
= xmalloc
(sizeof
(expr_t
));
918 /* check for compile-time optimization */
919 if
(expr1
->is_const
&& expr2
->is_const
) {
923 e
->cval
= expr1
->cval
+ expr2
->cval
;
926 e
->cval
= expr1
->cval
- expr2
->cval
;
929 e
->cval
= expr1
->cval
* expr2
->cval
;
932 e
->cval
= expr1
->cval
/ expr2
->cval
;
935 e
->cval
= expr1
->cval | expr2
->cval
;
938 e
->cval
= expr1
->cval
& expr2
->cval
;
941 e
->cval
= expr1
->cval
<< expr2
->cval
;
944 e
->cval
= expr1
->cval
>> expr2
->cval
;
954 static expr_t
*make_expr3
(enum expr_type type
, expr_t
*expr1
, expr_t
*expr2
, expr_t
*expr3
)
957 e
= xmalloc
(sizeof
(expr_t
));
964 /* check for compile-time optimization */
965 if
(expr1
->is_const
&& expr2
->is_const
&& expr3
->is_const
) {
969 e
->cval
= expr1
->cval ? expr2
->cval
: expr3
->cval
;
979 static type_t
*make_type
(unsigned char type
, type_t
*ref
)
981 type_t
*t
= xmalloc
(sizeof
(type_t
));
989 t
->ignore
= parse_only
;
999 static typeref_t
*make_tref
(char *name
, type_t
*ref
)
1001 typeref_t
*t
= xmalloc
(sizeof
(typeref_t
));
1004 t
->uniq
= ref ?
0 : 1;
1008 static typeref_t
*uniq_tref
(typeref_t
*ref
)
1012 if
(t
->uniq
) return t
;
1013 tp
= make_type
(0, t
->ref
);
1021 static type_t
*type_ref
(typeref_t
*ref
)
1023 type_t
*t
= ref
->ref
;
1024 if
(ref
->name
) free
(ref
->name
);
1029 static void set_type
(var_t
*v
, typeref_t
*ref
, expr_t
*arr
)
1032 v
->tname
= ref
->name
;
1038 static ifref_t
*make_ifref
(type_t
*iface
)
1040 ifref_t
*l
= xmalloc
(sizeof
(ifref_t
));
1047 static var_t
*make_var
(char *name
)
1049 var_t
*v
= xmalloc
(sizeof
(var_t
));
1062 static func_t
*make_func
(var_t
*def
, var_t
*args
)
1064 func_t
*f
= xmalloc
(sizeof
(func_t
));
1067 f
->ignore
= parse_only
;
1073 static class_t
*make_class
(char *name
)
1075 class_t
*c
= xmalloc
(sizeof
(class_t
));
1085 static int hash_ident
(const char *name
)
1087 const char *p
= name
;
1089 /* a simple sum hash is probably good enough */
1094 return sum
& (HASHMAX
-1);
1097 /***** type repository *****/
1106 struct rtype
*type_hash
[HASHMAX
];
1108 static type_t
*reg_type
(type_t
*type
, char *name
, int t
)
1113 yyerror("registering named type without name\n");
1116 hash
= hash_ident
(name
);
1117 nt
= xmalloc
(sizeof
(struct rtype
));
1121 nt
->next
= type_hash
[hash
];
1122 type_hash
[hash
] = nt
;
1126 /* determine pointer type from attrs */
1127 static unsigned char get_pointer_type
( type_t
*type
)
1130 if
(is_attr
( type
->attrs
, ATTR_STRING
))
1133 while
( t
->type
== 0 && t
->ref
)
1138 return RPC_FC_C_CSTRING
;
1140 return RPC_FC_C_WSTRING
;
1143 t
= get_attrv
( type
->attrs
, ATTR_POINTERTYPE
);
1148 static type_t
*reg_types
(type_t
*type
, var_t
*names
, int t
)
1154 var_t
*next
= NEXT_LINK
(names
);
1157 int cptr
= names
->ptr_level
;
1159 while
(cptr
> ptrc
) {
1160 int t
= get_pointer_type
( cur
);
1161 cur
= ptr
= make_type
(t
, cur
);
1165 while
(cptr
< ptrc
) {
1170 reg_type
(cur
, names
->name
, t
);
1178 static type_t
*find_type
(const char *name
, int t
)
1180 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
1181 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
1184 yyerror("type %s not found\n", name
);
1190 static type_t
*find_type2
(char *name
, int t
)
1192 type_t
*tp
= find_type
(name
, t
);
1197 int is_type
(const char *name
)
1199 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
1200 while
(cur
&& (cur
->t || strcmp
(cur
->name
, name
)))
1202 if
(cur
) return TRUE
;
1206 static type_t
*get_type
(unsigned char type
, char *name
, int t
)
1208 struct rtype
*cur
= NULL
;
1211 cur
= type_hash
[hash_ident
(name
)];
1212 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
1219 tp
= make_type
(type
, NULL
);
1221 if
(!name
) return tp
;
1222 return reg_type
(tp
, name
, t
);
1225 static type_t
*get_typev
(unsigned char type
, var_t
*name
, int t
)
1232 return get_type
(type
, sname
, t
);
1235 static int get_struct_type
(var_t
*field
)
1237 int has_pointer
= 0;
1238 int has_conformant_array
= 0;
1239 int has_conformant_string
= 0;
1243 type_t
*t
= field
->type
;
1245 /* get the base type */
1246 while
( (t
->type
== 0) && t
->ref
)
1252 * RPC_FC_BYTE, RPC_FC_STRUCT, etc
1253 * Simple types don't effect the type of struct.
1254 * A struct containing a simple struct is still a simple struct.
1255 * So long as we can block copy the data, we return RPC_FC_STRUCT.
1257 case
0: /* void pointer */
1267 case RPC_FC_INT3264
:
1268 case RPC_FC_UINT3264
:
1282 has_conformant_array
= 1;
1284 case RPC_FC_C_CSTRING
:
1285 case RPC_FC_C_WSTRING
:
1286 has_conformant_string
= 1;
1290 * Propagate member attributes
1291 * a struct should be at least as complex as its member
1293 case RPC_FC_CVSTRUCT
:
1294 has_conformant_string
= 1;
1298 case RPC_FC_CPSTRUCT
:
1299 has_conformant_array
= 1;
1303 case RPC_FC_CSTRUCT
:
1304 has_conformant_array
= 1;
1307 case RPC_FC_PSTRUCT
:
1312 fprintf
(stderr
,"Unknown struct member %s with type (0x%02x)\n",
1313 field
->name
, t
->type
);
1314 /* fallthru - treat it as complex */
1316 /* as soon as we see one of these these members, it's bogus... */
1318 case RPC_FC_ENCAPSULATED_UNION
:
1319 case RPC_FC_NON_ENCAPSULATED_UNION
:
1320 case RPC_FC_TRANSMIT_AS
:
1321 case RPC_FC_REPRESENT_AS
:
1323 case RPC_FC_EMBEDDED_COMPLEX
:
1324 case RPC_FC_BOGUS_STRUCT
:
1325 return RPC_FC_BOGUS_STRUCT
;
1327 field
= NEXT_LINK
(field
);
1330 if
( has_conformant_string
&& has_pointer
)
1331 return RPC_FC_CVSTRUCT
;
1332 if
( has_conformant_array
&& has_pointer
)
1333 return RPC_FC_CPSTRUCT
;
1334 if
( has_conformant_array
)
1335 return RPC_FC_CSTRUCT
;
1337 return RPC_FC_PSTRUCT
;
1338 return RPC_FC_STRUCT
;
1341 /***** constant repository *****/
1346 struct rconst
*next
;
1349 struct rconst
*const_hash
[HASHMAX
];
1351 static var_t
*reg_const
(var_t
*var
)
1356 yyerror("registering constant without name\n");
1359 hash
= hash_ident
(var
->name
);
1360 nc
= xmalloc
(sizeof
(struct rconst
));
1361 nc
->name
= var
->name
;
1363 nc
->next
= const_hash
[hash
];
1364 const_hash
[hash
] = nc
;
1368 static var_t
*find_const
(char *name
, int f
)
1370 struct rconst
*cur
= const_hash
[hash_ident
(name
)];
1371 while
(cur
&& strcmp
(cur
->name
, name
))
1374 if
(f
) yyerror("constant %s not found\n", name
);