Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008,
- 2009 Free Software Foundation, Inc.
+ 2009, 2010 Free Software Foundation, Inc.
This file is part of GDB.
#include "regcache.h"
#include "user-regs.h"
#include "valprint.h"
+#include "gdb_obstack.h"
+#include "objfiles.h"
#include "python/python.h"
#include "gdb_assert.h"
}
}
+/* Constructs a fake method with the given parameter types.
+ This function is used by the parser to construct an "expected"
+ type for method overload resolution. */
+
+static struct type *
+make_params (int num_types, struct type **param_types)
+{
+ struct type *type = XZALLOC (struct type);
+ TYPE_MAIN_TYPE (type) = XZALLOC (struct main_type);
+ TYPE_LENGTH (type) = 1;
+ TYPE_CODE (type) = TYPE_CODE_METHOD;
+ TYPE_VPTR_FIELDNO (type) = -1;
+ TYPE_CHAIN (type) = type;
+ TYPE_NFIELDS (type) = num_types;
+ TYPE_FIELDS (type) = (struct field *)
+ TYPE_ZALLOC (type, sizeof (struct field) * num_types);
+
+ while (num_types-- > 0)
+ TYPE_FIELD_TYPE (type, num_types) = param_types[num_types];
+
+ return type;
+}
+
struct value *
evaluate_subexp_standard (struct type *expect_type,
struct expression *exp, int *pos,
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;
goto nosideret;
arg1 = value_aggregate_elt (exp->elts[pc + 1].type,
&exp->elts[pc + 3].string,
- 0, noside);
+ expect_type, 0, noside);
if (arg1 == NULL)
error (_("There is no field named %s"), &exp->elts[pc + 3].string);
return arg1;
/* 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. */
+ struct type *qual_type;
+ 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
{
/* Non-method function call */
/* signal end of arglist */
argvec[tem] = 0;
- if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
+ 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))
{
&arg2 /* the object */ , NULL,
&valp, NULL, &static_memfuncp);
-
+ 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;
+ 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 *)));
for (ix = 1; ix <= nargs; ix++)
(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, function /* the function */ ,
NULL, &symp, NULL);
- /* 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
{
error (_("non-pointer-to-member value used in pointer-to-member construct"));
}
+ case TYPE_INSTANCE:
+ nargs = longest_to_int (exp->elts[pc + 1].longconst);
+ arg_types = (struct type **) alloca (nargs * sizeof (struct type *));
+ for (ix = 0; ix < nargs; ++ix)
+ arg_types[ix] = exp->elts[pc + 1 + ix + 1].type;
+
+ expect_type = make_params (nargs, arg_types);
+ *(pos) += 3 + nargs;
+ arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside);
+ xfree (TYPE_FIELDS (expect_type));
+ xfree (TYPE_MAIN_TYPE (expect_type));
+ xfree (expect_type);
+ return arg1;
+
case BINOP_CONCAT:
arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
arg1 = value_cast (type, arg1);
return arg1;
+ case UNOP_DYNAMIC_CAST:
+ (*pos) += 2;
+ type = exp->elts[pc + 1].type;
+ arg1 = evaluate_subexp (type, exp, pos, noside);
+ if (noside == EVAL_SKIP)
+ goto nosideret;
+ return value_dynamic_cast (type, arg1);
+
+ case UNOP_REINTERPRET_CAST:
+ (*pos) += 2;
+ type = exp->elts[pc + 1].type;
+ arg1 = evaluate_subexp (type, exp, pos, noside);
+ if (noside == EVAL_SKIP)
+ goto nosideret;
+ return value_reinterpret_cast (type, arg1);
+
case UNOP_MEMVAL:
(*pos) += 2;
arg1 = evaluate_subexp (expect_type, exp, pos, noside);
goto default_case_after_eval;
}
- return x;
+ return coerce_array (x);
case UNOP_MEMVAL:
(*pos) += 3;
(*pos) += 5 + BYTES_TO_EXP_ELEM (tem + 1);
x = value_aggregate_elt (exp->elts[pc + 1].type,
&exp->elts[pc + 3].string,
- 1, noside);
+ NULL, 1, noside);
if (x == NULL)
error (_("There is no field named %s"), &exp->elts[pc + 3].string);
return x;