aboutsummaryrefslogtreecommitdiff
path: root/gdb/ada-lang.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2020-10-09 08:27:30 -0600
committerTom Tromey <tromey@adacore.com>2020-10-09 08:27:30 -0600
commit5c4258f4c051a31d7209712ecd28830c55a92034 (patch)
tree4ca01f20c3de6dae58e62c5a3b0c34f3d78a0e10 /gdb/ada-lang.c
parentfa40fbe484954c560ab1c0ff4bc1b2eeb1511344 (diff)
downloadgdb-5c4258f4c051a31d7209712ecd28830c55a92034.zip
gdb-5c4258f4c051a31d7209712ecd28830c55a92034.tar.gz
gdb-5c4258f4c051a31d7209712ecd28830c55a92034.tar.bz2
Return std::string from ada_encode
This changes ada_encode to return a std::string. This simplifies it somewhat, removes a use of GROW_VECT, and is also simpler for callers to use. gdb/ChangeLog 2020-10-09 Tom Tromey <tromey@adacore.com> * ada-lang.h (ada_encode): Return std::string. * ada-lang.c (ada_encode_1): Return std::string. (ada_encode): Likewise. (type_from_tag, ada_lookup_name_info::ada_lookup_name_info): Update. * ada-exp.y (block_lookup, write_var_or_type): Update.
Diffstat (limited to 'gdb/ada-lang.c')
-rw-r--r--gdb/ada-lang.c50
1 files changed, 15 insertions, 35 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 0df406b..fbce14b 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -918,33 +918,21 @@ const struct ada_opname_map ada_opname_table[] = {
{NULL, NULL}
};
-/* The "encoded" form of DECODED, according to GNAT conventions. The
- result is valid until the next call to ada_encode. If
+/* The "encoded" form of DECODED, according to GNAT conventions. If
THROW_ERRORS, throw an error if invalid operator name is found.
- Otherwise, return NULL in that case. */
+ Otherwise, return the empty string in that case. */
-static char *
+static std::string
ada_encode_1 (const char *decoded, bool throw_errors)
{
- static char *encoding_buffer = NULL;
- static size_t encoding_buffer_size = 0;
- const char *p;
- int k;
-
if (decoded == NULL)
- return NULL;
-
- GROW_VECT (encoding_buffer, encoding_buffer_size,
- 2 * strlen (decoded) + 10);
+ return {};
- k = 0;
- for (p = decoded; *p != '\0'; p += 1)
+ std::string encoding_buffer;
+ for (const char *p = decoded; *p != '\0'; p += 1)
{
if (*p == '.')
- {
- encoding_buffer[k] = encoding_buffer[k + 1] = '_';
- k += 2;
- }
+ encoding_buffer.append ("__");
else if (*p == '"')
{
const struct ada_opname_map *mapping;
@@ -958,27 +946,21 @@ ada_encode_1 (const char *decoded, bool throw_errors)
if (throw_errors)
error (_("invalid Ada operator name: %s"), p);
else
- return NULL;
+ return {};
}
- strcpy (encoding_buffer + k, mapping->encoded);
- k += strlen (mapping->encoded);
+ encoding_buffer.append (mapping->encoded);
break;
}
else
- {
- encoding_buffer[k] = *p;
- k += 1;
- }
+ encoding_buffer.push_back (*p);
}
- encoding_buffer[k] = '\0';
return encoding_buffer;
}
-/* The "encoded" form of DECODED, according to GNAT conventions.
- The result is valid until the next call to ada_encode. */
+/* The "encoded" form of DECODED, according to GNAT conventions. */
-char *
+std::string
ada_encode (const char *decoded)
{
return ada_encode_1 (decoded, true);
@@ -6384,7 +6366,7 @@ type_from_tag (struct value *tag)
gdb::unique_xmalloc_ptr<char> type_name = ada_tag_name (tag);
if (type_name != NULL)
- return ada_find_any_type (ada_encode (type_name.get ()));
+ return ada_find_any_type (ada_encode (type_name.get ()).c_str ());
return NULL;
}
@@ -13613,10 +13595,8 @@ ada_lookup_name_info::ada_lookup_name_info (const lookup_name_info &lookup_name)
if (!m_encoded_p)
{
const char *folded = ada_fold_name (user_name);
- const char *encoded = ada_encode_1 (folded, false);
- if (encoded != NULL)
- m_encoded_name = encoded;
- else
+ m_encoded_name = ada_encode_1 (folded, false);
+ if (m_encoded_name.empty ())
m_encoded_name = gdb::to_string (user_name);
}
else