5 * Copyright 2002 Ove Kaaven
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
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
, const 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 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
135 %token tDEFAULTCOLLELEM
137 %token tDEFAULTVTABLE
139 %token tDISPINTERFACE
140 %token tDLLNAME tDOUBLE tDUAL
142 %token tENTRY tENUM tERRORSTATUST
143 %token tEXPLICITHANDLE tEXTERN
148 %token tHELPCONTEXT tHELPFILE
149 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
151 %token tHYPER tID tIDEMPOTENT
153 %token tIMMEDIATEBIND
154 %token tIMPLICITHANDLE
155 %token tIMPORT tIMPORTLIB
161 %token tLENGTHIS tLIBRARY
168 %token tNONEXTENSIBLE
169 %token tOBJECT tODL tOLEAUTOMATION
172 %token tPOINTERDEFAULT
174 %token tPROPGET tPROPPUT tPROPPUTREF
178 %token tREADONLY tREF
185 %token tSIZEIS tSIZEOF
189 %token tSTRING tSTRUCT
190 %token tSWITCH tSWITCHIS tSWITCHTYPE
202 %token tWCHAR tWIREMARSHAL
204 %type
<attr
> m_attributes attributes attrib_list attribute
205 %type
<expr
> m_exprs
/* exprs expr_list */ m_expr expr expr_list_const expr_const
206 %type
<expr
> array array_list
207 %type
<type
> inherit interface interfacehdr interfacedef interfacedec
208 %type
<type
> dispinterface dispinterfacehdr dispinterfacedef
209 %type
<type
> module modulehdr moduledef
210 %type
<type
> base_type int_std
211 %type
<type
> enumdef structdef typedef uniondef
212 %type
<ifref
> gbl_statements coclass_ints coclass_int
214 %type
<var
> m_args no_args args arg
215 %type
<var
> fields field s_field cases case enums enum_list
enum constdef externdef
216 %type
<var
> m_ident t_ident ident p_ident pident pident_list
217 %type
<var
> dispint_props
218 %type
<func
> funcdef int_statements
219 %type
<func
> dispint_meths
220 %type
<clas
> coclass coclasshdr coclassdef
221 %type
<num
> pointer_type version
222 %type
<str
> libraryhdr
238 input: gbl_statements
{ write_proxies
($1); write_client
($1); write_server
($1); }
241 gbl_statements: { $$
= NULL
; }
242 | gbl_statements interfacedec
{ $$
= $1; }
243 | gbl_statements interfacedef
{ $$
= make_ifref
($2); LINK
($$
, $1); }
244 | gbl_statements coclass
';' { $$
= $1; if
(!parse_only
&& do_header
) write_coclass_forward
($2); }
245 | gbl_statements coclassdef
{ $$
= $1; add_coclass
($2); }
246 | gbl_statements moduledef
{ $$
= $1; add_module
($2); }
247 | gbl_statements librarydef
{ $$
= $1; }
248 | gbl_statements statement
{ $$
= $1; }
252 | imp_statements interfacedec
{ if
(!parse_only
) add_interface
($2); }
253 | imp_statements interfacedef
{ if
(!parse_only
) add_interface
($2); }
254 | imp_statements coclass
';' {}
255 | imp_statements coclassdef
{ if
(!parse_only
) add_coclass
($2); }
256 | imp_statements moduledef
{ if
(!parse_only
) add_module
($2); }
257 | imp_statements statement
{}
258 | imp_statements importlib
{}
261 int_statements: { $$
= NULL
; }
262 | int_statements funcdef
';' { $$
= $2; LINK
($$
, $1); }
263 | int_statements statement
{ $$
= $1; }
267 | constdef
';' { if
(!parse_only
&& do_header
) { write_constdef
($1); } }
269 | enumdef
';' { if
(!parse_only
&& do_header
) { write_type
(header
, $1, NULL
, NULL
); fprintf
(header
, ";\n\n"); } }
270 | externdef
';' { if
(!parse_only
&& do_header
) { write_externdef
($1); } }
272 | structdef
';' { if
(!parse_only
&& do_header
) { write_type
(header
, $1, NULL
, NULL
); fprintf
(header
, ";\n\n"); } }
274 | uniondef
';' { if
(!parse_only
&& do_header
) { write_type
(header
, $1, NULL
, NULL
); fprintf
(header
, ";\n\n"); } }
277 cppquote: tCPPQUOTE
'(' aSTRING
')' { if
(!parse_only
&& do_header
) fprintf
(header
, "%s\n", $3); }
279 import_start: tIMPORT aSTRING
';' { assert
(yychar == YYEMPTY
);
280 if
(!do_import
($2)) yychar = aEOF
; }
282 import: import_start imp_statements aEOF
{}
285 importlib: tIMPORTLIB
'(' aSTRING
')' { if
(!parse_only
) add_importlib
($3); }
288 libraryhdr: tLIBRARY aIDENTIFIER
{ $$
= $2; }
290 library_start: attributes libraryhdr
'{' { start_typelib
($2, $1);
291 if
(!parse_only
&& do_header
) write_library
($2, $1); }
293 librarydef: library_start imp_statements
'}' { end_typelib
(); }
296 m_args: { $$
= NULL
; }
300 no_args: tVOID
{ $$
= NULL
; }
304 | args
',' arg
{ LINK
($3, $1); $$
= $3; }
308 /* split into two rules to get bison to resolve a tVOID conflict */
309 arg: attributes type pident array
{ $$
= $3;
310 set_type
($$
, $2, $4);
313 | type pident array
{ $$
= $2;
314 set_type
($$
, $1, $3);
316 | attributes type pident
'(' m_args
')' { $$
= $3;
318 set_type
($$
, $2, NULL
);
322 | type pident
'(' m_args
')' { $$
= $2;
324 set_type
($$
, $1, NULL
);
329 array: { $$
= NULL
; }
330 |
'[' array_list
']' { $$
= $2; }
331 |
'[' '*' ']' { $$
= make_expr
(EXPR_VOID
); }
334 array_list: m_expr
/* size of first dimension is optional */
335 | array_list
',' expr
{ LINK
($3, $1); $$
= $3; }
336 | array_list
']' '[' expr
{ LINK
($4, $1); $$
= $4; }
339 m_attributes: { $$
= NULL
; }
344 '[' attrib_list
']' { $$
= $2; }
347 attrib_list: attribute
348 | attrib_list
',' attribute
{ LINK
($3, $1); $$
= $3; }
349 | attrib_list
']' '[' attribute
{ LINK
($4, $1); $$
= $4; }
353 tAGGREGATABLE
{ $$
= make_attr
(ATTR_AGGREGATABLE
); }
354 | tAPPOBJECT
{ $$
= make_attr
(ATTR_APPOBJECT
); }
355 | tASYNC
{ $$
= make_attr
(ATTR_ASYNC
); }
356 | tAUTOHANDLE
{ $$
= make_attr
(ATTR_AUTO_HANDLE
); }
357 | tBINDABLE
{ $$
= make_attr
(ATTR_BINDABLE
); }
358 | tCALLAS
'(' ident
')' { $$
= make_attrp
(ATTR_CALLAS
, $3); }
359 | tCASE
'(' expr_list_const
')' { $$
= make_attrp
(ATTR_CASE
, $3); }
360 | tCONTEXTHANDLE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); }
361 | tCONTEXTHANDLENOSERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
362 | tCONTEXTHANDLESERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
363 | tCONTROL
{ $$
= make_attr
(ATTR_CONTROL
); }
364 | tDEFAULT
{ $$
= make_attr
(ATTR_DEFAULT
); }
365 | tDEFAULTCOLLELEM
{ $$
= make_attr
(ATTR_DEFAULTCOLLELEM
); }
366 | tDEFAULTVALUE
'(' expr_const
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE_EXPR
, $3); }
367 | tDEFAULTVALUE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE_STRING
, $3); }
368 | tDEFAULTVTABLE
{ $$
= make_attr
(ATTR_DEFAULTVTABLE
); }
369 | tDISPLAYBIND
{ $$
= make_attr
(ATTR_DISPLAYBIND
); }
370 | tDLLNAME
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DLLNAME
, $3); }
371 | tDUAL
{ $$
= make_attr
(ATTR_DUAL
); }
372 | tENDPOINT
'(' aSTRING
')' { $$
= make_attrp
(ATTR_ENDPOINT
, $3); }
373 | tENTRY
'(' aSTRING
')' { $$
= make_attrp
(ATTR_ENTRY_STRING
, $3); }
374 | tENTRY
'(' expr_const
')' { $$
= make_attrp
(ATTR_ENTRY_ORDINAL
, $3); }
375 | tEXPLICITHANDLE
{ $$
= make_attr
(ATTR_EXPLICIT_HANDLE
); }
376 | tHANDLE
{ $$
= make_attr
(ATTR_HANDLE
); }
377 | tHELPCONTEXT
'(' expr_const
')' { $$
= make_attrp
(ATTR_HELPCONTEXT
, $3); }
378 | tHELPFILE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPFILE
, $3); }
379 | tHELPSTRING
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRING
, $3); }
380 | tHELPSTRINGCONTEXT
'(' expr_const
')' { $$
= make_attrp
(ATTR_HELPSTRINGCONTEXT
, $3); }
381 | tHELPSTRINGDLL
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRINGDLL
, $3); }
382 | tHIDDEN
{ $$
= make_attr
(ATTR_HIDDEN
); }
383 | tID
'(' expr_const
')' { $$
= make_attrp
(ATTR_ID
, $3); }
384 | tIDEMPOTENT
{ $$
= make_attr
(ATTR_IDEMPOTENT
); }
385 | tIIDIS
'(' ident
')' { $$
= make_attrp
(ATTR_IIDIS
, $3); }
386 | tIMMEDIATEBIND
{ $$
= make_attr
(ATTR_IMMEDIATEBIND
); }
387 | tIMPLICITHANDLE
'(' tHANDLET aIDENTIFIER
')' { $$
= make_attrp
(ATTR_IMPLICIT_HANDLE
, $4); }
388 | tIN
{ $$
= make_attr
(ATTR_IN
); }
389 | tINPUTSYNC
{ $$
= make_attr
(ATTR_INPUTSYNC
); }
390 | tLENGTHIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_LENGTHIS
, $3); }
391 | tLOCAL
{ $$
= make_attr
(ATTR_LOCAL
); }
392 | tNONBROWSABLE
{ $$
= make_attr
(ATTR_NONBROWSABLE
); }
393 | tNONCREATABLE
{ $$
= make_attr
(ATTR_NONCREATABLE
); }
394 | tNONEXTENSIBLE
{ $$
= make_attr
(ATTR_NONEXTENSIBLE
); }
395 | tOBJECT
{ $$
= make_attr
(ATTR_OBJECT
); }
396 | tODL
{ $$
= make_attr
(ATTR_ODL
); }
397 | tOLEAUTOMATION
{ $$
= make_attr
(ATTR_OLEAUTOMATION
); }
398 | tOPTIONAL
{ $$
= make_attr
(ATTR_OPTIONAL
); }
399 | tOUT
{ $$
= make_attr
(ATTR_OUT
); }
400 | tPOINTERDEFAULT
'(' pointer_type
')' { $$
= make_attrv
(ATTR_POINTERDEFAULT
, $3); }
401 | tPROPGET
{ $$
= make_attr
(ATTR_PROPGET
); }
402 | tPROPPUT
{ $$
= make_attr
(ATTR_PROPPUT
); }
403 | tPROPPUTREF
{ $$
= make_attr
(ATTR_PROPPUTREF
); }
404 | tPUBLIC
{ $$
= make_attr
(ATTR_PUBLIC
); }
405 | tRANGE
'(' expr_const
',' expr_const
')' { LINK
($5, $3); $$
= make_attrp
(ATTR_RANGE
, $5); }
406 | tREADONLY
{ $$
= make_attr
(ATTR_READONLY
); }
407 | tREQUESTEDIT
{ $$
= make_attr
(ATTR_REQUESTEDIT
); }
408 | tRESTRICTED
{ $$
= make_attr
(ATTR_RESTRICTED
); }
409 | tRETVAL
{ $$
= make_attr
(ATTR_RETVAL
); }
410 | tSIZEIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_SIZEIS
, $3); }
411 | tSOURCE
{ $$
= make_attr
(ATTR_SOURCE
); }
412 | tSTRING
{ $$
= make_attr
(ATTR_STRING
); }
413 | tSWITCHIS
'(' expr
')' { $$
= make_attrp
(ATTR_SWITCHIS
, $3); }
414 | tSWITCHTYPE
'(' type
')' { $$
= make_attrp
(ATTR_SWITCHTYPE
, type_ref
($3)); }
415 | tTRANSMITAS
'(' type
')' { $$
= make_attrp
(ATTR_TRANSMITAS
, type_ref
($3)); }
416 | tUUID
'(' aUUID
')' { $$
= make_attrp
(ATTR_UUID
, $3); }
417 | tV1ENUM
{ $$
= make_attr
(ATTR_V1ENUM
); }
418 | tVARARG
{ $$
= make_attr
(ATTR_VARARG
); }
419 | tVERSION
'(' version
')' { $$
= make_attrv
(ATTR_VERSION
, $3); }
420 | tWIREMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_WIREMARSHAL
, type_ref
($3)); }
421 | pointer_type
{ $$
= make_attrv
(ATTR_POINTERTYPE
, $1); }
428 cases: { $$
= NULL
; }
429 | cases case
{ if
($2) { LINK
($2, $1); $$
= $2; }
434 case: tCASE expr
':' field
{ attr_t
*a
= make_attrp
(ATTR_CASE
, $2);
435 $$
= $4; if
(!$$
) $$
= make_var
(NULL
);
436 LINK
(a
, $$
->attrs
); $$
->attrs
= a
;
438 | tDEFAULT
':' field
{ attr_t
*a
= make_attr
(ATTR_DEFAULT
);
439 $$
= $3; if
(!$$
) $$
= make_var
(NULL
);
440 LINK
(a
, $$
->attrs
); $$
->attrs
= a
;
444 constdef: tCONST type ident
'=' expr_const
{ $$
= reg_const
($3);
445 set_type
($$
, $2, NULL
);
450 enums: { $$
= NULL
; }
451 | enum_list
',' { $$
= $1; }
455 enum_list: enum { if
(!$$
->eval
)
456 $$
->eval
= make_exprl
(EXPR_NUM
, 0 /* default for first enum entry */);
458 | enum_list
',' enum { LINK
($3, $1); $$
= $3;
460 $$
->eval
= make_exprl
(EXPR_NUM
, $1->eval
->cval
+ 1);
464 enum: ident
'=' expr_const
{ $$
= reg_const
($1);
466 $$
->type
= make_type
(RPC_FC_LONG
, &std_int
);
468 | ident
{ $$
= reg_const
($1);
469 $$
->type
= make_type
(RPC_FC_LONG
, &std_int
);
473 enumdef: tENUM t_ident
'{' enums
'}' { $$
= get_typev
(RPC_FC_ENUM16
, $2, tsENUM
);
482 | m_exprs
',' m_expr
{ LINK
($3, $1); $$
= $3; }
486 exprs: { $$ = make_expr(EXPR_VOID); }
491 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
495 m_expr: { $$
= make_expr
(EXPR_VOID
); }
499 expr: aNUM
{ $$
= make_exprl
(EXPR_NUM
, $1); }
500 | aHEXNUM
{ $$
= make_exprl
(EXPR_HEXNUM
, $1); }
501 | tFALSE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 0); }
502 | tTRUE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 1); }
503 | aIDENTIFIER
{ $$
= make_exprs
(EXPR_IDENTIFIER
, $1); }
504 | expr
'?' expr
':' expr
{ $$
= make_expr3
(EXPR_COND
, $1, $3, $5); }
505 | expr
'|' expr
{ $$
= make_expr2
(EXPR_OR
, $1, $3); }
506 | expr
'&' expr
{ $$
= make_expr2
(EXPR_AND
, $1, $3); }
507 | expr
'+' expr
{ $$
= make_expr2
(EXPR_ADD
, $1, $3); }
508 | expr
'-' expr
{ $$
= make_expr2
(EXPR_SUB
, $1, $3); }
509 | expr
'*' expr
{ $$
= make_expr2
(EXPR_MUL
, $1, $3); }
510 | expr
'/' expr
{ $$
= make_expr2
(EXPR_DIV
, $1, $3); }
511 | expr SHL expr
{ $$
= make_expr2
(EXPR_SHL
, $1, $3); }
512 | expr SHR expr
{ $$
= make_expr2
(EXPR_SHR
, $1, $3); }
513 |
'~' expr
{ $$
= make_expr1
(EXPR_NOT
, $2); }
514 |
'-' expr %prec NEG
{ $$
= make_expr1
(EXPR_NEG
, $2); }
515 |
'*' expr %prec PPTR
{ $$
= make_expr1
(EXPR_PPTR
, $2); }
516 |
'(' type
')' expr %prec CAST
{ $$
= make_exprt
(EXPR_CAST
, $2, $4); }
517 | tSIZEOF
'(' type
')' { $$
= make_exprt
(EXPR_SIZEOF
, $3, NULL
); }
518 |
'(' expr
')' { $$
= $2; }
521 expr_list_const: expr_const
522 | expr_list_const
',' expr_const
{ LINK
($3, $1); $$
= $3; }
525 expr_const: expr
{ $$
= $1;
527 yyerror("expression is not constant");
531 externdef: tEXTERN tCONST type ident
{ $$
= $4;
532 set_type
($$
, $3, NULL
);
536 fields: { $$
= NULL
; }
537 | fields field
{ if
($2) { LINK
($2, $1); $$
= $2; }
542 field: s_field
';' { $$
= $1; }
543 | m_attributes uniondef
';' { $$
= make_var
(NULL
); $$
->type
= $2; $$
->attrs
= $1; }
544 | attributes
';' { $$
= make_var
(NULL
); $$
->attrs
= $1; }
548 s_field: m_attributes type pident array
{ $$
= $3; set_type
($$
, $2, $4); $$
->attrs
= $1; }
552 m_attributes type callconv pident
553 '(' m_args
')' { set_type
($4, $2, NULL
);
555 $$
= make_func
($4, $6);
556 if
(is_attr
($4->attrs
, ATTR_IN
)) {
557 yyerror("inapplicable attribute [in] for function '%s'",$$
->def
->name
);
562 m_ident: { $$
= NULL
; }
566 t_ident: { $$
= NULL
; }
567 | aIDENTIFIER
{ $$
= make_var
($1); }
568 | aKNOWNTYPE
{ $$
= make_var
($1); }
571 ident: aIDENTIFIER
{ $$
= make_var
($1); }
572 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
573 | aKNOWNTYPE
{ $$
= make_var
($
<str
>1); }
574 | tASYNC
{ $$
= make_var
($
<str
>1); }
575 | tID
{ $$
= make_var
($
<str
>1); }
576 | tLCID
{ $$
= make_var
($
<str
>1); }
577 | tOBJECT
{ $$
= make_var
($
<str
>1); }
578 | tRANGE
{ $$
= make_var
($
<str
>1); }
579 | tRETVAL
{ $$
= make_var
($
<str
>1); }
580 | tUUID
{ $$
= make_var
($
<str
>1); }
581 | tVERSION
{ $$
= make_var
($
<str
>1); }
584 base_type: tBYTE
{ $$
= make_type
(RPC_FC_BYTE
, NULL
); }
585 | tWCHAR
{ $$
= make_type
(RPC_FC_WCHAR
, NULL
); }
587 | tSIGNED int_std
{ $$
= $2; $$
->sign
= 1; }
588 | tUNSIGNED int_std
{ $$
= $2; $$
->sign
= -1;
590 case RPC_FC_CHAR
: break
;
591 case RPC_FC_SMALL
: $$
->type
= RPC_FC_USMALL
; break
;
592 case RPC_FC_SHORT
: $$
->type
= RPC_FC_USHORT
; break
;
593 case RPC_FC_LONG
: $$
->type
= RPC_FC_ULONG
; break
;
595 if
(!$$
->ref
) { $$
->ref
= &std_uhyper
; $$
->sign
= 0; }
600 | tUNSIGNED
{ $$
= make_type
(RPC_FC_ULONG
, &std_int
); $$
->sign
= -1; }
601 | tFLOAT
{ $$
= make_type
(RPC_FC_FLOAT
, NULL
); }
602 | tSINGLE
{ $$
= make_type
(RPC_FC_FLOAT
, NULL
); }
603 | tDOUBLE
{ $$
= make_type
(RPC_FC_DOUBLE
, NULL
); }
604 | tBOOLEAN
{ $$
= make_type
(RPC_FC_BYTE
, &std_bool
); /* ? */ }
605 | tERRORSTATUST
{ $$
= make_type
(RPC_FC_ERROR_STATUS_T
, NULL
); }
606 | tHANDLET
{ $$
= make_type
(RPC_FC_BIND_PRIMITIVE
, NULL
); /* ? */ }
613 int_std: tINT
{ $$
= make_type
(RPC_FC_LONG
, &std_int
); } /* win32 only */
614 | tSHORT m_int
{ $$
= make_type
(RPC_FC_SHORT
, NULL
); }
615 | tSMALL
{ $$
= make_type
(RPC_FC_SMALL
, NULL
); }
616 | tLONG m_int
{ $$
= make_type
(RPC_FC_LONG
, NULL
); }
617 | tHYPER m_int
{ $$
= make_type
(RPC_FC_HYPER
, NULL
); }
618 | tINT64
{ $$
= make_type
(RPC_FC_HYPER
, &std_int64
); }
619 | tCHAR
{ $$
= make_type
(RPC_FC_CHAR
, NULL
); }
622 coclass: tCOCLASS aIDENTIFIER
{ $$
= make_class
($2); }
623 | tCOCLASS aKNOWNTYPE
{ $$
= make_class
($2); }
626 coclasshdr: attributes coclass
{ $$
= $2;
628 if
(!parse_only
&& do_header
)
633 coclassdef: coclasshdr
'{' coclass_ints
'}' { $$
= $1;
638 coclass_ints: { $$
= NULL
; }
639 | coclass_ints coclass_int
{ LINK
($2, $1); $$
= $2; }
643 m_attributes interfacedec
{ $$
= make_ifref
($2); $$
->attrs
= $1; }
646 dispinterface: tDISPINTERFACE aIDENTIFIER
{ $$
= get_type
(0, $2, 0); }
647 | tDISPINTERFACE aKNOWNTYPE
{ $$
= get_type
(0, $2, 0); }
650 dispinterfacehdr: attributes dispinterface
{ attr_t
*attrs
;
652 if
($$
->defined
) yyerror("multiple definition error");
653 attrs
= make_attr
(ATTR_DISPINTERFACE
);
656 $$
->ref
= find_type
("IDispatch", 0);
657 if
(!$$
->ref
) yyerror("IDispatch is undefined");
659 if
(!parse_only
&& do_header
) write_forward
($$
);
663 dispint_props: tPROPERTIES
':' { $$
= NULL
; }
664 | dispint_props s_field
';' { LINK
($2, $1); $$
= $2; }
667 dispint_meths: tMETHODS
':' { $$
= NULL
; }
668 | dispint_meths funcdef
';' { LINK
($2, $1); $$
= $2; }
671 dispinterfacedef: dispinterfacehdr
'{'
677 if
(!parse_only
&& do_header
) write_dispinterface
($$
);
679 /* FIXME: not sure how to handle this yet
680 | dispinterfacehdr '{' interface '}' { $$ = $1;
681 if (!parse_only && do_header) write_interface($$);
686 inherit: { $$
= NULL
; }
687 |
':' aKNOWNTYPE
{ $$
= find_type2
($2, 0); }
690 interface: tINTERFACE aIDENTIFIER
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
691 | tINTERFACE aKNOWNTYPE
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
694 interfacehdr: attributes interface
{ $$
= $2;
695 if
($$
->defined
) yyerror("multiple definition error");
698 if
(!parse_only
&& do_header
) write_forward
($$
);
702 interfacedef: interfacehdr inherit
703 '{' int_statements
'}' { $$
= $1;
706 if
(!parse_only
&& do_header
) write_interface
($$
);
708 /* MIDL is able to import the definition of a base class from inside the
709 * definition of a derived class, I'll try to support it with this rule */
710 | interfacehdr
':' aIDENTIFIER
711 '{' import int_statements
'}' { $$
= $1;
712 $$
->ref
= find_type2
($3, 0);
713 if
(!$$
->ref
) yyerror("base class '%s' not found in import", $3);
715 if
(!parse_only
&& do_header
) write_interface
($$
);
717 | dispinterfacedef
{ $$
= $1; }
721 interface
';' { $$
= $1; if
(!parse_only
&& do_header
) write_forward
($$
); }
722 | dispinterface
';' { $$
= $1; if
(!parse_only
&& do_header
) write_forward
($$
); }
725 module: tMODULE aIDENTIFIER
{ $$
= make_type
(0, NULL
); $$
->name
= $2; }
726 | tMODULE aKNOWNTYPE
{ $$
= make_type
(0, NULL
); $$
->name
= $2; }
729 modulehdr: attributes module
{ $$
= $2;
734 moduledef: modulehdr
'{' int_statements
'}' { $$
= $1;
736 /* FIXME: if (!parse_only && do_header) write_module($$); */
740 p_ident: '*' pident %prec PPTR
{ $$
= $2; $$
->ptr_level
++; }
741 | tCONST p_ident
{ $$
= $2; /* FIXME */ }
746 |
'(' pident
')' { $$
= $2; }
751 | pident_list
',' pident
{ LINK
($3, $1); $$
= $3; }
755 tREF
{ $$
= RPC_FC_RP
; }
756 | tUNIQUE
{ $$
= RPC_FC_UP
; }
757 | tPTR
{ $$
= RPC_FC_FP
; }
760 structdef: tSTRUCT t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_STRUCT
, $2, tsSTRUCT
);
761 /* overwrite RPC_FC_STRUCT with a more exact type */
762 $$
->type
= get_struct_type
( $4 );
770 type: tVOID
{ $$
= make_tref
(NULL
, make_type
(0, NULL
)); }
771 | aKNOWNTYPE
{ $$
= make_tref
($1, find_type
($1, 0)); }
772 | base_type
{ $$
= make_tref
(NULL
, $1); }
773 | tCONST type
{ $$
= uniq_tref
($2); $$
->ref
->is_const
= TRUE
; }
774 | enumdef
{ $$
= make_tref
(NULL
, $1); }
775 | tENUM aIDENTIFIER
{ $$
= make_tref
(NULL
, find_type2
($2, tsENUM
)); }
776 | structdef
{ $$
= make_tref
(NULL
, $1); }
777 | tSTRUCT aIDENTIFIER
{ $$
= make_tref
(NULL
, get_type
(RPC_FC_STRUCT
, $2, tsSTRUCT
)); }
778 | uniondef
{ $$
= make_tref
(NULL
, $1); }
779 | tUNION aIDENTIFIER
{ $$
= make_tref
(NULL
, find_type2
($2, tsUNION
)); }
782 typedef: tTYPEDEF m_attributes type pident_list
{ typeref_t
*tref
= uniq_tref
($3);
783 $4->tname
= tref
->name
;
787 if
(!parse_only
&& do_header
)
788 write_typedef
($$
, $4);
789 if
(in_typelib
&& $$
->attrs
)
791 reg_types
($$
, $4, 0);
795 uniondef: tUNION t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_NON_ENCAPSULATED_UNION
, $2, tsUNION
);
800 tSWITCH
'(' s_field
')'
801 m_ident
'{' cases
'}' { var_t
*u
= $7;
802 $$
= get_typev
(RPC_FC_ENCAPSULATED_UNION
, $2, tsUNION
);
803 if
(!u
) u
= make_var
("tagged_union");
804 u
->type
= make_type
(RPC_FC_NON_ENCAPSULATED_UNION
, NULL
);
805 u
->type
->fields
= $9;
806 u
->type
->defined
= TRUE
;
807 LINK
(u
, $5); $$
->fields
= u
;
813 aNUM
{ $$
= MAKELONG
($1, 0); }
814 | aNUM
'.' aNUM
{ $$
= MAKELONG
($1, $3); }
819 static attr_t
*make_attr
(enum attr_type type
)
821 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
828 static attr_t
*make_attrv
(enum attr_type type
, unsigned long val
)
830 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
837 static attr_t
*make_attrp
(enum attr_type type
, void *val
)
839 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
846 static expr_t
*make_expr
(enum expr_type type
)
848 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
857 static expr_t
*make_exprl
(enum expr_type type
, long val
)
859 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
865 /* check for numeric constant */
866 if
(type
== EXPR_NUM || type
== EXPR_HEXNUM || type
== EXPR_TRUEFALSE
) {
867 /* make sure true/false value is valid */
868 assert
(type
!= EXPR_TRUEFALSE || val
== 0 || val
== 1);
875 static expr_t
*make_exprs
(enum expr_type type
, char *val
)
878 e
= xmalloc
(sizeof
(expr_t
));
884 /* check for predefined constants */
885 if
(type
== EXPR_IDENTIFIER
) {
886 var_t
*c
= find_const
(val
, 0);
891 e
->cval
= c
->eval
->cval
;
897 static expr_t
*make_exprt
(enum expr_type type
, typeref_t
*tref
, expr_t
*expr
)
900 e
= xmalloc
(sizeof
(expr_t
));
906 /* check for cast of constant expression */
907 if
(type
== EXPR_SIZEOF
) {
908 switch
(tref
->ref
->type
) {
925 case RPC_FC_ERROR_STATUS_T
:
936 if
(type
== EXPR_CAST
&& expr
->is_const
) {
938 e
->cval
= expr
->cval
;
943 static expr_t
*make_expr1
(enum expr_type type
, expr_t
*expr
)
946 e
= xmalloc
(sizeof
(expr_t
));
952 /* check for compile-time optimization */
953 if
(expr
->is_const
) {
957 e
->cval
= -expr
->cval
;
960 e
->cval
= ~expr
->cval
;
970 static expr_t
*make_expr2
(enum expr_type type
, expr_t
*expr1
, expr_t
*expr2
)
973 e
= xmalloc
(sizeof
(expr_t
));
979 /* check for compile-time optimization */
980 if
(expr1
->is_const
&& expr2
->is_const
) {
984 e
->cval
= expr1
->cval
+ expr2
->cval
;
987 e
->cval
= expr1
->cval
- expr2
->cval
;
990 e
->cval
= expr1
->cval
* expr2
->cval
;
993 e
->cval
= expr1
->cval
/ expr2
->cval
;
996 e
->cval
= expr1
->cval | expr2
->cval
;
999 e
->cval
= expr1
->cval
& expr2
->cval
;
1002 e
->cval
= expr1
->cval
<< expr2
->cval
;
1005 e
->cval
= expr1
->cval
>> expr2
->cval
;
1008 e
->is_const
= FALSE
;
1015 static expr_t
*make_expr3
(enum expr_type type
, expr_t
*expr1
, expr_t
*expr2
, expr_t
*expr3
)
1018 e
= xmalloc
(sizeof
(expr_t
));
1023 e
->is_const
= FALSE
;
1025 /* check for compile-time optimization */
1026 if
(expr1
->is_const
&& expr2
->is_const
&& expr3
->is_const
) {
1030 e
->cval
= expr1
->cval ? expr2
->cval
: expr3
->cval
;
1033 e
->is_const
= FALSE
;
1040 static type_t
*make_type
(unsigned char type
, type_t
*ref
)
1042 type_t
*t
= xmalloc
(sizeof
(type_t
));
1049 t
->ignore
= parse_only
;
1050 t
->is_const
= FALSE
;
1054 t
->typelib_idx
= -1;
1059 static typeref_t
*make_tref
(char *name
, type_t
*ref
)
1061 typeref_t
*t
= xmalloc
(sizeof
(typeref_t
));
1064 t
->uniq
= ref ?
0 : 1;
1068 static typeref_t
*uniq_tref
(typeref_t
*ref
)
1072 if
(t
->uniq
) return t
;
1073 tp
= make_type
(0, t
->ref
);
1081 static type_t
*type_ref
(typeref_t
*ref
)
1083 type_t
*t
= ref
->ref
;
1084 if
(ref
->name
) free
(ref
->name
);
1089 static void set_type
(var_t
*v
, typeref_t
*ref
, expr_t
*arr
)
1092 v
->tname
= ref
->name
;
1098 static ifref_t
*make_ifref
(type_t
*iface
)
1100 ifref_t
*l
= xmalloc
(sizeof
(ifref_t
));
1107 static var_t
*make_var
(char *name
)
1109 var_t
*v
= xmalloc
(sizeof
(var_t
));
1121 static func_t
*make_func
(var_t
*def
, var_t
*args
)
1123 func_t
*f
= xmalloc
(sizeof
(func_t
));
1126 f
->ignore
= parse_only
;
1132 static class_t
*make_class
(char *name
)
1134 class_t
*c
= xmalloc
(sizeof
(class_t
));
1144 static int hash_ident
(const char *name
)
1146 const char *p
= name
;
1148 /* a simple sum hash is probably good enough */
1153 return sum
& (HASHMAX
-1);
1156 /***** type repository *****/
1165 struct rtype
*type_hash
[HASHMAX
];
1167 static type_t
*reg_type
(type_t
*type
, const char *name
, int t
)
1172 yyerror("registering named type without name");
1175 hash
= hash_ident
(name
);
1176 nt
= xmalloc
(sizeof
(struct rtype
));
1180 nt
->next
= type_hash
[hash
];
1181 type_hash
[hash
] = nt
;
1185 /* determine pointer type from attrs */
1186 static unsigned char get_pointer_type
( type_t
*type
)
1189 if
(is_attr
( type
->attrs
, ATTR_STRING
))
1192 while
( t
->type
== 0 && t
->ref
)
1197 return RPC_FC_C_CSTRING
;
1199 return RPC_FC_C_WSTRING
;
1202 t
= get_attrv
( type
->attrs
, ATTR_POINTERTYPE
);
1207 static type_t
*reg_types
(type_t
*type
, var_t
*names
, int t
)
1213 var_t
*next
= NEXT_LINK
(names
);
1216 int cptr
= names
->ptr_level
;
1218 while
(cptr
> ptrc
) {
1219 int t
= get_pointer_type
( cur
);
1220 cur
= ptr
= make_type
(t
, cur
);
1224 while
(cptr
< ptrc
) {
1229 reg_type
(cur
, names
->name
, t
);
1237 static type_t
*find_type
(const char *name
, int t
)
1239 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
1240 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
1243 yyerror("type '%s' not found", name
);
1249 static type_t
*find_type2
(char *name
, int t
)
1251 type_t
*tp
= find_type
(name
, t
);
1256 int is_type
(const char *name
)
1258 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
1259 while
(cur
&& (cur
->t || strcmp
(cur
->name
, name
)))
1261 if
(cur
) return TRUE
;
1265 static type_t
*get_type
(unsigned char type
, char *name
, int t
)
1267 struct rtype
*cur
= NULL
;
1270 cur
= type_hash
[hash_ident
(name
)];
1271 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
1278 tp
= make_type
(type
, NULL
);
1280 if
(!name
) return tp
;
1281 return reg_type
(tp
, name
, t
);
1284 static type_t
*get_typev
(unsigned char type
, var_t
*name
, int t
)
1291 return get_type
(type
, sname
, t
);
1294 static int get_struct_type
(var_t
*field
)
1296 int has_pointer
= 0;
1297 int has_conformance
= 0;
1298 int has_variance
= 0;
1300 for
(; field
; field
= NEXT_LINK
(field
))
1302 type_t
*t
= field
->type
;
1304 /* get the base type */
1305 while
( (t
->type
== 0) && t
->ref
)
1308 if
(field
->ptr_level
> 0)
1314 if
(is_string_type
(field
->attrs
, 0, field
->array
))
1316 has_conformance
= 1;
1321 if
(is_array_type
(field
->attrs
, 0, field
->array
))
1323 if
(field
->array
&& !field
->array
->is_const
)
1325 has_conformance
= 1;
1326 if
(PREV_LINK
(field
))
1327 yyerror("field '%s' deriving from a conformant array must be the last field in the structure",
1330 if
(is_attr
(field
->attrs
, ATTR_LENGTHIS
))
1337 * RPC_FC_BYTE, RPC_FC_STRUCT, etc
1338 * Simple types don't effect the type of struct.
1339 * A struct containing a simple struct is still a simple struct.
1340 * So long as we can block copy the data, we return RPC_FC_STRUCT.
1342 case
0: /* void pointer */
1352 case RPC_FC_INT3264
:
1353 case RPC_FC_UINT3264
:
1367 has_conformance
= 1;
1368 if
(PREV_LINK
(field
))
1369 yyerror("field '%s' deriving from a conformant array must be the last field in the structure",
1372 case RPC_FC_C_CSTRING
:
1373 case RPC_FC_C_WSTRING
:
1374 has_conformance
= 1;
1379 * Propagate member attributes
1380 * a struct should be at least as complex as its member
1382 case RPC_FC_CVSTRUCT
:
1383 has_conformance
= 1;
1388 case RPC_FC_CPSTRUCT
:
1389 has_conformance
= 1;
1390 if
(PREV_LINK
(field
))
1391 yyerror("field '%s' deriving from a conformant array must be the last field in the structure",
1396 case RPC_FC_CSTRUCT
:
1397 has_conformance
= 1;
1398 if
(PREV_LINK
(field
))
1399 yyerror("field '%s' deriving from a conformant array must be the last field in the structure",
1403 case RPC_FC_PSTRUCT
:
1408 fprintf
(stderr
,"Unknown struct member %s with type (0x%02x)\n",
1409 field
->name
, t
->type
);
1410 /* fallthru - treat it as complex */
1412 /* as soon as we see one of these these members, it's bogus... */
1414 case RPC_FC_ENCAPSULATED_UNION
:
1415 case RPC_FC_NON_ENCAPSULATED_UNION
:
1416 case RPC_FC_TRANSMIT_AS
:
1417 case RPC_FC_REPRESENT_AS
:
1419 case RPC_FC_EMBEDDED_COMPLEX
:
1420 case RPC_FC_BOGUS_STRUCT
:
1421 return RPC_FC_BOGUS_STRUCT
;
1426 return RPC_FC_CVSTRUCT
;
1427 if
( has_conformance
&& has_pointer
)
1428 return RPC_FC_CPSTRUCT
;
1429 if
( has_conformance
)
1430 return RPC_FC_CSTRUCT
;
1432 return RPC_FC_PSTRUCT
;
1433 return RPC_FC_STRUCT
;
1436 /***** constant repository *****/
1441 struct rconst
*next
;
1444 struct rconst
*const_hash
[HASHMAX
];
1446 static var_t
*reg_const
(var_t
*var
)
1451 yyerror("registering constant without name");
1454 hash
= hash_ident
(var
->name
);
1455 nc
= xmalloc
(sizeof
(struct rconst
));
1456 nc
->name
= var
->name
;
1458 nc
->next
= const_hash
[hash
];
1459 const_hash
[hash
] = nc
;
1463 static var_t
*find_const
(char *name
, int f
)
1465 struct rconst
*cur
= const_hash
[hash_ident
(name
)];
1466 while
(cur
&& strcmp
(cur
->name
, name
))
1469 if
(f
) yyerror("constant '%s' not found", name
);