OSDN Git Service

2010-10-08 Jerry DeLisle <jvdelisle@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / gengtype-parse.c
1 /* Process source files and output type information.
2    Copyright (C) 2006, 2007 Free Software Foundation, Inc.
3
4    This file is part of GCC.
5
6    GCC is free software; you can redistribute it and/or modify it under
7    the terms of the GNU General Public License as published by the Free
8    Software Foundation; either version 3, or (at your option) any later
9    version.
10
11    GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12    WARRANTY; without even the implied warranty of MERCHANTABILITY or
13    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14    for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with GCC; see the file COPYING3.  If not see
18    <http://www.gnu.org/licenses/>.  */
19
20 #include "bconfig.h"
21 #include "system.h"
22 #include "gengtype.h"
23
24 /* This is a simple recursive-descent parser which understands a subset of
25    the C type grammar.
26
27    Rule functions are suffixed _seq if they scan a sequence of items;
28    _opt if they may consume zero tokens; _seqopt if both are true.  The
29    "consume_" prefix indicates that a sequence of tokens is parsed for
30    syntactic correctness and then thrown away.  */
31
32 /* Simple one-token lookahead mechanism.  */
33
34 struct token
35 {
36   const char *value;
37   int code;
38   bool valid;
39 };
40 static struct token T;
41
42 /* Retrieve the code of the current token; if there is no current token,
43    get the next one from the lexer.  */
44 static inline int
45 token (void)
46 {
47   if (!T.valid)
48     {
49       T.code = yylex (&T.value);
50       T.valid = true;
51     }
52   return T.code;
53 }
54
55 /* Retrieve the value of the current token (if any) and mark it consumed.
56    The next call to token() will get another token from the lexer.  */
57 static inline const char *
58 advance (void)
59 {
60   T.valid = false;
61   return T.value;
62 }
63
64 /* Diagnostics.  */
65
66 /* This array is indexed by the token code minus CHAR_TOKEN_OFFSET.  */
67 static const char *const token_names[] = {
68   "GTY",
69   "typedef",
70   "extern",
71   "static",
72   "union",
73   "struct",
74   "enum",
75   "VEC",
76   "DEF_VEC_[OP]",
77   "DEF_VEC_I",
78   "DEF_VEC_ALLOC_[IOP]",
79   "...",
80   "ptr_alias",
81   "nested_ptr",
82   "a param<N>_is option",
83   "a number",
84   "a scalar type",
85   "an identifier",
86   "a string constant",
87   "a character constant",
88   "an array declarator",
89 };
90
91 /* This array is indexed by token code minus FIRST_TOKEN_WITH_VALUE.  */
92 static const char *const token_value_format[] = {
93   "%s",
94   "'%s'",
95   "'%s'",
96   "'%s'",
97   "'\"%s\"'",
98   "\"'%s'\"",
99   "'[%s]'",
100 };
101
102 /* Produce a printable representation for a token defined by CODE and
103    VALUE.  This sometimes returns pointers into malloc memory and
104    sometimes not, therefore it is unsafe to free the pointer it
105    returns, so that memory is leaked.  This does not matter, as this
106    function is only used for diagnostics, and in a successful run of
107    the program there will be none.  */
108 static const char *
109 print_token (int code, const char *value)
110 {
111   if (code < CHAR_TOKEN_OFFSET)
112     return xasprintf ("'%c'", code);
113   else if (code < FIRST_TOKEN_WITH_VALUE)
114     return xasprintf ("'%s'", token_names[code - CHAR_TOKEN_OFFSET]);
115   else if (!value)
116     return token_names[code - CHAR_TOKEN_OFFSET];       /* don't quote these */
117   else
118     return xasprintf (token_value_format[code - FIRST_TOKEN_WITH_VALUE],
119                       value);
120 }
121
122 /* Convenience wrapper around print_token which produces the printable
123    representation of the current token.  */
124 static inline const char *
125 print_cur_token (void)
126 {
127   return print_token (T.code, T.value);
128 }
129
130 /* Report a parse error on the current line, with diagnostic MSG.
131    Behaves as standard printf with respect to additional arguments and
132    format escapes.  */
133 static void ATTRIBUTE_PRINTF_1
134 parse_error (const char *msg, ...)
135 {
136   va_list ap;
137
138   fprintf (stderr, "%s:%d: parse error: ", lexer_line.file, lexer_line.line);
139
140   va_start (ap, msg);
141   vfprintf (stderr, msg, ap);
142   va_end (ap);
143
144   fputc ('\n', stderr);
145
146   hit_error = true;
147 }
148
149 /* If the next token does not have code T, report a parse error; otherwise
150    return the token's value.  */
151 static const char *
152 require (int t)
153 {
154   int u = token ();
155   const char *v = advance ();
156   if (u != t)
157     {
158       parse_error ("expected %s, have %s",
159                    print_token (t, 0), print_token (u, v));
160       return 0;
161     }
162   return v;
163 }
164
165 /* If the next token does not have one of the codes T1 or T2, report a
166    parse error; otherwise return the token's value.  */
167 static const char *
168 require2 (int t1, int t2)
169 {
170   int u = token ();
171   const char *v = advance ();
172   if (u != t1 && u != t2)
173     {
174       parse_error ("expected %s or %s, have %s",
175                    print_token (t1, 0), print_token (t2, 0),
176                    print_token (u, v));
177       return 0;
178     }
179   return v;
180 }
181
182 /* Near-terminals.  */
183
184 /* C-style string constant concatenation: STRING+
185    Bare STRING should appear nowhere else in this file.  */
186 static const char *
187 string_seq (void)
188 {
189   const char *s1, *s2;
190   size_t l1, l2;
191   char *buf;
192
193   s1 = require (STRING);
194   if (s1 == 0)
195     return "";
196   while (token () == STRING)
197     {
198       s2 = advance ();
199
200       l1 = strlen (s1);
201       l2 = strlen (s2);
202       buf = XRESIZEVEC (char, CONST_CAST (char *, s1), l1 + l2 + 1);
203       memcpy (buf + l1, s2, l2 + 1);
204       XDELETE (CONST_CAST (char *, s2));
205       s1 = buf;
206     }
207   return s1;
208 }
209
210 /* typedef_name: either an ID, or VEC(x,y) which is translated to VEC_x_y.
211    Use only where VEC(x,y) is legitimate, i.e. in positions where a
212    typedef name may appear.  */
213 static const char *
214 typedef_name (void)
215 {
216   if (token () == VEC_TOKEN)
217     {
218       const char *c1, *c2, *r;
219       advance ();
220       require ('(');
221       c1 = require2 (ID, SCALAR);
222       require (',');
223       c2 = require (ID);
224       require (')');
225       r = concat ("VEC_", c1, "_", c2, (char *) 0);
226       free (CONST_CAST (char *, c1));
227       free (CONST_CAST (char *, c2));
228       return r;
229     }
230   else
231     return require (ID);
232 }
233
234 /* Absorb a sequence of tokens delimited by balanced ()[]{}.  */
235 static void
236 consume_balanced (int opener, int closer)
237 {
238   require (opener);
239   for (;;)
240     switch (token ())
241       {
242       default:
243         advance ();
244         break;
245       case '(':
246         consume_balanced ('(', ')');
247         break;
248       case '[':
249         consume_balanced ('[', ']');
250         break;
251       case '{':
252         consume_balanced ('{', '}');
253         break;
254
255       case '}':
256       case ']':
257       case ')':
258         if (token () != closer)
259           parse_error ("unbalanced delimiters - expected '%c', have '%c'",
260                        closer, token ());
261       advance ();
262       return;
263
264       case EOF_TOKEN:
265         parse_error ("unexpected end of file within %c%c-delimited construct",
266                      opener, closer);
267         return;
268       }
269 }
270
271 /* Absorb a sequence of tokens, possibly including ()[]{}-delimited
272    expressions, until we encounter a semicolon outside any such
273    delimiters; absorb that too.  If IMMEDIATE is true, it is an error
274    if the semicolon is not the first token encountered.  */
275 static void
276 consume_until_semi (bool immediate)
277 {
278   if (immediate && token () != ';')
279     require (';');
280   for (;;)
281     switch (token ())
282       {
283       case ';':
284         advance ();
285         return;
286       default:
287         advance ();
288         break;
289
290       case '(':
291         consume_balanced ('(', ')');
292         break;
293       case '[':
294         consume_balanced ('[', ']');
295         break;
296       case '{':
297         consume_balanced ('{', '}');
298         break;
299
300       case '}':
301       case ']':
302       case ')':
303         parse_error ("unmatched '%c' while scanning for ';'", token ());
304       return;
305
306       case EOF_TOKEN:
307         parse_error ("unexpected end of file while scanning for ';'");
308         return;
309       }
310 }
311
312 /* Absorb a sequence of tokens, possibly including ()[]{}-delimited
313    expressions, until we encounter a comma or semicolon outside any
314    such delimiters; absorb that too.  If IMMEDIATE is true, it is an
315    error if the comma or semicolon is not the first token encountered.
316    Returns true if the loop ended with a comma.  */
317 static bool
318 consume_until_comma_or_semi (bool immediate)
319 {
320   if (immediate && token () != ',' && token () != ';')
321     require2 (',', ';');
322   for (;;)
323     switch (token ())
324       {
325       case ',':
326         advance ();
327         return true;
328       case ';':
329         advance ();
330         return false;
331       default:
332         advance ();
333         break;
334
335       case '(':
336         consume_balanced ('(', ')');
337         break;
338       case '[':
339         consume_balanced ('[', ']');
340         break;
341       case '{':
342         consume_balanced ('{', '}');
343         break;
344
345       case '}':
346       case ']':
347       case ')':
348         parse_error ("unmatched '%s' while scanning for ',' or ';'",
349                      print_cur_token ());
350       return false;
351
352       case EOF_TOKEN:
353         parse_error ("unexpected end of file while scanning for ',' or ';'");
354         return false;
355       }
356 }
357 \f
358
359 /* GTY(()) option handling.  */
360 static type_p type (options_p *optsp, bool nested);
361
362 /* Optional parenthesized string: ('(' string_seq ')')? */
363 static options_p
364 str_optvalue_opt (options_p prev)
365 {
366   const char *name = advance ();
367   const char *value = "";
368   if (token () == '(')
369     {
370       advance ();
371       value = string_seq ();
372       require (')');
373     }
374   return create_option (prev, name, value);
375 }
376
377 /* absdecl: type '*'*
378    -- a vague approximation to what the C standard calls an abstract
379    declarator.  The only kinds that are actually used are those that
380    are just a bare type and those that have trailing pointer-stars.
381    Further kinds should be implemented if and when they become
382    necessary.  Used only within GTY(()) option values, therefore
383    further GTY(()) tags within the type are invalid.  Note that the
384    return value has already been run through adjust_field_type.  */
385 static type_p
386 absdecl (void)
387 {
388   type_p ty;
389   options_p opts;
390
391   ty = type (&opts, true);
392   while (token () == '*')
393     {
394       ty = create_pointer (ty);
395       advance ();
396     }
397
398   if (opts)
399     parse_error ("nested GTY(()) options are invalid");
400
401   return adjust_field_type (ty, 0);
402 }
403
404 /* Type-option: '(' absdecl ')' */
405 static options_p
406 type_optvalue (options_p prev, const char *name)
407 {
408   type_p ty;
409   require ('(');
410   ty = absdecl ();
411   require (')');
412   return create_option (prev, name, ty);
413 }
414
415 /* Nested pointer data: '(' type '*'* ',' string_seq ',' string_seq ')' */
416 static options_p
417 nestedptr_optvalue (options_p prev)
418 {
419   type_p ty;
420   const char *from, *to;
421
422   require ('(');
423   ty = absdecl ();
424   require (',');
425   to = string_seq ();
426   require (',');
427   from = string_seq ();
428   require (')');
429
430   return create_nested_ptr_option (prev, ty, to, from);
431 }
432
433 /* One GTY(()) option:
434    ID str_optvalue_opt
435    | PTR_ALIAS type_optvalue
436    | PARAM_IS type_optvalue
437    | NESTED_PTR nestedptr_optvalue
438 */
439 static options_p
440 option (options_p prev)
441 {
442   switch (token ())
443     {
444     case ID:
445       return str_optvalue_opt (prev);
446
447     case PTR_ALIAS:
448       advance ();
449       return type_optvalue (prev, "ptr_alias");
450
451     case PARAM_IS:
452       return type_optvalue (prev, advance ());
453
454     case NESTED_PTR:
455       advance ();
456       return nestedptr_optvalue (prev);
457
458     default:
459       parse_error ("expected an option keyword, have %s", print_cur_token ());
460       advance ();
461       return create_option (prev, "", "");
462     }
463 }
464
465 /* One comma-separated list of options.  */
466 static options_p
467 option_seq (void)
468 {
469   options_p o;
470
471   o = option (0);
472   while (token () == ',')
473     {
474       advance ();
475       o = option (o);
476     }
477   return o;
478 }
479
480 /* GTY marker: 'GTY' '(' '(' option_seq? ')' ')' */
481 static options_p
482 gtymarker (void)
483 {
484   options_p result = 0;
485   require (GTY_TOKEN);
486   require ('(');
487   require ('(');
488   if (token () != ')')
489     result = option_seq ();
490   require (')');
491   require (')');
492   return result;
493 }
494
495 /* Optional GTY marker.  */
496 static options_p
497 gtymarker_opt (void)
498 {
499   if (token () != GTY_TOKEN)
500     return 0;
501   return gtymarker ();
502 }
503 \f
504 /* Declarators. The logic here is largely lifted from c-parser.c.
505    Note that we do not have to process abstract declarators, which can
506    appear only in parameter type lists or casts (but see absdecl,
507    above).  Also, type qualifiers are thrown out in gengtype-lex.l so
508    we don't have to do it.  */
509
510 /* array_and_function_declarators_opt:
511    \epsilon
512    array_and_function_declarators_opt ARRAY
513    array_and_function_declarators_opt '(' ... ')'
514
515    where '...' indicates stuff we ignore except insofar as grouping
516    symbols ()[]{} must balance.
517
518    Subroutine of direct_declarator - do not use elsewhere. */
519
520 static type_p
521 array_and_function_declarators_opt (type_p ty)
522 {
523   if (token () == ARRAY)
524     {
525       const char *array = advance ();
526       return create_array (array_and_function_declarators_opt (ty), array);
527     }
528   else if (token () == '(')
529     {
530       /* We don't need exact types for functions.  */
531       consume_balanced ('(', ')');
532       array_and_function_declarators_opt (ty);
533       return create_scalar_type ("function type");
534     }
535   else
536     return ty;
537 }
538
539 static type_p inner_declarator (type_p, const char **, options_p *);
540
541 /* direct_declarator:
542    '(' inner_declarator ')'
543    gtymarker_opt ID array_and_function_declarators_opt
544
545    Subroutine of declarator, mutually recursive with inner_declarator;
546    do not use elsewhere.  */
547 static type_p
548 direct_declarator (type_p ty, const char **namep, options_p *optsp)
549 {
550   /* The first token in a direct-declarator must be an ID, a
551      GTY marker, or an open parenthesis.  */
552   switch (token ())
553     {
554     case GTY_TOKEN:
555       *optsp = gtymarker ();
556       /* fall through */
557     case ID:
558       *namep = require (ID);
559       break;
560
561     case '(':
562       advance ();
563       ty = inner_declarator (ty, namep, optsp);
564       require (')');
565       break;
566
567     default:
568       parse_error ("expected '(', 'GTY', or an identifier, have %s",
569                    print_cur_token ());
570       /* Do _not_ advance if what we have is a close squiggle brace, as
571          we will get much better error recovery that way.  */
572       if (token () != '}')
573         advance ();
574       return 0;
575     }
576   return array_and_function_declarators_opt (ty);
577 }
578
579 /* The difference between inner_declarator and declarator is in the
580    handling of stars.  Consider this declaration:
581
582    char * (*pfc) (void)
583
584    It declares a pointer to a function that takes no arguments and
585    returns a char*.  To construct the correct type for this
586    declaration, the star outside the parentheses must be processed
587    _before_ the function type, the star inside the parentheses must
588    be processed _after_ the function type.  To accomplish this,
589    declarator() creates pointers before recursing (it is actually
590    coded as a while loop), whereas inner_declarator() recurses before
591    creating pointers.  */
592
593 /* inner_declarator:
594    '*' inner_declarator
595    direct_declarator
596
597    Mutually recursive subroutine of direct_declarator; do not use
598    elsewhere.  */
599
600 static type_p
601 inner_declarator (type_p ty, const char **namep, options_p *optsp)
602 {
603   if (token () == '*')
604     {
605       type_p inner;
606       advance ();
607       inner = inner_declarator (ty, namep, optsp);
608       if (inner == 0)
609         return 0;
610       else
611         return create_pointer (ty);
612     }
613   else
614     return direct_declarator (ty, namep, optsp);
615 }
616
617 /* declarator: '*'+ direct_declarator
618
619    This is the sole public interface to this part of the grammar.
620    Arguments are the type known so far, a pointer to where the name
621    may be stored, and a pointer to where GTY options may be stored.
622    Returns the final type. */
623
624 static type_p
625 declarator (type_p ty, const char **namep, options_p *optsp)
626 {
627   *namep = 0;
628   *optsp = 0;
629   while (token () == '*')
630     {
631       advance ();
632       ty = create_pointer (ty);
633     }
634   return direct_declarator (ty, namep, optsp);
635 }
636 \f
637 /* Types and declarations.  */
638
639 /* Structure field(s) declaration:
640    (
641    type bitfield ';'
642    | type declarator bitfield? ( ',' declarator bitfield? )+ ';'
643    )+
644
645    Knows that such declarations must end with a close brace (or,
646    erroneously, at EOF).
647 */
648 static pair_p
649 struct_field_seq (void)
650 {
651   pair_p f = 0;
652   type_p ty, dty;
653   options_p opts, dopts;
654   const char *name;
655   bool another;
656
657   do
658     {
659       ty = type (&opts, true);
660       /* Another piece of the IFCVT_EXTRA_FIELDS special case, see type().  */
661       if (!ty && token () == '}')
662         break;
663
664       if (!ty || token () == ':')
665         {
666           consume_until_semi (false);
667           continue;
668         }
669
670       do
671         {
672           dty = declarator (ty, &name, &dopts);
673           /* There could be any number of weird things after the declarator,
674              notably bitfield declarations and __attribute__s.  If this
675              function returns true, the last thing was a comma, so we have
676              more than one declarator paired with the current type.  */
677           another = consume_until_comma_or_semi (false);
678
679           if (!dty)
680             continue;
681
682           if (opts && dopts)
683             parse_error ("two GTY(()) options for field %s", name);
684           if (opts && !dopts)
685             dopts = opts;
686
687           f = create_field_at (f, dty, name, dopts, &lexer_line);
688         }
689       while (another);
690     }
691   while (token () != '}' && token () != EOF_TOKEN);
692   return nreverse_pairs (f);
693 }
694
695 /* This is called type(), but what it parses (sort of) is what C calls
696    declaration-specifiers and specifier-qualifier-list:
697
698    SCALAR
699    | ID     // typedef
700    | (STRUCT|UNION) ID? gtymarker? ( '{' gtymarker? struct_field_seq '}' )?
701    | ENUM ID ( '{' ... '}' )?
702
703    Returns a partial type; under some conditions (notably
704    "struct foo GTY((...)) thing;") it may write an options
705    structure to *OPTSP.
706 */
707 static type_p
708 type (options_p *optsp, bool nested)
709 {
710   const char *s;
711   *optsp = 0;
712   switch (token ())
713     {
714     case SCALAR:
715       s = advance ();
716       return create_scalar_type (s);
717
718     case ID:
719     case VEC_TOKEN:
720       s = typedef_name ();
721       return resolve_typedef (s, &lexer_line);
722
723     case STRUCT:
724     case UNION:
725       {
726         options_p opts = 0;
727         /* GTY annotations follow attribute syntax
728            GTY_BEFORE_ID is for union/struct declarations
729            GTY_AFTER_ID is for variable declarations.  */
730         enum
731         {
732           NO_GTY,
733           GTY_BEFORE_ID,
734           GTY_AFTER_ID
735         } is_gty = NO_GTY;
736         bool is_union = (token () == UNION);
737         advance ();
738
739         /* Top-level structures that are not explicitly tagged GTY(())
740            are treated as mere forward declarations.  This is because
741            there are a lot of structures that we don't need to know
742            about, and some of those have weird macro stuff in them
743            that we can't handle.  */
744         if (nested || token () == GTY_TOKEN)
745           {
746             is_gty = GTY_BEFORE_ID;
747             opts = gtymarker_opt ();
748           }
749
750         if (token () == ID)
751           s = advance ();
752         else
753           s = xasprintf ("anonymous:%s:%d", lexer_line.file, lexer_line.line);
754
755         /* Unfortunately above GTY_TOKEN check does not capture the
756            typedef struct_type GTY case.  */
757         if (token () == GTY_TOKEN)
758           {
759             is_gty = GTY_AFTER_ID;
760             opts = gtymarker_opt ();
761           }
762
763         if (is_gty)
764           {
765             if (token () == '{')
766               {
767                 pair_p fields;
768
769                 if (is_gty == GTY_AFTER_ID)
770                   parse_error ("GTY must be specified before identifier");
771
772                 advance ();
773                 fields = struct_field_seq ();
774                 require ('}');
775                 return new_structure (s, is_union, &lexer_line, fields, opts);
776               }
777           }
778         else if (token () == '{')
779           consume_balanced ('{', '}');
780         if (opts)
781           *optsp = opts;
782         return find_structure (s, is_union);
783       }
784
785     case ENUM:
786       advance ();
787       if (token () == ID)
788         s = advance ();
789       else
790         s = xasprintf ("anonymous:%s:%d", lexer_line.file, lexer_line.line);
791
792       if (token () == '{')
793         consume_balanced ('{', '}');
794       return create_scalar_type (s);
795
796     default:
797       parse_error ("expected a type specifier, have %s", print_cur_token ());
798       advance ();
799       return create_scalar_type ("erroneous type");
800     }
801 }
802 \f
803 /* Top level constructs.  */
804
805 /* Dispatch declarations beginning with 'typedef'.  */
806
807 static void
808 typedef_decl (void)
809 {
810   type_p ty, dty;
811   const char *name;
812   options_p opts;
813   bool another;
814
815   gcc_assert (token () == TYPEDEF);
816   advance ();
817
818   ty = type (&opts, false);
819   if (!ty)
820     return;
821   if (opts)
822     parse_error ("GTY((...)) cannot be applied to a typedef");
823   do
824     {
825       dty = declarator (ty, &name, &opts);
826       if (opts)
827         parse_error ("GTY((...)) cannot be applied to a typedef");
828
829       /* Yet another place where we could have junk (notably attributes)
830          after the declarator.  */
831       another = consume_until_comma_or_semi (false);
832       if (dty)
833         do_typedef (name, dty, &lexer_line);
834     }
835   while (another);
836 }
837
838 /* Structure definition: type() does all the work.  */
839
840 static void
841 struct_or_union (void)
842 {
843   options_p dummy;
844   type (&dummy, false);
845   /* There may be junk after the type: notably, we cannot currently
846      distinguish 'struct foo *function(prototype);' from 'struct foo;'
847      ...  we could call declarator(), but it's a waste of time at
848      present.  Instead, just eat whatever token is currently lookahead
849      and go back to lexical skipping mode. */
850   advance ();
851 }
852
853 /* GC root declaration:
854    (extern|static) gtymarker? type ID array_declarators_opt (';'|'=')
855    If the gtymarker is not present, we ignore the rest of the declaration.  */
856 static void
857 extern_or_static (void)
858 {
859   options_p opts, opts2, dopts;
860   type_p ty, dty;
861   const char *name;
862   require2 (EXTERN, STATIC);
863
864   if (token () != GTY_TOKEN)
865     {
866       advance ();
867       return;
868     }
869
870   opts = gtymarker ();
871   ty = type (&opts2, true);     /* if we get here, it's got a GTY(()) */
872   dty = declarator (ty, &name, &dopts);
873
874   if ((opts && dopts) || (opts && opts2) || (opts2 && dopts))
875     parse_error ("GTY((...)) specified more than once for %s", name);
876   else if (opts2)
877     opts = opts2;
878   else if (dopts)
879     opts = dopts;
880
881   if (dty)
882     {
883       note_variable (name, adjust_field_type (dty, opts), opts, &lexer_line);
884       require2 (';', '=');
885     }
886 }
887
888 /* Definition of a generic VEC structure:
889
890    'DEF_VEC_[IPO]' '(' id ')' ';'
891
892    Scalar VECs require slightly different treatment than otherwise -
893    that's handled in note_def_vec, we just pass it along.*/
894 static void
895 def_vec (void)
896 {
897   bool is_scalar = (token () == DEFVEC_I);
898   const char *type;
899
900   require2 (DEFVEC_OP, DEFVEC_I);
901   require ('(');
902   type = require2 (ID, SCALAR);
903   require (')');
904   require (';');
905
906   if (!type)
907     return;
908
909   note_def_vec (type, is_scalar, &lexer_line);
910   note_def_vec_alloc (type, "none", &lexer_line);
911 }
912
913 /* Definition of an allocation strategy for a VEC structure:
914
915    'DEF_VEC_ALLOC_[IPO]' '(' id ',' id ')' ';'
916
917    For purposes of gengtype, this just declares a wrapper structure.  */
918 static void
919 def_vec_alloc (void)
920 {
921   const char *type, *astrat;
922
923   require (DEFVEC_ALLOC);
924   require ('(');
925   type = require2 (ID, SCALAR);
926   require (',');
927   astrat = require (ID);
928   require (')');
929   require (';');
930
931   if (!type || !astrat)
932     return;
933
934   note_def_vec_alloc (type, astrat, &lexer_line);
935 }
936
937 /* Parse the file FNAME for GC-relevant declarations and definitions.
938    This is the only entry point to this file.  */
939 void
940 parse_file (const char *fname)
941 {
942   yybegin (fname);
943   for (;;)
944     {
945       switch (token ())
946         {
947         case EXTERN:
948         case STATIC:
949           extern_or_static ();
950           break;
951
952         case STRUCT:
953         case UNION:
954           struct_or_union ();
955           break;
956
957         case TYPEDEF:
958           typedef_decl ();
959           break;
960
961         case DEFVEC_OP:
962         case DEFVEC_I:
963           def_vec ();
964           break;
965
966         case DEFVEC_ALLOC:
967           def_vec_alloc ();
968           break;
969
970         case EOF_TOKEN:
971           goto eof;
972
973         default:
974           parse_error ("unexpected top level token, %s", print_cur_token ());
975           goto eof;
976         }
977       lexer_toplevel_done = 1;
978     }
979
980  eof:
981   advance ();
982   yyend ();
983 }