Skip to content

Commit

Permalink
Cppcheck: It's now possible to supply paths to #includes for use with…
Browse files Browse the repository at this point in the history
… the 'Missing includes' check

There is also a new 'Check configuration' tickbox. If checked, the next run passes the --check-config option, which checks the configuration and tells you _which_ #includes it's complaining about. NB using this disables the standard checks, so it's not serialised. To cancel it, run the Settings dialog again.
  • Loading branch information
dghart committed Jun 8, 2014
1 parent a7e649d commit d209950
Show file tree
Hide file tree
Showing 7 changed files with 1,014 additions and 74 deletions.
25 changes: 25 additions & 0 deletions cppchecker/cppcheck_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ void CppCheckSettings::Serialize(Archive& arch)
// Saving nothing would lose the original values; so save the cached originals
arch.Write(wxT("SuppressedWarningsStrings0"), m_SuppressedWarningsOrig0);
arch.Write(wxT("SuppressedWarningsStrings1"), m_SuppressedWarningsOrig1);
}

if (m_saveIncludeDirs) {
arch.Write(wxT("ExtraIncludeDirs"), m_IncludeDirs);
arch.Write(wxT("SuppressSystemIncludes"), m_SuppressSystemIncludes);
}
}

Expand All @@ -77,6 +82,11 @@ void CppCheckSettings::DeSerialize(Archive& arch)

arch.Read(wxT("SuppressedWarningsStrings0"), m_SuppressedWarnings0); // Unchecked ones
arch.Read(wxT("SuppressedWarningsStrings1"), m_SuppressedWarnings1); // Checked ones


arch.Read(wxT("ExtraIncludeDirs"), m_IncludeDirs);
arch.Read(wxT("SuppressSystemIncludes"), m_SuppressSystemIncludes);
m_saveIncludeDirs = m_IncludeDirs.GetCount() > 0; // If there are saved dirs, this must have been set last time
}

void CppCheckSettings::SetDefaultSuppressedWarnings()
Expand Down Expand Up @@ -154,13 +164,28 @@ wxString CppCheckSettings::GetOptions() const
if (GetForce()) {
options << wxT("--force ");
}
if (GetCheckConfig()) {
options << wxT("--check-config "); // Though this turns off other checks, afaict it does not harm to emit them
}

// Now add any ticked suppressedwarnings
std::map<wxString, wxString>::const_iterator iter = m_SuppressedWarnings1.begin();
for (; iter != m_SuppressedWarnings1.end(); ++iter) {
options << wxT(" --suppress=") << (*iter).first;
}

// IncludeDirs
for (size_t n=0; n < m_IncludeDirs.GetCount(); ++n) {
wxString item = m_IncludeDirs.Item(n);
item.Trim().Trim(false);
if (!item.empty()) {
options << " -I" << item;
}
}
if (m_SuppressSystemIncludes) {
options << wxT(" --suppress=") << "missingIncludeSystem";
}

