|
|
1.1 root 1: /* YACC parser for C syntax.
2: Copyright (C) 1987, 1988 Free Software Foundation, Inc.
3:
4: This file is part of GNU CC.
5:
6: GNU CC is distributed in the hope that it will be useful,
7: but WITHOUT ANY WARRANTY. No author or distributor
8: accepts responsibility to anyone for the consequences of using it
9: or for whether it serves any particular purpose or works at all,
10: unless he says so in writing. Refer to the GNU CC General Public
11: License for full details.
12:
13: Everyone is granted permission to copy, modify and redistribute
14: GNU CC, but only under the conditions described in the
15: GNU CC General Public License. A copy of this license is
16: supposed to have been given to you along with GNU CC so you
17: can know your rights and responsibilities. It should be in a
18: file named COPYING. Among other things, the copyright notice
19: and this notice must be preserved on all copies. */
20:
21:
22: /* To whomever it may concern: I have heard that such a thing was once
23: written by AT&T, but I have never seen it. */
24:
25: %expect 23
26:
27: /* These are the 23 conflicts you should get in parse.output;
28: the state numbers may vary if minor changes in the grammar are made.
29:
30: State 41 contains 1 shift/reduce conflict. (Two ways to recover from error.)
31: State 90 contains 1 shift/reduce conflict. (Two ways to recover from error.)
32: State 97 contains 1 shift/reduce conflict. (Two ways to recover from error.)
33: State 101 contains 1 shift/reduce conflict. (Two ways to recover from error.)
34: State 117 contains 1 shift/reduce conflict. (See comment at component_decl.)
35: State 169 contains 2 shift/reduce conflicts. (make notype_declarator longer.)
36: State 181 contains 1 shift/reduce conflict. (Two ways to recover from error.)
37: State 191 contains 1 shift/reduce conflict. (Two ways to recover from error.)
38: State 197 contains 1 shift/reduce conflict. (Two ways to recover from error.)
39: State 239 contains 2 shift/reduce conflicts. (make absdcl1 longer if poss.)
40: State 269 contains 2 shift/reduce conflicts. (same for after_type_declarator).
41: State 299 contains 2 shift/reduce conflicts. (similar for absdcl1 again.)
42: State 362 contains 1 shift/reduce conflict. (dangling else.)
43: State 370 contains 2 shift/reduce conflicts. (like 241, other context.)
44: State 373 contains 2 shift/reduce conflicts. (like 241, other context.)
45: State 411 contains 2 shift/reduce conflicts. (like 166 for parm_declarator)?
46: */
47:
48: %{
49: #include "config.h"
50: #include "tree.h"
1.1.1.2 root 51: #include "c-parse.h"
1.1 root 52: #include "c-tree.h"
53:
54: #include <stdio.h>
55: #include <errno.h>
56:
57: #ifndef errno
58: extern int errno;
59: #endif
60:
61: /* Cause the `yydebug' variable to be defined. */
62: #define YYDEBUG
63: %}
64:
65: %start program
66:
67: %union {long itype; tree ttype; enum tree_code code; char *cptr; }
68:
69: /* All identifiers that are not reserved words
70: and are not declared typedefs in the current block */
71: %token IDENTIFIER
72:
73: /* All identifiers that are declared typedefs in the current block.
74: In some contexts, they are treated just like IDENTIFIER,
75: but they can also serve as typespecs in declarations. */
76: %token TYPENAME
77:
78: /* Reserved words that specify storage class.
79: yylval contains an IDENTIFIER_NODE which indicates which one. */
80: %token SCSPEC
81:
82: /* Reserved words that specify type.
83: yylval contains an IDENTIFIER_NODE which indicates which one. */
84: %token TYPESPEC
85:
86: /* Reserved words that qualify type: "const" or "volatile".
87: yylval contains an IDENTIFIER_NODE which indicates which one. */
88: %token TYPE_QUAL
89:
90: /* Character or numeric constants.
91: yylval is the node for the constant. */
92: %token CONSTANT
93:
94: /* String constants in raw form.
95: yylval is a STRING_CST node. */
96: %token STRING
97:
98: /* "...", used for functions with variable arglists. */
99: %token ELLIPSIS
100:
101: /* the reserved words */
102: %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
103: %token BREAK CONTINUE RETURN GOTO ASM TYPEOF ALIGNOF
104:
105: /* Define the operator tokens and their precedences.
106: The value is an integer because, if used, it is the tree code
107: to use in the expression made from the operator. */
108:
109: %right <code> ASSIGN '='
110: %right <code> '?' ':'
111: %left <code> OROR
112: %left <code> ANDAND
113: %left <code> '|'
114: %left <code> '^'
115: %left <code> '&'
116: %left <code> EQCOMPARE
117: %left <code> ARITHCOMPARE
118: %left <code> LSHIFT RSHIFT
119: %left <code> '+' '-'
120: %left <code> '*' '/' '%'
121: %right <code> UNARY PLUSPLUS MINUSMINUS
122: %left HYPERUNARY
123: %left <code> POINTSAT '.'
124:
125: %type <code> unop
126:
127: %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
128: %type <ttype> expr_no_commas primary string STRING
129: %type <ttype> typed_declspecs reserved_declspecs
130: %type <ttype> typed_typespecs reserved_typespecquals
131: %type <ttype> declmods typespec typespecqual_reserved
132: %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
133: %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
134: %type <ttype> init initlist maybeasm
1.1.1.3 ! root 135: %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
1.1 root 136:
137: %type <ttype> declarator
138: %type <ttype> notype_declarator after_type_declarator
139: %type <ttype> parm_declarator
140:
141: %type <ttype> structsp component_decl_list component_decl components component_declarator
142: %type <ttype> enumlist enumerator
143: %type <ttype> typename absdcl absdcl1 type_quals
144: %type <ttype> xexpr parms parm identifiers
145:
146: %type <ttype> parmlist parmlist_1 parmlist_2
147: %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
148:
149: %type <itype> setspecs
150:
151: %{
152: /* the declaration found for the last IDENTIFIER token read in.
153: yylex must look this up to detect typedefs, which get token type TYPENAME,
154: so it is left around in case the identifier is not a typedef but is
155: used in a context which makes it a reference to a variable. */
156: static tree lastiddecl;
157:
158: static tree make_pointer_declarator ();
159: static tree combine_strings ();
160: static void reinit_parse_for_function ();
161:
162: extern double atof ();
163:
164: /* List of types and structure classes of the current declaration */
165: tree current_declspecs;
166:
167: char *input_filename; /* source file current line is coming from */
168: char *main_input_filename; /* top-level source file */
169:
170: static int yylex ();
171: %}
172:
173: %%
174: program: /* empty */
175: | extdefs
176: ;
177:
178: /* the reason for the strange actions in this rule
179: is so that notype_initdecls when reached via datadef
180: can find a valid list of type and sc specs in $0. */
181:
182: extdefs:
183: {$<ttype>$ = NULL_TREE; } extdef
184: | extdefs {$<ttype>$ = NULL_TREE; } extdef
185: ;
186:
187: extdef:
188: fndef
189: | datadef
190: | ASM '(' string ')' ';'
191: { if (pedantic)
192: warning ("ANSI C forbids use of `asm' keyword");
193: if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
194: assemble_asm ($3); }
195: ;
196:
197: datadef:
198: setspecs notype_initdecls ';'
199: { if (pedantic)
200: error ("ANSI C forbids data definition lacking type or storage class");
1.1.1.3 ! root 201: else if (!flag_traditional)
1.1 root 202: warning ("data definition lacks type or storage class"); }
203: | declmods setspecs notype_initdecls ';'
204: {}
205: | typed_declspecs setspecs initdecls ';'
206: {}
207: | declmods ';'
208: { error ("empty declaration"); }
209: | typed_declspecs ';'
210: { shadow_tag ($1); }
211: | error ';'
212: | error '}'
213: | ';'
214: ;
215:
216: fndef:
217: typed_declspecs setspecs declarator
218: { if (! start_function ($1, $3))
219: YYFAIL;
220: reinit_parse_for_function (); }
221: xdecls
222: { store_parm_decls (); }
223: compstmt_or_error
224: { finish_function (); }
225: | typed_declspecs setspecs declarator error
226: { }
227: | declmods setspecs notype_declarator
228: { if (! start_function ($1, $3))
229: YYFAIL;
230: reinit_parse_for_function (); }
231: xdecls
232: { store_parm_decls (); }
233: compstmt_or_error
234: { finish_function (); }
235: | declmods setspecs notype_declarator error
236: { }
237: | setspecs notype_declarator
238: { if (! start_function (0, $2))
239: YYFAIL;
240: reinit_parse_for_function (); }
241: xdecls
242: { store_parm_decls (); }
243: compstmt_or_error
244: { finish_function (); }
245: | setspecs notype_declarator error
246: { }
247: ;
248:
249: identifier:
250: IDENTIFIER
251: | TYPENAME
252: ;
253:
254: unop: '&'
255: { $$ = ADDR_EXPR; }
256: | '-'
257: { $$ = NEGATE_EXPR; }
258: | '+'
259: { $$ = CONVERT_EXPR; }
260: | PLUSPLUS
261: { $$ = PREINCREMENT_EXPR; }
262: | MINUSMINUS
263: { $$ = PREDECREMENT_EXPR; }
264: | '~'
265: { $$ = BIT_NOT_EXPR; }
266: | '!'
267: { $$ = TRUTH_NOT_EXPR; }
268: ;
269:
270: expr: nonnull_exprlist
271: { $$ = build_compound_expr ($1); }
272: ;
273:
274: exprlist:
275: /* empty */
276: { $$ = NULL_TREE; }
277: | nonnull_exprlist
278: ;
279:
280: nonnull_exprlist:
281: expr_no_commas
282: { $$ = build_tree_list (NULL_TREE, $1); }
283: | nonnull_exprlist ',' expr_no_commas
284: { chainon ($1, build_tree_list (NULL_TREE, $3)); }
285: ;
286:
287: expr_no_commas:
288: primary
289: | '*' expr_no_commas %prec UNARY
290: { $$ = build_indirect_ref ($2, "unary *"); }
291: | unop expr_no_commas %prec UNARY
292: { $$ = build_unary_op ($1, $2, 0); }
293: | '(' typename ')' expr_no_commas %prec UNARY
294: { tree type = groktypename ($2);
295: $$ = build_c_cast (type, $4); }
296: | '(' typename ')' '{' initlist maybecomma '}' %prec UNARY
297: { tree type = groktypename ($2);
298: if (pedantic)
299: warning ("ANSI C forbids constructor-expressions");
300: $$ = digest_init (type, build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($5)), 0);
301: if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
302: {
303: int failure = complete_array_type (type, $$, 1);
304: if (failure)
305: abort ();
306: }
307: }
308: | SIZEOF expr_no_commas %prec UNARY
309: { if (TREE_CODE ($2) == COMPONENT_REF
310: && TREE_PACKED (TREE_OPERAND ($2, 1)))
311: error ("sizeof applied to a bit-field");
312: $$ = c_sizeof (TREE_TYPE ($2)); }
313: | SIZEOF '(' typename ')' %prec HYPERUNARY
314: { $$ = c_sizeof (groktypename ($3)); }
315: | ALIGNOF expr_no_commas %prec UNARY
316: { if (TREE_CODE ($2) == COMPONENT_REF
317: && TREE_PACKED (TREE_OPERAND ($2, 1)))
318: error ("__alignof applied to a bit-field");
319: $$ = c_alignof (TREE_TYPE ($2)); }
320: | ALIGNOF '(' typename ')' %prec HYPERUNARY
321: { $$ = c_alignof (groktypename ($3)); }
322: | expr_no_commas '+' expr_no_commas
323: { $$ = build_binary_op ($2, $1, $3); }
324: | expr_no_commas '-' expr_no_commas
325: { $$ = build_binary_op ($2, $1, $3); }
326: | expr_no_commas '*' expr_no_commas
327: { $$ = build_binary_op ($2, $1, $3); }
328: | expr_no_commas '/' expr_no_commas
329: { $$ = build_binary_op ($2, $1, $3); }
330: | expr_no_commas '%' expr_no_commas
331: { $$ = build_binary_op ($2, $1, $3); }
332: | expr_no_commas LSHIFT expr_no_commas
333: { $$ = build_binary_op ($2, $1, $3); }
334: | expr_no_commas RSHIFT expr_no_commas
335: { $$ = build_binary_op ($2, $1, $3); }
336: | expr_no_commas ARITHCOMPARE expr_no_commas
337: { $$ = build_binary_op ($2, $1, $3); }
338: | expr_no_commas EQCOMPARE expr_no_commas
339: { $$ = build_binary_op ($2, $1, $3); }
340: | expr_no_commas '&' expr_no_commas
341: { $$ = build_binary_op ($2, $1, $3); }
342: | expr_no_commas '|' expr_no_commas
343: { $$ = build_binary_op ($2, $1, $3); }
344: | expr_no_commas '^' expr_no_commas
345: { $$ = build_binary_op ($2, $1, $3); }
346: | expr_no_commas ANDAND expr_no_commas
347: { $$ = build_binary_op (TRUTH_ANDIF_EXPR, $1, $3); }
348: | expr_no_commas OROR expr_no_commas
349: { $$ = build_binary_op (TRUTH_ORIF_EXPR, $1, $3); }
350: | expr_no_commas '?' xexpr ':' expr_no_commas
351: { $$ = build_conditional_expr ($1, $3, $5); }
352: | expr_no_commas '=' expr_no_commas
353: { $$ = build_modify_expr ($1, NOP_EXPR, $3); }
354: | expr_no_commas ASSIGN expr_no_commas
355: { $$ = build_modify_expr ($1, $2, $3); }
356: ;
357:
358: primary:
359: IDENTIFIER
360: { $$ = lastiddecl;
361: if (!$$)
362: {
363: if (yychar == YYEMPTY)
364: yychar = YYLEX;
365: if (yychar == '(')
366: $$ = implicitly_declare ($1);
367: else
368: {
369: if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node)
370: error ("undeclared variable `%s' (first use here)",
371: IDENTIFIER_POINTER ($1));
372: $$ = error_mark_node;
373: /* Prevent repeated error messages. */
374: IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
375: }
376: }
377: if (TREE_CODE ($$) == CONST_DECL)
378: $$ = DECL_INITIAL ($$);
379: }
380: | CONSTANT
381: | string
382: { $$ = combine_strings ($1); }
383: | '(' expr ')'
384: { $$ = $2; }
385: | '(' error ')'
386: { $$ = error_mark_node; }
387: | '('
388: { if (current_function_decl == 0)
389: {
390: error ("braced-group within expression allowed only inside a function");
391: YYFAIL;
392: }
1.1.1.2 root 393: $<ttype>$ = expand_start_stmt_expr (); }
1.1 root 394: compstmt ')'
395: { if (pedantic)
396: warning ("ANSI C forbids braced-groups within expressions");
1.1.1.2 root 397: $$ = expand_end_stmt_expr ($<ttype>2); }
1.1 root 398: | primary '(' exprlist ')' %prec '.'
399: { $$ = build_function_call ($1, $3); }
400: | primary '[' expr ']' %prec '.'
401: { $$ = build_array_ref ($1, $3); }
402: | primary '.' identifier
403: { $$ = build_component_ref ($1, $3); }
404: | primary POINTSAT identifier
405: { $$ = build_component_ref (build_indirect_ref ($1, "->"), $3); }
406: | primary PLUSPLUS
407: { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
408: | primary MINUSMINUS
409: { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
410: ;
411:
412: /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
413: string:
414: STRING
415: | string STRING
416: { $$ = chainon ($1, $2); }
417: ;
418:
419: xdecls:
420: /* empty */
421: | decls
422: ;
423:
424: decls:
425: decl
426: | errstmt
427: | decls decl
428: | decl errstmt
429: ;
430:
431: /* records the type and storage class specs to use for processing
432: the declarators that follow */
433: setspecs: /* empty */
434: { current_declspecs = $<ttype>0;
435: $$ = suspend_momentary (); }
436: ;
437:
438: decl:
439: typed_declspecs setspecs initdecls ';'
440: { resume_momentary ($2); }
441: | declmods setspecs notype_initdecls ';'
442: { resume_momentary ($2); }
443: | typed_declspecs ';'
444: { shadow_tag ($1); }
445: | declmods ';'
446: { warning ("empty declaration"); }
447: ;
448:
449: /* Declspecs which contain at least one type specifier or typedef name.
450: (Just `const' or `volatile' is not enough.)
451: A typedef'd name following these is taken as a name to be declared. */
452:
453: typed_declspecs:
454: typespec reserved_declspecs
455: { $$ = tree_cons (NULL_TREE, $1, $2); }
456: | declmods typespec reserved_declspecs
457: { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
458: ;
459:
460: reserved_declspecs: /* empty */
461: { $$ = NULL_TREE; }
462: | reserved_declspecs typespecqual_reserved
463: { $$ = tree_cons (NULL_TREE, $2, $1); }
464: | reserved_declspecs SCSPEC
465: { $$ = tree_cons (NULL_TREE, $2, $1); }
466: ;
467:
468: /* List of just storage classes and type modifiers.
469: A declaration can start with just this, but then it cannot be used
470: to redeclare a typedef-name. */
471:
472: declmods:
473: TYPE_QUAL
474: { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
475: | SCSPEC
476: { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
477: | declmods TYPE_QUAL
478: { $$ = tree_cons (NULL_TREE, $2, $1); }
479: | declmods SCSPEC
480: { $$ = tree_cons (NULL_TREE, $2, $1); }
481: ;
482:
483:
484: /* Used instead of declspecs where storage classes are not allowed
485: (that is, for typenames and structure components).
486: Don't accept a typedef-name if anything but a modifier precedes it. */
487:
488: typed_typespecs:
489: typespec reserved_typespecquals
490: { $$ = tree_cons (NULL_TREE, $1, $2); }
491: | nonempty_type_quals typespec reserved_typespecquals
492: { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
493: ;
494:
495: reserved_typespecquals: /* empty */
496: { $$ = NULL_TREE; }
497: | reserved_typespecquals typespecqual_reserved
498: { $$ = tree_cons (NULL_TREE, $2, $1); }
499: ;
500:
501: /* A typespec (but not a type qualifier).
502: Once we have seen one of these in a declaration,
503: if a typedef name appears then it is being redeclared. */
504:
505: typespec: TYPESPEC
506: | structsp
507: | TYPENAME
508: | TYPEOF '(' expr ')'
509: { $$ = TREE_TYPE ($3);
510: if (pedantic)
511: warning ("ANSI C forbids `typeof'"); }
512: | TYPEOF '(' typename ')'
513: { $$ = groktypename ($3);
514: if (pedantic)
515: warning ("ANSI C forbids `typeof'"); }
516: ;
517:
518: /* A typespec that is a reserved word, or a type qualifier. */
519:
520: typespecqual_reserved: TYPESPEC
521: | TYPE_QUAL
522: | structsp
523: ;
524:
525: initdecls:
526: initdcl
527: | initdecls ',' initdcl
528: ;
529:
530: notype_initdecls:
531: notype_initdcl
532: | notype_initdecls ',' initdcl
533: ;
534:
535: maybeasm:
536: /* empty */
537: { $$ = NULL_TREE; }
538: | ASM '(' string ')'
539: { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
540: $$ = $3;
541: if (pedantic)
542: warning ("ANSI C forbids use of `asm' keyword");
543: }
544: ;
545:
546: initdcl:
547: declarator maybeasm '='
548: { $<ttype>$ = start_decl ($1, current_declspecs, 1); }
549: init
550: /* Note how the declaration of the variable is in effect while its init is parsed! */
551: { finish_decl ($<ttype>4, $5, $2); }
552: | declarator maybeasm
553: { tree d = start_decl ($1, current_declspecs, 0);
554: finish_decl (d, NULL_TREE, $2); }
555: ;
556:
557: notype_initdcl:
558: notype_declarator maybeasm '='
559: { $<ttype>$ = start_decl ($1, current_declspecs, 1); }
560: init
561: /* Note how the declaration of the variable is in effect while its init is parsed! */
562: { finish_decl ($<ttype>4, $5, $2); }
563: | notype_declarator maybeasm
564: { tree d = start_decl ($1, current_declspecs, 0);
565: finish_decl (d, NULL_TREE, $2); }
566: ;
567:
568: init:
569: expr_no_commas
1.1.1.2 root 570: | '{' '}'
571: { $$ = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
572: if (pedantic)
573: warning ("ANSI C forbids empty initializer braces"); }
1.1 root 574: | '{' initlist '}'
575: { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2)); }
576: | '{' initlist ',' '}'
577: { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2)); }
578: | error
579: { $$ = NULL_TREE; }
580: ;
581:
582: /* This chain is built in reverse order,
583: and put in forward order where initlist is used. */
584: initlist:
1.1.1.2 root 585: init
1.1 root 586: { $$ = build_tree_list (NULL_TREE, $1); }
587: | initlist ',' init
588: { $$ = tree_cons (NULL_TREE, $3, $1); }
589: ;
590:
591: /* Any kind of declarator (thus, all declarators allowed
592: after an explicit typespec). */
593:
594: declarator:
595: after_type_declarator
596: | notype_declarator
597: ;
598:
599: /* A declarator that is allowed only after an explicit typespec. */
600:
601: after_type_declarator:
602: '(' after_type_declarator ')'
603: { $$ = $2; }
604: | after_type_declarator '(' parmlist_or_identifiers %prec '.'
605: { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
606: /* | after_type_declarator '(' error ')' %prec '.'
607: { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
608: poplevel (0, 0, 0); } */
609: | after_type_declarator '[' expr ']' %prec '.'
610: { $$ = build_nt (ARRAY_REF, $1, $3); }
611: | after_type_declarator '[' ']' %prec '.'
612: { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
613: | '*' type_quals after_type_declarator %prec UNARY
614: { $$ = make_pointer_declarator ($2, $3); }
615: | TYPENAME
616: ;
617:
618: /* Kinds of declarator that can appear in a parameter list
619: in addition to notype_declarator. This is like after_type_declarator
620: but does not allow a typedef name in parentheses as an identifier
621: (because it would conflict with a function with that typedef as arg). */
622:
623: parm_declarator:
624: parm_declarator '(' parmlist_or_identifiers %prec '.'
625: { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
626: /* | parm_declarator '(' error ')' %prec '.'
627: { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
628: poplevel (0, 0, 0); } */
629: | parm_declarator '[' expr ']' %prec '.'
630: { $$ = build_nt (ARRAY_REF, $1, $3); }
631: | parm_declarator '[' ']' %prec '.'
632: { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
633: | '*' type_quals parm_declarator %prec UNARY
634: { $$ = make_pointer_declarator ($2, $3); }
635: | TYPENAME
636: ;
637:
638: /* A declarator allowed whether or not there has been
639: an explicit typespec. These cannot redeclare a typedef-name. */
640:
641: notype_declarator:
642: notype_declarator '(' parmlist_or_identifiers %prec '.'
643: { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
644: /* | notype_declarator '(' error ')' %prec '.'
645: { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
646: poplevel (0, 0, 0); } */
647: | '(' notype_declarator ')'
648: { $$ = $2; }
649: | '*' type_quals notype_declarator %prec UNARY
650: { $$ = make_pointer_declarator ($2, $3); }
651: | notype_declarator '[' expr ']' %prec '.'
652: { $$ = build_nt (ARRAY_REF, $1, $3); }
653: | notype_declarator '[' ']' %prec '.'
654: { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
655: | IDENTIFIER
656: ;
657:
658: structsp:
659: STRUCT identifier '{'
660: { $$ = start_struct (RECORD_TYPE, $2);
661: /* Start scope of tag before parsing components. */
662: }
663: component_decl_list '}'
664: { $$ = finish_struct ($<ttype>4, $5);
665: /* Really define the structure. */
666: }
667: | STRUCT '{' component_decl_list '}'
668: { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
669: $3); }
670: | STRUCT identifier
671: { $$ = xref_tag (RECORD_TYPE, $2); }
672: | UNION identifier '{'
673: { $$ = start_struct (UNION_TYPE, $2); }
674: component_decl_list '}'
675: { $$ = finish_struct ($<ttype>4, $5); }
676: | UNION '{' component_decl_list '}'
677: { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
678: $3); }
679: | UNION identifier
680: { $$ = xref_tag (UNION_TYPE, $2); }
681: | ENUM identifier '{'
682: { $<itype>3 = suspend_momentary ();
683: $$ = start_enum ($2); }
684: enumlist maybecomma '}'
685: { $$ = finish_enum ($<ttype>4, nreverse ($5));
686: resume_momentary ($<itype>3); }
687: | ENUM '{'
688: { $<itype>2 = suspend_momentary ();
689: $$ = start_enum (NULL_TREE); }
690: enumlist maybecomma '}'
691: { $$ = finish_enum ($<ttype>3, nreverse ($4));
692: resume_momentary ($<itype>2); }
693: | ENUM identifier
694: { $$ = xref_tag (ENUMERAL_TYPE, $2); }
695: ;
696:
697: maybecomma:
698: /* empty */
699: | ','
700: ;
701:
702: component_decl_list: /* empty */
703: { $$ = NULL_TREE; }
704: | component_decl_list component_decl ';'
705: { $$ = chainon ($1, $2); }
706: | component_decl_list ';'
707: { if (pedantic)
708: warning ("extra semicolon in struct or union specified"); }
709: ;
710:
711: /* There is a shift-reduce conflict here, because `components' may
712: start with a `typename'. It happens that shifting (the default resolution)
713: does the right thing, because it treats the `typename' as part of
714: a `typed_typespecs'.
715:
716: It is possible that this same technique would allow the distinction
717: between `notype_initdecls' and `initdecls' to be eliminated.
718: But I am being cautious and not trying it. */
719:
720: component_decl:
721: typed_typespecs setspecs components
722: { $$ = $3;
723: resume_momentary ($2); }
724: | nonempty_type_quals setspecs components
725: { $$ = $3;
726: resume_momentary ($2); }
727: | error
728: { $$ = NULL_TREE; }
729: ;
730:
731: components:
732: /* empty */
733: { $$ = NULL_TREE; }
734: | component_declarator
735: | components ',' component_declarator
736: { $$ = chainon ($1, $3); }
737: ;
738:
739: component_declarator:
740: declarator
741: { $$ = grokfield (input_filename, lineno, $1, current_declspecs, NULL_TREE); }
742: | declarator ':' expr_no_commas
743: { $$ = grokfield (input_filename, lineno, $1, current_declspecs, $3); }
744: | ':' expr_no_commas
745: { $$ = grokfield (input_filename, lineno, NULL_TREE, current_declspecs, $2); }
746: ;
747:
748: /* We chain the enumerators in reverse order.
749: They are put in forward order where enumlist is used.
750: (The order used to be significant, but no longer is so.
751: However, we still maintain the order, just to be clean.) */
752:
753: enumlist:
754: enumerator
755: | enumlist ',' enumerator
756: { $$ = chainon ($3, $1); }
757: ;
758:
759:
760: enumerator:
761: identifier
762: { $$ = build_enumerator ($1, NULL_TREE); }
763: | identifier '=' expr_no_commas
764: { $$ = build_enumerator ($1, $3); }
765: ;
766:
767: typename:
768: typed_typespecs absdcl
769: { $$ = build_tree_list ($1, $2); }
770: | nonempty_type_quals absdcl
771: { $$ = build_tree_list ($1, $2); }
772: ;
773:
774: absdcl: /* an absolute declarator */
775: /* empty */
776: { $$ = NULL_TREE; }
777: | absdcl1
778: ;
779:
780: nonempty_type_quals:
781: TYPE_QUAL
782: { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
783: | nonempty_type_quals TYPE_QUAL
784: { $$ = tree_cons (NULL_TREE, $2, $1); }
785: ;
786:
787: type_quals:
788: /* empty */
789: { $$ = NULL_TREE; }
790: | type_quals TYPE_QUAL
791: { $$ = tree_cons (NULL_TREE, $2, $1); }
792: ;
793:
794: absdcl1: /* a nonempty absolute declarator */
795: '(' absdcl1 ')'
796: { $$ = $2; }
797: /* `(typedef)1' is `int'. */
798: | '*' type_quals absdcl1 %prec UNARY
799: { $$ = make_pointer_declarator ($2, $3); }
800: | '*' type_quals %prec UNARY
801: { $$ = make_pointer_declarator ($2, NULL_TREE); }
802: | absdcl1 '(' parmlist %prec '.'
803: { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
804: | absdcl1 '[' expr ']' %prec '.'
805: { $$ = build_nt (ARRAY_REF, $1, $3); }
806: | absdcl1 '[' ']' %prec '.'
807: { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
808: | '(' parmlist %prec '.'
809: { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
810: | '[' expr ']' %prec '.'
811: { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
812: | '[' ']' %prec '.'
813: { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
814: ;
815:
816: /* at least one statement, the first of which parses without error. */
817: /* stmts is used only after decls, so an invalid first statement
818: is actually regarded as an invalid decl and part of the decls. */
819:
820: stmts:
821: stmt
822: | stmts stmt
823: | stmts errstmt
824: ;
825:
826: xstmts:
827: /* empty */
828: | stmts
829: ;
830:
831: errstmt: error ';'
832: ;
833:
834: pushlevel: /* empty */
835: { pushlevel (0);
836: clear_last_expr ();
837: push_momentary ();
838: expand_start_bindings (0); }
839: ;
840:
841: /* This is the body of a function definition.
842: It causes syntax errors to ignore to the next openbrace. */
843: compstmt_or_error:
844: compstmt
845: | error compstmt
846: ;
847:
848: compstmt: '{' '}'
849: | '{' pushlevel decls xstmts '}'
1.1.1.2 root 850: { expand_end_bindings (getdecls (), 1, 0);
1.1 root 851: poplevel (1, 1, 0);
852: pop_momentary (); }
853: | '{' pushlevel error '}'
1.1.1.2 root 854: { expand_end_bindings (getdecls (), 0, 0);
1.1 root 855: poplevel (0, 0, 0);
856: pop_momentary (); }
857: | '{' pushlevel stmts '}'
1.1.1.2 root 858: { expand_end_bindings (getdecls (), 0, 0);
1.1 root 859: poplevel (0, 0, 0);
860: pop_momentary (); }
861: ;
862:
863: simple_if:
864: IF '(' expr ')'
865: { emit_note (input_filename, lineno);
866: expand_start_cond (truthvalue_conversion ($3), 0); }
867: stmt
868: ;
869:
870: stmt:
871: compstmt
872: | expr ';'
873: { emit_note (input_filename, lineno);
874: expand_expr_stmt ($1);
875: clear_momentary (); }
876: | simple_if ELSE
877: { expand_start_else (); }
878: stmt
879: { expand_end_else (); }
880: | simple_if
881: { expand_end_cond (); }
882: | WHILE
883: { emit_note (input_filename, lineno);
884: expand_start_loop (1); }
885: '(' expr ')'
886: { emit_note (input_filename, lineno);
887: expand_exit_loop_if_false (truthvalue_conversion ($4)); }
888: stmt
889: { expand_end_loop (); }
890: | DO
891: { emit_note (input_filename, lineno);
892: expand_start_loop_continue_elsewhere (1); }
893: stmt WHILE
894: { expand_loop_continue_here (); }
895: '(' expr ')' ';'
896: { emit_note (input_filename, lineno);
897: expand_exit_loop_if_false (truthvalue_conversion ($7));
898: expand_end_loop ();
899: clear_momentary (); }
900: | FOR
901: '(' xexpr ';'
902: { emit_note (input_filename, lineno);
903: if ($3) expand_expr_stmt ($3);
904: expand_start_loop_continue_elsewhere (1); }
905: xexpr ';'
906: { emit_note (input_filename, lineno);
907: if ($6)
908: expand_exit_loop_if_false (truthvalue_conversion ($6)); }
909: xexpr ')'
910: /* Don't let the tree nodes for $9 be discarded
911: by clear_momentary during the parsing of the next stmt. */
912: { push_momentary ();
913: $<itype>10 = lineno; }
914: stmt
915: { emit_note (input_filename, $<itype>10);
916: expand_loop_continue_here ();
917: if ($9)
918: expand_expr_stmt ($9);
919: pop_momentary ();
920: expand_end_loop (); }
921: | SWITCH '(' expr ')'
922: { emit_note (input_filename, lineno);
923: c_expand_start_case ($3);
924: /* Don't let the tree nodes for $3 be discarded by
925: clear_momentary during the parsing of the next stmt. */
926: push_momentary (); }
927: stmt
928: { expand_end_case ();
929: pop_momentary (); }
930: | CASE expr ':'
931: { register tree value = fold ($2);
932: register tree label
933: = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
934:
935: if (TREE_CODE (value) != INTEGER_CST
936: && value != error_mark_node)
937: {
938: error ("case label does not reduce to an integer constant");
939: value = error_mark_node;
940: }
941: else
942: /* Promote char or short to int. */
943: value = default_conversion (value);
944: if (value != error_mark_node)
945: {
946: int success = pushcase (value, label);
947: if (success == 1)
948: error ("case label not within a switch statement");
949: else if (success == 2)
950: error ("duplicate case value");
951: else if (success == 3)
952: warning ("case value out of range");
953: }
954: }
955: stmt
956: | DEFAULT ':'
957: {
958: register tree label
959: = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
960: int success = pushcase (NULL_TREE, label);
961: if (success == 1)
962: error ("default label not within a switch statement");
963: else if (success == 2)
964: error ("multiple default labels in one switch");
965: }
966: stmt
967: | BREAK ';'
968: { emit_note (input_filename, lineno);
969: if ( ! expand_exit_something ())
970: error ("break statement not within loop or switch"); }
971: | CONTINUE ';'
972: { emit_note (input_filename, lineno);
973: if (! expand_continue_loop ())
974: error ("continue statement not within a loop"); }
975: | RETURN ';'
976: { emit_note (input_filename, lineno);
977: c_expand_return (NULL_TREE); }
978: | RETURN expr ';'
979: { emit_note (input_filename, lineno);
980: c_expand_return ($2); }
981: | ASM maybe_type_qual '(' string ')' ';'
982: { if (pedantic)
983: warning ("ANSI C forbids use of `asm' keyword");
984: if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
985: expand_asm ($4); }
986: /* This is the case with just output operands. */
987: | ASM maybe_type_qual '(' string ':' asm_operands ')' ';'
988: { if (pedantic)
989: warning ("ANSI C forbids use of `asm' keyword");
990: if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
1.1.1.3 ! root 991: c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
1.1 root 992: $2 == ridpointers[(int)RID_VOLATILE]); }
993: /* This is the case with input operands as well. */
994: | ASM maybe_type_qual '(' string ':' asm_operands ':' asm_operands ')' ';'
995: { if (pedantic)
996: warning ("ANSI C forbids use of `asm' keyword");
997: if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
1.1.1.3 ! root 998: c_expand_asm_operands ($4, $6, $8, NULL_TREE,
! 999: $2 == ridpointers[(int)RID_VOLATILE]); }
! 1000: /* This is the case with clobbered registers as well. */
! 1001: | ASM maybe_type_qual '(' string ':' asm_operands ':'
! 1002: asm_operands ':' asm_clobbers ')' ';'
! 1003: { if (pedantic)
! 1004: warning ("ANSI C forbids use of `asm' keyword");
! 1005: if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
! 1006: c_expand_asm_operands ($4, $6, $8, $10,
1.1 root 1007: $2 == ridpointers[(int)RID_VOLATILE]); }
1008: | GOTO identifier ';'
1009: { tree decl;
1010: emit_note (input_filename, lineno);
1011: decl = lookup_label ($2);
1012: expand_goto (decl); }
1013: | identifier ':'
1014: { tree label = define_label (input_filename, lineno, $1);
1015: if (label)
1016: expand_label (label); }
1017: stmt
1018: | ';'
1019: ;
1020:
1021: maybe_type_qual:
1022: /* empty */
1023: { emit_note (input_filename, lineno); }
1024: | TYPE_QUAL
1025: { emit_note (input_filename, lineno); }
1026: ;
1027:
1028: xexpr:
1029: /* empty */
1030: { $$ = NULL_TREE; }
1031: | expr
1032: ;
1033:
1034: /* These are the operands other than the first string and colon
1035: in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
1036: asm_operands: /* empty */
1037: { $$ = NULL_TREE; }
1038: | nonnull_asm_operands
1039: ;
1040:
1041: nonnull_asm_operands:
1042: asm_operand
1043: | nonnull_asm_operands ',' asm_operand
1044: { $$ = chainon ($1, $3); }
1045: ;
1046:
1047: asm_operand:
1.1.1.3 ! root 1048: STRING '(' expr ')'
1.1 root 1049: { $$ = build_tree_list ($1, $3); }
1050: ;
1051:
1.1.1.3 ! root 1052: asm_clobbers:
! 1053: STRING
! 1054: { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
! 1055: | asm_clobbers ',' STRING
! 1056: { $$ = tree_cons (NULL_TREE, $3, $1); }
! 1057: ;
! 1058:
1.1 root 1059: /* This is what appears inside the parens in a function declarator.
1060: Its value is a list of ..._TYPE nodes. */
1061: parmlist:
1062: { pushlevel (0); }
1063: parmlist_1
1064: { $$ = $2; poplevel (0, 0, 0); }
1065: ;
1066:
1067: /* This is referred to where either a parmlist or an identifier list is ok.
1068: Its value is a list of ..._TYPE nodes or a list of identifiers. */
1069: parmlist_or_identifiers:
1070: { pushlevel (0); }
1071: parmlist_or_identifiers_1
1072: { $$ = $2; poplevel (0, 0, 0); }
1073: ;
1074:
1075: parmlist_or_identifiers_1:
1076: parmlist_2 ')'
1077: | identifiers ')'
1078: { $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
1079: | error ')'
1080: { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
1081: ;
1082:
1083: parmlist_1:
1084: parmlist_2 ')'
1085: | error ')'
1086: { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
1087: ;
1088:
1089: /* This is what appears inside the parens in a function declarator.
1090: Is value is represented in the format that grokdeclarator expects. */
1091: parmlist_2: /* empty */
1092: { $$ = get_parm_info (0); }
1093: | parms
1094: { $$ = get_parm_info (1); }
1095: | parms ',' ELLIPSIS
1096: { $$ = get_parm_info (0); }
1097: ;
1098:
1099: parms:
1100: parm
1101: { push_parm_decl ($1); }
1102: | parms ',' parm
1103: { push_parm_decl ($3); }
1104: ;
1105:
1106: /* A single parameter declaration or parameter type name,
1107: as found in a parmlist. */
1108: parm:
1109: typed_declspecs parm_declarator
1110: { $$ = build_tree_list ($1, $2) ; }
1111: | typed_declspecs notype_declarator
1112: { $$ = build_tree_list ($1, $2) ; }
1113: | typed_declspecs absdcl
1114: { $$ = build_tree_list ($1, $2); }
1115: | declmods notype_declarator
1116: { $$ = build_tree_list ($1, $2) ; }
1117: | declmods absdcl
1118: { $$ = build_tree_list ($1, $2); }
1119: ;
1120:
1121: /* A nonempty list of identifiers. */
1122: identifiers:
1123: IDENTIFIER
1124: { $$ = build_tree_list (NULL_TREE, $1); }
1125: | identifiers ',' IDENTIFIER
1126: { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
1127: ;
1128: %%
1129:
1130: /* Return something to represent absolute declarators containing a *.
1131: TARGET is the absolute declarator that the * contains.
1132: TYPE_QUALS is a list of modifiers such as const or volatile
1133: to apply to the pointer type, represented as identifiers.
1134:
1135: We return an INDIRECT_REF whose "contents" are TARGET
1136: and whose type is the modifier list. */
1137:
1138: static tree
1139: make_pointer_declarator (type_quals, target)
1140: tree type_quals, target;
1141: {
1142: return build (INDIRECT_REF, type_quals, target);
1143: }
1144:
1145: /* Given a chain of STRING_CST nodes,
1146: concatenate them into one STRING_CST
1147: and give it a suitable array-of-chars data type. */
1148:
1149: static tree
1150: combine_strings (strings)
1151: tree strings;
1152: {
1153: register tree value, t;
1154: register int length = 1;
1155: int wide_length = 0;
1156: int wide_flag = 0;
1157:
1158: if (TREE_CHAIN (strings))
1159: {
1160: /* More than one in the chain, so concatenate. */
1161: register char *p, *q;
1162:
1163: /* Don't include the \0 at the end of each substring,
1164: except for the last one.
1165: Count wide strings and ordinary strings separately. */
1166: for (t = strings; t; t = TREE_CHAIN (t))
1167: {
1168: if (TREE_TYPE (t) == int_array_type_node)
1169: {
1170: wide_length += (TREE_STRING_LENGTH (t) - 1);
1171: wide_flag = 1;
1172: }
1173: else
1174: length += (TREE_STRING_LENGTH (t) - 1);
1175: }
1176:
1177: /* If anything is wide, the non-wides will be converted,
1178: which makes them take more space. */
1179: if (wide_flag)
1180: length = length * UNITS_PER_WORD + wide_length;
1181:
1182: p = (char *) oballoc (length);
1183:
1184: /* Copy the individual strings into the new combined string.
1185: If the combined string is wide, convert the chars to ints
1186: for any individual strings that are not wide. */
1187:
1188: q = p;
1189: for (t = strings; t; t = TREE_CHAIN (t))
1190: {
1191: int len = TREE_STRING_LENGTH (t) - 1;
1192: if ((TREE_TYPE (t) == int_array_type_node) == wide_flag)
1193: {
1194: bcopy (TREE_STRING_POINTER (t), q, len);
1195: q += len;
1196: }
1197: else
1198: {
1199: int i;
1200: for (i = 0; i < len; i++)
1201: ((int *) q)[i] = TREE_STRING_POINTER (t)[i];
1202: q += len * UNITS_PER_WORD;
1203: }
1204: }
1205: *q = 0;
1206:
1207: value = make_node (STRING_CST);
1208: TREE_STRING_POINTER (value) = p;
1209: TREE_STRING_LENGTH (value) = length;
1210: TREE_LITERAL (value) = 1;
1211: }
1212: else
1213: {
1214: value = strings;
1215: length = TREE_STRING_LENGTH (value);
1216: if (TREE_TYPE (value) == int_array_type_node)
1217: wide_flag = 1;
1218: }
1219:
1.1.1.3 ! root 1220: /* Create the array type for the string constant.
! 1221: -Wwrite-strings says make the string constant an array of const char
! 1222: so that copying it to a non-const pointer will get a warning. */
! 1223: if (warn_write_strings)
! 1224: {
! 1225: tree elements
! 1226: = build_type_variant (wide_flag ? integer_type_node : char_type_node,
! 1227: 1, 0);
! 1228: TREE_TYPE (value)
! 1229: = build_array_type (elements,
! 1230: build_index_type (build_int_2 (length - 1, 0)));
! 1231: }
! 1232: else
! 1233: TREE_TYPE (value)
! 1234: = build_array_type (wide_flag ? integer_type_node : char_type_node,
! 1235: build_index_type (build_int_2 (length - 1, 0)));
1.1 root 1236: TREE_LITERAL (value) = 1;
1237: TREE_STATIC (value) = 1;
1238: return value;
1239: }
1240:
1241: int lineno; /* current line number in file being read */
1242:
1243: FILE *finput; /* input file.
1244: Normally a pipe from the preprocessor. */
1245:
1246: /* lexical analyzer */
1247:
1248: static int maxtoken; /* Current nominal length of token buffer */
1249: static char *token_buffer; /* Pointer to token buffer.
1250: Actual allocated length is maxtoken + 2. */
1251:
1252: #define MAXRESERVED 9
1253:
1254: /* frw[I] is index in `reswords' of the first word whose length is I;
1255: frw[I+1] is one plus the index of the last word whose length is I.
1256: The length of frw must be MAXRESERVED + 2 so there is an element
1257: at MAXRESERVED+1 for the case I == MAXRESERVED. */
1258:
1259: static char frw[MAXRESERVED+2] =
1260: { 0, 0, 0, 2, 5, 13, 19, 29, 31, 35, 36 };
1261:
1262: /* Table of reserved words. */
1263:
1264: struct resword { char *name; short token; enum rid rid;};
1265:
1266: #define NORID RID_UNUSED
1267:
1268: static struct resword reswords[]
1269: = {{"if", IF, NORID},
1270: {"do", DO, NORID},
1271: {"int", TYPESPEC, RID_INT},
1272: {"for", FOR, NORID},
1273: {"asm", ASM, NORID},
1274: {"case", CASE, NORID},
1275: {"char", TYPESPEC, RID_CHAR},
1276: {"auto", SCSPEC, RID_AUTO},
1277: {"goto", GOTO, NORID},
1278: {"else", ELSE, NORID},
1279: {"long", TYPESPEC, RID_LONG},
1280: {"void", TYPESPEC, RID_VOID},
1281: {"enum", ENUM, NORID},
1282: {"float", TYPESPEC, RID_FLOAT},
1283: {"short", TYPESPEC, RID_SHORT},
1284: {"union", UNION, NORID},
1285: {"break", BREAK, NORID},
1286: {"while", WHILE, NORID},
1287: {"const", TYPE_QUAL, RID_CONST},
1288: {"double", TYPESPEC, RID_DOUBLE},
1289: {"static", SCSPEC, RID_STATIC},
1290: {"extern", SCSPEC, RID_EXTERN},
1291: {"struct", STRUCT, NORID},
1292: {"return", RETURN, NORID},
1293: {"sizeof", SIZEOF, NORID},
1294: {"typeof", TYPEOF, NORID},
1295: {"switch", SWITCH, NORID},
1296: {"signed", TYPESPEC, RID_SIGNED},
1297: {"inline", SCSPEC, RID_INLINE},
1298: {"typedef", SCSPEC, RID_TYPEDEF},
1299: {"default", DEFAULT, NORID},
1300: {"unsigned", TYPESPEC, RID_UNSIGNED},
1301: {"continue", CONTINUE, NORID},
1302: {"register", SCSPEC, RID_REGISTER},
1303: {"volatile", TYPE_QUAL, RID_VOLATILE},
1304: {"__alignof", ALIGNOF, NORID}};
1305:
1306: /* The elements of `ridpointers' are identifier nodes
1307: for the reserved type names and storage classes.
1308: It is indexed by a RID_... value. */
1309:
1310: tree ridpointers[(int) RID_MAX];
1311:
1312: int check_newline ();
1313:
1314: void
1315: init_lex ()
1316: {
1317: extern char *malloc ();
1318:
1319: /* Start it at 0, because check_newline is called at the very beginning
1320: and will increment it to 1. */
1321: lineno = 0;
1322:
1323: maxtoken = 40;
1324: token_buffer = malloc (maxtoken + 2);
1325: ridpointers[(int) RID_INT] = get_identifier ("int");
1326: ridpointers[(int) RID_CHAR] = get_identifier ("char");
1327: ridpointers[(int) RID_VOID] = get_identifier ("void");
1328: ridpointers[(int) RID_FLOAT] = get_identifier ("float");
1329: ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
1330: ridpointers[(int) RID_SHORT] = get_identifier ("short");
1331: ridpointers[(int) RID_LONG] = get_identifier ("long");
1332: ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
1333: ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
1334: ridpointers[(int) RID_INLINE] = get_identifier ("inline");
1335: ridpointers[(int) RID_CONST] = get_identifier ("const");
1336: ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
1337: ridpointers[(int) RID_AUTO] = get_identifier ("auto");
1338: ridpointers[(int) RID_STATIC] = get_identifier ("static");
1339: ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
1340: ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
1341: ridpointers[(int) RID_REGISTER] = get_identifier ("register");
1342: }
1343:
1344: static void
1345: reinit_parse_for_function ()
1346: {
1347: }
1348:
1349: /* If C is not whitespace, return C.
1350: Otherwise skip whitespace and return first nonwhite char read. */
1351:
1352: static int
1353: skip_white_space (c)
1354: register int c;
1355: {
1356: register int inside;
1357:
1358: for (;;)
1359: {
1360: switch (c)
1361: {
1362: case '/':
1363: c = getc (finput);
1364: if (c != '*')
1365: {
1366: ungetc (c, finput);
1367: return '/';
1368: }
1369:
1370: c = getc (finput);
1371:
1372: inside = 1;
1373: while (inside)
1374: {
1375: if (c == '*')
1376: {
1377: while (c == '*')
1378: c = getc (finput);
1379:
1380: if (c == '/')
1381: {
1382: inside = 0;
1383: c = getc (finput);
1384: }
1385: }
1386: else if (c == '\n')
1387: {
1388: lineno++;
1389: c = getc (finput);
1390: }
1391: else if (c == EOF)
1392: {
1393: error ("unterminated comment");
1394: break;
1395: }
1396: else
1397: c = getc (finput);
1398: }
1399:
1400: break;
1401:
1402: case '\n':
1403: c = check_newline ();
1404: break;
1405:
1406: case ' ':
1407: case '\t':
1408: case '\f':
1409: case '\r':
1410: case '\b':
1411: c = getc (finput);
1412: break;
1413:
1414: case '\\':
1415: c = getc (finput);
1416: if (c == '\n')
1417: lineno++;
1418: else
1419: error ("stray '\\' in program");
1420: c = getc (finput);
1421: break;
1422:
1423: default:
1424: return (c);
1425: }
1426: }
1427: }
1428:
1429:
1430:
1431: /* Make the token buffer longer, preserving the data in it.
1432: P should point to just beyond the last valid character in the old buffer.
1433: The value we return is a pointer to the new buffer
1434: at a place corresponding to P. */
1435:
1436: static char *
1437: extend_token_buffer (p)
1438: char *p;
1439: {
1440: int offset = p - token_buffer;
1441:
1442: maxtoken = maxtoken * 2 + 10;
1443: token_buffer = (char *) realloc (token_buffer, maxtoken + 2);
1444: if (token_buffer == 0)
1445: fatal ("virtual memory exceeded");
1446:
1447: return token_buffer + offset;
1448: }
1449:
1450: /* At the beginning of a line, increment the line number
1451: and handle a #line directive immediately following.
1452: Return first nonwhite char of first non-# line following. */
1453:
1454: int
1455: check_newline ()
1456: {
1457: register int c;
1458: register int token;
1459:
1460: while (1)
1461: {
1462: lineno++;
1463:
1464: /* Read first nonwhite char on the line. */
1465:
1466: c = getc (finput);
1467: while (c == ' ' || c == '\t')
1468: c = getc (finput);
1469:
1470: if (c != '#')
1471: {
1472: /* If not #, return it so caller will use it. */
1473: return c;
1474: }
1475:
1476: /* Read first nonwhite char after the `#'. */
1477:
1478: c = getc (finput);
1479: while (c == ' ' || c == '\t')
1480: c = getc (finput);
1481:
1482: /* If a letter follows, then if the word here is `line', skip
1483: it and ignore it; otherwise, ignore the line, with an error
1484: if the word isn't `pragma'. */
1485:
1486: if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
1487: {
1488: if (c == 'p')
1489: {
1490: if (getc (finput) == 'r'
1491: && getc (finput) == 'a'
1492: && getc (finput) == 'g'
1493: && getc (finput) == 'm'
1494: && getc (finput) == 'a'
1495: && ((c = getc (finput)) == ' ' || c == '\t'))
1496: goto noerror;
1497: }
1498:
1499: else if (c == 'l')
1500: {
1501: if (getc (finput) == 'i'
1502: && getc (finput) == 'n'
1503: && getc (finput) == 'e'
1504: && ((c = getc (finput)) == ' ' || c == '\t'))
1505: goto linenum;
1506: }
1507: #ifdef IDENT_DIRECTIVE
1508: else if (c == 'i')
1509: {
1510: if (getc (finput) == 'd'
1511: && getc (finput) == 'e'
1512: && getc (finput) == 'n'
1513: && getc (finput) == 't'
1514: && ((c = getc (finput)) == ' ' || c == '\t'))
1515: {
1516: extern FILE *asm_out_file;
1517:
1518: if (pedantic)
1519: error ("ANSI C does not allow #ident");
1520:
1521: /* Here we have just seen `#ident '.
1522: A string constant should follow. */
1523:
1524: while (c == ' ' || c == '\t')
1525: c = getc (finput);
1526:
1527: /* If no argument, ignore the line. */
1528: if (c == '\n')
1529: continue;
1530:
1531: ungetc (c, finput);
1532: token = yylex ();
1533: if (token != STRING
1534: || TREE_CODE (yylval.ttype) != STRING_CST)
1535: {
1536: error ("invalid #ident");
1537: return getc (finput);
1538: }
1539:
1540: fprintf (asm_out_file, "\t.ident \"%s\"\n",
1541: TREE_STRING_POINTER (yylval.ttype));
1542:
1543: /* Skip the rest of this line. */
1544: while ((c = getc (finput)) && c != '\n');
1545: if (c == 0)
1546: return 0;
1547: continue;
1548: }
1549: }
1550: #endif
1551:
1552: error ("undefined or invalid # directive");
1553: noerror:
1554:
1555: while ((c = getc (finput)) && c != '\n');
1556:
1557: if (c == 0)
1558: return 0;
1559: continue;
1560: }
1561:
1562: linenum:
1563: /* Here we have either `#line' or `# <nonletter>'.
1564: In either case, it should be a line number; a digit should follow. */
1565:
1566: while (c == ' ' || c == '\t')
1567: c = getc (finput);
1568:
1569: /* If the # is the only nonwhite char on the line,
1570: just ignore it. Check the new newline. */
1571: if (c == '\n')
1572: continue;
1573:
1574: /* Something follows the #; read a token. */
1575:
1576: ungetc (c, finput);
1577: token = yylex ();
1578:
1579: if (token == CONSTANT
1580: && TREE_CODE (yylval.ttype) == INTEGER_CST)
1581: {
1582: /* subtract one, because it is the following line that
1583: gets the specified number */
1584:
1585: int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
1586:
1587: /* Is this the last nonwhite stuff on the line? */
1588: c = getc (finput);
1589: while (c == ' ' || c == '\t')
1590: c = getc (finput);
1591: if (c == '\n')
1592: {
1593: /* No more: store the line number and check following line. */
1594: lineno = l;
1595: continue;
1596: }
1597: ungetc (c, finput);
1598:
1599: /* More follows: it must be a string constant (filename). */
1600:
1601: token = yylex ();
1602: if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
1603: {
1604: error ("invalid #line");
1605: return getc (finput);
1606: }
1607:
1608: input_filename
1609: = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
1610: strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
1611: lineno = l;
1612:
1613: if (main_input_filename == 0)
1614: main_input_filename = input_filename;
1615: }
1616: else
1617: error ("invalid #line");
1618:
1619: /* skip the rest of this line. */
1620: while ((c = getc (finput)) && c != '\n');
1621: if (c == 0)
1622: return 0;
1623: }
1624: }
1625:
1626: #define isalnum(char) ((char >= 'a' && char <= 'z') || (char >= 'A' && char <= 'Z') || (char >= '0' && char <= '9'))
1627: #define isdigit(char) (char >= '0' && char <= '9')
1628: #define ENDFILE -1 /* token that represents end-of-file */
1629:
1630:
1631: static int
1632: readescape ()
1633: {
1634: register int c = getc (finput);
1635: register int count, code;
1636:
1637: switch (c)
1638: {
1639: case 'x':
1640: code = 0;
1641: count = 0;
1642: while (1)
1643: {
1644: c = getc (finput);
1645: if (!(c >= 'a' && c <= 'f')
1646: && !(c >= 'A' && c <= 'F')
1647: && !(c >= '0' && c <= '9'))
1648: {
1649: ungetc (c, finput);
1650: break;
1651: }
1652: code *= 16;
1653: if (c >= 'a' && c <= 'f')
1654: code += c - 'a' + 10;
1655: if (c >= 'A' && c <= 'F')
1656: code += c - 'A' + 10;
1657: if (c >= '0' && c <= '9')
1658: code += c - '0';
1659: count++;
1660: }
1661: if (count == 0)
1662: error ("\\x used with no following hex digits");
1663: return code;
1664:
1665: case '0': case '1': case '2': case '3': case '4':
1666: case '5': case '6': case '7':
1667: code = 0;
1668: count = 0;
1669: while ((c <= '7') && (c >= '0') && (count++ < 3))
1670: {
1671: code = (code * 8) + (c - '0');
1672: c = getc (finput);
1673: }
1674: ungetc (c, finput);
1675: return code;
1676:
1677: case '\\': case '\'': case '"':
1678: return c;
1679:
1680: case '\n':
1681: lineno++;
1682: return -1;
1683:
1684: case 'n':
1685: return TARGET_NEWLINE;
1686:
1687: case 't':
1688: return TARGET_TAB;
1689:
1690: case 'r':
1691: return TARGET_CR;
1692:
1693: case 'f':
1694: return TARGET_FF;
1695:
1696: case 'b':
1697: return TARGET_BS;
1698:
1699: case 'a':
1700: return TARGET_BELL;
1701:
1702: case 'v':
1703: return TARGET_VT;
1704:
1705: case 'E':
1706: return 033;
1707:
1708: case '?':
1.1.1.3 ! root 1709: /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
1.1.1.2 root 1710: case '(':
1.1.1.3 ! root 1711: case '{':
! 1712: case '[':
1.1 root 1713: return c;
1714: }
1715: if (c >= 040 && c <= 0177)
1716: warning ("unknown escape sequence `\\%c'", c);
1717: else
1718: warning ("unknown escape sequence: `\\' followed by char code 0x%x", c);
1719: return c;
1720: }
1721:
1722: void
1723: yyerror (string)
1724: char *string;
1725: {
1726: char buf[200];
1727:
1728: strcpy (buf, string);
1729:
1730: /* We can't print string and character constants well
1731: because the token_buffer contains the result of processing escapes. */
1732: if (token_buffer[0] == 0)
1733: strcat (buf, " at end of input");
1734: else if (token_buffer[0] == '"')
1735: strcat (buf, " before string constant");
1736: else if (token_buffer[0] == '\'')
1737: strcat (buf, " before character constant");
1738: else
1739: strcat (buf, " before `%s'");
1740:
1741: error (buf, token_buffer);
1742: }
1743:
1744: static int nextchar = -1;
1745:
1746: static int
1747: yylex ()
1748: {
1749: register int c;
1750: register char *p;
1751: register int value;
1752: int wide_flag = 0;
1753:
1754: if (nextchar >= 0)
1755: c = nextchar, nextchar = -1;
1756: else
1757: c = getc (finput);
1758:
1759: /* Effectively do c = skip_white_space (c)
1760: but do it faster in the usual cases. */
1761: while (1)
1762: switch (c)
1763: {
1764: case ' ':
1765: case '\t':
1766: case '\f':
1767: case '\r':
1768: case '\b':
1769: c = getc (finput);
1770: break;
1771:
1772: case '\n':
1773: case '/':
1774: case '\\':
1775: c = skip_white_space (c);
1776: default:
1777: goto found_nonwhite;
1778: }
1779: found_nonwhite:
1780:
1781: token_buffer[0] = c;
1782: token_buffer[1] = 0;
1783:
1784: /* yylloc.first_line = lineno; */
1785:
1786: switch (c)
1787: {
1788: case EOF:
1789: token_buffer[0] = 0;
1790: value = ENDFILE;
1791: break;
1792:
1793: case '$':
1794: if (dollars_in_ident)
1795: goto letter;
1796: return '$';
1797:
1798: case 'L':
1799: /* Capital L may start a wide-string or wide-character constant. */
1800: {
1801: register int c = getc (finput);
1802: if (c == '\'')
1803: {
1804: wide_flag = 1;
1805: goto char_constant;
1806: }
1807: if (c == '"')
1808: {
1809: wide_flag = 1;
1810: goto string_constant;
1811: }
1812: ungetc (c, finput);
1813: }
1814:
1815: case 'A': case 'B': case 'C': case 'D': case 'E':
1816: case 'F': case 'G': case 'H': case 'I': case 'J':
1817: case 'K': case 'M': case 'N': case 'O':
1818: case 'P': case 'Q': case 'R': case 'S': case 'T':
1819: case 'U': case 'V': case 'W': case 'X': case 'Y':
1820: case 'Z':
1821: case 'a': case 'b': case 'c': case 'd': case 'e':
1822: case 'f': case 'g': case 'h': case 'i': case 'j':
1823: case 'k': case 'l': case 'm': case 'n': case 'o':
1824: case 'p': case 'q': case 'r': case 's': case 't':
1825: case 'u': case 'v': case 'w': case 'x': case 'y':
1826: case 'z':
1827: case '_':
1828: letter:
1829: p = token_buffer;
1830: while (isalnum (c) || c == '_' || c == '$')
1831: {
1832: if (p >= token_buffer + maxtoken)
1833: p = extend_token_buffer (p);
1834: if (c == '$' && ! dollars_in_ident)
1835: break;
1836:
1837: *p++ = c;
1838: c = getc (finput);
1839: }
1840:
1841: *p = 0;
1842: nextchar = c;
1843:
1844: value = IDENTIFIER;
1845: yylval.itype = 0;
1846:
1847: /* Try to recognize a keyword. */
1848:
1849: if (p - token_buffer <= MAXRESERVED)
1850: {
1851: register int lim = frw [p - token_buffer + 1];
1852: register int i = frw[p - token_buffer];
1853: register struct resword *p = &reswords[i];
1854:
1855: for (; i < lim; i++, p++)
1856: if (p->name[0] == token_buffer[0]
1857: && !strcmp (p->name, token_buffer))
1858: {
1859: if (p->rid)
1860: yylval.ttype = ridpointers[(int) p->rid];
1861: if ((! flag_no_asm
1862: || ((int) p->token != ASM
1863: && (int) p->token != TYPEOF
1.1.1.2 root 1864: && p->rid != RID_INLINE))
1.1 root 1865: /* -ftraditional means don't recognize
1866: typeof, const, volatile, signed or inline. */
1867: && (! flag_traditional
1868: || ((int) p->token != TYPE_QUAL
1869: && (int) p->token != TYPEOF
1.1.1.2 root 1870: && p->rid != RID_SIGNED
1871: && p->rid != RID_INLINE)))
1.1 root 1872: value = (int) p->token;
1873: break;
1874: }
1875: }
1876:
1877: /* If we did not find a keyword, look for an identifier
1878: (or a typename). */
1879:
1880: if (value == IDENTIFIER)
1881: {
1882: yylval.ttype = get_identifier (token_buffer);
1883: lastiddecl = lookup_name (yylval.ttype);
1884:
1885: if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1886: value = TYPENAME;
1887: }
1888:
1889: break;
1890:
1891: case '0': case '1': case '2': case '3': case '4':
1892: case '5': case '6': case '7': case '8': case '9':
1893: case '.':
1894: {
1895: int base = 10;
1896: int count = 0;
1897: int largest_digit = 0;
1898: int numdigits = 0;
1899: /* for multi-precision arithmetic,
1900: we store only 8 live bits in each short,
1901: giving us 64 bits of reliable precision */
1902: short shorts[8];
1.1.1.3 ! root 1903:
! 1904: enum { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
! 1905: = NOT_FLOAT;
1.1 root 1906:
1907: for (count = 0; count < 8; count++)
1908: shorts[count] = 0;
1909:
1910: p = token_buffer;
1911: *p++ = c;
1912:
1913: if (c == '0')
1914: {
1915: *p++ = (c = getc (finput));
1916: if ((c == 'x') || (c == 'X'))
1917: {
1918: base = 16;
1919: *p++ = (c = getc (finput));
1920: }
1921: else
1922: {
1923: base = 8;
1924: numdigits++;
1925: }
1926: }
1927:
1928: /* Read all the digits-and-decimal-points. */
1929:
1930: while (c == '.'
1931: || (isalnum (c) && (c != 'l') && (c != 'L')
1932: && (c != 'u') && (c != 'U')
1.1.1.3 ! root 1933: && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
1.1 root 1934: {
1935: if (c == '.')
1936: {
1937: if (base == 16)
1938: error ("floating constant may not be in radix 16");
1.1.1.3 ! root 1939: if (floatflag == AFTER_POINT)
! 1940: {
! 1941: error ("malformed floating constant");
! 1942: floatflag = TOO_MANY_POINTS;
! 1943: }
! 1944: else
! 1945: floatflag = AFTER_POINT;
! 1946:
1.1 root 1947: base = 10;
1948: *p++ = c = getc (finput);
1949: /* Accept '.' as the start of a floating-point number
1950: only when it is followed by a digit.
1951: Otherwise, unread the following non-digit
1952: and use the '.' as a structural token. */
1953: if (p == token_buffer + 2 && !isdigit (c))
1954: {
1955: if (c == '.')
1956: {
1957: c = getc (finput);
1958: if (c == '.')
1959: {
1960: *p++ = c;
1961: *p = 0;
1962: return ELLIPSIS;
1963: }
1964: error ("parse error at `..'");
1965: }
1966: ungetc (c, finput);
1967: token_buffer[1] = 0;
1968: value = '.';
1969: goto done;
1970: }
1971: }
1972: else
1973: {
1974: /* It is not a decimal point.
1975: It should be a digit (perhaps a hex digit). */
1976:
1977: if (isdigit (c))
1978: {
1979: c = c - '0';
1980: }
1981: else if (base <= 10)
1982: {
1983: if ((c&~040) == 'E')
1984: {
1985: base = 10;
1.1.1.3 ! root 1986: floatflag = AFTER_POINT;
1.1 root 1987: break; /* start of exponent */
1988: }
1989: error ("nondigits in number and not hexadecimal");
1990: c = 0;
1991: }
1992: else if (c >= 'a')
1993: {
1994: c = c - 'a' + 10;
1995: }
1996: else
1997: {
1998: c = c - 'A' + 10;
1999: }
2000: if (c >= largest_digit)
2001: largest_digit = c;
2002: numdigits++;
2003:
2004: for (count = 0; count < 8; count++)
2005: {
2006: (shorts[count] *= base);
2007: if (count)
2008: {
2009: shorts[count] += (shorts[count-1] >> 8);
2010: shorts[count-1] &= (1<<8)-1;
2011: }
2012: else shorts[0] += c;
2013: }
2014:
2015: if (p >= token_buffer + maxtoken - 3)
2016: p = extend_token_buffer (p);
2017: *p++ = (c = getc (finput));
2018: }
2019: }
2020:
2021: if (numdigits == 0)
2022: error ("numeric constant with no digits");
2023:
2024: if (largest_digit >= base)
2025: error ("numeric constant contains digits beyond the radix");
2026:
2027: /* Remove terminating char from the token buffer and delimit the string */
2028: *--p = 0;
2029:
1.1.1.3 ! root 2030: if (floatflag != NOT_FLOAT)
1.1 root 2031: {
2032: tree type = double_type_node;
2033: char f_seen = 0;
2034: char l_seen = 0;
2035: double value;
2036:
2037: /* Read explicit exponent if any, and put it in tokenbuf. */
2038:
2039: if ((c == 'e') || (c == 'E'))
2040: {
2041: if (p >= token_buffer + maxtoken - 3)
2042: p = extend_token_buffer (p);
2043: *p++ = c;
2044: c = getc (finput);
2045: if ((c == '+') || (c == '-'))
2046: {
2047: *p++ = c;
2048: c = getc (finput);
2049: }
2050: if (! isdigit (c))
2051: error ("floating constant exponent has no digits");
2052: while (isdigit (c))
2053: {
2054: if (p >= token_buffer + maxtoken - 3)
2055: p = extend_token_buffer (p);
2056: *p++ = c;
2057: c = getc (finput);
2058: }
2059: }
2060:
2061: *p = 0;
2062: errno = 0;
2063: value = atof (token_buffer);
2064: #ifdef ERANGE
2065: if (errno == ERANGE && !flag_traditional)
1.1.1.2 root 2066: warning ("floating point number exceeds range of `double'");
1.1 root 2067: #endif
2068:
2069: /* Read the suffixes to choose a data type. */
2070: while (1)
2071: {
2072: if (c == 'f' || c == 'F')
2073: {
2074: if (f_seen)
2075: error ("two `f's in floating constant");
2076: f_seen = 1;
2077: type = float_type_node;
2078: }
2079: else if (c == 'l' || c == 'L')
2080: {
2081: if (l_seen)
2082: error ("two `l's in floating constant");
2083: l_seen = 1;
2084: type = long_double_type_node;
2085: }
2086: else
2087: {
2088: if (isalnum (c))
2089: {
2090: error ("garbage at end of number");
2091: while (isalnum (c))
2092: {
2093: if (p >= token_buffer + maxtoken - 3)
2094: p = extend_token_buffer (p);
2095: *p++ = c;
2096: c = getc (finput);
2097: }
2098: }
2099: break;
2100: }
2101: if (p >= token_buffer + maxtoken - 3)
2102: p = extend_token_buffer (p);
2103: *p++ = c;
2104: c = getc (finput);
2105: }
2106:
2107: /* Create a node with determined type and value. */
2108: yylval.ttype = build_real (type, value);
2109:
2110: ungetc (c, finput);
2111: *p = 0;
2112: }
2113: else
2114: {
2115: tree type;
2116: int spec_unsigned = 0;
2117: int spec_long = 0;
2118:
2119: while (1)
2120: {
2121: if (c == 'u' || c == 'U')
2122: {
2123: if (spec_unsigned)
2124: error ("two `u's in integer constant");
2125: spec_unsigned = 1;
2126: }
2127: else if (c == 'l' || c == 'L')
2128: {
2129: if (spec_long)
2130: error ("two `l's in integer constant");
2131: spec_long = 1;
2132: }
2133: else
2134: {
2135: if (isalnum (c))
2136: {
2137: error ("garbage at end of number");
2138: while (isalnum (c))
2139: {
2140: if (p >= token_buffer + maxtoken - 3)
2141: p = extend_token_buffer (p);
2142: *p++ = c;
2143: c = getc (finput);
2144: }
2145: }
2146: break;
2147: }
2148: if (p >= token_buffer + maxtoken - 3)
2149: p = extend_token_buffer (p);
2150: *p++ = c;
2151: c = getc (finput);
2152: }
2153:
2154: ungetc (c, finput);
2155:
2156: if (shorts[7] | shorts[6] | shorts[5] | shorts[4])
2157: warning ("integer constant out of range");
2158:
2159: /* This is simplified by the fact that our constant
2160: is always positive. */
2161: yylval.ttype
2162: = build_int_2 ((shorts[3]<<24) + (shorts[2]<<16) + (shorts[1]<<8) + shorts[0],
2163: 0);
2164:
2165: if (!spec_long && !spec_unsigned
2166: && int_fits_type_p (yylval.ttype, integer_type_node))
2167: type = integer_type_node;
2168:
2169: else if (!spec_long && base != 10
2170: && int_fits_type_p (yylval.ttype, unsigned_type_node))
2171: type = unsigned_type_node;
2172:
2173: else if (!spec_unsigned
2174: && int_fits_type_p (yylval.ttype, long_integer_type_node))
2175: type = long_integer_type_node;
2176:
2177: else
2178: {
2179: type = long_unsigned_type_node;
2180: if (! int_fits_type_p (yylval.ttype, long_unsigned_type_node))
2181: warning ("integer constant out of range");
2182: }
2183: TREE_TYPE (yylval.ttype) = type;
2184: }
2185:
2186: value = CONSTANT; break;
2187: }
2188:
2189: case '\'':
2190: char_constant:
2191: c = getc (finput);
2192: {
2193: register int code = 0;
2194:
2195: tryagain:
2196:
2197: if (c == '\\')
2198: {
2199: c = readescape ();
2200: if (c < 0)
2201: goto tryagain;
2202: }
2203: else if (c == '\n')
2204: {
2205: if (pedantic)
2206: warning ("ANSI C forbids newline in character constant");
2207: lineno++;
2208: }
2209:
2210: code = c;
2211: token_buffer[1] = c;
2212: token_buffer[2] = '\'';
2213: token_buffer[3] = 0;
2214:
2215: c = getc (finput);
2216: if (c != '\'')
2217: error ("malformatted character constant");
2218:
2219: /* If char type is signed, sign-extend the constant. */
2220: if (TREE_UNSIGNED (char_type_node)
2221: || ((code >> (BITS_PER_UNIT - 1)) & 1) == 0)
2222: yylval.ttype = build_int_2 (code & ((1 << BITS_PER_UNIT) - 1), 0);
2223: else
2224: yylval.ttype = build_int_2 (code | ((-1) << BITS_PER_UNIT), -1);
2225:
2226: TREE_TYPE (yylval.ttype) = integer_type_node;
2227: value = CONSTANT; break;
2228: }
2229:
2230: case '"':
2231: string_constant:
2232: {
2233: c = getc (finput);
2234: p = token_buffer + 1;
2235:
2236: while (c != '"')
2237: {
2238: if (c == '\\')
2239: {
2240: c = readescape ();
2241: if (c < 0)
2242: goto skipnewline;
2243: }
2244: else if (c == '\n')
2245: {
2246: if (pedantic)
2247: warning ("ANSI C forbids newline in string constant");
2248: lineno++;
2249: }
2250:
2251: if (p == token_buffer + maxtoken)
2252: p = extend_token_buffer (p);
2253: *p++ = c;
2254:
2255: skipnewline:
2256: c = getc (finput);
2257: }
2258:
2259: *p = 0;
2260:
2261: if (wide_flag)
2262: {
2263: /* If this is a L"..." wide-string, convert each char
2264: to an int, making a vector of ints. */
2265: int *widebuf = (int *) alloca (p - token_buffer);
2266: char *p1 = token_buffer + 1;
2267: for (; p1 != p; p1++)
2268: widebuf[p1 - token_buffer - 1] = *p1;
2269: yylval.ttype = build_string ((p - token_buffer) * sizeof (int),
2270: widebuf);
2271: TREE_TYPE (yylval.ttype) = int_array_type_node;
2272: }
2273: else
2274: {
2275: yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
2276: TREE_TYPE (yylval.ttype) = char_array_type_node;
2277: }
2278:
2279: *p++ = '"';
2280: *p = 0;
2281:
2282: value = STRING; break;
2283: }
2284:
2285: case '+':
2286: case '-':
2287: case '&':
2288: case '|':
2289: case '<':
2290: case '>':
2291: case '*':
2292: case '/':
2293: case '%':
2294: case '^':
2295: case '!':
2296: case '=':
2297: {
2298: register int c1;
2299:
2300: combine:
2301:
2302: switch (c)
2303: {
2304: case '+':
2305: yylval.code = PLUS_EXPR; break;
2306: case '-':
2307: yylval.code = MINUS_EXPR; break;
2308: case '&':
2309: yylval.code = BIT_AND_EXPR; break;
2310: case '|':
2311: yylval.code = BIT_IOR_EXPR; break;
2312: case '*':
2313: yylval.code = MULT_EXPR; break;
2314: case '/':
2315: yylval.code = TRUNC_DIV_EXPR; break;
2316: case '%':
2317: yylval.code = TRUNC_MOD_EXPR; break;
2318: case '^':
2319: yylval.code = BIT_XOR_EXPR; break;
2320: case LSHIFT:
2321: yylval.code = LSHIFT_EXPR; break;
2322: case RSHIFT:
2323: yylval.code = RSHIFT_EXPR; break;
2324: case '<':
2325: yylval.code = LT_EXPR; break;
2326: case '>':
2327: yylval.code = GT_EXPR; break;
2328: }
2329:
2330: token_buffer[1] = c1 = getc (finput);
2331: token_buffer[2] = 0;
2332:
2333: if (c1 == '=')
2334: {
2335: switch (c)
2336: {
2337: case '<':
2338: value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
2339: case '>':
2340: value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
2341: case '!':
2342: value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
2343: case '=':
2344: value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
2345: }
2346: value = ASSIGN; goto done;
2347: }
2348: else if (c == c1)
2349: switch (c)
2350: {
2351: case '+':
2352: value = PLUSPLUS; goto done;
2353: case '-':
2354: value = MINUSMINUS; goto done;
2355: case '&':
2356: value = ANDAND; goto done;
2357: case '|':
2358: value = OROR; goto done;
2359: case '<':
2360: c = LSHIFT;
2361: goto combine;
2362: case '>':
2363: c = RSHIFT;
2364: goto combine;
2365: }
2366: else if ((c == '-') && (c1 == '>'))
2367: { value = POINTSAT; goto done; }
2368: ungetc (c1, finput);
2369: token_buffer[1] = 0;
2370:
2371: if ((c == '<') || (c == '>'))
2372: value = ARITHCOMPARE;
2373: else value = c;
2374: goto done;
2375: }
2376:
2377: default:
2378: value = c;
2379: }
2380:
2381: done:
2382: /* yylloc.last_line = lineno; */
2383:
2384: return value;
2385: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.