Make CommandObject help getters/setters use StringRef.

llvm-svn: 286731
This commit is contained in:
Zachary Turner 2016-11-12 20:41:02 +00:00
parent e2411fabda
commit 442f6530d2
10 changed files with 116 additions and 116 deletions

View File

@ -58,13 +58,13 @@ public:
bool IsDashDashCommand() override;
const char *GetHelp() override;
llvm::StringRef GetHelp() override;
const char *GetHelpLong() override;
llvm::StringRef GetHelpLong() override;
void SetHelp(const char *str) override;
void SetHelp(llvm::StringRef str) override;
void SetHelpLong(const char *str) override;
void SetHelpLong(llvm::StringRef str) override;
bool Execute(const char *args_string, CommandReturnObject &result) override;

View File

@ -122,19 +122,19 @@ public:
CommandInterpreter &GetCommandInterpreter() { return m_interpreter; }
virtual const char *GetHelp();
virtual llvm::StringRef GetHelp();
virtual const char *GetHelpLong();
virtual llvm::StringRef GetHelpLong();
virtual const char *GetSyntax();
virtual llvm::StringRef GetSyntax();
llvm::StringRef GetCommandName() const;
virtual void SetHelp(const char *str);
virtual void SetHelp(llvm::StringRef str);
virtual void SetHelpLong(const char *str);
virtual void SetHelpLong(llvm::StringRef str);
void SetSyntax(const char *str);
void SetSyntax(llvm::StringRef str);
// override this to return true if you want to enable the user to delete
// the Command object from the Command dictionary (aliases have their own
@ -167,7 +167,7 @@ public:
StringList &commands_found,
StringList &commands_help) {}
void FormatLongHelpText(Stream &output_strm, const char *long_help);
void FormatLongHelpText(Stream &output_strm, llvm::StringRef long_help);
void GenerateHelpText(CommandReturnObject &result);
@ -219,7 +219,7 @@ public:
bool ParseOptions(Args &args, CommandReturnObject &result);
void SetCommandName(const char *name);
void SetCommandName(llvm::StringRef name);
//------------------------------------------------------------------
/// The input array contains a parsed version of the line. The insertion

View File

@ -90,7 +90,7 @@ public:
// used for this object.
virtual CommandObject *GetProxyCommandObject() = 0;
const char *GetHelpLong() override;
llvm::StringRef GetHelpLong() override;
bool IsRemovable() const override;

View File

