From patchwork Wed Oct 11 18:04:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 824505 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-463969-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="fmB+obNn"; 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 3yC21t5Lqzz9t2W for ; Thu, 12 Oct 2017 05:04:49 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=AZdzrFrI5kObXh8VY5wfXESMUPwfqQ2AwoWFsfp4S/V+c6qJ+9 PXl5KMOAKJXIw5Ix5rsp8y2yyDGBbfKlBGRnZQmKsmMMu9g6vNwPyTH4xepkr1wT OZMhSPdUXi5+RdU6EketIoiOkJqIZmpDfdbcrkX7WChYnqc4CAhWHpYCw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=paaBUdhXBvVCsH6gZ+vbIobSuDo=; b=fmB+obNn/1mbtBQFfSfp /3ZL/VTcCQWUR/3Y9vcJmZpJuDCqhLxAa8tREazITbMIAS8nYh12MUHiDfKSG8xl wsn+bdvE6fQd3xm+L9aq1UuBibNn8eRrixVUHWv4RnUifM+SEeLk37qG/+fnVQiD 6+o0wv7e3p0/qTFI424QnSw= Received: (qmail 39814 invoked by alias); 11 Oct 2017 18:04:40 -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 38051 invoked by uid 89); 11 Oct 2017 18:04:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=awareness, bracket, Various, cpath X-HELO: mail-qt0-f174.google.com Received: from mail-qt0-f174.google.com (HELO mail-qt0-f174.google.com) (209.85.216.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Oct 2017 18:04:37 +0000 Received: by mail-qt0-f174.google.com with SMTP id x54so7756548qth.12 for ; Wed, 11 Oct 2017 11:04:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=jbRVEPPbWUZqA6vmvcmzgCEKV9Gio06OK6OdD0HRlDI=; b=rBnHLWCDW4HD2ACkvusON+GEEkCCPfwR8IKTePF9ddUsvgnbSFnMJc2XOuSe6tOzdx fOlZy0mnaNmH62fyLhX9W32UGj9jTe45wUQEeNqhi9WcOECcoL3o5SbqIOLiE/WqY/+J S/BMnxH6HPTOwHoCutbAOW7KOOZSqLeSnfbfdczWLfsJgtfAroC68eNOlc/wLdnvMX6f 0FZUCCVI6yoY3G2gr3en+za10RrvwZeb0ni7DO+BYSnGmtWCafDg4dzG5hxYCvP3F/sK d4yE2/K0WPNRxTJdqb8g+Ds/Dbz6eebH1etDFhW0coZ1e+KFRI/EpI3foJRVXYmMSSBe 7hTQ== X-Gm-Message-State: AMCzsaXVh8v0h85A/7Y3darQ4xskYRcXrqHm5MjQY3Gd9V6z0GFiIJYc x1Uylu+GnkVcqgbUnh83ZN0= X-Google-Smtp-Source: AOwi7QDfL1Uav8W8bLJ3WqT9n6MguUq7bc8HEcKdVZw9sZHLM8P/D2w+2ISIs0PzypjqoMkMe3Song== X-Received: by 10.37.5.201 with SMTP id 192mr276780ybf.197.1507745075240; Wed, 11 Oct 2017 11:04:35 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::7ed9]) by smtp.googlemail.com with ESMTPSA id c74sm8198294ywh.19.2017.10.11.11.04.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Oct 2017 11:04:34 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [PATCH] Include path enumeration Message-ID: <47d59110-a024-7fc6-1f67-b2c067fd6727@acm.org> Date: Wed, 11 Oct 2017 14:04:33 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 We have an enumeration to indicate particular fragments of the include path. But 1) it's unnamed. So we pass it as int or size_t(!), which is stupid. 2) It's members have rather generic names (QUOTE, BRACKET, SYSTEM, AFTER) 3) There's no MAX value, so we use a magic constant '4'. This patch fixes these by (a) naming it incpath_kind, prefixing its members with INC_ and providing an INC_MAX member. Applying to trunk as sufficiently obvious and close to C++FE and cpplib. nathan 2017-10-11 Nathan Sidwell gcc/ * incpath.h (enum incpath_e): Name enum, prefix values. (add_path, add_cpp_dir_path, get_added_cpp_dirs): Use incpath_e type. * incpath.c (heads, tails): Use INC_MAX. (add_env_var_paths, add_standard_paths): Use incpath_e type. (merge_include_chains, split_quote_chain, register_include_chains): Update incpath_e names. (add_cpp_dir_path, add_path, get_added_cpp_dirs): Use incpath_e type. * config/darwin-c.c (add_system_framework_path): Update incpath_e names. (add_framework_path, darwin_register_objc_includes ): Likewise. * config/vms/vms-c.c (vms_c_register_includes): Likewise. c-family/ * c-opts.c (add_prefixed_path): Change chain to incpath_e type. (c_common_handle_option): Update incpath_e names. fortran/ * cpp.c (gfc_cpp_add_include_path): Update incpath_e names. (gfc_cpp_add_include_path_after): Likewise. Index: incpath.h =================================================================== --- incpath.h (revision 253649) +++ incpath.h (working copy) @@ -18,13 +18,22 @@ #ifndef GCC_INCPATH_H #define GCC_INCPATH_H +/* Various fragments of include path. */ +enum incpath_kind { + INC_QUOTE = 0, /* include "foo" */ + INC_BRACKET, /* include */ + INC_SYSTEM, /* sysinclude */ + INC_AFTER, /* post-sysinclude. */ + INC_MAX +}; + extern void split_quote_chain (void); -extern void add_path (char *, int, int, bool); +extern void add_path (char *, incpath_kind, int, bool); extern void register_include_chains (cpp_reader *, const char *, const char *, const char *, int, int, int); -extern void add_cpp_dir_path (struct cpp_dir *, int); -extern struct cpp_dir *get_added_cpp_dirs (int); +extern void add_cpp_dir_path (struct cpp_dir *, incpath_kind); +extern struct cpp_dir *get_added_cpp_dirs (incpath_kind); struct target_c_incpath_s { /* Do extra includes processing. STDINC is false iff -nostdinc was given. */ @@ -34,6 +43,4 @@ struct target_c_incpath_s { extern struct target_c_incpath_s target_c_incpath; -enum { QUOTE = 0, BRACKET, SYSTEM, AFTER }; - #endif /* GCC_INCPATH_H */ Index: c-family/c-opts.c =================================================================== --- c-family/c-opts.c (revision 253649) +++ c-family/c-opts.c (working copy) @@ -118,7 +118,7 @@ static void set_std_c11 (int); static void check_deps_environment_vars (void); static void handle_deferred_opts (void); static void sanitize_cpp_opts (void); -static void add_prefixed_path (const char *, size_t); +static void add_prefixed_path (const char *, incpath_kind); static void push_command_line_include (void); static void cb_file_change (cpp_reader *, const line_map_ordinary *); static void cb_dir_change (cpp_reader *, const char *); @@ -316,7 +316,7 @@ c_common_handle_option (size_t scode, co case OPT_I: if (strcmp (arg, "-")) - add_path (xstrdup (arg), BRACKET, 0, true); + add_path (xstrdup (arg), INC_BRACKET, 0, true); else { if (quote_chain_split) @@ -550,7 +550,7 @@ c_common_handle_option (size_t scode, co break; case OPT_idirafter: - add_path (xstrdup (arg), AFTER, 0, true); + add_path (xstrdup (arg), INC_AFTER, 0, true); break; case OPT_imacros: @@ -567,7 +567,7 @@ c_common_handle_option (size_t scode, co break; case OPT_iquote: - add_path (xstrdup (arg), QUOTE, 0, true); + add_path (xstrdup (arg), INC_QUOTE, 0, true); break; case OPT_isysroot: @@ -575,15 +575,15 @@ c_common_handle_option (size_t scode, co break; case OPT_isystem: - add_path (xstrdup (arg), SYSTEM, 0, true); + add_path (xstrdup (arg), INC_SYSTEM, 0, true); break; case OPT_iwithprefix: - add_prefixed_path (arg, SYSTEM); + add_prefixed_path (arg, INC_SYSTEM); break; case OPT_iwithprefixbefore: - add_prefixed_path (arg, BRACKET); + add_prefixed_path (arg, INC_BRACKET); break; case OPT_lang_asm: @@ -1326,7 +1326,7 @@ sanitize_cpp_opts (void) /* Add include path with a prefix at the front of its name. */ static void -add_prefixed_path (const char *suffix, size_t chain) +add_prefixed_path (const char *suffix, incpath_kind chain) { char *path; const char *prefix; Index: config/darwin-c.c =================================================================== --- config/darwin-c.c (revision 253649) +++ config/darwin-c.c (working copy) @@ -433,7 +433,7 @@ add_system_framework_path (char *path) p->construct = framework_construct_pathname; using_frameworks = 1; - add_cpp_dir_path (p, SYSTEM); + add_cpp_dir_path (p, INC_SYSTEM); } /* Add PATH to the bracket includes. PATH must be malloc-ed and @@ -451,7 +451,7 @@ add_framework_path (char *path) p->construct = framework_construct_pathname; using_frameworks = 1; - add_cpp_dir_path (p, BRACKET); + add_cpp_dir_path (p, INC_BRACKET); } static const char *framework_defaults [] = @@ -488,7 +488,7 @@ darwin_register_objc_includes (const cha { str = concat (iprefix, fname + len, NULL); /* FIXME: wrap the headers for C++awareness. */ - add_path (str, SYSTEM, /*c++aware=*/false, false); + add_path (str, INC_SYSTEM, /*c++aware=*/false, false); } /* Should this directory start with the sysroot? */ @@ -497,7 +497,7 @@ darwin_register_objc_includes (const cha else str = update_path (fname, ""); - add_path (str, SYSTEM, /*c++aware=*/false, false); + add_path (str, INC_SYSTEM, /*c++aware=*/false, false); } } Index: config/vms/vms-c.c =================================================================== --- config/vms/vms-c.c (revision 253649) +++ config/vms/vms-c.c (working copy) @@ -418,7 +418,7 @@ vms_c_register_includes (const char *sys if (!stdinc) return; - for (dir = get_added_cpp_dirs (SYSTEM); dir != NULL; dir = dir->next) + for (dir = get_added_cpp_dirs (INC_SYSTEM); dir != NULL; dir = dir->next) { const char * const *lib; for (lib = vms_std_modules; *lib != NULL; lib++) @@ -441,7 +441,7 @@ vms_c_register_includes (const char *sys p->sysp = 1; p->construct = vms_construct_include_filename; p->user_supplied_p = 0; - add_cpp_dir_path (p, SYSTEM); + add_cpp_dir_path (p, INC_SYSTEM); } else free (path); Index: fortran/cpp.c =================================================================== --- fortran/cpp.c (revision 253649) +++ fortran/cpp.c (working copy) @@ -683,14 +683,14 @@ gfc_cpp_add_include_path (char *path, bo include path. Fortran does not define any system include paths. */ int cxx_aware = 0; - add_path (path, BRACKET, cxx_aware, user_supplied); + add_path (path, INC_BRACKET, cxx_aware, user_supplied); } void gfc_cpp_add_include_path_after (char *path, bool user_supplied) { int cxx_aware = 0; - add_path (path, AFTER, cxx_aware, user_supplied); + add_path (path, INC_AFTER, cxx_aware, user_supplied); } void Index: incpath.c =================================================================== --- incpath.c (revision 253649) +++ incpath.c (working copy) @@ -46,7 +46,7 @@ static const char dir_separator_str[] = { DIR_SEPARATOR, 0 }; -static void add_env_var_paths (const char *, int); +static void add_env_var_paths (const char *, incpath_kind); static void add_standard_paths (const char *, const char *, const char *, int); static void free_path (struct cpp_dir *, int); static void merge_include_chains (const char *, cpp_reader *, int); @@ -56,8 +56,9 @@ static struct cpp_dir *remove_duplicates struct cpp_dir *, int); /* Include chains heads and tails. */ -static struct cpp_dir *heads[4]; -static struct cpp_dir *tails[4]; +static struct cpp_dir *heads[INC_MAX]; +static struct cpp_dir *tails[INC_MAX]; + static bool quote_ignores_source_dir; enum { REASON_QUIET = 0, REASON_NOENT, REASON_DUP, REASON_DUP_SYS }; @@ -92,7 +93,7 @@ free_path (struct cpp_dir *path, int rea /* Read ENV_VAR for a PATH_SEPARATOR-separated list of file names; and append all the names to the search path CHAIN. */ static void -add_env_var_paths (const char *env_var, int chain) +add_env_var_paths (const char *env_var, incpath_kind chain) { char *p, *q, *path; @@ -116,7 +117,7 @@ add_env_var_paths (const char *env_var, path[q - p] = '\0'; } - add_path (path, chain, chain == SYSTEM, false); + add_path (path, chain, chain == INC_SYSTEM, false); } } @@ -159,7 +160,7 @@ add_standard_paths (const char *sysroot, str = reconcat (str, str, dir_separator_str, imultiarch, NULL); } - add_path (str, SYSTEM, p->cxx_aware, false); + add_path (str, INC_SYSTEM, p->cxx_aware, false); } } } @@ -225,7 +226,7 @@ add_standard_paths (const char *sysroot, str = reconcat (str, str, dir_separator_str, imultiarch, NULL); } - add_path (str, SYSTEM, p->cxx_aware, false); + add_path (str, INC_SYSTEM, p->cxx_aware, false); } } } @@ -349,29 +350,32 @@ merge_include_chains (const char *sysroo /* Add the sysroot to user-supplied paths starting with "=". */ if (sysroot) { - add_sysroot_to_chain (sysroot, QUOTE); - add_sysroot_to_chain (sysroot, BRACKET); - add_sysroot_to_chain (sysroot, SYSTEM); - add_sysroot_to_chain (sysroot, AFTER); + add_sysroot_to_chain (sysroot, INC_QUOTE); + add_sysroot_to_chain (sysroot, INC_BRACKET); + add_sysroot_to_chain (sysroot, INC_SYSTEM); + add_sysroot_to_chain (sysroot, INC_AFTER); } /* Join the SYSTEM and AFTER chains. Remove duplicates in the resulting SYSTEM chain. */ - if (heads[SYSTEM]) - tails[SYSTEM]->next = heads[AFTER]; + if (heads[INC_SYSTEM]) + tails[INC_SYSTEM]->next = heads[INC_AFTER]; else - heads[SYSTEM] = heads[AFTER]; - heads[SYSTEM] = remove_duplicates (pfile, heads[SYSTEM], 0, 0, verbose); + heads[INC_SYSTEM] = heads[INC_AFTER]; + heads[INC_SYSTEM] + = remove_duplicates (pfile, heads[INC_SYSTEM], 0, 0, verbose); /* Remove duplicates from BRACKET that are in itself or SYSTEM, and join it to SYSTEM. */ - heads[BRACKET] = remove_duplicates (pfile, heads[BRACKET], heads[SYSTEM], - heads[SYSTEM], verbose); + heads[INC_BRACKET] + = remove_duplicates (pfile, heads[INC_BRACKET], heads[INC_SYSTEM], + heads[INC_SYSTEM], verbose); /* Remove duplicates from QUOTE that are in itself or SYSTEM, and join it to BRACKET. */ - heads[QUOTE] = remove_duplicates (pfile, heads[QUOTE], heads[SYSTEM], - heads[BRACKET], verbose); + heads[INC_QUOTE] + = remove_duplicates (pfile, heads[INC_QUOTE], heads[INC_SYSTEM], + heads[INC_BRACKET], verbose); /* If verbose, print the list of dirs to search. */ if (verbose) @@ -379,9 +383,9 @@ merge_include_chains (const char *sysroo struct cpp_dir *p; fprintf (stderr, _("#include \"...\" search starts here:\n")); - for (p = heads[QUOTE];; p = p->next) + for (p = heads[INC_QUOTE];; p = p->next) { - if (p == heads[BRACKET]) + if (p == heads[INC_BRACKET]) fprintf (stderr, _("#include <...> search starts here:\n")); if (!p) break; @@ -398,14 +402,14 @@ merge_include_chains (const char *sysroo void split_quote_chain (void) { - if (heads[QUOTE]) - free_path (heads[QUOTE], REASON_QUIET); - if (tails[QUOTE]) - free_path (tails[QUOTE], REASON_QUIET); - heads[QUOTE] = heads[BRACKET]; - tails[QUOTE] = tails[BRACKET]; - heads[BRACKET] = NULL; - tails[BRACKET] = NULL; + if (heads[INC_QUOTE]) + free_path (heads[INC_QUOTE], REASON_QUIET); + if (tails[INC_QUOTE]) + free_path (tails[INC_QUOTE], REASON_QUIET); + heads[INC_QUOTE] = heads[INC_BRACKET]; + tails[INC_QUOTE] = tails[INC_BRACKET]; + heads[INC_BRACKET] = NULL; + tails[INC_BRACKET] = NULL; /* This is NOT redundant. */ quote_ignores_source_dir = true; } @@ -413,7 +417,7 @@ split_quote_chain (void) /* Add P to the chain specified by CHAIN. */ void -add_cpp_dir_path (cpp_dir *p, int chain) +add_cpp_dir_path (cpp_dir *p, incpath_kind chain) { if (tails[chain]) tails[chain]->next = p; @@ -425,7 +429,7 @@ add_cpp_dir_path (cpp_dir *p, int chain) /* Add PATH to the include chain CHAIN. PATH must be malloc-ed and NUL-terminated. */ void -add_path (char *path, int chain, int cxx_aware, bool user_supplied_p) +add_path (char *path, incpath_kind chain, int cxx_aware, bool user_supplied_p) { cpp_dir *p; @@ -450,7 +454,7 @@ add_path (char *path, int chain, int cxx #ifndef INO_T_EQ p->canonical_name = lrealpath (path); #endif - if (chain == SYSTEM || chain == AFTER) + if (chain == INC_SYSTEM || chain == INC_AFTER) p->sysp = 1 + !cxx_aware; else p->sysp = 0; @@ -480,8 +484,8 @@ register_include_chains (cpp_reader *pfi /* CPATH and language-dependent environment variables may add to the include chain. */ - add_env_var_paths ("CPATH", BRACKET); - add_env_var_paths (lang_env_vars[idx], SYSTEM); + add_env_var_paths ("CPATH", INC_BRACKET); + add_env_var_paths (lang_env_vars[idx], INC_SYSTEM); target_c_incpath.extra_pre_includes (sysroot, iprefix, stdinc); @@ -493,14 +497,14 @@ register_include_chains (cpp_reader *pfi merge_include_chains (sysroot, pfile, verbose); - cpp_set_include_chains (pfile, heads[QUOTE], heads[BRACKET], + cpp_set_include_chains (pfile, heads[INC_QUOTE], heads[INC_BRACKET], quote_ignores_source_dir); } /* Return the current chain of cpp dirs. */ struct cpp_dir * -get_added_cpp_dirs (int chain) +get_added_cpp_dirs (incpath_kind chain) { return heads[chain]; }