]> git.saurik.com Git - bison.git/blame - src/scan-code.h
tests: fix expected output.
[bison.git] / src / scan-code.h
CommitLineData
28e52c0d 1/* Bison code properties structure and scanner.
e9071366 2
c932d613 3 Copyright (C) 2006-2007, 2009-2012 Free Software Foundation, Inc.
e9071366
AD
4
5 This file is part of Bison, the GNU Compiler Compiler.
6
f16b0819 7 This program is free software: you can redistribute it and/or modify
e9071366 8 it under the terms of the GNU General Public License as published by
f16b0819 9 the Free Software Foundation, either version 3 of the License, or
e9071366
AD
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
f16b0819 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
e9071366
AD
19
20#ifndef SCAN_CODE_H_
21# define SCAN_CODE_H_
22
23# include "location.h"
7685e2f7 24# include "named-ref.h"
e9071366 25
28e52c0d
JD
26struct symbol_list;
27
28/**
29 * Keeps track of the maximum number of semantic values to the left of a handle
30 * (those referenced by $0, $-1, etc.) that are required by the semantic
31 * actions of this grammar.
32 */
e9071366
AD
33extern int max_left_semantic_context;
34
28e52c0d
JD
35/**
36 * A code passage captured from the grammar file and possibly translated,
37 * and/or properties associated with such a code passage. Don't break
38 * encapsulation by modifying the fields directly. Use the provided interface
39 * functions.
40 */
41typedef struct code_props {
42 /** Set by the init functions. */
43 enum {
44 CODE_PROPS_NONE, CODE_PROPS_PLAIN,
45 CODE_PROPS_SYMBOL_ACTION, CODE_PROPS_RULE_ACTION
46 } kind;
47
48 /** \c NULL iff \c code_props::kind is \c CODE_PROPS_NONE. */
49 char const *code;
50 /** Undefined iff \c code_props::code is \c NULL. */
51 location location;
52
53 /**
54 * \c false iff either:
55 * - \c code_props_translate_code has never previously been invoked for
56 * the \c code_props that would contain the code passage associated
57 * with \c self. (That \c code_props is not the same as this one if this
58 * one is for a RHS \c symbol_list node. Instead, it's the \c code_props
59 * for the LHS symbol of the same rule.)
60 * - \c code_props_translate_code has been invoked for that \c code_props,
61 * but the symbol value associated with this \c code_props was not
62 * referenced in the code passage.
63 */
64 bool is_value_used;
65
66 /** \c NULL iff \c code_props::kind is not \c CODE_PROPS_RULE_ACTION. */
67 struct symbol_list *rule;
7685e2f7
AR
68
69 /* Named reference. */
70 named_ref *named_ref;
28e52c0d
JD
71} code_props;
72
73/**
74 * \pre
75 * - <tt>self != NULL</tt>.
76 * \post
77 * - \c self has been overwritten to contain no code.
78 */
79void code_props_none_init (code_props *self);
80
81/** Equivalent to \c code_props_none_init. */
82#define CODE_PROPS_NONE_INIT \
7685e2f7 83 {CODE_PROPS_NONE, NULL, EMPTY_LOCATION_INIT, false, NULL, NULL}
28e52c0d
JD
84
85/** Initialized by \c CODE_PROPS_NONE_INIT with no further modification. */
86extern code_props const code_props_none;
87
88/**
89 * \pre
90 * - <tt>self != NULL</tt>.
91 * - <tt>code != NULL</tt>.
92 * - \c code is an untranslated code passage containing no Bison escapes.
93 * - \c code was extracted from the grammar file at \c code_loc.
94 * \post
95 * - \c self has been overwritten to represent the specified plain code
96 * passage.
97 * - \c self will become invalid if the caller frees \c code before invoking
98 * \c code_props_translate_code on \c self.
99 */
100void code_props_plain_init (code_props *self, char const *code,
101 location code_loc);
102
103/**
104 * \pre
105 * - <tt>self != NULL</tt>.
106 * - <tt>code != NULL</tt>.
107 * - \c code is an untranslated code passage. The only Bison escapes it
108 * might contain are $$ and \@$, referring to a single symbol.
109 * - \c code was extracted from the grammar file at \c code_loc.
110 * \post
111 * - \c self has been overwritten to represent the specified symbol action.
112 * - \c self will become invalid if the caller frees \c code before invoking
113 * \c code_props_translate_code on \c self.
114 */
115void code_props_symbol_action_init (code_props *self, char const *code,
116 location code_loc);
117
118/**
119 * \pre
120 * - <tt>self != NULL</tt>.
121 * - <tt>code != NULL</tt>.
122 * - <tt>rule != NULL</tt>.
123 * - \c code is the untranslated action of the rule for which \c rule is the
124 * LHS node. Thus, \c code possibly contains Bison escapes such as $$, $1,
125 * $2, etc referring to the values of the rule.
126 * - \c code was extracted from the grammar file at \c code_loc.
127 * \post
128 * - \c self has been overwritten to represent the specified rule action.
129 * - \c self does not claim responsibility for the memory of \c rule.
130 * - \c self will become invalid if:
131 * - The caller frees \c code before invoking \c code_props_translate_code
132 * on \c self.
133 * - The caller frees \c rule.
134 */
135void code_props_rule_action_init (code_props *self, char const *code,
7685e2f7 136 location code_loc, struct symbol_list *rule,
9852b61c 137 named_ref *name);
28e52c0d
JD
138
139/**
140 * \pre
141 * - If there's a code passage contained in \c self and it contains Bison
142 * escapes, all grammar declarations have already been parsed as they may
143 * affect warnings and complaints issued here.
144 * \post
145 * - All M4-special symbols and Bison escapes have been translated in
146 * \c self->code.
147 * - <tt>self->code != self->code\@pre</tt> unless
148 * <tt>self->code\@pre = NULL</tt>.
149 */
150void code_props_translate_code (code_props *self);
151
152/**
153 * \pre
154 * - None.
155 * \post
156 * - The dynamic memory allocated by the previous invocation of
157 * \c code_props_translate_code (if any) was freed. The \c code_props
158 * instance for which \c code_props_translate_code was invoked is now
159 * invalid.
160 */
161void code_scanner_last_string_free (void);
162
163/**
164 * \pre
165 * - None.
166 * \post
7c0c6181 167 * - All dynamic memory allocated during invocations of
f6857bbf
JD
168 * \c code_props_translate_code (if any) has been freed. All \c code_props
169 * instances may now be invalid.
28e52c0d 170 */
b0f4c4ea 171void code_scanner_free (void);
76290368 172
e9071366 173#endif /* !SCAN_CODE_H_ */