]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Simplify logic of -x handling 678/head
authorAlexander Lanin <alex@lanin.de>
Fri, 2 Oct 2020 20:04:12 +0000 (22:04 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 5 Oct 2020 07:36:59 +0000 (09:36 +0200)
src/argprocessing.cpp

index 86b96a10fa87d6c1c493d9b216639f42bae03b63..c3593e6ded274e167c1bac0e93f3b60f8855e3bb 100644 (file)
@@ -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.