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
40 /* Berkeley yacc (byacc) doesn't seem to know about these */
41 /* Some *BSD supplied versions do define these though */
43 # define YYEMPTY (-1) /* Empty lookahead value of yychar */
46 # define YYLEX yylex()
49 #elif defined(YYBISON)
50 /* Bison was used for original development */
51 /* #define YYEMPTY -2 */
52 /* #define YYLEX yylex() */
55 /* No yacc we know yet */
56 # if !defined(YYEMPTY) || !defined(YYLEX)
57 # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
58 # elif defined(__GNUC__) /* gcc defines the #warning directive */
59 # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
60 /* #else we just take a chance that it works... */
64 static attr_t
*make_attr
(enum attr_type type
);
65 static attr_t
*make_attrv
(enum attr_type type
, DWORD val
);
66 static attr_t
*make_attrp
(enum attr_type type
, void *val
);
67 static expr_t
*make_expr
(enum expr_type type
);
68 static expr_t
*make_exprl
(enum expr_type type
, long val
);
69 static expr_t
*make_exprs
(enum expr_type type
, char *val
);
70 static expr_t
*make_exprt
(enum expr_type type
, typeref_t
*tref
, expr_t
*expr
);
71 static expr_t
*make_expr1
(enum expr_type type
, expr_t
*expr
);
72 static expr_t
*make_expr2
(enum expr_type type
, expr_t
*exp1
, expr_t
*exp2
);
73 static type_t
*make_type
(BYTE type
, type_t
*ref
);
74 static typeref_t
*make_tref
(char *name
, type_t
*ref
);
75 static typeref_t
*uniq_tref
(typeref_t
*ref
);
76 static type_t
*type_ref
(typeref_t
*ref
);
77 static void set_type
(var_t
*v
, typeref_t
*ref
, expr_t
*arr
);
78 static var_t
*make_var
(char *name
);
79 static func_t
*make_func
(var_t
*def
, var_t
*args
);
81 static type_t
*reg_type
(type_t
*type
, char *name
, int t
);
82 static type_t
*reg_types
(type_t
*type
, var_t
*names
, int t
);
83 static type_t
*find_type
(char *name
, int t
);
84 static type_t
*find_type2
(char *name
, int t
);
85 static type_t
*get_type
(BYTE type
, char *name
, int t
);
86 static type_t
*get_typev
(BYTE type
, var_t
*name
, int t
);
88 static var_t
*reg_const
(var_t
*var
);
89 static var_t
*find_const
(char *name
, int f
);
95 static type_t std_bool
= { "boolean" };
96 static type_t std_int
= { "int" };
97 static type_t std_int64
= { "__int64" };
98 static type_t std_uhyper
= { "MIDL_uhyper" };
113 %token
<str
> aIDENTIFIER
114 %token
<str
> aKNOWNTYPE
115 %token
<num
> aNUM aHEXNUM
120 %token tAGGREGATABLE tALLOCATE tAPPOBJECT tARRAYS tASYNC tASYNCUUID
121 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
122 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
123 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
124 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
127 %token tENUM tERRORSTATUST
134 %token tIMPORT tIMPORTLIB
135 %token tIN tINCLUDE tINLINE
141 %token tOBJECT tODL tOLEAUTOMATION
143 %token tPOINTERDEFAULT
147 %token tSIZEIS tSIZEOF
149 %token tSTRING tSTRUCT
150 %token tSWITCH tSWITCHIS tSWITCHTYPE
159 %token tWCHAR tWIREMARSHAL
164 %type
<attr
> m_attributes attributes attrib_list attribute
165 %type
<expr
> m_exprs
/* exprs expr_list */ m_expr expr expr_list_const expr_const
166 %type
<expr
> array array_list
167 %type
<type
> inherit interface interfacehdr interfacedef lib_statements
168 %type
<type
> base_type int_std
169 %type
<type
> enumdef structdef typedef uniondef
171 %type
<var
> m_args no_args args arg
172 %type
<var
> fields field s_field cases case enums enum_list
enum constdef externdef
173 %type
<var
> m_ident t_ident ident p_ident pident pident_list
174 %type
<func
> funcdef int_statements
175 %type
<num
> pointer_type version
190 input: lib_statements
{ /* FIXME */ }
193 lib_statements: { $$
= NULL
; }
194 | lib_statements interface
';' { if
(!parse_only
) write_forward
($2); }
195 | lib_statements interfacedef
{ LINK
($2, $1); $$
= $2; }
196 /* | lib_statements librarydef (when implemented) */
197 | lib_statements statement
200 int_statements: { $$
= NULL
; }
201 | int_statements funcdef
';' { LINK
($2, $1); $$
= $2; }
202 | int_statements statement
206 | constdef
';' { if
(!parse_only
) { write_constdef
($1); } }
208 | enumdef
';' { if
(!parse_only
) { write_type
(header
, $1, NULL
, NULL
); fprintf
(header
, ";\n\n"); } }
209 | externdef
';' { if
(!parse_only
) { write_externdef
($1); } }
211 /* | interface ';' {} */
212 /* | interfacedef {} */
213 | structdef
';' { if
(!parse_only
) { write_type
(header
, $1, NULL
, NULL
); fprintf
(header
, ";\n\n"); } }
215 | uniondef
';' { if
(!parse_only
) { write_type
(header
, $1, NULL
, NULL
); fprintf
(header
, ";\n\n"); } }
218 cppquote: tCPPQUOTE
'(' aSTRING
')' { if
(!parse_only
) fprintf
(header
, "%s\n", $3); }
220 import_start: tIMPORT aSTRING
';' { assert
(yychar == YYEMPTY
);
221 if
(!do_import
($2)) yychar = aEOF
; }
223 import: import_start input aEOF
{}
226 m_args: { $$
= NULL
; }
230 no_args: tVOID
{ $$
= NULL
; }
234 | args
',' arg
{ LINK
($3, $1); $$
= $3; }
238 /* split into two rules to get bison to resolve a tVOID conflict */
239 arg: attributes type pident array
{ $$
= $3;
240 set_type
($$
, $2, $4);
243 | type pident array
{ $$
= $2;
244 set_type
($$
, $1, $3);
248 array: { $$
= NULL
; }
249 |
'[' array_list
']' { $$
= $2; }
250 |
'[' '*' ']' { $$
= make_expr
(EXPR_VOID
); }
253 array_list: m_expr
/* size of first dimension is optional */
254 | array_list
',' expr
{ LINK
($3, $1); $$
= $3; }
255 | array_list
']' '[' expr
{ LINK
($4, $1); $$
= $4; }
258 m_attributes: { $$
= NULL
; }
263 '[' attrib_list
']' { $$
= $2; }
266 attrib_list: attribute
267 | attrib_list
',' attribute
{ LINK
($3, $1); $$
= $3; }
268 | attrib_list
']' '[' attribute
{ LINK
($4, $1); $$
= $4; }
272 tASYNC
{ $$
= make_attr
(ATTR_ASYNC
); }
273 | tCALLAS
'(' ident
')' { $$
= make_attrp
(ATTR_CALLAS
, $3); }
274 | tCASE
'(' expr_list_const
')' { $$
= make_attrp
(ATTR_CASE
, $3); }
275 | tCONTEXTHANDLE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); }
276 | tCONTEXTHANDLENOSERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
277 | tCONTEXTHANDLESERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
278 | tDEFAULT
{ $$
= make_attr
(ATTR_DEFAULT
); }
279 | tIDEMPOTENT
{ $$
= make_attr
(ATTR_IDEMPOTENT
); }
280 | tIIDIS
'(' ident
')' { $$
= make_attrp
(ATTR_IIDIS
, $3); }
281 | tIN
{ $$
= make_attr
(ATTR_IN
); }
282 | tLENGTHIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_LENGTHIS
, $3); }
283 | tLOCAL
{ $$
= make_attr
(ATTR_LOCAL
); }
284 | tOBJECT
{ $$
= make_attr
(ATTR_OBJECT
); }
285 | tOLEAUTOMATION
{ $$
= make_attr
(ATTR_OLEAUTOMATION
); }
286 | tOUT
{ $$
= make_attr
(ATTR_OUT
); }
287 | tPOINTERDEFAULT
'(' pointer_type
')' { $$
= make_attrv
(ATTR_POINTERDEFAULT
, $3); }
288 | tSIZEIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_SIZEIS
, $3); }
289 | tSTRING
{ $$
= make_attr
(ATTR_STRING
); }
290 | tSWITCHIS
'(' expr
')' { $$
= make_attrp
(ATTR_SWITCHIS
, $3); }
291 | tSWITCHTYPE
'(' type
')' { $$
= make_attrp
(ATTR_SWITCHTYPE
, type_ref
($3)); }
292 | tUUID
'(' aUUID
')' { $$
= make_attrp
(ATTR_UUID
, $3); }
293 | tV1ENUM
{ $$
= make_attr
(ATTR_V1ENUM
); }
294 | tVERSION
'(' version
')' { $$
= make_attrv
(ATTR_VERSION
, $3); }
295 | tWIREMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_WIREMARSHAL
, type_ref
($3)); }
296 | pointer_type
{ $$
= make_attrv
(ATTR_POINTERTYPE
, $1); }
303 cases: { $$
= NULL
; }
304 | cases case
{ if
($2) { LINK
($2, $1); $$
= $2; }
309 case: tCASE expr
':' field
{ attr_t
*a
= make_attrp
(ATTR_CASE
, $2);
310 $$
= $4; if
(!$$
) $$
= make_var
(NULL
);
311 LINK
(a
, $$
->attrs
); $$
->attrs
= a
;
313 | tDEFAULT
':' field
{ attr_t
*a
= make_attr
(ATTR_DEFAULT
);
314 $$
= $3; if
(!$$
) $$
= make_var
(NULL
);
315 LINK
(a
, $$
->attrs
); $$
->attrs
= a
;
319 constdef: tCONST type ident
'=' expr_const
{ $$
= reg_const
($3);
320 set_type
($$
, $2, NULL
);
326 enums: { $$
= NULL
; }
327 | enum_list
',' { $$
= $1; }
332 | enum_list
',' enum { LINK
($3, $1); $$
= $3;
334 $3->lval
= $1->lval
+ 1;
338 enum: ident
'=' expr_const
{ $$
= reg_const
($1);
342 | ident
{ $$
= reg_const
($1);
343 $$
->lval
= 0; /* default for first enum entry */
347 enumdef: tENUM t_ident
'{' enums
'}' { $$
= get_typev
(RPC_FC_ENUM16
, $2, tsENUM
);
354 | m_exprs
',' m_expr
{ LINK
($3, $1); $$
= $3; }
358 exprs: { $$ = make_expr(EXPR_VOID); }
363 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
367 m_expr: { $$
= make_expr
(EXPR_VOID
); }
371 expr: aNUM
{ $$
= make_exprl
(EXPR_NUM
, $1); }
372 | aHEXNUM
{ $$
= make_exprl
(EXPR_HEXNUM
, $1); }
373 | aIDENTIFIER
{ $$
= make_exprs
(EXPR_IDENTIFIER
, $1); }
374 | expr
'|' expr
{ $$
= make_expr2
(EXPR_OR
, $1, $3); }
375 | expr
'&' expr
{ $$
= make_expr2
(EXPR_AND
, $1, $3); }
376 | expr
'+' expr
{ $$
= make_expr2
(EXPR_ADD
, $1, $3); }
377 | expr
'-' expr
{ $$
= make_expr2
(EXPR_SUB
, $1, $3); }
378 | expr
'*' expr
{ $$
= make_expr2
(EXPR_MUL
, $1, $3); }
379 | expr
'/' expr
{ $$
= make_expr2
(EXPR_DIV
, $1, $3); }
380 | expr SHL expr
{ $$
= make_expr2
(EXPR_SHL
, $1, $3); }
381 | expr SHR expr
{ $$
= make_expr2
(EXPR_SHR
, $1, $3); }
382 |
'~' expr
{ $$
= make_expr1
(EXPR_NOT
, $2); }
383 |
'-' expr %prec NEG
{ $$
= make_expr1
(EXPR_NEG
, $2); }
384 |
'*' expr %prec PPTR
{ $$
= make_expr1
(EXPR_PPTR
, $2); }
385 |
'(' type
')' expr %prec CAST
{ $$
= make_exprt
(EXPR_CAST
, $2, $4); }
386 | tSIZEOF
'(' type
')' { $$
= make_exprt
(EXPR_SIZEOF
, $3, NULL
); }
387 |
'(' expr
')' { $$
= $2; }
390 expr_list_const: expr_const
391 | expr_list_const
',' expr_const
{ LINK
($3, $1); $$
= $3; }
394 expr_const: expr
{ $$
= $1;
395 if
(!$$
->is_const
) yyerror("expression is not constant\n");
399 externdef: tEXTERN tCONST type ident
{ $$
= $4;
400 set_type
($$
, $3, NULL
);
404 fields: { $$
= NULL
; }
405 | fields field
{ if
($2) { LINK
($2, $1); $$
= $2; }
410 field: s_field
';' { $$
= $1; }
411 | m_attributes uniondef
';' { $$
= make_var
(NULL
); $$
->type
= $2; $$
->attrs
= $1; }
412 | attributes
';' { $$
= make_var
(NULL
); $$
->attrs
= $1; }
416 s_field: m_attributes type pident array
{ $$
= $3; set_type
($$
, $2, $4); $$
->attrs
= $1; }
420 m_attributes type callconv pident
421 '(' m_args
')' { set_type
($4, $2, NULL
);
423 $$
= make_func
($4, $6);
427 m_ident: { $$
= NULL
; }
431 t_ident: { $$
= NULL
; }
432 | aIDENTIFIER
{ $$
= make_var
($1); }
433 | aKNOWNTYPE
{ $$
= make_var
($1); }
436 ident: aIDENTIFIER
{ $$
= make_var
($1); }
437 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
438 | tVERSION
{ $$
= make_var
($
<str
>1); }
441 base_type: tBYTE
{ $$
= make_type
(RPC_FC_BYTE
, NULL
); }
442 | tWCHAR
{ $$
= make_type
(RPC_FC_WCHAR
, NULL
); }
444 | tSIGNED int_std
{ $$
= $2; $$
->sign
= 1; }
445 | tUNSIGNED int_std
{ $$
= $2; $$
->sign
= -1;
447 case RPC_FC_SMALL
: $$
->type
= RPC_FC_USMALL
; break
;
448 case RPC_FC_SHORT
: $$
->type
= RPC_FC_USHORT
; break
;
449 case RPC_FC_LONG
: $$
->type
= RPC_FC_ULONG
; break
;
451 if
(!$$
->ref
) { $$
->ref
= &std_uhyper
; $$
->sign
= 0; }
456 | tFLOAT
{ $$
= make_type
(RPC_FC_FLOAT
, NULL
); }
457 | tDOUBLE
{ $$
= make_type
(RPC_FC_DOUBLE
, NULL
); }
458 | tBOOLEAN
{ $$
= make_type
(RPC_FC_BYTE
, &std_bool
); /* ? */ }
459 | tERRORSTATUST
{ $$
= make_type
(RPC_FC_ERROR_STATUS_T
, NULL
); }
460 | tHANDLET
{ $$
= make_type
(RPC_FC_BIND_PRIMITIVE
, NULL
); /* ? */ }
467 int_std: tINT
{ $$
= make_type
(RPC_FC_LONG
, &std_int
); } /* win32 only */
468 | tSHORT m_int
{ $$
= make_type
(RPC_FC_SHORT
, NULL
); }
469 | tLONG m_int
{ $$
= make_type
(RPC_FC_LONG
, NULL
); }
470 | tHYPER m_int
{ $$
= make_type
(RPC_FC_HYPER
, NULL
); }
471 | tINT64
{ $$
= make_type
(RPC_FC_HYPER
, &std_int64
); }
472 | tCHAR
{ $$
= make_type
(RPC_FC_CHAR
, NULL
); }
475 inherit: { $$
= NULL
; }
476 |
':' aKNOWNTYPE
{ $$
= find_type2
($2, 0); }
479 interface: tINTERFACE aIDENTIFIER
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
480 | tINTERFACE aKNOWNTYPE
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
483 interfacehdr: attributes interface
{ $$
= $2;
484 if
($$
->defined
) yyerror("multiple definition error\n");
487 if
(!parse_only
) write_forward
($$
);
491 interfacedef: interfacehdr inherit
492 '{' int_statements
'}' { $$
= $1;
495 if
(!parse_only
) write_interface
($$
);
497 /* MIDL is able to import the definition of a base class from inside the
498 * definition of a derived class, I'll try to support it with this rule */
499 | interfacehdr
':' aIDENTIFIER
500 '{' import int_statements
'}' { $$
= $1;
501 $$
->ref
= find_type2
($3, 0);
502 if
(!$$
->ref
) yyerror("base class %s not found in import\n", $3);
504 if
(!parse_only
) write_interface
($$
);
508 p_ident: '*' pident %prec PPTR
{ $$
= $2; $$
->ptr_level
++; }
509 | tCONST p_ident
{ $$
= $2; /* FIXME */ }
514 |
'(' pident
')' { $$
= $2; }
519 | pident_list
',' pident
{ LINK
($3, $1); $$
= $3; }
523 tREF
{ $$
= RPC_FC_RP
; }
524 | tUNIQUE
{ $$
= RPC_FC_UP
; }
527 structdef: tSTRUCT t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_STRUCT
, $2, tsSTRUCT
);
533 type: tVOID
{ $$
= make_tref
(NULL
, make_type
(0, NULL
)); }
534 | aKNOWNTYPE
{ $$
= make_tref
($1, find_type
($1, 0)); }
535 | base_type
{ $$
= make_tref
(NULL
, $1); }
536 | tCONST type
{ $$
= uniq_tref
($2); $$
->ref
->is_const
= TRUE
; }
537 | enumdef
{ $$
= make_tref
(NULL
, $1); }
538 | tENUM aIDENTIFIER
{ $$
= make_tref
(NULL
, find_type2
($2, tsENUM
)); }
539 | structdef
{ $$
= make_tref
(NULL
, $1); }
540 | tSTRUCT aIDENTIFIER
{ $$
= make_tref
(NULL
, get_type
(RPC_FC_STRUCT
, $2, tsSTRUCT
)); }
541 | uniondef
{ $$
= make_tref
(NULL
, $1); }
542 | tUNION aIDENTIFIER
{ $$
= make_tref
(NULL
, find_type2
($2, tsUNION
)); }
545 typedef: tTYPEDEF m_attributes type pident_list
{ typeref_t
*tref
= uniq_tref
($3);
546 $4->tname
= tref
->name
;
550 if
(!parse_only
) write_typedef
($$
, $4);
551 reg_types
($$
, $4, 0);
555 uniondef: tUNION t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_NON_ENCAPSULATED_UNION
, $2, tsUNION
);
560 tSWITCH
'(' s_field
')'
561 m_ident
'{' cases
'}' { var_t
*u
= $7;
562 $$
= get_typev
(RPC_FC_ENCAPSULATED_UNION
, $2, tsUNION
);
563 if
(!u
) u
= make_var
("tagged_union");
564 u
->type
= make_type
(RPC_FC_NON_ENCAPSULATED_UNION
, NULL
);
565 u
->type
->fields
= $9;
566 u
->type
->defined
= TRUE
;
567 LINK
(u
, $5); $$
->fields
= u
;
573 aNUM
{ $$
= MAKELONG
($1, 0); }
574 | aNUM
'.' aNUM
{ $$
= MAKELONG
($1, $3); }
579 static attr_t
*make_attr
(enum attr_type type
)
581 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
588 static attr_t
*make_attrv
(enum attr_type type
, DWORD val
)
590 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
597 static attr_t
*make_attrp
(enum attr_type type
, void *val
)
599 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
606 static expr_t
*make_expr
(enum expr_type type
)
608 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
617 static expr_t
*make_exprl
(enum expr_type type
, long val
)
619 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
625 /* check for numeric constant */
626 if
(type
== EXPR_NUM || type
== EXPR_HEXNUM
) {
633 static expr_t
*make_exprs
(enum expr_type type
, char *val
)
636 e
= xmalloc
(sizeof
(expr_t
));
642 /* check for predefined constants */
643 if
(type
== EXPR_IDENTIFIER
) {
644 var_t
*c
= find_const
(val
, 0);
655 static expr_t
*make_exprt
(enum expr_type type
, typeref_t
*tref
, expr_t
*expr
)
658 e
= xmalloc
(sizeof
(expr_t
));
664 /* check for cast of constant expression */
665 if
(type
== EXPR_CAST
&& expr
->is_const
) {
667 e
->cval
= expr
->cval
;
672 static expr_t
*make_expr1
(enum expr_type type
, expr_t
*expr
)
675 e
= xmalloc
(sizeof
(expr_t
));
681 /* check for compile-time optimization */
682 if
(expr
->is_const
) {
686 e
->cval
= -expr
->cval
;
689 e
->cval
= ~expr
->cval
;
699 static expr_t
*make_expr2
(enum expr_type type
, expr_t
*expr1
, expr_t
*expr2
)
702 e
= xmalloc
(sizeof
(expr_t
));
708 /* check for compile-time optimization */
709 if
(expr1
->is_const
&& expr2
->is_const
) {
713 e
->cval
= expr1
->cval
+ expr2
->cval
;
716 e
->cval
= expr1
->cval
- expr2
->cval
;
719 e
->cval
= expr1
->cval
* expr2
->cval
;
722 e
->cval
= expr1
->cval
/ expr2
->cval
;
725 e
->cval
= expr1
->cval | expr2
->cval
;
728 e
->cval
= expr1
->cval
& expr2
->cval
;
731 e
->cval
= expr1
->cval
<< expr2
->cval
;
734 e
->cval
= expr1
->cval
>> expr2
->cval
;
744 static type_t
*make_type
(BYTE type
, type_t
*ref
)
746 type_t
*t
= xmalloc
(sizeof
(type_t
));
754 t
->ignore
= parse_only
;
763 static typeref_t
*make_tref
(char *name
, type_t
*ref
)
765 typeref_t
*t
= xmalloc
(sizeof
(typeref_t
));
768 t
->uniq
= ref ?
0 : 1;
772 static typeref_t
*uniq_tref
(typeref_t
*ref
)
776 if
(t
->uniq
) return t
;
777 tp
= make_type
(0, t
->ref
);
785 static type_t
*type_ref
(typeref_t
*ref
)
787 type_t
*t
= ref
->ref
;
788 if
(ref
->name
) free
(ref
->name
);
793 static void set_type
(var_t
*v
, typeref_t
*ref
, expr_t
*arr
)
796 v
->tname
= ref
->name
;
802 static var_t
*make_var
(char *name
)
804 var_t
*v
= xmalloc
(sizeof
(var_t
));
817 static func_t
*make_func
(var_t
*def
, var_t
*args
)
819 func_t
*f
= xmalloc
(sizeof
(func_t
));
822 f
->ignore
= parse_only
;
830 static int hash_ident
(const char *name
)
832 const char *p
= name
;
834 /* a simple sum hash is probably good enough */
839 return sum
& (HASHMAX
-1);
842 /***** type repository *****/
851 struct rtype
*type_hash
[HASHMAX
];
853 static type_t
*reg_type
(type_t
*type
, char *name
, int t
)
858 yyerror("registering named type without name\n");
861 hash
= hash_ident
(name
);
862 nt
= xmalloc
(sizeof
(struct rtype
));
866 nt
->next
= type_hash
[hash
];
867 type_hash
[hash
] = nt
;
871 static type_t
*reg_types
(type_t
*type
, var_t
*names
, int t
)
877 var_t
*next
= NEXT_LINK
(names
);
880 int cptr
= names
->ptr_level
;
882 while
(cptr
> ptrc
) {
883 cur
= ptr
= make_type
(RPC_FC_FP
, cur
); /* FIXME: pointer type from attrs? */
887 while
(cptr
< ptrc
) {
892 reg_type
(cur
, names
->name
, t
);
900 static type_t
*find_type
(char *name
, int t
)
902 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
903 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
906 yyerror("type %s not found\n", name
);
912 static type_t
*find_type2
(char *name
, int t
)
914 type_t
*tp
= find_type
(name
, t
);
919 int is_type
(const char *name
)
921 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
922 while
(cur
&& (cur
->t || strcmp
(cur
->name
, name
)))
924 if
(cur
) return TRUE
;
928 static type_t
*get_type
(BYTE type
, char *name
, int t
)
930 struct rtype
*cur
= NULL
;
933 cur
= type_hash
[hash_ident
(name
)];
934 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
941 tp
= make_type
(type
, NULL
);
943 if
(!name
) return tp
;
944 return reg_type
(tp
, name
, t
);
947 static type_t
*get_typev
(BYTE type
, var_t
*name
, int t
)
954 return get_type
(type
, sname
, t
);
957 /***** constant repository *****/
965 struct rconst
*const_hash
[HASHMAX
];
967 static var_t
*reg_const
(var_t
*var
)
972 yyerror("registering constant without name\n");
975 hash
= hash_ident
(var
->name
);
976 nc
= xmalloc
(sizeof
(struct rconst
));
977 nc
->name
= var
->name
;
979 nc
->next
= const_hash
[hash
];
980 const_hash
[hash
] = nc
;
984 static var_t
*find_const
(char *name
, int f
)
986 struct rconst
*cur
= const_hash
[hash_ident
(name
)];
987 while
(cur
&& strcmp
(cur
->name
, name
))
990 if
(f
) yyerror("constant %s not found\n", name
);