// (Un)Definitions
for (size_t n=0; n < m_definitions.GetCount(); ++n) {
wxString item = m_definitions.Item(n);
Expand Down
22 changes: 22 additions & 0 deletions cppchecker/cppcheck_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ class CppCheckSettings : public SerializedObject
bool m_C99Standards;
bool m_Cpp11Standards;
bool m_Force;
bool m_CheckConfig;
wxArrayString m_excludeFiles;
StrStrMap m_SuppressedWarnings0; // The items unchecked in the checklistbox
StrStrMap m_SuppressedWarnings1; // The checked ones
StrStrMap m_SuppressedWarningsOrig0; // Ditto, containing the original values
StrStrMap m_SuppressedWarningsOrig1;
bool m_saveSuppressedWarnings;
wxArrayString m_IncludeDirs;
bool m_SuppressSystemIncludes;
bool m_saveIncludeDirs;
wxArrayString m_definitions;
wxArrayString m_undefines;

Expand Down Expand Up @@ -69,6 +73,9 @@ class CppCheckSettings : public SerializedObject
bool GetForce() const {
return m_Force;
}
bool GetCheckConfig() const {
return m_CheckConfig;
}
const wxArrayString& GetExcludeFiles() const {
return m_excludeFiles;
}
Expand All @@ -78,6 +85,15 @@ class CppCheckSettings : public SerializedObject
const StrStrMap* GetSuppressedWarningsStrings1() const {
return &m_SuppressedWarnings1;
}
const wxArrayString& GetIncludeDirs() const {
return m_IncludeDirs;
}
bool GetSuppressSystemIncludes() const {
return m_SuppressSystemIncludes;
}
bool GetSaveIncludeDirs() const {
return m_saveIncludeDirs;
}
const wxArrayString& GetDefinitions() const {
return m_definitions;
}
Expand All @@ -95,6 +111,7 @@ class CppCheckSettings : public SerializedObject
void SetC99Standards(bool C99Standards) { m_C99Standards = C99Standards; }
void SetCpp11Standards(bool Cpp11Standards) { m_Cpp11Standards = Cpp11Standards; }
void SetForce(bool Force) { m_Force = Force; }
void SetCheckConfig(bool checkconfig) { m_CheckConfig = checkconfig; }
void SetExcludeFiles(const wxArrayString& excludeFiles) {
m_excludeFiles = excludeFiles;
}
Expand All @@ -103,6 +120,11 @@ class CppCheckSettings : public SerializedObject
void SetSuppressedWarnings(wxCheckListBox* clb, const wxArrayString& keys);
void SetSaveSuppressedWarnings(bool save) { m_saveSuppressedWarnings = save; }
void SetDefaultSuppressedWarnings();

void SetIncludeDirs(const wxArrayString& dirs) { m_IncludeDirs = dirs; }
void SetSuppressSystemIncludes(bool suppress) { m_SuppressSystemIncludes = suppress; }
void SetSaveIncludeDirs(bool save) { m_saveIncludeDirs = save; }

void SetDefinitions(const wxArrayString& definitions) {
m_definitions = definitions;
}
Expand Down
48 changes: 46 additions & 2 deletions cppchecker/cppchecksettingsdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <wx/msgdlg.h>
#include <wx/filedlg.h>
#include <wx/textdlg.h>
#include <wx/dirdlg.h>

CppCheckSettingsDialog::CppCheckSettingsDialog(wxWindow* parent, CppCheckSettings* settings, IConfigTool *conf, const wxString& defaultpath, bool showDefsTab)
: CppCheckSettingsDialogBase(parent)
Expand Down Expand Up @@ -41,7 +42,11 @@ CppCheckSettingsDialog::CppCheckSettingsDialog(wxWindow* parent, CppCheckSetting
m_checkListSuppress->Check(index, false);
m_SuppressionsKeys.Add((*iter).first);
}


m_listBoxIncludeDirs->Append(settings->GetIncludeDirs());
m_checkBoxSuppressSystemIncludes->SetValue(settings->GetSuppressSystemIncludes());
m_checkBoxSerialiseIncludeDirs->SetValue(settings->GetSaveIncludeDirs());

if (showDefsTab) {
m_listBoxDefinelist->Append(settings->GetDefinitions());
m_listBoxUndefineList->Append(settings->GetUndefines());
Expand All @@ -64,12 +69,17 @@ void CppCheckSettingsDialog::OnBtnOK(wxCommandEvent& e)
m_settings->SetC99Standards(m_checkListExtraWarnings->IsChecked(7));
m_settings->SetCpp11Standards(m_checkListExtraWarnings->IsChecked(8));
m_settings->SetForce(m_cbOptionForce->IsChecked());
m_settings->SetCheckConfig(m_cbCheckConfig->IsChecked());

m_settings->SetExcludeFiles(m_listBoxExcludelist->GetStrings());

m_settings->SetSuppressedWarnings(m_checkListSuppress, m_SuppressionsKeys);
m_settings->SetSaveSuppressedWarnings(m_checkBoxSerialise->IsChecked());

m_settings->SetIncludeDirs(m_listBoxIncludeDirs->GetStrings());
m_settings->SetSuppressSystemIncludes(m_checkBoxSuppressSystemIncludes->IsChecked());
m_settings->SetSaveIncludeDirs(m_checkBoxSerialiseIncludeDirs->IsChecked());

m_settings->SetDefinitions(m_listBoxDefinelist->GetStrings());
m_settings->SetUndefines(m_listBoxUndefineList->GetStrings());

Expand Down Expand Up @@ -185,6 +195,24 @@ void CppCheckSettingsDialog::OnSuppressUntickAll(wxCommandEvent& WXUNUSED(e))
m_checkListSuppress->Check(n, false);
}
}


