]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Pass const Context to process_arg
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 26 Sep 2021 19:56:14 +0000 (21:56 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 26 Sep 2021 19:56:14 +0000 (21:56 +0200)
This narrows down what process_arg is allowed to do.

src/argprocessing.cpp

index 3c94b6f47e1d03a8a55a3160cd37e790c41c59ee..5b5b60540e884498fa7f17f7b48350fe3ac13d24 100644 (file)
@@ -148,7 +148,9 @@ detect_pch(const std::string& option,
 }
 
 bool
-process_profiling_option(Context& ctx, const std::string& arg)
+process_profiling_option(const Context& ctx,
+                         ArgsInfo& args_info,
+                         const std::string& arg)
 {
   static const std::vector<std::string> known_simple_options = {
     "-fprofile-correction",
@@ -168,7 +170,7 @@ process_profiling_option(Context& ctx, const std::string& arg)
   if (util::starts_with(arg, "-fprofile-dir=")) {
     new_profile_path = arg.substr(arg.find('=') + 1);
   } else if (arg == "-fprofile-generate" || arg == "-fprofile-instr-generate") {
-    ctx.args_info.profile_generate = true;
+    args_info.profile_generate = true;
     if (ctx.config.compiler_type() == CompilerType::clang) {
       new_profile_path = ".";
     } else {
@@ -177,13 +179,13 @@ process_profiling_option(Context& ctx, const std::string& arg)
     }
   } else if (util::starts_with(arg, "-fprofile-generate=")
              || util::starts_with(arg, "-fprofile-instr-generate=")) {
-    ctx.args_info.profile_generate = true;
+    args_info.profile_generate = true;
     new_profile_path = arg.substr(arg.find('=') + 1);
   } else if (arg == "-fprofile-use" || arg == "-fprofile-instr-use"
              || arg == "-fprofile-sample-use" || arg == "-fbranch-probabilities"
              || arg == "-fauto-profile") {
     new_profile_use = true;
-    if (ctx.args_info.profile_path.empty()) {
+    if (args_info.profile_path.empty()) {
       new_profile_path = ".";
     }
   } else if (util::starts_with(arg, "-fprofile-use=")
@@ -198,19 +200,19 @@ process_profiling_option(Context& ctx, const std::string& arg)
   }
 
   if (new_profile_use) {
-    if (ctx.args_info.profile_use) {
+    if (args_info.profile_use) {
       LOG_RAW("Multiple profiling options not supported");
       return false;
     }
-    ctx.args_info.profile_use = true;
+    args_info.profile_use = true;
   }
 
   if (!new_profile_path.empty()) {
-    ctx.args_info.profile_path = new_profile_path;
-    LOG("Set profile directory to {}", ctx.args_info.profile_path);
+    args_info.profile_path = new_profile_path;
+    LOG("Set profile directory to {}", args_info.profile_path);
   }
 
-  if (ctx.args_info.profile_generate && ctx.args_info.profile_use) {
+  if (args_info.profile_generate && args_info.profile_use) {
     // Too hard to figure out what the compiler will do.
     LOG_RAW("Both generating and using profile info, giving up");
     return false;
@@ -220,14 +222,13 @@ process_profiling_option(Context& ctx, const std::string& arg)
 }
 
 optional<Statistic>
-process_arg(Context& ctx,
+process_arg(const Context& ctx,
+            ArgsInfo& args_info,
+            Config& config,
             Args& args,
             size_t& args_index,
             ArgumentProcessingState& state)
 {
-  ArgsInfo& args_info = ctx.args_info;
-  Config& config = ctx.config;
-
   size_t& i = args_index;
 
   // The user knows best: just swallow the next arg.
@@ -546,7 +547,7 @@ process_arg(Context& ctx,
   }
 
   if (util::starts_with(args[i], "-MQ") || util::starts_with(args[i], "-MT")) {
-    ctx.args_info.dependency_target_specified = true;
+    args_info.dependency_target_specified = true;
 
     if (args[i].size() == 3) {
       // -MQ arg or -MT arg
@@ -602,7 +603,7 @@ process_arg(Context& ctx,
   if (util::starts_with(args[i], "-fprofile-")
       || util::starts_with(args[i], "-fauto-profile")
       || args[i] == "-fbranch-probabilities") {
-    if (!process_profiling_option(ctx, args[i])) {
+    if (!process_profiling_option(ctx, args_info, args[i])) {
       // The failure is logged by process_profiling_option.
       return Statistic::unsupported_compiler_option;
     }
@@ -1011,7 +1012,8 @@ process_args(Context& ctx)
 
   optional<Statistic> argument_error;
   for (size_t i = 1; i < args.size(); i++) {
-    const auto error = process_arg(ctx, args, i, state);
+    const auto error =
+      process_arg(ctx, ctx.args_info, ctx.config, args, i, state);
     if (error && !argument_error) {
       argument_error = error;
     }