Cppcheck
Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
CmdLineParser Class Reference

The command line parser. More...

#include <cmdlineparser.h>

Public Types

enum class  Result { Success , Exit , Fail }
 

Public Member Functions

 CmdLineParser (CmdLineLogger &logger, Settings &settings, Suppressions &suppressions)
 The constructor. More...
 
bool fillSettingsFromArgs (int argc, const char *const argv[])
 Parse command line args and fill settings and file lists from there. More...
 
Result parseFromArgs (int argc, const char *const argv[])
 Parse given command line. More...
 
const std::vector< std::string > & getPathNames () const
 Return the path names user gave to command line. More...
 
const std::list< FileWithDetails > & getFiles () const
 Return the files user gave to command line. More...
 
const std::list< FileSettings > & getFileSettings () const
 Return the file settings read from command line. More...
 
const std::vector< std::string > & getIgnoredPaths () const
 Return a list of paths user wants to ignore. More...
 
std::string getVersion () const
 Get Cppcheck version. More...
 

Protected Member Functions

void printHelp () const
 Print help text to the console. More...
 

Private Member Functions

bool isCppcheckPremium () const
 
template<typename T >
bool parseNumberArg (const char *const arg, std::size_t offset, T &num, bool mustBePositive=false)
 
bool tryLoadLibrary (Library &destination, const std::string &basepath, const char *filename)
 Tries to load a library and prints warning/error messages. More...
 
bool loadLibraries (Settings &settings)
 Load libraries. More...
 
bool loadAddons (Settings &settings)
 Load addons. More...
 
bool loadCppcheckCfg ()
 

Private Attributes

CmdLineLoggermLogger
 
std::vector< std::string > mPathNames
 
std::list< FileWithDetailsmFiles
 
std::list< FileSettingsmFileSettings
 
std::vector< std::string > mIgnoredPaths
 
SettingsmSettings
 
SuppressionsmSuppressions
 
std::string mVSConfig
 

Detailed Description

The command line parser.

The command line parser parses options and parameters user gives to cppcheck command line.

The parser takes a pointer to Settings instance which it will update based on options user has given. Couple of options are handled as class internal options.

Definition at line 48 of file cmdlineparser.h.

Member Enumeration Documentation

◆ Result

enum CmdLineParser::Result
strong
Enumerator
Success 
Exit 
Fail 

Definition at line 59 of file cmdlineparser.h.

Constructor & Destructor Documentation

◆ CmdLineParser()

CmdLineParser::CmdLineParser ( CmdLineLogger logger,
Settings settings,
Suppressions suppressions 
)

The constructor.

Parameters
loggerThe logger instance to log messages through
settingsSettings instance that will be modified according to options user has given.
suppressionsSuppressions instance that keeps the suppressions

Definition at line 138 of file cmdlineparser.cpp.

Member Function Documentation

◆ fillSettingsFromArgs()

bool CmdLineParser::fillSettingsFromArgs ( int  argc,
const char *const  argv[] 
)

◆ getFiles()

const std::list<FileWithDetails>& CmdLineParser::getFiles ( ) const
inline

Return the files user gave to command line.

Definition at line 87 of file cmdlineparser.h.

References mFiles.

Referenced by CppCheckExecutor::check().

◆ getFileSettings()

const std::list<FileSettings>& CmdLineParser::getFileSettings ( ) const
inline

Return the file settings read from command line.

Definition at line 94 of file cmdlineparser.h.

References mFileSettings.

Referenced by CppCheckExecutor::check(), and fillSettingsFromArgs().

◆ getIgnoredPaths()

const std::vector<std::string>& CmdLineParser::getIgnoredPaths ( ) const
inline

Return a list of paths user wants to ignore.

Definition at line 101 of file cmdlineparser.h.

References mIgnoredPaths.

Referenced by fillSettingsFromArgs().

◆ getPathNames()

const std::vector<std::string>& CmdLineParser::getPathNames ( ) const
inline

Return the path names user gave to command line.

Definition at line 80 of file cmdlineparser.h.