void CppCheckSettingsDialog::OnAddIncludeDir(wxCommandEvent& WXUNUSED(e))
{
wxDirDialog dlg(this, _("Select the path containing include files"));
if (dlg.ShowModal() == wxID_OK) {
m_listBoxIncludeDirs->Append(dlg.GetPath());
}
}

void CppCheckSettingsDialog::OnRemoveIncludeDir(wxCommandEvent& WXUNUSED(e))
{
int sel = m_listBoxIncludeDirs->GetSelection();
if ( sel != wxNOT_FOUND ) {
m_listBoxIncludeDirs->Delete((unsigned int)sel);
}
}


void CppCheckSettingsDialog::OnAddDefinition(wxCommandEvent& WXUNUSED(e))
{
Expand All @@ -198,7 +226,7 @@ void CppCheckSettingsDialog::OnRemoveDefinition(wxCommandEvent& WXUNUSED(e))
{
int sel = m_listBoxDefinelist->GetSelection();
if ( sel != wxNOT_FOUND ) {
m_listBoxDefinelist->Delete((unsigned int) sel);
m_listBoxDefinelist->Delete((unsigned int)sel);
}
}

Expand Down Expand Up @@ -289,6 +317,22 @@ void CppCheckSettingsDialog::OnSuppressUntickAllUI(wxUpdateUIEvent& e)
e.Enable(false);
}

void CppCheckSettingsDialog::OnIncludeDirsUpdateUI(wxUpdateUIEvent& event)
{
bool enable(false);
int index = m_checkListExtraWarnings->FindString(_("Missing includes"));
if (index != wxNOT_FOUND) {
enable = m_checkListExtraWarnings->IsChecked(index);
}
// Only enable the IncludeDirs panel if the "Missing includes" warning is enabled
event.Enable(enable);
}

void CppCheckSettingsDialog::OnRemoveIncludeDirUI(wxUpdateUIEvent& event)
{
event.Enable( m_listBoxIncludeDirs->GetSelection() != wxNOT_FOUND );
}

void CppCheckSettingsDialog::OnRemoveDefinitionUI(wxUpdateUIEvent& e)
{
e.Enable( m_listBoxDefinelist->GetSelection() != wxNOT_FOUND );
Expand Down
6 changes: 6 additions & 0 deletions cppchecker/cppchecksettingsdlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class CppCheckSettingsDialog : public CppCheckSettingsDialogBase
virtual void OnSuppressTickAllUI(wxUpdateUIEvent& e);
virtual void OnSuppressUntickAllUI(wxUpdateUIEvent& e);

// Extra include dirs page
virtual void OnIncludeDirsUpdateUI(wxUpdateUIEvent& event);
virtual void OnAddIncludeDir(wxCommandEvent& event);
virtual void OnRemoveIncludeDir(wxCommandEvent& event);
virtual void OnRemoveIncludeDirUI(wxUpdateUIEvent& event);

// Definitions page
virtual void OnAddDefinition(wxCommandEvent& e);
virtual void OnRemoveDefinition(wxCommandEvent& e);
Expand Down
Loading

0 comments on commit d209950

Please sign in to comment.