Cppcheck
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
SuppressionList Class Reference

class for handling suppressions More...

#include <suppressions.h>

Classes

struct  ErrorMessage
 
struct  Suppression
 

Public Types

enum class  Type {
  unique , file , block , blockBegin ,
  blockEnd , macro
}
 

Public Member Functions

std::string parseFile (std::istream &istr)
 Don't show errors listed in the file. More...
 
std::string parseXmlFile (const char *filename)
 Don't show errors listed in the file. More...
 
std::string addSuppressionLine (const std::string &line)
 Don't show the given error. More...
 
std::string addSuppression (Suppression suppression)
 Don't show this error. More...
 
std::string addSuppressions (std::list< Suppression > suppressions)
 Combine list of suppressions into the current suppressions. More...
 
bool isSuppressed (const ErrorMessage &errmsg, bool global=true)
 Returns true if this message should not be shown to the user. More...
 
bool isSuppressedExplicitly (const ErrorMessage &errmsg, bool global=true)
 Returns true if this message is "explicitly" suppressed. More...
 
bool isSuppressed (const ::ErrorMessage &errmsg, const std::set< std::string > &macroNames)
 Returns true if this message should not be shown to the user. More...
 
void dump (std::ostream &out) const
 Create an xml dump of suppressions. More...
 
std::list< SuppressiongetUnmatchedLocalSuppressions (const std::string &file, const bool unusedFunctionChecking) const
 Returns list of unmatched local (per-file) suppressions. More...
 
std::list< SuppressiongetUnmatchedGlobalSuppressions (const bool unusedFunctionChecking) const
 Returns list of unmatched global (glob pattern) suppressions. More...
 
const std::list< Suppression > & getSuppressions () const
 Returns list of all suppressions. More...
 
void markUnmatchedInlineSuppressionsAsChecked (const Tokenizer &tokenizer)
 Marks Inline Suppressions as checked if source line is in the token stream. More...
 

Static Public Member Functions

static std::vector< SuppressionparseMultiSuppressComment (const std::string &comment, std::string *errorMessage)
 Parse multi inline suppression in comment. More...
 
static bool reportUnmatchedSuppressions (const std::list< SuppressionList::Suppression > &unmatched, ErrorLogger &errorLogger)
 Report unmatched suppressions. More...
 

Private Attributes

std::list< SuppressionmSuppressions
 List of error which the user doesn't want to see. More...
 

Detailed Description

class for handling suppressions

Definition at line 42 of file suppressions.h.

Member Enumeration Documentation

◆ Type

enum SuppressionList::Type
strong
Enumerator
unique 
file 
block 
blockBegin 
blockEnd 
macro 

Definition at line 45 of file suppressions.h.

Member Function Documentation

◆ addSuppression()

std::string SuppressionList::addSuppression ( SuppressionList::Suppression  suppression)

Don't show this error.

File and/or line are optional. In which case the errorId alone is used for filtering.

Parameters
suppressionsuppression details
Returns
error message. empty upon success

Definition at line 247 of file suppressions.cpp.

References SuppressionList::Suppression::errorId, SuppressionList::Suppression::fileName, SuppressionList::Suppression::hash, isAcceptedErrorIdChar(), SuppressionList::Suppression::isLocal(), SuppressionList::Suppression::isSameParameters(), isValidGlobPattern(), SuppressionList::Suppression::matched, and mSuppressions.

Referenced by addInlineSuppressions(), addSuppressionLine(), addSuppressions(), MainWindow::getCppcheckSettings(), and parseXmlFile().

◆ addSuppressionLine()

std::string SuppressionList::addSuppressionLine ( const std::string &  line)

Don't show the given error.

Parameters
lineDescription of error to suppress (in id:file:line format).
Returns
error message. empty upon success

Definition at line 199 of file suppressions.cpp.

References addSuppression(), SuppressionList::Suppression::errorId, SuppressionList::Suppression::fileName, SuppressionList::Suppression::lineNumber, SuppressionList::Suppression::NO_LINE, and Path::simplifyPath().

Referenced by Settings::loadCppcheckCfg(), parseFile(), and CmdLineParser::parseFromArgs().

◆ addSuppressions()

std::string SuppressionList::addSuppressions ( std::list< Suppression suppressions)

Combine list of suppressions into the current suppressions.

Parameters
suppressionslist of suppression details
Returns
error message. empty upon success

Definition at line 282 of file suppressions.cpp.

References addSuppression().

Referenced by CppCheck::check().

◆ dump()

void SuppressionList::dump ( std::ostream &  out) const

Create an xml dump of suppressions.

Parameters
outstream to write XML to

Definition at line 445 of file suppressions.cpp.

References block, blockBegin, blockEnd, file, macro, mSuppressions, SuppressionList::Suppression::NO_LINE, and ErrorLogger::toxml().

Referenced by CppCheck::checkFile().

◆ getSuppressions()

const std::list< SuppressionList::Suppression > & SuppressionList::getSuppressions ( ) const

Returns list of all suppressions.

Returns
list of suppressions

Definition at line 519 of file suppressions.cpp.

References mSuppressions.

Referenced by CppCheck::check(), and CppCheckExecutor::reportSuppressions().

◆ getUnmatchedGlobalSuppressions()

std::list< SuppressionList::Suppression > SuppressionList::getUnmatchedGlobalSuppressions ( const bool  unusedFunctionChecking) const

