Settings: Added an 'append' command line flag that allows the user to provide extra information about functions. See ticket #260

This commit is contained in:
Daniel Marjamäki 2009-09-08 19:49:05 +02:00
parent ed425158d9
commit 80bf406a97
3 changed files with 38 additions and 4 deletions

View File

@ -114,6 +114,10 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
else if (strcmp(argv[i], "--unused-functions") == 0) else if (strcmp(argv[i], "--unused-functions") == 0)
_settings._unusedFunctions = true; _settings._unusedFunctions = true;
// Append userdefined code to checked source code
else if (strncmp(argv[i], "--append=", 9) == 0)
_settings.append(9 + argv[i]);
#ifdef __GNUC__ #ifdef __GNUC__
// show timing information.. // show timing information..
else if (strcmp(argv[i], "--showtime") == 0) else if (strcmp(argv[i], "--showtime") == 0)
@ -294,15 +298,18 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
oss << "Cppcheck - A tool for static C/C++ code analysis\n" oss << "Cppcheck - A tool for static C/C++ code analysis\n"
"\n" "\n"
"Syntax:\n" "Syntax:\n"
" cppcheck [--all] [--auto-dealloc file.lst] [--error-exitcode=[n]] [--force]\n" " cppcheck [--all] [--append=file] [--auto-dealloc file.lst]\n"
" [--help] [-Idir] [-j [jobs]] [--quiet] [--style] [--unused-functions]\n" " [--error-exitcode=[n]] [--force] [--help] [-Idir] [-j [jobs]]\n"
" [--verbose] [--version] [--xml] [file or path1] [file or path] ...\n" " [--quiet] [--style] [--unused-functions] [--verbose] [--version]\n"
" [--xml] [file or path1] [file or path] ...\n"
"\n" "\n"
"If path is given instead of filename, *.cpp, *.cxx, *.cc, *.c++ and *.c files\n" "If path is given instead of filename, *.cpp, *.cxx, *.cc, *.c++ and *.c files\n"
"are checked recursively from given directory.\n\n" "are checked recursively from given directory.\n\n"
"Options:\n" "Options:\n"
" -a, --all Make the checking more sensitive. More bugs are\n" " -a, --all Make the checking more sensitive. More bugs are\n"
" detected, but there are also more false positives\n" " detected, but there are also more false positives\n"
" --append=file This allows you to provide information about\n"
" functions by providing an implementation for these.\n"
" --auto-dealloc file Suppress warnings about classes that have automatic\n" " --auto-dealloc file Suppress warnings about classes that have automatic\n"
" deallocation.\n" " deallocation.\n"
" The classnames must be provided in plain text - one\n" " The classnames must be provided in plain text - one\n"
@ -413,7 +420,7 @@ unsigned int CppCheck::check()
if (_settings._errorsOnly == false && it != configurations.begin()) if (_settings._errorsOnly == false && it != configurations.begin())
_errorLogger->reportOut(std::string("Checking ") + fname + ": " + cfg + std::string("...")); _errorLogger->reportOut(std::string("Checking ") + fname + ": " + cfg + std::string("..."));
checkFile(codeWithoutCfg, _filenames[c].c_str()); checkFile(codeWithoutCfg + _settings.append(), _filenames[c].c_str());
++checkCount; ++checkCount;
} }
} }

View File

@ -19,6 +19,7 @@
#include "settings.h" #include "settings.h"
#include <algorithm> #include <algorithm>
#include <fstream>
Settings::Settings() Settings::Settings()
{ {
@ -35,6 +36,7 @@ Settings::Settings()
#ifdef __GNUC__ #ifdef __GNUC__
_showtime = false; _showtime = false;
#endif #endif
_append = "";
} }
Settings::~Settings() Settings::~Settings()
@ -67,3 +69,19 @@ bool Settings::isAutoDealloc(const char classname[]) const
return (std::find(_autoDealloc.begin(), _autoDealloc.end(), classname) != _autoDealloc.end()); return (std::find(_autoDealloc.begin(), _autoDealloc.end(), classname) != _autoDealloc.end());
} }
void Settings::append(const std::string &filename)
{
_append = "\n";
std::ifstream fin(filename.c_str());
std::string line;
while (std::getline(fin, line))
{
_append += line + "\n";
}
}
std::string Settings::append() const
{
return _append;
}

View File

@ -38,6 +38,9 @@ private:
/** classes that are automaticly deallocated */ /** classes that are automaticly deallocated */
std::list<std::string> _autoDealloc; std::list<std::string> _autoDealloc;
/** Code to append in the checks */
std::string _append;
public: public:
Settings(); Settings();
virtual ~Settings(); virtual ~Settings();
@ -86,6 +89,12 @@ public:
/** is a class automaticly deallocated? */ /** is a class automaticly deallocated? */
bool isAutoDealloc(const char classname[]) const; bool isAutoDealloc(const char classname[]) const;
/** assign append code */
void append(const std::string &filename);
/** get append code */
std::string append() const;
}; };
/// @} /// @}