diff mbox series

[v2,06/21] libcc1: use variadic templates for "rpc"

Message ID 20210428010119.806184-7-tom@tromey.com
State New
Headers show
Series C++11-based improvements for libcc1 | expand

Commit Message

Tom Tromey April 28, 2021, 1:01 a.m. UTC
This changes libcc1 to use variadic templates for the "rpc" functions.
This simplifies the code and removes some possibility for mistakes.

libcc1/ChangeLog
2021-04-27  Tom Tromey  <tom@tromey.com>

	* libcp1.cc (rpc): Use variadic template.  Remove overloads.
	* libcc1.cc (rpc): Use variadic template.  Remove overloads.
---
 libcc1/ChangeLog |  5 +++
 libcc1/libcc1.cc | 81 +++---------------------------------------------
 libcc1/libcp1.cc | 81 +++---------------------------------------------
 3 files changed, 13 insertions(+), 154 deletions(-)

Comments

Jeff Law April 28, 2021, 6:28 p.m. UTC | #1
On 4/27/2021 7:01 PM, Tom Tromey wrote:
> This changes libcc1 to use variadic templates for the "rpc" functions.
> This simplifies the code and removes some possibility for mistakes.
>
> libcc1/ChangeLog
> 2021-04-27  Tom Tromey  <tom@tromey.com>
>
> 	* libcp1.cc (rpc): Use variadic template.  Remove overloads.
> 	* libcc1.cc (rpc): Use variadic template.  Remove overloads.

OK

jeff
diff mbox series

Patch

diff --git a/libcc1/libcc1.cc b/libcc1/libcc1.cc
index 2c08dabb1a49..3432f4e8b212 100644
--- a/libcc1/libcc1.cc
+++ b/libcc1/libcc1.cc
@@ -210,90 +210,17 @@  set_callbacks (struct gcc_c_context *s,
   self->oracle_datum = datum;
 }
 
-// Instances of these rpc<> template functions are installed into the
+// Instances of this rpc<> template function are installed into the
 // "c_vtable".  These functions are parameterized by type and method
 // name and forward the call via the connection.
 
-template<typename R, const char *&NAME>
-R rpc (struct gcc_c_context *s)
+template<typename R, const char *&NAME, typename... Arg>
+R rpc (struct gcc_c_context *s, Arg... rest)
 {
   libcc1 *self = (libcc1 *) s;
   R result;
 
-  if (!cc1_plugin::call (self->connection, NAME, &result))
-    return 0;
-  return result;
-}
-
-template<typename R, const char *&NAME, typename A>
-R rpc (struct gcc_c_context *s, A arg)
-{
-  libcc1 *self = (libcc1 *) s;
-  R result;
-
-  if (!cc1_plugin::call (self->connection, NAME, &result, arg))
-    return 0;
-  return result;
-}
-
-template<typename R, const char *&NAME, typename A1, typename A2>
-R rpc (struct gcc_c_context *s, A1 arg1, A2 arg2)
-{
-  libcc1 *self = (libcc1 *) s;
-  R result;
-
-  if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2))
-    return 0;
-  return result;
-}
-
-template<typename R, const char *&NAME, typename A1, typename A2, typename A3>
-R rpc (struct gcc_c_context *s, A1 arg1, A2 arg2, A3 arg3)
-{
-  libcc1 *self = (libcc1 *) s;
-  R result;
-
-  if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2, arg3))
-    return 0;
-  return result;
-}
-
-template<typename R, const char *&NAME, typename A1, typename A2, typename A3,
-	 typename A4>
-R rpc (struct gcc_c_context *s, A1 arg1, A2 arg2, A3 arg3, A4 arg4)
-{
-  libcc1 *self = (libcc1 *) s;
-  R result;
-
-  if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2, arg3,
-			 arg4))
-    return 0;
-  return result;
-}
-
-template<typename R, const char *&NAME, typename A1, typename A2, typename A3,
-	 typename A4, typename A5>
-R rpc (struct gcc_c_context *s, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5)
-{
-  libcc1 *self = (libcc1 *) s;
-  R result;
-
-  if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2, arg3,
-			 arg4, arg5))
-    return 0;
-  return result;
-}
-
-template<typename R, const char *&NAME, typename A1, typename A2, typename A3,
-	 typename A4, typename A5, typename A6, typename A7>
-R rpc (struct gcc_c_context *s, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5,
-       A6 arg6, A7 arg7)
-{
-  libcc1 *self = (libcc1 *) s;
-  R result;
-
-  if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2, arg3,
-			 arg4, arg5, arg6, arg7))
+  if (!cc1_plugin::call (self->connection, NAME, &result, rest...))
     return 0;
   return result;
 }