Returns list of unmatched global (glob pattern) suppressions.

Returns
list of unmatched suppressions

Definition at line 500 of file suppressions.cpp.

References ID_CHECKERSREPORT, ID_UNUSEDFUNCTION, mSuppressions, and SuppressionList::Suppression::NO_LINE.

Referenced by CppCheckExecutor::reportSuppressions().

◆ getUnmatchedLocalSuppressions()

std::list< SuppressionList::Suppression > SuppressionList::getUnmatchedLocalSuppressions ( const std::string &  file,
const bool  unusedFunctionChecking 
) const

Returns list of unmatched local (per-file) suppressions.

Returns
list of unmatched suppressions

Definition at line 478 of file suppressions.cpp.

References ID_CHECKERSREPORT, ID_UNUSEDFUNCTION, macro, mSuppressions, SuppressionList::Suppression::NO_LINE, and Path::simplifyPath().

Referenced by CppCheck::checkFile(), and CppCheckExecutor::reportSuppressions().

◆ isSuppressed() [1/2]

bool SuppressionList::isSuppressed ( const ::ErrorMessage errmsg,
const std::set< std::string > &  macroNames 
)

Returns true if this message should not be shown to the user.

Parameters
errmsgerror message
Returns
true if this error is suppressed.

Definition at line 438 of file suppressions.cpp.

References SuppressionList::ErrorMessage::fromErrorMessage(), isSuppressed(), and mSuppressions.

◆ isSuppressed() [2/2]

bool SuppressionList::isSuppressed ( const ErrorMessage errmsg,
bool  global = true 
)

Returns true if this message should not be shown to the user.

Parameters
errmsgerror message
globaluse global suppressions
Returns
true if this error is suppressed.

Definition at line 410 of file suppressions.cpp.

References SuppressionList::ErrorMessage::errorId, and mSuppressions.

Referenced by Executor::hasToLog(), SuppressionList::Suppression::isMatch(), isSuppressed(), CppCheck::reportErr(), and ProcessExecutor::reportInternalChildErr().

◆ isSuppressedExplicitly()

bool SuppressionList::isSuppressedExplicitly ( const ErrorMessage errmsg,
bool  global = true 
)

Returns true if this message is "explicitly" suppressed.

The suppression "id" must match textually exactly.

Parameters
errmsgerror message
globaluse global suppressions
Returns
true if this error is explicitly suppressed.

Definition at line 425 of file suppressions.cpp.

References SuppressionList::ErrorMessage::errorId, and mSuppressions.

Referenced by CppCheck::reportErr().

◆ markUnmatchedInlineSuppressionsAsChecked()

void SuppressionList::markUnmatchedInlineSuppressionsAsChecked ( const Tokenizer tokenizer)

Marks Inline Suppressions as checked if source line is in the token stream.

Definition at line 524 of file suppressions.cpp.

References block, TokenList::file(), Tokenizer::list, mSuppressions, Token::next(), Tokenizer::tokens(), and unique.

Referenced by CppCheck::checkFile().

◆ parseFile()

std::string SuppressionList::parseFile ( std::istream &  istr)

Don't show errors listed in the file.

Parameters
istrOpen file stream where errors can be read.
Returns
error message. empty upon success

Definition at line 71 of file suppressions.cpp.

References addSuppressionLine(), and replace().

Referenced by CmdLineParser::parseFromArgs().

◆ parseMultiSuppressComment()

std::vector< SuppressionList::Suppression > SuppressionList::parseMultiSuppressComment ( const std::string &  comment,
std::string *  errorMessage 
)
static

Parse multi inline suppression in comment.

Parameters
commentthe full comment text
errorMessageoutput parameter for error message (wrong suppression attribute)
Returns
empty vector if something wrong.

Definition at line 142 of file suppressions.cpp.

References SuppressionList::Suppression::errorId, startsWith(), and SuppressionList::Suppression::symbolName.

Referenced by parseInlineSuppressionCommentToken().

◆ parseXmlFile()

std::string SuppressionList::parseXmlFile ( const char *  filename)

Don't show errors listed in the file.

Parameters
filenamefile name
Returns
error message. empty upon success

Definition at line 102 of file suppressions.cpp.

References addSuppression(), error, SuppressionList::Suppression::errorId, SuppressionList::Suppression::fileName, SuppressionList::Suppression::hash, SuppressionList::Suppression::lineNumber, and SuppressionList::Suppression::symbolName.

Referenced by CmdLineParser::parseFromArgs().

◆ reportUnmatchedSuppressions()

bool SuppressionList::reportUnmatchedSuppressions ( const std::list< SuppressionList::Suppression > &  unmatched,
ErrorLogger errorLogger 
)
static

Report unmatched suppressions.

Parameters
unmatchedlist of unmatched suppressions (from Settings::Suppressions::getUnmatched(Local|Global)Suppressions)
Returns
true is returned if errors are reported

Definition at line 548 of file suppressions.cpp.

References emptyString, information, SuppressionList::Suppression::NO_LINE, normal, and ErrorLogger::reportErr().

Referenced by CppCheck::checkFile(), and CppCheckExecutor::reportSuppressions().

Member Data Documentation

◆ mSuppressions

std::list<Suppression> SuppressionList::mSuppressions
private

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