Skip to content

Commit

Permalink
[cleanup] Remove fixed parameters of Language::GetLocalVariables
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarod42 committed Dec 29, 2024
1 parent 51bfd4d commit 1b7fdf3
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 488 deletions.
2 changes: 1 addition & 1 deletion CodeLite/Cxx/cpp_comment_creator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ wxString CppCommentCreator::FunctionComment()

// parse the function signature
Language* lang = LanguageST::Get();
const std::vector<TagEntryPtr> tags = lang->GetLocalVariables(m_tag->GetSignature(), true);
const std::vector<TagEntryPtr> tags = lang->GetLocalVariables(m_tag->GetSignature());

comment << wxT("$(FunctionPattern)\n");
for(size_t i = 0; i < tags.size(); i++)
Expand Down
71 changes: 2 additions & 69 deletions CodeLite/language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,46 +206,19 @@ bool Language::VariableFromPattern(const wxString& in, const wxString& name, Var

bool Language::FunctionFromPattern(TagEntryPtr tag, clFunction& foo) { return false; }

std::vector<TagEntryPtr> Language::GetLocalVariables(const wxString& in, bool isFuncSignature, const wxString& name,
size_t flags)
std::vector<TagEntryPtr> Language::GetLocalVariables(const wxString& in)
{
wxString pattern(in);
pattern = pattern.Trim().Trim(false);

if(flags & ReplaceTokens) {
// Apply ctags replcements table on the current input string
pattern = ApplyCtagsReplacementTokens(in);
}

CxxVariableScanner scanner(pattern, eCxxStandard::kCxx11, GetTagsManager()->GetCtagsOptions().GetTokensWxMap(),
isFuncSignature);
true);
CxxVariable::Vec_t locals = scanner.GetVariables(false);

std::vector<TagEntryPtr> tags;
for(CxxVariable::Ptr_t local : locals) {
const wxString& tagName = local->GetName();

// if we have name, collect only tags that matches name
if(!name.IsEmpty()) {
// incase CaseSensitive is not required, make both string lower case
wxString tmpName(name);
wxString tmpTagName(tagName);
if(flags & IgnoreCaseSensitive) {
tmpName.MakeLower();
tmpTagName.MakeLower();
}

if((flags & PartialMatch) && !tmpTagName.StartsWith(tmpName))
continue;
// Don't suggest what we have typed so far
if((flags & PartialMatch) && tmpTagName == tmpName)
continue;
;
if((flags & ExactMatch) && tmpTagName != tmpName)
continue;
;
} // else no name is specified, collect all tags

TagEntryPtr tag(new TagEntry());
tag->SetName(tagName);
tag->SetKind(wxT("variable"));
Expand Down Expand Up @@ -379,46 +352,6 @@ Language* LanguageST::Get()
return gs_Language;
}

wxString Language::ApplyCtagsReplacementTokens(const wxString& in)
{
// First, get the replacement map
CLReplacementList replacements;
const wxStringTable_t& replacementMap = GetTagsManager()->GetCtagsOptions().GetTokensWxMap();
wxStringTable_t::const_iterator iter = replacementMap.begin();
for(; iter != replacementMap.end(); ++iter) {

if(iter->second.IsEmpty())
continue;

wxString pattern = iter->first;
wxString replace = iter->second;
pattern.Trim().Trim(false);
replace.Trim().Trim(false);
CLReplacement repl;
repl.construct(pattern.To8BitData().data(), replace.To8BitData().data());
if(repl.is_ok) {
replacements.push_back(repl);
}
}

if(replacements.empty())
return in;

// Now, apply the replacements
wxString outputStr;
wxArrayString lines = ::wxStringTokenize(in, wxT("\r\n"), wxTOKEN_STRTOK);
for(size_t i = 0; i < lines.GetCount(); i++) {
std::string outStr = lines.Item(i).mb_str(wxConvUTF8).data();
CLReplacementList::iterator iter = replacements.begin();
for(; iter != replacements.end(); iter++) {
::CLReplacePatternA(outStr, *iter, outStr);
}

outputStr << wxString(outStr.c_str(), wxConvUTF8) << wxT("\n");
}
return outputStr;
}

int Language::DoReadClassName(CppScanner& scanner, wxString& clsname) const
{
clsname.clear();
Expand Down
9 changes: 2 additions & 7 deletions CodeLite/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "Cxx/cpp_scanner.h"
#include "codelite_exports.h"
#include "database/entry.h"
#include "expression_result.h"
#include "function.h"
#include "macros.h"
#include "variable.h"
Expand Down Expand Up @@ -123,16 +122,12 @@ class WXDLLIMPEXP_CL Language
wxString GetScopeName(const wxString& in);

/**
* Collect local variables from given scope text (in) and an optional symbol name
* Collect local variables from given scope text (in (a function signature))
* @param in scope to search for
* @param name optional name to look for (name can be partial).
* @return since we dont have full information about each token,
* all local variables returned are of type 'variable' with public access
*/
std::vector<TagEntryPtr> GetLocalVariables(const wxString& in, bool isFuncSignature,
const wxString& name = wxEmptyString, size_t flag = PartialMatch);

wxString ApplyCtagsReplacementTokens(const wxString& in);
std::vector<TagEntryPtr> GetLocalVariables(const wxString& in);

bool VariableFromPattern(const wxString& pattern, const wxString& name, Variable& var);
bool FunctionFromPattern(TagEntryPtr tag, clFunction& foo);
Expand Down
Loading

0 comments on commit 1b7fdf3

Please sign in to comment.