]> git.saurik.com Git - bison.git/blob - src/scan-code.l
scan-code: avoid compiler warnings
[bison.git] / src / scan-code.l
1 /* Bison Action Scanner -*- C -*-
2
3 Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
4
5 This file is part of Bison, the GNU Compiler Compiler.
6
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.
11
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.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 %option debug nodefault nounput noyywrap never-interactive
21 %option prefix="code_" outfile="lex.yy.c"
22
23 %{
24 /* Work around a bug in flex 2.5.31. See Debian bug 333231
25 <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
26 #undef code_wrap
27 #define code_wrap() 1
28
29 #define FLEX_PREFIX(Id) code_ ## Id
30 #include "flex-scanner.h"
31
32 #include "complain.h"
33 #include "reader.h"
34 #include "getargs.h"
35 #include <get-errno.h>
36 #include <quote.h>
37
38 #include "scan-code.h"
39 #include "symlist.h"
40
41 /* The current calling start condition: SC_RULE_ACTION or
42 SC_SYMBOL_ACTION. */
43 # define YY_DECL static char *code_lex (code_props *self, int sc_context)
44 YY_DECL;
45
46 #define YY_USER_ACTION location_compute (loc, &loc->end, yytext, yyleng);
47
48 static void handle_action_dollar (symbol_list *rule, char *cp,
49 location dollar_loc);
50 static void handle_action_at (symbol_list *rule, char *cp, location at_loc);
51
52 /* A string to be pushed to obstack after dollar/at has been handled */
53 static char *ref_tail_fields;
54
55 static location the_location;
56 static location *loc = &the_location;
57
58 /* A string representing the most recent translation. */
59 static char *last_string;
60
61 /* True if an untyped $$ or $n was seen. */
62 static bool untyped_var_seen;
63
64 %}
65 /* C and C++ comments in code. */
66 %x SC_COMMENT SC_LINE_COMMENT
67 /* Strings and characters in code. */
68 %x SC_STRING SC_CHARACTER
69 /* Whether in a rule or symbol action. Specifies the translation
70 of $ and @. */
71 %x SC_RULE_ACTION SC_SYMBOL_ACTION
72
73
74 /* POSIX says that a tag must be both an id and a C union member, but
75 historically almost any character is allowed in a tag. We disallow
76 NUL and newline, as this simplifies our implementation. */
77 tag [^\0\n>]+
78
79 /* Zero or more instances of backslash-newline. Following GCC, allow
80 white space between the backslash and the newline. */
81 splice (\\[ \f\t\v]*\n)*
82
83 /* C style identifier. Must start with letter. Will be used for
84 named symbol references. */
85 letter [-.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
86 id {letter}({letter}|[0-9])*
87 ref -?[0-9]+|{id}|"["{id}"]"|"$"
88
89 %%
90
91 %{
92 /* Nesting level of the current code in braces. */
93 int braces_level = 0;
94
95 /* Whether a semicolon is probably needed.
96 The heuristic is that a semicolon is not needed after `{', `}', `;',
97 or a C preprocessor directive, and that whitespaces and comments
98 do not affect this flag.
99 Note that `{' does not need a semicolon because of `{}'.
100 A semicolon may be needed before a cpp direcive, but don't bother. */
101 bool need_semicolon = false;
102
103 /* Whether in a C preprocessor directive. Don't use a start condition
104 for this because, at the end of strings and comments, we still need
105 to know whether we're in a directive. */
106 bool in_cpp = false;
107
108 /* This scanner is special: it is invoked only once, henceforth
109 is expected to return only once. This initialization is
110 therefore done once per action to translate. */
111 aver (sc_context == SC_SYMBOL_ACTION
112 || sc_context == SC_RULE_ACTION
113 || sc_context == INITIAL);
114 BEGIN sc_context;
115 %}
116
117 /*------------------------------------------------------------.
118 | Scanning a C comment. The initial `/ *' is already eaten. |
119 `------------------------------------------------------------*/
120
121 <SC_COMMENT>
122 {
123 "*"{splice}"/" STRING_GROW; BEGIN sc_context;
124 }
125
126
127 /*--------------------------------------------------------------.
128 | Scanning a line comment. The initial `//' is already eaten. |
129 `--------------------------------------------------------------*/
130
131 <SC_LINE_COMMENT>
132 {
133 "\n" STRING_GROW; BEGIN sc_context;
134 {splice} STRING_GROW;
135 }
136
137
138 /*--------------------------------------------.
139 | Scanning user-code characters and strings. |
140 `--------------------------------------------*/
141
142 <SC_CHARACTER,SC_STRING>
143 {
144 {splice}|\\{splice}. STRING_GROW;
145 }
146
147 <SC_CHARACTER>
148 {
149 "'" STRING_GROW; BEGIN sc_context;
150 }
151
152 <SC_STRING>
153 {
154 "\"" STRING_GROW; BEGIN sc_context;
155 }
156
157
158 <SC_RULE_ACTION,SC_SYMBOL_ACTION>{
159 "'" {
160 STRING_GROW;
161 BEGIN SC_CHARACTER;
162 need_semicolon = true;
163 }
164 "\"" {
165 STRING_GROW;
166 BEGIN SC_STRING;
167 need_semicolon = true;
168 }
169 "/"{splice}"*" {
170 STRING_GROW;
171 BEGIN SC_COMMENT;
172 }
173 "/"{splice}"/" {
174 STRING_GROW;
175 BEGIN SC_LINE_COMMENT;
176 }
177 }
178
179 <SC_RULE_ACTION>
180 {
181 "$"("<"{tag}">")?{ref} {
182 ref_tail_fields = 0;
183 handle_action_dollar (self->rule, yytext, *loc);
184 if (ref_tail_fields != NULL) {
185 obstack_sgrow (&obstack_for_string, ref_tail_fields);
186 }
187 need_semicolon = true;
188 }
189 "@"{ref} {
190 ref_tail_fields = 0;
191 handle_action_at (self->rule, yytext, *loc);
192 if (ref_tail_fields != NULL) {
193 obstack_sgrow (&obstack_for_string, ref_tail_fields);
194 }
195 need_semicolon = true;
196 }
197 "$" {
198 warn_at (*loc, _("stray `$'"));
199 obstack_sgrow (&obstack_for_string, "$][");
200 need_semicolon = true;
201 }
202 "@" {
203 warn_at (*loc, _("stray `@'"));
204 obstack_sgrow (&obstack_for_string, "@@");
205 need_semicolon = true;
206 }
207 "[" {
208 obstack_sgrow (&obstack_for_string, "@{");
209 need_semicolon = true;
210 }
211 "]" {
212 obstack_sgrow (&obstack_for_string, "@}");
213 need_semicolon = true;
214 }
215
216 ";" STRING_GROW; need_semicolon = false;
217 "{" STRING_GROW; ++braces_level; need_semicolon = false;
218 "}" {
219 bool outer_brace = --braces_level == 0;
220
221 /* As an undocumented Bison extension, append `;' before the last
222 brace in braced code, so that the user code can omit trailing
223 `;'. But do not append `;' if emulating Yacc, since Yacc does
224 not append one. */
225 if (outer_brace && !yacc_flag && language_prio == default_prio
226 && skeleton_prio == default_prio && need_semicolon && ! in_cpp)
227 {
228 warn_at (*loc, _("a `;' might be needed at the end of action code"));
229 warn_at (*loc, _("future versions of Bison will not add the `;'"));
230 obstack_1grow (&obstack_for_string, ';');
231 }
232
233 STRING_GROW;
234 need_semicolon = false;
235 }
236
237 /* Preprocessing directives should only be recognized at the beginning
238 of lines, allowing whitespace including comments, but in C/C++,
239 `#' can only be the start of preprocessor directives or within
240 `#define' directives anyway, so don't bother with begin of line. */
241 "#" STRING_GROW; in_cpp = true;
242
243 {splice} STRING_GROW;
244 [\n\r] STRING_GROW; if (in_cpp) in_cpp = need_semicolon = false;
245 [ \t\f] STRING_GROW;
246 . STRING_GROW; need_semicolon = true;
247 }
248
249 <SC_SYMBOL_ACTION>
250 {
251 "$$" {
252 obstack_sgrow (&obstack_for_string, "]b4_dollar_dollar[");
253 self->is_value_used = true;
254 }
255 "@$" {
256 obstack_sgrow (&obstack_for_string, "]b4_at_dollar[");
257 locations_flag = true;
258 }
259 }
260
261
262 /*-----------------------------------------.
263 | Escape M4 quoting characters in C code. |
264 `-----------------------------------------*/
265
266 <*>
267 {
268 \$ obstack_sgrow (&obstack_for_string, "$][");
269 \@ obstack_sgrow (&obstack_for_string, "@@");
270 \[ obstack_sgrow (&obstack_for_string, "@{");
271 \] obstack_sgrow (&obstack_for_string, "@}");
272 }
273
274 /*-----------------------------------------------------.
275 | By default, grow the string obstack with the input. |
276 `-----------------------------------------------------*/
277
278 <*>.|\n STRING_GROW;
279
280 /* End of processing. */
281 <*><<EOF>> {
282 STRING_FINISH;
283 return last_string;
284 }
285
286 %%
287
288
289 static inline bool
290 symbol_list_null(symbol_list *l)
291 {
292 if (l && !(l->content_type == SYMLIST_SYMBOL && l->content.sym == NULL))
293 return false;
294 else
295 return true;
296 }
297
298 static inline bool
299 is_dot_or_dash(char ch)
300 {
301 return ch == '.' || ch == '-';
302 }
303
304 static inline bool
305 is_digit(char ch)
306 {
307 return '0' <= ch && ch <= '9';
308 }
309
310 static inline bool
311 contains_dot_or_dash(const char* str)
312 {
313 return strpbrk(str, ".-") != NULL;
314 }
315
316 #define VARIANT_HIDDEN (1 << 0)
317 #define VARIANT_BAD_BRACKETING (1 << 1)
318 #define VARIANT_NOT_VISIBLE_FROM_MIDRULE (1 << 2)
319
320 typedef struct
321 {
322 /* Index in symbol list. */
323 long int ind;
324
325 /* Matched symbol id and loc. */
326 uniqstr id;
327 location loc;
328
329 /* Hidding named reference. */
330 named_ref* hidden_by;
331
332 /* Error flags. */
333 unsigned err;
334 } variant;
335
336 static variant *variant_table = 0;
337 static unsigned variant_table_size = 0;
338 static unsigned variant_count = 0;
339
340 static variant *
341 variant_table_grow()
342 {
343 ++variant_count;
344 if (variant_count > variant_table_size)
345 {
346 while (variant_count > variant_table_size)
347 variant_table_size = 2 * variant_table_size + 3;
348 variant_table = xnrealloc (variant_table, variant_table_size,
349 sizeof *variant_table);
350 }
351 return &variant_table[variant_count - 1];
352 }
353
354 static char *
355 find_prefix_end(const char *prefix, char *begin, char *end)
356 {
357 char *ptr = begin;
358
359 while (*prefix && ptr != end)
360 {
361 if (*prefix != *ptr)
362 return 0;
363 ++prefix, ++ptr;
364 }
365
366 if (*prefix)
367 return 0;
368
369 return ptr;
370 }
371
372 static variant *
373 variant_add(uniqstr id, location loc, long int ind,
374 char *cp, char *cp_end, bool exact_mode)
375 {
376 char *prefix_end;
377
378 prefix_end = find_prefix_end(id, cp, cp_end);
379 if (prefix_end &&
380 (prefix_end == cp_end ||
381 (!exact_mode && is_dot_or_dash(*prefix_end))))
382 {
383 variant *r = variant_table_grow();
384 r->ind = ind;
385 r->id = id;
386 r->loc = loc;
387 r->hidden_by = NULL;
388 r->err = 0;
389 return r;
390 }
391 else
392 return NULL;
393 }
394
395 #define INVALID_REF (INT_MIN)
396 #define LHS_REF (INT_MIN + 1)
397
398 static long int
399 parse_named_ref(char *cp, symbol_list *rule, int rule_length,
400 int midrule_rhs_index, char *text, location loc,
401 char dollar_or_at)
402 {
403 symbol_list *l;
404 char *cp_end;
405 bool exact_mode;
406 bool has_error;
407 bool has_valid;
408 long int ind, i;
409 variant* variant;
410 char* p;
411
412 if ('$' == *cp)
413 return LHS_REF;
414
415 if (is_digit (*cp) || (*cp == '-' && is_digit (* (cp + 1))))
416 {
417 long int num = strtol (cp, &cp, 10);
418 if (1 - INT_MAX + rule_length <= num && num <= rule_length)
419 return num;
420 else
421 {
422 complain_at (loc, _("integer out of range: %s"), quote (text));
423 return INVALID_REF;
424 }
425 }
426
427 if ('[' == *cp)
428 {
429 exact_mode = true;
430
431 /* Ignore the brackets. */
432 ++cp;
433 for (p = cp; *p != ']'; ++p);
434 cp_end = p;
435 }
436 else
437 {
438 exact_mode = false;
439
440 /* Take all characters of the name. */
441 for (p = cp; *p; ++p)
442 if (is_dot_or_dash(*p))
443 {
444 ref_tail_fields = p;
445 break;
446 }
447 for (p = cp; *p; ++p);
448 cp_end = p;
449 }
450
451 /* Add all relevant variants. */
452 variant_count = 0;
453 for (ind = 0, l = rule; !symbol_list_null(l); ++ind, l = l->next)
454 {
455 if (l->content_type != SYMLIST_SYMBOL)
456 continue;
457
458 variant = variant_add(l->content.sym->tag, l->sym_loc, ind,
459 cp, cp_end, exact_mode);
460
461 if (variant && l->named_ref)
462 variant->hidden_by = l->named_ref;
463
464 if (l->named_ref)
465 variant_add(l->named_ref->id, l->named_ref->loc, ind,
466 cp, cp_end, exact_mode);
467 }
468
469 /* Check errors. */
470 has_error = false;
471 has_valid = false;
472 for (i = 0; i < variant_count; ++i)
473 {
474 variant = &variant_table[i];
475 ind = variant->ind;
476
477 /* Check visibility from mid-rule actions. */
478 if (midrule_rhs_index != 0 &&
479 (ind == 0 || ind > midrule_rhs_index))
480 {
481 variant->err |= VARIANT_NOT_VISIBLE_FROM_MIDRULE;
482 has_error = true;
483 }
484
485 /* Check correct bracketing. */
486 if (!exact_mode && contains_dot_or_dash(variant->id))
487 {
488 variant->err |= VARIANT_BAD_BRACKETING;
489 has_error = true;
490 }
491
492 /* Check using of hidden symbols. */
493 if (variant->hidden_by != NULL)
494 {
495 variant->err |= VARIANT_HIDDEN;
496 has_error = true;
497 }
498
499 if (!variant->err)
500 has_valid = true;
501 }
502
503 if (variant_count == 1 && has_valid)
504 {
505 /* The only "good" case is here. */
506 ind = variant_table[0].ind;
507 if (ind == midrule_rhs_index)
508 return LHS_REF;
509 else
510 return ind;
511 }
512
513 /* Start complaining. */
514
515 if (variant_count == 0)
516 complain_at (loc, _("reference is invalid: %s, symbol not found"),
517 quote (text));
518 else if (variant_count > 1 && !has_error)
519 complain_at (loc, _("reference is ambiguous: %s"),
520 quote (text));
521 else if (variant_count > 1 && has_valid && has_error)
522 complain_at (loc, _("reference is misleading: %s"),
523 quote (text));
524 else
525 complain_at (loc, _("reference is invalid: %s"),
526 quote (text));
527
528 for (i = 0; i < variant_count; ++i)
529 {
530 static char at_buf[20];
531
532 variant = &variant_table[i];
533
534 if (variant->ind == 0)
535 strcpy(at_buf, "$$");
536 else
537 snprintf(at_buf, sizeof(at_buf), "$%ld", variant->ind);
538
539 if (variant->err == 0)
540 complain_at (variant->loc, _(" refers to: %c%s at %s"),
541 dollar_or_at, variant->id, at_buf);
542 else
543 {
544 static struct obstack msg_buf;
545 const char *tail = "";
546 const char *id;
547 location loc;
548
549 if (!exact_mode)
550 tail = cp + strlen(variant->id);
551
552 if (variant->hidden_by)
553 {
554 id = variant->hidden_by->id;
555 loc = variant->hidden_by->loc;
556 }
557 else
558 {
559 id = variant->id;
560 loc = variant->loc;
561 }
562
563 /* Create the explanation message. */
564
565 obstack_init (&msg_buf);
566
567 obstack_fgrow1 (&msg_buf, " possibly meant: %c", dollar_or_at);
568 if (contains_dot_or_dash (id))
569 obstack_fgrow1 (&msg_buf, "[%s]", id);
570 else
571 obstack_sgrow (&msg_buf, id);
572 obstack_sgrow (&msg_buf, tail);
573
574 if (variant->err & VARIANT_HIDDEN)
575 {
576 obstack_fgrow1 (&msg_buf, ", hiding %c", dollar_or_at);
577 if (contains_dot_or_dash (variant->id))
578 obstack_fgrow1 (&msg_buf, "[%s]", variant->id);
579 else
580 obstack_sgrow (&msg_buf, variant->id);
581 obstack_sgrow (&msg_buf, tail);
582 }
583
584 obstack_fgrow1 (&msg_buf, " at %s", at_buf);
585
586 if (variant->err & VARIANT_NOT_VISIBLE_FROM_MIDRULE)
587 obstack_fgrow1 (&msg_buf, ", cannot be accessed from "
588 "mid-rule action at $%d", midrule_rhs_index);
589
590 obstack_1grow (&msg_buf, '\0');
591 complain_at (loc, _("%s"), (char *) obstack_finish (&msg_buf));
592 obstack_free (&msg_buf, 0);
593 }
594 }
595
596 return INVALID_REF;
597 }
598
599 /* Keeps track of the maximum number of semantic values to the left of
600 a handle (those referenced by $0, $-1, etc.) are required by the
601 semantic actions of this grammar. */
602 int max_left_semantic_context = 0;
603
604
605 /*------------------------------------------------------------------.
606 | TEXT is pointing to a wannabee semantic value (i.e., a `$'). |
607 | |
608 | Possible inputs: $[<TYPENAME>]($|integer) |
609 | |
610 | Output to OBSTACK_FOR_STRING a reference to this semantic value. |
611 `------------------------------------------------------------------*/
612
613 static void
614 handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
615 {
616 char const *type_name = NULL;
617 char *cp = text + 1;
618 char *gt_ptr = 0;
619 symbol_list *effective_rule;
620 int effective_rule_length, n;
621
622 if (rule->midrule_parent_rule)
623 {
624 effective_rule = rule->midrule_parent_rule;
625 effective_rule_length = rule->midrule_parent_rhs_index - 1;
626 }
627 else
628 {
629 effective_rule = rule;
630 effective_rule_length = symbol_list_length (rule->next);
631 }
632
633 /* Get the type name if explicit. */
634 if (*cp == '<')
635 {
636 type_name = ++cp;
637 while (*cp != '>')
638 ++cp;
639
640 /* The '>' symbol will be later replaced by '\0'. Original
641 'text' is needed for error messages. */
642 gt_ptr = cp;
643 ++cp;
644 if (untyped_var_seen)
645 complain_at (dollar_loc, _("explicit type given in untyped grammar"));
646 tag_seen = true;
647 }
648
649 n = parse_named_ref (cp, effective_rule, effective_rule_length,
650 rule->midrule_parent_rhs_index, text, dollar_loc, '$');
651
652 if (gt_ptr)
653 *gt_ptr = '\0';
654
655 switch (n)
656 {
657 case INVALID_REF:
658 break;
659
660 case LHS_REF:
661 if (!type_name)
662 type_name = symbol_list_n_type_name_get (rule, dollar_loc, 0);
663
664 if (!type_name)
665 {
666 if (union_seen | tag_seen)
667 {
668 if (rule->midrule_parent_rule)
669 complain_at (dollar_loc,
670 _("$$ for the midrule at $%d of `%s'"
671 " has no declared type"),
672 rule->midrule_parent_rhs_index,
673 effective_rule->content.sym->tag);
674 else
675 complain_at (dollar_loc, _("$$ of `%s' has no declared type"),
676 rule->content.sym->tag);
677 }
678 else
679 untyped_var_seen = true;
680 type_name = "";
681 }
682
683 obstack_fgrow1 (&obstack_for_string,
684 "]b4_lhs_value([%s])[", type_name);
685 rule->action_props.is_value_used = true;
686 break;
687
688 default:
689 if (max_left_semantic_context < 1 - n)
690 max_left_semantic_context = 1 - n;
691 if (!type_name && 0 < n)
692 type_name =
693 symbol_list_n_type_name_get (effective_rule, dollar_loc, n);
694 if (!type_name)
695 {
696 if (union_seen | tag_seen)
697 complain_at (dollar_loc, _("$%s of `%s' has no declared type"),
698 cp, effective_rule->content.sym->tag);
699 else
700 untyped_var_seen = true;
701 type_name = "";
702 }
703
704 obstack_fgrow3 (&obstack_for_string,
705 "]b4_rhs_value(%d, %d, [%s])[",
706 effective_rule_length, n, type_name);
707 if (n > 0)
708 symbol_list_n_get (effective_rule, n)->action_props.is_value_used =
709 true;
710 break;
711 }
712 }
713
714
715 /*------------------------------------------------------.
716 | TEXT is a location token (i.e., a `@...'). Output to |
717 | OBSTACK_FOR_STRING a reference to this location. |
718 `------------------------------------------------------*/
719
720 static void
721 handle_action_at (symbol_list *rule, char *text, location at_loc)
722 {
723 char *cp = text + 1;
724 symbol_list *effective_rule;
725 int effective_rule_length, n;
726
727 if (rule->midrule_parent_rule)
728 {
729 effective_rule = rule->midrule_parent_rule;
730 effective_rule_length = rule->midrule_parent_rhs_index - 1;
731 }
732 else
733 {
734 effective_rule = rule;
735 effective_rule_length = symbol_list_length (rule->next);
736 }
737
738 locations_flag = true;
739
740 n = parse_named_ref (cp, effective_rule, effective_rule_length,
741 rule->midrule_parent_rhs_index, text, at_loc, '@');
742 switch (n)
743 {
744 case INVALID_REF:
745 break;
746
747 case LHS_REF:
748 obstack_sgrow (&obstack_for_string, "]b4_lhs_location[");
749 break;
750
751 default:
752 obstack_fgrow2 (&obstack_for_string, "]b4_rhs_location(%d, %d)[",
753 effective_rule_length, n);
754 break;
755 }
756 }
757
758
759 /*-------------------------.
760 | Initialize the scanner. |
761 `-------------------------*/
762
763 /* Translate the dollars and ats in \a self, in the context \a sc_context
764 (SC_RULE_ACTION, SC_SYMBOL_ACTION, INITIAL). */
765
766 static char const *
767 translate_action (code_props *self, int sc_context)
768 {
769 char *res;
770 static bool initialized = false;
771 if (!initialized)
772 {
773 obstack_init (&obstack_for_string);
774 yy_flex_debug = 0;
775 initialized = true;
776 }
777
778 loc->start = loc->end = self->location.start;
779 yy_switch_to_buffer (yy_scan_string (self->code));
780 res = code_lex (self, sc_context);
781 yy_delete_buffer (YY_CURRENT_BUFFER);
782
783 return res;
784 }
785
786 /*------------------------------------------------------------------------.
787 | Implementation of the public interface as documented in "scan-code.h". |
788 `------------------------------------------------------------------------*/
789
790 void
791 code_props_none_init (code_props *self)
792 {
793 *self = code_props_none;
794 }
795
796 code_props const code_props_none = CODE_PROPS_NONE_INIT;
797
798 void
799 code_props_plain_init (code_props *self, char const *code, location code_loc)
800 {
801 self->kind = CODE_PROPS_PLAIN;
802 self->code = code;
803 self->location = code_loc;
804 self->is_value_used = false;
805 self->rule = NULL;
806 self->named_ref = NULL;
807 }
808
809 void
810 code_props_symbol_action_init (code_props *self, char const *code,
811 location code_loc)
812 {
813 self->kind = CODE_PROPS_SYMBOL_ACTION;
814 self->code = code;
815 self->location = code_loc;
816 self->is_value_used = false;
817 self->rule = NULL;
818 self->named_ref = NULL;
819 }
820
821 void
822 code_props_rule_action_init (code_props *self, char const *code,
823 location code_loc, symbol_list *rule,
824 named_ref *named_ref)
825 {
826 self->kind = CODE_PROPS_RULE_ACTION;
827 self->code = code;
828 self->location = code_loc;
829 self->is_value_used = false;
830 self->rule = rule;
831 self->named_ref = named_ref;
832 }
833
834 void
835 code_props_translate_code (code_props *self)
836 {
837 switch (self->kind)
838 {
839 case CODE_PROPS_NONE:
840 break;
841 case CODE_PROPS_PLAIN:
842 self->code = translate_action (self, INITIAL);
843 break;
844 case CODE_PROPS_SYMBOL_ACTION:
845 self->code = translate_action (self, SC_SYMBOL_ACTION);
846 break;
847 case CODE_PROPS_RULE_ACTION:
848 self->code = translate_action (self, SC_RULE_ACTION);
849 break;
850 }
851 }
852
853 void
854 code_scanner_last_string_free (void)
855 {
856 STRING_FREE;
857 }
858
859 void
860 code_scanner_free (void)
861 {
862 obstack_free (&obstack_for_string, 0);
863 /* Reclaim Flex's buffers. */
864 yylex_destroy ();
865 }