Skip to content

Commit

Permalink
[cleanup]: Change ToArrayString to no longer uses output parameter.…
Browse files Browse the repository at this point in the history
… and use it more.
  • Loading branch information
Jarod42 committed Aug 3, 2024
1 parent 1e601a5 commit b7d99a6
Show file tree
Hide file tree
Showing 52 changed files with 568 additions and 798 deletions.
15 changes: 6 additions & 9 deletions CMakePlugin/CMakePlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,16 @@ BuildConfigPtr CMakePlugin::GetSelectedBuildConfig() const

wxArrayString CMakePlugin::GetSupportedGenerators() const
{
wxArrayString generators;

#ifdef __WXMSW__
// Windows supported generators
generators.Add("MinGW Makefiles");
return StdToWX::ToArrayString({ "MinGW Makefiles" });
#else
// Linux / Mac supported generators
generators.Add("Unix Makefiles");
// generators.Add("Ninja");
return StdToWX::ToArrayString({
"Unix Makefiles",
// "Ninja",
});
#endif

return generators;
}

/* ************************************************************************ */
Expand Down Expand Up @@ -619,8 +617,7 @@ bool CMakePlugin::IsCMakeListsExists() const
wxString CMakePlugin::WriteCMakeListsAndOpenIt(const std::vector<wxString>& lines) const
{
wxFileName cmakelists_txt{ ::wxGetCwd(), "CMakeLists.txt" };
wxArrayString wx_lines;
StdToWX::ToArrayString(lines, &wx_lines);
const wxArrayString wx_lines = StdToWX::ToArrayString(lines);
FileUtils::WriteFileContent(cmakelists_txt, wxJoin(wx_lines, '\n'));
clGetManager()->OpenFile(cmakelists_txt.GetFullPath());
return cmakelists_txt.GetFullPath();
Expand Down
12 changes: 3 additions & 9 deletions CodeLite/AsyncProcess/asyncprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class IProcess;

#include "asyncprocess.h"

#include "StdToWX.h"
#include "StringUtils.h"
#include "clTempFile.hpp"
#include "cl_command_event.h"
Expand Down Expand Up @@ -106,24 +107,17 @@ static wxArrayString __WrapInShell(const wxArrayString& args, size_t flags)
}

wxString cmd = wxJoin(tmparr, ' ', 0);
wxArrayString command;

bool is_ssh = flags & IProcessCreateSSH;
if (shell_is_cmd && !is_ssh) {
wxString shell = wxGetenv("COMSPEC");
if (shell.IsEmpty()) {
shell = "CMD.EXE";
}
command.Add(shell);
command.Add("/C");
command.Add("\"" + cmd + "\"");

return StdToWX::ToArrayString({ shell, "/C", "\"" + cmd + "\"" });
} else {
command.Add("/bin/sh");
command.Add("-c");
command.Add("'" + cmd + "'");
return StdToWX::ToArrayString({ "/bin/sh", "-c", "'" + cmd + "'" });
}
return command;
}

