From: Joel Rosdahl Date: Sat, 14 May 2022 18:36:01 +0000 (+0200) Subject: style: Improve names of Args::AtFileFormat values X-Git-Tag: v4.6.1~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80ba758c0e522a2fb27bc4519309eaa81568afdd;p=thirdparty%2Fccache.git style: Improve names of Args::AtFileFormat values --- diff --git a/src/Args.cpp b/src/Args.cpp index 6b4ec2183..09aa8482d 100644 --- a/src/Args.cpp +++ b/src/Args.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2021 Joel Rosdahl and other contributors +// Copyright (C) 2020-2022 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -74,12 +74,12 @@ Args::from_atfile(const std::string& filename, AtFileFormat format) case '\\': pos++; switch (format) { - case AtFileFormat::QuoteAny_EscapeAny: + case AtFileFormat::gcc: if (*pos == '\0') { continue; } break; - case AtFileFormat::QuoteDouble_EscapeQuoteEscape: + case AtFileFormat::msvc: if (*pos != '"' && *pos != '\\') { pos--; } @@ -88,7 +88,7 @@ Args::from_atfile(const std::string& filename, AtFileFormat format) break; case '\'': - if (format == AtFileFormat::QuoteDouble_EscapeQuoteEscape) { + if (format == AtFileFormat::msvc) { break; } // Fall through. diff --git a/src/Args.hpp b/src/Args.hpp index 75aa331fe..d55ecd41a 100644 --- a/src/Args.hpp +++ b/src/Args.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2021 Joel Rosdahl and other contributors +// Copyright (C) 2020-2022 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -30,6 +30,11 @@ class Args { public: + enum class AtFileFormat { + gcc, // '\'' and '"' quote, '\\' escapes any character + msvc, // '"' quotes, '\\' escapes only '"' and '\\' + }; + Args() = default; Args(const Args& other) = default; Args(Args&& other) noexcept; @@ -37,13 +42,9 @@ public: static Args from_argv(int argc, const char* const* argv); static Args from_string(const std::string& command); - enum class AtFileFormat { - QuoteAny_EscapeAny, // '\'' and '"' quote, '\\' escapes any character - QuoteDouble_EscapeQuoteEscape, // '"' quotes, '\\' escapes only '"' and '\\' - }; static nonstd::optional from_atfile(const std::string& filename, - AtFileFormat format = AtFileFormat::QuoteAny_EscapeAny); + AtFileFormat format = AtFileFormat::gcc); Args& operator=(const Args& other) = default; Args& operator=(Args&& other) noexcept; diff --git a/src/argprocessing.cpp b/src/argprocessing.cpp index 679ee101e..cc4040d72 100644 --- a/src/argprocessing.cpp +++ b/src/argprocessing.cpp @@ -306,11 +306,10 @@ process_arg(const Context& ctx, if (argpath[-1] == '-') { ++argpath; } - auto file_args = - Args::from_atfile(argpath, - config.is_compiler_group_msvc() - ? Args::AtFileFormat::QuoteDouble_EscapeQuoteEscape - : Args::AtFileFormat::QuoteAny_EscapeAny); + auto file_args = Args::from_atfile(argpath, + config.is_compiler_group_msvc() + ? Args::AtFileFormat::msvc + : Args::AtFileFormat::gcc); if (!file_args) { LOG("Couldn't read arg file {}", argpath); return Statistic::bad_compiler_arguments; diff --git a/unittest/test_Args.cpp b/unittest/test_Args.cpp index ee9f80831..db656079c 100644 --- a/unittest/test_Args.cpp +++ b/unittest/test_Args.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Joel Rosdahl and other contributors +// Copyright (C) 2020-2022 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -140,8 +140,7 @@ TEST_CASE("Args::from_atfile") SUBCASE("Only escape double quote and backslash in alternate format") { Util::write_file("at_file", "\"\\\"\\a\\ \\\\\\ \\b\\\"\"\\"); - args = *Args::from_atfile( - "at_file", Args::AtFileFormat::QuoteDouble_EscapeQuoteEscape); + args = *Args::from_atfile("at_file", Args::AtFileFormat::msvc); CHECK(args.size() == 1); CHECK(args[0] == "\"\\a\\ \\\\ \\b\"\\"); } @@ -149,8 +148,7 @@ TEST_CASE("Args::from_atfile") SUBCASE("Ignore single quote in alternate format") { Util::write_file("at_file", "'a b'"); - args = *Args::from_atfile( - "at_file", Args::AtFileFormat::QuoteDouble_EscapeQuoteEscape); + args = *Args::from_atfile("at_file", Args::AtFileFormat::msvc); CHECK(args.size() == 2); CHECK(args[0] == "'a"); CHECK(args[1] == "b'");