[Lldb-commits] [lldb] r286731 - Make CommandObject help getters/setters use StringRef.
Zachary Turner via lldb-commits
lldb-commits at lists.llvm.org
Sat Nov 12 12:41:03 PST 2016
Author: zturner
Date: Sat Nov 12 14:41:02 2016
New Revision: 286731
URL: http://llvm.org/viewvc/llvm-project?rev=286731&view=rev
Log:
Make CommandObject help getters/setters use StringRef.
Modified:
lldb/trunk/include/lldb/Interpreter/CommandAlias.h
lldb/trunk/include/lldb/Interpreter/CommandObject.h
lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h
lldb/trunk/source/API/SBCommandInterpreter.cpp
lldb/trunk/source/Commands/CommandObjectCommands.cpp
lldb/trunk/source/Commands/CommandObjectMultiword.cpp
lldb/trunk/source/Commands/CommandObjectType.cpp
lldb/trunk/source/Interpreter/CommandAlias.cpp
lldb/trunk/source/Interpreter/CommandObject.cpp
lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp
Modified: lldb/trunk/include/lldb/Interpreter/CommandAlias.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandAlias.h?rev=286731&r1=286730&r2=286731&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandAlias.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandAlias.h Sat Nov 12 14:41:02 2016
@@ -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;
Modified: lldb/trunk/include/lldb/Interpreter/CommandObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandObject.h?rev=286731&r1=286730&r2=286731&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandObject.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandObject.h Sat Nov 12 14:41:02 2016
@@ -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
Modified: lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h?rev=286731&r1=286730&r2=286731&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h Sat Nov 12 14:41:02 2016
@@ -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;
Modified: lldb/trunk/source/API/SBCommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCommandInterpreter.cpp?rev=286731&r1=286730&r2=286731&view=diff
==============================================================================
--- lldb/trunk/source/API/SBCommandInterpreter.cpp (original)
+++ lldb/trunk/source/API/SBCommandInterpreter.cpp Sat Nov 12 14:41:02 2016
@@ -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) {
Modified: lldb/trunk/source/Commands/CommandObjectCommands.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCommands.cpp?rev=286731&r1=286730&r2=286731&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectCommands.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectCommands.cpp Sat Nov 12 14:41:02 2016
@@ -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();
}
Modified: lldb/trunk/source/Commands/CommandObjectMultiword.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectMultiword.cpp?rev=286731&r1=286730&r2=286731&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectMultiword.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectMultiword.cpp Sat Nov 12 14:41:02 2016
@@ -278,11 +278,11 @@ CommandObjectProxy::CommandObjectProxy(C
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 {
Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=286731&r1=286730&r2=286731&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Sat Nov 12 14:41:02 2016
@@ -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};
-
- for (const auto lang_type : languages) {
- if (auto language = Language::FindPlugin(lang_type)) {
- if (const char *help =
- language->GetLanguageSpecificTypeLookupHelp()) {
- stream.Printf("%s\n", help);
- }
+ llvm::StringRef GetHelpLong() override {
+ if (!m_cmd_help_long.empty())
+ return m_cmd_help_long;
+
+ 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,
Modified: lldb/trunk/source/Interpreter/CommandAlias.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandAlias.cpp?rev=286731&r1=286730&r2=286731&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandAlias.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandAlias.cpp Sat Nov 12 14:41:02 2016
@@ -224,28 +224,28 @@ std::pair<lldb::CommandObjectSP, OptionA
// 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();
}
Modified: lldb/trunk/source/Interpreter/CommandObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandObject.cpp?rev=286731&r1=286730&r2=286731&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandObject.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandObject.cpp Sat Nov 12 14:41:02 2016
@@ -52,48 +52,42 @@ CommandObject::CommandObject(CommandInte
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
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 *ExprPathHelpTextCallb
}
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(Str
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) {
Modified: lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp?rev=286731&r1=286730&r2=286731&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp Sat Nov 12 14:41:02 2016
@@ -71,7 +71,7 @@ bool CommandObjectRegexCommand::DoExecut
}
}
result.SetStatus(eReturnStatusFailed);
- if (GetSyntax() != nullptr)
+ if (!GetSyntax().empty())
result.AppendError(GetSyntax());
else
result.AppendErrorWithFormat("Command contents '%s' failed to match any "
More information about the lldb-commits
mailing list