diff options
author | Tom Tromey <tom@tromey.com> | 2021-05-04 15:26:58 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2021-05-05 00:06:16 -0600 |
commit | dc6be7c02258f6c79ed97b6886c81278ef7f264d (patch) | |
tree | f28421f9321410cebe73ed51df961032693293ff /libcc1/marshall.hh | |
parent | c10a3b13fec850effc68c8b4f8861158f7fa7fed (diff) | |
download | gcc-dc6be7c02258f6c79ed97b6886c81278ef7f264d.zip gcc-dc6be7c02258f6c79ed97b6886c81278ef7f264d.tar.gz gcc-dc6be7c02258f6c79ed97b6886c81278ef7f264d.tar.bz2 |
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.hh | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libcc1/marshall.hh b/libcc1/marshall.hh index 8d890eb..4a28a8f 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 |