Cppcheck
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
Suppressions 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< Suppressions::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 Suppressions::Type
strong
Enumerator
unique 
file 
block 
blockBegin 
blockEnd 
macro 

Definition at line 45 of file suppressions.h.

Member Function Documentation

◆ addSuppression()

std::string Suppressions::addSuppression ( Suppressions::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 246 of file suppressions.cpp.

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

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

◆ addSuppressionLine()

std::string Suppressions::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 198 of file suppressions.cpp.

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

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

◆ addSuppressions()

std::string Suppressions::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 281 of file suppressions.cpp.

References addSuppression().

Referenced by CppCheck::check().

◆ dump()

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

Create an xml dump of suppressions.

Parameters
outstream to write XML to

Definition at line 444 of file suppressions.cpp.

References mSuppressions, Suppressions::Suppression::NO_LINE, and ErrorLogger::toxml().

Referenced by CppCheck::checkFile().

◆ getSuppressions()

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

Returns list of all suppressions.

Returns
list of suppressions

Definition at line 504 of file suppressions.cpp.

References mSuppressions.

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

◆ getUnmatchedGlobalSuppressions()

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

Returns list of unmatched global (glob pattern) suppressions.

Returns
list of unmatched suppressions

Definition at line 485 of file suppressions.cpp.

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

Referenced by CppCheckExecutor::reportSuppressions().

◆ getUnmatchedLocalSuppressions()

std::list< Suppressions::Suppression > Suppressions::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 463 of file suppressions.cpp.

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

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

◆ isSuppressed() [1/2]

bool Suppressions::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 437 of file suppressions.cpp.

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

◆ isSuppressed() [2/2]

bool Suppressions::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 409 of file suppressions.cpp.

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

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

◆ isSuppressedExplicitly()

bool Suppressions::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 424 of file suppressions.cpp.

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

Referenced by CppCheck::reportErr().

◆ markUnmatchedInlineSuppressionsAsChecked()

void Suppressions::markUnmatchedInlineSuppressionsAsChecked ( const Tokenizer tokenizer)

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

Definition at line 509 of file suppressions.cpp.

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

Referenced by CppCheck::checkFile().

◆ parseFile()

std::string Suppressions::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< Suppressions::Suppression > Suppressions::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 141 of file suppressions.cpp.

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

Referenced by parseInlineSuppressionCommentToken().

◆ parseXmlFile()

std::string Suppressions::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, Suppressions::Suppression::errorId, Suppressions::Suppression::fileName, Suppressions::Suppression::hash, Suppressions::Suppression::lineNumber, and Suppressions::Suppression::symbolName.

Referenced by CmdLineParser::parseFromArgs().

◆ reportUnmatchedSuppressions()

bool Suppressions::reportUnmatchedSuppressions ( const std::list< Suppressions::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 533 of file suppressions.cpp.

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

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

Member Data Documentation

◆ mSuppressions

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

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