static wxArrayString __AddSshCommand(const wxArrayString& args, const wxString& wd, const wxString& sshAccountName,
Expand Down
22 changes: 7 additions & 15 deletions CodeLite/Console/clConsoleBase.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "clConsoleBase.h"

#include "StdToWX.h"
#include "clConsoleAlacritty.hpp"
#include "clConsoleCMD.h"
#include "clConsoleGnomeTerminal.h"
Expand Down Expand Up @@ -95,25 +96,16 @@ clConsoleBase::Ptr_t clConsoleBase::GetTerminal()

wxArrayString clConsoleBase::GetAvailableTerminals()
{
wxArrayString terminals;
return StdToWX::ToArrayString({
#ifdef __WXMSW__
terminals.Add("CMD");
"CMD",
#elif defined(__WXGTK__)
terminals.Add("konsole");
terminals.Add("gnome-terminal");
terminals.Add("lxterminal");
terminals.Add("mate-terminal");
terminals.Add("qterminal");
terminals.Add("xfce4-terminal");
terminals.Add("rxvt-unicode");
terminals.Add("Kitty");
"konsole", "gnome-terminal", "lxterminal", "mate-terminal", "qterminal", "xfce4-terminal", "rxvt-unicode",
"Kitty",
#else
terminals.Add("Terminal");
terminals.Add("iTerm2");
terminals.Add("Kitty");
"Terminal", "iTerm2", "Kitty",
#endif
terminals.Add("alacritty");
return terminals;
"alacritty" });
}

void clConsoleBase::AddEnvVariable(const wxString& name, const wxString& value)
Expand Down
6 changes: 2 additions & 4 deletions CodeLite/Console/clConsoleRXVTerminal.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#include "clConsoleRXVTerminal.h"

#include "Platform/Platform.hpp"
#include "StdToWX.h"

clConsoleRXVTTerminal::clConsoleRXVTTerminal()
{
wxString executable = "rxvt-unicode";
wxArrayString commands;
commands.Add("rxvt-unicode");
commands.Add("urxvt");
commands.Add("rxvt");
const wxArrayString commands = StdToWX::ToArrayString({"rxvt-unicode", "urxvt", "rxvt"});
ThePlatform->AnyWhich(commands, &executable);

SetTerminalCommand(executable + " -cd %WD% -e /bin/bash -c '%COMMAND%'");
Expand Down
12 changes: 3 additions & 9 deletions CodeLite/Cxx/CxxCodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "CxxExpression.hpp"
#include "CxxScannerTokens.h"
#include "CxxVariableScanner.h"
#include "StdToWX.h"
#include "ctags_manager.h"
#include "file_logger.h"
#include "fileextmanager.h"
Expand Down Expand Up @@ -213,15 +214,8 @@ void CxxCodeCompletion::shrink_scope(const wxString& text, std::unordered_map<wx
}

// we also include the anonymous entries for this scope
wxArrayString kinds;
kinds.Add("class");
kinds.Add("struct");
kinds.Add("namespace");
kinds.Add("member");
kinds.Add("function");
kinds.Add("variable");
kinds.Add("enum");
kinds.Add("macro");
const wxArrayString kinds =
StdToWX::ToArrayString({ "class", "struct", "namespace", "member", "function", "variable", "enum", "macro" });
std::vector<TagEntryPtr> anonymous_tags;
get_anonymous_tags(wxEmptyString, kinds, anonymous_tags);

Expand Down
7 changes: 2 additions & 5 deletions CodeLite/StdToWX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ void StdToWX::RemoveLast(std::string& str, size_t count)
}
}

void StdToWX::ToArrayString(const std::vector<wxString>& vec, wxArrayString* arr)
wxArrayString StdToWX::ToArrayString(const std::vector<wxString>& vec)
{
arr->reserve(vec.size());
for(const wxString& s : vec) {
arr->Add(s);
}
return { vec.size(), vec.data() };
}
2 changes: 1 addition & 1 deletion CodeLite/StdToWX.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class WXDLLIMPEXP_CL StdToWX
/**
* @brief convert std::vector into wxArrayString
*/
static void ToArrayString(const std::vector<wxString>& vec, wxArrayString* arr);
static wxArrayString ToArrayString(const std::vector<wxString>& vec);
};

