gdb/mi: add new --group-by-objfile flag for -file-list-exec-source-files
[deliverable/binutils-gdb.git] / gdb / parser-defs.h
CommitLineData
c906108c 1/* Parser definitions for GDB.
96cb11df 2
3666a048 3 Copyright (C) 1986-2021 Free Software Foundation, Inc.
96cb11df 4
c906108c
SS
5 Modified from expread.y by the Department of Computer Science at the
6 State University of New York at Buffalo.
7
c5aa993b 8 This file is part of GDB.
c906108c 9
c5aa993b
JM
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
a9762ec7 12 the Free Software Foundation; either version 3 of the License, or
c5aa993b 13 (at your option) any later version.
c906108c 14
c5aa993b
JM
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
c906108c 19
c5aa993b 20 You should have received a copy of the GNU General Public License
a9762ec7 21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
22
23#if !defined (PARSER_DEFS_H)
24#define PARSER_DEFS_H 1
25
74e5a346 26#include "expression.h"
0d12e84c 27#include "symtab.h"
4933522d 28#include "expop.h"
d16aafd8 29
fe898f56 30struct block;
410a0ff2
SDJ
31struct language_defn;
32struct internalvar;
699bd4cf 33class innermost_block_tracker;
fe898f56 34
491144b5 35extern bool parser_debug;
92981e24 36
37eedb39
TT
37/* A class that can be used to build a "struct expression". */
38
39struct expr_builder
410a0ff2 40{
1201a264
TT
41 /* Constructor. LANG is the language used to parse the expression.
42 And GDBARCH is the gdbarch to use during parsing. */
e9d9f57e 43
37eedb39 44 expr_builder (const struct language_defn *lang,
ce284361
TT
45 struct gdbarch *gdbarch)
46 : expout (new expression (lang, gdbarch))
47 {
48 }
e9d9f57e 49
37eedb39 50 DISABLE_COPY_AND_ASSIGN (expr_builder);
410a0ff2 51
e9d9f57e
TT
52 /* Resize the allocated expression to the correct size, and return
53 it as an expression_up -- passing ownership to the caller. */
ce284361
TT
54 ATTRIBUTE_UNUSED_RESULT expression_up release ()
55 {
56 return std::move (expout);
57 }
410a0ff2 58
fa9f5be6
TT
59 /* Return the gdbarch that was passed to the constructor. */
60
61 struct gdbarch *gdbarch ()
62 {
63 return expout->gdbarch;
64 }
65
73923d7e
TT
66 /* Return the language that was passed to the constructor. */
67
68 const struct language_defn *language ()
69 {
70 return expout->language_defn;
71 }
72
413403fc
TT
73 /* Set the root operation of the expression that is currently being
74 built. */
75 void set_operation (expr::operation_up &&op)
76 {
77 expout->op = std::move (op);
78 }
79
e9d9f57e
TT
80 /* The expression related to this parser state. */
81
82 expression_up expout;
410a0ff2 83};
3e79cecf 84
2a612529
TT
85/* This is used for expression completion. */
86
87struct expr_completion_state
88{
4933522d
TT
89 /* The last struct expression directly before a '.' or '->'. This
90 is set when parsing and is only used when completing a field
91 name. It is nullptr if no dereference operation was found. */
92 expr::structop_base_operation *expout_last_op = nullptr;
93
2a612529
TT
94 /* If we are completing a tagged type name, this will be nonzero. */
95 enum type_code expout_tag_completion_type = TYPE_CODE_UNDEF;
96
97 /* The token for tagged type name completion. */
98 gdb::unique_xmalloc_ptr<char> expout_completion_name;
99};
100
37eedb39
TT
101/* An instance of this type is instantiated during expression parsing,
102 and passed to the appropriate parser. It holds both inputs to the
103 parser, and result. */
104
105struct parser_state : public expr_builder
106{
107 /* Constructor. LANG is the language used to parse the expression.
108 And GDBARCH is the gdbarch to use during parsing. */
109
110 parser_state (const struct language_defn *lang,
1e58a4a4
TT
111 struct gdbarch *gdbarch,
112 const struct block *context_block,
8621b685 113 CORE_ADDR context_pc,
5776fca3 114 int comma,
2a612529 115 const char *input,
7056f312 116 bool completion,
c5c41205
TT
117 innermost_block_tracker *tracker,
118 bool void_p)
1e58a4a4
TT
119 : expr_builder (lang, gdbarch),
120 expression_context_block (context_block),
8621b685 121 expression_context_pc (context_pc),
5776fca3 122 comma_terminates (comma),
2a612529 123 lexptr (input),
699bd4cf 124 parse_completion (completion),
c5c41205
TT
125 block_tracker (tracker),
126 void_context_p (void_p)
37eedb39
TT
127 {
128 }
129
130 DISABLE_COPY_AND_ASSIGN (parser_state);
37eedb39 131
43476f0b
TT
132 /* Begin counting arguments for a function call,
133 saving the data about any containing call. */
134
135 void start_arglist ()
136 {
137 m_funcall_chain.push_back (arglist_len);
138 arglist_len = 0;
139 }
140
141 /* Return the number of arguments in a function call just terminated,
142 and restore the data for the containing function call. */
143
144 int end_arglist ()
145 {
146 int val = arglist_len;
147 arglist_len = m_funcall_chain.back ();
148 m_funcall_chain.pop_back ();
149 return val;
150 }
151
4933522d
TT
152 /* Mark the given operation as the starting location of a structure
153 expression. This is used when completing on field names. */
154
155 void mark_struct_expression (expr::structop_base_operation *op);
156
2a612529
TT
157 /* Indicate that the current parser invocation is completing a tag.
158 TAG is the type code of the tag, and PTR and LENGTH represent the
159 start of the tag name. */
160
161 void mark_completion_tag (enum type_code tag, const char *ptr, int length);
162
8227d9e2
TT
163 /* Push an operation on the stack. */
164 void push (expr::operation_up &&op)
165 {
166 m_operations.push_back (std::move (op));
167 }
168
169 /* Create a new operation and push it on the stack. */
170 template<typename T, typename... Arg>
171 void push_new (Arg... args)
172 {
173 m_operations.emplace_back (new T (std::forward<Arg> (args)...));
174 }
175
176 /* Push a new C string operation. */
177 void push_c_string (int, struct stoken_vector *vec);
178
179 /* Push a symbol reference. If SYM is nullptr, look for a minimal
180 symbol. */
181 void push_symbol (const char *name, block_symbol sym);
182
183 /* Push a reference to $mumble. This may result in a convenience
184 variable, a history reference, or a register. */
185 void push_dollar (struct stoken str);
186
187 /* Pop an operation from the stack. */
188 expr::operation_up pop ()
189 {
190 expr::operation_up result = std::move (m_operations.back ());
191 m_operations.pop_back ();
192 return result;
193 }
194
195 /* Pop N elements from the stack and return a vector. */
196 std::vector<expr::operation_up> pop_vector (int n)
197 {
198 std::vector<expr::operation_up> result (n);
199 for (int i = 1; i <= n; ++i)
200 result[n - i] = pop ();
201 return result;
202 }
203
204 /* A helper that pops an operation, wraps it in some other
205 operation, and pushes it again. */
206 template<typename T>
207 void wrap ()
208 {
209 using namespace expr;
210 operation_up v = ::expr::make_operation<T> (pop ());
211 push (std::move (v));
212 }
213
214 /* A helper that pops two operations, wraps them in some other
215 operation, and pushes the result. */
216 template<typename T>
217 void wrap2 ()
218 {
219 expr::operation_up rhs = pop ();
220 expr::operation_up lhs = pop ();
221 push (expr::make_operation<T> (std::move (lhs), std::move (rhs)));
222 }
43476f0b 223
1e58a4a4
TT
224 /* If this is nonzero, this block is used as the lexical context for
225 symbol names. */
c906108c 226
1e58a4a4 227 const struct block * const expression_context_block;
c906108c 228
1e58a4a4
TT
229 /* If expression_context_block is non-zero, then this is the PC
230 within the block that we want to evaluate expressions at. When
231 debugging C or C++ code, we use this to find the exact line we're
232 at, and then look up the macro definitions active at that
233 point. */
234 const CORE_ADDR expression_context_pc;
8621b685
TT
235
236 /* Nonzero means stop parsing on first comma (if not within parentheses). */
237
238 int comma_terminates;
5776fca3
TT
239
240 /* During parsing of a C expression, the pointer to the next character
241 is in this variable. */
242
243 const char *lexptr;
244
245 /* After a token has been recognized, this variable points to it.
246 Currently used only for error reporting. */
247 const char *prev_lexptr = nullptr;
43476f0b
TT
248
249 /* Number of arguments seen so far in innermost function call. */
250
251 int arglist_len = 0;
252
2a612529 253 /* True if parsing an expression to attempt completion. */
7056f312 254 bool parse_completion;
2a612529
TT
255
256 /* Completion state is updated here. */
257 expr_completion_state m_completion_state;
258
699bd4cf
TT
259 /* The innermost block tracker. */
260 innermost_block_tracker *block_tracker;
261
c5c41205
TT
262 /* True if no value is expected from the expression. */
263 bool void_context_p;
264
43476f0b
TT
265private:
266
267 /* Data structure for saving values of arglist_len for function calls whose
268 arguments contain other function calls. */
269
270 std::vector<int> m_funcall_chain;
8227d9e2
TT
271
272 /* Stack of operations. */
273 std::vector<expr::operation_up> m_operations;
1e58a4a4 274};
84f0252a 275
aee1fcdf
AB
276/* When parsing expressions we track the innermost block that was
277 referenced. */
278
279class innermost_block_tracker
280{
281public:
699bd4cf
TT
282 innermost_block_tracker (innermost_block_tracker_types types
283 = INNERMOST_BLOCK_FOR_SYMBOLS)
284 : m_types (types),
ae451627 285 m_innermost_block (NULL)
aee1fcdf
AB
286 { /* Nothing. */ }
287
aee1fcdf 288 /* Update the stored innermost block if the new block B is more inner
ae451627
AB
289 than the currently stored block, or if no block is stored yet. The
290 type T tells us whether the block B was for a symbol or for a
291 register. The stored innermost block is only updated if the type T is
292 a type we are interested in, the types we are interested in are held
293 in M_TYPES and set during RESET. */
294 void update (const struct block *b, innermost_block_tracker_types t);
aee1fcdf
AB
295
296 /* Overload of main UPDATE method which extracts the block from BS. */
297 void update (const struct block_symbol &bs)
298 {
ae451627 299 update (bs.block, INNERMOST_BLOCK_FOR_SYMBOLS);
aee1fcdf
AB
300 }
301
302 /* Return the stored innermost block. Can be nullptr if no symbols or
303 registers were found during an expression parse, and so no innermost
304 block was defined. */
305 const struct block *block () const
306 {
307 return m_innermost_block;
308 }
309
310private:
ae451627
AB
311 /* The type of innermost block being looked for. */
312 innermost_block_tracker_types m_types;
313
aee1fcdf
AB
314 /* The currently stored innermost block found while parsing an
315 expression. */
316 const struct block *m_innermost_block;
317};
318
c906108c 319/* A string token, either a char-string or bit-string. Char-strings are
0df8b418 320 used, for example, for the names of symbols. */
c906108c
SS
321
322struct stoken
323 {
0df8b418 324 /* Pointer to first byte of char-string or first bit of bit-string. */
d7561cbb 325 const char *ptr;
0df8b418 326 /* Length of string in bytes for char-string or bits for bit-string. */
c906108c
SS
327 int length;
328 };
329
6c7a06a3
TT
330struct typed_stoken
331 {
332 /* A language-specific type field. */
333 int type;
0df8b418 334 /* Pointer to first byte of char-string or first bit of bit-string. */
6c7a06a3 335 char *ptr;
0df8b418 336 /* Length of string in bytes for char-string or bits for bit-string. */
6c7a06a3
TT
337 int length;
338 };
339
340struct stoken_vector
341 {
342 int len;
343 struct typed_stoken *tokens;
344 };
345
c906108c
SS
346struct ttype
347 {
348 struct stoken stoken;
349 struct type *type;
350 };
351
352struct symtoken
353 {
354 struct stoken stoken;
d12307c1 355 struct block_symbol sym;
c906108c
SS
356 int is_a_field_of_this;
357 };
358
379b85df
AF
359struct objc_class_str
360 {
361 struct stoken stoken;
362 struct type *type;
fe978cb0 363 int theclass;
379b85df
AF
364 };
365
d7561cbb 366extern const char *find_template_name_end (const char *);
c906108c 367
61f4b350 368extern std::string copy_name (struct stoken);
c906108c 369
edd079d9
UW
370extern bool parse_float (const char *p, int len,
371 const struct type *type, gdb_byte *data);
c906108c 372\f
6d816919 373
f461f5cf
PM
374/* Function used to avoid direct calls to fprintf
375 in the code generated by the bison parser. */
376
a0b31db1 377extern void parser_fprintf (FILE *, const char *, ...) ATTRIBUTE_PRINTF (2, 3);
f461f5cf 378
40d07d07 379extern bool exp_uses_objfile (struct expression *exp, struct objfile *objfile);
c0201579 380
c5aa993b 381#endif /* PARSER_DEFS_H */
2f68a895 382
This page took 2.036683 seconds and 4 git commands to generate.