Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make subcommand constructor with options private.
  • Loading branch information
aw-andre committed Nov 13, 2025
commit c960524968a13eded40c5422e4c36d3c53f6ea6c
9 changes: 6 additions & 3 deletions toolchain/driver/build_runtimes_subcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "common/command_line.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "toolchain/driver/carbon_runner.h"
#include "toolchain/driver/codegen_options.h"
#include "toolchain/driver/driver_env.h"
#include "toolchain/driver/driver_subcommand.h"
Expand All @@ -26,19 +27,21 @@ struct BuildRuntimesOptions {

// Implements the link subcommand of the driver.
class BuildRuntimesSubcommand : public DriverSubcommand {
friend CarbonRunner;

Comment on lines +30 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? It doesn't seem like it should be...

public:
explicit BuildRuntimesSubcommand();

// For manual construction of subcommands.
explicit BuildRuntimesSubcommand(BuildRuntimesOptions options);

auto BuildOptions(CommandLine::CommandBuilder& b) -> void override {
options_.Build(b);
}

auto Run(DriverEnv& driver_env) -> DriverResult override;

private:
// For manual construction of subcommands.
explicit BuildRuntimesSubcommand(BuildRuntimesOptions options);

auto RunInternal(DriverEnv& driver_env) -> ErrorOr<std::filesystem::path>;

BuildRuntimesOptions options_;
Expand Down
9 changes: 6 additions & 3 deletions toolchain/driver/clang_subcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "common/command_line.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "toolchain/driver/carbon_runner.h"
#include "toolchain/driver/driver_env.h"
#include "toolchain/driver/driver_subcommand.h"

Expand All @@ -26,19 +27,21 @@ struct ClangOptions {

// Implements the clang subcommand of the driver.
class ClangSubcommand : public DriverSubcommand {
friend CarbonRunner;

public:
explicit ClangSubcommand();

// For manual construction of subcommands.
explicit ClangSubcommand(ClangOptions options);

auto BuildOptions(CommandLine::CommandBuilder& b) -> void override {
options_.Build(b);
}

auto Run(DriverEnv& driver_env) -> DriverResult override;

private:
// For manual construction of subcommands.
explicit ClangSubcommand(ClangOptions options);

ClangOptions options_;
};

Expand Down
9 changes: 6 additions & 3 deletions toolchain/driver/compile_subcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "toolchain/check/check.h"
#include "toolchain/driver/carbon_runner.h"
#include "toolchain/driver/codegen_options.h"
#include "toolchain/driver/driver_env.h"
#include "toolchain/driver/driver_subcommand.h"
Expand Down Expand Up @@ -73,19 +74,21 @@ struct CompileOptions {

// Implements the compile subcommand of the driver.
class CompileSubcommand : public DriverSubcommand {
friend CarbonRunner;

public:
explicit CompileSubcommand();

// For manual construction of subcommands.
explicit CompileSubcommand(CompileOptions options);

auto BuildOptions(CommandLine::CommandBuilder& b) -> void override {
options_.Build(b);
}

auto Run(DriverEnv& driver_env) -> DriverResult override;

private:
// For manual construction of subcommands.
explicit CompileSubcommand(CompileOptions options);

// Does custom validation of the compile-subcommand options structure beyond
// what the command line parsing library supports. Diagnoses and returns false
// on failure.
Expand Down
9 changes: 6 additions & 3 deletions toolchain/driver/format_subcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define CARBON_TOOLCHAIN_DRIVER_FORMAT_SUBCOMMAND_H_

#include "common/command_line.h"
#include "toolchain/driver/carbon_runner.h"
#include "toolchain/driver/driver_env.h"
#include "toolchain/driver/driver_subcommand.h"

Expand All @@ -23,19 +24,21 @@ struct FormatOptions {

// Implements the format subcommand of the driver.
class FormatSubcommand : public DriverSubcommand {
friend CarbonRunner;

public:
explicit FormatSubcommand();

// For manual construction of subcommands.
explicit FormatSubcommand(FormatOptions options);

auto BuildOptions(CommandLine::CommandBuilder& b) -> void override {
options_.Build(b);
}

auto Run(DriverEnv& driver_env) -> DriverResult override;

private:
// For manual construction of subcommands.
explicit FormatSubcommand(FormatOptions options);

FormatOptions options_;
};

Expand Down
9 changes: 6 additions & 3 deletions toolchain/driver/link_subcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "common/error.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "toolchain/driver/carbon_runner.h"
#include "toolchain/driver/codegen_options.h"
#include "toolchain/driver/driver_env.h"
#include "toolchain/driver/driver_subcommand.h"
Expand All @@ -28,19 +29,21 @@ struct LinkOptions {

// Implements the link subcommand of the driver.
class LinkSubcommand : public DriverSubcommand {
friend CarbonRunner;

public:
explicit LinkSubcommand();

// For manual construction of subcommands.
explicit LinkSubcommand(LinkOptions options);

auto BuildOptions(CommandLine::CommandBuilder& b) -> void override {
options_.Build(b);
}

auto Run(DriverEnv& driver_env) -> DriverResult override;

private:
// For manual construction of subcommands.
explicit LinkSubcommand(LinkOptions options);

auto RunInternal(DriverEnv& driver_env) -> ErrorOr<bool>;

LinkOptions options_;
Expand Down
9 changes: 6 additions & 3 deletions toolchain/driver/lld_subcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "common/command_line.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "toolchain/driver/carbon_runner.h"
#include "toolchain/driver/driver_env.h"
#include "toolchain/driver/driver_subcommand.h"

Expand Down Expand Up @@ -36,19 +37,21 @@ struct LldOptions {

// Implements the LLD subcommand of the driver.
class LldSubcommand : public DriverSubcommand {
friend CarbonRunner;

public:
explicit LldSubcommand();

// For manual construction of subcommands.
explicit LldSubcommand(LldOptions options);

auto BuildOptions(CommandLine::CommandBuilder& b) -> void override {
options_.Build(b);
}

auto Run(DriverEnv& driver_env) -> DriverResult override;

private:
// For manual construction of subcommands.
explicit LldSubcommand(LldOptions options);

LldOptions options_;
};

Expand Down
9 changes: 6 additions & 3 deletions toolchain/driver/llvm_subcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "toolchain/base/llvm_tools.h"
#include "toolchain/driver/carbon_runner.h"
#include "toolchain/driver/driver_env.h"
#include "toolchain/driver/driver_subcommand.h"

Expand All @@ -34,12 +35,11 @@ struct LLVMOptions {
//
// This provides access to the full collection of LLVM command line tools.
class LLVMSubcommand : public DriverSubcommand {
friend CarbonRunner;

public:
explicit LLVMSubcommand();

// For manual construction of subcommands.
explicit LLVMSubcommand(LLVMOptions options);

// The LLVM subcommand uses a custom subcommand structure, so `BuildOptions`
// is a no-op and we override the more complex layer.
auto BuildOptions(CommandLine::CommandBuilder& /*b*/) -> void override {
Expand All @@ -54,6 +54,9 @@ class LLVMSubcommand : public DriverSubcommand {
auto Run(DriverEnv& driver_env) -> DriverResult override;

private:
// For manual construction of subcommands.
explicit LLVMSubcommand(LLVMOptions options);

LLVMOptions options_;
};

Expand Down