References mPathNames.

Referenced by fillSettingsFromArgs().

◆ getVersion()

std::string CmdLineParser::getVersion ( ) const

Get Cppcheck version.

Definition at line 1789 of file cmdlineparser.cpp.

References Settings::cppcheckCfgProductName, CppCheck::extraVersion(), mSettings, and CppCheck::version().

Referenced by parseFromArgs().

◆ isCppcheckPremium()

bool CmdLineParser::isCppcheckPremium ( ) const
private

◆ loadAddons()

bool CmdLineParser::loadAddons ( Settings settings)
private

Load addons.

Parameters
settingsSettings
Returns
Returns true if successful

Definition at line 1878 of file cmdlineparser.cpp.

References Settings::addonInfos, Settings::addons, Settings::exename, AddonInfo::getAddonInfo(), mLogger, and CmdLineLogger::printRaw().

Referenced by fillSettingsFromArgs().

◆ loadCppcheckCfg()

bool CmdLineParser::loadCppcheckCfg ( )
private

◆ loadLibraries()

bool CmdLineParser::loadLibraries ( Settings settings)
private

Load libraries.

Parameters
settingsSettings
Returns
Returns true if successful

Definition at line 1851 of file cmdlineparser.cpp.

References Settings::exename, Path::fromNativeSeparators(), Path::getPathFromFilename(), Settings::libraries, Settings::library, mLogger, CmdLineLogger::printRaw(), and tryLoadLibrary().

Referenced by fillSettingsFromArgs().

◆ parseFromArgs()

CmdLineParser::Result CmdLineParser::parseFromArgs ( int  argc,
const char *const  argv[] 
)

Parse given command line.

Returns
true if command line was ok, false if there was an error.

Definition at line 310 of file cmdlineparser.cpp.

References Settings::addEnabled(), addFilesToList(), addIncludePathsToList(), Settings::addonPython, Settings::addons, addPathsToSet(), SuppressionList::addSuppressionLine(), ImportProject::analyzeAllVsConfigs, Settings::basePaths, Settings::buildDir, Standards::c, Settings::certainty, Settings::checkAllConfigurations, Settings::checkConfiguration, Settings::checkersReportFilename, Settings::checkLibrary, Settings::checks, Settings::checksMaxTime, Settings::clang, Settings::clangExecutable, Settings::configExcludePaths, Standards::cpp, ImportProject::CPPCHECK_GUI, Settings::cppcheckCfgProductName, Settings::daca, Settings::debugnormal, Settings::debugSimplified, Settings::debugtemplate, Settings::debugwarnings, Settings::defaultExecutor(), Platform::defaultSign, Settings::dump, empty_if_null(), SimpleEnableGroup< T >::enable(), endsWith(), Settings::enforcedLang, ImportProject::excludedPaths, Settings::executor, Settings::exename, Settings::exhaustive, Exit, Settings::exitCode, Fail, ImportProject::FAILURE, Settings::fileFilters, ImportProject::fileSettings, Settings::force, Path::fromNativeSeparators(), Standards::getC(), Standards::getCPP(), Path::getCurrentExecutablePath(), CppCheck::getErrorMessages(), getVersion(), ErrorMessage::getXMLFooter(), ErrorMessage::getXMLHeader(), ImportProject::guiProject, ImportProject::ignoreOtherConfigs(), ImportProject::ignorePaths(), ImportProject::import(), Settings::includePaths, inconclusive, Settings::inlineSuppressions, Check::instances(), isCppcheckPremium(), Path::isDirectory(), SimpleEnableGroup< T >::isEnabled(), Settings::jobs, ImportProject::libraries, Settings::libraries, Settings::loadAverage, loadCppcheckCfg(), Settings::maxConfigs, Settings::maxCtuDepth, mFileSettings, mIgnoredPaths, ImportProject::MISSING, mLogger, mPathNames, mSettings, mSuppressions, mVSConfig, Suppressions::nofail, Suppressions::nomsg, none, ImportProject::NONE, Settings::normal, Settings::outputFile, SuppressionList::parseFile(), parseNumberArg(), SuppressionList::parseXmlFile(), ImportProject::pathNames, Settings::performanceValueFlowMaxIfCount, Settings::performanceValueFlowMaxTime, ImportProject::platform, Settings::platform, Settings::plistOutput, Settings::premiumArgs, Settings::preprocessOnly, CmdLineLogger::printError(), printHelp(), CmdLineLogger::printMessage(), CmdLineLogger::printRaw(), ImportProject::projectFile, ImportProject::projectType, Settings::quiet, Settings::relativePaths, Settings::removeEnabled(), Path::removeQuotationMarks(), Settings::reportProgress, Settings::safety, ImportProject::selectOneVsConfig(), Platform::set(), Settings::setCheckLevel(), CppCheckExecutor::setExceptionOutput(), severityFromString(), Settings::showtime, SHOWTIME_FILE, SHOWTIME_FILE_TOTAL, SHOWTIME_NONE, SHOWTIME_SUMMARY, SHOWTIME_TOP5_FILE, SHOWTIME_TOP5_SUMMARY, Path::simplifyPath(), Settings::standards, startsWith(), strToInt(), substituteTemplateFormatStatic(), substituteTemplateLocationStatic(), Success, Settings::templateFormat, Settings::templateLocation, Settings::templateMaxTime, Path::toNativeSeparators(), Platform::type, Settings::typedefMaxTime, ImportProject::UNKNOWN, unusedFunction, Settings::userDefines, Settings::userIncludes, Settings::userUndefs, Settings::useSingleJob(), Settings::valueFlowMaxIterations, Settings::verbose, ImportProject::VS_SLN, ImportProject::VS_VCXPROJ, Settings::xml, and Settings::xml_version.

