forked from Imagelibrary/binutils-gdb
Use std::string, std::vector in rust-lang.c
This patch changes some spots in rust-lang.c to use std::string or std::vector, removing some cleanups. 2016-09-23 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.
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
2016-09-23 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-23 Tom Tromey <tom@tromey.com>
|
2016-09-23 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* cp-namespace.c: Include <string>.
|
* cp-namespace.c: Include <string>.
|
||||||
|
|||||||
@@ -32,6 +32,8 @@
|
|||||||
#include "rust-lang.h"
|
#include "rust-lang.h"
|
||||||
#include "valprint.h"
|
#include "valprint.h"
|
||||||
#include "varobj.h"
|
#include "varobj.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
extern initialize_file_ftype _initialize_rust_language;
|
extern initialize_file_ftype _initialize_rust_language;
|
||||||
|
|
||||||
@@ -1154,10 +1156,7 @@ rust_evaluate_funcall (struct expression *exp, int *pos, enum noside noside)
|
|||||||
int i;
|
int i;
|
||||||
int num_args = exp->elts[*pos + 1].longconst;
|
int num_args = exp->elts[*pos + 1].longconst;
|
||||||
const char *method;
|
const char *method;
|
||||||
char *name;
|
|
||||||
struct value *function, *result, *arg0;
|
struct value *function, *result, *arg0;
|
||||||
struct value **args;
|
|
||||||
struct cleanup *cleanup;
|
|
||||||
struct type *type, *fn_type;
|
struct type *type, *fn_type;
|
||||||
const struct block *block;
|
const struct block *block;
|
||||||
struct block_symbol sym;
|
struct block_symbol sym;
|
||||||
@@ -1183,8 +1182,7 @@ rust_evaluate_funcall (struct expression *exp, int *pos, enum noside noside)
|
|||||||
return arg0;
|
return arg0;
|
||||||
}
|
}
|
||||||
|
|
||||||
args = XNEWVEC (struct value *, num_args + 1);
|
std::vector<struct value *> args (num_args + 1);
|
||||||
cleanup = make_cleanup (xfree, args);
|
|
||||||
args[0] = arg0;
|
args[0] = arg0;
|
||||||
|
|
||||||
/* We don't yet implement real Deref semantics. */
|
/* We don't yet implement real Deref semantics. */
|
||||||
@@ -1200,17 +1198,16 @@ rust_evaluate_funcall (struct expression *exp, int *pos, enum noside noside)
|
|||||||
if (TYPE_TAG_NAME (type) == NULL)
|
if (TYPE_TAG_NAME (type) == NULL)
|
||||||
error (_("Method call on nameless type"));
|
error (_("Method call on nameless type"));
|
||||||
|
|
||||||
name = concat (TYPE_TAG_NAME (type), "::", method, (char *) NULL);
|
std::string name = std::string (TYPE_TAG_NAME (type)) + "::" + method;
|
||||||
make_cleanup (xfree, name);
|
|
||||||
|
|
||||||
block = get_selected_block (0);
|
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)
|
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);
|
fn_type = SYMBOL_TYPE (sym.symbol);
|
||||||
if (TYPE_NFIELDS (fn_type) == 0)
|
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)
|
if (TYPE_CODE (TYPE_FIELD_TYPE (fn_type, 0)) == TYPE_CODE_PTR)
|
||||||
args[0] = value_addr (args[0]);
|
args[0] = value_addr (args[0]);
|
||||||
@@ -1223,8 +1220,7 @@ rust_evaluate_funcall (struct expression *exp, int *pos, enum noside noside)
|
|||||||
if (noside == EVAL_AVOID_SIDE_EFFECTS)
|
if (noside == EVAL_AVOID_SIDE_EFFECTS)
|
||||||
result = value_zero (TYPE_TARGET_TYPE (fn_type), not_lval);
|
result = value_zero (TYPE_TARGET_TYPE (fn_type), not_lval);
|
||||||
else
|
else
|
||||||
result = call_function_by_hand (function, num_args + 1, args);
|
result = call_function_by_hand (function, num_args + 1, args.data ());
|
||||||
do_cleanups (cleanup);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1601,14 +1597,11 @@ rust_evaluate_subexp (struct type *expect_type, struct expression *exp,
|
|||||||
{
|
{
|
||||||
CORE_ADDR addr;
|
CORE_ADDR addr;
|
||||||
int i;
|
int i;
|
||||||
struct value **eltvec = XNEWVEC (struct value *, copies);
|
std::vector<struct value *> eltvec (copies);
|
||||||
struct cleanup *cleanup = make_cleanup (xfree, eltvec);
|
|
||||||
|
|
||||||
for (i = 0; i < copies; ++i)
|
for (i = 0; i < copies; ++i)
|
||||||
eltvec[i] = elt;
|
eltvec[i] = elt;
|
||||||
result = value_array (0, copies - 1, eltvec);
|
result = value_array (0, copies - 1, eltvec.data ());
|
||||||
|
|
||||||
do_cleanups (cleanup);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -2036,14 +2029,12 @@ rust_lookup_symbol_nonlocal (const struct language_defn *langdef,
|
|||||||
|
|
||||||
if (scope[0] != '\0')
|
if (scope[0] != '\0')
|
||||||
{
|
{
|
||||||
char *scopedname = concat (scope, "::", name, (char *) NULL);
|
std::string scopedname = std::string (scope) + "::" + name;
|
||||||
struct cleanup *cleanup = make_cleanup (xfree, scopedname);
|
|
||||||
|
|
||||||
result = lookup_symbol_in_static_block (scopedname, block,
|
result = lookup_symbol_in_static_block (scopedname.c_str (), block,
|
||||||
domain);
|
domain);
|
||||||
if (result.symbol == NULL)
|
if (result.symbol == NULL)
|
||||||
result = lookup_global_symbol (scopedname, block, domain);
|
result = lookup_global_symbol (scopedname.c_str (), block, domain);
|
||||||
do_cleanups (cleanup);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user