From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 08/12] Move "temp_parse_space" into ada_parse_state
Date: Thu, 21 Mar 2024 13:03:36 -0600 [thread overview]
Message-ID: <20240321-ada-iterated-assign-v1-8-925cdd4f1f4a@adacore.com> (raw)
In-Reply-To: <20240321-ada-iterated-assign-v1-0-925cdd4f1f4a@adacore.com>
This patch moves the "temp_parse_space" global into ada_parse_state.
It is also renamed to remove the redundant "parse". Finally, it is
changed to an auto_obstack to avoid the need for any manual
management.
---
gdb/ada-exp.y | 28 +++++++++++-----------------
gdb/ada-lex.l | 7 ++++---
2 files changed, 15 insertions(+), 20 deletions(-)
diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index 615b74d14d8..73178a58a0c 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -101,6 +101,8 @@ struct ada_parse_state
std::unordered_map<std::string, std::vector<ada_index_var_operation *>>
iterated_associations;
+ auto_obstack temp_space;
+
private:
/* We don't have a good way to manage non-POD data in Yacc, so store
@@ -1234,8 +1236,6 @@ primary : '*' primary %prec '.'
#define yyrestart ada_yyrestart
#define yytext ada_yytext
-static struct obstack temp_parse_space;
-
/* The following kludge was found necessary to prevent conflicts between */
/* defs.h and non-standard stdlib.h files. */
#define qsort __qsort__dummy
@@ -1255,8 +1255,6 @@ ada_parse (struct parser_state *par_state)
par_state->debug);
lexer_init (yyin); /* (Re-)initialize lexer. */
- obstack_free (&temp_parse_space, NULL);
- obstack_init (&temp_parse_space);
int result = yyparse ();
if (!result)
@@ -1323,7 +1321,7 @@ write_object_renaming (struct parser_state *par_state,
if (orig_left_context == NULL)
orig_left_context = get_selected_block (NULL);
- name = obstack_strndup (&temp_parse_space, renamed_entity,
+ name = obstack_strndup (&ada_parser->temp_space, renamed_entity,
renamed_entity_len);
ada_lookup_encoded_symbol (name, orig_left_context, SEARCH_VFT, &sym_info);
if (sym_info.symbol == NULL)
@@ -1389,7 +1387,8 @@ write_object_renaming (struct parser_state *par_state,
if (end == NULL)
end = renaming_expr + strlen (renaming_expr);
- index_name = obstack_strndup (&temp_parse_space, renaming_expr,
+ index_name = obstack_strndup (&ada_parser->temp_space,
+ renaming_expr,
end - renaming_expr);
renaming_expr = end;
@@ -1608,10 +1607,10 @@ static void
write_ambiguous_var (struct parser_state *par_state,
const struct block *block, const char *name, int len)
{
- struct symbol *sym = new (&temp_parse_space) symbol ();
+ struct symbol *sym = new (&ada_parser->temp_space) symbol ();
sym->set_domain (UNDEF_DOMAIN);
- sym->set_linkage_name (obstack_strndup (&temp_parse_space, name, len));
+ sym->set_linkage_name (obstack_strndup (&ada_parser->temp_space, name, len));
sym->set_language (language_ada, nullptr);
block_symbol bsym { sym, block };
@@ -1719,7 +1718,8 @@ write_var_or_type (struct parser_state *par_state,
}
name_len = name_storage.size ();
- encoded_name = obstack_strndup (&temp_parse_space, name_storage.c_str (),
+ encoded_name = obstack_strndup (&ada_parser->temp_space,
+ name_storage.c_str (),
name_len);
for (depth = 0; depth < MAX_RENAMING_CHAIN_LENGTH; depth += 1)
{
@@ -1765,7 +1765,8 @@ write_var_or_type (struct parser_state *par_state,
{
int alloc_len = renaming_len + name_len - tail_index + 1;
char *new_name
- = (char *) obstack_alloc (&temp_parse_space, alloc_len);
+ = (char *) obstack_alloc (&ada_parser->temp_space,
+ alloc_len);
strncpy (new_name, renaming, renaming_len);
strcpy (new_name + renaming_len, encoded_name + tail_index);
encoded_name = new_name;
@@ -1987,10 +1988,3 @@ type_system_address (struct parser_state *par_state)
"system__address");
return type != NULL ? type : parse_type (par_state)->builtin_data_ptr;
}
-
-void _initialize_ada_exp ();
-void
-_initialize_ada_exp ()
-{
- obstack_init (&temp_parse_space);
-}
diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l
index 109b95ccc35..90cb5ba1b8a 100644
--- a/gdb/ada-lex.l
+++ b/gdb/ada-lex.l
@@ -531,7 +531,7 @@ processReal (struct parser_state *par_state, const char *num0)
static struct stoken
processId (const char *name0, int len)
{
- char *name = (char *) obstack_alloc (&temp_parse_space, len + 11);
+ char *name = (char *) obstack_alloc (&ada_parser->temp_space, len + 11);
int i0, i;
struct stoken result;
@@ -593,7 +593,7 @@ processString (const char *text, int len)
const char *lim = text + len;
struct stoken result;
- q = (char *) obstack_alloc (&temp_parse_space, len);
+ q = (char *) obstack_alloc (&ada_parser->temp_space, len);
result.ptr = q;
p = text;
while (p < lim)
@@ -706,7 +706,8 @@ processAttribute (const char *str)
{
/* This is enforced by YY_INPUT. */
gdb_assert (pstate->parse_completion);
- yylval.sval.ptr = obstack_strndup (&temp_parse_space, str, len - 1);
+ yylval.sval.ptr = obstack_strndup (&ada_parser->temp_space,
+ str, len - 1);
yylval.sval.length = len - 1;
return TICK_COMPLETE;
}
--
2.43.0
next prev parent reply other threads:[~2024-03-21 19:05 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-21 19:03 [PATCH 00/12] Ada iterated assignment, plus parser cleanups Tom Tromey
2024-03-21 19:03 ` [PATCH 01/12] Introduce and use aggregate_assigner type Tom Tromey
2024-03-21 19:03 ` [PATCH 02/12] Implement Ada 2022 iterated assignment Tom Tromey
2024-03-21 19:03 ` [PATCH 03/12] Introduce ada_parse_state Tom Tromey
2024-03-21 19:03 ` [PATCH 04/12] Move "int_storage" global into ada_parse_state Tom Tromey
2024-03-21 19:03 ` [PATCH 05/12] Move "components" and "associations" " Tom Tromey
2024-03-21 19:03 ` [PATCH 06/12] Move "assignments" global " Tom Tromey
2024-03-21 19:03 ` [PATCH 07/12] Move "iterated_associations" " Tom Tromey
2024-03-21 19:03 ` Tom Tromey [this message]
2024-03-21 19:03 ` [PATCH 09/12] Move "paren_depth" " Tom Tromey
2024-03-21 19:03 ` [PATCH 10/12] Move "returned_complete" " Tom Tromey
2024-03-21 19:03 ` [PATCH 11/12] Remove "numbuf" global Tom Tromey
2024-03-21 19:03 ` [PATCH 12/12] Constify ada-lex.l:attributes Tom Tromey
2024-04-02 17:35 ` [PATCH 00/12] Ada iterated assignment, plus parser cleanups Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240321-ada-iterated-assign-v1-8-925cdd4f1f4a@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox