Remove unused methods in commands, tools, writers

Delete unreferenced methods and unused CommandSwitches fields across
Builder, BuilderRecord, CommandSwitches, Toolchain, RustTool,
SubstitutionWriter, and PBXProject.

Change-Id: I2e322501765a4a1d9e8b83c24b90aa087f231d1b
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/29047
Commit-Queue: Takuto Ikuta <tikuta@google.com>
Reviewed-by: David Turner <digit@google.com>
diff --git a/src/gn/builder.cc b/src/gn/builder.cc
index bf5ec83..932c501 100644
--- a/src/gn/builder.cc
+++ b/src/gn/builder.cc
@@ -156,16 +156,6 @@
   return record->item()->AsToolchain();
 }
 
-std::vector<const BuilderRecord*> Builder::GetAllRecords() const {
-  std::vector<const BuilderRecord*> result;
-  result.reserve(records_.size());
-  for (const auto& record : records_)
-    result.push_back(&record);
-  // Ensure deterministic outputs.
-  std::sort(result.begin(), result.end(), BuilderRecord::LabelCompare);
-  return result;
-}
-
 std::vector<const Item*> Builder::GetAllResolvedItems() const {
   std::vector<const Item*> result;
   result.reserve(records_.size());
diff --git a/src/gn/builder.h b/src/gn/builder.h
index 542b751..394c343 100644
--- a/src/gn/builder.h
+++ b/src/gn/builder.h
@@ -44,8 +44,6 @@
   const Item* GetItem(const Label& label) const;
   const Toolchain* GetToolchain(const Label& label) const;
 
-  std::vector<const BuilderRecord*> GetAllRecords() const;
-
   // Returns items which should be generated and which are defined.
   std::vector<const Item*> GetAllResolvedItems() const;
 
diff --git a/src/gn/builder_record.h b/src/gn/builder_record.h
index 2dc4c58..f3c2040 100644
--- a/src/gn/builder_record.h
+++ b/src/gn/builder_record.h
@@ -262,18 +262,6 @@
 
   // Used by unit-tests.
 
-  // Records that are waiting on this one to be defined. This is used for
-  // "validations" dependencies which don't require the target to be fully
-  // resolved, only defined.
-  BuilderRecordSet waiting_on_validation_definition() const {
-    BuilderRecordSet result;
-    for (const auto& pair : waiting_map_) {
-      if (pair.second.wait_validation_defined)
-        result.add(pair.first);
-    }
-    return result;
-  }
-
   // Records that are waiting on this one to be resolved. This is the other
   // end of the "unresolved deps" arrow for standard dependencies.
   BuilderRecordSet waiting_on_resolution() const {
diff --git a/src/gn/commands.cc b/src/gn/commands.cc
index 1c2c16b..9918a39 100644
--- a/src/gn/commands.cc
+++ b/src/gn/commands.cc
@@ -451,19 +451,6 @@
 bool CommandSwitches::InitFrom(const base::CommandLine& cmdline) {
   CommandSwitches result;
   result.initialized_ = true;
-  result.has_quiet_ = cmdline.HasSwitch("a");
-  result.has_force_ = cmdline.HasSwitch("force");
-  result.has_all_ = cmdline.HasSwitch("all");
-  result.has_blame_ = cmdline.HasSwitch("blame");
-  result.has_tree_ = cmdline.HasSwitch("tree");
-  result.has_format_json_ = cmdline.GetSwitchValueString("format") == "json";
-  result.has_default_toolchain_ =
-      cmdline.HasSwitch(switches::kDefaultToolchain);
-
-  result.has_check_generated_ = cmdline.HasSwitch("check-generated");
-  result.has_check_system_ = cmdline.HasSwitch("check-system");
-  result.has_public_ = cmdline.HasSwitch("public");
-  result.has_with_data_ = cmdline.HasSwitch("with-data");
 
   std::string_view target_print_switch = "as";
   if (cmdline.HasSwitch(target_print_switch)) {
@@ -553,9 +540,6 @@
     }
   }
 
-  result.meta_rebase_dir_ = cmdline.GetSwitchValueString("rebase");
-  result.meta_data_keys_ = cmdline.GetSwitchValueString("data");
-  result.meta_walk_keys_ = cmdline.GetSwitchValueString("walk");
   *this = result;
   return true;
 }
diff --git a/src/gn/commands.h b/src/gn/commands.h
index f725c92..91749b4 100644
--- a/src/gn/commands.h
+++ b/src/gn/commands.h
@@ -267,39 +267,6 @@
   // Default constructor.
   CommandSwitches() = default;
 
-  // For --quiet, used by `refs`.
-  bool has_quiet() const { return has_quiet_; }
-
-  // For --force, used by `check`.
-  bool has_force() const { return has_force_; }
-
-  // For --all, used by `desc` and `refs`.
-  bool has_all() const { return has_all_; }
-
-  // For --blame used by `desc`.
-  bool has_blame() const { return has_blame_; }
-
-  // For --tree used by `desc` and `refs`.
-  bool has_tree() const { return has_tree_; }
-
-  // For --format=json used by `desc`.
-  bool has_format_json() const { return has_format_json_; }
-
-  // For --default-toolchain used by `desc`, `refs`.
-  bool has_default_toolchain() const { return has_default_toolchain_; }
-
-  // For --check-generated
-  bool has_check_generated() const { return has_check_generated_; }
-
-  // For --check-system
-  bool has_check_system() const { return has_check_system_; }
-
-  // For --public
-  bool has_public() const { return has_public_; }
-
-  // For --with-data
-  bool has_with_data() const { return has_with_data_; }
-
   // For --as=(buildtype|label|output).
   enum TargetPrintMode {
     TARGET_PRINT_BUILDFILE,
@@ -325,11 +292,6 @@
   };
   TestonlyMode testonly_mode() const { return testonly_mode_; }
 
-  // For --rebase, --walk and --data in `gn meta`
-  std::string meta_rebase_dir() const { return meta_rebase_dir_; }
-  std::string meta_data_keys() const { return meta_data_keys_; }
-  std::string meta_walk_keys() const { return meta_walk_keys_; }
-
   // Initialize the global set from a given command line.
   // Must be called early from main(). On success return true,
   // on failure return false after printing an error message.
@@ -350,26 +312,11 @@
   static CommandSwitches s_global_switches_;
 
   bool initialized_ = false;
-  bool has_quiet_ = false;
-  bool has_force_ = false;
-  bool has_all_ = false;
-  bool has_blame_ = false;
-  bool has_tree_ = false;
-  bool has_format_json_ = false;
-  bool has_default_toolchain_ = false;
-  bool has_check_generated_ = false;
-  bool has_check_system_ = false;
-  bool has_public_ = false;
-  bool has_with_data_ = false;
 
   TargetPrintMode target_print_mode_ = TARGET_PRINT_LABEL;
   std::vector<Target::OutputType> target_types_;
   std::vector<Target::OutputType> target_exclude_types_;
   TestonlyMode testonly_mode_ = TESTONLY_NONE;
-
-  std::string meta_rebase_dir_;
-  std::string meta_data_keys_;
-  std::string meta_walk_keys_;
 };
 
 // Helper functions for some commands ------------------------------------------