diff --git a/libcc1/libcp1.cc b/libcc1/libcp1.cc
index fb91125ef0cf..4273f8d83826 100644
--- a/libcc1/libcp1.cc
+++ b/libcc1/libcp1.cc
@@ -233,90 +233,17 @@  set_callbacks (struct gcc_cp_context *s,
   self->oracle_datum = datum;
 }
 
-// Instances of these rpc<> template functions are installed into the
+// Instances of this rpc<> template function are installed into the
 // "cp_vtable".  These functions are parameterized by type and method
 // name and forward the call via the connection.
 
-template<typename R, const char *&NAME>
-R rpc (struct gcc_cp_context *s)
+template<typename R, const char *&NAME, typename... Arg>
+R rpc (struct gcc_cp_context *s, Arg... rest)
 {
   libcp1 *self = (libcp1 *) s;
   R result;
 
-  if (!cc1_plugin::call (self->connection, NAME, &result))
-    return 0;
-  return result;
-}
-
-template<typename R, const char *&NAME, typename A>
-R rpc (struct gcc_cp_context *s, A arg)
-{
-  libcp1 *self = (libcp1 *) s;
-  R result;
-
-  if (!cc1_plugin::call (self->connection, NAME, &result, arg))
-    return 0;
-  return result;
-}
-
-template<typename R, const char *&NAME, typename A1, typename A2>
-R rpc (struct gcc_cp_context *s, A1 arg1, A2 arg2)
-{
-  libcp1 *self = (libcp1 *) s;
-  R result;
-
-  if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2))
-    return 0;
-  return result;
-}
-
-template<typename R, const char *&NAME, typename A1, typename A2, typename A3>
-R rpc (struct gcc_cp_context *s, A1 arg1, A2 arg2, A3 arg3)
-{
-  libcp1 *self = (libcp1 *) s;
-  R result;
-
-  if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2, arg3))
-    return 0;
-  return result;
-}
-
-template<typename R, const char *&NAME, typename A1, typename A2, typename A3,
-	 typename A4>
-R rpc (struct gcc_cp_context *s, A1 arg1, A2 arg2, A3 arg3, A4 arg4)
-{
-  libcp1 *self = (libcp1 *) s;
-  R result;
-
-  if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2, arg3,
-			 arg4))
-    return 0;
-  return result;
-}
-
-template<typename R, const char *&NAME, typename A1, typename A2, typename A3,
-	 typename A4, typename A5>
-R rpc (struct gcc_cp_context *s, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5)
-{
-  libcp1 *self = (libcp1 *) s;
-  R result;
-
-  if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2, arg3,
-			 arg4, arg5))
-    return 0;
-  return result;
-}
-
-template<typename R, const char *&NAME, typename A1, typename A2, typename A3,
-	 typename A4, typename A5, typename A6, typename A7>
-R rpc (struct gcc_cp_context *s, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5,
-       A6 arg6, A7 arg7)
-{
-  libcp1 *self = (libcp1 *) s;
-  R result;
-
-  if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2, arg3,
-			 arg4, arg5, arg6, arg7))
+  if (!cc1_plugin::call (self->connection, NAME, &result, rest...))
     return 0;
   return result;
 }