summaryrefslogtreecommitdiff
path: root/libcc1/marshall.hh
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-05-04 15:26:58 -0600
committerTom Tromey <tom@tromey.com>2021-05-05 00:06:16 -0600
commitdc6be7c02258f6c79ed97b6886c81278ef7f264d (patch)
treef28421f9321410cebe73ed51df961032693293ff /libcc1/marshall.hh
parentc10a3b13fec850effc68c8b4f8861158f7fa7fed (diff)
libcc1: use variadic templates for "call"
This changes libcc1 to use variadic templates for the "call" functions. The primary benefit is that this simplifies the code. libcc1 * rpc.hh (call): Use variadic template. Remove overloads. * marshall.hh (marshall): Add base overload. Use variadic template.
Diffstat (limited to 'libcc1/marshall.hh')
-rw-r--r--libcc1/marshall.hh16
1 files changed, 16 insertions, 0 deletions
diff --git a/libcc1/marshall.hh b/libcc1/marshall.hh
index 8d890eb9b6c..4a28a8fe4ae 100644
--- a/libcc1/marshall.hh
+++ b/libcc1/marshall.hh
@@ -52,6 +52,14 @@ namespace cc1_plugin
status unmarshall_array_start (connection *, char, size_t *);
status unmarshall_array_elmts (connection *, size_t, void *);
+ // An "empty" marshall call -- used to handle the base case for some
+ // variadic templates.
+ static inline
+ status marshall (connection *)
+ {
+ return OK;
+ }
+
// A template function that can handle marshalling various integer
// objects to the connection.
template<typename T>
@@ -103,6 +111,14 @@ namespace cc1_plugin
// resulting array must be freed by the caller, using 'delete[]' on
// the elements, and 'delete' on the array object itself.
status unmarshall (connection *, struct gcc_type_array **);
+
+ template<typename T1, typename T2, typename... Arg>
+ status marshall (connection *c, T1 arg1, T2 arg2, Arg... rest)
+ {
+ if (!marshall (c, arg1))
+ return FAIL;
+ return marshall (c, arg2, rest...);
+ }
};
#endif // CC1_PLUGIN_MARSHALL_HH