diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2022-05-14 20:36:01 +0200 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2022-05-14 20:41:33 +0200 |
commit | 80ba758c0e522a2fb27bc4519309eaa81568afdd (patch) | |
tree | f54cf2efeb392318552d991732fb5702fd245038 | |
parent | 8108ab842bce2e1f4ce9f7f1c62515d894786277 (diff) | |
download | ccache-80ba758c0e522a2fb27bc4519309eaa81568afdd.tar.gz |
style: Improve names of Args::AtFileFormat values
-rw-r--r-- | src/Args.cpp | 8 | ||||
-rw-r--r-- | src/Args.hpp | 13 | ||||
-rw-r--r-- | src/argprocessing.cpp | 9 | ||||
-rw-r--r-- | unittest/test_Args.cpp | 8 |
4 files changed, 18 insertions, 20 deletions
diff --git a/src/Args.cpp b/src/Args.cpp index 6b4ec218..09aa8482 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 75aa331f..d55ecd41 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<Args> 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 679ee101..cc4040d7 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 ee9f8083..db656079 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'"); |