From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 3/5] Use std::string, std::vector in rust-lang.c
Date: Thu, 22 Sep 2016 17:51:00 -0000 [thread overview]
Message-ID: <1474566656-15389-4-git-send-email-tom@tromey.com> (raw)
In-Reply-To: <1474566656-15389-1-git-send-email-tom@tromey.com>
This patche changes some spots in rust-lang.c to use std::string or
std::vector, removing some cleanups.
2016-09-22 Tom Tromey <tom@tromey.com>
* rust-lang.c: Include <string> and <vector>.
(rust_evaluate_funcall): Use std::vector, std::string.
(rust_evaluate_subexp): Use std::string.
(rust_lookup_symbol_nonlocal): Use std::string.
---
gdb/ChangeLog | 7 +++++++
gdb/rust-lang.c | 38 ++++++++++++++++----------------------
2 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 2029bcb..670406d 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@
2016-09-22 Tom Tromey <tom@tromey.com>
+ * rust-lang.c: Include <string> and <vector>.
+ (rust_evaluate_funcall): Use std::vector, std::string.
+ (rust_evaluate_subexp): Use std::string.
+ (rust_lookup_symbol_nonlocal): Use std::string.
+
+2016-09-22 Tom Tromey <tom@tromey.com>
+
* cp-namespace.c: Include <string>.
(cp_search_static_and_baseclasses)
(cp_lookup_symbol_imports_or_template, find_symbol_in_baseclass):
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 77f7428..b9acfcf 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -32,6 +32,8 @@
#include "rust-lang.h"
#include "valprint.h"
#include "varobj.h"
+#include <string>
+#include <vector>
extern initialize_file_ftype _initialize_rust_language;
@@ -1154,10 +1156,9 @@ rust_evaluate_funcall (struct expression *exp, int *pos, enum noside noside)
int i;
int num_args = exp->elts[*pos + 1].longconst;
const char *method;
- char *name;
+ std::string name;
struct value *function, *result, *arg0;
- struct value **args;
- struct cleanup *cleanup;
+ std::vector<struct value *> args (num_args + 1);
struct type *type, *fn_type;
const struct block *block;
struct block_symbol sym;
@@ -1183,8 +1184,6 @@ rust_evaluate_funcall (struct expression *exp, int *pos, enum noside noside)
return arg0;
}
- args = XNEWVEC (struct value *, num_args + 1);
- cleanup = make_cleanup (xfree, args);
args[0] = arg0;
/* We don't yet implement real Deref semantics. */
@@ -1200,17 +1199,16 @@ rust_evaluate_funcall (struct expression *exp, int *pos, enum noside noside)
if (TYPE_TAG_NAME (type) == NULL)
error (_("Method call on nameless type"));
- name = concat (TYPE_TAG_NAME (type), "::", method, (char *) NULL);
- make_cleanup (xfree, name);
+ name = std::string (TYPE_TAG_NAME (type)) + "::" + method;
block = get_selected_block (0);
- sym = lookup_symbol (name, block, VAR_DOMAIN, NULL);
+ sym = lookup_symbol (name.c_str (), block, VAR_DOMAIN, NULL);
if (sym.symbol == NULL)
- error (_("Could not find function named '%s'"), name);
+ error (_("Could not find function named '%s'"), name.c_str ());
fn_type = SYMBOL_TYPE (sym.symbol);
if (TYPE_NFIELDS (fn_type) == 0)
- error (_("Function '%s' takes no arguments"), name);
+ error (_("Function '%s' takes no arguments"), name.c_str ());
if (TYPE_CODE (TYPE_FIELD_TYPE (fn_type, 0)) == TYPE_CODE_PTR)
args[0] = value_addr (args[0]);
@@ -1223,8 +1221,7 @@ rust_evaluate_funcall (struct expression *exp, int *pos, enum noside noside)
if (noside == EVAL_AVOID_SIDE_EFFECTS)
result = value_zero (TYPE_TARGET_TYPE (fn_type), not_lval);
else
- result = call_function_by_hand (function, num_args + 1, args);
- do_cleanups (cleanup);
+ result = call_function_by_hand (function, num_args + 1, args.data ());
return result;
}
@@ -1601,14 +1598,11 @@ rust_evaluate_subexp (struct type *expect_type, struct expression *exp,
{
CORE_ADDR addr;
int i;
- struct value **eltvec = XNEWVEC (struct value *, copies);
- struct cleanup *cleanup = make_cleanup (xfree, eltvec);
+ std::vector<struct value *> eltvec (copies);
for (i = 0; i < copies; ++i)
eltvec[i] = elt;
- result = value_array (0, copies - 1, eltvec);
-
- do_cleanups (cleanup);
+ result = value_array (0, copies - 1, eltvec.data ());
}
else
{
@@ -2036,14 +2030,14 @@ rust_lookup_symbol_nonlocal (const struct language_defn *langdef,
if (scope[0] != '\0')
{
- char *scopedname = concat (scope, "::", name, (char *) NULL);
- struct cleanup *cleanup = make_cleanup (xfree, scopedname);
+ std::string scopedname;
+
+ scopedname = std::string (scope) + "::" + name;
- result = lookup_symbol_in_static_block (scopedname, block,
+ result = lookup_symbol_in_static_block (scopedname.c_str (), block,
domain);
if (result.symbol == NULL)
- result = lookup_global_symbol (scopedname, block, domain);
- do_cleanups (cleanup);
+ result = lookup_global_symbol (scopedname.c_str (), block, domain);
}
}
return result;
--
2.7.4
next prev parent reply other threads:[~2016-09-22 17:51 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-22 17:51 [RFA 0/5] Some random C++-ification Tom Tromey
2016-09-22 17:51 ` [RFA 4/5] Use std::vector in objfiles.c Tom Tromey
2016-09-22 17:51 ` [RFA 2/5] Use std::string in cp-namespace.c Tom Tromey
2016-09-22 19:08 ` Pedro Alves
2016-09-22 20:56 ` Tom Tromey
2016-09-22 17:51 ` [RFA 1/5] Use std::string in break-catch-sig.c Tom Tromey
2016-09-23 13:17 ` Yao Qi
2016-09-22 17:51 ` Tom Tromey [this message]
2016-09-22 19:03 ` [RFA 3/5] Use std::string, std::vector in rust-lang.c Pedro Alves
2016-09-22 19:24 ` Tom Tromey
2016-09-22 19:35 ` Pedro Alves
2016-09-22 20:37 ` Pierre Muller
[not found] ` <57e4328a.c3c4620a.59d5b.803fSMTPIN_ADDED_BROKEN@mx.google.com>
2016-09-23 9:44 ` Pedro Alves
2016-09-23 15:56 ` Tom Tromey
2016-09-23 16:15 ` Pedro Alves
2016-09-22 19:03 ` [RFA 5/5] Use std::string rather than dyn-string Tom Tromey
2016-09-22 19:10 ` [RFA 0/5] Some random C++-ification Pedro Alves
2016-09-22 19:15 ` Pedro Alves
2016-09-22 23:10 ` Trevor Saunders
2016-09-23 15:47 ` Tom Tromey
2016-09-23 15:49 ` Pedro Alves
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=1474566656-15389-4-git-send-email-tom@tromey.com \
--to=tom@tromey.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