|
|
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
135: %type <ttype> asm_operands nonnull_asm_operands asm_operand
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");
201: else
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);
991: c_expand_asm_operands ($4, $6, NULL_TREE,
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);
998: c_expand_asm_operands ($4, $6, $8,
999: $2 == ridpointers[(int)RID_VOLATILE]); }
1000: | GOTO identifier ';'
1001: { tree decl;
1002: emit_note (input_filename, lineno);
1003: decl = lookup_label ($2);
1004: expand_goto (decl); }
1005: | identifier ':'
1006: { tree label = define_label (input_filename, lineno, $1);
1007: if (label)
1008: expand_label (label); }
1009: stmt
1010: | ';'
1011: ;
1012:
1013: maybe_type_qual:
1014: /* empty */
1015: { emit_note (input_filename, lineno); }
1016: | TYPE_QUAL
1017: { emit_note (input_filename, lineno); }
1018: ;
1019:
1020: xexpr:
1021: /* empty */
1022: { $$ = NULL_TREE; }
1023: | expr
1024: ;
1025:
1026: /* These are the operands other than the first string and colon
1027: in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
1028: asm_operands: /* empty */
1029: { $$ = NULL_TREE; }
1030: | nonnull_asm_operands
1031: ;
1032:
1033: nonnull_asm_operands:
1034: asm_operand
1035: | nonnull_asm_operands ',' asm_operand
1036: { $$ = chainon ($1, $3); }
1037: ;
1038:
1039: asm_operand:
1040: STRING '(' expr ')'
1041: { $$ = build_tree_list ($1, $3); }
1042: ;
1043:
1044: /* This is what appears inside the parens in a function declarator.
1045: Its value is a list of ..._TYPE nodes. */
1046: parmlist:
1047: { pushlevel (0); }
1048: parmlist_1
1049: { $$ = $2; poplevel (0, 0, 0); }
1050: ;
1051:
1052: /* This is referred to where either a parmlist or an identifier list is ok.
1053: Its value is a list of ..._TYPE nodes or a list of identifiers. */
1054: parmlist_or_identifiers:
1055: { pushlevel (0); }
1056: parmlist_or_identifiers_1
1057: { $$ = $2; poplevel (0, 0, 0); }
1058: ;
1059:
1060: parmlist_or_identifiers_1:
1061: parmlist_2 ')'
1062: | identifiers ')'
1063: { $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
1064: | error ')'
1065: { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
1066: ;
1067:
1068: parmlist_1:
1069: parmlist_2 ')'
1070: | error ')'
1071: { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
1072: ;
1073:
1074: /* This is what appears inside the parens in a function declarator.
1075: Is value is represented in the format that grokdeclarator expects. */
1076: parmlist_2: /* empty */
1077: { $$ = get_parm_info (0); }
1078: | parms
1079: { $$ = get_parm_info (1); }
1080: | parms ',' ELLIPSIS
1081: { $$ = get_parm_info (0); }
1082: ;
1083:
1084: parms:
1085: parm
1086: { push_parm_decl ($1); }
1087: | parms ',' parm
1088: { push_parm_decl ($3); }
1089: ;
1090:
1091: /* A single parameter declaration or parameter type name,
1092: as found in a parmlist. */
1093: parm:
1094: typed_declspecs parm_declarator
1095: { $$ = build_tree_list ($1, $2) ; }
1096: | typed_declspecs notype_declarator
1097: { $$ = build_tree_list ($1, $2) ; }
1098: | typed_declspecs absdcl
1099: { $$ = build_tree_list ($1, $2); }
1100: | declmods notype_declarator
1101: { $$ = build_tree_list ($1, $2) ; }
1102: | declmods absdcl
1103: { $$ = build_tree_list ($1, $2); }
1104: ;
1105:
1106: /* A nonempty list of identifiers. */
1107: identifiers:
1108: IDENTIFIER
1109: { $$ = build_tree_list (NULL_TREE, $1); }
1110: | identifiers ',' IDENTIFIER
1111: { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
1112: ;
1113: %%
1114:
1115: /* Return something to represent absolute declarators containing a *.
1116: TARGET is the absolute declarator that the * contains.
1117: TYPE_QUALS is a list of modifiers such as const or volatile
1118: to apply to the pointer type, represented as identifiers.
1119:
1120: We return an INDIRECT_REF whose "contents" are TARGET
1121: and whose type is the modifier list. */
1122:
1123: static tree
1124: make_pointer_declarator (type_quals, target)
1125: tree type_quals, target;
1126: {
1127: return build (INDIRECT_REF, type_quals, target);
1128: }
1129:
1130: /* Given a chain of STRING_CST nodes,
1131: concatenate them into one STRING_CST
1132: and give it a suitable array-of-chars data type. */
1133:
1134: static tree
1135: combine_strings (strings)
1136: tree strings;
1137: {
1138: register tree value, t;
1139: register int length = 1;
1140: int wide_length = 0;
1141: int wide_flag = 0;
1142:
1143: if (TREE_CHAIN (strings))
1144: {
1145: /* More than one in the chain, so concatenate. */
1146: register char *p, *q;
1147:
1148: /* Don't include the \0 at the end of each substring,
1149: except for the last one.
1150: Count wide strings and ordinary strings separately. */
1151: for (t = strings; t; t = TREE_CHAIN (t))
1152: {
1153: if (TREE_TYPE (t) == int_array_type_node)
1154: {
1155: wide_length += (TREE_STRING_LENGTH (t) - 1);
1156: wide_flag = 1;
1157: }
1158: else
1159: length += (TREE_STRING_LENGTH (t) - 1);
1160: }
1161:
1162: /* If anything is wide, the non-wides will be converted,
1163: which makes them take more space. */
1164: if (wide_flag)
1165: length = length * UNITS_PER_WORD + wide_length;
1166:
1167: p = (char *) oballoc (length);
1168:
1169: /* Copy the individual strings into the new combined string.
1170: If the combined string is wide, convert the chars to ints
1171: for any individual strings that are not wide. */
1172:
1173: q = p;
1174: for (t = strings; t; t = TREE_CHAIN (t))
1175: {
1176: int len = TREE_STRING_LENGTH (t) - 1;
1177: if ((TREE_TYPE (t) == int_array_type_node) == wide_flag)
1178: {
1179: bcopy (TREE_STRING_POINTER (t), q, len);
1180: q += len;
1181: }
1182: else
1183: {
1184: int i;
1185: for (i = 0; i < len; i++)
1186: ((int *) q)[i] = TREE_STRING_POINTER (t)[i];
1187: q += len * UNITS_PER_WORD;
1188: }
1189: }
1190: *q = 0;
1191:
1192: value = make_node (STRING_CST);
1193: TREE_STRING_POINTER (value) = p;
1194: TREE_STRING_LENGTH (value) = length;
1195: TREE_LITERAL (value) = 1;
1196: }
1197: else
1198: {
1199: value = strings;
1200: length = TREE_STRING_LENGTH (value);
1201: if (TREE_TYPE (value) == int_array_type_node)
1202: wide_flag = 1;
1203: }
1204:
1205: TREE_TYPE (value)
1206: = build_array_type (wide_flag ? integer_type_node : char_type_node,
1207: make_index_type (build_int_2 (length - 1, 0)));
1208: TREE_LITERAL (value) = 1;
1209: TREE_STATIC (value) = 1;
1210: return value;
1211: }
1212:
1213: int lineno; /* current line number in file being read */
1214:
1215: FILE *finput; /* input file.
1216: Normally a pipe from the preprocessor. */
1217:
1218: /* lexical analyzer */
1219:
1220: static int maxtoken; /* Current nominal length of token buffer */
1221: static char *token_buffer; /* Pointer to token buffer.
1222: Actual allocated length is maxtoken + 2. */
1223:
1224: #define MAXRESERVED 9
1225:
1226: /* frw[I] is index in `reswords' of the first word whose length is I;
1227: frw[I+1] is one plus the index of the last word whose length is I.
1228: The length of frw must be MAXRESERVED + 2 so there is an element
1229: at MAXRESERVED+1 for the case I == MAXRESERVED. */
1230:
1231: static char frw[MAXRESERVED+2] =
1232: { 0, 0, 0, 2, 5, 13, 19, 29, 31, 35, 36 };
1233:
1234: /* Table of reserved words. */
1235:
1236: struct resword { char *name; short token; enum rid rid;};
1237:
1238: #define NORID RID_UNUSED
1239:
1240: static struct resword reswords[]
1241: = {{"if", IF, NORID},
1242: {"do", DO, NORID},
1243: {"int", TYPESPEC, RID_INT},
1244: {"for", FOR, NORID},
1245: {"asm", ASM, NORID},
1246: {"case", CASE, NORID},
1247: {"char", TYPESPEC, RID_CHAR},
1248: {"auto", SCSPEC, RID_AUTO},
1249: {"goto", GOTO, NORID},
1250: {"else", ELSE, NORID},
1251: {"long", TYPESPEC, RID_LONG},
1252: {"void", TYPESPEC, RID_VOID},
1253: {"enum", ENUM, NORID},
1254: {"float", TYPESPEC, RID_FLOAT},
1255: {"short", TYPESPEC, RID_SHORT},
1256: {"union", UNION, NORID},
1257: {"break", BREAK, NORID},
1258: {"while", WHILE, NORID},
1259: {"const", TYPE_QUAL, RID_CONST},
1260: {"double", TYPESPEC, RID_DOUBLE},
1261: {"static", SCSPEC, RID_STATIC},
1262: {"extern", SCSPEC, RID_EXTERN},
1263: {"struct", STRUCT, NORID},
1264: {"return", RETURN, NORID},
1265: {"sizeof", SIZEOF, NORID},
1266: {"typeof", TYPEOF, NORID},
1267: {"switch", SWITCH, NORID},
1268: {"signed", TYPESPEC, RID_SIGNED},
1269: {"inline", SCSPEC, RID_INLINE},
1270: {"typedef", SCSPEC, RID_TYPEDEF},
1271: {"default", DEFAULT, NORID},
1272: {"unsigned", TYPESPEC, RID_UNSIGNED},
1273: {"continue", CONTINUE, NORID},
1274: {"register", SCSPEC, RID_REGISTER},
1275: {"volatile", TYPE_QUAL, RID_VOLATILE},
1276: {"__alignof", ALIGNOF, NORID}};
1277:
1278: /* The elements of `ridpointers' are identifier nodes
1279: for the reserved type names and storage classes.
1280: It is indexed by a RID_... value. */
1281:
1282: tree ridpointers[(int) RID_MAX];
1283:
1284: int check_newline ();
1285:
1286: void
1287: init_lex ()
1288: {
1289: extern char *malloc ();
1290:
1291: /* Start it at 0, because check_newline is called at the very beginning
1292: and will increment it to 1. */
1293: lineno = 0;
1294:
1295: maxtoken = 40;
1296: token_buffer = malloc (maxtoken + 2);
1297: ridpointers[(int) RID_INT] = get_identifier ("int");
1298: ridpointers[(int) RID_CHAR] = get_identifier ("char");
1299: ridpointers[(int) RID_VOID] = get_identifier ("void");
1300: ridpointers[(int) RID_FLOAT] = get_identifier ("float");
1301: ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
1302: ridpointers[(int) RID_SHORT] = get_identifier ("short");
1303: ridpointers[(int) RID_LONG] = get_identifier ("long");
1304: ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
1305: ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
1306: ridpointers[(int) RID_INLINE] = get_identifier ("inline");
1307: ridpointers[(int) RID_CONST] = get_identifier ("const");
1308: ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
1309: ridpointers[(int) RID_AUTO] = get_identifier ("auto");
1310: ridpointers[(int) RID_STATIC] = get_identifier ("static");
1311: ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
1312: ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
1313: ridpointers[(int) RID_REGISTER] = get_identifier ("register");
1314: }
1315:
1316: static void
1317: reinit_parse_for_function ()
1318: {
1319: }
1320:
1321: /* If C is not whitespace, return C.
1322: Otherwise skip whitespace and return first nonwhite char read. */
1323:
1324: static int
1325: skip_white_space (c)
1326: register int c;
1327: {
1328: register int inside;
1329:
1330: for (;;)
1331: {
1332: switch (c)
1333: {
1334: case '/':
1335: c = getc (finput);
1336: if (c != '*')
1337: {
1338: ungetc (c, finput);
1339: return '/';
1340: }
1341:
1342: c = getc (finput);
1343:
1344: inside = 1;
1345: while (inside)
1346: {
1347: if (c == '*')
1348: {
1349: while (c == '*')
1350: c = getc (finput);
1351:
1352: if (c == '/')
1353: {
1354: inside = 0;
1355: c = getc (finput);
1356: }
1357: }
1358: else if (c == '\n')
1359: {
1360: lineno++;
1361: c = getc (finput);
1362: }
1363: else if (c == EOF)
1364: {
1365: error ("unterminated comment");
1366: break;
1367: }
1368: else
1369: c = getc (finput);
1370: }
1371:
1372: break;
1373:
1374: case '\n':
1375: c = check_newline ();
1376: break;
1377:
1378: case ' ':
1379: case '\t':
1380: case '\f':
1381: case '\r':
1382: case '\b':
1383: c = getc (finput);
1384: break;
1385:
1386: case '\\':
1387: c = getc (finput);
1388: if (c == '\n')
1389: lineno++;
1390: else
1391: error ("stray '\\' in program");
1392: c = getc (finput);
1393: break;
1394:
1395: default:
1396: return (c);
1397: }
1398: }
1399: }
1400:
1401:
1402:
1403: /* Make the token buffer longer, preserving the data in it.
1404: P should point to just beyond the last valid character in the old buffer.
1405: The value we return is a pointer to the new buffer
1406: at a place corresponding to P. */
1407:
1408: static char *
1409: extend_token_buffer (p)
1410: char *p;
1411: {
1412: int offset = p - token_buffer;
1413:
1414: maxtoken = maxtoken * 2 + 10;
1415: token_buffer = (char *) realloc (token_buffer, maxtoken + 2);
1416: if (token_buffer == 0)
1417: fatal ("virtual memory exceeded");
1418:
1419: return token_buffer + offset;
1420: }
1421:
1422: /* At the beginning of a line, increment the line number
1423: and handle a #line directive immediately following.
1424: Return first nonwhite char of first non-# line following. */
1425:
1426: int
1427: check_newline ()
1428: {
1429: register int c;
1430: register int token;
1431:
1432: while (1)
1433: {
1434: lineno++;
1435:
1436: /* Read first nonwhite char on the line. */
1437:
1438: c = getc (finput);
1439: while (c == ' ' || c == '\t')
1440: c = getc (finput);
1441:
1442: if (c != '#')
1443: {
1444: /* If not #, return it so caller will use it. */
1445: return c;
1446: }
1447:
1448: /* Read first nonwhite char after the `#'. */
1449:
1450: c = getc (finput);
1451: while (c == ' ' || c == '\t')
1452: c = getc (finput);
1453:
1454: /* If a letter follows, then if the word here is `line', skip
1455: it and ignore it; otherwise, ignore the line, with an error
1456: if the word isn't `pragma'. */
1457:
1458: if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
1459: {
1460: if (c == 'p')
1461: {
1462: if (getc (finput) == 'r'
1463: && getc (finput) == 'a'
1464: && getc (finput) == 'g'
1465: && getc (finput) == 'm'
1466: && getc (finput) == 'a'
1467: && ((c = getc (finput)) == ' ' || c == '\t'))
1468: goto noerror;
1469: }
1470:
1471: else if (c == 'l')
1472: {
1473: if (getc (finput) == 'i'
1474: && getc (finput) == 'n'
1475: && getc (finput) == 'e'
1476: && ((c = getc (finput)) == ' ' || c == '\t'))
1477: goto linenum;
1478: }
1479: #ifdef IDENT_DIRECTIVE
1480: else if (c == 'i')
1481: {
1482: if (getc (finput) == 'd'
1483: && getc (finput) == 'e'
1484: && getc (finput) == 'n'
1485: && getc (finput) == 't'
1486: && ((c = getc (finput)) == ' ' || c == '\t'))
1487: {
1488: extern FILE *asm_out_file;
1489:
1490: if (pedantic)
1491: error ("ANSI C does not allow #ident");
1492:
1493: /* Here we have just seen `#ident '.
1494: A string constant should follow. */
1495:
1496: while (c == ' ' || c == '\t')
1497: c = getc (finput);
1498:
1499: /* If no argument, ignore the line. */
1500: if (c == '\n')
1501: continue;
1502:
1503: ungetc (c, finput);
1504: token = yylex ();
1505: if (token != STRING
1506: || TREE_CODE (yylval.ttype) != STRING_CST)
1507: {
1508: error ("invalid #ident");
1509: return getc (finput);
1510: }
1511:
1512: fprintf (asm_out_file, "\t.ident \"%s\"\n",
1513: TREE_STRING_POINTER (yylval.ttype));
1514:
1515: /* Skip the rest of this line. */
1516: while ((c = getc (finput)) && c != '\n');
1517: if (c == 0)
1518: return 0;
1519: continue;
1520: }
1521: }
1522: #endif
1523:
1524: error ("undefined or invalid # directive");
1525: noerror:
1526:
1527: while ((c = getc (finput)) && c != '\n');
1528:
1529: if (c == 0)
1530: return 0;
1531: continue;
1532: }
1533:
1534: linenum:
1535: /* Here we have either `#line' or `# <nonletter>'.
1536: In either case, it should be a line number; a digit should follow. */
1537:
1538: while (c == ' ' || c == '\t')
1539: c = getc (finput);
1540:
1541: /* If the # is the only nonwhite char on the line,
1542: just ignore it. Check the new newline. */
1543: if (c == '\n')
1544: continue;
1545:
1546: /* Something follows the #; read a token. */
1547:
1548: ungetc (c, finput);
1549: token = yylex ();
1550:
1551: if (token == CONSTANT
1552: && TREE_CODE (yylval.ttype) == INTEGER_CST)
1553: {
1554: /* subtract one, because it is the following line that
1555: gets the specified number */
1556:
1557: int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
1558:
1559: /* Is this the last nonwhite stuff on the line? */
1560: c = getc (finput);
1561: while (c == ' ' || c == '\t')
1562: c = getc (finput);
1563: if (c == '\n')
1564: {
1565: /* No more: store the line number and check following line. */
1566: lineno = l;
1567: continue;
1568: }
1569: ungetc (c, finput);
1570:
1571: /* More follows: it must be a string constant (filename). */
1572:
1573: token = yylex ();
1574: if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
1575: {
1576: error ("invalid #line");
1577: return getc (finput);
1578: }
1579:
1580: input_filename
1581: = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
1582: strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
1583: lineno = l;
1584:
1585: if (main_input_filename == 0)
1586: main_input_filename = input_filename;
1587: }
1588: else
1589: error ("invalid #line");
1590:
1591: /* skip the rest of this line. */
1592: while ((c = getc (finput)) && c != '\n');
1593: if (c == 0)
1594: return 0;
1595: }
1596: }
1597:
1598: #define isalnum(char) ((char >= 'a' && char <= 'z') || (char >= 'A' && char <= 'Z') || (char >= '0' && char <= '9'))
1599: #define isdigit(char) (char >= '0' && char <= '9')
1600: #define ENDFILE -1 /* token that represents end-of-file */
1601:
1602:
1603: static int
1604: readescape ()
1605: {
1606: register int c = getc (finput);
1607: register int count, code;
1608:
1609: switch (c)
1610: {
1611: case 'x':
1612: code = 0;
1613: count = 0;
1614: while (1)
1615: {
1616: c = getc (finput);
1617: if (!(c >= 'a' && c <= 'f')
1618: && !(c >= 'A' && c <= 'F')
1619: && !(c >= '0' && c <= '9'))
1620: {
1621: ungetc (c, finput);
1622: break;
1623: }
1624: code *= 16;
1625: if (c >= 'a' && c <= 'f')
1626: code += c - 'a' + 10;
1627: if (c >= 'A' && c <= 'F')
1628: code += c - 'A' + 10;
1629: if (c >= '0' && c <= '9')
1630: code += c - '0';
1631: count++;
1632: }
1633: if (count == 0)
1634: error ("\\x used with no following hex digits");
1635: return code;
1636:
1637: case '0': case '1': case '2': case '3': case '4':
1638: case '5': case '6': case '7':
1639: code = 0;
1640: count = 0;
1641: while ((c <= '7') && (c >= '0') && (count++ < 3))
1642: {
1643: code = (code * 8) + (c - '0');
1644: c = getc (finput);
1645: }
1646: ungetc (c, finput);
1647: return code;
1648:
1649: case '\\': case '\'': case '"':
1650: return c;
1651:
1652: case '\n':
1653: lineno++;
1654: return -1;
1655:
1656: case 'n':
1657: return TARGET_NEWLINE;
1658:
1659: case 't':
1660: return TARGET_TAB;
1661:
1662: case 'r':
1663: return TARGET_CR;
1664:
1665: case 'f':
1666: return TARGET_FF;
1667:
1668: case 'b':
1669: return TARGET_BS;
1670:
1671: case 'a':
1672: return TARGET_BELL;
1673:
1674: case 'v':
1675: return TARGET_VT;
1676:
1677: case 'E':
1678: return 033;
1679:
1680: case '?':
1.1.1.2 ! root 1681: /* `\(' is used at the beginning of a line to avoid confusing Emacs. */
! 1682: case '(':
1.1 root 1683: return c;
1684: }
1685: if (c >= 040 && c <= 0177)
1686: warning ("unknown escape sequence `\\%c'", c);
1687: else
1688: warning ("unknown escape sequence: `\\' followed by char code 0x%x", c);
1689: return c;
1690: }
1691:
1692: void
1693: yyerror (string)
1694: char *string;
1695: {
1696: char buf[200];
1697:
1698: strcpy (buf, string);
1699:
1700: /* We can't print string and character constants well
1701: because the token_buffer contains the result of processing escapes. */
1702: if (token_buffer[0] == 0)
1703: strcat (buf, " at end of input");
1704: else if (token_buffer[0] == '"')
1705: strcat (buf, " before string constant");
1706: else if (token_buffer[0] == '\'')
1707: strcat (buf, " before character constant");
1708: else
1709: strcat (buf, " before `%s'");
1710:
1711: error (buf, token_buffer);
1712: }
1713:
1714: static int nextchar = -1;
1715:
1716: static int
1717: yylex ()
1718: {
1719: register int c;
1720: register char *p;
1721: register int value;
1722: int wide_flag = 0;
1723:
1724: if (nextchar >= 0)
1725: c = nextchar, nextchar = -1;
1726: else
1727: c = getc (finput);
1728:
1729: /* Effectively do c = skip_white_space (c)
1730: but do it faster in the usual cases. */
1731: while (1)
1732: switch (c)
1733: {
1734: case ' ':
1735: case '\t':
1736: case '\f':
1737: case '\r':
1738: case '\b':
1739: c = getc (finput);
1740: break;
1741:
1742: case '\n':
1743: case '/':
1744: case '\\':
1745: c = skip_white_space (c);
1746: default:
1747: goto found_nonwhite;
1748: }
1749: found_nonwhite:
1750:
1751: token_buffer[0] = c;
1752: token_buffer[1] = 0;
1753:
1754: /* yylloc.first_line = lineno; */
1755:
1756: switch (c)
1757: {
1758: case EOF:
1759: token_buffer[0] = 0;
1760: value = ENDFILE;
1761: break;
1762:
1763: case '$':
1764: if (dollars_in_ident)
1765: goto letter;
1766: return '$';
1767:
1768: case 'L':
1769: /* Capital L may start a wide-string or wide-character constant. */
1770: {
1771: register int c = getc (finput);
1772: if (c == '\'')
1773: {
1774: wide_flag = 1;
1775: goto char_constant;
1776: }
1777: if (c == '"')
1778: {
1779: wide_flag = 1;
1780: goto string_constant;
1781: }
1782: ungetc (c, finput);
1783: }
1784:
1785: case 'A': case 'B': case 'C': case 'D': case 'E':
1786: case 'F': case 'G': case 'H': case 'I': case 'J':
1787: case 'K': case 'M': case 'N': case 'O':
1788: case 'P': case 'Q': case 'R': case 'S': case 'T':
1789: case 'U': case 'V': case 'W': case 'X': case 'Y':
1790: case 'Z':
1791: case 'a': case 'b': case 'c': case 'd': case 'e':
1792: case 'f': case 'g': case 'h': case 'i': case 'j':
1793: case 'k': case 'l': case 'm': case 'n': case 'o':
1794: case 'p': case 'q': case 'r': case 's': case 't':
1795: case 'u': case 'v': case 'w': case 'x': case 'y':
1796: case 'z':
1797: case '_':
1798: letter:
1799: p = token_buffer;
1800: while (isalnum (c) || c == '_' || c == '$')
1801: {
1802: if (p >= token_buffer + maxtoken)
1803: p = extend_token_buffer (p);
1804: if (c == '$' && ! dollars_in_ident)
1805: break;
1806:
1807: *p++ = c;
1808: c = getc (finput);
1809: }
1810:
1811: *p = 0;
1812: nextchar = c;
1813:
1814: value = IDENTIFIER;
1815: yylval.itype = 0;
1816:
1817: /* Try to recognize a keyword. */
1818:
1819: if (p - token_buffer <= MAXRESERVED)
1820: {
1821: register int lim = frw [p - token_buffer + 1];
1822: register int i = frw[p - token_buffer];
1823: register struct resword *p = &reswords[i];
1824:
1825: for (; i < lim; i++, p++)
1826: if (p->name[0] == token_buffer[0]
1827: && !strcmp (p->name, token_buffer))
1828: {
1829: if (p->rid)
1830: yylval.ttype = ridpointers[(int) p->rid];
1831: if ((! flag_no_asm
1832: || ((int) p->token != ASM
1833: && (int) p->token != TYPEOF
1.1.1.2 ! root 1834: && p->rid != RID_INLINE))
1.1 root 1835: /* -ftraditional means don't recognize
1836: typeof, const, volatile, signed or inline. */
1837: && (! flag_traditional
1838: || ((int) p->token != TYPE_QUAL
1839: && (int) p->token != TYPEOF
1.1.1.2 ! root 1840: && p->rid != RID_SIGNED
! 1841: && p->rid != RID_INLINE)))
1.1 root 1842: value = (int) p->token;
1843: break;
1844: }
1845: }
1846:
1847: /* If we did not find a keyword, look for an identifier
1848: (or a typename). */
1849:
1850: if (value == IDENTIFIER)
1851: {
1852: yylval.ttype = get_identifier (token_buffer);
1853: lastiddecl = lookup_name (yylval.ttype);
1854:
1855: if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
1856: value = TYPENAME;
1857: }
1858:
1859: break;
1860:
1861: case '0': case '1': case '2': case '3': case '4':
1862: case '5': case '6': case '7': case '8': case '9':
1863: case '.':
1864: {
1865: int base = 10;
1866: int count = 0;
1867: int largest_digit = 0;
1868: int numdigits = 0;
1869: /* for multi-precision arithmetic,
1870: we store only 8 live bits in each short,
1871: giving us 64 bits of reliable precision */
1872: short shorts[8];
1873: int floatflag = 0; /* Set 1 if we learn this is a floating constant */
1874:
1875: for (count = 0; count < 8; count++)
1876: shorts[count] = 0;
1877:
1878: p = token_buffer;
1879: *p++ = c;
1880:
1881: if (c == '0')
1882: {
1883: *p++ = (c = getc (finput));
1884: if ((c == 'x') || (c == 'X'))
1885: {
1886: base = 16;
1887: *p++ = (c = getc (finput));
1888: }
1889: else
1890: {
1891: base = 8;
1892: numdigits++;
1893: }
1894: }
1895:
1896: /* Read all the digits-and-decimal-points. */
1897:
1898: while (c == '.'
1899: || (isalnum (c) && (c != 'l') && (c != 'L')
1900: && (c != 'u') && (c != 'U')
1901: && (!floatflag || ((c != 'f') && (c != 'F')))))
1902: {
1903: if (c == '.')
1904: {
1905: if (base == 16)
1906: error ("floating constant may not be in radix 16");
1907: floatflag = 1;
1908: base = 10;
1909: *p++ = c = getc (finput);
1910: /* Accept '.' as the start of a floating-point number
1911: only when it is followed by a digit.
1912: Otherwise, unread the following non-digit
1913: and use the '.' as a structural token. */
1914: if (p == token_buffer + 2 && !isdigit (c))
1915: {
1916: if (c == '.')
1917: {
1918: c = getc (finput);
1919: if (c == '.')
1920: {
1921: *p++ = c;
1922: *p = 0;
1923: return ELLIPSIS;
1924: }
1925: error ("parse error at `..'");
1926: }
1927: ungetc (c, finput);
1928: token_buffer[1] = 0;
1929: value = '.';
1930: goto done;
1931: }
1932: }
1933: else
1934: {
1935: /* It is not a decimal point.
1936: It should be a digit (perhaps a hex digit). */
1937:
1938: if (isdigit (c))
1939: {
1940: c = c - '0';
1941: }
1942: else if (base <= 10)
1943: {
1944: if ((c&~040) == 'E')
1945: {
1946: base = 10;
1947: floatflag = 1;
1948: break; /* start of exponent */
1949: }
1950: error ("nondigits in number and not hexadecimal");
1951: c = 0;
1952: }
1953: else if (c >= 'a')
1954: {
1955: c = c - 'a' + 10;
1956: }
1957: else
1958: {
1959: c = c - 'A' + 10;
1960: }
1961: if (c >= largest_digit)
1962: largest_digit = c;
1963: numdigits++;
1964:
1965: for (count = 0; count < 8; count++)
1966: {
1967: (shorts[count] *= base);
1968: if (count)
1969: {
1970: shorts[count] += (shorts[count-1] >> 8);
1971: shorts[count-1] &= (1<<8)-1;
1972: }
1973: else shorts[0] += c;
1974: }
1975:
1976: if (p >= token_buffer + maxtoken - 3)
1977: p = extend_token_buffer (p);
1978: *p++ = (c = getc (finput));
1979: }
1980: }
1981:
1982: if (numdigits == 0)
1983: error ("numeric constant with no digits");
1984:
1985: if (largest_digit >= base)
1986: error ("numeric constant contains digits beyond the radix");
1987:
1988: /* Remove terminating char from the token buffer and delimit the string */
1989: *--p = 0;
1990:
1991: if (floatflag)
1992: {
1993: tree type = double_type_node;
1994: char f_seen = 0;
1995: char l_seen = 0;
1996: double value;
1997:
1998: /* Read explicit exponent if any, and put it in tokenbuf. */
1999:
2000: if ((c == 'e') || (c == 'E'))
2001: {
2002: if (p >= token_buffer + maxtoken - 3)
2003: p = extend_token_buffer (p);
2004: *p++ = c;
2005: c = getc (finput);
2006: if ((c == '+') || (c == '-'))
2007: {
2008: *p++ = c;
2009: c = getc (finput);
2010: }
2011: if (! isdigit (c))
2012: error ("floating constant exponent has no digits");
2013: while (isdigit (c))
2014: {
2015: if (p >= token_buffer + maxtoken - 3)
2016: p = extend_token_buffer (p);
2017: *p++ = c;
2018: c = getc (finput);
2019: }
2020: }
2021:
2022: *p = 0;
2023: errno = 0;
2024: value = atof (token_buffer);
2025: #ifdef ERANGE
2026: if (errno == ERANGE && !flag_traditional)
1.1.1.2 ! root 2027: warning ("floating point number exceeds range of `double'");
1.1 root 2028: #endif
2029:
2030: /* Read the suffixes to choose a data type. */
2031: while (1)
2032: {
2033: if (c == 'f' || c == 'F')
2034: {
2035: if (f_seen)
2036: error ("two `f's in floating constant");
2037: f_seen = 1;
2038: type = float_type_node;
2039: }
2040: else if (c == 'l' || c == 'L')
2041: {
2042: if (l_seen)
2043: error ("two `l's in floating constant");
2044: l_seen = 1;
2045: type = long_double_type_node;
2046: }
2047: else
2048: {
2049: if (isalnum (c))
2050: {
2051: error ("garbage at end of number");
2052: while (isalnum (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: break;
2061: }
2062: if (p >= token_buffer + maxtoken - 3)
2063: p = extend_token_buffer (p);
2064: *p++ = c;
2065: c = getc (finput);
2066: }
2067:
2068: /* Create a node with determined type and value. */
2069: yylval.ttype = build_real (type, value);
2070:
2071: ungetc (c, finput);
2072: *p = 0;
2073: }
2074: else
2075: {
2076: tree type;
2077: int spec_unsigned = 0;
2078: int spec_long = 0;
2079:
2080: while (1)
2081: {
2082: if (c == 'u' || c == 'U')
2083: {
2084: if (spec_unsigned)
2085: error ("two `u's in integer constant");
2086: spec_unsigned = 1;
2087: }
2088: else if (c == 'l' || c == 'L')
2089: {
2090: if (spec_long)
2091: error ("two `l's in integer constant");
2092: spec_long = 1;
2093: }
2094: else
2095: {
2096: if (isalnum (c))
2097: {
2098: error ("garbage at end of number");
2099: while (isalnum (c))
2100: {
2101: if (p >= token_buffer + maxtoken - 3)
2102: p = extend_token_buffer (p);
2103: *p++ = c;
2104: c = getc (finput);
2105: }
2106: }
2107: break;
2108: }
2109: if (p >= token_buffer + maxtoken - 3)
2110: p = extend_token_buffer (p);
2111: *p++ = c;
2112: c = getc (finput);
2113: }
2114:
2115: ungetc (c, finput);
2116:
2117: if (shorts[7] | shorts[6] | shorts[5] | shorts[4])
2118: warning ("integer constant out of range");
2119:
2120: /* This is simplified by the fact that our constant
2121: is always positive. */
2122: yylval.ttype
2123: = build_int_2 ((shorts[3]<<24) + (shorts[2]<<16) + (shorts[1]<<8) + shorts[0],
2124: 0);
2125:
2126: if (!spec_long && !spec_unsigned
2127: && int_fits_type_p (yylval.ttype, integer_type_node))
2128: type = integer_type_node;
2129:
2130: else if (!spec_long && base != 10
2131: && int_fits_type_p (yylval.ttype, unsigned_type_node))
2132: type = unsigned_type_node;
2133:
2134: else if (!spec_unsigned
2135: && int_fits_type_p (yylval.ttype, long_integer_type_node))
2136: type = long_integer_type_node;
2137:
2138: else
2139: {
2140: type = long_unsigned_type_node;
2141: if (! int_fits_type_p (yylval.ttype, long_unsigned_type_node))
2142: warning ("integer constant out of range");
2143: }
2144: TREE_TYPE (yylval.ttype) = type;
2145: }
2146:
2147: value = CONSTANT; break;
2148: }
2149:
2150: case '\'':
2151: char_constant:
2152: c = getc (finput);
2153: {
2154: register int code = 0;
2155:
2156: tryagain:
2157:
2158: if (c == '\\')
2159: {
2160: c = readescape ();
2161: if (c < 0)
2162: goto tryagain;
2163: }
2164: else if (c == '\n')
2165: {
2166: if (pedantic)
2167: warning ("ANSI C forbids newline in character constant");
2168: lineno++;
2169: }
2170:
2171: code = c;
2172: token_buffer[1] = c;
2173: token_buffer[2] = '\'';
2174: token_buffer[3] = 0;
2175:
2176: c = getc (finput);
2177: if (c != '\'')
2178: error ("malformatted character constant");
2179:
2180: /* If char type is signed, sign-extend the constant. */
2181: if (TREE_UNSIGNED (char_type_node)
2182: || ((code >> (BITS_PER_UNIT - 1)) & 1) == 0)
2183: yylval.ttype = build_int_2 (code & ((1 << BITS_PER_UNIT) - 1), 0);
2184: else
2185: yylval.ttype = build_int_2 (code | ((-1) << BITS_PER_UNIT), -1);
2186:
2187: TREE_TYPE (yylval.ttype) = integer_type_node;
2188: value = CONSTANT; break;
2189: }
2190:
2191: case '"':
2192: string_constant:
2193: {
2194: c = getc (finput);
2195: p = token_buffer + 1;
2196:
2197: while (c != '"')
2198: {
2199: if (c == '\\')
2200: {
2201: c = readescape ();
2202: if (c < 0)
2203: goto skipnewline;
2204: }
2205: else if (c == '\n')
2206: {
2207: if (pedantic)
2208: warning ("ANSI C forbids newline in string constant");
2209: lineno++;
2210: }
2211:
2212: if (p == token_buffer + maxtoken)
2213: p = extend_token_buffer (p);
2214: *p++ = c;
2215:
2216: skipnewline:
2217: c = getc (finput);
2218: }
2219:
2220: *p = 0;
2221:
2222: if (wide_flag)
2223: {
2224: /* If this is a L"..." wide-string, convert each char
2225: to an int, making a vector of ints. */
2226: int *widebuf = (int *) alloca (p - token_buffer);
2227: char *p1 = token_buffer + 1;
2228: for (; p1 != p; p1++)
2229: widebuf[p1 - token_buffer - 1] = *p1;
2230: yylval.ttype = build_string ((p - token_buffer) * sizeof (int),
2231: widebuf);
2232: TREE_TYPE (yylval.ttype) = int_array_type_node;
2233: }
2234: else
2235: {
2236: yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
2237: TREE_TYPE (yylval.ttype) = char_array_type_node;
2238: }
2239:
2240: *p++ = '"';
2241: *p = 0;
2242:
2243: value = STRING; break;
2244: }
2245:
2246: case '+':
2247: case '-':
2248: case '&':
2249: case '|':
2250: case '<':
2251: case '>':
2252: case '*':
2253: case '/':
2254: case '%':
2255: case '^':
2256: case '!':
2257: case '=':
2258: {
2259: register int c1;
2260:
2261: combine:
2262:
2263: switch (c)
2264: {
2265: case '+':
2266: yylval.code = PLUS_EXPR; break;
2267: case '-':
2268: yylval.code = MINUS_EXPR; break;
2269: case '&':
2270: yylval.code = BIT_AND_EXPR; break;
2271: case '|':
2272: yylval.code = BIT_IOR_EXPR; break;
2273: case '*':
2274: yylval.code = MULT_EXPR; break;
2275: case '/':
2276: yylval.code = TRUNC_DIV_EXPR; break;
2277: case '%':
2278: yylval.code = TRUNC_MOD_EXPR; break;
2279: case '^':
2280: yylval.code = BIT_XOR_EXPR; break;
2281: case LSHIFT:
2282: yylval.code = LSHIFT_EXPR; break;
2283: case RSHIFT:
2284: yylval.code = RSHIFT_EXPR; break;
2285: case '<':
2286: yylval.code = LT_EXPR; break;
2287: case '>':
2288: yylval.code = GT_EXPR; break;
2289: }
2290:
2291: token_buffer[1] = c1 = getc (finput);
2292: token_buffer[2] = 0;
2293:
2294: if (c1 == '=')
2295: {
2296: switch (c)
2297: {
2298: case '<':
2299: value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
2300: case '>':
2301: value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
2302: case '!':
2303: value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
2304: case '=':
2305: value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
2306: }
2307: value = ASSIGN; goto done;
2308: }
2309: else if (c == c1)
2310: switch (c)
2311: {
2312: case '+':
2313: value = PLUSPLUS; goto done;
2314: case '-':
2315: value = MINUSMINUS; goto done;
2316: case '&':
2317: value = ANDAND; goto done;
2318: case '|':
2319: value = OROR; goto done;
2320: case '<':
2321: c = LSHIFT;
2322: goto combine;
2323: case '>':
2324: c = RSHIFT;
2325: goto combine;
2326: }
2327: else if ((c == '-') && (c1 == '>'))
2328: { value = POINTSAT; goto done; }
2329: ungetc (c1, finput);
2330: token_buffer[1] = 0;
2331:
2332: if ((c == '<') || (c == '>'))
2333: value = ARITHCOMPARE;
2334: else value = c;
2335: goto done;
2336: }
2337:
2338: default:
2339: value = c;
2340: }
2341:
2342: done:
2343: /* yylloc.last_line = lineno; */
2344:
2345: return value;
2346: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.