#endif // STDTOWX_H
145 changes: 47 additions & 98 deletions CodeLite/ctags_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "Cxx/CxxTemplateFunction.h"
#include "Cxx/CxxVariableScanner.h"
#include "Cxx/cpp_comment_creator.h"
#include "StdToWX.h"
#include "cl_command_event.h"
#include "code_completion_api.h"
#include "codelite_events.h"
Expand Down Expand Up @@ -423,10 +424,7 @@ bool TagsManager::GetDerivationListInternal(const wxString& path, TagEntryPtr de
{
std::vector<TagEntryPtr> tags;
TagEntryPtr tag;

wxArrayString kind;
kind.Add(wxT("class"));
kind.Add(wxT("struct"));
const wxArrayString kind = StdToWX::ToArrayString({ wxT("class"), wxT("struct") });

GetDatabase()->GetTagsByKindAndPath(kind, path, tags);

Expand Down Expand Up @@ -762,10 +760,7 @@ bool TagsManager::ProcessExpression(const wxString& expression, wxString& type,

void TagsManager::GetClasses(std::vector<TagEntryPtr>& tags, bool onlyWorkspace)
{
wxArrayString kind;
kind.Add(wxT("class"));
kind.Add(wxT("struct"));
kind.Add(wxT("union"));
const wxArrayString kind = StdToWX::ToArrayString({ wxT("class"), wxT("struct"), wxT("union") });

GetDatabase()->GetTagsByKind(kind, wxT("name"), ITagsStorage::OrderAsc, tags);
}
Expand Down Expand Up @@ -844,9 +839,7 @@ void TagsManager::CacheFile(const wxString& fileName)
m_cachedFile = fileName;
m_cachedFileFunctionsTags.clear();

wxArrayString kinds;
kinds.Add(wxT("function"));
kinds.Add(wxT("prototype"));
const wxArrayString kinds = StdToWX::ToArrayString({ wxT("function"), wxT("prototype") });
// disable the cache
GetDatabase()->SetUseCache(false);
GetDatabase()->GetTagsByKindAndFile(kinds, fileName, wxT("line"), ITagsStorage::OrderDesc,
Expand Down Expand Up @@ -1159,93 +1152,49 @@ void TagsManager::GetCXXKeywords(wxStringSet_t& words)

void TagsManager::GetCXXKeywords(wxArrayString& words)
{
words.Clear();
words.Add("alignas");
words.Add("alignof");
words.Add("and");
words.Add("and_eq");
words.Add("asm");
words.Add("auto");
words.Add("bitand");
words.Add("bitor");
words.Add("bool");
words.Add("break");
words.Add("case");
words.Add("catch");
words.Add("char");
words.Add("char16_t");
words.Add("char32_t");
words.Add("class");
words.Add("compl");
words.Add("const");
words.Add("constexpr");
words.Add("const_cast");
words.Add("continue");
words.Add("decltype");
words.Add("default");
words.Add("delete");
words.Add("do");
words.Add("double");
words.Add("dynamic_cast");
words.Add("else");
words.Add("enum");
words.Add("explicit");
words.Add("export");
words.Add("extern");
words.Add("false");
words.Add("final");
words.Add("float");
words.Add("for");
words.Add("friend");
words.Add("goto");
words.Add("if");
words.Add("inline");
words.Add("int");
words.Add("long");
words.Add("mutable");
words.Add("namespace");
words.Add("new");
words.Add("noexcept");
words.Add("not");
words.Add("not_eq");
words.Add("nullptr");
words.Add("operator");
words.Add("or");
words.Add("or_eq");
words.Add("override");
words.Add("private");
words.Add("protected");
words.Add("public");
words.Add("register");
words.Add("reinterpret_cast");
words.Add("return");
words.Add("short");
words.Add("signed");
words.Add("sizeof");
words.Add("static");
words.Add("static_assert");
words.Add("static_cast");
words.Add("struct");
words.Add("switch");
words.Add("template");
words.Add("this");
words.Add("thread_local");
words.Add("throw");
words.Add("true");
words.Add("try");
words.Add("typedef");
words.Add("typeid");
words.Add("typename");
words.Add("union");
words.Add("unsigned");
words.Add("using");
words.Add("virtual");
words.Add("void");
words.Add("volatile");
words.Add("wchar_t");
words.Add("while");
words.Add("xor");
words.Add("xor_eq");
words = StdToWX::ToArrayString({ "alignas", "alignof",
"and", "and_eq",
"asm", "auto",
"bitand", "bitor",
"bool", "break",
"case", "catch",
"char", "char16_t",
"char32_t", "class",
"compl", "const",
"constexpr", "const_cast",
"continue", "decltype",
"default", "delete",
"do", "double",
"dynamic_cast", "else",
"enum", "explicit",
"export", "extern",
"false", "final",
"float", "for",
"friend", "goto",
"if", "inline",
"int", "long",
"mutable", "namespace",
"new", "noexcept",
"not", "not_eq",
"nullptr", "operator",
"or", "or_eq",
"override", "private",
"protected", "public",
"register", "reinterpret_cast",
"return", "short",
"signed", "sizeof",
"static", "static_assert",
"static_cast", "struct",
"switch", "template",
"this", "thread_local",
"throw", "true",
"try", "typedef",
"typeid", "typename",
"union", "unsigned",
"using", "virtual",
"void", "volatile",
"wchar_t", "while",
"xor", "xor_eq" });
}

TagEntryPtrVector_t TagsManager::ParseBuffer(const wxString& content, const wxString& filename, const wxString& kinds)
Expand Down
Loading

0 comments on commit b7d99a6

Please sign in to comment.