2011-10-28 22:39:46 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2014-02-15 07:45:39 +01:00
|
|
|
* Copyright (C) 2007-2014 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
2013-09-04 20:59:49 +02:00
|
|
|
#ifndef checkinternalH
|
|
|
|
#define checkinternalH
|
2011-10-28 22:39:46 +02:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "check.h"
|
2012-06-10 14:19:09 +02:00
|
|
|
#include "config.h"
|
2011-10-28 22:39:46 +02:00
|
|
|
|
|
|
|
/// @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 */
|
2014-11-20 14:20:09 +01:00
|
|
|
CheckInternal() : Check(myName()) {
|
2013-08-07 16:27:37 +02:00
|
|
|
}
|
2011-10-28 22:39:46 +02:00
|
|
|
|
|
|
|
/** This constructor is used when running checks. */
|
|
|
|
CheckInternal(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
2014-11-20 14:20:09 +01:00
|
|
|
: Check(myName(), tokenizer, settings, errorLogger) {
|
2013-08-07 16:27:37 +02:00
|
|
|
}
|
2011-10-28 22:39:46 +02:00
|
|
|
|
|
|
|
/** Simplified checks. The token list is simplified. */
|
2014-11-20 14:20:09 +01:00
|
|
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
|
2011-10-28 22:39:46 +02:00
|
|
|
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();
|
2012-09-07 12:36:40 +02:00
|
|
|
checkInternal.checkRedundantNextPrevious();
|
2014-12-30 14:21:18 +01:00
|
|
|
checkInternal.checkExtraWhitespace();
|
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-09-07 12:36:40 +02:00
|
|
|
/** @brief %Check for unknown (invalid) complex patterns like "%typ%" */
|
2012-07-11 17:45:16 +02:00
|
|
|
void checkUnknownPattern();
|
|
|
|
|
2012-09-07 12:36:40 +02:00
|
|
|
/** @brief %Check for inefficient usage of Token::next(), Token::previous() and Token::tokAt() */
|
|
|
|
void checkRedundantNextPrevious();
|
|
|
|
|
2014-12-30 14:21:18 +01:00
|
|
|
/** @brief %Check if there is whitespace at the beginning or at the end of a pattern */
|
|
|
|
void checkExtraWhitespace();
|
|
|
|
|
2011-10-28 22:39:46 +02:00
|
|
|
private:
|
2014-01-05 21:15:41 +01:00
|
|
|
void multiComparePatternError(const Token *tok, const std::string &pattern, const std::string &funcname);
|
2011-10-28 22:39:46 +02:00
|
|
|
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);
|
2012-09-07 12:36:40 +02:00
|
|
|
void redundantNextPreviousError(const Token* tok, const std::string& func1, const std::string& func2);
|
2014-07-02 15:50:49 +02:00
|
|
|
void orInComplexPattern(const Token *tok, const std::string &pattern, const std::string &funcname);
|
2014-12-30 14:21:18 +01:00
|
|
|
void extraWhitespaceError(const Token *tok, const std::string &pattern, const std::string &funcname);
|
2011-10-28 22:39:46 +02:00
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
|
2011-10-28 22:39:46 +02:00
|
|
|
CheckInternal c(0, settings, errorLogger);
|
2014-01-05 21:15:41 +01:00
|
|
|
c.multiComparePatternError(0, ";|%type%", "Match");
|
2011-10-28 22:39:46 +02:00
|
|
|
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");
|
2012-09-07 12:36:40 +02:00
|
|
|
c.redundantNextPreviousError(0, "previous", "next");
|
2014-07-02 15:50:49 +02:00
|
|
|
c.orInComplexPattern(0, "||", "Match");
|
2014-12-30 14:21:18 +01:00
|
|
|
c.extraWhitespaceError(0, "%str% ", "Match");
|
2011-10-28 22:39:46 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
static std::string myName() {
|
2011-10-28 22:39:46 +02:00
|
|
|
return "cppcheck internal API usage";
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
/// @}
|
|
|
|
//---------------------------------------------------------------------------
|
2013-09-04 20:59:49 +02:00
|
|
|
#endif // checkinternalH
|