/* Perform arithmetic and other operations on values, for GDB.
- Copyright (C) 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
- 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009,
- 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 1986, 1988-2005, 2007-2012 Free Software Foundation,
+ Inc.
This file is part of GDB.
#include "exceptions.h"
/* Define whether or not the C operator '/' truncates towards zero for
- differently signed operands (truncation direction is undefined in C). */
+ differently signed operands (truncation direction is undefined in C). */
#ifndef TRUNCATION_TOWARDS_ZERO
#define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2)
If the pointer type is void *, then return 1.
If the target type is incomplete, then error out.
This isn't a general purpose function, but just a
- helper for value_ptradd.
-*/
+ helper for value_ptradd. */
static LONGEST
find_size_for_pointer_math (struct type *ptr_type)
sz = 1;
else
{
- char *name;
+ const char *name;
name = TYPE_NAME (ptr_target);
if (name == NULL)
if (TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1)))
!= TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type2))))
- error (_("\
-First argument of `-' is a pointer and second argument is neither\n\
-an integer nor a pointer of the same type."));
+ error (_("First argument of `-' is a pointer and "
+ "second argument is neither\n"
+ "an integer nor a pointer of the same type."));
sz = TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1)));
if (sz == 0)
See comments in value_coerce_array() for rationale for reason for
doing lower bounds adjustment here rather than there.
FIXME: Perhaps we should validate that the index is valid and if
- verbosity is set, warn about invalid indices (but still use them). */
+ verbosity is set, warn about invalid indices (but still use them). */
struct value *
value_subscript (struct value *array, LONGEST index)
&& elt_offs >= TYPE_LENGTH (array_type)))
error (_("no such vector element"));
- v = allocate_value (elt_type);
if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
- set_value_lazy (v, 1);
+ v = allocate_value_lazy (elt_type);
else
- memcpy (value_contents_writeable (v),
- value_contents (array) + elt_offs, elt_size);
+ {
+ v = allocate_value (elt_type);
+ value_contents_copy (v, value_embedded_offset (v),
+ array, value_embedded_offset (array) + elt_offs,
+ elt_size);
+ }
set_value_component_location (v, array);
VALUE_REGNUM (v) = VALUE_REGNUM (array);
if (op == UNOP_ADDR)
return 0;
type1 = check_typedef (value_type (arg1));
- for (;;)
- {
- if (TYPE_CODE (type1) == TYPE_CODE_STRUCT)
- return 1;
- else if (TYPE_CODE (type1) == TYPE_CODE_REF)
- type1 = TYPE_TARGET_TYPE (type1);
- else
- return 0;
- }
+ if (TYPE_CODE (type1) == TYPE_CODE_REF)
+ type1 = check_typedef (TYPE_TARGET_TYPE (type1));
+ return TYPE_CODE (type1) == TYPE_CODE_STRUCT;
}
/* Try to find an operator named OPERATOR which takes NARGS arguments
struct symbol *symp = NULL;
struct value *valp = NULL;
- struct type **arg_types;
- int i;
-
- arg_types = (struct type **) alloca (nargs * (sizeof (struct type *)));
- /* Prepare list of argument types for overload resolution */
- for (i = 0; i < nargs; i++)
- arg_types[i] = value_type (args[i]);
- find_overload_match (arg_types, nargs, operator, BOTH /* could be method */,
+ find_overload_match (args, nargs, operator, BOTH /* could be method */,
0 /* strict match */, &args[0], /* objp */
NULL /* pass NULL symbol since symbol is unknown */,
&valp, &symp, static_memfuncp, 0);
argvec[2] = arg2;
argvec[3] = 0;
- /* make the right function name up */
+ /* Make the right function name up. */
strcpy (tstr, "operator__");
ptr = tstr + 8;
switch (op)
= TYPE_TARGET_TYPE (check_typedef (value_type (argvec[0])));
return value_zero (return_type, VALUE_LVAL (arg1));
}
- return call_function_by_hand (argvec[0], 2 - static_memfuncp, argvec + 1);
+ return call_function_by_hand (argvec[0], 2 - static_memfuncp,
+ argvec + 1);
}
throw_error (NOT_FOUND_ERROR,
_("member function %s not found"), tstr);
}
/* We know that arg1 is a structure, so try to find a unary user
- defined operator that matches the operator in question.
+ defined operator that matches the operator in question.
Create an argument vector that calls arg1.operator @ (arg1)
and return that value (where '@' is (almost) any unary operator which
is legal for GNU C++). */
nargs = 1;
- /* make the right function name up */
+ /* Make the right function name up. */
strcpy (tstr, "operator__");
ptr = tstr + 8;
strcpy (mangle_tstr, "__");
values of length 1.
(3) Character values are also allowed and are treated as character
- string values of length 1.
- */
+ string values of length 1. */
struct value *
value_concat (struct value *arg1, struct value *arg2)
or a repeat count and a value to be repeated. INVAL1 is set to the
first of two concatenated values, or the repeat count. INVAL2 is set
to the second of the two concatenated values or the value to be
- repeated. */
+ repeated. */
if (TYPE_CODE (type2) == TYPE_CODE_INT)
{
inval2 = arg2;
}
- /* Now process the input values. */
+ /* Now process the input values. */
if (TYPE_CODE (type1) == TYPE_CODE_INT)
{
/* We have a repeat count. Validate the second value and then
- construct a value repeated that many times. */
+ construct a value repeated that many times. */
if (TYPE_CODE (type2) == TYPE_CODE_STRING
|| TYPE_CODE (type2) == TYPE_CODE_CHAR)
{
else if (TYPE_CODE (type1) == TYPE_CODE_STRING
|| TYPE_CODE (type1) == TYPE_CODE_CHAR)
{
- /* We have two character strings to concatenate. */
+ /* We have two character strings to concatenate. */
if (TYPE_CODE (type2) != TYPE_CODE_STRING
&& TYPE_CODE (type2) != TYPE_CODE_CHAR)
{
else if (TYPE_CODE (type1) == TYPE_CODE_BITSTRING
|| TYPE_CODE (type1) == TYPE_CODE_BOOL)
{
- /* We have two bitstrings to concatenate. */
+ /* We have two bitstrings to concatenate. */
if (TYPE_CODE (type2) != TYPE_CODE_BITSTRING
&& TYPE_CODE (type2) != TYPE_CODE_BOOL)
{
- error (_("Bitstrings or booleans can only be concatenated with other bitstrings or booleans."));
+ error (_("Bitstrings or booleans can only be concatenated "
+ "with other bitstrings or booleans."));
}
error (_("unimplemented support for bitstring/boolean concatenation."));
}
else
{
- /* We don't know how to concatenate these operands. */
+ /* We don't know how to concatenate these operands. */
error (_("illegal operands for concatenation."));
}
return (outval);
\f
/* Integer exponentiation: V1**V2, where both arguments are
integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
+
static LONGEST
integer_pow (LONGEST v1, LONGEST v2)
{
}
else
{
- /* The Russian Peasant's Algorithm */
+ /* The Russian Peasant's Algorithm. */
LONGEST v;
v = 1;
/* Integer exponentiation: V1**V2, where both arguments are
integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
+
static ULONGEST
uinteger_pow (ULONGEST v1, LONGEST v2)
{
}
else
{
- /* The Russian Peasant's Algorithm */
+ /* The Russian Peasant's Algorithm. */
ULONGEST v;
v = 1;
/* The DFP extension to the C language does not allow mixing of
* decimal float types with other float types in expressions
* (see WDTR 24732, page 12). */
- error (_("Mixing decimal floating types with other floating types is not allowed."));
+ error (_("Mixing decimal floating types with "
+ "other floating types is not allowed."));
/* Obtain decimal value of arg1, converting from other types
if necessary. */
errno = 0;
v = pow (v1, v2);
if (errno)
- error (_("Cannot perform exponentiation: %s"), safe_strerror (errno));
+ error (_("Cannot perform exponentiation: %s"),
+ safe_strerror (errno));
break;
case BINOP_MIN:
case BINOP_MOD:
/* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
- v1 mod 0 has a defined value, v1. */
+ v1 mod 0 has a defined value, v1. */
if (v2 == 0)
{
v = v1;
else
{
v = v1 / v2;
- /* Note floor(v1/v2) == v1/v2 for unsigned. */
+ /* Note floor(v1/v2) == v1/v2 for unsigned. */
v = v1 - (v2 * v);
}
break;
case BINOP_MOD:
/* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
- X mod 0 has a defined value, X. */
+ X mod 0 has a defined value, X. */
if (v2 == 0)
{
v = v1;
else
{
v = v1 / v2;
- /* Compute floor. */
+ /* Compute floor. */
if (TRUNCATION_TOWARDS_ZERO && (v < 0) && ((v1 % v2) != 0))
{
v--;
}
/* Perform a comparison on two string values (whose content are not
- necessarily null terminated) based on their length */
+ necessarily null terminated) based on their length. */
static int
value_strcmp (struct value *arg1, struct value *arg2)
else
{
error (_("Invalid type combination in equality test."));
- return 0; /* For lint -- never reached */
+ return 0; /* For lint -- never reached. */
}
}
}
else
{
- error ("Argument to positive operation not a number.");
- return 0; /* For lint -- never reached */
+ error (_("Argument to positive operation not a number."));
+ return 0; /* For lint -- never reached. */
}
}
{
struct value *val = allocate_value (type);
int len = TYPE_LENGTH (type);
- gdb_byte decbytes[16]; /* a decfloat is at most 128 bits long */
+ gdb_byte decbytes[16]; /* a decfloat is at most 128 bits long. */
memcpy (decbytes, value_contents (arg1), len);
else
{
error (_("Argument to negate operation not a number."));
- return 0; /* For lint -- never reached */
+ return 0; /* For lint -- never reached. */
}
}
\f
/* The INDEX'th bit of SET value whose value_type is TYPE,
and whose value_contents is valaddr.
- Return -1 if out of range, -2 other error. */
+ Return -1 if out of range, -2 other error. */
int
value_bit_index (struct type *type, const gdb_byte *valaddr, int index)