widl: Be more strict about where semicolons can appear in IDL files.
[wine/multimedia.git] / tools / widl / parser.y
blobdd02ab66c035e9d539599e7f4a5cb725a2fe5700
1 %{
2 /*
3 * IDL Compiler
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
22 #include "config.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <assert.h>
28 #include <ctype.h>
29 #include <string.h>
30 #ifdef HAVE_ALLOCA_H
31 #include <alloca.h>
32 #endif
34 #include "widl.h"
35 #include "utils.h"
36 #include "parser.h"
37 #include "header.h"
38 #include "typelib.h"
39 #include "typegen.h"
41 #if defined(YYBYACC)
42 /* Berkeley yacc (byacc) doesn't seem to know about these */
43 /* Some *BSD supplied versions do define these though */
44 # ifndef YYEMPTY
45 # define YYEMPTY (-1) /* Empty lookahead value of yychar */
46 # endif
47 # ifndef YYLEX
48 # define YYLEX yylex()
49 # endif
51 #elif defined(YYBISON)
52 /* Bison was used for original development */
53 /* #define YYEMPTY -2 */
54 /* #define YYLEX yylex() */
56 #else
57 /* No yacc we know yet */
58 # if !defined(YYEMPTY) || !defined(YYLEX)
59 # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
60 # elif defined(__GNUC__) /* gcc defines the #warning directive */
61 # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
62 /* #else we just take a chance that it works... */
63 # endif
64 #endif
66 unsigned char pointer_default = RPC_FC_UP;
68 typedef struct list typelist_t;
69 struct typenode {
70 type_t *type;
71 struct list entry;
74 typelist_t incomplete_types = LIST_INIT(incomplete_types);
76 static void add_incomplete(type_t *t);
77 static void fix_incomplete(void);
79 static str_list_t *append_str(str_list_t *list, char *str);
80 static attr_list_t *append_attr(attr_list_t *list, attr_t *attr);
81 static attr_t *make_attr(enum attr_type type);
82 static attr_t *make_attrv(enum attr_type type, unsigned long val);
83 static attr_t *make_attrp(enum attr_type type, void *val);
84 static expr_t *make_expr(enum expr_type type);
85 static expr_t *make_exprl(enum expr_type type, long val);
86 static expr_t *make_exprd(enum expr_type type, double val);
87 static expr_t *make_exprs(enum expr_type type, char *val);
88 static expr_t *make_exprt(enum expr_type type, type_t *tref, expr_t *expr);
89 static expr_t *make_expr1(enum expr_type type, expr_t *expr);
90 static expr_t *make_expr2(enum expr_type type, expr_t *exp1, expr_t *exp2);
91 static expr_t *make_expr3(enum expr_type type, expr_t *expr1, expr_t *expr2, expr_t *expr3);
92 static type_t *make_type(unsigned char type, type_t *ref);
93 static expr_list_t *append_expr(expr_list_t *list, expr_t *expr);
94 static array_dims_t *append_array(array_dims_t *list, expr_t *expr);
95 static void set_type(var_t *v, type_t *type, int ptr_level, array_dims_t *arr, int top);
96 static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface);
97 static ifref_t *make_ifref(type_t *iface);
98 static var_list_t *append_var(var_list_t *list, var_t *var);
99 static var_t *make_var(char *name);
100 static pident_list_t *append_pident(pident_list_t *list, pident_t *p);
101 static pident_t *make_pident(var_t *var);
102 static func_list_t *append_func(func_list_t *list, func_t *func);
103 static func_t *make_func(var_t *def);
104 static type_t *make_class(char *name);
105 static type_t *make_safearray(type_t *type);
106 static type_t *make_builtin(char *name);
107 static type_t *make_int(int sign);
109 static type_t *reg_type(type_t *type, const char *name, int t);
110 static type_t *reg_typedefs(type_t *type, var_list_t *names, attr_list_t *attrs);
111 static type_t *find_type(const char *name, int t);
112 static type_t *find_type2(char *name, int t);
113 static type_t *get_type(unsigned char type, char *name, int t);
114 static type_t *get_typev(unsigned char type, var_t *name, int t);
115 static int get_struct_type(var_list_t *fields);
117 static var_t *reg_const(var_t *var);
118 static var_t *find_const(char *name, int f);
120 static void write_libid(const char *name, const attr_list_t *attr);
121 static void write_clsid(type_t *cls);
122 static void write_diid(type_t *iface);
123 static void write_iid(type_t *iface);
125 static int compute_method_indexes(type_t *iface);
126 static char *gen_name(void);
127 static void process_typedefs(var_list_t *names);
128 static void check_arg(var_t *arg);
129 static void check_all_user_types(ifref_list_t *ifaces);
131 #define tsENUM 1
132 #define tsSTRUCT 2
133 #define tsUNION 3
136 %union {
137 attr_t *attr;
138 attr_list_t *attr_list;
139 str_list_t *str_list;
140 expr_t *expr;
141 expr_list_t *expr_list;
142 array_dims_t *array_dims;
143 type_t *type;
144 var_t *var;
145 var_list_t *var_list;
146 pident_t *pident;
147 pident_list_t *pident_list;
148 func_t *func;
149 func_list_t *func_list;
150 ifref_t *ifref;
151 ifref_list_t *ifref_list;
152 char *str;
153 UUID *uuid;
154 unsigned int num;
155 double dbl;
156 interface_info_t ifinfo;
159 %token <str> aIDENTIFIER
160 %token <str> aKNOWNTYPE
161 %token <num> aNUM aHEXNUM
162 %token <dbl> aDOUBLE
163 %token <str> aSTRING
164 %token <uuid> aUUID
165 %token aEOF
166 %token SHL SHR
167 %token tAGGREGATABLE tALLOCATE tAPPOBJECT tASYNC tASYNCUUID
168 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
169 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
170 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
171 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
172 %token tDEFAULT
173 %token tDEFAULTCOLLELEM
174 %token tDEFAULTVALUE
175 %token tDEFAULTVTABLE
176 %token tDISPLAYBIND
177 %token tDISPINTERFACE
178 %token tDLLNAME tDOUBLE tDUAL
179 %token tENDPOINT
180 %token tENTRY tENUM tERRORSTATUST
181 %token tEXPLICITHANDLE tEXTERN
182 %token tFALSE
183 %token tFLOAT
184 %token tHANDLE
185 %token tHANDLET
186 %token tHELPCONTEXT tHELPFILE
187 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
188 %token tHIDDEN
189 %token tHYPER tID tIDEMPOTENT
190 %token tIIDIS
191 %token tIMMEDIATEBIND
192 %token tIMPLICITHANDLE
193 %token tIMPORT tIMPORTLIB
194 %token tIN tINLINE
195 %token tINPUTSYNC
196 %token tINT tINT64
197 %token tINTERFACE
198 %token tLCID
199 %token tLENGTHIS tLIBRARY
200 %token tLOCAL
201 %token tLONG
202 %token tMETHODS
203 %token tMODULE
204 %token tNONBROWSABLE
205 %token tNONCREATABLE
206 %token tNONEXTENSIBLE
207 %token tOBJECT tODL tOLEAUTOMATION
208 %token tOPTIONAL
209 %token tOUT
210 %token tPOINTERDEFAULT
211 %token tPROPERTIES
212 %token tPROPGET tPROPPUT tPROPPUTREF
213 %token tPTR
214 %token tPUBLIC
215 %token tRANGE
216 %token tREADONLY tREF
217 %token tREQUESTEDIT
218 %token tRESTRICTED
219 %token tRETVAL
220 %token tSAFEARRAY
221 %token tSHORT
222 %token tSIGNED
223 %token tSINGLE
224 %token tSIZEIS tSIZEOF
225 %token tSMALL
226 %token tSOURCE
227 %token tSTDCALL
228 %token tSTRICTCONTEXTHANDLE
229 %token tSTRING tSTRUCT
230 %token tSWITCH tSWITCHIS tSWITCHTYPE
231 %token tTRANSMITAS
232 %token tTRUE
233 %token tTYPEDEF
234 %token tUNION
235 %token tUNIQUE
236 %token tUNSIGNED
237 %token tUUID
238 %token tV1ENUM
239 %token tVARARG
240 %token tVERSION
241 %token tVOID
242 %token tWCHAR tWIREMARSHAL
244 %type <attr> attribute
245 %type <attr_list> m_attributes attributes attrib_list
246 %type <str_list> str_list
247 %type <expr> m_expr expr expr_const
248 %type <expr_list> m_exprs /* exprs expr_list */ expr_list_const
249 %type <array_dims> array array_list
250 %type <ifinfo> interfacehdr
251 %type <type> inherit interface interfacedef interfacedec
252 %type <type> dispinterface dispinterfacehdr dispinterfacedef
253 %type <type> module modulehdr moduledef
254 %type <type> base_type int_std
255 %type <type> enumdef structdef uniondef
256 %type <type> type
257 %type <ifref> coclass_int
258 %type <ifref_list> gbl_statements coclass_ints
259 %type <var> arg field s_field case enum constdef externdef
260 %type <var_list> m_args no_args args fields cases enums enum_list dispint_props
261 %type <var> m_ident t_ident ident
262 %type <pident> pident func_ident direct_ident
263 %type <pident_list> pident_list
264 %type <func> funcdef
265 %type <func_list> int_statements dispint_meths
266 %type <type> coclass coclasshdr coclassdef
267 %type <num> pointer_type version
268 %type <str> libraryhdr
269 %type <uuid> uuid_string
270 %type <num> import_start
272 %left ','
273 %right '?' ':'
274 %left '|'
275 %left '&'
276 %left '-' '+'
277 %left '*' '/'
278 %left SHL SHR
279 %right '~'
280 %right CAST
281 %right PPTR
282 %right NEG
283 %right ADDRESSOF
287 input: gbl_statements { fix_incomplete();
288 check_all_user_types($1);
289 write_proxies($1);
290 write_client($1);
291 write_server($1);
292 write_dlldata($1);
296 gbl_statements: { $$ = NULL; }
297 | gbl_statements interfacedec { $$ = $1; }
298 | gbl_statements interfacedef { $$ = append_ifref( $1, make_ifref($2) ); }
299 | gbl_statements coclass ';' { $$ = $1;
300 reg_type($2, $2->name, 0);
301 if (!parse_only && do_header) write_coclass_forward($2);
303 | gbl_statements coclassdef { $$ = $1;
304 add_typelib_entry($2);
305 reg_type($2, $2->name, 0);
306 if (!parse_only && do_header) write_coclass_forward($2);
308 | gbl_statements moduledef { $$ = $1; add_typelib_entry($2); }
309 | gbl_statements librarydef { $$ = $1; }
310 | gbl_statements statement { $$ = $1; }
313 imp_statements: {}
314 | imp_statements interfacedec { if (!parse_only) add_typelib_entry($2); }
315 | imp_statements interfacedef { if (!parse_only) add_typelib_entry($2); }
316 | imp_statements coclass ';' { reg_type($2, $2->name, 0); if (!parse_only && do_header) write_coclass_forward($2); }
317 | imp_statements coclassdef { if (!parse_only) add_typelib_entry($2);
318 reg_type($2, $2->name, 0);
319 if (!parse_only && do_header) write_coclass_forward($2);
321 | imp_statements moduledef { if (!parse_only) add_typelib_entry($2); }
322 | imp_statements statement {}
323 | imp_statements importlib {}
324 | imp_statements librarydef {}
327 int_statements: { $$ = NULL; }
328 | int_statements funcdef ';' { $$ = append_func( $1, $2 ); }
329 | int_statements statement { $$ = $1; }
332 semicolon_opt:
333 | ';'
336 statement: constdef ';' { if (!parse_only && do_header) { write_constdef($1); } }
337 | cppquote {}
338 | enumdef ';' { if (!parse_only && do_header) {
339 write_type_def_or_decl(header, $1, FALSE, NULL);
340 fprintf(header, ";\n\n");
343 | externdef ';' { if (!parse_only && do_header) { write_externdef($1); } }
344 | import {}
345 | structdef ';' { if (!parse_only && do_header) {
346 write_type_def_or_decl(header, $1, FALSE, NULL);
347 fprintf(header, ";\n\n");
350 | typedef ';' {}
351 | uniondef ';' { if (!parse_only && do_header) {
352 write_type_def_or_decl(header, $1, FALSE, NULL);
353 fprintf(header, ";\n\n");
358 cppquote: tCPPQUOTE '(' aSTRING ')' { if (!parse_only && do_header) fprintf(header, "%s\n", $3); }
360 import_start: tIMPORT aSTRING ';' { assert(yychar == YYEMPTY);
361 $$ = do_import($2);
362 if (!$$) yychar = aEOF;
366 import: import_start imp_statements aEOF
367 { if ($1) pop_import(); }
370 importlib: tIMPORTLIB '(' aSTRING ')'
371 semicolon_opt { if(!parse_only) add_importlib($3); }
374 libraryhdr: tLIBRARY aIDENTIFIER { $$ = $2; }
376 library_start: attributes libraryhdr '{' { if (!parse_only) start_typelib($2, $1);
377 if (!parse_only && do_header) write_library($2, $1);
378 if (!parse_only && do_idfile) write_libid($2, $1);
381 librarydef: library_start imp_statements '}'
382 semicolon_opt { if (!parse_only) end_typelib(); }
385 m_args: { $$ = NULL; }
386 | args
389 no_args: tVOID { $$ = NULL; }
392 args: arg { check_arg($1); $$ = append_var( NULL, $1 ); }
393 | args ',' arg { check_arg($3); $$ = append_var( $1, $3); }
394 | no_args
397 /* split into two rules to get bison to resolve a tVOID conflict */
398 arg: attributes type pident array { $$ = $3->var;
399 $$->attrs = $1;
400 set_type($$, $2, $3->ptr_level, $4, TRUE);
401 free($3);
403 | type pident array { $$ = $2->var;
404 set_type($$, $1, $2->ptr_level, $3, TRUE);
405 free($2);
409 array: { $$ = NULL; }
410 | '[' array_list ']' { $$ = $2; }
411 | '[' '*' ']' { $$ = append_array( NULL, make_expr(EXPR_VOID) ); }
414 array_list: m_expr /* size of first dimension is optional */ { $$ = append_array( NULL, $1 ); }
415 | array_list ',' expr { $$ = append_array( $1, $3 ); }
416 | array_list ']' '[' expr { $$ = append_array( $1, $4 ); }
419 m_attributes: { $$ = NULL; }
420 | attributes
423 attributes:
424 '[' attrib_list ']' { $$ = $2;
425 if (!$$)
426 error_loc("empty attribute lists unsupported\n");
430 attrib_list: attribute { $$ = append_attr( NULL, $1 ); }
431 | attrib_list ',' attribute { $$ = append_attr( $1, $3 ); }
432 | attrib_list ']' '[' attribute { $$ = append_attr( $1, $4 ); }
435 str_list: aSTRING { $$ = append_str( NULL, $1 ); }
436 | str_list ',' aSTRING { $$ = append_str( $1, $3 ); }
439 attribute: { $$ = NULL; }
440 | tAGGREGATABLE { $$ = make_attr(ATTR_AGGREGATABLE); }
441 | tAPPOBJECT { $$ = make_attr(ATTR_APPOBJECT); }
442 | tASYNC { $$ = make_attr(ATTR_ASYNC); }
443 | tAUTOHANDLE { $$ = make_attr(ATTR_AUTO_HANDLE); }
444 | tBINDABLE { $$ = make_attr(ATTR_BINDABLE); }
445 | tCALLAS '(' ident ')' { $$ = make_attrp(ATTR_CALLAS, $3); }
446 | tCASE '(' expr_list_const ')' { $$ = make_attrp(ATTR_CASE, $3); }
447 | tCONTEXTHANDLE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); }
448 | tCONTEXTHANDLENOSERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
449 | tCONTEXTHANDLESERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
450 | tCONTROL { $$ = make_attr(ATTR_CONTROL); }
451 | tDEFAULT { $$ = make_attr(ATTR_DEFAULT); }
452 | tDEFAULTCOLLELEM { $$ = make_attr(ATTR_DEFAULTCOLLELEM); }
453 | tDEFAULTVALUE '(' expr_const ')' { $$ = make_attrp(ATTR_DEFAULTVALUE_EXPR, $3); }
454 | tDEFAULTVALUE '(' aSTRING ')' { $$ = make_attrp(ATTR_DEFAULTVALUE_STRING, $3); }
455 | tDEFAULTVTABLE { $$ = make_attr(ATTR_DEFAULTVTABLE); }
456 | tDISPLAYBIND { $$ = make_attr(ATTR_DISPLAYBIND); }
457 | tDLLNAME '(' aSTRING ')' { $$ = make_attrp(ATTR_DLLNAME, $3); }
458 | tDUAL { $$ = make_attr(ATTR_DUAL); }
459 | tENDPOINT '(' str_list ')' { $$ = make_attrp(ATTR_ENDPOINT, $3); }
460 | tENTRY '(' aSTRING ')' { $$ = make_attrp(ATTR_ENTRY_STRING, $3); }
461 | tENTRY '(' expr_const ')' { $$ = make_attrp(ATTR_ENTRY_ORDINAL, $3); }
462 | tEXPLICITHANDLE { $$ = make_attr(ATTR_EXPLICIT_HANDLE); }
463 | tHANDLE { $$ = make_attr(ATTR_HANDLE); }
464 | tHELPCONTEXT '(' expr_const ')' { $$ = make_attrp(ATTR_HELPCONTEXT, $3); }
465 | tHELPFILE '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPFILE, $3); }
466 | tHELPSTRING '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRING, $3); }
467 | tHELPSTRINGCONTEXT '(' expr_const ')' { $$ = make_attrp(ATTR_HELPSTRINGCONTEXT, $3); }
468 | tHELPSTRINGDLL '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRINGDLL, $3); }
469 | tHIDDEN { $$ = make_attr(ATTR_HIDDEN); }
470 | tID '(' expr_const ')' { $$ = make_attrp(ATTR_ID, $3); }
471 | tIDEMPOTENT { $$ = make_attr(ATTR_IDEMPOTENT); }
472 | tIIDIS '(' expr ')' { $$ = make_attrp(ATTR_IIDIS, $3); }
473 | tIMMEDIATEBIND { $$ = make_attr(ATTR_IMMEDIATEBIND); }
474 | tIMPLICITHANDLE '(' tHANDLET aIDENTIFIER ')' { $$ = make_attrp(ATTR_IMPLICIT_HANDLE, $4); }
475 | tIN { $$ = make_attr(ATTR_IN); }
476 | tINPUTSYNC { $$ = make_attr(ATTR_INPUTSYNC); }
477 | tLENGTHIS '(' m_exprs ')' { $$ = make_attrp(ATTR_LENGTHIS, $3); }
478 | tLOCAL { $$ = make_attr(ATTR_LOCAL); }
479 | tNONBROWSABLE { $$ = make_attr(ATTR_NONBROWSABLE); }
480 | tNONCREATABLE { $$ = make_attr(ATTR_NONCREATABLE); }
481 | tNONEXTENSIBLE { $$ = make_attr(ATTR_NONEXTENSIBLE); }
482 | tOBJECT { $$ = make_attr(ATTR_OBJECT); }
483 | tODL { $$ = make_attr(ATTR_ODL); }
484 | tOLEAUTOMATION { $$ = make_attr(ATTR_OLEAUTOMATION); }
485 | tOPTIONAL { $$ = make_attr(ATTR_OPTIONAL); }
486 | tOUT { $$ = make_attr(ATTR_OUT); }
487 | tPOINTERDEFAULT '(' pointer_type ')' { $$ = make_attrv(ATTR_POINTERDEFAULT, $3); }
488 | tPROPGET { $$ = make_attr(ATTR_PROPGET); }
489 | tPROPPUT { $$ = make_attr(ATTR_PROPPUT); }
490 | tPROPPUTREF { $$ = make_attr(ATTR_PROPPUTREF); }
491 | tPUBLIC { $$ = make_attr(ATTR_PUBLIC); }
492 | tRANGE '(' expr_const ',' expr_const ')' { expr_list_t *list = append_expr( NULL, $3 );
493 list = append_expr( list, $5 );
494 $$ = make_attrp(ATTR_RANGE, list); }
495 | tREADONLY { $$ = make_attr(ATTR_READONLY); }
496 | tREQUESTEDIT { $$ = make_attr(ATTR_REQUESTEDIT); }
497 | tRESTRICTED { $$ = make_attr(ATTR_RESTRICTED); }
498 | tRETVAL { $$ = make_attr(ATTR_RETVAL); }
499 | tSIZEIS '(' m_exprs ')' { $$ = make_attrp(ATTR_SIZEIS, $3); }
500 | tSOURCE { $$ = make_attr(ATTR_SOURCE); }
501 | tSTRICTCONTEXTHANDLE { $$ = make_attr(ATTR_STRICTCONTEXTHANDLE); }
502 | tSTRING { $$ = make_attr(ATTR_STRING); }
503 | tSWITCHIS '(' expr ')' { $$ = make_attrp(ATTR_SWITCHIS, $3); }
504 | tSWITCHTYPE '(' type ')' { $$ = make_attrp(ATTR_SWITCHTYPE, $3); }
505 | tTRANSMITAS '(' type ')' { $$ = make_attrp(ATTR_TRANSMITAS, $3); }
506 | tUUID '(' uuid_string ')' { $$ = make_attrp(ATTR_UUID, $3); }
507 | tV1ENUM { $$ = make_attr(ATTR_V1ENUM); }
508 | tVARARG { $$ = make_attr(ATTR_VARARG); }
509 | tVERSION '(' version ')' { $$ = make_attrv(ATTR_VERSION, $3); }
510 | tWIREMARSHAL '(' type ')' { $$ = make_attrp(ATTR_WIREMARSHAL, $3); }
511 | pointer_type { $$ = make_attrv(ATTR_POINTERTYPE, $1); }
514 uuid_string:
515 aUUID
516 | aSTRING { if (!is_valid_uuid($1))
517 error_loc("invalid UUID: %s\n", $1);
518 $$ = parse_uuid($1); }
521 callconv:
522 | tSTDCALL
525 cases: { $$ = NULL; }
526 | cases case { $$ = append_var( $1, $2 ); }
529 case: tCASE expr ':' field { attr_t *a = make_attrp(ATTR_CASE, append_expr( NULL, $2 ));
530 $$ = $4; if (!$$) $$ = make_var(NULL);
531 $$->attrs = append_attr( $$->attrs, a );
533 | tDEFAULT ':' field { attr_t *a = make_attr(ATTR_DEFAULT);
534 $$ = $3; if (!$$) $$ = make_var(NULL);
535 $$->attrs = append_attr( $$->attrs, a );
539 constdef: tCONST type ident '=' expr_const { $$ = reg_const($3);
540 set_type($$, $2, 0, NULL, FALSE);
541 $$->eval = $5;
545 enums: { $$ = NULL; }
546 | enum_list ',' { $$ = $1; }
547 | enum_list
550 enum_list: enum { if (!$1->eval)
551 $1->eval = make_exprl(EXPR_NUM, 0 /* default for first enum entry */);
552 $$ = append_var( NULL, $1 );
554 | enum_list ',' enum { if (!$3->eval)
556 var_t *last = LIST_ENTRY( list_tail($$), var_t, entry );
557 $3->eval = make_exprl(EXPR_NUM, last->eval->cval + 1);
559 $$ = append_var( $1, $3 );
563 enum: ident '=' expr_const { $$ = reg_const($1);
564 $$->eval = $3;
565 $$->type = make_int(0);
567 | ident { $$ = reg_const($1);
568 $$->type = make_int(0);
572 enumdef: tENUM t_ident '{' enums '}' { $$ = get_typev(RPC_FC_ENUM16, $2, tsENUM);
573 $$->kind = TKIND_ENUM;
574 $$->fields = $4;
575 $$->defined = TRUE;
576 if(in_typelib)
577 add_typelib_entry($$);
581 m_exprs: m_expr { $$ = append_expr( NULL, $1 ); }
582 | m_exprs ',' m_expr { $$ = append_expr( $1, $3 ); }
586 exprs: { $$ = make_expr(EXPR_VOID); }
587 | expr_list
590 expr_list: expr
591 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
595 m_expr: { $$ = make_expr(EXPR_VOID); }
596 | expr
599 expr: aNUM { $$ = make_exprl(EXPR_NUM, $1); }
600 | aHEXNUM { $$ = make_exprl(EXPR_HEXNUM, $1); }
601 | aDOUBLE { $$ = make_exprd(EXPR_DOUBLE, $1); }
602 | tFALSE { $$ = make_exprl(EXPR_TRUEFALSE, 0); }
603 | tTRUE { $$ = make_exprl(EXPR_TRUEFALSE, 1); }
604 | aIDENTIFIER { $$ = make_exprs(EXPR_IDENTIFIER, $1); }
605 | expr '?' expr ':' expr { $$ = make_expr3(EXPR_COND, $1, $3, $5); }
606 | expr '|' expr { $$ = make_expr2(EXPR_OR , $1, $3); }
607 | expr '&' expr { $$ = make_expr2(EXPR_AND, $1, $3); }
608 | expr '+' expr { $$ = make_expr2(EXPR_ADD, $1, $3); }
609 | expr '-' expr { $$ = make_expr2(EXPR_SUB, $1, $3); }
610 | expr '*' expr { $$ = make_expr2(EXPR_MUL, $1, $3); }
611 | expr '/' expr { $$ = make_expr2(EXPR_DIV, $1, $3); }
612 | expr SHL expr { $$ = make_expr2(EXPR_SHL, $1, $3); }
613 | expr SHR expr { $$ = make_expr2(EXPR_SHR, $1, $3); }
614 | '~' expr { $$ = make_expr1(EXPR_NOT, $2); }
615 | '-' expr %prec NEG { $$ = make_expr1(EXPR_NEG, $2); }
616 | '&' expr %prec ADDRESSOF { $$ = make_expr1(EXPR_ADDRESSOF, $2); }
617 | '*' expr %prec PPTR { $$ = make_expr1(EXPR_PPTR, $2); }
618 | '(' type ')' expr %prec CAST { $$ = make_exprt(EXPR_CAST, $2, $4); }
619 | tSIZEOF '(' type ')' { $$ = make_exprt(EXPR_SIZEOF, $3, NULL); }
620 | '(' expr ')' { $$ = $2; }
623 expr_list_const: expr_const { $$ = append_expr( NULL, $1 ); }
624 | expr_list_const ',' expr_const { $$ = append_expr( $1, $3 ); }
627 expr_const: expr { $$ = $1;
628 if (!$$->is_const)
629 error_loc("expression is not constant\n");
633 externdef: tEXTERN tCONST type ident { $$ = $4;
634 set_type($$, $3, 0, NULL, FALSE);
638 fields: { $$ = NULL; }
639 | fields field { $$ = append_var( $1, $2 ); }
642 field: s_field ';' { $$ = $1; }
643 | m_attributes uniondef ';' { $$ = make_var(NULL); $$->type = $2; $$->attrs = $1; }
644 | attributes ';' { $$ = make_var(NULL); $$->attrs = $1; }
645 | ';' { $$ = NULL; }
648 s_field: m_attributes type pident array { $$ = $3->var;
649 $$->attrs = $1;
650 set_type($$, $2, $3->ptr_level, $4, FALSE);
651 free($3);
655 funcdef:
656 m_attributes type callconv pident { var_t *v = $4->var;
657 v->attrs = $1;
658 set_type(v, $2, $4->ptr_level, NULL, FALSE);
659 free($4);
660 $$ = make_func(v);
661 if (is_attr(v->attrs, ATTR_IN)) {
662 error_loc("inapplicable attribute [in] for function '%s'\n",$$->def->name);
667 m_ident: { $$ = NULL; }
668 | ident
671 t_ident: { $$ = NULL; }
672 | aIDENTIFIER { $$ = make_var($1); }
673 | aKNOWNTYPE { $$ = make_var($1); }
676 ident: aIDENTIFIER { $$ = make_var($1); }
677 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
678 | aKNOWNTYPE { $$ = make_var($<str>1); }
681 base_type: tBYTE { $$ = make_builtin($<str>1); }
682 | tWCHAR { $$ = make_builtin($<str>1); }
683 | int_std
684 | tSIGNED int_std { $$ = $2; $$->sign = 1; }
685 | tUNSIGNED int_std { $$ = $2; $$->sign = -1;
686 switch ($$->type) {
687 case RPC_FC_CHAR: break;
688 case RPC_FC_SMALL: $$->type = RPC_FC_USMALL; break;
689 case RPC_FC_SHORT: $$->type = RPC_FC_USHORT; break;
690 case RPC_FC_LONG: $$->type = RPC_FC_ULONG; break;
691 case RPC_FC_HYPER:
692 if ($$->name[0] == 'h') /* hyper, as opposed to __int64 */
694 $$ = alias($$, "MIDL_uhyper");
695 $$->sign = 0;
697 break;
698 default: break;
701 | tUNSIGNED { $$ = make_int(-1); }
702 | tFLOAT { $$ = make_builtin($<str>1); }
703 | tSINGLE { $$ = duptype(find_type("float", 0), 1); }
704 | tDOUBLE { $$ = make_builtin($<str>1); }
705 | tBOOLEAN { $$ = make_builtin($<str>1); }
706 | tERRORSTATUST { $$ = make_builtin($<str>1); }
707 | tHANDLET { $$ = make_builtin($<str>1); }
710 m_int:
711 | tINT
714 int_std: tINT { $$ = make_builtin($<str>1); }
715 | tSHORT m_int { $$ = make_builtin($<str>1); }
716 | tSMALL { $$ = make_builtin($<str>1); }
717 | tLONG m_int { $$ = make_builtin($<str>1); }
718 | tHYPER m_int { $$ = make_builtin($<str>1); }
719 | tINT64 { $$ = make_builtin($<str>1); }
720 | tCHAR { $$ = make_builtin($<str>1); }
723 coclass: tCOCLASS aIDENTIFIER { $$ = make_class($2); }
724 | tCOCLASS aKNOWNTYPE { $$ = find_type($2, 0);
725 if ($$->defined) error_loc("multiple definition error\n");
726 if ($$->kind != TKIND_COCLASS) error_loc("%s was not declared a coclass\n", $2);
730 coclasshdr: attributes coclass { $$ = $2;
731 $$->attrs = $1;
732 if (!parse_only && do_header)
733 write_coclass($$);
734 if (!parse_only && do_idfile)
735 write_clsid($$);
739 coclassdef: coclasshdr '{' coclass_ints '}' semicolon_opt
740 { $$ = $1;
741 $$->ifaces = $3;
742 $$->defined = TRUE;
746 coclass_ints: { $$ = NULL; }
747 | coclass_ints coclass_int { $$ = append_ifref( $1, $2 ); }
750 coclass_int:
751 m_attributes interfacedec { $$ = make_ifref($2); $$->attrs = $1; }
754 dispinterface: tDISPINTERFACE aIDENTIFIER { $$ = get_type(0, $2, 0); $$->kind = TKIND_DISPATCH; }
755 | tDISPINTERFACE aKNOWNTYPE { $$ = get_type(0, $2, 0); $$->kind = TKIND_DISPATCH; }
758 dispinterfacehdr: attributes dispinterface { attr_t *attrs;
759 $$ = $2;
760 if ($$->defined) error_loc("multiple definition error\n");
761 attrs = make_attr(ATTR_DISPINTERFACE);
762 $$->attrs = append_attr( $1, attrs );
763 $$->ref = find_type("IDispatch", 0);
764 if (!$$->ref) error_loc("IDispatch is undefined\n");
765 $$->defined = TRUE;
766 if (!parse_only && do_header) write_forward($$);
770 dispint_props: tPROPERTIES ':' { $$ = NULL; }
771 | dispint_props s_field ';' { $$ = append_var( $1, $2 ); }
774 dispint_meths: tMETHODS ':' { $$ = NULL; }
775 | dispint_meths funcdef ';' { $$ = append_func( $1, $2 ); }
778 dispinterfacedef: dispinterfacehdr '{'
779 dispint_props
780 dispint_meths
781 '}' { $$ = $1;
782 $$->fields = $3;
783 $$->funcs = $4;
784 if (!parse_only && do_header) write_dispinterface($$);
785 if (!parse_only && do_idfile) write_diid($$);
787 | dispinterfacehdr
788 '{' interface ';' '}' { $$ = $1;
789 $$->fields = $3->fields;
790 $$->funcs = $3->funcs;
791 if (!parse_only && do_header) write_dispinterface($$);
792 if (!parse_only && do_idfile) write_diid($$);
796 inherit: { $$ = NULL; }
797 | ':' aKNOWNTYPE { $$ = find_type2($2, 0); }
800 interface: tINTERFACE aIDENTIFIER { $$ = get_type(RPC_FC_IP, $2, 0); $$->kind = TKIND_INTERFACE; }
801 | tINTERFACE aKNOWNTYPE { $$ = get_type(RPC_FC_IP, $2, 0); $$->kind = TKIND_INTERFACE; }
804 interfacehdr: attributes interface { $$.interface = $2;
805 $$.old_pointer_default = pointer_default;
806 if (is_attr($1, ATTR_POINTERDEFAULT))
807 pointer_default = get_attrv($1, ATTR_POINTERDEFAULT);
808 if ($2->defined) error_loc("multiple definition error\n");
809 $2->attrs = $1;
810 $2->defined = TRUE;
811 if (!parse_only && do_header) write_forward($2);
815 interfacedef: interfacehdr inherit
816 '{' int_statements '}' semicolon_opt { $$ = $1.interface;
817 $$->ref = $2;
818 $$->funcs = $4;
819 compute_method_indexes($$);
820 if (!parse_only && do_header) write_interface($$);
821 if (!parse_only && local_stubs) write_locals(local_stubs, $$, TRUE);
822 if (!parse_only && do_idfile) write_iid($$);
823 pointer_default = $1.old_pointer_default;
825 /* MIDL is able to import the definition of a base class from inside the
826 * definition of a derived class, I'll try to support it with this rule */
827 | interfacehdr ':' aIDENTIFIER
828 '{' import int_statements '}'
829 semicolon_opt { $$ = $1.interface;
830 $$->ref = find_type2($3, 0);
831 if (!$$->ref) error_loc("base class '%s' not found in import\n", $3);
832 $$->funcs = $6;
833 compute_method_indexes($$);
834 if (!parse_only && do_header) write_interface($$);
835 if (!parse_only && local_stubs) write_locals(local_stubs, $$, TRUE);
836 if (!parse_only && do_idfile) write_iid($$);
837 pointer_default = $1.old_pointer_default;
839 | dispinterfacedef semicolon_opt { $$ = $1; }
842 interfacedec:
843 interface ';' { $$ = $1; if (!parse_only && do_header) write_forward($$); }
844 | dispinterface ';' { $$ = $1; if (!parse_only && do_header) write_forward($$); }
847 module: tMODULE aIDENTIFIER { $$ = make_type(0, NULL); $$->name = $2; $$->kind = TKIND_MODULE; }
848 | tMODULE aKNOWNTYPE { $$ = make_type(0, NULL); $$->name = $2; $$->kind = TKIND_MODULE; }
851 modulehdr: attributes module { $$ = $2;
852 $$->attrs = $1;
856 moduledef: modulehdr '{' int_statements '}'
857 semicolon_opt { $$ = $1;
858 $$->funcs = $3;
859 /* FIXME: if (!parse_only && do_header) write_module($$); */
863 pident: '*' pident %prec PPTR { $$ = $2; $$->ptr_level++; }
864 | tCONST pident { $$ = $2; /* FIXME */ }
865 | direct_ident
868 func_ident: direct_ident '(' m_args ')' { $$ = $1; $1->var->args = $3; }
870 direct_ident: ident { $$ = make_pident($1); }
871 | '(' pident ')' { $$ = $2; }
872 | func_ident { $$ = $1;
873 $$->func_ptr_level = $$->ptr_level;
874 $$->ptr_level = 0;
878 pident_list:
879 pident { $$ = append_pident( NULL, $1 ); }
880 | pident_list ',' pident { $$ = append_pident( $1, $3 ); }
883 pointer_type:
884 tREF { $$ = RPC_FC_RP; }
885 | tUNIQUE { $$ = RPC_FC_UP; }
886 | tPTR { $$ = RPC_FC_FP; }
889 structdef: tSTRUCT t_ident '{' fields '}' { $$ = get_typev(RPC_FC_STRUCT, $2, tsSTRUCT);
890 /* overwrite RPC_FC_STRUCT with a more exact type */
891 $$->type = get_struct_type( $4 );
892 $$->kind = TKIND_RECORD;
893 $$->fields = $4;
894 $$->defined = TRUE;
895 if(in_typelib)
896 add_typelib_entry($$);
900 type: tVOID { $$ = duptype(find_type("void", 0), 1); }
901 | aKNOWNTYPE { $$ = find_type($1, 0); }
902 | base_type { $$ = $1; }
903 | tCONST type { $$ = duptype($2, 1); $$->is_const = TRUE; }
904 | enumdef { $$ = $1; }
905 | tENUM aIDENTIFIER { $$ = find_type2($2, tsENUM); }
906 | structdef { $$ = $1; }
907 | tSTRUCT aIDENTIFIER { $$ = get_type(RPC_FC_STRUCT, $2, tsSTRUCT); }
908 | uniondef { $$ = $1; }
909 | tUNION aIDENTIFIER { $$ = find_type2($2, tsUNION); }
910 | tSAFEARRAY '(' type ')' { $$ = make_safearray($3); }
913 typedef: tTYPEDEF m_attributes type pident_list { reg_typedefs($3, $4, $2);
914 process_typedefs($4);
918 uniondef: tUNION t_ident '{' fields '}' { $$ = get_typev(RPC_FC_NON_ENCAPSULATED_UNION, $2, tsUNION);
919 $$->kind = TKIND_UNION;
920 $$->fields = $4;
921 $$->defined = TRUE;
923 | tUNION t_ident
924 tSWITCH '(' s_field ')'
925 m_ident '{' cases '}' { var_t *u = $7;
926 $$ = get_typev(RPC_FC_ENCAPSULATED_UNION, $2, tsUNION);
927 $$->kind = TKIND_UNION;
928 if (!u) u = make_var( xstrdup("tagged_union") );
929 u->type = make_type(RPC_FC_NON_ENCAPSULATED_UNION, NULL);
930 u->type->kind = TKIND_UNION;
931 u->type->fields = $9;
932 u->type->defined = TRUE;
933 $$->fields = append_var( $$->fields, $5 );
934 $$->fields = append_var( $$->fields, u );
935 $$->defined = TRUE;
939 version:
940 aNUM { $$ = MAKEVERSION($1, 0); }
941 | aNUM '.' aNUM { $$ = MAKEVERSION($1, $3); }
946 static void decl_builtin(const char *name, unsigned char type)
948 type_t *t = make_type(type, NULL);
949 t->name = xstrdup(name);
950 reg_type(t, name, 0);
953 static type_t *make_builtin(char *name)
955 /* NAME is strdup'd in the lexer */
956 type_t *t = duptype(find_type(name, 0), 0);
957 t->name = name;
958 return t;
961 static type_t *make_int(int sign)
963 type_t *t = duptype(find_type("int", 0), 1);
965 t->sign = sign;
966 if (sign < 0)
967 t->type = t->type == RPC_FC_LONG ? RPC_FC_ULONG : RPC_FC_USHORT;
969 return t;
972 void init_types(void)
974 decl_builtin("void", 0);
975 decl_builtin("byte", RPC_FC_BYTE);
976 decl_builtin("wchar_t", RPC_FC_WCHAR);
977 decl_builtin("int", RPC_FC_LONG); /* win32 */
978 decl_builtin("short", RPC_FC_SHORT);
979 decl_builtin("small", RPC_FC_SMALL);
980 decl_builtin("long", RPC_FC_LONG);
981 decl_builtin("hyper", RPC_FC_HYPER);
982 decl_builtin("__int64", RPC_FC_HYPER);
983 decl_builtin("char", RPC_FC_CHAR);
984 decl_builtin("float", RPC_FC_FLOAT);
985 decl_builtin("double", RPC_FC_DOUBLE);
986 decl_builtin("boolean", RPC_FC_BYTE);
987 decl_builtin("error_status_t", RPC_FC_ERROR_STATUS_T);
988 decl_builtin("handle_t", RPC_FC_BIND_PRIMITIVE);
991 static str_list_t *append_str(str_list_t *list, char *str)
993 struct str_list_entry_t *entry;
995 if (!str) return list;
996 if (!list)
998 list = xmalloc( sizeof(*list) );
999 list_init( list );
1001 entry = xmalloc( sizeof(*entry) );
1002 entry->str = str;
1003 list_add_tail( list, &entry->entry );
1004 return list;
1007 static attr_list_t *append_attr(attr_list_t *list, attr_t *attr)
1009 if (!attr) return list;
1010 if (!list)
1012 list = xmalloc( sizeof(*list) );
1013 list_init( list );
1015 list_add_tail( list, &attr->entry );
1016 return list;
1019 static attr_t *make_attr(enum attr_type type)
1021 attr_t *a = xmalloc(sizeof(attr_t));
1022 a->type = type;
1023 a->u.ival = 0;
1024 return a;
1027 static attr_t *make_attrv(enum attr_type type, unsigned long val)
1029 attr_t *a = xmalloc(sizeof(attr_t));
1030 a->type = type;
1031 a->u.ival = val;
1032 return a;
1035 static attr_t *make_attrp(enum attr_type type, void *val)
1037 attr_t *a = xmalloc(sizeof(attr_t));
1038 a->type = type;
1039 a->u.pval = val;
1040 return a;
1043 static expr_t *make_expr(enum expr_type type)
1045 expr_t *e = xmalloc(sizeof(expr_t));
1046 e->type = type;
1047 e->ref = NULL;
1048 e->u.lval = 0;
1049 e->is_const = FALSE;
1050 e->cval = 0;
1051 return e;
1054 static expr_t *make_exprl(enum expr_type type, long val)
1056 expr_t *e = xmalloc(sizeof(expr_t));
1057 e->type = type;
1058 e->ref = NULL;
1059 e->u.lval = val;
1060 e->is_const = FALSE;
1061 /* check for numeric constant */
1062 if (type == EXPR_NUM || type == EXPR_HEXNUM || type == EXPR_TRUEFALSE) {
1063 /* make sure true/false value is valid */
1064 assert(type != EXPR_TRUEFALSE || val == 0 || val == 1);
1065 e->is_const = TRUE;
1066 e->cval = val;
1068 return e;
1071 static expr_t *make_exprd(enum expr_type type, double val)
1073 expr_t *e = xmalloc(sizeof(expr_t));
1074 e->type = type;
1075 e->ref = NULL;
1076 e->u.dval = val;
1077 e->is_const = TRUE;
1078 e->cval = val;
1079 return e;
1082 static expr_t *make_exprs(enum expr_type type, char *val)
1084 expr_t *e;
1085 e = xmalloc(sizeof(expr_t));
1086 e->type = type;
1087 e->ref = NULL;
1088 e->u.sval = val;
1089 e->is_const = FALSE;
1090 /* check for predefined constants */
1091 if (type == EXPR_IDENTIFIER) {
1092 var_t *c = find_const(val, 0);
1093 if (c) {
1094 e->u.sval = c->name;
1095 free(val);
1096 e->is_const = TRUE;
1097 e->cval = c->eval->cval;
1100 return e;
1103 static expr_t *make_exprt(enum expr_type type, type_t *tref, expr_t *expr)
1105 expr_t *e;
1106 e = xmalloc(sizeof(expr_t));
1107 e->type = type;
1108 e->ref = expr;
1109 e->u.tref = tref;
1110 e->is_const = FALSE;
1111 /* check for cast of constant expression */
1112 if (type == EXPR_SIZEOF) {
1113 switch (tref->type) {
1114 case RPC_FC_BYTE:
1115 case RPC_FC_CHAR:
1116 case RPC_FC_SMALL:
1117 case RPC_FC_USMALL:
1118 e->is_const = TRUE;
1119 e->cval = 1;
1120 break;
1121 case RPC_FC_WCHAR:
1122 case RPC_FC_USHORT:
1123 case RPC_FC_SHORT:
1124 e->is_const = TRUE;
1125 e->cval = 2;
1126 break;
1127 case RPC_FC_LONG:
1128 case RPC_FC_ULONG:
1129 case RPC_FC_FLOAT:
1130 case RPC_FC_ERROR_STATUS_T:
1131 e->is_const = TRUE;
1132 e->cval = 4;
1133 break;
1134 case RPC_FC_HYPER:
1135 case RPC_FC_DOUBLE:
1136 e->is_const = TRUE;
1137 e->cval = 8;
1138 break;
1141 if (type == EXPR_CAST && expr->is_const) {
1142 e->is_const = TRUE;
1143 e->cval = expr->cval;
1145 return e;
1148 static expr_t *make_expr1(enum expr_type type, expr_t *expr)
1150 expr_t *e;
1151 if (type == EXPR_ADDRESSOF && expr->type != EXPR_IDENTIFIER)
1152 error("address-of operator applied to invalid expression\n");
1153 e = xmalloc(sizeof(expr_t));
1154 e->type = type;
1155 e->ref = expr;
1156 e->u.lval = 0;
1157 e->is_const = FALSE;
1158 /* check for compile-time optimization */
1159 if (expr->is_const) {
1160 e->is_const = TRUE;
1161 switch (type) {
1162 case EXPR_NEG:
1163 e->cval = -expr->cval;
1164 break;
1165 case EXPR_NOT:
1166 e->cval = ~expr->cval;
1167 break;
1168 default:
1169 e->is_const = FALSE;
1170 break;
1173 return e;
1176 static expr_t *make_expr2(enum expr_type type, expr_t *expr1, expr_t *expr2)
1178 expr_t *e;
1179 e = xmalloc(sizeof(expr_t));
1180 e->type = type;
1181 e->ref = expr1;
1182 e->u.ext = expr2;
1183 e->is_const = FALSE;
1184 /* check for compile-time optimization */
1185 if (expr1->is_const && expr2->is_const) {
1186 e->is_const = TRUE;
1187 switch (type) {
1188 case EXPR_ADD:
1189 e->cval = expr1->cval + expr2->cval;
1190 break;
1191 case EXPR_SUB:
1192 e->cval = expr1->cval - expr2->cval;
1193 break;
1194 case EXPR_MUL:
1195 e->cval = expr1->cval * expr2->cval;
1196 break;
1197 case EXPR_DIV:
1198 e->cval = expr1->cval / expr2->cval;
1199 break;
1200 case EXPR_OR:
1201 e->cval = expr1->cval | expr2->cval;
1202 break;
1203 case EXPR_AND:
1204 e->cval = expr1->cval & expr2->cval;
1205 break;
1206 case EXPR_SHL:
1207 e->cval = expr1->cval << expr2->cval;
1208 break;
1209 case EXPR_SHR:
1210 e->cval = expr1->cval >> expr2->cval;
1211 break;
1212 default:
1213 e->is_const = FALSE;
1214 break;
1217 return e;
1220 static expr_t *make_expr3(enum expr_type type, expr_t *expr1, expr_t *expr2, expr_t *expr3)
1222 expr_t *e;
1223 e = xmalloc(sizeof(expr_t));
1224 e->type = type;
1225 e->ref = expr1;
1226 e->u.ext = expr2;
1227 e->ext2 = expr3;
1228 e->is_const = FALSE;
1229 /* check for compile-time optimization */
1230 if (expr1->is_const && expr2->is_const && expr3->is_const) {
1231 e->is_const = TRUE;
1232 switch (type) {
1233 case EXPR_COND:
1234 e->cval = expr1->cval ? expr2->cval : expr3->cval;
1235 break;
1236 default:
1237 e->is_const = FALSE;
1238 break;
1241 return e;
1244 static expr_list_t *append_expr(expr_list_t *list, expr_t *expr)
1246 if (!expr) return list;
1247 if (!list)
1249 list = xmalloc( sizeof(*list) );
1250 list_init( list );
1252 list_add_tail( list, &expr->entry );
1253 return list;
1256 static array_dims_t *append_array(array_dims_t *list, expr_t *expr)
1258 if (!expr) return list;
1259 if (!list)
1261 list = xmalloc( sizeof(*list) );
1262 list_init( list );
1264 list_add_tail( list, &expr->entry );
1265 return list;
1268 static struct list type_pool = LIST_INIT(type_pool);
1269 typedef struct
1271 type_t data;
1272 struct list link;
1273 } type_pool_node_t;
1275 type_t *alloc_type(void)
1277 type_pool_node_t *node = xmalloc(sizeof *node);
1278 list_add_tail(&type_pool, &node->link);
1279 return &node->data;
1282 void set_all_tfswrite(int val)
1284 type_pool_node_t *node;
1285 LIST_FOR_EACH_ENTRY(node, &type_pool, type_pool_node_t, link)
1286 node->data.tfswrite = val;
1289 static type_t *make_type(unsigned char type, type_t *ref)
1291 type_t *t = alloc_type();
1292 t->name = NULL;
1293 t->kind = TKIND_PRIMITIVE;
1294 t->type = type;
1295 t->ref = ref;
1296 t->attrs = NULL;
1297 t->orig = NULL;
1298 t->funcs = NULL;
1299 t->fields = NULL;
1300 t->ifaces = NULL;
1301 t->dim = 0;
1302 t->size_is = NULL;
1303 t->length_is = NULL;
1304 t->typestring_offset = 0;
1305 t->ptrdesc = 0;
1306 t->declarray = FALSE;
1307 t->ignore = (parse_only != 0);
1308 t->is_const = FALSE;
1309 t->sign = 0;
1310 t->defined = FALSE;
1311 t->written = FALSE;
1312 t->user_types_registered = FALSE;
1313 t->tfswrite = FALSE;
1314 t->typelib_idx = -1;
1315 return t;
1318 static void set_type(var_t *v, type_t *type, int ptr_level, array_dims_t *arr,
1319 int top)
1321 expr_list_t *sizes = get_attrp(v->attrs, ATTR_SIZEIS);
1322 expr_list_t *lengs = get_attrp(v->attrs, ATTR_LENGTHIS);
1323 int ptr_attr = get_attrv(v->attrs, ATTR_POINTERTYPE);
1324 int ptr_type = ptr_attr;
1325 int sizeless, has_varconf;
1326 expr_t *dim;
1327 type_t *atype, **ptype;
1329 v->type = type;
1331 if (!ptr_type && top)
1332 ptr_type = RPC_FC_RP;
1334 for ( ; 0 < ptr_level; --ptr_level)
1336 v->type = make_type(pointer_default, v->type);
1337 if (ptr_level == 1 && ptr_type && !arr)
1339 v->type->type = ptr_type;
1340 ptr_type = 0;
1344 if (ptr_type && !arr)
1346 if (is_ptr(v->type))
1348 if (v->type->type != ptr_type)
1350 v->type = duptype(v->type, 1);
1351 v->type->type = ptr_type;
1354 else if (!arr && ptr_attr)
1355 error("%s: pointer attribute applied to non-pointer type\n", v->name);
1358 sizeless = FALSE;
1359 if (arr) LIST_FOR_EACH_ENTRY_REV(dim, arr, expr_t, entry)
1361 if (sizeless)
1362 error("%s: only the first array dimension can be unspecified\n", v->name);
1364 if (dim->is_const)
1366 unsigned int align = 0;
1367 size_t size = type_memsize(v->type, &align);
1369 if (dim->cval <= 0)
1370 error("%s: array dimension must be positive\n", v->name);
1372 if (0xffffffffuL / size < (unsigned long) dim->cval)
1373 error("%s: total array size is too large\n", v->name);
1374 else if (0xffffuL < size * dim->cval)
1375 v->type = make_type(RPC_FC_LGFARRAY, v->type);
1376 else
1377 v->type = make_type(RPC_FC_SMFARRAY, v->type);
1379 else
1381 sizeless = TRUE;
1382 v->type = make_type(RPC_FC_CARRAY, v->type);
1385 v->type->declarray = TRUE;
1386 v->type->dim = dim->cval;
1389 ptype = &v->type;
1390 has_varconf = FALSE;
1391 if (sizes) LIST_FOR_EACH_ENTRY(dim, sizes, expr_t, entry)
1393 if (dim->type != EXPR_VOID)
1395 has_varconf = TRUE;
1396 atype = *ptype = duptype(*ptype, 0);
1398 if (atype->type == RPC_FC_SMFARRAY || atype->type == RPC_FC_LGFARRAY)
1399 error("%s: cannot specify size_is for a fixed sized array\n", v->name);
1401 if (atype->type != RPC_FC_CARRAY && !is_ptr(atype))
1402 error("%s: size_is attribute applied to illegal type\n", v->name);
1404 atype->type = RPC_FC_CARRAY;
1405 atype->size_is = dim;
1408 ptype = &(*ptype)->ref;
1409 if (*ptype == NULL)
1410 error("%s: too many expressions in size_is attribute\n", v->name);
1413 ptype = &v->type;
1414 if (lengs) LIST_FOR_EACH_ENTRY(dim, lengs, expr_t, entry)
1416 if (dim->type != EXPR_VOID)
1418 has_varconf = TRUE;
1419 atype = *ptype = duptype(*ptype, 0);
1421 if (atype->type == RPC_FC_SMFARRAY)
1422 atype->type = RPC_FC_SMVARRAY;
1423 else if (atype->type == RPC_FC_LGFARRAY)
1424 atype->type = RPC_FC_LGVARRAY;
1425 else if (atype->type == RPC_FC_CARRAY)
1426 atype->type = RPC_FC_CVARRAY;
1427 else
1428 error("%s: length_is attribute applied to illegal type\n", v->name);
1430 atype->length_is = dim;
1433 ptype = &(*ptype)->ref;
1434 if (*ptype == NULL)
1435 error("%s: too many expressions in length_is attribute\n", v->name);
1438 if (has_varconf && !last_array(v->type))
1440 ptype = &v->type;
1441 for (ptype = &v->type; is_array(*ptype); ptype = &(*ptype)->ref)
1443 *ptype = duptype(*ptype, 0);
1444 (*ptype)->type = RPC_FC_BOGUS_ARRAY;
1448 if (is_array(v->type))
1450 const type_t *rt = v->type->ref;
1451 if (is_user_type(rt))
1452 v->type->type = RPC_FC_BOGUS_ARRAY;
1453 else
1454 switch (rt->type)
1456 case RPC_FC_BOGUS_STRUCT:
1457 case RPC_FC_NON_ENCAPSULATED_UNION:
1458 case RPC_FC_ENCAPSULATED_UNION:
1459 case RPC_FC_ENUM16:
1460 v->type->type = RPC_FC_BOGUS_ARRAY;
1461 break;
1462 /* FC_RP should be above, but widl overuses these, and will break things. */
1463 case RPC_FC_UP:
1464 case RPC_FC_RP:
1465 if (rt->ref->type == RPC_FC_IP)
1466 v->type->type = RPC_FC_BOGUS_ARRAY;
1467 break;
1472 static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface)
1474 if (!iface) return list;
1475 if (!list)
1477 list = xmalloc( sizeof(*list) );
1478 list_init( list );
1480 list_add_tail( list, &iface->entry );
1481 return list;
1484 static ifref_t *make_ifref(type_t *iface)
1486 ifref_t *l = xmalloc(sizeof(ifref_t));
1487 l->iface = iface;
1488 l->attrs = NULL;
1489 return l;
1492 static var_list_t *append_var(var_list_t *list, var_t *var)
1494 if (!var) return list;
1495 if (!list)
1497 list = xmalloc( sizeof(*list) );
1498 list_init( list );
1500 list_add_tail( list, &var->entry );
1501 return list;
1504 static var_t *make_var(char *name)
1506 var_t *v = xmalloc(sizeof(var_t));
1507 v->name = name;
1508 v->type = NULL;
1509 v->args = NULL;
1510 v->attrs = NULL;
1511 v->eval = NULL;
1512 return v;
1515 static pident_list_t *append_pident(pident_list_t *list, pident_t *p)
1517 if (!p) return list;
1518 if (!list) {
1519 list = xmalloc(sizeof(*list));
1520 list_init(list);
1522 list_add_tail(list, &p->entry);
1523 return list;
1526 static pident_t *make_pident(var_t *var)
1528 pident_t *p = xmalloc(sizeof(*p));
1529 p->var = var;
1530 p->ptr_level = 0;
1531 p->func_ptr_level = 0;
1532 return p;
1535 static func_list_t *append_func(func_list_t *list, func_t *func)
1537 if (!func) return list;
1538 if (!list)
1540 list = xmalloc( sizeof(*list) );
1541 list_init( list );
1543 list_add_tail( list, &func->entry );
1544 return list;
1547 static func_t *make_func(var_t *def)
1549 func_t *f = xmalloc(sizeof(func_t));
1550 f->def = def;
1551 f->args = def->args;
1552 def->args = NULL;
1553 f->ignore = parse_only;
1554 f->idx = -1;
1555 return f;
1558 static type_t *make_class(char *name)
1560 type_t *c = make_type(0, NULL);
1561 c->name = name;
1562 c->kind = TKIND_COCLASS;
1563 return c;
1566 static type_t *make_safearray(type_t *type)
1568 type_t *sa = duptype(find_type("SAFEARRAY", 0), 1);
1569 sa->ref = type;
1570 return make_type(pointer_default, sa);
1573 #define HASHMAX 64
1575 static int hash_ident(const char *name)
1577 const char *p = name;
1578 int sum = 0;
1579 /* a simple sum hash is probably good enough */
1580 while (*p) {
1581 sum += *p;
1582 p++;
1584 return sum & (HASHMAX-1);
1587 /***** type repository *****/
1589 struct rtype {
1590 const char *name;
1591 type_t *type;
1592 int t;
1593 struct rtype *next;
1596 struct rtype *type_hash[HASHMAX];
1598 static type_t *reg_type(type_t *type, const char *name, int t)
1600 struct rtype *nt;
1601 int hash;
1602 if (!name) {
1603 error_loc("registering named type without name\n");
1604 return type;
1606 hash = hash_ident(name);
1607 nt = xmalloc(sizeof(struct rtype));
1608 nt->name = name;
1609 nt->type = type;
1610 nt->t = t;
1611 nt->next = type_hash[hash];
1612 type_hash[hash] = nt;
1613 return type;
1616 static int is_incomplete(const type_t *t)
1618 return !t->defined && (is_struct(t->type) || is_union(t->type));
1621 static void add_incomplete(type_t *t)
1623 struct typenode *tn = xmalloc(sizeof *tn);
1624 tn->type = t;
1625 list_add_tail(&incomplete_types, &tn->entry);
1628 static void fix_type(type_t *t)
1630 if (t->kind == TKIND_ALIAS && is_incomplete(t)) {
1631 type_t *ot = t->orig;
1632 fix_type(ot);
1633 t->fields = ot->fields;
1634 t->defined = ot->defined;
1638 static void fix_incomplete(void)
1640 struct typenode *tn, *next;
1642 LIST_FOR_EACH_ENTRY_SAFE(tn, next, &incomplete_types, struct typenode, entry) {
1643 fix_type(tn->type);
1644 free(tn);
1648 static type_t *reg_typedefs(type_t *type, pident_list_t *pidents, attr_list_t *attrs)
1650 type_t *ptr = type;
1651 const pident_t *pident;
1652 int ptrc = 0;
1653 int is_str = is_attr(attrs, ATTR_STRING);
1654 unsigned char ptr_type = get_attrv(attrs, ATTR_POINTERTYPE);
1656 if (is_str)
1658 type_t *t = type;
1659 unsigned char c;
1661 while (is_ptr(t))
1662 t = t->ref;
1664 c = t->type;
1665 if (c != RPC_FC_CHAR && c != RPC_FC_BYTE && c != RPC_FC_WCHAR)
1667 pident = LIST_ENTRY( list_head( pidents ), const pident_t, entry );
1668 error_loc("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
1669 pident->var->name);
1673 /* We must generate names for tagless enum, struct or union.
1674 Typedef-ing a tagless enum, struct or union means we want the typedef
1675 to be included in a library whether it has other attributes or not,
1676 hence the public attribute. */
1677 if ((type->kind == TKIND_ENUM || type->kind == TKIND_RECORD
1678 || type->kind == TKIND_UNION) && ! type->name && ! parse_only)
1680 if (! is_attr(attrs, ATTR_PUBLIC))
1681 attrs = append_attr( attrs, make_attr(ATTR_PUBLIC) );
1682 type->name = gen_name();
1685 LIST_FOR_EACH_ENTRY( pident, pidents, const pident_t, entry )
1687 var_t *name = pident->var;
1689 if (name->name) {
1690 type_t *cur = ptr;
1691 int cptr = pident->ptr_level;
1692 if (cptr > ptrc) {
1693 while (cptr > ptrc) {
1694 cur = ptr = make_type(pointer_default, cur);
1695 ptrc++;
1697 } else {
1698 while (cptr < ptrc) {
1699 cur = cur->ref;
1700 cptr++;
1703 cur = alias(cur, name->name);
1704 cur->attrs = attrs;
1705 if (ptr_type)
1707 if (is_ptr(cur))
1708 cur->type = ptr_type;
1709 else
1710 error_loc("'%s': pointer attribute applied to non-pointer type\n",
1711 cur->name);
1713 else if (is_str && ! is_ptr(cur))
1714 error_loc("'%s': [string] attribute applied to non-pointer type\n",
1715 cur->name);
1717 if (is_incomplete(cur))
1718 add_incomplete(cur);
1719 reg_type(cur, cur->name, 0);
1722 return type;
1725 static type_t *find_type(const char *name, int t)
1727 struct rtype *cur = type_hash[hash_ident(name)];
1728 while (cur && (cur->t != t || strcmp(cur->name, name)))
1729 cur = cur->next;
1730 if (!cur) {
1731 error_loc("type '%s' not found\n", name);
1732 return NULL;
1734 return cur->type;
1737 static type_t *find_type2(char *name, int t)
1739 type_t *tp = find_type(name, t);
1740 free(name);
1741 return tp;
1744 int is_type(const char *name)
1746 struct rtype *cur = type_hash[hash_ident(name)];
1747 while (cur && (cur->t || strcmp(cur->name, name)))
1748 cur = cur->next;
1749 if (cur) return TRUE;
1750 return FALSE;
1753 static type_t *get_type(unsigned char type, char *name, int t)
1755 struct rtype *cur = NULL;
1756 type_t *tp;
1757 if (name) {
1758 cur = type_hash[hash_ident(name)];
1759 while (cur && (cur->t != t || strcmp(cur->name, name)))
1760 cur = cur->next;
1762 if (cur) {
1763 free(name);
1764 return cur->type;
1766 tp = make_type(type, NULL);
1767 tp->name = name;
1768 if (!name) return tp;
1769 return reg_type(tp, name, t);
1772 static type_t *get_typev(unsigned char type, var_t *name, int t)
1774 char *sname = NULL;
1775 if (name) {
1776 sname = name->name;
1777 free(name);
1779 return get_type(type, sname, t);
1782 static int get_struct_type(var_list_t *fields)
1784 int has_pointer = 0;
1785 int has_conformance = 0;
1786 int has_variance = 0;
1787 var_t *field;
1789 if (get_padding(fields))
1790 return RPC_FC_BOGUS_STRUCT;
1792 if (fields) LIST_FOR_EACH_ENTRY( field, fields, var_t, entry )
1794 type_t *t = field->type;
1796 if (is_user_type(t))
1797 return RPC_FC_BOGUS_STRUCT;
1799 if (is_ptr(t))
1802 t = t->ref;
1803 while (is_ptr(t));
1805 switch (t->type)
1807 case RPC_FC_IP:
1808 case RPC_FC_ENCAPSULATED_UNION:
1809 case RPC_FC_NON_ENCAPSULATED_UNION:
1810 case RPC_FC_BOGUS_STRUCT:
1811 return RPC_FC_BOGUS_STRUCT;
1814 has_pointer = 1;
1815 continue;
1818 if (field->type->declarray)
1820 if (is_string_type(field->attrs, field->type))
1822 if (is_conformant_array(field->type))
1823 has_conformance = 1;
1824 has_variance = 1;
1825 continue;
1828 if (is_array(field->type->ref))
1829 return RPC_FC_BOGUS_STRUCT;
1831 if (is_conformant_array(field->type))
1833 has_conformance = 1;
1834 if (field->type->declarray && list_next(fields, &field->entry))
1835 error_loc("field '%s' deriving from a conformant array must be the last field in the structure\n",
1836 field->name);
1838 if (field->type->length_is)
1839 has_variance = 1;
1841 t = field->type->ref;
1844 switch (t->type)
1847 * RPC_FC_BYTE, RPC_FC_STRUCT, etc
1848 * Simple types don't effect the type of struct.
1849 * A struct containing a simple struct is still a simple struct.
1850 * So long as we can block copy the data, we return RPC_FC_STRUCT.
1852 case 0: /* void pointer */
1853 case RPC_FC_BYTE:
1854 case RPC_FC_CHAR:
1855 case RPC_FC_SMALL:
1856 case RPC_FC_USMALL:
1857 case RPC_FC_WCHAR:
1858 case RPC_FC_SHORT:
1859 case RPC_FC_USHORT:
1860 case RPC_FC_LONG:
1861 case RPC_FC_ULONG:
1862 case RPC_FC_INT3264:
1863 case RPC_FC_UINT3264:
1864 case RPC_FC_HYPER:
1865 case RPC_FC_FLOAT:
1866 case RPC_FC_DOUBLE:
1867 case RPC_FC_STRUCT:
1868 case RPC_FC_ENUM32:
1869 break;
1871 case RPC_FC_RP:
1872 case RPC_FC_UP:
1873 case RPC_FC_FP:
1874 case RPC_FC_OP:
1875 case RPC_FC_CARRAY:
1876 case RPC_FC_CVARRAY:
1877 case RPC_FC_BOGUS_ARRAY:
1878 has_pointer = 1;
1879 break;
1882 * Propagate member attributes
1883 * a struct should be at least as complex as its member
1885 case RPC_FC_CVSTRUCT:
1886 has_conformance = 1;
1887 has_variance = 1;
1888 has_pointer = 1;
1889 break;
1891 case RPC_FC_CPSTRUCT:
1892 has_conformance = 1;
1893 if (list_next( fields, &field->entry ))
1894 error_loc("field '%s' deriving from a conformant array must be the last field in the structure\n",
1895 field->name);
1896 has_pointer = 1;
1897 break;
1899 case RPC_FC_CSTRUCT:
1900 has_conformance = 1;
1901 if (list_next( fields, &field->entry ))
1902 error_loc("field '%s' deriving from a conformant array must be the last field in the structure\n",
1903 field->name);
1904 break;
1906 case RPC_FC_PSTRUCT:
1907 has_pointer = 1;
1908 break;
1910 default:
1911 error_loc("Unknown struct member %s with type (0x%02x)\n", field->name, t->type);
1912 /* fallthru - treat it as complex */
1914 /* as soon as we see one of these these members, it's bogus... */
1915 case RPC_FC_ENCAPSULATED_UNION:
1916 case RPC_FC_NON_ENCAPSULATED_UNION:
1917 case RPC_FC_BOGUS_STRUCT:
1918 case RPC_FC_ENUM16:
1919 return RPC_FC_BOGUS_STRUCT;
1923 if( has_variance )
1925 if ( has_conformance )
1926 return RPC_FC_CVSTRUCT;
1927 else
1928 return RPC_FC_BOGUS_STRUCT;
1930 if( has_conformance && has_pointer )
1931 return RPC_FC_CPSTRUCT;
1932 if( has_conformance )
1933 return RPC_FC_CSTRUCT;
1934 if( has_pointer )
1935 return RPC_FC_PSTRUCT;
1936 return RPC_FC_STRUCT;
1939 /***** constant repository *****/
1941 struct rconst {
1942 char *name;
1943 var_t *var;
1944 struct rconst *next;
1947 struct rconst *const_hash[HASHMAX];
1949 static var_t *reg_const(var_t *var)
1951 struct rconst *nc;
1952 int hash;
1953 if (!var->name) {
1954 error_loc("registering constant without name\n");
1955 return var;
1957 hash = hash_ident(var->name);
1958 nc = xmalloc(sizeof(struct rconst));
1959 nc->name = var->name;
1960 nc->var = var;
1961 nc->next = const_hash[hash];
1962 const_hash[hash] = nc;
1963 return var;
1966 static var_t *find_const(char *name, int f)
1968 struct rconst *cur = const_hash[hash_ident(name)];
1969 while (cur && strcmp(cur->name, name))
1970 cur = cur->next;
1971 if (!cur) {
1972 if (f) error_loc("constant '%s' not found\n", name);
1973 return NULL;
1975 return cur->var;
1978 static void write_libid(const char *name, const attr_list_t *attr)
1980 const UUID *uuid = get_attrp(attr, ATTR_UUID);
1981 write_guid(idfile, "LIBID", name, uuid);
1984 static void write_clsid(type_t *cls)
1986 const UUID *uuid = get_attrp(cls->attrs, ATTR_UUID);
1987 write_guid(idfile, "CLSID", cls->name, uuid);
1990 static void write_diid(type_t *iface)
1992 const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
1993 write_guid(idfile, "DIID", iface->name, uuid);
1996 static void write_iid(type_t *iface)
1998 const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
1999 write_guid(idfile, "IID", iface->name, uuid);
2002 static int compute_method_indexes(type_t *iface)
2004 int idx;
2005 func_t *f;
2007 if (iface->ref)
2008 idx = compute_method_indexes(iface->ref);
2009 else
2010 idx = 0;
2012 if (!iface->funcs)
2013 return idx;
2015 LIST_FOR_EACH_ENTRY( f, iface->funcs, func_t, entry )
2016 if (! is_callas(f->def->attrs))
2017 f->idx = idx++;
2019 return idx;
2022 static char *gen_name(void)
2024 static const char format[] = "__WIDL_%s_generated_name_%08lX";
2025 static unsigned long n = 0;
2026 static const char *file_id;
2027 static size_t size;
2028 char *name;
2030 if (! file_id)
2032 char *dst = dup_basename(input_name, ".idl");
2033 file_id = dst;
2035 for (; *dst; ++dst)
2036 if (! isalnum((unsigned char) *dst))
2037 *dst = '_';
2039 size = sizeof format - 7 + strlen(file_id) + 8;
2042 name = xmalloc(size);
2043 sprintf(name, format, file_id, n++);
2044 return name;
2047 static void process_typedefs(pident_list_t *pidents)
2049 pident_t *pident, *next;
2051 if (!pidents) return;
2052 LIST_FOR_EACH_ENTRY_SAFE( pident, next, pidents, pident_t, entry )
2054 var_t *var = pident->var;
2055 type_t *type = find_type(var->name, 0);
2057 if (! parse_only && do_header)
2058 write_typedef(type);
2059 if (in_typelib && type->attrs)
2060 add_typelib_entry(type);
2062 free(pident);
2063 free(var);
2067 static void check_arg(var_t *arg)
2069 type_t *t = arg->type;
2071 if (t->type == 0 && ! is_var_ptr(arg))
2072 error_loc("argument '%s' has void type\n", arg->name);
2075 static void check_all_user_types(ifref_list_t *ifrefs)
2077 const ifref_t *ifref;
2078 const func_t *f;
2080 if (ifrefs) LIST_FOR_EACH_ENTRY(ifref, ifrefs, const ifref_t, entry)
2082 const func_list_t *fs = ifref->iface->funcs;
2083 if (fs) LIST_FOR_EACH_ENTRY(f, fs, const func_t, entry)
2084 check_for_additional_prototype_types(f->args);
2088 int is_valid_uuid(const char *s)
2090 int i;
2092 for (i = 0; i < 36; ++i)
2093 if (i == 8 || i == 13 || i == 18 || i == 23)
2095 if (s[i] != '-')
2096 return FALSE;
2098 else
2099 if (!isxdigit(s[i]))
2100 return FALSE;
2102 return s[i] == '\0';