Skip to content

Commit 463a02b

Browse files
authored
[lldb] Part 1 of 2 - Refactor CommandObject::Execute(...) return void (not bool) (llvm#69989)
[lldb] Part 1 of 2 - Refactor `CommandObject::Execute(...)` 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 2 refactors the `CommandObject::DoExecute(...)` method. - See [https://github.com/llvm/llvm-project/pull/69991](https://github.com/llvm/llvm-project/pull/69991) rdar://117378957
1 parent c9ca2fe commit 463a02b

File tree

6 files changed

+22
-26
lines changed

6 files changed

+22
-26
lines changed

lldb/include/lldb/Interpreter/CommandAlias.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class CommandAlias : public CommandObject {
5656

5757
void SetHelpLong(llvm::StringRef str) override;
5858

59-
bool Execute(const char *args_string, CommandReturnObject &result) override;
59+
void Execute(const char *args_string, CommandReturnObject &result) override;
6060

6161
lldb::CommandObjectSP GetUnderlyingCommand() {
6262
return m_underlying_command_sp;

lldb/include/lldb/Interpreter/CommandObject.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ class CommandObject : public std::enable_shared_from_this<CommandObject> {
312312
return false;
313313
}
314314

315-
virtual bool Execute(const char *args_string,
315+
virtual void Execute(const char *args_string,
316316
CommandReturnObject &result) = 0;
317317

318318
protected:
@@ -398,7 +398,7 @@ class CommandObjectParsed : public CommandObject {
398398

399399
~CommandObjectParsed() override = default;
400400

401-
bool Execute(const char *args_string, CommandReturnObject &result) override;
401+
void Execute(const char *args_string, CommandReturnObject &result) override;
402402

403403
protected:
404404
virtual bool DoExecute(Args &command, CommandReturnObject &result) = 0;
@@ -415,7 +415,7 @@ class CommandObjectRaw : public CommandObject {
415415

416416
~CommandObjectRaw() override = default;
417417

418-
bool Execute(const char *args_string, CommandReturnObject &result) override;
418+
void Execute(const char *args_string, CommandReturnObject &result) override;
419419

420420
protected:
421421
virtual bool DoExecute(llvm::StringRef command,

lldb/include/lldb/Interpreter/CommandObjectMultiword.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class CommandObjectMultiword : public CommandObject {
5959
std::optional<std::string> GetRepeatCommand(Args &current_command_args,
6060
uint32_t index) override;
6161

62-
bool Execute(const char *args_string, CommandReturnObject &result) override;
62+
void Execute(const char *args_string, CommandReturnObject &result) override;
6363

6464
bool IsRemovable() const override { return m_can_be_removed; }
6565

@@ -129,7 +129,7 @@ class CommandObjectProxy : public CommandObject {
129129
/// Execute is called) and \a GetProxyCommandObject returned null.
130130
virtual llvm::StringRef GetUnsupportedError();
131131

132-
bool Execute(const char *args_string, CommandReturnObject &result) override;
132+
void Execute(const char *args_string, CommandReturnObject &result) override;
133133

134134
protected:
135135
// These two want to iterate over the subcommand dictionary.

lldb/source/Commands/CommandObjectMultiword.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,25 @@ llvm::Error CommandObjectMultiword::RemoveUserSubcommand(llvm::StringRef cmd_nam
159159
return llvm::Error::success();
160160
}
161161

162-
bool CommandObjectMultiword::Execute(const char *args_string,
162+
void CommandObjectMultiword::Execute(const char *args_string,
163163
CommandReturnObject &result) {
164164
Args args(args_string);
165165
const size_t argc = args.GetArgumentCount();
166166
if (argc == 0) {
167167
this->CommandObject::GenerateHelpText(result);
168-
return result.Succeeded();
168+
return;
169169
}
170170

171171
auto sub_command = args[0].ref();
172172
if (sub_command.empty()) {
173173
result.AppendError("Need to specify a non-empty subcommand.");
174-
return result.Succeeded();
174+
return;
175175
}
176176

177177
if (m_subcommand_dict.empty()) {
178178
result.AppendErrorWithFormat("'%s' does not have any subcommands.\n",
179179
GetCommandName().str().c_str());
180-
return false;
180+
return;
181181
}
182182

183183
StringList matches;
@@ -189,7 +189,7 @@ bool CommandObjectMultiword::Execute(const char *args_string,
189189

190190
args.Shift();
191191
sub_cmd_obj->Execute(args_string, result);
192-
return result.Succeeded();
192+
return;
193193
}
194194

195195
std::string error_msg;
@@ -214,7 +214,6 @@ bool CommandObjectMultiword::Execute(const char *args_string,
214214
}
215215
error_msg.append("\n");
216216
result.AppendRawError(error_msg.c_str());
217-
return false;
218217
}
219218

220219
void CommandObjectMultiword::GenerateHelpText(Stream &output_stream) {
@@ -429,11 +428,10 @@ llvm::StringRef CommandObjectProxy::GetUnsupportedError() {
429428
return "command is not implemented";
430429
}
431430

432-
bool CommandObjectProxy::Execute(const char *args_string,
431+
void CommandObjectProxy::Execute(const char *args_string,
433432
CommandReturnObject &result) {
434-
CommandObject *proxy_command = GetProxyCommandObject();
435-
if (proxy_command)
436-
return proxy_command->Execute(args_string, result);
437-
result.AppendError(GetUnsupportedError());
438-
return false;
433+
if (CommandObject *proxy_command = GetProxyCommandObject())
434+
proxy_command->Execute(args_string, result);
435+
else
436+
result.AppendError(GetUnsupportedError());
439437
}

lldb/source/Interpreter/CommandAlias.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Options *CommandAlias::GetOptions() {
135135
return nullptr;
136136
}
137137

138-
bool CommandAlias::Execute(const char *args_string,
138+
void CommandAlias::Execute(const char *args_string,
139139
CommandReturnObject &result) {
140140
llvm_unreachable("CommandAlias::Execute is not to be called");
141141
}

lldb/source/Interpreter/CommandObject.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ Thread *CommandObject::GetDefaultThread() {
715715
return nullptr;
716716
}
717717

718-
bool CommandObjectParsed::Execute(const char *args_string,
718+
void CommandObjectParsed::Execute(const char *args_string,
719719
CommandReturnObject &result) {
720720
bool handled = false;
721721
Args cmd_args(args_string);
@@ -746,18 +746,17 @@ bool CommandObjectParsed::Execute(const char *args_string,
746746
result.AppendErrorWithFormatv("'{0}' doesn't take any arguments.",
747747
GetCommandName());
748748
Cleanup();
749-
return false;
749+
return;
750750
}
751-
handled = DoExecute(cmd_args, result);
751+
DoExecute(cmd_args, result);
752752
}
753753
}
754754

755755
Cleanup();
756756
}
757-
return handled;
758757
}
759758

760-
bool CommandObjectRaw::Execute(const char *args_string,
759+
void CommandObjectRaw::Execute(const char *args_string,
761760
CommandReturnObject &result) {
762761
bool handled = false;
763762
if (HasOverrideCallback()) {
@@ -770,9 +769,8 @@ bool CommandObjectRaw::Execute(const char *args_string,
770769
}
771770
if (!handled) {
772771
if (CheckRequirements(result))
773-
handled = DoExecute(args_string, result);
772+
DoExecute(args_string, result);
774773

775774
Cleanup();
776775
}
777-
return handled;
778776
}

0 commit comments

Comments
 (0)