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" };
111 %token
<str
> aIDENTIFIER
112 %token
<str
> aKNOWNTYPE
113 %token
<num
> aNUM aHEXNUM
118 %token tAGGREGATABLE tALLOCATE tAPPOBJECT tARRAYS tASYNC tASYNCUUID
119 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
120 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
121 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
122 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
130 %token tIMPORT tIMPORTLIB
131 %token tIN tINCLUDE tINLINE
137 %token tOBJECT tODL tOLEAUTOMATION
139 %token tPOINTERDEFAULT
143 %token tSIZEIS tSIZEOF
145 %token tSTRING tSTRUCT
146 %token tSWITCH tSWITCHIS tSWITCHTYPE
155 %token tWCHAR tWIREMARSHAL
160 %type
<attr
> m_attributes attributes attrib_list attribute
161 %type
<expr
> exprs expr_list expr array expr_const
162 %type
<type
> inherit interface interfacehdr interfacedef lib_statements
163 %type
<type
> base_type int_std
164 %type
<type
> enumdef structdef typedef uniondef
166 %type
<var
> m_args no_args args arg
167 %type
<var
> fields field s_field cases case enums enum_list
enum constdef externdef
168 %type
<var
> m_ident t_ident ident p_ident pident pident_list
169 %type
<func
> funcdef int_statements
170 %type
<num
> pointer_type
184 input: lib_statements
{ /* FIXME */ }
187 lib_statements: { $$
= NULL
; }
188 | lib_statements interface
';' { if
(!parse_only
) write_forward
($2); }
189 | lib_statements interfacedef
{ LINK
($2, $1); $$
= $2; }
190 /* | lib_statements librarydef (when implemented) */
191 | lib_statements statement
194 int_statements: { $$
= NULL
; }
195 | int_statements funcdef
';' { LINK
($2, $1); $$
= $2; }
196 | int_statements statement
200 | constdef
';' { if
(!parse_only
) { write_constdef
($1); } }
202 | enumdef
';' { if
(!parse_only
) { write_type
(header
, $1, NULL
, NULL
); fprintf
(header
, ";\n\n"); } }
203 | externdef
';' { if
(!parse_only
) { write_externdef
($1); } }
205 /* | interface ';' {} */
206 /* | interfacedef {} */
207 | structdef
';' { if
(!parse_only
) { write_type
(header
, $1, NULL
, NULL
); fprintf
(header
, ";\n\n"); } }
209 | uniondef
';' { if
(!parse_only
) { write_type
(header
, $1, NULL
, NULL
); fprintf
(header
, ";\n\n"); } }
212 cppquote: tCPPQUOTE
'(' aSTRING
')' { if
(!parse_only
) fprintf
(header
, "%s\n", $3); }
214 import_start: tIMPORT aSTRING
';' { assert
(yychar == YYEMPTY
);
215 if
(!do_import
($2)) yychar = aEOF
; }
217 import: import_start input aEOF
{}
220 m_args: { $$
= NULL
; }
224 no_args: tVOID
{ $$
= NULL
; }
228 | args
',' arg
{ LINK
($3, $1); $$
= $3; }
232 /* split into two rules to get bison to resolve a tVOID conflict */
233 arg: attributes type pident array
{ $$
= $3;
234 set_type
($$
, $2, $4);
237 | type pident array
{ $$
= $2;
238 set_type
($$
, $1, $3);
242 array: { $$
= NULL
; }
243 |
'[' exprs
']' { $$
= $2; }
244 |
'[' '*' ']' { $$
= make_expr
(EXPR_VOID
); }
247 m_attributes: { $$
= NULL
; }
252 m_attributes
'[' attrib_list
']' { LINK_LAST
($3, $1); $$
= $3; }
255 attrib_list: attribute
256 | attrib_list
',' attribute
{ LINK_SAFE
($3, $1); $$
= $3; /* FIXME: don't use SAFE */ }
260 tASYNC
{ $$
= make_attr
(ATTR_ASYNC
); }
261 | tCALLAS
'(' ident
')' { $$
= make_attrp
(ATTR_CALLAS
, $3); }
262 | tCASE
'(' expr_list
')' { $$
= NULL
; }
263 | tCONTEXTHANDLE
{ $$
= NULL
; }
264 | tCONTEXTHANDLENOSERIALIZE
{ $$
= NULL
; }
265 | tCONTEXTHANDLESERIALIZE
{ $$
= NULL
; }
266 | tDEFAULT
{ $$
= make_attr
(ATTR_DEFAULT
); }
267 | tIIDIS
'(' ident
')' { $$
= make_attrp
(ATTR_IIDIS
, $3); }
268 | tIN
{ $$
= make_attr
(ATTR_IN
); }
269 | tLENGTHIS
'(' exprs
')' { $$
= NULL
; }
270 | tLOCAL
{ $$
= make_attr
(ATTR_LOCAL
); }
271 | tOBJECT
{ $$
= make_attr
(ATTR_OBJECT
); }
272 | tOLEAUTOMATION
{ $$
= make_attr
(ATTR_OLEAUTOMATION
); }
273 | tOUT
{ $$
= make_attr
(ATTR_OUT
); }
274 | tPOINTERDEFAULT
'(' pointer_type
')' { $$
= make_attrv
(ATTR_POINTERDEFAULT
, $3); }
275 | tSIZEIS
'(' exprs
')' { $$
= NULL
; }
276 | tSTRING
{ $$
= make_attr
(ATTR_STRING
); }
277 | tSWITCHIS
'(' expr
')' { $$
= NULL
; }
278 | tSWITCHTYPE
'(' type
')' { $$
= NULL
; }
279 | tUUID
'(' aUUID
')' { $$
= make_attrp
(ATTR_UUID
, $3); }
280 | tV1ENUM
{ $$
= make_attr
(ATTR_V1ENUM
); }
281 | tVERSION
'(' version
')' { $$
= NULL
; }
282 | tWIREMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_WIREMARSHAL
, type_ref
($3)); }
283 | pointer_type
{ $$
= make_attrv
(ATTR_POINTERTYPE
, $1); }
290 cases: { $$
= NULL
; }
291 | cases case
{ if
($2) { LINK
($2, $1); $$
= $2; }
296 case: tCASE expr
':' field
{ /* attr_t *a = NULL; */ /* FIXME */
297 $$
= $4; if
(!$$
) $$
= make_var
(NULL
);
298 /* LINK(a, $$->attrs); $$->attrs = a; */
300 | tDEFAULT
':' field
{ attr_t
*a
= make_attr
(ATTR_DEFAULT
);
301 $$
= $3; if
(!$$
) $$
= make_var
(NULL
);
302 LINK
(a
, $$
->attrs
); $$
->attrs
= a
;
306 constdef: tCONST type ident
'=' expr_const
{ $$
= reg_const
($3);
307 set_type
($$
, $2, NULL
);
313 enums: { $$
= NULL
; }
314 | enum_list
',' { $$
= $1; }
319 | enum_list
',' enum { LINK
($3, $1); $$
= $3;
321 $3->lval
= $1->lval
+ 1;
325 enum: ident
'=' expr_const
{ $$
= reg_const
($1);
329 | ident
{ $$
= reg_const
($1);
330 $$
->lval
= 0; /* default for first enum entry */
334 enumdef: tENUM t_ident
'{' enums
'}' { $$
= get_typev
(RPC_FC_ENUM16
, $2, tsENUM
);
340 exprs: { $$
= make_expr
(EXPR_VOID
); }
345 | expr_list
',' expr
{ LINK
($3, $1); $$
= $3; }
348 expr: aNUM
{ $$
= make_exprl
(EXPR_NUM
, $1); }
349 | aHEXNUM
{ $$
= make_exprl
(EXPR_HEXNUM
, $1); }
350 | aIDENTIFIER
{ $$
= make_exprs
(EXPR_IDENTIFIER
, $1); }
351 | expr
'|' expr
{ $$
= make_expr2
(EXPR_OR
, $1, $3); }
352 | expr
'&' expr
{ $$
= make_expr2
(EXPR_AND
, $1, $3); }
353 | expr
'+' expr
{ $$
= make_expr2
(EXPR_ADD
, $1, $3); }
354 | expr
'-' expr
{ $$
= make_expr2
(EXPR_SUB
, $1, $3); }
355 | expr
'*' expr
{ $$
= make_expr2
(EXPR_MUL
, $1, $3); }
356 | expr
'/' expr
{ $$
= make_expr2
(EXPR_DIV
, $1, $3); }
357 | expr SHL expr
{ $$
= make_expr2
(EXPR_SHL
, $1, $3); }
358 | expr SHR expr
{ $$
= make_expr2
(EXPR_SHR
, $1, $3); }
359 |
'-' expr %prec NEG
{ $$
= make_expr1
(EXPR_NEG
, $2); }
360 |
'*' expr %prec PPTR
{ $$
= make_expr1
(EXPR_PPTR
, $2); }
361 |
'(' type
')' expr %prec CAST
{ $$
= make_exprt
(EXPR_CAST
, $2, $4); }
362 | tSIZEOF
'(' type
')' { $$
= make_exprt
(EXPR_SIZEOF
, $3, NULL
); }
363 |
'(' expr
')' { $$
= $2; }
366 expr_const: expr
{ $$
= $1;
367 if
(!$$
->is_const
) yyerror("expression is not constant\n");
371 externdef: tEXTERN tCONST type ident
{ $$
= $4;
372 set_type
($$
, $3, NULL
);
376 fields: { $$
= NULL
; }
377 | fields field
{ if
($2) { LINK
($2, $1); $$
= $2; }
382 field: s_field
';' { $$
= $1; }
383 | m_attributes uniondef
';' { $$
= make_var
(NULL
); $$
->type
= $2; $$
->attrs
= $1; }
384 | attributes
';' { $$
= make_var
(NULL
); $$
->attrs
= $1; }
388 s_field: m_attributes type pident array
{ $$
= $3; set_type
($$
, $2, $4); $$
->attrs
= $1; }
392 m_attributes type callconv pident
393 '(' m_args
')' { set_type
($4, $2, NULL
);
395 $$
= make_func
($4, $6);
399 m_ident: { $$
= NULL
; }
403 t_ident: { $$
= NULL
; }
404 | aIDENTIFIER
{ $$
= make_var
($1); }
405 | aKNOWNTYPE
{ $$
= make_var
($1); }
408 ident: aIDENTIFIER
{ $$
= make_var
($1); }
411 base_type: tBYTE
{ $$
= make_type
(RPC_FC_BYTE
, NULL
); }
412 | tWCHAR
{ $$
= make_type
(RPC_FC_WCHAR
, NULL
); }
414 | tSIGNED int_std
{ $$
= $2; $$
->sign
= 1; }
415 | tUNSIGNED int_std
{ $$
= $2; $$
->sign
= -1;
417 case RPC_FC_SMALL
: $$
->type
= RPC_FC_USMALL
; break
;
418 case RPC_FC_SHORT
: $$
->type
= RPC_FC_USHORT
; break
;
419 case RPC_FC_LONG
: $$
->type
= RPC_FC_ULONG
; break
;
423 | tFLOAT
{ $$
= make_type
(RPC_FC_FLOAT
, NULL
); }
424 | tDOUBLE
{ $$
= make_type
(RPC_FC_DOUBLE
, NULL
); }
425 | tBOOLEAN
{ $$
= make_type
(RPC_FC_BYTE
, &std_bool
); /* ? */ }
432 int_std: tINT
{ $$
= make_type
(RPC_FC_LONG
, &std_int
); } /* win32 only */
433 | tSHORT m_int
{ $$
= make_type
(RPC_FC_SHORT
, NULL
); }
434 | tLONG m_int
{ $$
= make_type
(RPC_FC_LONG
, NULL
); }
435 | tHYPER m_int
{ $$
= make_type
(RPC_FC_HYPER
, NULL
); }
436 | tINT64
{ $$
= make_type
(RPC_FC_HYPER
, NULL
); }
437 | tCHAR
{ $$
= make_type
(RPC_FC_CHAR
, NULL
); }
440 inherit: { $$
= NULL
; }
441 |
':' aKNOWNTYPE
{ $$
= find_type2
($2, 0); }
444 interface: tINTERFACE aIDENTIFIER
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
445 | tINTERFACE aKNOWNTYPE
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
448 interfacehdr: attributes interface
{ $$
= $2;
449 if
($$
->defined
) yyerror("multiple definition error\n");
452 if
(!parse_only
) write_forward
($$
);
456 interfacedef: interfacehdr inherit
457 '{' int_statements
'}' { $$
= $1;
460 if
(!parse_only
) write_interface
($$
);
462 /* MIDL is able to import the definition of a base class from inside the
463 * definition of a derived class, I'll try to support it with this rule */
464 | interfacehdr
':' aIDENTIFIER
465 '{' import int_statements
'}' { $$
= $1;
466 $$
->ref
= find_type2
($3, 0);
467 if
(!$$
->ref
) yyerror("base class %s not found in import\n", $3);
469 if
(!parse_only
) write_interface
($$
);
473 p_ident: '*' pident %prec PPTR
{ $$
= $2; $$
->ptr_level
++; }
474 | tCONST p_ident
{ $$
= $2; /* FIXME */ }
479 |
'(' pident
')' { $$
= $2; }
484 | pident_list
',' pident
{ LINK
($3, $1); $$
= $3; }
488 tREF
{ $$
= RPC_FC_RP
; }
489 | tUNIQUE
{ $$
= RPC_FC_UP
; }
492 structdef: tSTRUCT t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_STRUCT
, $2, tsSTRUCT
);
498 type: tVOID
{ $$
= make_tref
(NULL
, make_type
(0, NULL
)); }
499 | aKNOWNTYPE
{ $$
= make_tref
($1, find_type
($1, 0)); }
500 | base_type
{ $$
= make_tref
(NULL
, $1); }
501 | tCONST type
{ $$
= uniq_tref
($2); $$
->ref
->is_const
= TRUE
; }
502 | enumdef
{ $$
= make_tref
(NULL
, $1); }
503 | tENUM aIDENTIFIER
{ $$
= make_tref
(NULL
, find_type2
($2, tsENUM
)); }
504 | structdef
{ $$
= make_tref
(NULL
, $1); }
505 | tSTRUCT aIDENTIFIER
{ $$
= make_tref
(NULL
, get_type
(RPC_FC_STRUCT
, $2, tsSTRUCT
)); }
506 | uniondef
{ $$
= make_tref
(NULL
, $1); }
507 | tUNION aIDENTIFIER
{ $$
= make_tref
(NULL
, find_type2
($2, tsUNION
)); }
510 typedef: tTYPEDEF m_attributes type pident_list
{ typeref_t
*tref
= uniq_tref
($3);
511 $4->tname
= tref
->name
;
515 if
(!parse_only
) write_typedef
($$
, $4);
516 reg_types
($$
, $4, 0);
520 uniondef: tUNION t_ident
'{' fields
'}' { $$
= get_typev
(RPC_FC_NON_ENCAPSULATED_UNION
, $2, tsUNION
);
525 tSWITCH
'(' s_field
')'
526 m_ident
'{' cases
'}' { var_t
*u
= $7;
527 $$
= get_typev
(RPC_FC_ENCAPSULATED_UNION
, $2, tsUNION
);
528 if
(!u
) u
= make_var
("tagged_union");
529 u
->type
= make_type
(RPC_FC_NON_ENCAPSULATED_UNION
, NULL
);
530 u
->type
->fields
= $9;
531 u
->type
->defined
= TRUE
;
532 LINK
(u
, $5); $$
->fields
= u
;
544 static attr_t
*make_attr
(enum attr_type type
)
546 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
553 static attr_t
*make_attrv
(enum attr_type type
, DWORD val
)
555 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
562 static attr_t
*make_attrp
(enum attr_type type
, void *val
)
564 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
571 static expr_t
*make_expr
(enum expr_type type
)
573 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
582 static expr_t
*make_exprl
(enum expr_type type
, long val
)
584 expr_t
*e
= xmalloc
(sizeof
(expr_t
));
590 /* check for numeric constant */
591 if
(type
== EXPR_NUM || type
== EXPR_HEXNUM
) {
598 static expr_t
*make_exprs
(enum expr_type type
, char *val
)
601 e
= xmalloc
(sizeof
(expr_t
));
607 /* check for predefined constants */
608 if
(type
== EXPR_IDENTIFIER
) {
609 var_t
*c
= find_const
(val
, 0);
620 static expr_t
*make_exprt
(enum expr_type type
, typeref_t
*tref
, expr_t
*expr
)
623 e
= xmalloc
(sizeof
(expr_t
));
629 /* check for cast of constant expression */
630 if
(type
== EXPR_CAST
&& expr
->is_const
) {
632 e
->cval
= expr
->cval
;
637 static expr_t
*make_expr1
(enum expr_type type
, expr_t
*expr
)
640 e
= xmalloc
(sizeof
(expr_t
));
646 /* check for compile-time optimization */
647 if
(expr
->is_const
) {
651 e
->cval
= -expr
->cval
;
661 static expr_t
*make_expr2
(enum expr_type type
, expr_t
*expr1
, expr_t
*expr2
)
664 e
= xmalloc
(sizeof
(expr_t
));
670 /* check for compile-time optimization */
671 if
(expr1
->is_const
&& expr2
->is_const
) {
675 e
->cval
= expr1
->cval
+ expr2
->cval
;
678 e
->cval
= expr1
->cval
- expr2
->cval
;
681 e
->cval
= expr1
->cval
* expr2
->cval
;
684 e
->cval
= expr1
->cval
/ expr2
->cval
;
687 e
->cval
= expr1
->cval | expr2
->cval
;
690 e
->cval
= expr1
->cval
& expr2
->cval
;
693 e
->cval
= expr1
->cval
<< expr2
->cval
;
696 e
->cval
= expr1
->cval
>> expr2
->cval
;
706 static type_t
*make_type
(BYTE type
, type_t
*ref
)
708 type_t
*t
= xmalloc
(sizeof
(type_t
));
716 t
->ignore
= parse_only
;
725 static typeref_t
*make_tref
(char *name
, type_t
*ref
)
727 typeref_t
*t
= xmalloc
(sizeof
(typeref_t
));
730 t
->uniq
= ref ?
0 : 1;
734 static typeref_t
*uniq_tref
(typeref_t
*ref
)
738 if
(t
->uniq
) return t
;
739 tp
= make_type
(0, t
->ref
);
747 static type_t
*type_ref
(typeref_t
*ref
)
749 type_t
*t
= ref
->ref
;
750 if
(ref
->name
) free
(ref
->name
);
755 static void set_type
(var_t
*v
, typeref_t
*ref
, expr_t
*arr
)
758 v
->tname
= ref
->name
;
764 static var_t
*make_var
(char *name
)
766 var_t
*v
= xmalloc
(sizeof
(var_t
));
779 static func_t
*make_func
(var_t
*def
, var_t
*args
)
781 func_t
*f
= xmalloc
(sizeof
(func_t
));
784 f
->ignore
= parse_only
;
792 static int hash_ident
(const char *name
)
794 const char *p
= name
;
796 /* a simple sum hash is probably good enough */
801 return sum
& (HASHMAX
-1);
804 /***** type repository *****/
813 struct rtype
*type_hash
[HASHMAX
];
815 static type_t
*reg_type
(type_t
*type
, char *name
, int t
)
820 yyerror("registering named type without name\n");
823 hash
= hash_ident
(name
);
824 nt
= xmalloc
(sizeof
(struct rtype
));
828 nt
->next
= type_hash
[hash
];
829 type_hash
[hash
] = nt
;
833 static type_t
*reg_types
(type_t
*type
, var_t
*names
, int t
)
839 var_t
*next
= NEXT_LINK
(names
);
842 int cptr
= names
->ptr_level
;
844 while
(cptr
> ptrc
) {
845 cur
= ptr
= make_type
(RPC_FC_FP
, cur
); /* FIXME: pointer type from attrs? */
849 while
(cptr
< ptrc
) {
854 reg_type
(cur
, names
->name
, t
);
862 static type_t
*find_type
(char *name
, int t
)
864 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
865 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
868 yyerror("type %s not found\n", name
);
874 static type_t
*find_type2
(char *name
, int t
)
876 type_t
*tp
= find_type
(name
, t
);
881 int is_type
(const char *name
)
883 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
884 while
(cur
&& (cur
->t || strcmp
(cur
->name
, name
)))
886 if
(cur
) return TRUE
;
890 static type_t
*get_type
(BYTE type
, char *name
, int t
)
892 struct rtype
*cur
= NULL
;
895 cur
= type_hash
[hash_ident
(name
)];
896 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
903 tp
= make_type
(type
, NULL
);
905 if
(!name
) return tp
;
906 return reg_type
(tp
, name
, t
);
909 static type_t
*get_typev
(BYTE type
, var_t
*name
, int t
)
916 return get_type
(type
, sname
, t
);
919 /***** constant repository *****/
927 struct rconst
*const_hash
[HASHMAX
];
929 static var_t
*reg_const
(var_t
*var
)
934 yyerror("registering constant without name\n");
937 hash
= hash_ident
(var
->name
);
938 nc
= xmalloc
(sizeof
(struct rconst
));
939 nc
->name
= var
->name
;
941 nc
->next
= const_hash
[hash
];
942 const_hash
[hash
] = nc
;
946 static var_t
*find_const
(char *name
, int f
)
948 struct rconst
*cur
= const_hash
[hash_ident
(name
)];
949 while
(cur
&& strcmp
(cur
->name
, name
))
952 if
(f
) yyerror("constant %s not found\n", name
);