From: Tom Tromey <tom@tromey.com>
To: gcc-patches@gcc.gnu.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH v2 01/21] libcc1: use templates to unmarshall enums
Date: Tue, 27 Apr 2021 19:00:59 -0600 [thread overview]
Message-ID: <20210428010119.806184-2-tom@tromey.com> (raw)
In-Reply-To: <20210428010119.806184-1-tom@tromey.com>
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/ChangeLog
2021-04-27 Tom Tromey <tom@tromey.com>
* 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.
---
libcc1/ChangeLog | 8 ++++++
libcc1/libcc1.cc | 3 ++-
libcc1/libcc1plugin.cc | 3 ++-
libcc1/marshall-c.hh | 59 ------------------------------------------
libcc1/marshall-cp.hh | 40 ----------------------------
libcc1/marshall.hh | 26 +++++++++++++++----
6 files changed, 33 insertions(+), 106 deletions(-)
delete mode 100644 libcc1/marshall-c.hh
diff --git a/libcc1/libcc1.cc b/libcc1/libcc1.cc
index e4c200c8abd5..68d366a72871 100644
--- a/libcc1/libcc1.cc
+++ b/libcc1/libcc1.cc
@@ -29,7 +29,7 @@ along with GCC; see the file COPYING3. If not see
#include <sys/stat.h>
#include <stdlib.h>
#include <sstream>
-#include "marshall-c.hh"
+#include "marshall.hh"
#include "rpc.hh"
#include "connection.hh"
#include "names.hh"
@@ -39,6 +39,7 @@ along with GCC; see the file COPYING3. If not see
#include "findcomp.hh"
#include "compiler-name.hh"
#include "intl.h"
+#include "gcc-c-interface.h"
struct libcc1;
diff --git a/libcc1/libcc1plugin.cc b/libcc1/libcc1plugin.cc
index e80ecd8f4b35..59e4851064a2 100644
--- a/libcc1/libcc1plugin.cc
+++ b/libcc1/libcc1plugin.cc
@@ -63,8 +63,9 @@
#include "callbacks.hh"
#include "connection.hh"
-#include "marshall-c.hh"
+#include "marshall.hh"
#include "rpc.hh"
+#include "gcc-c-interface.h"
#ifdef __GNUC__
#pragma GCC visibility push(default)
diff --git a/libcc1/marshall-c.hh b/libcc1/marshall-c.hh
deleted file mode 100644
index 212603ebb819..000000000000
--- a/libcc1/marshall-c.hh
+++ /dev/null
@@ -1,59 +0,0 @@
-/* Marshalling and unmarshalling of C-specific types.
- Copyright (C) 2014-2021 Free Software Foundation, Inc.
-
-This file is part of GCC.
-
-GCC is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 3, or (at your option) any later
-version.
-
-GCC is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING3. If not see
-<http://www.gnu.org/licenses/>. */
-
-#ifndef CC1_PLUGIN_MARSHALL_C_HH
-#define CC1_PLUGIN_MARSHALL_C_HH
-
-#include "marshall.hh"
-#include "gcc-c-interface.h"
-
-namespace cc1_plugin
-{
- status
- unmarshall (connection *conn, enum gcc_c_symbol_kind *result)
- {
- protocol_int p;
- if (!unmarshall_intlike (conn, &p))
- return FAIL;
- *result = (enum gcc_c_symbol_kind) p;
- return OK;
- }
-
- status
- unmarshall (connection *conn, enum gcc_c_oracle_request *result)
- {
- protocol_int p;
- if (!unmarshall_intlike (conn, &p))
- return FAIL;
- *result = (enum gcc_c_oracle_request) p;
- return OK;
- }
-
- status
- unmarshall (connection *conn, enum gcc_qualifiers *result)
- {
- protocol_int p;
- if (!unmarshall_intlike (conn, &p))
- return FAIL;
- *result = (enum gcc_qualifiers) p;
- return OK;
- }
-}
-
-#endif // CC1_PLUGIN_MARSHALL_C_HH
diff --git a/libcc1/marshall-cp.hh b/libcc1/marshall-cp.hh
index ff80bfe41870..3d6ae4126aee 100644
--- a/libcc1/marshall-cp.hh
+++ b/libcc1/marshall-cp.hh
@@ -25,46 +25,6 @@ along with GCC; see the file COPYING3. If not see
namespace cc1_plugin
{
- status
- unmarshall (connection *conn, enum gcc_cp_symbol_kind *result)
- {
- protocol_int p;
- if (!unmarshall_intlike (conn, &p))
- return FAIL;
- *result = (enum gcc_cp_symbol_kind) p;
- return OK;
- }
-
- status
- unmarshall (connection *conn, enum gcc_cp_oracle_request *result)
- {
- protocol_int p;
- if (!unmarshall_intlike (conn, &p))
- return FAIL;
- *result = (enum gcc_cp_oracle_request) p;
- return OK;
- }
-
- status
- unmarshall (connection *conn, enum gcc_cp_qualifiers *result)
- {
- protocol_int p;
- if (!unmarshall_intlike (conn, &p))
- return FAIL;
- *result = (enum gcc_cp_qualifiers) p;
- return OK;
- }
-
- status
- unmarshall (connection *conn, enum gcc_cp_ref_qualifiers *result)
- {
- protocol_int p;
- if (!unmarshall_intlike (conn, &p))
- return FAIL;
- *result = (enum gcc_cp_ref_qualifiers) p;
- return OK;
- }
-
// Send a gcc_vbase_array marker followed by the array.
status
marshall (connection *conn, const gcc_vbase_array *a)
diff --git a/libcc1/marshall.hh b/libcc1/marshall.hh
index 6999c4ff8fd1..8d890eb9b6c7 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;
}
--
2.26.2
next prev parent reply other threads:[~2021-04-28 1:01 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-28 1:00 [PATCH v2 00/21] C++11-based improvements for libcc1 Tom Tromey
2021-04-28 1:00 ` Tom Tromey [this message]
2021-04-28 18:27 ` [PATCH v2 01/21] libcc1: use templates to unmarshall enums Jeff Law
2021-04-28 1:01 ` [PATCH v2 02/21] libcc1: use "override" Tom Tromey
2021-04-28 15:53 ` Jeff Law
2021-04-28 1:01 ` [PATCH v2 03/21] libcc1: inline some simple methods Tom Tromey
2021-04-28 15:54 ` Jeff Law
2021-04-28 1:01 ` [PATCH v2 04/21] libcc1: delete copy constructor and assignment operators Tom Tromey
2021-04-28 15:55 ` Jeff Law
2021-04-28 1:01 ` [PATCH v2 05/21] libcc1: use variadic templates for "call" Tom Tromey
2021-04-28 18:28 ` Jeff Law
2021-04-28 1:01 ` [PATCH v2 06/21] libcc1: use variadic templates for "rpc" Tom Tromey
2021-04-28 18:28 ` Jeff Law
2021-04-28 1:01 ` [PATCH v2 07/21] libcc1: use std::vector when building function types Tom Tromey
2021-04-28 16:01 ` Jeff Law
2021-04-28 19:56 ` Tom Tromey
2021-04-28 20:07 ` Jeff Law
2021-04-28 1:01 ` [PATCH v2 08/21] libcc1: add deleter objects Tom Tromey
2021-04-28 21:06 ` Jeff Law
2021-04-28 1:01 ` [PATCH v2 09/21] libcc1: add more uses of 'deleter' Tom Tromey
2021-04-29 12:43 ` Jeff Law
2021-04-28 1:01 ` [PATCH v2 10/21] libcc1: use unique_ptr more Tom Tromey
2021-04-29 12:44 ` Jeff Law
2021-04-28 1:01 ` [PATCH v2 11/21] libcc1: unify compiler handling Tom Tromey
2021-04-29 12:47 ` Jeff Law
2021-04-28 1:01 ` [PATCH v2 12/21] libcc1: use foreach Tom Tromey
2021-04-28 16:04 ` Jeff Law
2021-04-28 1:01 ` [PATCH v2 13/21] libcc1: use static_assert Tom Tromey
2021-04-28 16:06 ` Jeff Law
2021-04-28 1:01 ` [PATCH v2 14/21] libcc1: share basic context code Tom Tromey
2021-04-29 12:50 ` Jeff Law
2021-04-28 1:01 ` [PATCH v2 15/21] libcc1: share GDB plugin code Tom Tromey
2021-04-30 14:50 ` Jeff Law
2021-04-28 1:01 ` [PATCH v2 16/21] libcc1: use GCC_FE_VERSION_1 in C++ plugin Tom Tromey
2021-04-28 16:06 ` Jeff Law
2021-04-28 1:01 ` [PATCH v2 17/21] libcc1: share the GCC interface code Tom Tromey
2021-04-30 15:07 ` Jeff Law
2021-04-28 1:01 ` [PATCH v2 18/21] libcc1: fix a memory leak Tom Tromey
2021-04-28 16:07 ` Jeff Law
2021-04-28 1:01 ` [PATCH v2 19/21] libcc1: use variadic templates for callbacks Tom Tromey
2021-04-30 15:08 ` Jeff Law
2021-05-04 22:05 ` Tom Tromey
2021-04-28 1:01 ` [PATCH v2 20/21] libcc1: avoid extra string copies Tom Tromey
2021-04-28 16:07 ` Jeff Law
2021-04-28 1:01 ` [PATCH v2 21/21] libcc1: avoid a call to c_str Tom Tromey
2021-04-28 16:08 ` Jeff Law
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210428010119.806184-2-tom@tromey.com \
--to=tom@tromey.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).