2011-10-28 22:39:46 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2012-01-01 00:05:37 +01:00
|
|
|
* Copyright (C) 2007-2012 Daniel Marjamäki and Cppcheck team.
|
2011-10-28 22:39:46 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
#ifndef CHECKINTERNAL_H
|
|
|
|
#define CHECKINTERNAL_H
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "check.h"
|
2012-06-10 14:19:09 +02:00
|
|
|
#include "config.h"
|
2011-10-28 22:39:46 +02:00
|
|
|
|
|
|
|
class Token;
|
|
|
|
|
|
|
|
/// @addtogroup Checks
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief %Check Internal cppcheck API usage */
|
2012-06-10 14:19:09 +02:00
|
|
|
class CPPCHECKLIB CheckInternal : public Check {
|
2011-10-28 22:39:46 +02:00
|
|
|
public:
|
|
|
|
/** This constructor is used when registering the CheckClass */
|
|
|
|
CheckInternal() : Check(myName())
|
|
|
|
{ }
|
|
|
|
|
|
|
|
/** This constructor is used when running checks. */
|
|
|
|
CheckInternal(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
|
|
|
: Check(myName(), tokenizer, settings, errorLogger)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
/** Simplified checks. The token list is simplified. */
|
|
|
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
|
|
|
|
if (!settings->isEnabled("internal"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
CheckInternal checkInternal(tokenizer, settings, errorLogger);
|
|
|
|
|
|
|
|
checkInternal.checkTokenMatchPatterns();
|
|
|
|
checkInternal.checkTokenSimpleMatchPatterns();
|
2011-10-29 12:13:46 +02:00
|
|
|
checkInternal.checkMissingPercentCharacter();
|
2012-07-11 17:45:16 +02:00
|
|
|
checkInternal.checkUnknownPattern();
|
2011-10-28 22:39:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief %Check if a simple pattern is used inside Token::Match or Token::findmatch */
|
|
|
|
void checkTokenMatchPatterns();
|
|
|
|
|
|
|
|
/** @brief %Check if a complex pattern is used inside Token::simpleMatch or Token::findsimplematch */
|
|
|
|
void checkTokenSimpleMatchPatterns();
|
|
|
|
|
2011-10-29 12:13:46 +02:00
|
|
|
/** @brief %Check for missing % end character in Token::Match pattern */
|
|
|
|
void checkMissingPercentCharacter();
|
|
|
|
|
2012-07-21 15:54:04 +02:00
|
|
|
/** @brief %Check for for unknown (invalid) complex patterns like "%typ%" */
|
2012-07-11 17:45:16 +02:00
|
|
|
void checkUnknownPattern();
|
|
|
|
|
2011-10-28 22:39:46 +02:00
|
|
|
private:
|
|
|
|
void simplePatternError(const Token *tok, const std::string &pattern, const std::string &funcname);
|
|
|
|
void complexPatternError(const Token *tok, const std::string &pattern, const std::string &funcname);
|
2011-10-29 12:13:46 +02:00
|
|
|
void missingPercentCharacterError(const Token *tok, const std::string &pattern, const std::string &funcname);
|
2012-07-11 17:45:16 +02:00
|
|
|
void unknownPatternError(const Token* tok, const std::string& pattern);
|
2011-10-28 22:39:46 +02:00
|
|
|
|
2012-02-18 23:43:51 +01:00
|
|
|
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
|
2011-10-28 22:39:46 +02:00
|
|
|
CheckInternal c(0, settings, errorLogger);
|
|
|
|
c.simplePatternError(0, "class {", "Match");
|
|
|
|
c.complexPatternError(0, "%type% ( )", "Match");
|
2011-10-29 12:13:46 +02:00
|
|
|
c.missingPercentCharacterError(0, "%num", "Match");
|
2012-07-11 17:45:16 +02:00
|
|
|
c.unknownPatternError(0, "%typ");
|
2011-10-28 22:39:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string myName() const {
|
|
|
|
return "cppcheck internal API usage";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string classInfo() const {
|
2011-12-10 18:39:25 +01:00
|
|
|
// Don't include these checks on the WIKI where people can read what
|
|
|
|
// checks there are. These checks are not intended for users.
|
|
|
|
return "";
|
2011-10-28 22:39:46 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
/// @}
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
#endif
|