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