Implement binary comparison operations
[deliverable/binutils-gdb.git] / gdb / eval.c
index 87c8b0d69e001853efd9ad82198f93cbd5e8627a..83d0147f96e4efce3f6b291467d8b7494c1117a0 100644 (file)
@@ -1511,7 +1511,7 @@ eval_op_sub (struct type *expect_type, struct expression *exp,
 
 /* Helper function for several different binary operations.  */
 
-static struct value *
+struct value *
 eval_op_binary (struct type *expect_type, struct expression *exp,
                enum noside noside, enum exp_opcode op,
                struct value *arg1, struct value *arg2)
@@ -1558,7 +1558,7 @@ eval_op_binary (struct type *expect_type, struct expression *exp,
 
 /* A helper function for BINOP_SUBSCRIPT.  */
 
-static struct value *
+struct value *
 eval_op_subscript (struct type *expect_type, struct expression *exp,
                   enum noside noside, enum exp_opcode op,
                   struct value *arg1, struct value *arg2)
@@ -1594,7 +1594,7 @@ eval_op_subscript (struct type *expect_type, struct expression *exp,
 
 /* A helper function for BINOP_EQUAL.  */
 
-static struct value *
+struct value *
 eval_op_equal (struct type *expect_type, struct expression *exp,
               enum noside noside, enum exp_opcode op,
               struct value *arg1, struct value *arg2)
@@ -1617,7 +1617,7 @@ eval_op_equal (struct type *expect_type, struct expression *exp,
 
 /* A helper function for BINOP_NOTEQUAL.  */
 
-static struct value *
+struct value *
 eval_op_notequal (struct type *expect_type, struct expression *exp,
                  enum noside noside, enum exp_opcode op,
                  struct value *arg1, struct value *arg2)
@@ -1640,7 +1640,7 @@ eval_op_notequal (struct type *expect_type, struct expression *exp,
 
 /* A helper function for BINOP_LESS.  */
 
-static struct value *
+struct value *
 eval_op_less (struct type *expect_type, struct expression *exp,
              enum noside noside, enum exp_opcode op,
              struct value *arg1, struct value *arg2)
@@ -1663,7 +1663,7 @@ eval_op_less (struct type *expect_type, struct expression *exp,
 
 /* A helper function for BINOP_GTR.  */
 
-static struct value *
+struct value *
 eval_op_gtr (struct type *expect_type, struct expression *exp,
             enum noside noside, enum exp_opcode op,
             struct value *arg1, struct value *arg2)
@@ -1686,7 +1686,7 @@ eval_op_gtr (struct type *expect_type, struct expression *exp,
 
 /* A helper function for BINOP_GEQ.  */
 
-static struct value *
+struct value *
 eval_op_geq (struct type *expect_type, struct expression *exp,
             enum noside noside, enum exp_opcode op,
             struct value *arg1, struct value *arg2)
@@ -1709,7 +1709,7 @@ eval_op_geq (struct type *expect_type, struct expression *exp,
 
 /* A helper function for BINOP_LEQ.  */
 
-static struct value *
+struct value *
 eval_op_leq (struct type *expect_type, struct expression *exp,
             enum noside noside, enum exp_opcode op,
             struct value *arg1, struct value *arg2)
@@ -3536,6 +3536,39 @@ var_msym_value_operation::evaluate_for_sizeof (struct expression *exp,
   return value_from_longest (size_type, TYPE_LENGTH (type));
 }
 
+value *
+subscript_operation::evaluate_for_sizeof (struct expression *exp,
+                                         enum noside noside)
+{
+  if (noside == EVAL_NORMAL)
+    {
+      value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
+                                                     EVAL_AVOID_SIDE_EFFECTS);
+      struct type *type = check_typedef (value_type (val));
+      if (type->code () == TYPE_CODE_ARRAY)
+       {
+         type = check_typedef (TYPE_TARGET_TYPE (type));
+         if (type->code () == TYPE_CODE_ARRAY)
+           {
+             type = type->index_type ();
+             /* Only re-evaluate the right hand side if the resulting type
+                is a variable length type.  */
+             if (type->bounds ()->flag_bound_evaluated)
+               {
+                 val = evaluate (nullptr, exp, EVAL_NORMAL);
+                 /* FIXME: This should be size_t.  */
+                 struct type *size_type
+                   = builtin_type (exp->gdbarch)->builtin_int;
+                 return value_from_longest
+                   (size_type, (LONGEST) TYPE_LENGTH (value_type (val)));
+               }
+           }
+       }
+    }
+
+  return operation::evaluate_for_sizeof (exp, noside);
+}
+
 }
 
 /* Evaluate a subexpression of EXP, at index *POS, and return a value
This page took 0.132828 seconds and 4 git commands to generate.