From patchwork Wed Apr 28 01:00:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 1470928 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=gHK24jb2; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FVL1r5f3gz9sWc for ; Wed, 28 Apr 2021 11:01:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EAA3539B8C1F; Wed, 28 Apr 2021 01:01:43 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from gateway30.websitewelcome.com (gateway30.websitewelcome.com [192.185.146.7]) by sourceware.org (Postfix) with ESMTPS id 6A4A43857025 for ; Wed, 28 Apr 2021 01:01:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6A4A43857025 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway30.websitewelcome.com (Postfix) with ESMTP id C12BE115CD for ; Tue, 27 Apr 2021 20:01:38 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id bYaAlzbAcmJLsbYaAlGRf9; Tue, 27 Apr 2021 20:01:38 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=5RUgzyqsF6oRGvqsd6nuTzb4NMbU0QcTftfxiz8ngaA=; b=gHK24jb2YIfTLl3Nyh/mUWcVoc H55FRgT5A59QS6ScsRQBlTUSpNO1eVQKNy+bJCeOJzShfdj0LmY2SITZ1nwSqtR/a/eEMCfV3jV7R oxGK+tAxXxVxCrpERPjjVwRSu; Received: from 97-122-70-176.hlrn.qwest.net ([97.122.70.176]:32966 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1lbYaA-003tiR-CM; Tue, 27 Apr 2021 19:01:38 -0600 From: Tom Tromey To: gcc-patches@gcc.gnu.org Subject: [PATCH v2 01/21] libcc1: use templates to unmarshall enums Date: Tue, 27 Apr 2021 19:00:59 -0600 Message-Id: <20210428010119.806184-2-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210428010119.806184-1-tom@tromey.com> References: <20210428010119.806184-1-tom@tromey.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.70.176 X-Source-L: No X-Exim-ID: 1lbYaA-003tiR-CM X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-70-176.hlrn.qwest.net (localhost.localdomain) [97.122.70.176]:32966 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3031.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP, URIBL_CSS, URIBL_CSS_A autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Tromey Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" 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 * 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 #include #include -#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 -. */ - -#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 + #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 + status unmarshall (connection *conn, T *scalar, + typename std::enable_if::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 - status unmarshall (connection *conn, T *scalar) + status unmarshall (connection *conn, T *e_val, + typename std::enable_if::value, T>::type * = 0) { protocol_int result; if (!unmarshall_intlike (conn, &result)) return FAIL; - *scalar = result; + *e_val = (T) result; return OK; }