Merge pull request #128 from acmyo/master

Fix compiler warnings and comment/string typos
This commit is contained in:
Daniel Marjamäki 2013-01-16 08:00:59 -08:00
commit 4cd8c7c608
32 changed files with 102 additions and 100 deletions

View File

@ -210,7 +210,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
} }
// Filter errors // Filter errors
// This is deprecated, see --supressions-list above // This is deprecated, see --suppressions-list above
else if (std::strcmp(argv[i], "--suppressions") == 0) { else if (std::strcmp(argv[i], "--suppressions") == 0) {
++i; ++i;

View File

@ -186,7 +186,7 @@ unsigned int ThreadExecutor::check()
fileChecker.settings() = _settings; fileChecker.settings() = _settings;
unsigned int resultOfCheck = 0; unsigned int resultOfCheck = 0;
if (_fileContents.size() > 0 && _fileContents.find(i->first) != _fileContents.end()) { if (!_fileContents.empty() && _fileContents.find(i->first) != _fileContents.end()) {
// File content was given as a string // File content was given as a string
resultOfCheck = fileChecker.check(i->first, _fileContents[ i->first ]); resultOfCheck = fileChecker.check(i->first, _fileContents[ i->first ]);
} else { } else {

View File

@ -32,7 +32,7 @@ ScratchPad::ScratchPad(MainWindow& mainWindow)
void ScratchPad::CheckButtonClicked() void ScratchPad::CheckButtonClicked()
{ {
QString filename = mUI.lineEdit->text(); QString filename = mUI.lineEdit->text();
if (filename.size() == 0) if (filename.isEmpty())
filename = "test.cpp"; filename = "test.cpp";
mMainWindow.CheckCode(mUI.plainTextEdit->toPlainText(), filename); mMainWindow.CheckCode(mUI.plainTextEdit->toPlainText(), filename);
} }

View File

@ -242,7 +242,7 @@ void SettingsDialog::EditApplication()
void SettingsDialog::DefaultApplication() void SettingsDialog::DefaultApplication()
{ {
QList<QListWidgetItem *> selected = mUI.mListWidget->selectedItems(); QList<QListWidgetItem *> selected = mUI.mListWidget->selectedItems();
if (selected.size() > 0) { if (!selected.isEmpty()) {
int index = mUI.mListWidget->row(selected[0]); int index = mUI.mListWidget->row(selected[0]);
mTempApplications->SetDefault(index); mTempApplications->SetDefault(index);
mUI.mListWidget->clear(); mUI.mListWidget->clear();

View File

@ -532,7 +532,7 @@ void CheckOther::checkIncorrectLogicOperator()
const Token *endTok = tok ? tok->next()->link() : NULL; const Token *endTok = tok ? tok->next()->link() : NULL;
while (tok && endTok) { while (tok && endTok) {
// Find a pair of OR'd terms, with or without parenthesis // Find a pair of OR'd terms, with or without parentheses
// e.g. if (x != 3 || x != 4) // e.g. if (x != 3 || x != 4)
const Token *logicTok = NULL, *term1Tok = NULL, *term2Tok = NULL; const Token *logicTok = NULL, *term1Tok = NULL, *term2Tok = NULL;
const Token *op1Tok = NULL, *op2Tok = NULL, *op3Tok = NULL, *nextTok = NULL; const Token *op1Tok = NULL, *op2Tok = NULL, *op3Tok = NULL, *nextTok = NULL;
@ -2772,7 +2772,7 @@ void CheckOther::checkMathFunctions()
MathLib::toLongNumber(tok->tokAt(2)->str()) <= 0) { MathLib::toLongNumber(tok->tokAt(2)->str()) <= 0) {
mathfunctionCallError(tok); mathfunctionCallError(tok);
} }
// acos( x ), asin( x ) where x is defined for intervall [-1,+1], but not beyound // acos( x ), asin( x ) where x is defined for interval [-1,+1], but not beyond
else if (tok->varId() == 0 && else if (tok->varId() == 0 &&
Token::Match(tok, "acos|asin ( %num% )") && Token::Match(tok, "acos|asin ( %num% )") &&
std::fabs(MathLib::toDoubleNumber(tok->tokAt(2)->str())) > 1.0) { std::fabs(MathLib::toDoubleNumber(tok->tokAt(2)->str())) > 1.0) {
@ -3508,6 +3508,6 @@ void CheckOther::unsignedPositive(const Token *tok, const std::string &varname)
{ {
reportError(tok, Severity::style, "unsignedPositive", reportError(tok, Severity::style, "unsignedPositive",
"Checking if unsigned variable '" + varname + "' is positive is always true.\n" "Checking if unsigned variable '" + varname + "' is positive is always true.\n"
"An unsigned variable will never alwayw be positive so it is either pointless or " "An unsigned variable can't be negative so it is either pointless or "
"an error to check if it is."); "an error to check if it is.");
} }

View File

@ -175,10 +175,7 @@ void ThreadHandler::SaveSettings(QSettings &settings) const
bool ThreadHandler::HasPreviousFiles() const bool ThreadHandler::HasPreviousFiles() const
{ {
if (mLastFiles.size() > 0) return !mLastFiles.isEmpty();
return true;
return false;
} }
int ThreadHandler::GetPreviousFilesCount() const int ThreadHandler::GetPreviousFilesCount() const

View File

@ -91,7 +91,7 @@ void ThreadResult::reportErr(const ErrorLogger::ErrorMessage &msg)
QString ThreadResult::GetNextFile() QString ThreadResult::GetNextFile()
{ {
QMutexLocker locker(&mutex); QMutexLocker locker(&mutex);
if (mFiles.size() == 0) { if (mFiles.isEmpty()) {
return ""; return "";
} }

View File

@ -59,7 +59,7 @@ void TxtReport::WriteError(const ErrorItem &error)
for (int i = 0; i < error.lines.size(); i++) { for (int i = 0; i < error.lines.size(); i++) {
const QString file = QDir::toNativeSeparators(error.files[i]); const QString file = QDir::toNativeSeparators(error.files[i]);
line += QString("[%1:%2]").arg(file).arg(error.lines[i]); line += QString("[%1:%2]").arg(file).arg(error.lines[i]);
if (i < error.lines.size() - 1 && error.lines.size() > 0) { if (i < error.lines.size() - 1 && !error.lines.isEmpty()) {
line += " -> "; line += " -> ";
} }

View File

@ -162,7 +162,7 @@ ErrorItem XmlReportV1::ReadError(QXmlStreamReader *reader)
item.errorId = attribs.value("", IdAttribute).toString(); item.errorId = attribs.value("", IdAttribute).toString();
item.severity = GuiSeverity::fromString(attribs.value("", SeverityAttribute).toString()); item.severity = GuiSeverity::fromString(attribs.value("", SeverityAttribute).toString());
// NOTE: This dublicates the message to Summary-field. But since // NOTE: This duplicates the message to Summary-field. But since
// old XML format doesn't have separate summary and verbose messages // old XML format doesn't have separate summary and verbose messages
// we must add same message to both data so it shows up in GUI. // we must add same message to both data so it shows up in GUI.
// Check if there is full stop and cut the summary to it. // Check if there is full stop and cut the summary to it.

View File

@ -75,7 +75,7 @@ void Check64BitPortability::pointerassignment()
} }
} }
// Check assignements // Check assignments
for (std::size_t i = 0; i < functions; ++i) { for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i]; const Scope * scope = symbolDatabase->functionScopes[i];
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {

View File

@ -825,7 +825,7 @@ void CheckBufferOverrun::checkScopeForBody(const Token *tok, const ArrayInfo &ar
if (Token::Match(tok2->next(), "%var% =") && MathLib::toLongNumber(max_counter_value) < size) if (Token::Match(tok2->next(), "%var% =") && MathLib::toLongNumber(max_counter_value) < size)
condition_out_of_bounds = false; condition_out_of_bounds = false;
// Goto the end parenthesis of the for-statement: "for (x; y; z)" .. // Goto the end parentheses of the for-statement: "for (x; y; z)" ..
tok2 = tok->next()->link(); tok2 = tok->next()->link();
if (!tok2 || !tok2->tokAt(5)) { if (!tok2 || !tok2->tokAt(5)) {
bailout = true; bailout = true;

View File

@ -771,7 +771,7 @@ void CheckClass::privateFunctions()
} }
} }
// Bailout for overriden virtual functions of base classes // Bailout for overridden virtual functions of base classes
if (!scope->derivedFrom.empty()) { if (!scope->derivedFrom.empty()) {
// Check virtual functions // Check virtual functions
for (std::list<const Function*>::iterator it = FuncList.begin(); it != FuncList.end();) { for (std::list<const Function*>::iterator it = FuncList.begin(); it != FuncList.end();) {
@ -1108,7 +1108,7 @@ bool CheckClass::hasAllocation(const Function *func, const Scope* scope)
var = tok->tokAt(3); var = tok->tokAt(3);
else if (Token::Match(tok, "delete %var%")) else if (Token::Match(tok, "delete %var%"))
var = tok->next(); var = tok->next();
// Check for assignement to the deleted pointer (only if its a member of the class) // Check for assignment to the deleted pointer (only if its a member of the class)
if (var && isMemberVar(scope, var)) { if (var && isMemberVar(scope, var)) {
for (const Token *tok1 = var->next(); tok1 && (tok1 != last); tok1 = tok1->next()) { for (const Token *tok1 = var->next(); tok1 && (tok1 != last); tok1 = tok1->next()) {
if (Token::Match(tok1, "%var% =")) { if (Token::Match(tok1, "%var% =")) {

View File

@ -115,7 +115,7 @@ void CheckExceptionSafety::deallocThrow()
// Variable is assigned -> Bail out // Variable is assigned -> Bail out
else if (Token::Match(tok2, "%varid% =", varid)) { else if (Token::Match(tok2, "%varid% =", varid)) {
if (ThrowToken) // For non-inconclusive checking, wait until we find an assignement to it. Otherwise we assume it is safe to leave a dead pointer. if (ThrowToken) // For non-inconclusive checking, wait until we find an assignment to it. Otherwise we assume it is safe to leave a dead pointer.
deallocThrowError(ThrowToken, tok2->str()); deallocThrowError(ThrowToken, tok2->str());
break; break;
} }

View File

@ -92,9 +92,14 @@ static const char * const call_func_white_list[] = {
, "vscanf", "vsnprintf", "vsprintf", "vsscanf", "while", "wordexp","write", "writev" , "vscanf", "vsnprintf", "vsprintf", "vsscanf", "while", "wordexp","write", "writev"
}; };
static int call_func_white_list_compare(const void *a, const void *b) extern "C"
{ {
return std::strcmp((const char *)a, *(const char * const *)b); int call_func_white_list_compare(const void *a, const void *b);
int call_func_white_list_compare(const void *a, const void *b)
{
return std::strcmp((const char *)a, *(const char * const *)b);
}
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -358,7 +358,7 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown, const Sym
// streams dereference nullpointers // streams dereference nullpointers
if (Token::Match(tok->previous(), "<<|>> %var%")) { if (Token::Match(tok->previous(), "<<|>> %var%")) {
const Variable* var = symbolDatabase->getVariableFromVarId(tok->varId()); const Variable* var = symbolDatabase->getVariableFromVarId(tok->varId());
if (var && var->isPointer() && Token::Match(var->typeStartToken(), "char|wchar_t")) { // Only outputing or reading to char* can cause problems if (var && var->isPointer() && Token::Match(var->typeStartToken(), "char|wchar_t")) { // Only outputting or reading to char* can cause problems
const Token* tok2 = tok->previous(); // Find start of statement const Token* tok2 = tok->previous(); // Find start of statement
for (; tok2; tok2 = tok2->previous()) { for (; tok2; tok2 = tok2->previous()) {
if (Token::Match(tok2->previous(), ";|{|}|:")) if (Token::Match(tok2->previous(), ";|{|}|:"))

View File

@ -1266,7 +1266,7 @@ void CheckOther::checkIncorrectLogicOperator()
for (std::size_t ii = 0; ii < functions; ++ii) { for (std::size_t ii = 0; ii < functions; ++ii) {
const Scope * scope = symbolDatabase->functionScopes[ii]; const Scope * scope = symbolDatabase->functionScopes[ii];
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
// Find a pair of comparison expressions with or without parenthesis // Find a pair of comparison expressions with or without parentheses
// with a shared variable and constants and with a logical operator between them. // with a shared variable and constants and with a logical operator between them.
// e.g. if (x != 3 || x != 4) // e.g. if (x != 3 || x != 4)
const Token *term1Tok = NULL, *term2Tok = NULL; const Token *term1Tok = NULL, *term2Tok = NULL;
@ -2231,7 +2231,7 @@ void CheckOther::checkMathFunctions()
} }
} }
// acos( x ), asin( x ) where x is defined for intervall [-1,+1], but not beyound // acos( x ), asin( x ) where x is defined for interval [-1,+1], but not beyond
else if (Token::Match(tok, "acos|asin ( %num% )") && else if (Token::Match(tok, "acos|asin ( %num% )") &&
std::fabs(MathLib::toDoubleNumber(tok->strAt(2))) > 1.0) { std::fabs(MathLib::toDoubleNumber(tok->strAt(2))) > 1.0) {
mathfunctionCallError(tok); mathfunctionCallError(tok);
@ -2985,7 +2985,7 @@ void CheckOther::checkExpressionRange(const std::list<const Function*> &constFun
for (; it != expressions.getMap().end(); ++it) { for (; it != expressions.getMap().end(); ++it) {
// check expression.. // check expression..
bool valid = true; bool valid = true;
unsigned int parenthesis = 0; // () unsigned int parentheses = 0; // ()
unsigned int brackets = 0; // [] unsigned int brackets = 0; // []
// taking address? // taking address?
@ -2995,13 +2995,13 @@ void CheckOther::checkExpressionRange(const std::list<const Function*> &constFun
for (const Token *tok = it->second.start; tok && tok != it->second.end; tok = tok->next()) { for (const Token *tok = it->second.start; tok && tok != it->second.end; tok = tok->next()) {
if (tok->str() == "(") { if (tok->str() == "(") {
++parenthesis; ++parentheses;
} else if (tok->str() == ")") { } else if (tok->str() == ")") {
if (parenthesis == 0) { if (parentheses == 0) {
valid = false; valid = false;
break; break;
} }
--parenthesis; --parentheses;
} else if (tok->str() == "[") { } else if (tok->str() == "[") {
++brackets; ++brackets;
} else if (tok->str() == "]") { } else if (tok->str() == "]") {
@ -3016,7 +3016,7 @@ void CheckOther::checkExpressionRange(const std::list<const Function*> &constFun
} }
} }
if (!valid || parenthesis!=0 || brackets!=0) if (!valid || parentheses!=0 || brackets!=0)
continue; continue;
const ExpressionTokens &expr = it->second; const ExpressionTokens &expr = it->second;
@ -3764,7 +3764,7 @@ void CheckOther::checkVarFuncNullUB()
if (Token::Match(tok,"[(,] NULL [,)]")) { if (Token::Match(tok,"[(,] NULL [,)]")) {
// Locate function name in this function call. // Locate function name in this function call.
const Token *ftok = tok; const Token *ftok = tok;
int argnr = 1; std::size_t argnr = 1;
while (ftok && ftok->str() != "(") { while (ftok && ftok->str() != "(") {
if (ftok->str() == ")") if (ftok->str() == ")")
ftok = ftok->link(); ftok = ftok->link();

View File

@ -1344,10 +1344,10 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
return false; return false;
} }
bool CheckUninitVar::checkIfForWhileHead(const Scope *scope, const Token *startparanthesis, const Variable& var, bool suppressErrors, bool isuninit) bool CheckUninitVar::checkIfForWhileHead(const Scope *scope, const Token *startparentheses, const Variable& var, bool suppressErrors, bool isuninit)
{ {
const Token * const endpar = startparanthesis->link(); const Token * const endpar = startparentheses->link();
for (const Token *tok = startparanthesis->next(); tok && tok != endpar; tok = tok->next()) { for (const Token *tok = startparentheses->next(); tok && tok != endpar; tok = tok->next()) {
if (tok->varId() == var.varId()) { if (tok->varId() == var.varId()) {
if (isVariableUsage(scope, tok, var.isPointer())) { if (isVariableUsage(scope, tok, var.isPointer())) {
if (!suppressErrors) if (!suppressErrors)
@ -1374,7 +1374,7 @@ bool CheckUninitVar::isVariableUsage(const Scope* scope, const Token *vartok, bo
if (Token::Match(vartok->previous(), "[(,] %var% [,)]") || Token::Match(vartok->tokAt(-2), "[(,] & %var% [,)]")) { if (Token::Match(vartok->previous(), "[(,] %var% [,)]") || Token::Match(vartok->tokAt(-2), "[(,] & %var% [,)]")) {
const bool address(vartok->previous()->str() == "&"); const bool address(vartok->previous()->str() == "&");
// locate start parenthesis in function call.. // locate start parentheses in function call..
int argumentNumber = 0; int argumentNumber = 0;
const Token *start = vartok; const Token *start = vartok;
while (start && !Token::Match(start, "[;{}(]")) { while (start && !Token::Match(start, "[;{}(]")) {

View File

@ -65,7 +65,7 @@ public:
void check(); void check();
void checkScope(const Scope* scope); void checkScope(const Scope* scope);
bool checkScopeForVariable(const Scope* scope, const Token *tok, const Variable& var, bool * const possibleInit, bool * const noreturn); bool checkScopeForVariable(const Scope* scope, const Token *tok, const Variable& var, bool * const possibleInit, bool * const noreturn);
bool checkIfForWhileHead(const Scope *scope, const Token *startparanthesis, const Variable& var, bool suppressErrors, bool isuninit); bool checkIfForWhileHead(const Scope *scope, const Token *startparentheses, const Variable& var, bool suppressErrors, bool isuninit);
bool isVariableUsage(const Scope* scope, const Token *vartok, bool ispointer) const; bool isVariableUsage(const Scope* scope, const Token *vartok, bool ispointer) const;

View File

@ -127,7 +127,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer)
else else
continue; continue;
// funcname ( => Assert that the end parenthesis isn't followed by { // funcname ( => Assert that the end parentheses isn't followed by {
if (Token::Match(funcname, "%var% (")) { if (Token::Match(funcname, "%var% (")) {
if (Token::Match(funcname->linkAt(1), ") const|throw|{")) if (Token::Match(funcname->linkAt(1), ") const|throw|{"))
funcname = NULL; funcname = NULL;

View File

@ -363,7 +363,7 @@ std::string MathLib::abs(const std::string &tok)
bool MathLib::isEqual(const std::string &first, const std::string &second) bool MathLib::isEqual(const std::string &first, const std::string &second)
{ {
// this conversion is needed for formating // this conversion is needed for formatting
// e.g. if first=0.1 and second=1.0E-1, the direct comparison of the strings whould fail // e.g. if first=0.1 and second=1.0E-1, the direct comparison of the strings whould fail
return doubleToString(toDoubleNumber(first)) == doubleToString(toDoubleNumber(second)); return doubleToString(toDoubleNumber(first)) == doubleToString(toDoubleNumber(second));
} }

View File

@ -646,7 +646,7 @@ std::string Preprocessor::removeParentheses(const std::string &str)
while ((pos = line.find(") ", pos)) != std::string::npos) while ((pos = line.find(") ", pos)) != std::string::npos)
line.erase(pos + 1, 1); line.erase(pos + 1, 1);
// Remove inner parenthesis "((..))".. // Remove inner parentheses "((..))"..
pos = 0; pos = 0;
while ((pos = line.find("((", pos)) != std::string::npos) { while ((pos = line.find("((", pos)) != std::string::npos) {
++pos; ++pos;
@ -1506,7 +1506,7 @@ void Preprocessor::simplifyCondition(const std::map<std::string, std::string> &c
modified = false; modified = false;
modified |= tokenizer.simplifySizeof(); modified |= tokenizer.simplifySizeof();
modified |= tokenizer.simplifyCalculations(); modified |= tokenizer.simplifyCalculations();
modified |= tokenizer.simplifyRedundantParenthesis(); modified |= tokenizer.simplifyRedundantParentheses();
for (Token *tok = const_cast<Token *>(tokenizer.tokens()); tok; tok = tok->next()) { for (Token *tok = const_cast<Token *>(tokenizer.tokens()); tok; tok = tok->next()) {
if (Token::Match(tok, "! %num%")) { if (Token::Match(tok, "! %num%")) {
tok->deleteThis(); tok->deleteThis();
@ -2231,7 +2231,7 @@ static void skipstring(const std::string &line, std::string::size_type &pos)
* @param pos in: Position to the '('. out: Position to the ')' * @param pos in: Position to the '('. out: Position to the ')'
* @param params out: The extracted parameters * @param params out: The extracted parameters
* @param numberOfNewlines out: number of newlines in the macro call * @param numberOfNewlines out: number of newlines in the macro call
* @param endFound out: was the end parenthesis found? * @param endFound out: was the end parentheses found?
*/ */
static void getparams(const std::string &line, static void getparams(const std::string &line,
std::string::size_type &pos, std::string::size_type &pos,
@ -2257,14 +2257,14 @@ static void getparams(const std::string &line,
// scan for parameters.. // scan for parameters..
for (; pos < line.length(); ++pos) { for (; pos < line.length(); ++pos) {
// increase parenthesis level // increase parentheses level
if (line[pos] == '(') { if (line[pos] == '(') {
++parlevel; ++parlevel;
if (parlevel == 1) if (parlevel == 1)
continue; continue;
} }
// decrease parenthesis level // decrease parentheses level
else if (line[pos] == ')') { else if (line[pos] == ')') {
--parlevel; --parlevel;
if (parlevel <= 0) { if (parlevel <= 0) {
@ -2909,7 +2909,7 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file
// if the macro has parentheses, get parameters // if the macro has parentheses, get parameters
if (macro->variadic() || macro->nopar() || macro->params().size()) { if (macro->variadic() || macro->nopar() || macro->params().size()) {
// is the end parenthesis found? // is the end parentheses found?
bool endFound = false; bool endFound = false;
getparams(line,pos2,params,numberOfNewlines,endFound); getparams(line,pos2,params,numberOfNewlines,endFound);

View File

@ -833,7 +833,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
_variableList[varId] = &(*var); _variableList[varId] = &(*var);
} }
// add all function paramaters // add all function parameters
std::list<Function>::const_iterator func; std::list<Function>::const_iterator func;
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) { for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
// ignore function without implementations // ignore function without implementations

View File

@ -1035,7 +1035,7 @@ bool TemplateSimplifier::simplifyTemplateInstantions(
std::string templateMatchPattern(name + " < "); std::string templateMatchPattern(name + " < ");
unsigned int indentlevel = 0; unsigned int indentlevel = 0;
for (const Token *tok3 = tok2->tokAt(2); tok3 && (indentlevel > 0 || tok3->str() != ">"); tok3 = tok3->next()) { for (const Token *tok3 = tok2->tokAt(2); tok3 && (indentlevel > 0 || tok3->str() != ">"); tok3 = tok3->next()) {
// #2648 - unhandled parenthesis => bail out // #2648 - unhandled parentheses => bail out
// #2721 - unhandled [ => bail out // #2721 - unhandled [ => bail out
if (tok3->str() == "(" || tok3->str() == "[") { if (tok3->str() == "(" || tok3->str() == "[") {
typeForNewNameStr.clear(); typeForNewNameStr.clear();
@ -1090,7 +1090,7 @@ bool TemplateSimplifier::simplifyTemplateInstantions(
for (Token *tok4 = tok2; tok4; tok4 = tok4->next()) { for (Token *tok4 = tok2; tok4; tok4 = tok4->next()) {
if (Token::simpleMatch(tok4, templateMatchPattern.c_str())) { if (Token::simpleMatch(tok4, templateMatchPattern.c_str())) {
Token * tok5 = tok4->tokAt(2); Token * tok5 = tok4->tokAt(2);
unsigned int typeCountInInstantion = 1U; // There is always atleast one type unsigned int typeCountInInstantion = 1U; // There is always at least one type
const Token *typetok = (!typesUsedInTemplateInstantion.empty()) ? typesUsedInTemplateInstantion[0] : 0; const Token *typetok = (!typesUsedInTemplateInstantion.empty()) ? typesUsedInTemplateInstantion[0] : 0;
unsigned int indentlevel5 = 0; // indentlevel for tok5 unsigned int indentlevel5 = 0; // indentlevel for tok5
while (tok5 && (indentlevel5 > 0 || tok5->str() != ">")) { while (tok5 && (indentlevel5 > 0 || tok5->str() != ">")) {

View File

@ -1058,7 +1058,7 @@ void Token::astFunctionCall()
_next->_astParent = this; _next->_astParent = this;
} }
void Token::astHandleParenthesis() void Token::astHandleParentheses()
{ {
Token *innerTop; Token *innerTop;
if (_str != "(") if (_str != "(")

View File

@ -578,7 +578,7 @@ public:
void astOperand1(Token *tok); void astOperand1(Token *tok);
void astOperand2(Token *tok); void astOperand2(Token *tok);
void astFunctionCall(); void astFunctionCall();
void astHandleParenthesis(); void astHandleParentheses();
const Token * astOperand1() const { const Token * astOperand1() const {
return _astOperand1; return _astOperand1;

View File

@ -1209,7 +1209,7 @@ void Tokenizer::simplifyTypedef()
} }
else if (functionPtr || functionRef || function) { else if (functionPtr || functionRef || function) {
// don't add parenthesis around function names because it // don't add parentheses around function names because it
// confuses other simplifications // confuses other simplifications
bool needParen = true; bool needParen = true;
if (!inTemplate && function && tok2->next() && tok2->next()->str() != "*") if (!inTemplate && function && tok2->next() && tok2->next()->str() != "*")
@ -1655,7 +1655,7 @@ bool Tokenizer::tokenize(std::istream &code,
simplifyExternC(); simplifyExternC();
// simplify weird but legal code: "[;{}] ( { code; } ) ;"->"[;{}] code;" // simplify weird but legal code: "[;{}] ( { code; } ) ;"->"[;{}] code;"
simplifyRoundCurlyParenthesis(); simplifyRoundCurlyParentheses();
// check for simple syntax errors.. // check for simple syntax errors..
for (const Token *tok = list.front(); tok; tok = tok->next()) { for (const Token *tok = list.front(); tok; tok = tok->next()) {
@ -1962,7 +1962,7 @@ bool Tokenizer::tokenize(std::istream &code,
simplifyVariableMultipleAssign(); simplifyVariableMultipleAssign();
// Remove redundant parentheses // Remove redundant parentheses
simplifyRedundantParenthesis(); simplifyRedundantParentheses();
for (Token *tok = list.front(); tok; tok = tok->next()) for (Token *tok = list.front(); tok; tok = tok->next())
while (TemplateSimplifier::simplifyNumericCalculations(tok)); while (TemplateSimplifier::simplifyNumericCalculations(tok));
@ -2178,7 +2178,7 @@ void Tokenizer::simplifyExternC()
} }
} }
void Tokenizer::simplifyRoundCurlyParenthesis() void Tokenizer::simplifyRoundCurlyParentheses()
{ {
for (Token *tok = list.front(); tok; tok = tok->next()) { for (Token *tok = list.front(); tok; tok = tok->next()) {
while (Token::Match(tok, "[;{}] ( {") && while (Token::Match(tok, "[;{}] ( {") &&
@ -2866,7 +2866,7 @@ void Tokenizer::setVarId()
// Found a class function.. // Found a class function..
if (Token::Match(tok2, funcpattern.c_str())) { if (Token::Match(tok2, funcpattern.c_str())) {
// Goto the end parenthesis.. // Goto the end parentheses..
tok2 = tok2->linkAt(3); tok2 = tok2->linkAt(3);
if (!tok2) if (!tok2)
break; break;
@ -3135,7 +3135,7 @@ bool Tokenizer::simplifySizeof()
// sizeof int -> sizeof( int ) // sizeof int -> sizeof( int )
else if (tok->next()->str() != "(") { else if (tok->next()->str() != "(") {
// Add parenthesis around the sizeof // Add parentheses around the sizeof
int parlevel = 0; int parlevel = 0;
for (Token *tempToken = tok->next(); tempToken; tempToken = tempToken->next()) { for (Token *tempToken = tok->next(); tempToken; tempToken = tempToken->next()) {
if (tempToken->str() == "(") if (tempToken->str() == "(")
@ -3365,7 +3365,7 @@ bool Tokenizer::simplifyTokenList()
elseif(); elseif();
simplifyErrNoInWhile(); simplifyErrNoInWhile();
simplifyIfAssign(); simplifyIfAssign();
simplifyRedundantParenthesis(); simplifyRedundantParentheses();
simplifyIfNot(); simplifyIfNot();
simplifyIfNotNull(); simplifyIfNotNull();
simplifyIfSameInnerCondition(); simplifyIfSameInnerCondition();
@ -3386,7 +3386,7 @@ bool Tokenizer::simplifyTokenList()
modified |= simplifyFunctionReturn(); modified |= simplifyFunctionReturn();
modified |= simplifyKnownVariables(); modified |= simplifyKnownVariables();
modified |= removeRedundantConditions(); modified |= removeRedundantConditions();
modified |= simplifyRedundantParenthesis(); modified |= simplifyRedundantParentheses();
modified |= simplifyConstTernaryOp(); modified |= simplifyConstTernaryOp();
modified |= simplifyCalculations(); modified |= simplifyCalculations();
} }
@ -3519,7 +3519,7 @@ void Tokenizer::removeMacroInVarDecl()
{ {
for (Token *tok = list.front(); tok; tok = tok->next()) { for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "[;{}] %var% (") && tok->next()->isUpperCaseName()) { if (Token::Match(tok, "[;{}] %var% (") && tok->next()->isUpperCaseName()) {
// goto ')' paranthesis // goto ')' parentheses
const Token *tok2 = tok; const Token *tok2 = tok;
int parlevel = 0; int parlevel = 0;
while (tok2) { while (tok2) {
@ -4133,9 +4133,9 @@ void Tokenizer::simplifyCompoundAssignment()
while (tok->next()->str() != ";") while (tok->next()->str() != ";")
tok->deleteNext(); tok->deleteNext();
} else { } else {
// Enclose the rhs in parenthesis.. // Enclose the rhs in parentheses..
if (!Token::Match(tok->tokAt(2), "[;)]")) { if (!Token::Match(tok->tokAt(2), "[;)]")) {
// Only enclose rhs in parenthesis if there is some operator // Only enclose rhs in parentheses if there is some operator
bool someOperator = false; bool someOperator = false;
for (Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) { for (Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
if (tok2->str() == "(") if (tok2->str() == "(")
@ -4466,7 +4466,7 @@ bool Tokenizer::simplifyConstTernaryOp()
if (offset == 2) { if (offset == 2) {
// go further back before the "(" // go further back before the "("
tok = tok->tokAt(-2); tok = tok->tokAt(-2);
//simplify the parenthesis //simplify the parentheses
tok->deleteNext(); tok->deleteNext();
tok->next()->deleteNext(); tok->next()->deleteNext();
} }
@ -4638,7 +4638,7 @@ bool Tokenizer::simplifyFunctionParameters()
!(tok->strAt(-1) == ":" || tok->strAt(-1) == ",")) { !(tok->strAt(-1) == ":" || tok->strAt(-1) == ",")) {
// We have found old style function, now we need to change it // We have found old style function, now we need to change it
// First step: Get list of argument names in parenthesis // First step: Get list of argument names in parentheses
std::map<std::string, Token *> argumentNames; std::map<std::string, Token *> argumentNames;
bool bailOut = false; bool bailOut = false;
Token * tokparam = NULL; Token * tokparam = NULL;
@ -4696,7 +4696,7 @@ bool Tokenizer::simplifyFunctionParameters()
tok1 = tok->link()->next(); tok1 = tok->link()->next();
// there should be the sequence '; {' after the round parenthesis // there should be the sequence '; {' after the round parentheses
for (const Token* tok2 = tok1; tok2; tok2 = tok2->next()) { for (const Token* tok2 = tok1; tok2; tok2 = tok2->next()) {
if (Token::simpleMatch(tok2, "; {")) if (Token::simpleMatch(tok2, "; {"))
break; break;
@ -4785,7 +4785,7 @@ bool Tokenizer::simplifyFunctionParameters()
//remove ';' after declaration //remove ';' after declaration
declEnd->deleteNext(); declEnd->deleteNext();
//replace the parameter name in the parenthesis with all the declaration //replace the parameter name in the parentheses with all the declaration
Token::replace(tok->next(), declStart, declEnd); Token::replace(tok->next(), declStart, declEnd);
//since there are changes to tokens, put tok where tok1 is //since there are changes to tokens, put tok where tok1 is
@ -5453,7 +5453,7 @@ void Tokenizer::simplifyIfAssign()
if (isNot) if (isNot)
tok->next()->deleteNext(); tok->next()->deleteNext();
// Delete parenthesis.. and remember how many there are with // Delete parentheses.. and remember how many there are with
// their links. // their links.
std::stack<Token *> braces; std::stack<Token *> braces;
while (tok->next()->str() == "(") { while (tok->next()->str() == "(") {
@ -6539,7 +6539,7 @@ void Tokenizer::elseif()
} }
bool Tokenizer::simplifyRedundantParenthesis() bool Tokenizer::simplifyRedundantParentheses()
{ {
bool ret = false; bool ret = false;
for (Token *tok = list.front(); tok; tok = tok->next()) { for (Token *tok = list.front(); tok; tok = tok->next()) {
@ -6559,14 +6559,14 @@ bool Tokenizer::simplifyRedundantParenthesis()
while (Token::simpleMatch(tok, "( (") && while (Token::simpleMatch(tok, "( (") &&
tok->link()->previous() == tok->next()->link()) { tok->link()->previous() == tok->next()->link()) {
// We have "(( *something* ))", remove the inner // We have "(( *something* ))", remove the inner
// parenthesis // parentheses
tok->deleteNext(); tok->deleteNext();
tok->link()->tokAt(-2)->deleteNext(); tok->link()->tokAt(-2)->deleteNext();
ret = true; ret = true;
} }
if (Token::Match(tok->previous(), "! ( %var% )")) { if (Token::Match(tok->previous(), "! ( %var% )")) {
// Remove the parenthesis // Remove the parentheses
tok->deleteThis(); tok->deleteThis();
tok->deleteNext(); tok->deleteNext();
ret = true; ret = true;
@ -6575,7 +6575,7 @@ bool Tokenizer::simplifyRedundantParenthesis()
if (Token::Match(tok->previous(), "[(,;{}] ( %var% (") && if (Token::Match(tok->previous(), "[(,;{}] ( %var% (") &&
tok->link()->previous() == tok->linkAt(2)) { tok->link()->previous() == tok->linkAt(2)) {
// We have "( func ( *something* ))", remove the outer // We have "( func ( *something* ))", remove the outer
// parenthesis // parentheses
tok->link()->deleteThis(); tok->link()->deleteThis();
tok->deleteThis(); tok->deleteThis();
ret = true; ret = true;
@ -6583,7 +6583,7 @@ bool Tokenizer::simplifyRedundantParenthesis()
if (Token::Match(tok->previous(), "[,;{}] ( delete [| ]| %var% ) ;")) { if (Token::Match(tok->previous(), "[,;{}] ( delete [| ]| %var% ) ;")) {
// We have "( delete [| ]| var )", remove the outer // We have "( delete [| ]| var )", remove the outer
// parenthesis // parentheses
tok->link()->deleteThis(); tok->link()->deleteThis();
tok->deleteThis(); tok->deleteThis();
ret = true; ret = true;
@ -6599,7 +6599,7 @@ bool Tokenizer::simplifyRedundantParenthesis()
} }
if (Token::Match(tok->previous(), "[(!*;{}] ( %var% )") && tok->next()->varId() != 0) { if (Token::Match(tok->previous(), "[(!*;{}] ( %var% )") && tok->next()->varId() != 0) {
// We have "( var )", remove the parenthesis // We have "( var )", remove the parentheses
tok->deleteThis(); tok->deleteThis();
tok->deleteNext(); tok->deleteNext();
ret = true; ret = true;
@ -6612,7 +6612,7 @@ bool Tokenizer::simplifyRedundantParenthesis()
} }
if (tok2 != tok->link()) if (tok2 != tok->link())
break; break;
// We have "( var . var . ... . var )", remove the parenthesis // We have "( var . var . ... . var )", remove the parentheses
tok = tok->previous(); tok = tok->previous();
tok->deleteNext(); tok->deleteNext();
tok2->deleteThis(); tok2->deleteThis();
@ -6635,7 +6635,7 @@ bool Tokenizer::simplifyRedundantParenthesis()
while (Token::Match(tok->previous(), "[{([,:] ( !!{") && while (Token::Match(tok->previous(), "[{([,:] ( !!{") &&
Token::Match(tok->link(), ") [;,])]") && Token::Match(tok->link(), ") [;,])]") &&
!Token::findsimplematch(tok, ",", tok->link())) { !Token::findsimplematch(tok, ",", tok->link())) {
// We have "( ... )", remove the parenthesis // We have "( ... )", remove the parentheses
tok->link()->deleteThis(); tok->link()->deleteThis();
tok->deleteThis(); tok->deleteThis();
ret = true; ret = true;
@ -7569,17 +7569,17 @@ bool Tokenizer::isFunctionParameterPassedByValue(const Token *fpar) const
const Token *ftok; const Token *ftok;
// Look at function call, what parameter number is it? // Look at function call, what parameter number is it?
unsigned int parenthesis = 1; unsigned int parentheses = 1;
unsigned int parameter = 1; unsigned int parameter = 1;
for (ftok = fpar; ftok; ftok = ftok->previous()) { for (ftok = fpar; ftok; ftok = ftok->previous()) {
if (ftok->str() == "(") { if (ftok->str() == "(") {
--parenthesis; --parentheses;
if (parenthesis == 0) { if (parentheses == 0) {
break; break;
} }
} else if (ftok->str() == ")") { } else if (ftok->str() == ")") {
++parenthesis; ++parentheses;
} else if (parenthesis == 1 && ftok->str() == ",") { } else if (parentheses == 1 && ftok->str() == ",") {
++parameter; ++parameter;
} else if (Token::Match(ftok, "[;{}]")) { } else if (Token::Match(ftok, "[;{}]")) {
break; break;
@ -7655,7 +7655,7 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
continue; continue;
} else if (tok->next()->str() == ")") { } else if (tok->next()->str() == ")") {
if (!roundbraces) if (!roundbraces)
break; //too many ending round parenthesis break; //too many ending round parentheses
--roundbraces; --roundbraces;
tok->deleteNext(); tok->deleteNext();
continue; continue;

View File

@ -390,7 +390,7 @@ public:
void simplifyStructDecl(); void simplifyStructDecl();
/** /**
* Remove redundant parenthesis: * Remove redundant parentheses:
* - "((x))" => "(x)" * - "((x))" => "(x)"
* - "(function())" => "function()" * - "(function())" => "function()"
* - "(delete x)" => "delete x" * - "(delete x)" => "delete x"
@ -398,7 +398,7 @@ public:
* @return true if modifications to token-list are done. * @return true if modifications to token-list are done.
* false if no modifications are done. * false if no modifications are done.
*/ */
bool simplifyRedundantParenthesis(); bool simplifyRedundantParentheses();
void simplifyCharAt(); void simplifyCharAt();
@ -435,7 +435,7 @@ public:
void simplifyExternC(); void simplifyExternC();
void simplifyRoundCurlyParenthesis(); void simplifyRoundCurlyParentheses();
void simplifyDebugNew(); void simplifyDebugNew();

View File

@ -409,7 +409,7 @@ void TokenList::createAst()
// parentheses.. // parentheses..
for (Token *tok = _front; tok; tok = tok->next()) { for (Token *tok = _front; tok; tok = tok->next()) {
if (tok->str() == "(" || tok->str() == ")" || tok->str() == "]") { if (tok->str() == "(" || tok->str() == ")" || tok->str() == "]") {
tok->astHandleParenthesis(); tok->astHandleParentheses();
} }
} }
} }

View File

@ -266,7 +266,7 @@ private:
TEST_CASE(def_handleIncludes_ifelse1); // problems in handleIncludes for #else TEST_CASE(def_handleIncludes_ifelse1); // problems in handleIncludes for #else
TEST_CASE(def_handleIncludes_ifelse2); TEST_CASE(def_handleIncludes_ifelse2);
TEST_CASE(def_valueWithParenthesis); // #3531 TEST_CASE(def_valueWithParentheses); // #3531
// Using -U to undefine symbols // Using -U to undefine symbols
TEST_CASE(undef1); TEST_CASE(undef1);
@ -3424,8 +3424,8 @@ private:
preprocessor.handleIncludes(code, "test.c", includePaths, defs).find("123")); preprocessor.handleIncludes(code, "test.c", includePaths, defs).find("123"));
} }
void def_valueWithParenthesis() { void def_valueWithParentheses() {
// #define should introduce a new symbol regardless of parenthesis in the value // #define should introduce a new symbol regardless of parentheses in the value
// and regardless of white space in weird places (people do this for some reason). // and regardless of white space in weird places (people do this for some reason).
const char code[] = "#define A (Fred)\n" const char code[] = "#define A (Fred)\n"
" # define B (Flintstone)\n" " # define B (Flintstone)\n"

View File

@ -2485,17 +2485,17 @@ private:
"return(-1);\n" "return(-1);\n"
"fclose(f);\n" "fclose(f);\n"
"}\n"; "}\n";
const char *exptected = "void foo ( ) " const char *expected = "void foo ( ) "
"{ " "{ "
"FILE * f ; " "FILE * f ; "
"f = fopen ( \"foo\" , \"r\" ) ; " "f = fopen ( \"foo\" , \"r\" ) ; "
"if ( ! f ) " "if ( ! f ) "
"{ " "{ "
"return -1 ; " "return -1 ; "
"} " "} "
"fclose ( f ) ; " "fclose ( f ) ; "
"}"; "}";
ASSERT_EQUALS(exptected, tok(code)); ASSERT_EQUALS(expected, tok(code));
} }
void whileAssign1() { void whileAssign1() {

View File

@ -2251,7 +2251,7 @@ private:
} }
void simplifyKnownVariables37() { void simplifyKnownVariables37() {
// Ticket #2398 - no simplication in for loop // Ticket #2398 - no simplification in for loop
const char code[] = "void f() {\n" const char code[] = "void f() {\n"
" double x = 0;\n" " double x = 0;\n"
" for (int iter=0; iter<42; iter++) {\n" " for (int iter=0; iter<42; iter++) {\n"
@ -6364,11 +6364,11 @@ private:
//with '&' operator //with '&' operator
ASSERT_EQUALS("void f(){ ab:;& b=0;}", labels_("void f() { ab: &b=0; }")); ASSERT_EQUALS("void f(){ ab:;& b=0;}", labels_("void f() { ab: &b=0; }"));
ASSERT_EQUALS("void f(){ ab:;&( b. x)=0;}", labels_("void f() { ab: &(b->x)=0; }")); ASSERT_EQUALS("void f(){ ab:;&( b. x)=0;}", labels_("void f() { ab: &(b->x)=0; }"));
//with '(' parenthesis //with '(' parentheses
ASSERT_EQUALS("void f(){ ab:;*(* b). x=0;}", labels_("void f() { ab: *(* b)->x=0; }")); ASSERT_EQUALS("void f(){ ab:;*(* b). x=0;}", labels_("void f() { ab: *(* b)->x=0; }"));
ASSERT_EQUALS("void f(){ ab:;(** b). x=0;}", labels_("void f() { ab: (** b).x=0; }")); ASSERT_EQUALS("void f(){ ab:;(** b). x=0;}", labels_("void f() { ab: (** b).x=0; }"));
ASSERT_EQUALS("void f(){ ab:;&(* b. x)=0;}", labels_("void f() { ab: &(*b.x)=0; }")); ASSERT_EQUALS("void f(){ ab:;&(* b. x)=0;}", labels_("void f() { ab: &(*b.x)=0; }"));
//with '{' parenthesis //with '{' parentheses
ASSERT_EQUALS("void f(){ ab:;{ b=0;}}", labels_("void f() { ab: {b=0;} }")); ASSERT_EQUALS("void f(){ ab:;{ b=0;}}", labels_("void f() { ab: {b=0;} }"));
ASSERT_EQUALS("void f(){ ab:;{* b=0;}}", labels_("void f() { ab: { *b=0;} }")); ASSERT_EQUALS("void f(){ ab:;{* b=0;}}", labels_("void f() { ab: { *b=0;} }"));
ASSERT_EQUALS("void f(){ ab:;{& b=0;}}", labels_("void f() { ab: { &b=0;} }")); ASSERT_EQUALS("void f(){ ab:;{& b=0;}}", labels_("void f() { ab: { &b=0;} }"));

View File

@ -419,7 +419,7 @@ private:
"class derived : public base {\n" "class derived : public base {\n"
"private:\n" "private:\n"
" void foo() {}\n" // Skip for overrides of virtual functions of base " void foo() {}\n" // Skip for overrides of virtual functions of base
" void bar() {}\n" // Don't skip if no function is overriden " void bar() {}\n" // Don't skip if no function is overridden
"};"); "};");
ASSERT_EQUALS("[test.cpp:9]: (style) Unused private function: 'derived::bar'\n", errout.str()); ASSERT_EQUALS("[test.cpp:9]: (style) Unused private function: 'derived::bar'\n", errout.str());