diff --git a/src/gn/rust_tool.cc b/src/gn/rust_tool.cc
index 2cf2e2d..a051d8f 100644
--- a/src/gn/rust_tool.cc
+++ b/src/gn/rust_tool.cc
@@ -62,21 +62,6 @@
   return rust_sysroot_;
 }
 
-bool RustTool::SetOutputExtension(const Value* value,
-                                  std::string* var,
-                                  Err* err) {
-  DCHECK(!complete_);
-  if (!value)
-    return true;  // Not present is fine.
-  if (!value->VerifyTypeIs(Value::STRING, err))
-    return false;
-  if (value->string_value().empty())
-    return true;
-
-  *var = std::move(value->string_value());
-  return true;
-}
-
 bool RustTool::ReadOutputsPatternList(Scope* scope,
                                       const char* var,
                                       SubstitutionList* field,
diff --git a/src/gn/rust_tool.h b/src/gn/rust_tool.h
index 76e8bf1..d067d11 100644
--- a/src/gn/rust_tool.h
+++ b/src/gn/rust_tool.h
@@ -69,7 +69,6 @@
   std::string rust_sysroot_;
   std::string dynamic_link_switch_;
 
-  bool SetOutputExtension(const Value* value, std::string* var, Err* err);
   bool ReadOutputsPatternList(Scope* scope,
                               const char* var,
                               SubstitutionList* field,
diff --git a/src/gn/substitution_writer.cc b/src/gn/substitution_writer.cc
index 8d28f7b..9faa012 100644
--- a/src/gn/substitution_writer.cc
+++ b/src/gn/substitution_writer.cc
@@ -402,34 +402,6 @@
 }
 
 // static
-OutputFile SubstitutionWriter::ApplyPatternToTargetAsOutputFile(
-    const Target* target,
-    const Tool* tool,
-    const SubstitutionPattern& pattern) {
-  std::string result_value;
-  for (const auto& subrange : pattern.ranges()) {
-    if (subrange.type == &SubstitutionLiteral) {
-      result_value.append(subrange.literal);
-    } else {
-      std::string subst;
-      CHECK(GetTargetSubstitution(target, subrange.type, &subst));
-      result_value.append(subst);
-    }
-  }
-  return OutputFile(result_value);
-}
-
-// static
-void SubstitutionWriter::ApplyListToTargetAsOutputFile(
-    const Target* target,
-    const Tool* tool,
-    const SubstitutionList& list,
-    std::vector<OutputFile>* output) {
-  for (const auto& item : list.list())
-    output->push_back(ApplyPatternToTargetAsOutputFile(target, tool, item));
-}
-
-// static
 bool SubstitutionWriter::GetTargetSubstitution(const Target* target,
                                                const Substitution* type,
                                                std::string* result) {
diff --git a/src/gn/substitution_writer.h b/src/gn/substitution_writer.h
index 48cd1e0..0dbd8b3 100644
--- a/src/gn/substitution_writer.h
+++ b/src/gn/substitution_writer.h
@@ -175,18 +175,8 @@
   // Target substitutions ------------------------------------------------------
   //
   // Handles the target substitutions that apply to both compiler and linker
-  // tools.
-  static OutputFile ApplyPatternToTargetAsOutputFile(
-      const Target* target,
-      const Tool* tool,
-      const SubstitutionPattern& pattern);
-  static void ApplyListToTargetAsOutputFile(const Target* target,
-                                            const Tool* tool,
-                                            const SubstitutionList& list,
-                                            std::vector<OutputFile>* output);
-
-  // This function is slightly different than the other substitution getters
-  // since it can handle failure (since it is designed to be used by the
+  // tools. This function is slightly different than the other substitution
+  // getters since it can handle failure (since it is designed to be used by the
   // compiler and linker ones which will fall through if it's not a common tool
   // one).
   static bool GetTargetSubstitution(const Target* target,
diff --git a/src/gn/toolchain.cc b/src/gn/toolchain.cc
index 334277f..670d540 100644
--- a/src/gn/toolchain.cc
+++ b/src/gn/toolchain.cc
@@ -52,27 +52,6 @@
   return nullptr;
 }
 
-GeneralTool* Toolchain::GetToolAsGeneral(const char* name) {
-  if (Tool* tool = GetTool(name)) {
-    return tool->AsGeneral();
-  }
-  return nullptr;
-}
-
-const GeneralTool* Toolchain::GetToolAsGeneral(const char* name) const {
-  if (const Tool* tool = GetTool(name)) {
-    return tool->AsGeneral();
-  }
-  return nullptr;
-}
-
-CTool* Toolchain::GetToolAsC(const char* name) {
-  if (Tool* tool = GetTool(name)) {
-    return tool->AsC();
-  }
-  return nullptr;
-}
-
 const CTool* Toolchain::GetToolAsC(const char* name) const {
   if (const Tool* tool = GetTool(name)) {
     return tool->AsC();
@@ -80,13 +59,6 @@
   return nullptr;
 }
 
-RustTool* Toolchain::GetToolAsRust(const char* name) {
-  if (Tool* tool = GetTool(name)) {
-    return tool->AsRust();
-  }
-  return nullptr;
-}
-
 const RustTool* Toolchain::GetToolAsRust(const char* name) const {
   if (const Tool* tool = GetTool(name)) {
     return tool->AsRust();
@@ -94,20 +66,6 @@
   return nullptr;
 }
 
-BuiltinTool* Toolchain::GetToolAsBuiltin(const char* name) {
-  if (Tool* tool = GetTool(name)) {
-    return tool->AsBuiltin();
-  }
-  return nullptr;
-}
-
-const BuiltinTool* Toolchain::GetToolAsBuiltin(const char* name) const {
-  if (const Tool* tool = GetTool(name)) {
-    return tool->AsBuiltin();
-  }
-  return nullptr;
-}
-
 void Toolchain::SetTool(std::unique_ptr<Tool> t) {
   DCHECK(t->name() != Tool::kToolNone);
   DCHECK(tools_.find(t->name()) == tools_.end());
@@ -127,25 +85,6 @@
   return GetTool(Tool::GetToolTypeForSourceType(type));
 }
 
-const CTool* Toolchain::GetToolForSourceTypeAsC(SourceFile::Type type) const {
-  return GetToolAsC(Tool::GetToolTypeForSourceType(type));
-}
-
-const GeneralTool* Toolchain::GetToolForSourceTypeAsGeneral(
-    SourceFile::Type type) const {
-  return GetToolAsGeneral(Tool::GetToolTypeForSourceType(type));
-}
-
-const RustTool* Toolchain::GetToolForSourceTypeAsRust(
-    SourceFile::Type type) const {
-  return GetToolAsRust(Tool::GetToolTypeForSourceType(type));
-}
-
-const BuiltinTool* Toolchain::GetToolForSourceTypeAsBuiltin(
-    SourceFile::Type type) const {
-  return GetToolAsBuiltin(Tool::GetToolTypeForSourceType(type));
-}
-
 const Tool* Toolchain::GetToolForTargetFinalOutput(const Target* target) const {
   return GetTool(Tool::GetToolTypeForTargetFinalOutput(target));
 }
@@ -155,17 +94,7 @@
   return GetToolAsC(Tool::GetToolTypeForTargetFinalOutput(target));
 }
 
-const GeneralTool* Toolchain::GetToolForTargetFinalOutputAsGeneral(
-    const Target* target) const {
-  return GetToolAsGeneral(Tool::GetToolTypeForTargetFinalOutput(target));
-}
-
 const RustTool* Toolchain::GetToolForTargetFinalOutputAsRust(
     const Target* target) const {
   return GetToolAsRust(Tool::GetToolTypeForTargetFinalOutput(target));
 }
-
-const BuiltinTool* Toolchain::GetToolForTargetFinalOutputAsBuiltin(
-    const Target* target) const {
-  return GetToolAsBuiltin(Tool::GetToolTypeForTargetFinalOutput(target));
-}
diff --git a/src/gn/toolchain.h b/src/gn/toolchain.h
index d83a64e..4ebd1ef 100644
--- a/src/gn/toolchain.h
+++ b/src/gn/toolchain.h
@@ -16,8 +16,6 @@
 #include "gn/tool.h"
 #include "gn/value.h"
 
-class BuiltinTool;
-
 // Holds information on a specific toolchain. This data is filled in when we
 // encounter a toolchain definition.
 //
@@ -58,14 +56,8 @@
   const Tool* GetTool(const char* name) const;
 
   // Returns null if the tool hasn't been defined or is not the correct type.
-  GeneralTool* GetToolAsGeneral(const char* name);
-  const GeneralTool* GetToolAsGeneral(const char* name) const;
-  CTool* GetToolAsC(const char* name);
   const CTool* GetToolAsC(const char* name) const;
-  RustTool* GetToolAsRust(const char* name);
   const RustTool* GetToolAsRust(const char* name) const;
-  BuiltinTool* GetToolAsBuiltin(const char* name);
-  const BuiltinTool* GetToolAsBuiltin(const char* name) const;
 
   // Set a tool. When all tools are configured, you should call
   // ToolchainSetupComplete().
@@ -94,10 +86,6 @@
 
   // Returns the tool for compiling the given source file type.
   const Tool* GetToolForSourceType(SourceFile::Type type) const;
-  const CTool* GetToolForSourceTypeAsC(SourceFile::Type type) const;
-  const GeneralTool* GetToolForSourceTypeAsGeneral(SourceFile::Type type) const;
-  const RustTool* GetToolForSourceTypeAsRust(SourceFile::Type type) const;
-  const BuiltinTool* GetToolForSourceTypeAsBuiltin(SourceFile::Type type) const;
 
   // Returns the tool that produces the final output for the given target type.
   // This isn't necessarily the tool you would expect. For copy target, this
@@ -105,11 +93,7 @@
   // target is a phony alias to the set of copies done so there is one output.
   const Tool* GetToolForTargetFinalOutput(const Target* target) const;
   const CTool* GetToolForTargetFinalOutputAsC(const Target* target) const;
-  const GeneralTool* GetToolForTargetFinalOutputAsGeneral(
-      const Target* target) const;
   const RustTool* GetToolForTargetFinalOutputAsRust(const Target* target) const;
-  const BuiltinTool* GetToolForTargetFinalOutputAsBuiltin(
-      const Target* target) const;
 
   const SubstitutionBits& substitution_bits() const {
     DCHECK(setup_complete_);
diff --git a/src/gn/xcode_object.cc b/src/gn/xcode_object.cc
index 1526ec8..7d0d0fe 100644
--- a/src/gn/xcode_object.cc
+++ b/src/gn/xcode_object.cc
@@ -887,21 +887,6 @@
   return static_cast<PBXNativeTarget*>(targets_.back().get());
 }
 
-void PBXProject::SetProjectDirPath(const std::string& project_dir_path) {
-  DCHECK(!project_dir_path.empty());
-  project_dir_path_.assign(project_dir_path);
-}
-
-void PBXProject::SetProjectRoot(const std::string& project_root) {
-  DCHECK(!project_root.empty());
-  project_root_.assign(project_root);
-}
-
-void PBXProject::AddTarget(std::unique_ptr<PBXTarget> target) {
-  DCHECK(target);
-  targets_.push_back(std::move(target));
-}
-
 PBXObjectClass PBXProject::Class() const {
   return PBXProjectClass;
 }
diff --git a/src/gn/xcode_object.h b/src/gn/xcode_object.h
index 3bf29c9..2877dc2 100644
--- a/src/gn/xcode_object.h
+++ b/src/gn/xcode_object.h
@@ -392,10 +392,6 @@
       const std::string& shell_script,
       const PBXAttributes& extra_attributes = PBXAttributes());
 
-  void SetProjectDirPath(const std::string& project_dir_path);
-  void SetProjectRoot(const std::string& project_root);
-  void AddTarget(std::unique_ptr<PBXTarget> target);
-
   // PBXObject implementation.
   PBXObjectClass Class() const override;
   std::string Name() const override;