public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
* [rfc] patch for pr8880
@ 2010-02-08 16:35 Sami Wagiaalla
  2010-02-08 17:30 ` Tom Tromey
  0 siblings, 1 reply; 10+ messages in thread
From: Sami Wagiaalla @ 2010-02-08 16:35 UTC (permalink / raw)
  To: Project Archer

[-- Attachment #1: Type: text/plain, Size: 3781 bytes --]

This was a long chase but an easy fix.
Thoughts ?

diff --git a/gdb/testsuite/gdb.cp/namespace-koenig.cc b/gdb/testsuite/gdb.cp/namespace-koenig.cc
index 6c2c01d..5df6a33 100644
--- a/gdb/testsuite/gdb.cp/namespace-koenig.cc
+++ b/gdb/testsuite/gdb.cp/namespace-koenig.cc
@@ -129,6 +129,29 @@ namespace L {
 }
 
 //------------
+
+namespace M {
+  class O{
+  public:
+    int operator== (int){
+      return 18;
+    }
+
+    int operator== (float){
+      return 19;
+    }
+  };
+
+  int operator!= (O, int){
+    return 20;
+  }
+
+  int operator!= (O, double){
+    return 21;
+  }
+
+}
+//------------
 int
 main ()
 {
@@ -180,6 +203,12 @@ main ()
 
   L::A::B::O labo;
   foo (labo);
+
+  M::O o;
+  o == 5;
+  o == 5.0f;
+  o != 5;
+  o != 5.0f;
   
   return first (0, c) + foo (eo) +
          foo (eo, eo) + foo (eo, eo, 1)  +
diff --git a/gdb/testsuite/gdb.cp/namespace-koenig.exp b/gdb/testsuite/gdb.cp/namespace-koenig.exp
index 616b816..f9ac963 100644
--- a/gdb/testsuite/gdb.cp/namespace-koenig.exp
+++ b/gdb/testsuite/gdb.cp/namespace-koenig.exp
@@ -93,3 +93,10 @@ gdb_test "p bar(ko,1)" "= -1"
 
 #test lookup of objects belonging to nested namespaces
 gdb_test "p foo(labo)" "= 17"
+
+# test lookup of namespace user-defined operators
+# and overload resolution.
+gdb_test "p o == 5" "= 18"
+gdb_test "p o == 5.0f" "= 19"
+gdb_test "p o != 5" "= 20"
+gdb_test "p o != 5.0f" "= 21"
diff --git a/gdb/valops.c b/gdb/valops.c
index e6ea6c9..25d077f 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -889,6 +889,13 @@ value_at (struct type *type, CORE_ADDR addr)
   return get_value_at (type, addr, 0);
 }
 
+struct value *
+value_at_value (struct value *value)
+{
+  return value_at(TYPE_TARGET_TYPE (value_type(value)),
+                  value_as_address(value));
+}
+
 /* Return a lazy value with type TYPE located at ADDR (cf. value_at).  */
 
 struct value *
@@ -2104,6 +2111,9 @@ value_struct_elt (struct value **argp, struct value **args,
   struct type *t;
   struct value *v;
 
+  struct type **arg_types;
+  int nargs, i = 0;
+
   *argp = coerce_array (*argp);
 
   t = check_typedef (value_type (*argp));
@@ -2173,6 +2183,33 @@ value_struct_elt (struct value **argp, struct value **args,
 	*static_memfuncp = 1;
     }
 
+  /* try Koenig lookup.  */
+  if (!v && args)
+    {
+      struct symbol *symp;
+      /* This function, if found, will not be a member function
+         and does not expect a pointer as its first argument
+         rather the explicit structure.  */
+      args[0] = value_at_value(args[0]);
+
+      nargs = 0;
+      if (args[1] == 0)
+        nargs = 1;
+      else if (args[2] == 0)
+        nargs = 2;
+
+      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, name, 0 /* not method */,
+                           0 /* strict match */, NULL,
+                           NULL /* pass NULL symbol since symbol is unknown */,
+                           NULL, &symp, NULL);
+
+      v = value_of_variable (symp, 0);
+    }
   if (!v)
     error (_("Structure has no component named %s."), name);
   return v;
diff --git a/gdb/value.h b/gdb/value.h
index 42b4497..1f1dead 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -348,6 +348,7 @@ extern struct value *value_from_decfloat (struct type *type,
 					  const gdb_byte *decbytes);
 
 extern struct value *value_at (struct type *type, CORE_ADDR addr);
+extern struct value *value_at_value (struct value *value);
 extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);
 
 extern struct value *value_from_contents_and_address (struct type *,


[-- Attachment #2: pr8880.patch --]
[-- Type: text/plain, Size: 3730 bytes --]

diff --git a/gdb/testsuite/gdb.cp/namespace-koenig.cc b/gdb/testsuite/gdb.cp/namespace-koenig.cc
index 6c2c01d..5df6a33 100644
--- a/gdb/testsuite/gdb.cp/namespace-koenig.cc
+++ b/gdb/testsuite/gdb.cp/namespace-koenig.cc
@@ -129,6 +129,29 @@ namespace L {
 }
 
 //------------
+
+namespace M {
+  class O{
+  public:
+    int operator== (int){
+      return 18;
+    }
+
+    int operator== (float){
+      return 19;
+    }
+  };
+
+  int operator!= (O, int){
+    return 20;
+  }
+
+  int operator!= (O, double){
+    return 21;
+  }
+
+}
+//------------
 int
 main ()
 {
@@ -180,6 +203,12 @@ main ()
 
   L::A::B::O labo;
   foo (labo);
+
+  M::O o;
+  o == 5;
+  o == 5.0f;
+  o != 5;
+  o != 5.0f;
   
   return first (0, c) + foo (eo) +
          foo (eo, eo) + foo (eo, eo, 1)  +
diff --git a/gdb/testsuite/gdb.cp/namespace-koenig.exp b/gdb/testsuite/gdb.cp/namespace-koenig.exp
index 616b816..f9ac963 100644
--- a/gdb/testsuite/gdb.cp/namespace-koenig.exp
+++ b/gdb/testsuite/gdb.cp/namespace-koenig.exp
@@ -93,3 +93,10 @@ gdb_test "p bar(ko,1)" "= -1"
 
 #test lookup of objects belonging to nested namespaces
 gdb_test "p foo(labo)" "= 17"
+
+# test lookup of namespace user-defined operators
+# and overload resolution.
+gdb_test "p o == 5" "= 18"
+gdb_test "p o == 5.0f" "= 19"
+gdb_test "p o != 5" "= 20"
+gdb_test "p o != 5.0f" "= 21"
diff --git a/gdb/valops.c b/gdb/valops.c
index e6ea6c9..25d077f 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -889,6 +889,13 @@ value_at (struct type *type, CORE_ADDR addr)
   return get_value_at (type, addr, 0);
 }
 
+struct value *
+value_at_value (struct value *value)
+{
+  return value_at(TYPE_TARGET_TYPE (value_type(value)),
+                  value_as_address(value));
+}
+
 /* Return a lazy value with type TYPE located at ADDR (cf. value_at).  */
 
 struct value *
@@ -2104,6 +2111,9 @@ value_struct_elt (struct value **argp, struct value **args,
   struct type *t;
   struct value *v;
 
+  struct type **arg_types;
+  int nargs, i = 0;
+
   *argp = coerce_array (*argp);
 
   t = check_typedef (value_type (*argp));
@@ -2173,6 +2183,33 @@ value_struct_elt (struct value **argp, struct value **args,
 	*static_memfuncp = 1;
     }
 
+  /* try Koenig lookup.  */
+  if (!v && args)
+    {
+      struct symbol *symp;
+      /* This function, if found, will not be a member function
+         and does not expect a pointer as its first argument
+         rather the explicit structure.  */
+      args[0] = value_at_value(args[0]);
+
+      nargs = 0;
+      if (args[1] == 0)
+        nargs = 1;
+      else if (args[2] == 0)
+        nargs = 2;
+
+      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, name, 0 /* not method */,
+                           0 /* strict match */, NULL,
+                           NULL /* pass NULL symbol since symbol is unknown */,
+                           NULL, &symp, NULL);
+
+      v = value_of_variable (symp, 0);
+    }
   if (!v)
     error (_("Structure has no component named %s."), name);
   return v;
diff --git a/gdb/value.h b/gdb/value.h
index 42b4497..1f1dead 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -348,6 +348,7 @@ extern struct value *value_from_decfloat (struct type *type,
 					  const gdb_byte *decbytes);
 
 extern struct value *value_at (struct type *type, CORE_ADDR addr);
+extern struct value *value_at_value (struct value *value);
 extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);
 
 extern struct value *value_from_contents_and_address (struct type *,


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-02-23 22:32 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-08 16:35 [rfc] patch for pr8880 Sami Wagiaalla
2010-02-08 17:30 ` Tom Tromey
2010-02-09 19:23   ` Sami Wagiaalla
2010-02-09 23:35     ` Tom Tromey
2010-02-11 21:00       ` Tom Tromey
2010-02-12 15:44         ` Sami Wagiaalla
2010-02-18 19:45       ` Sami Wagiaalla
2010-02-19 23:23         ` Tom Tromey
2010-02-22 16:37           ` Sami Wagiaalla
2010-02-23 22:32             ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).