From 841593b6b43b6d16f39423dc6aec718048e76f83 Mon Sep 17 00:00:00 2001 From: Alexander Lanin Date: Fri, 2 Oct 2020 22:04:12 +0200 Subject: [PATCH] refactor: Simplify logic of -x handling --- src/argprocessing.cpp | 50 ++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/argprocessing.cpp b/src/argprocessing.cpp index 86b96a10f..c3593e6de 100644 --- a/src/argprocessing.cpp +++ b/src/argprocessing.cpp @@ -389,33 +389,35 @@ process_arg(Context& ctx, return nullopt; } - if (args[i].length() >= 3 && Util::starts_with(args[i], "-x") - && !islower(args[i][2])) { - // -xCODE (where CODE can be e.g. Host or CORE-AVX2, always starting with an - // uppercase letter) is an ordinary Intel compiler option, not a language - // specification. (GCC's "-x" language argument is always lowercase.) - state.common_args.push_back(args[i]); - return nullopt; - } - - // Special handling for -x: remember the last specified language before the - // input file and strip all -x options from the arguments. - if (args[i] == "-x") { - if (i == args.size() - 1) { - log("Missing argument to {}", args[i]); - return Statistic::bad_compiler_arguments; + if (Util::starts_with(args[i], "-x")) { + if (args[i].length() >= 3 && !islower(args[i][2])) { + // -xCODE (where CODE can be e.g. Host or CORE-AVX2, always starting with + // an uppercase letter) is an ordinary Intel compiler option, not a + // language specification. (GCC's "-x" language argument is always + // lowercase.) + state.common_args.push_back(args[i]); + return nullopt; } - if (args_info.input_file.empty()) { - state.explicit_language = args[i + 1]; + + // Special handling for -x: remember the last specified language before the + // input file and strip all -x options from the arguments. + if (args[i].length() == 2) { + if (i == args.size() - 1) { + log("Missing argument to {}", args[i]); + return Statistic::bad_compiler_arguments; + } + if (args_info.input_file.empty()) { + state.explicit_language = args[i + 1]; + } + i++; + return nullopt; } - i++; - return nullopt; - } - if (Util::starts_with(args[i], "-x")) { - if (args_info.input_file.empty()) { - state.explicit_language = args[i].substr(2); + if (args[i].length() >= 3) { + if (args_info.input_file.empty()) { + state.explicit_language = args[i].substr(2); + } + return nullopt; } - return nullopt; } // We need to work out where the output was meant to go. -- 2.47.2