Referenced by fillSettingsFromArgs().

◆ parseNumberArg()

template<typename T >
bool CmdLineParser::parseNumberArg ( const char *const  arg,
std::size_t  offset,
T &  num,
bool  mustBePositive = false 
)
inlineprivate

Definition at line 121 of file cmdlineparser.h.

References mLogger, CmdLineLogger::printError(), and strToInt().

Referenced by parseFromArgs().

◆ printHelp()

void CmdLineParser::printHelp ( ) const
protected

Print help text to the console.

Definition at line 1433 of file cmdlineparser.cpp.

References isCppcheckPremium(), mLogger, and CmdLineLogger::printRaw().

Referenced by parseFromArgs().

◆ tryLoadLibrary()

bool CmdLineParser::tryLoadLibrary ( Library destination,
const std::string &  basepath,
const char *  filename 
)
private

Member Data Documentation

◆ mFiles

std::list<FileWithDetails> CmdLineParser::mFiles
private

Definition at line 162 of file cmdlineparser.h.

Referenced by fillSettingsFromArgs(), and getFiles().

◆ mFileSettings

std::list<FileSettings> CmdLineParser::mFileSettings
private

Definition at line 163 of file cmdlineparser.h.

Referenced by fillSettingsFromArgs(), getFileSettings(), and parseFromArgs().

◆ mIgnoredPaths

std::vector<std::string> CmdLineParser::mIgnoredPaths
private

Definition at line 164 of file cmdlineparser.h.

Referenced by getIgnoredPaths(), and parseFromArgs().

◆ mLogger

CmdLineLogger& CmdLineParser::mLogger
private

◆ mPathNames

std::vector<std::string> CmdLineParser::mPathNames
private

Definition at line 161 of file cmdlineparser.h.

Referenced by getPathNames(), and parseFromArgs().

◆ mSettings

Settings& CmdLineParser::mSettings
private

◆ mSuppressions

Suppressions& CmdLineParser::mSuppressions
private

Definition at line 166 of file cmdlineparser.h.

Referenced by loadCppcheckCfg(), and parseFromArgs().

◆ mVSConfig

std::string CmdLineParser::mVSConfig
private

Definition at line 167 of file cmdlineparser.h.

Referenced by parseFromArgs().


The documentation for this class was generated from the following files: