2011-11-09 Roland McGrath <mcgrathr@google.com>
[deliverable/binutils-gdb.git] / gdb / valops.c
index 32d71cdf86f61754bfee8f8871405a300c975d73..cb39677f45768e8b4378d8d6f01ebc031d0bd243 100644 (file)
@@ -61,20 +61,20 @@ static struct value *search_struct_method (const char *, struct value **,
                                           struct value **,
                                           int, int *, struct type *);
 
-static int find_oload_champ_namespace (struct type **, int,
+static int find_oload_champ_namespace (struct value **, int,
                                       const char *, const char *,
                                       struct symbol ***,
                                       struct badness_vector **,
                                       const int no_adl);
 
 static
-int find_oload_champ_namespace_loop (struct type **, int,
+int find_oload_champ_namespace_loop (struct value **, int,
                                     const char *, const char *,
                                     int, struct symbol ***,
                                     struct badness_vector **, int *,
                                     const int no_adl);
 
-static int find_oload_champ (struct type **, int, int, int,
+static int find_oload_champ (struct value **, int, int, int,
                             struct fn_field *, struct symbol **,
                             struct badness_vector **);
 
@@ -1110,7 +1110,8 @@ value_fetch_lazy (struct value *val)
         watchpoints from trying to watch the saved frame pointer.  */
       value_free_to_mark (mark);
     }
-  else if (VALUE_LVAL (val) == lval_computed)
+  else if (VALUE_LVAL (val) == lval_computed
+          && value_computed_funcs (val)->read != NULL)
     value_computed_funcs (val)->read (val);
   else if (value_optimized_out (val))
     /* Keep it optimized out.  */;
@@ -1381,9 +1382,13 @@ value_assign (struct value *toval, struct value *fromval)
       {
        const struct lval_funcs *funcs = value_computed_funcs (toval);
 
-       funcs->write (toval, fromval);
+       if (funcs->write != NULL)
+         {
+           funcs->write (toval, fromval);
+           break;
+         }
       }
-      break;
+      /* Fall through.  */
 
     default:
       error (_("Left operand of assignment is not an lvalue."));
@@ -1486,7 +1491,7 @@ value_repeat (struct value *arg1, int count)
 }
 
 struct value *
-value_of_variable (struct symbol *var, struct block *b)
+value_of_variable (struct symbol *var, const struct block *b)
 {
   struct frame_info *frame;
 
@@ -2486,7 +2491,7 @@ value_find_oload_method_list (struct value **argp, const char *method,
                           basetype, boffset);
 }
 
-/* Given an array of argument types (ARGTYPES) (which includes an
+/* Given an array of arguments (ARGS) (which includes an
    entry for "this" in the case of C++ methods), the number of
    arguments NARGS, the NAME of a function whether it's a method or
    not (METHOD), and the degree of laxness (LAX) in conforming to
@@ -2529,13 +2534,14 @@ value_find_oload_method_list (struct value **argp, const char *method,
    resolution is permitted.  */
 
 int
-find_overload_match (struct type **arg_types, int nargs, 
+find_overload_match (struct value **args, int nargs,
                     const char *name, enum oload_search_type method,
                     int lax, struct value **objp, struct symbol *fsym,
                     struct value **valp, struct symbol **symp, 
                     int *staticp, const int no_adl)
 {
   struct value *obj = (objp ? *objp : NULL);
+  struct type *obj_type = obj ? value_type (obj) : NULL;
   /* Index of best overloaded function.  */
   int func_oload_champ = -1;
   int method_oload_champ = -1;
@@ -2604,7 +2610,7 @@ find_overload_match (struct type **arg_types, int nargs,
       if (fns_ptr)
        {
          gdb_assert (TYPE_DOMAIN_TYPE (fns_ptr[0].type) != NULL);
-         method_oload_champ = find_oload_champ (arg_types, nargs, method,
+         method_oload_champ = find_oload_champ (args, nargs, method,
                                                 num_fns, fns_ptr,
                                                 oload_syms, &method_badness);
 
@@ -2626,7 +2632,8 @@ find_overload_match (struct type **arg_types, int nargs,
          and non member function, the first argument must now be
          dereferenced.  */
       if (method == BOTH)
-       arg_types[0] = TYPE_TARGET_TYPE (arg_types[0]);
+       deprecated_set_value_type (args[0],
+                                  TYPE_TARGET_TYPE (value_type (args[0])));
 
       if (fsym)
         {
@@ -2672,7 +2679,7 @@ find_overload_match (struct type **arg_types, int nargs,
           return 0;
         }
 
-      func_oload_champ = find_oload_champ_namespace (arg_types, nargs,
+      func_oload_champ = find_oload_champ_namespace (args, nargs,
                                                      func_name,
                                                      qualified_name,
                                                      &oload_syms,
@@ -2776,11 +2783,11 @@ find_overload_match (struct type **arg_types, int nargs,
   if (objp)
     {
       struct type *temp_type = check_typedef (value_type (temp));
-      struct type *obj_type = check_typedef (value_type (*objp));
+      struct type *objtype = check_typedef (obj_type);
 
       if (TYPE_CODE (temp_type) != TYPE_CODE_PTR
-         && (TYPE_CODE (obj_type) == TYPE_CODE_PTR
-             || TYPE_CODE (obj_type) == TYPE_CODE_REF))
+         && (TYPE_CODE (objtype) == TYPE_CODE_PTR
+             || TYPE_CODE (objtype) == TYPE_CODE_REF))
        {
          temp = value_addr (temp);
        }
@@ -2809,7 +2816,7 @@ find_overload_match (struct type **arg_types, int nargs,
    performned.  */
 
 static int
-find_oload_champ_namespace (struct type **arg_types, int nargs,
+find_oload_champ_namespace (struct value **args, int nargs,
                            const char *func_name,
                            const char *qualified_name,
                            struct symbol ***oload_syms,
@@ -2818,7 +2825,7 @@ find_oload_champ_namespace (struct type **arg_types, int nargs,
 {
   int oload_champ;
 
-  find_oload_champ_namespace_loop (arg_types, nargs,
+  find_oload_champ_namespace_loop (args, nargs,
                                   func_name,
                                   qualified_name, 0,
                                   oload_syms, oload_champ_bv,
@@ -2838,7 +2845,7 @@ find_oload_champ_namespace (struct type **arg_types, int nargs,
    *OLOAD_CHAMP_BV.  */
 
 static int
-find_oload_champ_namespace_loop (struct type **arg_types, int nargs,
+find_oload_champ_namespace_loop (struct value **args, int nargs,
                                 const char *func_name,
                                 const char *qualified_name,
                                 int namespace_len,
@@ -2875,7 +2882,7 @@ find_oload_champ_namespace_loop (struct type **arg_types, int nargs,
     {
       searched_deeper = 1;
 
-      if (find_oload_champ_namespace_loop (arg_types, nargs,
+      if (find_oload_champ_namespace_loop (args, nargs,
                                           func_name, qualified_name,
                                           next_namespace_len,
                                           oload_syms, oload_champ_bv,
@@ -2904,12 +2911,22 @@ find_oload_champ_namespace_loop (struct type **arg_types, int nargs,
   /* If we have reached the deepest level perform argument
      determined lookup.  */
   if (!searched_deeper && !no_adl)
-    make_symbol_overload_list_adl (arg_types, nargs, func_name);
+    {
+      int ix;
+      struct type **arg_types;
+
+      /* Prepare list of argument types for overload resolution.  */
+      arg_types = (struct type **)
+       alloca (nargs * (sizeof (struct type *)));
+      for (ix = 0; ix < nargs; ix++)
+       arg_types[ix] = value_type (args[ix]);
+      make_symbol_overload_list_adl (arg_types, nargs, func_name);
+    }
 
   while (new_oload_syms[num_fns])
     ++num_fns;
 
-  new_oload_champ = find_oload_champ (arg_types, nargs, 0, num_fns,
+  new_oload_champ = find_oload_champ (args, nargs, 0, num_fns,
                                      NULL, new_oload_syms,
                                      &new_oload_champ_bv);
 
@@ -2946,7 +2963,7 @@ find_oload_champ_namespace_loop (struct type **arg_types, int nargs,
     }
 }
 
-/* Look for a function to take NARGS args of types ARG_TYPES.  Find
+/* Look for a function to take NARGS args of ARGS.  Find
    the best match from among the overloaded methods or functions
    (depending on METHOD) given by FNS_PTR or OLOAD_SYMS, respectively.
    The number of methods/functions in the list is given by NUM_FNS.
@@ -2956,7 +2973,7 @@ find_oload_champ_namespace_loop (struct type **arg_types, int nargs,
    It is the caller's responsibility to free *OLOAD_CHAMP_BV.  */
 
 static int
-find_oload_champ (struct type **arg_types, int nargs, int method,
+find_oload_champ (struct value **args, int nargs, int method,
                  int num_fns, struct fn_field *fns_ptr,
                  struct symbol **oload_syms,
                  struct badness_vector **oload_champ_bv)
@@ -3002,7 +3019,7 @@ find_oload_champ (struct type **arg_types, int nargs, int method,
       /* Compare parameter types to supplied argument types.  Skip
          THIS for static methods.  */
       bv = rank_function (parm_types, nparms, 
-                         arg_types + static_offset,
+                         args + static_offset,
                          nargs - static_offset);
 
       if (!*oload_champ_bv)
@@ -3076,6 +3093,7 @@ classify_oload_match (struct badness_vector *oload_champ_bv,
                      int static_offset)
 {
   int ix;
+  enum oload_classification worst = STANDARD;
 
   for (ix = 1; ix <= nargs - static_offset; ix++)
     {
@@ -3088,11 +3106,13 @@ classify_oload_match (struct badness_vector *oload_champ_bv,
          NS_POINTER_CONVERSION_BADNESS or worse return NON_STANDARD.  */
       else if (compare_ranks (oload_champ_bv->rank[ix],
                               NS_POINTER_CONVERSION_BADNESS) <= 0)
-       return NON_STANDARD;    /* Non-standard type conversions
+       worst = NON_STANDARD;   /* Non-standard type conversions
                                   needed.  */
     }
 
-  return STANDARD;             /* Only standard conversions needed.  */
+  /* If no INCOMPATIBLE classification was found, return the worst one
+     that was found (if any).  */
+  return worst;
 }
 
 /* C++: return 1 is NAME is a legitimate name for the destructor of
@@ -3226,7 +3246,7 @@ compare_parameters (struct type *t1, struct type *t2, int skip_artificial)
       for (i = 0; i < TYPE_NFIELDS (t2); ++i)
        {
          if (compare_ranks (rank_one_type (TYPE_FIELD_TYPE (t1, start + i),
-                                          TYPE_FIELD_TYPE (t2, i)),
+                                           TYPE_FIELD_TYPE (t2, i), NULL),
                             EXACT_MATCH_BADNESS) != 0)
            return 0;
        }
This page took 0.02856 seconds and 4 git commands to generate.