Skip to content

Commit

Permalink
Merge pull request #431 from antonvw/312-cppcheck-update-add-dynamic-…
Browse files Browse the repository at this point in the history
…and-memory-analysis

312 cppcheck update add dynamic and memory analysis
  • Loading branch information
antonvw authored Sep 4, 2023
2 parents d876fe4 + 33800c3 commit 96fc3bf
Show file tree
Hide file tree
Showing 17 changed files with 112 additions and 74 deletions.
3 changes: 2 additions & 1 deletion ci/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ if (NOT WIN32)

add_custom_target(cppcheck
COMMAND cppcheck
--std=c++${WEX_CXX_STANDARD}20
--std=c++${WEX_CXX_STANDARD}
--quiet --enable=all
--suppress=missingInclude
--suppress=cppcheckError
--suppress=cstyleCast
--suppress=missingIncludeSystem
--suppress=internalAstError
--suppress=invalidFunctionArg
--suppress=noExplicitConstructor
Expand Down
4 changes: 4 additions & 0 deletions include/wex/core/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace wex
{
class file_translations_loader;

/// Offers the application, with lib specific init and exit,
/// and provides access to the locale and the catalog dir.
/// Your application should be derived from this class.
Expand Down Expand Up @@ -48,6 +50,8 @@ class app : public wxApp

wxLanguage m_language;

file_translations_loader* m_loader{nullptr};

static int m_first_init;
};
}; // namespace wex
5 changes: 5 additions & 0 deletions sample/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ frame::frame()
{"PaneMacro", 50}});
}

frame::~frame()
{
delete m_process;
}

wex::del::listview*
frame::activate(wex::data::listview::type_t type, const wex::lexer* lexer)
{
Expand Down
5 changes: 5 additions & 0 deletions sample/frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@
class frame : public wex::del::frame
{
public:
/// Default constructor.
frame();

/// Destructor.
~frame();

/// Update from app.
void update(app* a);

private:
Expand Down
9 changes: 6 additions & 3 deletions src/core/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ int wex::app::OnExit()
std::cout << e.what() << "\n";
}

delete wxTranslations::Get();
delete m_loader;

return wxApp::OnExit();
}

Expand All @@ -75,13 +78,13 @@ bool wex::app::OnInit()

if (m_language != wxLANGUAGE_UNKNOWN && m_language != wxLANGUAGE_DEFAULT)
{
auto* loader = new file_translations_loader();
m_loader = new file_translations_loader();
wxUILocale::FromTag(wxUILocale::GetLanguageCanonicalName(m_language));
wxTranslations::Set(new wxTranslations());
wxTranslations::Get()->SetLanguage(m_language);
wxTranslations::Get()->SetLoader(loader);
wxTranslations::Get()->SetLoader(m_loader);

loader->add_catalogs(m_language);
m_loader->add_catalogs(m_language);
}

// Necessary for auto_complete images.
Expand Down
2 changes: 1 addition & 1 deletion src/ex/vi/commands-motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ void wex::vi::visual_extend(int begin_pos, int end_pos) const
default:
get_stc()->SetCurrentPos(end_pos);
get_stc()
->SelectNone(); // appearently previous call selects to the new pos ..
->SelectNone(); // apparently previous call selects to the new pos ..
break;
}
}
6 changes: 3 additions & 3 deletions src/factory/process-imp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool wex::factory::process_imp::stop(wxEvtHandler* e)
return false;
}

