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 | 25d1a6ecdc443f19d63ab4dfc449417347ca7be0 (patch) | |
tree | d7d7e3693096c36217f47ba8f9b0ebf8b0123203 /libcc1/marshall.hh | |
parent | 523ca6403c68d580043af01485f2a8a8ce3a56d1 (diff) | |
download | gcc-25d1a6ecdc443f19d63ab4dfc449417347ca7be0.zip gcc-25d1a6ecdc443f19d63ab4dfc449417347ca7be0.tar.gz gcc-25d1a6ecdc443f19d63ab4dfc449417347ca7be0.tar.bz2 |
libcc1: use templates to unmarshall enums
Now that C++11 can be used in GCC, libcc1 can be changed to use
templates and type traits to handle unmarshalling all kinds of enums.
libcc1
* marshall.hh (cc1_plugin::unmarshall): Use type traits.
* marshall-cp.hh (cc1_plugin::unmarshall): Remove overloads.
* marshall-c.hh: Remove.
* libcc1plugin.cc: Update includes.
* libcc1.cc: Update includes.
Diffstat (limited to 'libcc1/marshall.hh')
-rw-r--r-- | libcc1/marshall.hh | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/libcc1/marshall.hh b/libcc1/marshall.hh index 6999c4f..8d890eb 100644 --- a/libcc1/marshall.hh +++ b/libcc1/marshall.hh @@ -20,6 +20,8 @@ along with GCC; see the file COPYING3. If not see #ifndef CC1_PLUGIN_MARSHALL_HH #define CC1_PLUGIN_MARSHALL_HH +#include <type_traits> + #include "status.hh" #include "gcc-interface.h" @@ -59,17 +61,31 @@ namespace cc1_plugin } // A template function that can handle unmarshalling various integer - // objects from the connection. Note that this can't be - // instantiated for enum types. Note also that there's no way at - // the protocol level to distinguish different int types. + // objects from the connection. Note that there's no way at the + // protocol level to distinguish different int types. + template<typename T> + status unmarshall (connection *conn, T *scalar, + typename std::enable_if<std::is_integral<T>::value, T>::type * = 0) + { + protocol_int result; + + if (!unmarshall_intlike (conn, &result)) + return FAIL; + *scalar = (T) result; + return OK; + } + + // A template function that can handle unmarshalling various enum + // objects from the connection. template<typename T> - status unmarshall (connection *conn, T *scalar) + status unmarshall (connection *conn, T *e_val, + typename std::enable_if<std::is_enum<T>::value, T>::type * = 0) { protocol_int result; if (!unmarshall_intlike (conn, &result)) return FAIL; - *scalar = result; + *e_val = (T) result; return OK; } |