From patchwork Fri Aug 17 12:01:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 958787 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-483843-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EhWetXAd"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41sMHy4FKtz9s3Z for ; Fri, 17 Aug 2018 22:01:50 +1000 (AEST) Received: (qmail 53751 invoked by alias); 17 Aug 2018 12:01:38 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 53650 invoked by uid 89); 17 Aug 2018 12:01:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=citizens, continued, HX-Gm-Message-State:AOUpUlE, c-cppbuiltin.c X-HELO: mail-yb0-f172.google.com Received: from mail-yb0-f172.google.com (HELO mail-yb0-f172.google.com) (209.85.213.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 17 Aug 2018 12:01:34 +0000 Received: by mail-yb0-f172.google.com with SMTP id c1-v6so159609ybq.5 for ; Fri, 17 Aug 2018 05:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=tSRG7FzZcz19pX4/jHlnYquMN5O5ByqpSHfGa0U3Kjg=; b=EhWetXAdPzq99A3fYHpPMFGmr2SvfVNtqIzmf9Honj3Z/WBqL3kyWklwiy0DJLvT0D Hp99iUT6A0C6Im6eIyprb5cGD9gNRm1cLD5PMTJSrWu1UuSaWu9DDVRfkXKWQ1iY4DTM /Kti4An2iLUFZnjHaLAYu9pGVwzCzoqNB5BDss+ksqhOxb7O6Ro1Rys4ovKJntUPTwzK gTwFgdOlGpvhLLEnd3ePqDlgbM9uNnbRJTaA3CjWJyUhmMvYwO1cfhF+Krt2QcO+g3/m 5ieWUYJVYxUO/oYuIpwNXHnhxv6YqydFBKQTr85tqxhYfNooBmRVszsArnuPAZ+rtj16 GeUQ== Received: from ?IPv6:2620:10d:c0a1:1102:495f:7267:5ff:a250? ([2620:10d:c091:180::1:995c]) by smtp.googlemail.com with ESMTPSA id c203-v6sm886069ywc.26.2018.08.17.05.01.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Aug 2018 05:01:32 -0700 (PDT) Sender: Nathan Sidwell To: "gcc-p >> GCC Patches" From: Nathan Sidwell Subject: [PATCH] Move cpp_macro to cpplib.h Message-ID: <30a34796-6c47-591f-a313-440d6edcda1b@acm.org> Date: Fri, 17 Aug 2018 08:01:30 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Way back Geoff Keating broke cpp-id-data.h out of internal.h so that PCH could write out tokenized macro definitions. That removed the need to stringize and retokenize them. cpp-id-data.h was fed to the gty machinery, and users of cpplib continued to use cpplib.h unaware of the cpp_macro definition. but some of its effects are felt in cpplib.h (the GTY markup for instance). Since then we now include cpp-id-data.h in a few places where we need to look inside a cpp_macro. That's a nasty hole punched through the abstraction layer :( This patch moves a couple of cpplib-internal declarations to internal.h and moves cpp_macro to cpplib.h, thereby exposing it to users properly. The remains of cpp-id-data.h will evaporate with this patch series, but we're not there yet. This allows the includers of cpp-id-data.h to become better citizens and use cpplib.h. I'll be morphing the cpp_macro definition, but thought it better to move then morph, than vice-versa. booted & tested on x86_64-linux nathan 2018-08-17 Nathan Sidwell libcpp/ * cpp-id-data.h (uchar, UC): Move to internal.h (struct cpp_macro): Move to cpplib.h. * internal.h (uchar, UC): From cpp-id-data.h. * include/cpplib.h (struct cpp_macro): From cpp-id-data.h. gcc/c-family/ * c-ada-spec.c: Don't #include "cpp-id-data.h" * c-cppbuiltin.c: Likewise. gcc/ * cppbuiltin.c: Include "cpplib.h", not "cpp-id-data.h". Index: gcc/c-family/c-ada-spec.c =================================================================== --- gcc/c-family/c-ada-spec.c (revision 263587) +++ gcc/c-family/c-ada-spec.c (working copy) @@ -27,7 +27,6 @@ along with GCC; see the file COPYING3. #include "c-ada-spec.h" #include "fold-const.h" #include "c-pragma.h" -#include "cpp-id-data.h" #include "stringpool.h" #include "attribs.h" Index: gcc/c-family/c-cppbuiltin.c =================================================================== --- gcc/c-family/c-cppbuiltin.c (revision 263587) +++ gcc/c-family/c-cppbuiltin.c (working copy) @@ -31,7 +31,6 @@ along with GCC; see the file COPYING3. #include "output.h" /* For user_label_prefix. */ #include "debug.h" /* For dwarf2out_do_cfi_asm. */ #include "common/common-target.h" -#include "cpp-id-data.h" #include "cppbuiltin.h" #ifndef TARGET_OS_CPP_BUILTINS Index: gcc/cppbuiltin.c =================================================================== --- gcc/cppbuiltin.c (revision 263587) +++ gcc/cppbuiltin.c (working copy) @@ -25,7 +25,7 @@ along with GCC; see the file COPYING3. #include "tree.h" #include "version.h" #include "flags.h" -#include "cpp-id-data.h" +#include "cpplib.h" #include "cppbuiltin.h" Index: libcpp/include/cpp-id-data.h =================================================================== --- libcpp/include/cpp-id-data.h (revision 263587) +++ libcpp/include/cpp-id-data.h (working copy) @@ -17,12 +17,6 @@ along with this program; see the file CO #include "cpplib.h" -#if !defined (HAVE_UCHAR) && !defined (IN_GCC) -typedef unsigned char uchar; -#endif - -#define UC (const unsigned char *) /* Intended use: UC"string" */ - /* Chained list of answers to an assertion. */ struct GTY(()) answer { struct answer *next; @@ -30,53 +24,3 @@ struct GTY(()) answer { cpp_token GTY ((length ("%h.count"))) first[1]; }; -/* Each macro definition is recorded in a cpp_macro structure. - Variadic macros cannot occur with traditional cpp. */ -struct GTY(()) cpp_macro { - /* Parameters, if any. If parameter names use extended identifiers, - the original spelling of those identifiers, not the canonical - UTF-8 spelling, goes here. */ - cpp_hashnode ** GTY ((nested_ptr (union tree_node, - "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL", - "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL"), - length ("%h.paramc"))) - params; - - /* Replacement tokens (ISO) or replacement text (traditional). See - comment at top of cpptrad.c for how traditional function-like - macros are encoded. */ - union cpp_macro_u - { - cpp_token * GTY ((tag ("0"), length ("%0.count"))) tokens; - const unsigned char * GTY ((tag ("1"))) text; - } GTY ((desc ("%1.traditional"))) exp; - - /* Definition line number. */ - source_location line; - - /* Number of tokens in expansion, or bytes for traditional macros. */ - unsigned int count; - - /* Number of parameters. */ - unsigned short paramc; - - /* If a function-like macro. */ - unsigned int fun_like : 1; - - /* If a variadic macro. */ - unsigned int variadic : 1; - - /* If macro defined in system header. */ - unsigned int syshdr : 1; - - /* Nonzero if it has been expanded or had its existence tested. */ - unsigned int used : 1; - - /* Indicate which field of 'exp' is in use. */ - unsigned int traditional : 1; - - /* Indicate whether the tokens include extra CPP_PASTE tokens at the - end to track invalid redefinitions with consecutive CPP_PASTE - tokens. */ - unsigned int extra_tokens : 1; -}; Index: libcpp/include/cpplib.h =================================================================== --- libcpp/include/cpplib.h (revision 263587) +++ libcpp/include/cpplib.h (working copy) @@ -671,6 +671,57 @@ struct cpp_dir dev_t dev; }; +/* Each macro definition is recorded in a cpp_macro structure. + Variadic macros cannot occur with traditional cpp. */ +struct GTY(()) cpp_macro { + /* Parameters, if any. If parameter names use extended identifiers, + the original spelling of those identifiers, not the canonical + UTF-8 spelling, goes here. */ + cpp_hashnode ** GTY ((nested_ptr (union tree_node, + "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL", + "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL"), + length ("%h.paramc"))) + params; + + /* Replacement tokens (ISO) or replacement text (traditional). See + comment at top of cpptrad.c for how traditional function-like + macros are encoded. */ + union cpp_macro_u + { + cpp_token * GTY ((tag ("0"), length ("%0.count"))) tokens; + const unsigned char * GTY ((tag ("1"))) text; + } GTY ((desc ("%1.traditional"))) exp; + + /* Definition line number. */ + source_location line; + + /* Number of tokens in expansion, or bytes for traditional macros. */ + unsigned int count; + + /* Number of parameters. */ + unsigned short paramc; + + /* If a function-like macro. */ + unsigned int fun_like : 1; + + /* If a variadic macro. */ + unsigned int variadic : 1; + + /* If macro defined in system header. */ + unsigned int syshdr : 1; + + /* Nonzero if it has been expanded or had its existence tested. */ + unsigned int used : 1; + + /* Indicate which field of 'exp' is in use. */ + unsigned int traditional : 1; + + /* Indicate whether the tokens include extra CPP_PASTE tokens at the + end to track invalid redefinitions with consecutive CPP_PASTE + tokens. */ + unsigned int extra_tokens : 1; +}; + /* The structure of a node in the hash table. The hash table has entries for all identifiers: either macros defined by #define commands (type NT_MACRO), assertions created with #assert Index: libcpp/internal.h =================================================================== --- libcpp/internal.h (revision 263600) +++ libcpp/internal.h (working copy) @@ -602,6 +602,12 @@ extern const unsigned char _cpp_trigraph extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1]; #endif +#if !defined (HAVE_UCHAR) && !defined (IN_GCC) +typedef unsigned char uchar; +#endif + +#define UC (const uchar *) /* Intended use: UC"string" */ + /* Macros. */ static inline int cpp_in_system_header (cpp_reader *);