void wex::factory::process_imp::thread_error(process* p)
void wex::factory::process_imp::thread_error(const process* p)
{
std::thread v(
[debug = m_debug.load(),
Expand Down Expand Up @@ -144,7 +144,7 @@ void wex::factory::process_imp::thread_error(process* p)
v.detach();
}

void wex::factory::process_imp::thread_input(process* p)
void wex::factory::process_imp::thread_input(const process* p)
{
std::thread t(
[debug = m_debug.load(),
Expand Down Expand Up @@ -196,7 +196,7 @@ void wex::factory::process_imp::thread_input(process* p)
t.detach();
}

void wex::factory::process_imp::thread_output(process* p)
void wex::factory::process_imp::thread_output(const process* p)
{
std::thread u(
[debug = m_debug.load(),
Expand Down
6 changes: 3 additions & 3 deletions src/factory/process-imp.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class process_imp

private:
void boost_async_system(process* p, const process_data& data);
void thread_error(process* p);
void thread_input(process* p);
void thread_output(process* p);
void thread_error(const process* p);
void thread_input(const process* p);
void thread_output(const process* p);

std::shared_ptr<boost::asio::io_context> m_io;
std::shared_ptr<std::queue<std::string>> m_queue;
Expand Down
4 changes: 2 additions & 2 deletions src/stc/scope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Name: scope.cpp
// Purpose: Implementation of class wex::scope
// Author: Anton van Wezenbeek
// Copyright: (c) 2020-2021 Anton van Wezenbeek
// Copyright: (c) 2020-2023 Anton van Wezenbeek
////////////////////////////////////////////////////////////////////////////////

#include <wex/core/log.h>
Expand All @@ -17,7 +17,7 @@ wex::scope::scope(stc* s)
{
}

void wex::scope::check_levels(check_t type)
void wex::scope::check_levels(const check_t& type)
{
bool changed = false;
const auto level(m_stc->get_fold_level());
Expand Down
4 changes: 2 additions & 2 deletions src/stc/scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Name: scope.h
// Purpose: Implementation of class wex::scope
// Author: Anton van Wezenbeek
// Copyright: (c) 2020-2022 Anton van Wezenbeek
// Copyright: (c) 2020-2023 Anton van Wezenbeek
////////////////////////////////////////////////////////////////////////////////

#pragma once
Expand Down Expand Up @@ -62,7 +62,7 @@ class scope

typedef std::bitset<2> check_t;

void check_levels(check_t type = check_t().set());
void check_levels(const check_t& type = check_t().set());

/// Finds text in scope (from current down), returns iterator.
map_t::const_iterator iterator(const std::string& text) const;
Expand Down
14 changes: 7 additions & 7 deletions src/syntax/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,15 @@ bool wex::lexer::apply() const

int wex::lexer::attrib(const std::string& name) const
{
for (const auto& a : m_attribs)
{
if (std::get<0>(a) == name)
const auto& a = std::find_if(
m_attribs.begin(),
m_attribs.end(),
[&](auto const& i)
{
return std::get<1>(a);
}
}
return std::get<0>(i) == name;
});

return -1;
return a != m_attribs.end() ? std::get<1>(*a) : -1;
}

void wex::lexer::auto_match(const std::string& lexer)
Expand Down
54 changes: 31 additions & 23 deletions src/syntax/wex/lex-lilypond-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#pragma once

#include <algorithm>

namespace Scintilla
{
/// Offers some general methods.
Expand All @@ -22,6 +24,15 @@ class lilypond
/// Constructor.
lilypond(LexAccessor& s)
: m_styler(s)
, m_words{
"align",
"alignat",
"flalign",
"gather",
"multiline",
"displaymath",
"eqnarray",
"equation"}
{
;
}
Expand All @@ -41,7 +52,8 @@ class lilypond
bool next_not_blank_is(Sci_Position i, char needle) const;

private:
LexAccessor& m_styler;
LexAccessor& m_styler;
const std::vector<std::string> m_words;
};

// inline implementation lex_rfw_access
Expand Down Expand Up @@ -134,15 +146,19 @@ inline bool lilypond::last_word_check(
}
else
{
for (const auto& w : checks)
{
if (last_word_is(match, std::string("{" + w + "}").c_str()))
return std::any_of(
checks.begin(),
checks.end(),
[this, &match, &state, &start](const auto& w)
{
m_styler.ColourTo(start - 1, state);
state = SCE_L_COMMAND;
return true;
}
}
if (last_word_is(match, std::string("{" + w + "}").c_str()))
{
m_styler.ColourTo(start - 1, state);
state = SCE_L_COMMAND;
return true;
}
return false;
});
}
}
}
Expand Down Expand Up @@ -198,21 +214,13 @@ inline bool lilypond::last_word_is_match_env(Sci_Position pos) const
if (s[j - 1] == '*')
s[--j] = '\0';

for (const auto& word : std::vector<std::string>{
"align",
"alignat",
"flalign",
"gather",
"multiline",
"displaymath",
"eqnarray",
"equation"})
{
if (word == s)
return std::any_of(
m_words.begin(),
m_words.end(),
[&s](const auto& w)
{
return true;
}
}
return w == s;
});

return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/syntax/wex/lex-lilypond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ void SCI_METHOD lex_lilypond::Fold(

do
{
char ch, buf[16];
char buf[16];
Sci_Position i, j;
int lev = -1;
bool needFold = false;
for (i = static_cast<Sci_Position>(startPos);
i < static_cast<Sci_Position>(endPos);
++i)
{
ch = styler.SafeGetCharAt(i);
const char ch = styler.SafeGetCharAt(i);
if (ch == '\r' || ch == '\n')
break;
if (ch == '{')
Expand Down
1 change: 0 additions & 1 deletion src/syntax/wex/lex-rfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
////////////////////////////////////////////////////////////////////////////////

#include <algorithm>
#include <iostream>

#include "lex-rfw.h"

Expand Down
2 changes: 2 additions & 0 deletions src/ui/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ wex::frame::~frame()
{
delete m_ofs;
}

delete m_ex_commandline;
}

bool wex::frame::add_toolbar_panes(const panes_t& panes)
Expand Down
5 changes: 2 additions & 3 deletions src/ui/statusbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,9 @@ void wex::statusbar::pane_dialog()
std::tuple<bool, int, int>
wex::statusbar::pane_info(const std::string& pane) const
{
const std::string use_pane = pane.empty() ? "PaneText" : pane;
int shown_pane_no = 0;
const std::string use_pane = pane.empty() ? "PaneText" : pane;

for (int pane_no = 0; const auto& it : m_panes)
for (int pane_no = 0, shown_pane_no = 0; const auto& it : m_panes)
{
if (it.is_shown())
{
Expand Down
Loading

0 comments on commit 96fc3bf

Please sign in to comment.