glr2.cc: prefer unnamed namespace to 'static'
[bison.git] / src / scan-code.l
blobfced37d2d46ea6781386cdfe113e5bf24e1cecb6
1 /* Bison Action Scanner                             -*- C -*-
3    Copyright (C) 2006-2015, 2018-2021 Free Software Foundation, Inc.
5    This file is part of Bison, the GNU Compiler Compiler.
7    This program is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
20 %option debug nodefault noinput nounput noyywrap never-interactive
21 %option prefix="code_" outfile="lex.yy.c"
24 #include <c-ctype.h>
25 #include <get-errno.h>
26 #include <quote.h>
28 #include "src/complain.h"
29 #include "src/getargs.h"
30 #include "src/muscle-tab.h"
31 #include "src/reader.h"
32 #include "src/scan-code.h"
33 #include "src/symlist.h"
35 #define FLEX_PREFIX(Id) code_ ## Id
36 #include "src/flex-scanner.h"
38 /* Work around a bug in flex 2.5.31.  See Debian bug 333231
39    <https://bugs.debian.org/333231>.  */
40 #undef code_wrap
41 #define code_wrap() 1
43 struct obstack *obstack_for_actions = &obstack_for_string;
45 /* The current calling start condition: SC_RULE_ACTION or
46    SC_SYMBOL_ACTION. */
47 # define YY_DECL static char *code_lex (code_props *self, int sc_context)
48 YY_DECL;
50 #define YY_USER_ACTION  location_compute (loc, &loc->end, yytext, yyleng);
52 static char *fetch_type_name (char *cp, char const **type_name,
53                               const location *dollar_loc);
55 static void handle_action_dollar (symbol_list *rule, char *cp,
56                                   const location *dollar_loc);
57 static void handle_action_at (symbol_list *rule, char *cp,
58                               const location *at_loc);
60 /* A string to be pushed to obstack after dollar/at has been handled. */
61 static char *ref_tail_fields;
63 static location current_loc;
64 static location *loc = &current_loc;
66 /* A string representing the most recent translation.  */
67 static char *last_string;
69 /* True if an untyped $$ or $n was seen.  */
70 static bool untyped_var_seen;
73  /* C and C++ comments in code. */
74 %x SC_COMMENT SC_LINE_COMMENT
75  /* Strings and characters in code. */
76 %x SC_STRING SC_CHARACTER
77  /* Whether in a rule or symbol action.  Specifies the translation
78     of $ and @.  */
79 %x SC_RULE_ACTION SC_SYMBOL_ACTION
82 /* POSIX says that a tag must be both an id and a C union member, but
83    historically almost any character is allowed in a tag.  We disallow
84    NUL and newline, as this simplifies our implementation.  We allow
85    "->" as a means to dereference a pointer.  */
86 tag      ([^\0\n>]|->)*[^-]
88 /* Zero or more instances of backslash-newline.  Following GCC, allow
89    white space between the backslash and the newline.  */
90 splice   (\\[ \f\t\v]*\n)*
92 /* C style identifier. Must start with letter. Will be used for
93    named symbol references. Shall be kept synchronized with
94    scan-gram.l "letter" and "id". */
95 letter   [.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
96 id       {letter}({letter}|[-0-9])*
97 ref      -?[0-9]+|{id}|"["{id}"]"|"$"
102   /* This scanner is special: it is invoked only once, henceforth
103      is expected to return only once.  This initialization is
104      therefore done once per action to translate. */
105   aver (sc_context == SC_SYMBOL_ACTION
106         || sc_context == SC_RULE_ACTION
107         || sc_context == INITIAL);
108   BEGIN sc_context;
111   /*------------------------------------------------------------.
112   | Scanning a C comment.  The initial '/ *' is already eaten.  |
113   `------------------------------------------------------------*/
115 <SC_COMMENT>
117   "*"{splice}"/"  STRING_GROW (); BEGIN sc_context;
121   /*--------------------------------------------------------------.
122   | Scanning a line comment.  The initial '//' is already eaten.  |
123   `--------------------------------------------------------------*/
125 <SC_LINE_COMMENT>
127   "\n"           STRING_GROW (); BEGIN sc_context;
128   {splice}       STRING_GROW ();
132   /*--------------------------------------------.
133   | Scanning user-code characters and strings.  |
134   `--------------------------------------------*/
136 <SC_CHARACTER,SC_STRING>
138   {splice}|\\{splice}.  STRING_GROW ();
141 <SC_CHARACTER>
143   "'"           STRING_GROW (); BEGIN sc_context;
146 <SC_STRING>
148   "\""          STRING_GROW (); BEGIN sc_context;
152 <SC_RULE_ACTION,SC_SYMBOL_ACTION>
154   "'"              STRING_GROW (); BEGIN SC_CHARACTER;
155   "\""             STRING_GROW (); BEGIN SC_STRING;
156   "/"{splice}"*"   STRING_GROW (); BEGIN SC_COMMENT;
157   "/"{splice}"/"   STRING_GROW (); BEGIN SC_LINE_COMMENT;
159   [$@]  {
160     complain (loc, Wother, _("stray '%s'"), yytext);
161     obstack_escape (&obstack_for_string, yytext);
162   }
165 <SC_RULE_ACTION>
167   "$"("<"{tag}">")?{ref}  {
168     ref_tail_fields = NULL;
169     handle_action_dollar (self->rule, yytext, loc);
170     if (ref_tail_fields)
171       obstack_sgrow (&obstack_for_string, ref_tail_fields);
172   }
173   "@"{ref} {
174     ref_tail_fields = NULL;
175     handle_action_at (self->rule, yytext, loc);
176     if (ref_tail_fields)
177       obstack_sgrow (&obstack_for_string, ref_tail_fields);
178   }
181 <SC_SYMBOL_ACTION>
183   "$"("<"{tag}">")?"$" {
184     const char *type_name = NULL;
185     fetch_type_name (yytext + 1, &type_name, loc)[-1] = 0;
186     obstack_sgrow (&obstack_for_string, "]b4_dollar_dollar(");
187     obstack_quote (&obstack_for_string, type_name);
188     obstack_sgrow (&obstack_for_string, ")[");
189     self->is_value_used = true;
190   }
191   "@$" {
192     obstack_sgrow (&obstack_for_string, "]b4_at_dollar[");
193     muscle_percent_define_ensure("locations", *loc, true);
194   }
200   /* Escape M4 quoting characters in C code.  */
201   [$@\[\]]    obstack_escape (&obstack_for_string, yytext);
203   /* By default, grow the string obstack with the input.  */
204   .|\n        STRING_GROW ();
206   /* End of processing. */
207   <<EOF>>     STRING_FINISH (); return last_string;
212 static inline bool
213 is_dot_or_dash (char ch)
215   return ch == '.' || ch == '-';
218 static inline bool
219 contains_dot_or_dash (const char* p)
221   return !!strpbrk (p, ".-");
224 /* Defines a variant of a symbolic name resolution. */
225 typedef struct
227   /* Index in symbol list. */
228   int symbol_index;
230   /* Matched symbol id and loc. */
231   uniqstr id;
232   location loc;
234   /* Hiding named reference. */
235   named_ref* hidden_by;
237   /* Error flags. May contain zero (no errors) or
238      a combination of VARIANT_* values. */
239   unsigned err;
240 } variant;
242 /* Set when the variant refers to a symbol hidden
243    by an explicit symbol reference. */
244 #define VARIANT_HIDDEN (1 << 0)
246 /* Set when the variant refers to a symbol containing
247    dots or dashes. Will require explicit bracketing. */
248 #define VARIANT_BAD_BRACKETING (1 << 1)
250 /* Set when the variant refers to a symbol which is
251    not visible from current midrule. */
252 #define VARIANT_NOT_VISIBLE_FROM_MIDRULE (1 << 2)
254 static variant *variant_table = NULL;
255 static int variant_table_size = 0;
256 static int variant_count = 0;
258 static variant *
259 variant_table_grow (void)
261   ++variant_count;
262   if (variant_count > variant_table_size)
263     {
264       while (variant_count > variant_table_size)
265         variant_table_size = 2 * variant_table_size + 3;
266       variant_table = xnrealloc (variant_table, variant_table_size,
267                                  sizeof *variant_table);
268     }
269   return &variant_table[variant_count - 1];
272 static void
273 variant_table_free (void)
275   free (variant_table);
276   variant_table = NULL;
277   variant_table_size = variant_count = 0;
280 static char const *
281 find_prefix_end (char const *prefix, char const *cp, char const *end)
283   for (; *prefix && cp != end; ++prefix, ++cp)
284     if (*prefix != *cp)
285       return NULL;
287   return *prefix ? NULL : cp;
290 static variant *
291 variant_add (uniqstr id, location id_loc, int symbol_index,
292              char const *cp, char const *cp_end, bool explicit_bracketing)
294   char const *prefix_end = find_prefix_end (id, cp, cp_end);
295   if (prefix_end &&
296       (prefix_end == cp_end ||
297        (!explicit_bracketing && is_dot_or_dash (*prefix_end))))
298     {
299       variant *r = variant_table_grow ();
300       r->symbol_index = symbol_index;
301       r->id = id;
302       r->loc = id_loc;
303       r->hidden_by = NULL;
304       r->err = 0;
305       return r;
306     }
307   else
308     return NULL;
311 static const char *
312 get_at_spec(int symbol_index)
314   static char at_buf[20];
315   if (symbol_index == 0)
316     strcpy (at_buf, "$$");
317   else
318     snprintf (at_buf, sizeof at_buf, "$%u", symbol_index);
319   return at_buf;
322 static void
323 show_sub_message (warnings warning,
324                   const char* cp, bool explicit_bracketing,
325                   int midrule_rhs_index, char dollar_or_at,
326                   const variant *var)
328   const char *at_spec = get_at_spec (var->symbol_index);
330   if (var->err == 0)
331     subcomplain (&var->loc, warning,
332                  _("refers to: %c%s at %s"), dollar_or_at,
333                  var->id, at_spec);
334   else
335     {
336       const char *id;
337       location id_loc;
339       if (var->hidden_by)
340         {
341           id = var->hidden_by->id;
342           id_loc = var->hidden_by->loc;
343         }
344       else
345         {
346           id = var->id;
347           id_loc = var->loc;
348         }
350       const char *tail = explicit_bracketing ? "" : cp + strlen (var->id);
352       /* Create the explanation message. */
353       static struct obstack msg_buf;
354       obstack_init (&msg_buf);
356       obstack_printf (&msg_buf, _("possibly meant: %c"), dollar_or_at);
357       if (contains_dot_or_dash (id))
358         obstack_printf (&msg_buf, "[%s]", id);
359       else
360         obstack_sgrow (&msg_buf, id);
361       obstack_sgrow (&msg_buf, tail);
363       if (var->err & VARIANT_HIDDEN)
364         {
365           obstack_printf (&msg_buf, _(", hiding %c"), dollar_or_at);
366           if (contains_dot_or_dash (var->id))
367             obstack_printf (&msg_buf, "[%s]", var->id);
368           else
369             obstack_sgrow (&msg_buf, var->id);
370           obstack_sgrow (&msg_buf, tail);
371         }
373       obstack_printf (&msg_buf, _(" at %s"), at_spec);
375       if (var->err & VARIANT_NOT_VISIBLE_FROM_MIDRULE)
376         obstack_printf (&msg_buf,
377                         _(", cannot be accessed from midrule action at $%d"),
378                         midrule_rhs_index);
380       subcomplain (&id_loc, warning, "%s",
381                    obstack_finish0 (&msg_buf));
382       obstack_free (&msg_buf, 0);
383     }
386 static void
387 show_sub_messages (warnings warning,
388                    const char* cp, bool explicit_bracketing,
389                    int midrule_rhs_index, char dollar_or_at)
391   for (int i = 0; i < variant_count; ++i)
392     show_sub_message (warning | silent,
393                       cp, explicit_bracketing,
394                       midrule_rhs_index, dollar_or_at,
395                       &variant_table[i]);
398 /* Returned from "parse_ref" when the reference
399    is inappropriate. */
400 #define INVALID_REF (INT_MIN)
402 /* Returned from "parse_ref" when the reference
403    points to LHS ($$) of the current rule or midrule. */
404 #define LHS_REF (INT_MIN + 1)
406 /* Parse a positional reference in RULE.  */
407 static long
408 parse_positional_ref (char *cp, int rule_length,
409                       char *text, const location *text_loc)
411   long num = strtol (cp, &cp, 10);
412   if (1 - INT_MAX + rule_length <= num && num <= rule_length)
413     return num;
414   else
415     {
416       complain (text_loc, complaint, _("integer out of range: %s"),
417                 quote (text));
418       return INVALID_REF;
419     }
423 /* Parse named or positional reference. In case of positional
424    references, can return negative values for $-n "deep" stack
425    accesses. */
426 static long
427 parse_ref (char *cp, symbol_list *rule, int rule_length,
428            int midrule_rhs_index, char *text, const location *text_loc,
429            char dollar_or_at)
431   if ('$' == *cp)
432     return LHS_REF;
434   if (c_isdigit (*cp) || (*cp == '-' && c_isdigit (cp[1])))
435     return parse_positional_ref (cp, rule_length, text, text_loc);
437   bool const explicit_bracketing = *cp == '[';
439   if (explicit_bracketing)
440     ++cp;
441   else
442     ref_tail_fields = strpbrk (cp, ".-");
444   char const *cp_end = strchr (cp, explicit_bracketing ? ']' : '\0');
446   /* Add all relevant variants. */
447   {
448     int symbol_index;
449     symbol_list *l;
450     variant_count = 0;
451     for (symbol_index = 0, l = rule; !symbol_list_null (l);
452          ++symbol_index, l = l->next)
453       {
454         if (l->content_type != SYMLIST_SYMBOL)
455           continue;
457         variant *var
458           = variant_add (l->content.sym->tag, l->sym_loc,
459                          symbol_index, cp, cp_end, explicit_bracketing);
460         if (var && l->named_ref)
461           var->hidden_by = l->named_ref;
463         if (l->named_ref)
464           variant_add (l->named_ref->id, l->named_ref->loc,
465                        symbol_index, cp, cp_end, explicit_bracketing);
466       }
467   }
469   /* Check errors. */
470   int valid_variants = 0;
471   int valid_variant_index = 0;
472   for (int i = 0; i < variant_count; ++i)
473     {
474       variant *var = &variant_table[i];
475       int symbol_index = var->symbol_index;
477       /* Check visibility from midrule actions. */
478       if (midrule_rhs_index != 0
479           && (symbol_index == 0 || midrule_rhs_index < symbol_index))
480         var->err |= VARIANT_NOT_VISIBLE_FROM_MIDRULE;
482       /* Check correct bracketing. */
483       if (!explicit_bracketing && contains_dot_or_dash (var->id))
484         var->err |= VARIANT_BAD_BRACKETING;
486       /* Check using of hidden symbols. */
487       if (var->hidden_by)
488         var->err |= VARIANT_HIDDEN;
490       if (!var->err)
491         {
492           valid_variant_index = i;
493           ++valid_variants;
494         }
495     }
497   switch (valid_variants)
498     {
499     case 0:
500       {
501         int len = (explicit_bracketing || !ref_tail_fields) ?
502           cp_end - cp : ref_tail_fields - cp;
504         complain (text_loc, complaint,
505                   _("invalid reference: %s"), quote (text));
506         if (len == 0)
507           {
508             location sym_loc = *text_loc;
509             sym_loc.start.column += 1;
510             sym_loc.end = sym_loc.start;
511             subcomplain (&sym_loc, complaint,
512                          _("syntax error after '%c', expecting integer, "
513                          "letter, '_', '[', or '$'"),
514                          dollar_or_at);
515           }
516         else if (midrule_rhs_index)
517           subcomplain (&rule->rhs_loc, complaint,
518                        _("symbol not found in production before $%d: "
519                        "%.*s"),
520                        midrule_rhs_index, len, cp);
521         else
522           subcomplain (&rule->rhs_loc, complaint,
523                        _("symbol not found in production: %.*s"),
524                        len, cp);
526         if (variant_count > 0)
527           show_sub_messages (complaint,
528                              cp, explicit_bracketing, midrule_rhs_index,
529                              dollar_or_at);
530         return INVALID_REF;
531       }
532     case 1:
533       {
534         if (variant_count > 1)
535           {
536             complain (text_loc, Wother,
537                       _("misleading reference: %s"), quote (text));
538             show_sub_messages (Wother,
539                                cp, explicit_bracketing, midrule_rhs_index,
540                                dollar_or_at);
541           }
542         {
543           int symbol_index =
544             variant_table[valid_variant_index].symbol_index;
545           return (symbol_index == midrule_rhs_index) ? LHS_REF : symbol_index;
546         }
547       }
548     case 2:
549     default:
550       {
551         complain (text_loc, complaint,
552                   _("ambiguous reference: %s"), quote (text));
553         show_sub_messages (complaint,
554                            cp, explicit_bracketing, midrule_rhs_index,
555                            dollar_or_at);
556         return INVALID_REF;
557       }
558     }
561 /* Keeps track of the maximum number of semantic values to the left of
562    a handle (those referenced by $0, $-1, etc.) are required by the
563    semantic actions of this grammar. */
564 int max_left_semantic_context = 0;
567 /* If CP points to a typename (i.e., <.*?>), set TYPE_NAME to its
568    beginning (i.e., after the opening "<", and return the pointer
569    immediately after it.  */
571 static
572 char *
573 fetch_type_name (char *cp, char const **type_name,
574                  const location *dollar_loc)
576   if (*cp == '<')
577     {
578       *type_name = ++cp;
579       /* Series of non-'>' or "->".  */
580       while (*cp != '>' || cp[-1] == '-')
581         ++cp;
583       /* The '>' symbol will be later replaced by '\0'. Original
584          'text' is needed for error messages. */
585       ++cp;
586       if (untyped_var_seen)
587         complain (dollar_loc, complaint,
588                   _("explicit type given in untyped grammar"));
589       tag_seen = true;
590     }
591   return cp;
594 /*------------------------------------------------------------------.
595 | TEXT is pointing to a wannabee semantic value (i.e., a '$').      |
596 |                                                                   |
597 | Possible inputs: $[<TYPENAME>]($|INTEGER)                         |
598 |                                                                   |
599 | Output to OBSTACK_FOR_STRING a reference to this semantic value.  |
600 `------------------------------------------------------------------*/
602 static void
603 handle_action_dollar (symbol_list *rule, char *text, const location *dollar_loc)
605   symbol_list *effective_rule;
606   int effective_rule_length;
608   if (rule->midrule_parent_rule)
609     {
610       effective_rule = rule->midrule_parent_rule;
611       effective_rule_length = rule->midrule_parent_rhs_index - 1;
612     }
613   else
614     {
615       effective_rule = rule;
616       effective_rule_length = symbol_list_length (rule->next);
617     }
619   /* The type name if explicit, otherwise left null. */
620   char const *type_name = NULL;
621   char *cp = fetch_type_name (text + 1, &type_name, dollar_loc);
622   int n = parse_ref (cp, effective_rule, effective_rule_length,
623                      rule->midrule_parent_rhs_index, text, dollar_loc, '$');
624   /* End type_name.  Don't do it earlier: parse_ref depends on TEXT.  */
625   if (type_name)
626     cp[-1] = '\0';
628   switch (n)
629     {
630     case INVALID_REF:
631       break;
633     case LHS_REF:
634       {
635         symbol_list *sym = symbol_list_n_get (rule, 0);
636         if (!type_name
637             && !sym->content.sym->content->type_name)
638           {
639             if (union_seen || tag_seen)
640               {
641                 if (rule->midrule_parent_rule)
642                   complain (dollar_loc, complaint,
643                             _("$$ for the midrule at $%d of %s"
644                               " has no declared type"),
645                             rule->midrule_parent_rhs_index,
646                             quote (effective_rule->content.sym->tag));
647                 else
648                   complain (dollar_loc, complaint,
649                             _("$$ of %s has no declared type"),
650                             quote (rule->content.sym->tag));
651               }
652             else
653               untyped_var_seen = true;
654           }
656         obstack_printf (&obstack_for_string, "]b4_lhs_value(orig %d, ",
657                         sym->content.sym->content->number);
658         obstack_quote (&obstack_for_string, type_name);
659         obstack_sgrow (&obstack_for_string, ")[");
660         rule->action_props.is_value_used = true;
661       }
662       break;
664       /* Reference to a RHS symbol.  */
665     default:
666       {
667         if (max_left_semantic_context < 1 - n)
668           max_left_semantic_context = 1 - n;
669         symbol_list *sym = 0 < n ? symbol_list_n_get (effective_rule, n) : NULL;
670         if (!type_name
671             && (!sym || !sym->content.sym->content->type_name))
672           {
673             if (union_seen || tag_seen)
674               complain (dollar_loc, complaint,
675                         _("$%s of %s has no declared type"), cp,
676                         quote (effective_rule->content.sym->tag));
677             else
678               untyped_var_seen = true;
679           }
681         obstack_printf (&obstack_for_string,
682                         "]b4_rhs_value(%d, %d, ",
683                         effective_rule_length, n);
684         if (sym)
685           obstack_printf (&obstack_for_string, "%s%d, ",
686                           sym->content.sym->content->class == nterm_sym ? "orig " : "",
687                           sym->content.sym->content->number);
688         else
689           obstack_sgrow (&obstack_for_string, "[], ");
691         obstack_quote (&obstack_for_string, type_name);
692         obstack_sgrow (&obstack_for_string, ")[");
693         if (0 < n)
694           {
695             if (muscle_percent_define_ifdef ("api.value.automove")
696                 && sym->action_props.is_value_used)
697               complain (dollar_loc, Wother,
698                         _("multiple occurrences of $%d with api.value.automove"),
699                         n);
700             sym->action_props.is_value_used = true;
701           }
702       }
703       break;
704     }
708 /*------------------------------------------------------.
709 | TEXT is a location token (i.e., a '@...').  Output to |
710 | OBSTACK_FOR_STRING a reference to this location.      |
711 `------------------------------------------------------*/
713 static void
714 handle_action_at (symbol_list *rule, char *text, const location *at_loc)
716   symbol_list *effective_rule;
717   int effective_rule_length;
719   if (rule->midrule_parent_rule)
720     {
721       effective_rule = rule->midrule_parent_rule;
722       effective_rule_length = rule->midrule_parent_rhs_index - 1;
723     }
724   else
725     {
726       effective_rule = rule;
727       effective_rule_length = symbol_list_length (rule->next);
728     }
730   muscle_percent_define_ensure ("locations", *at_loc, true);
732   int n = parse_ref (text + 1, effective_rule, effective_rule_length,
733                      rule->midrule_parent_rhs_index, text, at_loc, '@');
734   switch (n)
735     {
736     case INVALID_REF:
737       break;
739     case LHS_REF:
740       obstack_sgrow (&obstack_for_string, "]b4_lhs_location[");
741       break;
743     default:
744       obstack_printf (&obstack_for_string, "]b4_rhs_location(%d, %d)[",
745                       effective_rule_length, n);
746       break;
747     }
751 /*-------------------------.
752 | Initialize the scanner.  |
753 `-------------------------*/
755 /* Translate the '$...' and '@...' in \a self, in the context \a
756    sc_context (SC_RULE_ACTION, SC_SYMBOL_ACTION, INITIAL).  */
758 static char const *
759 translate_action (code_props *self, int sc_context)
761   loc->start = loc->end = self->location.start;
762   yy_switch_to_buffer (yy_scan_string (self->code));
763   char *res = code_lex (self, sc_context);
764   yy_delete_buffer (YY_CURRENT_BUFFER);
765   return res;
768 /*------------------------------------------------------------------------.
769 | Implementation of the public interface as documented in "scan-code.h".  |
770 `------------------------------------------------------------------------*/
772 void
773 code_props_none_init (code_props *self)
775   *self = code_props_none;
778 code_props code_props_none = CODE_PROPS_NONE_INIT;
780 void
781 code_props_plain_init (code_props *self, char const *code,
782                        location code_loc)
784   code_props_none_init (self);
785   self->kind = CODE_PROPS_PLAIN;
786   self->code = code;
787   self->location = code_loc;
790 void
791 code_props_symbol_action_init (code_props *self, char const *code,
792                                location code_loc)
794   code_props_none_init (self);
795   self->kind = CODE_PROPS_SYMBOL_ACTION;
796   self->code = code;
797   self->location = code_loc;
800 void
801 code_props_rule_action_init (code_props *self, char const *code,
802                              location code_loc, symbol_list *rule,
803                              named_ref *name, uniqstr type,
804                              bool is_predicate)
806   code_props_none_init (self);
807   self->kind = CODE_PROPS_RULE_ACTION;
808   self->code = code;
809   self->location = code_loc;
810   self->rule = rule;
811   self->named_ref = name;
812   self->type = type;
813   self->is_predicate = is_predicate;
816 void
817 code_props_translate_code (code_props *self)
819   switch (self->kind)
820     {
821     case CODE_PROPS_NONE:
822       break;
823     case CODE_PROPS_PLAIN:
824       self->code = translate_action (self, INITIAL);
825       break;
826     case CODE_PROPS_SYMBOL_ACTION:
827       self->code = translate_action (self, SC_SYMBOL_ACTION);
828       break;
829     case CODE_PROPS_RULE_ACTION:
830       self->code = translate_action (self, SC_RULE_ACTION);
831       break;
832     }
835 void
836 code_scanner_last_string_free (void)
838   STRING_FREE ();
841 void
842 code_scanner_init (void)
844   obstack_init (&obstack_for_string);
845   yy_flex_debug = 0;
848 void
849 code_scanner_free (void)
851   obstack_free (&obstack_for_string, 0);
852   variant_table_free ();
854   /* Reclaim Flex's buffers.  */
855   yylex_destroy ();