Support overloading of 'operator->'.
authorSami Wagiaalla <swagiaal@redhat.com>
Tue, 19 Oct 2010 20:53:15 +0000 (20:53 +0000)
committerSami Wagiaalla <swagiaal@redhat.com>
Tue, 19 Oct 2010 20:53:15 +0000 (20:53 +0000)
2010-10-19  Sami Wagiaalla  <swagiaal@redhat.com>

 PR C++/11500:
* valarith.c (value_x_unop): Handle STRUCTOP_PTR.
* eval.c (evaluate_subexp_standard): Check for overload of
'operator->'.
* valarith.c (value_x_binop): Throw NOT_FOUND_ERROR.
(value_x_unop): Ditto.
* valops.c: Include "exceptions.h".
(find_overload_match): Throw NOT_FOUND_ERROR.
(value_struct_elt): Ditto.

2010-10-19  Sami Wagiaalla  <swagiaal@redhat.com>

* gdb.cp/smartp.exp: New test.
* gdb.cp/smartp.cc : New test.

gdb/ChangeLog
gdb/eval.c
gdb/testsuite/ChangeLog
gdb/valarith.c
gdb/valops.c

index d2b0c89758198b764cb7b4f2d2dfd0ba8a46ad16..13336bad5e84db6d2fada995fa30653e3776df86 100644 (file)
@@ -1,3 +1,15 @@
+2010-10-19  Sami Wagiaalla  <swagiaal@redhat.com>
+
+        PR C++/11500:
+       * valarith.c (value_x_unop): Handle STRUCTOP_PTR.
+       * eval.c (evaluate_subexp_standard): Check for overload of
+       'operator->'.
+       * valarith.c (value_x_binop): Throw NOT_FOUND_ERROR.
+       (value_x_unop): Ditto.
+       * valops.c: Include "exceptions.h".
+       (find_overload_match): Throw NOT_FOUND_ERROR.
+       (value_struct_elt): Ditto.
+
 2010-10-19  Tom Tromey  <tromey@redhat.com>
 
        * python/py-cmd.c (cmdpy_function): Unreference exception state.
index 635db34e22a89635c1fe0f3d90bb066646774e48..471dcd7a56359a7844ac161e19c65ef12ae58282 100644 (file)
@@ -1510,6 +1510,28 @@ evaluate_subexp_standard (struct type *expect_type,
          else
            {
              arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
+
+             /* Check to see if the operator '->' has been overloaded.  If the operator
+                has been overloaded replace arg2 with the value returned by the custom
+                operator and continue evaluation.  */
+             while (unop_user_defined_p (op, arg2))
+               {
+                 volatile struct gdb_exception except;
+                 struct value *value = NULL;
+                 TRY_CATCH (except, RETURN_MASK_ERROR)
+                   {
+                     value = value_x_unop (arg2, op, noside);
+                   }
+
+                 if (except.reason < 0)
+                   {
+                     if (except.error == NOT_FOUND_ERROR)
+                       break;
+                     else
+                       throw_exception (except);
+                   }
+                 arg2 = value;
+               }
            }
          /* Now, say which argument to start evaluating from */
          tem = 2;
@@ -1898,6 +1920,27 @@ evaluate_subexp_standard (struct type *expect_type,
       if (noside == EVAL_SKIP)
        goto nosideret;
 
+      /* Check to see if operator '->' has been overloaded.  If so replace
+         arg1 with the value returned by evaluating operator->().  */
+      while (unop_user_defined_p (op, arg1))
+       {
+         volatile struct gdb_exception except;
+         struct value *value = NULL;
+         TRY_CATCH (except, RETURN_MASK_ERROR)
+           {
+             value = value_x_unop (arg1, op, noside);
+           }
+
+         if (except.reason < 0)
+           {
+             if (except.error == NOT_FOUND_ERROR)
+               break;
+             else
+               throw_exception (except);
+           }
+         arg1 = value;
+       }
+
       /* JYG: if print object is on we need to replace the base type
         with rtti type in order to continue on with successful
         lookup of member / method only available in the rtti type. */
index 824796e0659dd99057c2e9d1c3b96e9a5a9d5d4d..2bdc9d01e06042a259a93d6f735b9caa6304638b 100644 (file)
@@ -1,3 +1,8 @@
+2010-10-19  Sami Wagiaalla  <swagiaal@redhat.com>
+
+       * gdb.cp/smartp.exp: New test.
+       * gdb.cp/smartp.cc : New test.
+
 2010-10-19  Sami Wagiaalla  <swagiaal@redhat.com>
 
        * gdb.cp/converts.exp: Test pointer to bool conversion.
index 554c4ff3a2966c38294e8f104b39b7fb693aa73c..88f1448b0dd2e9c13db088c10987ecc2e943c60e 100644 (file)
@@ -541,7 +541,8 @@ value_x_binop (struct value *arg1, struct value *arg2, enum exp_opcode op,
        }
       return call_function_by_hand (argvec[0], 2 - static_memfuncp, argvec + 1);
     }
-  error (_("member function %s not found"), tstr);
+  throw_error (NOT_FOUND_ERROR,
+               _("member function %s not found"), tstr);
 #ifdef lint
   return call_function_by_hand (argvec[0], 2 - static_memfuncp, argvec + 1);
 #endif
@@ -616,6 +617,9 @@ value_x_unop (struct value *arg1, enum exp_opcode op, enum noside noside)
     case UNOP_IND:
       strcpy (ptr, "*");
       break;
+    case STRUCTOP_PTR:
+      strcpy (ptr, "->");
+      break;
     default:
       error (_("Invalid unary operation specified."));
     }
@@ -641,7 +645,9 @@ value_x_unop (struct value *arg1, enum exp_opcode op, enum noside noside)
        }
       return call_function_by_hand (argvec[0], nargs, argvec + 1);
     }
-  error (_("member function %s not found"), tstr);
+  throw_error (NOT_FOUND_ERROR,
+               _("member function %s not found"), tstr);
+
   return 0;                    /* For lint -- never reached */
 }
 \f
index fe4576ec8aec8da207088388c7063208a12fe552..07b62a165c7c7336324e04762c7d545ffb5ce736 100644 (file)
@@ -46,6 +46,7 @@
 #include "observer.h"
 #include "objfiles.h"
 #include "symtab.h"
+#include "exceptions.h"
 
 extern int overload_debug;
 /* Local functions.  */
@@ -2215,7 +2216,8 @@ value_struct_elt (struct value **argp, struct value **args,
     }
 
   if (!v)
-    error (_("Structure has no component named %s."), name);
+    throw_error (NOT_FOUND_ERROR,
+                 _("Structure has no component named %s."), name);
   return v;
 }
 
@@ -2533,7 +2535,9 @@ find_overload_match (struct type **arg_types, int nargs,
 
   /* Did we find a match ?  */
   if (method_oload_champ == -1 && func_oload_champ == -1)
-    error (_("No symbol \"%s\" in current context."), name);
+    throw_error (NOT_FOUND_ERROR,
+                 _("No symbol \"%s\" in current context."),
+                 name);
 
   /* If we have found both a method match and a function
      match, find out which one is better, and calculate match
This page took 0.051398 seconds and 4 git commands to generate.