/* Evaluate expressions for GDB.
- Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
+ Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005 Free
Software Foundation, Inc.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
+ Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA. */
#include "defs.h"
#include "gdb_string.h"
fieldno++)
{
char *field_name = TYPE_FIELD_NAME (struct_type, fieldno);
- if (field_name != NULL && DEPRECATED_STREQ (field_name, label))
+ if (field_name != NULL && strcmp (field_name, label) == 0)
{
variantno = -1;
subfieldno = fieldno;
subfieldno < TYPE_NFIELDS (substruct_type);
subfieldno++)
{
- if (DEPRECATED_STREQ (TYPE_FIELD_NAME (substruct_type,
+ if (strcmp(TYPE_FIELD_NAME (substruct_type,
subfieldno),
- label))
+ label) == 0)
{
goto found;
}
if (variantno < 0)
{
fieldno++;
+ /* Skip static fields. */
+ while (fieldno < TYPE_NFIELDS (struct_type)
+ && TYPE_FIELD_STATIC_KIND (struct_type, fieldno))
+ fieldno++;
subfieldno = fieldno;
if (fieldno >= TYPE_NFIELDS (struct_type))
error (_("too many initializers"));
return index;
}
+struct value *
+value_f90_subarray (struct value *array,
+ struct expression *exp, int *pos, enum noside noside)
+{
+ int pc = (*pos) + 1;
+ LONGEST low_bound, high_bound;
+ struct type *range = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
+ enum f90_range_type range_type = longest_to_int (exp->elts[pc].longconst);
+
+ *pos += 3;
+
+ if (range_type == LOW_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
+ low_bound = TYPE_LOW_BOUND (range);
+ else
+ low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
+
+ if (range_type == HIGH_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
+ high_bound = TYPE_HIGH_BOUND (range);
+ else
+ high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
+
+ return value_slice (array, low_bound, high_bound - low_bound + 1);
+}
+
struct value *
evaluate_subexp_standard (struct type *expect_type,
struct expression *exp, int *pos,
&& TYPE_CODE (type) == TYPE_CODE_SET)
{
struct value *set = allocate_value (expect_type);
- char *valaddr = value_contents_raw (set);
+ gdb_byte *valaddr = value_contents_raw (set);
struct type *element_type = TYPE_INDEX_TYPE (type);
struct type *check_type = element_type;
LONGEST low_bound, high_bound;
type = check_typedef (value_type (arg1));
code = TYPE_CODE (type);
+ if (code == TYPE_CODE_PTR)
+ {
+ /* Fortran always passes variable to subroutines as pointer.
+ So we need to look into its target type to see if it is
+ array, string or function. If it is, we need to switch
+ to the target value the original one points to. */
+ struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
+
+ if (TYPE_CODE (target_type) == TYPE_CODE_ARRAY
+ || TYPE_CODE (target_type) == TYPE_CODE_STRING
+ || TYPE_CODE (target_type) == TYPE_CODE_FUNC)
+ {
+ arg1 = value_ind (arg1);
+ type = check_typedef (value_type (arg1));
+ code = TYPE_CODE (type);
+ }
+ }
+
switch (code)
{
case TYPE_CODE_ARRAY:
- goto multi_f77_subscript;
+ if (exp->elts[*pos].opcode == OP_F90_RANGE)
+ return value_f90_subarray (arg1, exp, pos, noside);
+ else
+ goto multi_f77_subscript;
case TYPE_CODE_STRING:
- goto op_f77_substr;
+ if (exp->elts[*pos].opcode == OP_F90_RANGE)
+ return value_f90_subarray (arg1, exp, pos, noside);
+ else
+ {
+ arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
+ return value_subscript (arg1, arg2);
+ }
case TYPE_CODE_PTR:
case TYPE_CODE_FUNC:
error (_("Cannot perform substring on this type"));
}
- op_f77_substr:
- /* We have a substring operation on our hands here,
- let us get the string we will be dealing with */
-
- /* Now evaluate the 'from' and 'to' */
-
- arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
-
- if (nargs < 2)
- return value_subscript (arg1, arg2);
-
- arg3 = evaluate_subexp_with_coercion (exp, pos, noside);
-
- if (noside == EVAL_SKIP)
- goto nosideret;
-
- tem2 = value_as_long (arg2);
- tem3 = value_as_long (arg3);
-
- return value_slice (arg1, tem2, tem3 - tem2 + 1);
-
case OP_COMPLEX:
/* We have a complex number, There should be 2 floating
point numbers that compose it */
else
return value_sub (arg1, arg2);
+ case BINOP_EXP:
case BINOP_MUL:
case BINOP_DIV:
case BINOP_REM:
return value_of_local ("self", 1);
case OP_TYPE:
- error (_("Attempt to use a type name as an expression"));
+ /* The value is not supposed to be used. This is here to make it
+ easier to accommodate expressions that contain types. */
+ (*pos) += 2;
+ if (noside == EVAL_SKIP)
+ goto nosideret;
+ else if (noside == EVAL_AVOID_SIDE_EFFECTS)
+ return allocate_value (exp->elts[pc + 1].type);
+ else
+ error (_("Attempt to use a type name as an expression"));
default:
/* Removing this case and compiling with gcc -Wall reveals that
enum exp_opcode op;
int pc;
struct symbol *var;
+ struct value *x;
pc = (*pos);
op = exp->elts[pc].opcode;
{
case UNOP_IND:
(*pos)++;
- return evaluate_subexp (NULL_TYPE, exp, pos, noside);
+ x = evaluate_subexp (NULL_TYPE, exp, pos, noside);
+
+ /* We can't optimize out "&*" if there's a user-defined operator*. */
+ if (unop_user_defined_p (op, x))
+ {
+ x = value_x_unop (x, op, noside);
+ if (noside == EVAL_AVOID_SIDE_EFFECTS)
+ {
+ if (VALUE_LVAL (x) == lval_memory)
+ return value_zero (lookup_pointer_type (value_type (x)),
+ not_lval);
+ else
+ error (_("Attempt to take address of non-lval"));
+ }
+ return value_addr (x);
+ }
+
+ return x;
case UNOP_MEMVAL:
(*pos) += 3;
default:
default_case:
+ x = evaluate_subexp (NULL_TYPE, exp, pos, noside);
if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
- struct value *x = evaluate_subexp (NULL_TYPE, exp, pos, noside);
if (VALUE_LVAL (x) == lval_memory)
return value_zero (lookup_pointer_type (value_type (x)),
not_lval);
else
error (_("Attempt to take address of non-lval"));
}
- return value_addr (evaluate_subexp (NULL_TYPE, exp, pos, noside));
+ return value_addr (x);
}
}