From dc6be7c02258f6c79ed97b6886c81278ef7f264d Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 4 May 2021 15:26:58 -0600 Subject: 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. --- libcc1/marshall.hh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'libcc1/marshall.hh') 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 @@ -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 + 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 -- cgit v1.1