@ -542,11 +542,13 @@ const char *SBCommand::GetName() {
}
const char *SBCommand::GetHelp() {
return (IsValid() ? m_opaque_sp->GetHelp() : nullptr);
return (IsValid() ? ConstString(m_opaque_sp->GetHelp()).AsCString()
: nullptr);
}
const char *SBCommand::GetHelpLong() {
return (IsValid() ? m_opaque_sp->GetHelpLong() : nullptr);
return (IsValid() ? ConstString(m_opaque_sp->GetHelpLong()).AsCString()
: nullptr);
}
void SBCommand::SetHelp(const char *help) {

View File

@ -1282,7 +1282,7 @@ public:
: CommandObjectRaw(interpreter, name),
m_function_name(funct), m_synchro(synch), m_fetched_help_long(false) {
if (!help.empty())
SetHelp(help.c_str());
SetHelp(help);
else {
StreamString stream;
stream.Printf("For more information run 'help %s'", name.c_str());
@ -1298,17 +1298,19 @@ public:
ScriptedCommandSynchronicity GetSynchronicity() { return m_synchro; }
const char *GetHelpLong() override {
if (!m_fetched_help_long) {
ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
if (scripter) {
std::string docstring;
m_fetched_help_long = scripter->GetDocumentationForItem(
m_function_name.c_str(), docstring);
if (!docstring.empty())
SetHelpLong(docstring.c_str());
}
}
llvm::StringRef GetHelpLong() override {
if (m_fetched_help_long)
return CommandObjectRaw::GetHelpLong();
ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
if (!scripter)
return CommandObjectRaw::GetHelpLong();
std::string docstring;
m_fetched_help_long =
scripter->GetDocumentationForItem(m_function_name.c_str(), docstring);
if (!docstring.empty())
SetHelpLong(docstring);
return CommandObjectRaw::GetHelpLong();
}
@ -1371,31 +1373,34 @@ public:
ScriptedCommandSynchronicity GetSynchronicity() { return m_synchro; }
const char *GetHelp() override {
if (!m_fetched_help_short) {
ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
if (scripter) {
std::string docstring;
m_fetched_help_short =
scripter->GetShortHelpForCommandObject(m_cmd_obj_sp, docstring);
if (!docstring.empty())
SetHelp(docstring.c_str());
}
}
llvm::StringRef GetHelp() override {
if (m_fetched_help_short)
return CommandObjectRaw::GetHelp();
ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
if (!scripter)
return CommandObjectRaw::GetHelp();
std::string docstring;
m_fetched_help_short =
scripter->GetShortHelpForCommandObject(m_cmd_obj_sp, docstring);
if (!docstring.empty())
SetHelp(docstring);
return CommandObjectRaw::GetHelp();
}
const char *GetHelpLong() override {
if (!m_fetched_help_long) {
ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
if (scripter) {
std::string docstring;
m_fetched_help_long =
scripter->GetLongHelpForCommandObject(m_cmd_obj_sp, docstring);
if (!docstring.empty())
SetHelpLong(docstring.c_str());
}
}
llvm::StringRef GetHelpLong() override {
if (m_fetched_help_long)
return CommandObjectRaw::GetHelpLong();
ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
if (!scripter)
return CommandObjectRaw::GetHelpLong();
std::string docstring;
m_fetched_help_long =
scripter->GetLongHelpForCommandObject(m_cmd_obj_sp, docstring);
if (!docstring.empty())
SetHelpLong(docstring);
return CommandObjectRaw::GetHelpLong();
}

View File

@ -278,11 +278,11 @@ CommandObjectProxy::CommandObjectProxy(CommandInterpreter &interpreter,
CommandObjectProxy::~CommandObjectProxy() = default;
const char *CommandObjectProxy::GetHelpLong() {
llvm::StringRef CommandObjectProxy::GetHelpLong() {
CommandObject *proxy_command = GetProxyCommandObject();
if (proxy_command)
return proxy_command->GetHelpLong();
return nullptr;
return llvm::StringRef();
}
bool CommandObjectProxy::IsRemovable() const {

View File

@ -2841,26 +2841,25 @@ public:
Options *GetOptions() override { return &m_option_group; }
const char *GetHelpLong() override {
if (m_cmd_help_long.empty()) {
StreamString stream;
// FIXME: hardcoding languages is not good
lldb::LanguageType languages[] = {eLanguageTypeObjC,
eLanguageTypeC_plus_plus};
llvm::StringRef GetHelpLong() override {
if (!m_cmd_help_long.empty())
return m_cmd_help_long;
for (const auto lang_type : languages) {
if (auto language = Language::FindPlugin(lang_type)) {
if (const char *help =
language->GetLanguageSpecificTypeLookupHelp()) {
stream.Printf("%s\n", help);
}
StreamString stream;
// FIXME: hardcoding languages is not good
lldb::LanguageType languages[] = {eLanguageTypeObjC,
eLanguageTypeC_plus_plus};
for (const auto lang_type : languages) {
if (auto language = Language::FindPlugin(lang_type)) {
if (const char *help = language->GetLanguageSpecificTypeLookupHelp()) {
stream.Printf("%s\n", help);
}
}
if (stream.GetData())
m_cmd_help_long.assign(stream.GetString());
}
return this->CommandObject::GetHelpLong();
m_cmd_help_long = stream.GetString();
return m_cmd_help_long;
}
bool DoExecute(const char *raw_command_line,

View File

@ -224,28 +224,28 @@ std::pair<lldb::CommandObjectSP, OptionArgVectorSP> CommandAlias::Desugar() {
// allow CommandAlias objects to provide their own help, but fallback to the
// info
// for the underlying command if no customization has been provided
void CommandAlias::SetHelp(const char *str) {
void CommandAlias::SetHelp(llvm::StringRef str) {
this->CommandObject::SetHelp(str);
m_did_set_help = true;
}
void CommandAlias::SetHelpLong(const char *str) {
void CommandAlias::SetHelpLong(llvm::StringRef str) {
this->CommandObject::SetHelpLong(str);
m_did_set_help_long = true;
}
const char *CommandAlias::GetHelp() {
llvm::StringRef CommandAlias::GetHelp() {
if (!m_cmd_help_short.empty() || m_did_set_help)
return m_cmd_help_short.c_str();
return m_cmd_help_short;
if (IsValid())
return m_underlying_command_sp->GetHelp();
return nullptr;
return llvm::StringRef();
}
const char *CommandAlias::GetHelpLong() {
llvm::StringRef CommandAlias::GetHelpLong() {
if (!m_cmd_help_long.empty() || m_did_set_help_long)
return m_cmd_help_long.c_str();
return m_cmd_help_long;
if (IsValid())
return m_underlying_command_sp->GetHelpLong();
return nullptr;
return llvm::StringRef();
}

View File

@ -52,48 +52,42 @@ CommandObject::CommandObject(CommandInterpreter &interpreter, llvm::StringRef na
CommandObject::~CommandObject() {}
const char *CommandObject::GetHelp() { return m_cmd_help_short.c_str(); }
llvm::StringRef CommandObject::GetHelp() { return m_cmd_help_short; }
const char *CommandObject::GetHelpLong() { return m_cmd_help_long.c_str(); }
llvm::StringRef CommandObject::GetHelpLong() { return m_cmd_help_long; }
const char *CommandObject::GetSyntax() {
if (m_cmd_syntax.length() == 0) {
StreamString syntax_str;
syntax_str.Printf("%s", GetCommandName().str().c_str());
if (!IsDashDashCommand() && GetOptions() != nullptr)
syntax_str.Printf(" <cmd-options>");
if (m_arguments.size() > 0) {
syntax_str.Printf(" ");
if (!IsDashDashCommand() && WantsRawCommandString() && GetOptions() &&
GetOptions()->NumCommandOptions())
syntax_str.Printf("-- ");
GetFormattedCommandArguments(syntax_str);
}
m_cmd_syntax = syntax_str.GetData();
llvm::StringRef CommandObject::GetSyntax() {
if (m_cmd_syntax.empty())
return m_cmd_syntax;
StreamString syntax_str;
syntax_str.PutCString(GetCommandName());
if (!IsDashDashCommand() && GetOptions() != nullptr)
syntax_str.PutCString(" <cmd-options>");
if (!m_arguments.empty()) {
syntax_str.PutCString(" ");
if (!IsDashDashCommand() && WantsRawCommandString() && GetOptions() &&
GetOptions()->NumCommandOptions())
syntax_str.PutCString("-- ");
GetFormattedCommandArguments(syntax_str);
}
m_cmd_syntax = syntax_str.GetData();
return m_cmd_syntax.c_str();
return m_cmd_syntax;
}
llvm::StringRef CommandObject::GetCommandName() const { return m_cmd_name; }
void CommandObject::SetCommandName(const char *name) { m_cmd_name = name; }
void CommandObject::SetCommandName(llvm::StringRef name) { m_cmd_name = name; }
void CommandObject::SetHelp(const char *cstr) {
if (cstr)
m_cmd_help_short = cstr;
else
m_cmd_help_short.assign("");
}
void CommandObject::SetHelp(llvm::StringRef str) { m_cmd_help_short = str; }
void CommandObject::SetHelpLong(const char *cstr) {
if (cstr)
m_cmd_help_long = cstr;
else
m_cmd_help_long.assign("");
}
void CommandObject::SetHelpLong(llvm::StringRef str) { m_cmd_help_long = str; }
void CommandObject::SetSyntax(const char *cstr) { m_cmd_syntax = cstr; }
void CommandObject::SetSyntax(llvm::StringRef str) { m_cmd_syntax = str; }
Options *CommandObject::GetOptions() {
// By default commands don't have options unless this virtual function
@ -331,15 +325,15 @@ bool CommandObject::HelpTextContainsWord(const char *search_word,
bool found_word = false;
const char *short_help = GetHelp();
const char *long_help = GetHelpLong();
const char *syntax_help = GetSyntax();
llvm::StringRef short_help = GetHelp();
llvm::StringRef long_help = GetHelpLong();
llvm::StringRef syntax_help = GetSyntax();
if (search_short_help && short_help && strcasestr(short_help, search_word))
if (search_short_help && short_help.contains_lower(search_word))
found_word = true;
else if (search_long_help && long_help && strcasestr(long_help, search_word))
else if (search_long_help && long_help.contains_lower(search_word))
found_word = true;
else if (search_syntax && syntax_help && strcasestr(syntax_help, search_word))
else if (search_syntax && syntax_help.contains_lower(search_word))
found_word = true;
if (!found_word && search_options && GetOptions() != nullptr) {
@ -842,7 +836,7 @@ static const char *ExprPathHelpTextCallback() {
}
void CommandObject::FormatLongHelpText(Stream &output_strm,
const char *long_help) {
llvm::StringRef long_help) {
CommandInterpreter &interpreter = GetCommandInterpreter();
std::stringstream lineStream(long_help);
std::string line;
@ -884,8 +878,8 @@ void CommandObject::GenerateHelpText(Stream &output_strm) {
output_strm, this,
GetCommandInterpreter().GetDebugger().GetTerminalWidth());
}
const char *long_help = GetHelpLong();
if ((long_help != nullptr) && (strlen(long_help) > 0)) {
llvm::StringRef long_help = GetHelpLong();
if (!long_help.empty()) {
FormatLongHelpText(output_strm, long_help);
}
if (!IsDashDashCommand() && options && options->NumCommandOptions() > 0) {

View File

@ -71,7 +71,7 @@ bool CommandObjectRegexCommand::DoExecute(const char *command,
}
}
result.SetStatus(eReturnStatusFailed);
if (GetSyntax() != nullptr)
if (!GetSyntax().empty())
result.AppendError(GetSyntax());
else
result.AppendErrorWithFormat("Command contents '%s' failed to match any "