Skip to content

Commit

Permalink
[lldb] Part 2 of 2 - Refactor CommandObject::DoExecute(...) return …
Browse files Browse the repository at this point in the history
…`void` (not `bool`) (#69991)

[lldb] Part 2 of 2 - Refactor `CommandObject::DoExecute(...)` to return
`void` instead of ~~`bool`~~

Justifications:
- The code doesn't ultimately apply the `true`/`false` return values.
- The methods already pass around a `CommandReturnObject`, typically
with a `result` parameter.
- Each command return object already contains:
	- A more precise status
	- The error code(s) that apply to that status

Part 1 refactors the `CommandObject::Execute(...)` method.
- See
[#69989

rdar://117378957
  • Loading branch information
PortalPete committed Oct 30, 2023
1 parent 2446439 commit 92d8a28
Show file tree
Hide file tree
Showing 57 changed files with 747 additions and 1,041 deletions.
4 changes: 2 additions & 2 deletions lldb/include/lldb/Interpreter/CommandObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class CommandObjectParsed : public CommandObject {
void Execute(const char *args_string, CommandReturnObject &result) override;

protected:
virtual bool DoExecute(Args &command, CommandReturnObject &result) = 0;
virtual void DoExecute(Args &command, CommandReturnObject &result) = 0;

bool WantsRawCommandString() override { return false; }
};
Expand All @@ -418,7 +418,7 @@ class CommandObjectRaw : public CommandObject {
void Execute(const char *args_string, CommandReturnObject &result) override;

protected:
virtual bool DoExecute(llvm::StringRef command,
virtual void DoExecute(llvm::StringRef command,
CommandReturnObject &result) = 0;

bool WantsRawCommandString() override { return true; }
Expand Down
6 changes: 2 additions & 4 deletions lldb/source/API/SBCommandInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,11 @@ class CommandPluginInterfaceImplementation : public CommandObjectParsed {
}

protected:
bool DoExecute(Args &command, CommandReturnObject &result) override {
void DoExecute(Args &command, CommandReturnObject &result) override {
SBCommandReturnObject sb_return(result);
SBCommandInterpreter sb_interpreter(&m_interpreter);
SBDebugger debugger_sb(m_interpreter.GetDebugger().shared_from_this());
bool ret = m_backend->DoExecute(debugger_sb, command.GetArgumentVector(),
sb_return);
return ret;
m_backend->DoExecute(debugger_sb, command.GetArgumentVector(), sb_return);
}
std::shared_ptr<lldb::SBCommandPluginInterface> m_backend;
std::optional<std::string> m_auto_repeat_command;
Expand Down
4 changes: 1 addition & 3 deletions lldb/source/Commands/CommandObjectApropos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ CommandObjectApropos::CommandObjectApropos(CommandInterpreter &interpreter)

CommandObjectApropos::~CommandObjectApropos() = default;

bool CommandObjectApropos::DoExecute(Args &args, CommandReturnObject &result) {
void CommandObjectApropos::DoExecute(Args &args, CommandReturnObject &result) {
const size_t argc = args.GetArgumentCount();

if (argc == 1) {
Expand Down Expand Up @@ -90,6 +90,4 @@ bool CommandObjectApropos::DoExecute(Args &args, CommandReturnObject &result) {
} else {
result.AppendError("'apropos' must be called with exactly one argument.\n");
}

return result.Succeeded();
}
2 changes: 1 addition & 1 deletion lldb/source/Commands/CommandObjectApropos.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CommandObjectApropos : public CommandObjectParsed {
~CommandObjectApropos() override;

protected:
bool DoExecute(Args &command, CommandReturnObject &result) override;
void DoExecute(Args &command, CommandReturnObject &result) override;
};

} // namespace lldb_private
Expand Down

0 comments on commit 92d8a28

Please sign in to comment.