}
static int
-ptrmath_type_p (struct type *type)
+ptrmath_type_p (const struct language_defn *lang, struct type *type)
{
type = check_typedef (type);
if (TYPE_CODE (type) == TYPE_CODE_REF)
return 1;
case TYPE_CODE_ARRAY:
- return current_language->c_style_arrays;
+ return lang->c_style_arrays;
default:
return 0;
struct type *type;
int nargs;
struct value **argvec;
- int upper, lower, retcode;
+ int upper, lower;
int code;
int ix;
long mem_offset;
struct type **arg_types;
int save_pos1;
+ struct symbol *function = NULL;
+ char *function_name = NULL;
pc = (*pos)++;
op = exp->elts[pc].opcode;
return value_from_decfloat (exp->elts[pc + 1].type,
exp->elts[pc + 2].decfloatconst);
+ case OP_ADL_FUNC:
case OP_VAR_VALUE:
(*pos) += 3;
if (noside == EVAL_SKIP)
/* Now, say which argument to start evaluating from */
tem = 2;
}
+ else if (op == OP_SCOPE
+ && overload_resolution
+ && (exp->language_defn->la_language == language_cplus))
+ {
+ /* Unpack it locally so we can properly handle overload
+ resolution. */
+ char *name;
+ int local_tem;
+
+ pc2 = (*pos)++;
+ local_tem = longest_to_int (exp->elts[pc2 + 2].longconst);
+ (*pos) += 4 + BYTES_TO_EXP_ELEM (local_tem + 1);
+ type = exp->elts[pc2 + 1].type;
+ name = &exp->elts[pc2 + 3].string;
+
+ function = NULL;
+ function_name = NULL;
+ if (TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
+ {
+ function = cp_lookup_symbol_namespace (TYPE_TAG_NAME (type),
+ name,
+ get_selected_block (0),
+ VAR_DOMAIN);
+ if (function == NULL)
+ error (_("No symbol \"%s\" in namespace \"%s\"."),
+ name, TYPE_TAG_NAME (type));
+
+ tem = 1;
+ }
+ else
+ {
+ gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
+ || TYPE_CODE (type) == TYPE_CODE_UNION);
+ function_name = name;
+
+ arg2 = value_zero (type, lval_memory);
+ ++nargs;
+ tem = 2;
+ }
+ }
+ else if (op == OP_ADL_FUNC)
+ {
+ /* Save the function position and move pos so that the arguments
+ can be evaluated. */
+ int func_name_len;
+ save_pos1 = *pos;
+ tem = 1;
+
+ func_name_len = longest_to_int (exp->elts[save_pos1 + 3].longconst);
+ (*pos) += 6 + BYTES_TO_EXP_ELEM (func_name_len + 1);
+ }
else
{
/* Non-method function call */
/* signal end of arglist */
argvec[tem] = 0;
-
- if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
+ if (op == OP_ADL_FUNC)
+ {
+ struct symbol *symp;
+ char *func_name;
+ int name_len;
+ int string_pc = save_pos1 + 3;
+
+ /* Extract the function name. */
+ name_len = longest_to_int (exp->elts[string_pc].longconst);
+ func_name = (char *) alloca (name_len + 1);
+ strcpy (func_name, &exp->elts[string_pc + 1].string);
+
+ /* Prepare list of argument types for overload resolution */
+ arg_types = (struct type **) alloca (nargs * (sizeof (struct type *)));
+ for (ix = 1; ix <= nargs; ix++)
+ arg_types[ix - 1] = value_type (argvec[ix]);
+
+ find_overload_match (arg_types, nargs, func_name,
+ 0 /* not method */ , 0 /* strict match */ ,
+ NULL, NULL /* pass NULL symbol since symbol is unknown */ ,
+ NULL, &symp, NULL, 0);
+
+ /* Now fix the expression being evaluated. */
+ exp->elts[save_pos1 + 2].symbol = symp;
+ argvec[0] = evaluate_subexp_with_coercion (exp, &save_pos1, noside);
+ }
+
+ if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR
+ || (op == OP_SCOPE && function_name != NULL))
{
int static_memfuncp;
- char tstr[256];
+ char *tstr;
/* Method invocation : stuff "this" as first parameter */
argvec[1] = arg2;
- /* Name of method from expression */
- strcpy (tstr, &exp->elts[pc2 + 2].string);
+
+ if (op != OP_SCOPE)
+ {
+ /* Name of method from expression */
+ tstr = &exp->elts[pc2 + 2].string;
+ }
+ else
+ tstr = function_name;
if (overload_resolution && (exp->language_defn->la_language == language_cplus))
{
(void) find_overload_match (arg_types, nargs, tstr,
1 /* method */ , 0 /* strict match */ ,
&arg2 /* the object */ , NULL,
- &valp, NULL, &static_memfuncp);
-
+ &valp, NULL, &static_memfuncp, 0);
+ if (op == OP_SCOPE && !static_memfuncp)
+ {
+ /* For the time being, we don't handle this. */
+ error (_("Call to overloaded function %s requires "
+ "`this' pointer"),
+ function_name);
+ }
argvec[1] = arg2; /* the ``this'' pointer */
argvec[0] = valp; /* use the method found after overload resolution */
}
argvec[1] = arg2;
argvec[0] = arg1;
}
- else if (op == OP_VAR_VALUE)
+ else if (op == OP_VAR_VALUE || (op == OP_SCOPE && function != NULL))
{
/* Non-member function being called */
/* fn: This can only be done for C++ functions. A C-style function
{
/* Language is C++, do some overload resolution before evaluation */
struct symbol *symp;
+ int no_adl = 0;
+
+ /* If a scope has been specified disable ADL. */
+ if (op == OP_SCOPE)
+ no_adl = 1;
+
+ if (op == OP_VAR_VALUE)
+ function = exp->elts[save_pos1+2].symbol;
/* Prepare list of argument types for overload resolution */
arg_types = (struct type **) alloca (nargs * (sizeof (struct type *)));
(void) find_overload_match (arg_types, nargs, NULL /* no need for name */ ,
0 /* not method */ , 0 /* strict match */ ,
- NULL, exp->elts[save_pos1+2].symbol /* the function */ ,
- NULL, &symp, NULL);
+ NULL, function /* the function */ ,
+ NULL, &symp, NULL, no_adl);
- /* Now fix the expression being evaluated */
- exp->elts[save_pos1+2].symbol = symp;
- argvec[0] = evaluate_subexp_with_coercion (exp, &save_pos1, noside);
+ if (op == OP_VAR_VALUE)
+ {
+ /* Now fix the expression being evaluated */
+ exp->elts[save_pos1+2].symbol = symp;
+ argvec[0] = evaluate_subexp_with_coercion (exp, &save_pos1,
+ noside);
+ }
+ else
+ argvec[0] = value_of_variable (symp, get_selected_block (0));
}
else
{
op = exp->elts[pc + 1].opcode;
if (binop_user_defined_p (op, arg1, arg2))
return value_x_binop (arg1, arg2, BINOP_ASSIGN_MODIFY, op, noside);
- else if (op == BINOP_ADD && ptrmath_type_p (value_type (arg1))
+ else if (op == BINOP_ADD && ptrmath_type_p (exp->language_defn,
+ value_type (arg1))
&& is_integral_type (value_type (arg2)))
arg2 = value_ptradd (arg1, value_as_long (arg2));
- else if (op == BINOP_SUB && ptrmath_type_p (value_type (arg1))
+ else if (op == BINOP_SUB && ptrmath_type_p (exp->language_defn,
+ value_type (arg1))
&& is_integral_type (value_type (arg2)))
arg2 = value_ptradd (arg1, - value_as_long (arg2));
else
goto nosideret;
if (binop_user_defined_p (op, arg1, arg2))
return value_x_binop (arg1, arg2, op, OP_NULL, noside);
- else if (ptrmath_type_p (value_type (arg1))
+ else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
&& is_integral_type (value_type (arg2)))
return value_ptradd (arg1, value_as_long (arg2));
- else if (ptrmath_type_p (value_type (arg2))
+ else if (ptrmath_type_p (exp->language_defn, value_type (arg2))
&& is_integral_type (value_type (arg1)))
return value_ptradd (arg2, value_as_long (arg1));
else
goto nosideret;
if (binop_user_defined_p (op, arg1, arg2))
return value_x_binop (arg1, arg2, op, OP_NULL, noside);
- else if (ptrmath_type_p (value_type (arg1))
- && ptrmath_type_p (value_type (arg2)))
+ else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
+ && ptrmath_type_p (exp->language_defn, value_type (arg2)))
{
/* FIXME -- should be ptrdiff_t */
type = builtin_type (exp->gdbarch)->builtin_long;
return value_from_longest (type, value_ptrdiff (arg1, arg2));
}
- else if (ptrmath_type_p (value_type (arg1))
+ else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
&& is_integral_type (value_type (arg2)))
return value_ptradd (arg1, - value_as_long (arg2));
else
}
else
{
- if (ptrmath_type_p (value_type (arg1)))
+ if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
arg2 = value_ptradd (arg1, 1);
else
{
}
else
{
- if (ptrmath_type_p (value_type (arg1)))
+ if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
arg2 = value_ptradd (arg1, -1);
else
{
}
else
{
- if (ptrmath_type_p (value_type (arg1)))
+ if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
arg2 = value_ptradd (arg1, 1);
else
{
}
else
{
- if (ptrmath_type_p (value_type (arg1)))
+ if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
arg2 = value_ptradd (arg1, -1);
else
{
goto default_case_after_eval;
}
- return x;
+ return coerce_array (x);
case UNOP_MEMVAL:
(*pos) += 3;
var = exp->elts[pc + 2].symbol;
type = check_typedef (SYMBOL_TYPE (var));
if (TYPE_CODE (type) == TYPE_CODE_ARRAY
- && CAST_IS_CONVERSION)
+ && CAST_IS_CONVERSION (exp->language_defn))
{
(*pos) += 4;
val = address_of_variable (var, exp->elts[pc + 1].block);