Disabled several checks and simplifications for C code, if they are C++-only. Do not match arguments for C code, since there can't be overloads.

This commit is contained in:
PKEuS 2014-09-01 17:01:05 +02:00
parent 9bc0e3afd6
commit 80df3dc642
5 changed files with 50 additions and 40 deletions

View File

@ -371,6 +371,9 @@ static bool astHasAutoResult(const Token *tok)
void CheckAutoVariables::returnReference() void CheckAutoVariables::returnReference()
{ {
if (_tokenizer->isC())
return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size(); const std::size_t functions = symbolDatabase->functionScopes.size();

View File

@ -38,6 +38,9 @@ namespace {
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckIO::checkCoutCerrMisusage() void CheckIO::checkCoutCerrMisusage()
{ {
if (_tokenizer->isC())
return;
const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase();
std::size_t functions = symbolDatabase->functionScopes.size(); std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functions; ++i) { for (std::size_t i = 0; i < functions; ++i) {

View File

@ -777,31 +777,33 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
} }
} }
// fill in base class info if (!_tokenizer->isC()) {
for (std::list<Type>::iterator it = typeList.begin(); it != typeList.end(); ++it) { // fill in base class info
// finish filling in base class info for (std::list<Type>::iterator it = typeList.begin(); it != typeList.end(); ++it) {
for (unsigned int i = 0; i < it->derivedFrom.size(); ++i) // finish filling in base class info
it->derivedFrom[i].type = findType(it->derivedFrom[i].nameTok, it->enclosingScope); for (unsigned int i = 0; i < it->derivedFrom.size(); ++i)
} it->derivedFrom[i].type = findType(it->derivedFrom[i].nameTok, it->enclosingScope);
// fill in friend info
for (std::list<Type>::iterator it = typeList.begin(); it != typeList.end(); ++it) {
for (std::list<Type::FriendInfo>::iterator i = it->friendList.begin(); i != it->friendList.end(); ++i) {
i->type = findType(i->nameStart, it->enclosingScope);
} }
}
// fill in using info // fill in friend info
for (std::list<Scope>::iterator it = scopeList.begin(); it != scopeList.end(); ++it) { for (std::list<Type>::iterator it = typeList.begin(); it != typeList.end(); ++it) {
for (std::list<Scope::UsingInfo>::iterator i = it->usingList.begin(); i != it->usingList.end(); ++i) { for (std::list<Type::FriendInfo>::iterator i = it->friendList.begin(); i != it->friendList.end(); ++i) {
// only find if not already found i->type = findType(i->nameStart, it->enclosingScope);
if (i->scope == nullptr) { }
// check scope for match }
scope = findScope(i->start->tokAt(2), &(*it));
if (scope) { // fill in using info
// set found scope for (std::list<Scope>::iterator it = scopeList.begin(); it != scopeList.end(); ++it) {
i->scope = scope; for (std::list<Scope::UsingInfo>::iterator i = it->usingList.begin(); i != it->usingList.end(); ++i) {
break; // only find if not already found
if (i->scope == nullptr) {
// check scope for match
scope = findScope(i->start->tokAt(2), &(*it));
if (scope) {
// set found scope
i->scope = scope;
break;
}
} }
} }
} }
@ -1210,14 +1212,14 @@ void Variable::evaluate()
bool Function::argsMatch(const Scope *scope, const Token *first, const Token *second, const std::string &path, unsigned int depth) bool Function::argsMatch(const Scope *scope, const Token *first, const Token *second, const std::string &path, unsigned int depth)
{ {
const bool isCPP = scope->check->isCPP(); const bool isCPP = scope->check->isCPP();
if (!isCPP) // C does not support overloads
return true;
// skip "struct" if it is C++ // skip "struct"
if (isCPP) { if (first->str() == "struct")
if (first->str() == "struct") first = first->next();
first = first->next(); if (second->str() == "struct")
if (second->str() == "struct") second = second->next();
second = second->next();
}
// skip const on type passed by value // skip const on type passed by value
if (Token::Match(first, "const %type% %var%|,|)")) if (Token::Match(first, "const %type% %var%|,|)"))
@ -1339,13 +1341,11 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
first = first->next(); first = first->next();
second = second->next(); second = second->next();
// skip "struct" if it is C++ // skip "struct"
if (isCPP) { if (first->str() == "struct")
if (first->str() == "struct") first = first->next();
first = first->next(); if (second->str() == "struct")
if (second->str() == "struct") second = second->next();
second = second->next();
}
// skip const on type passed by value // skip const on type passed by value
if (Token::Match(first, "const %type% %var%|,|)")) if (Token::Match(first, "const %type% %var%|,|)"))

View File

@ -3247,7 +3247,7 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
// ";a+=b;" => ";a=a+b;" // ";a+=b;" => ";a=a+b;"
simplifyCompoundAssignment(); simplifyCompoundAssignment();
if (!_settings->library.markupFile(FileName)) { if (!isC() && !_settings->library.markupFile(FileName)) {
findComplicatedSyntaxErrorsInTemplates(); findComplicatedSyntaxErrorsInTemplates();
} }
@ -3461,7 +3461,8 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
// then unsimplified function calls etc remain. These have the // then unsimplified function calls etc remain. These have the
// "wrong" syntax. So this function will just fix so that the // "wrong" syntax. So this function will just fix so that the
// syntax is corrected. // syntax is corrected.
TemplateSimplifier::cleanupAfterSimplify(list.front()); if (!isC())
TemplateSimplifier::cleanupAfterSimplify(list.front());
// Collapse operator name tokens into single token // Collapse operator name tokens into single token
// operator = => operator= // operator = => operator=
@ -6220,6 +6221,9 @@ bool Tokenizer::simplifyCAlternativeTokens()
// int i(0), j; => int i; i = 0; int j; // int i(0), j; => int i; i = 0; int j;
void Tokenizer::simplifyInitVar() void Tokenizer::simplifyInitVar()
{ {
if (isC())
return;
for (Token *tok = list.front(); tok; tok = tok->next()) { for (Token *tok = list.front(); tok; tok = tok->next()) {
if (!tok->isName() || (tok->previous() && !Token::Match(tok->previous(), "[;{}]"))) if (!tok->isName() || (tok->previous() && !Token::Match(tok->previous(), "[;{}]")))
continue; continue;

View File

@ -563,7 +563,7 @@ static void compilePrecedence2(Token *&tok, AST_state& state)
} else } else
compileBinOp(tok, state, compileScope); compileBinOp(tok, state, compileScope);
} else if (tok->str() == "[") { } else if (tok->str() == "[") {
if (isPrefixUnary(tok, state.cpp) && tok->link()->strAt(1) == "(") { // Lambda if (state.cpp && isPrefixUnary(tok, state.cpp) && tok->link()->strAt(1) == "(") { // Lambda
// What we do here: // What we do here:
// - Nest the round bracket under the square bracket. // - Nest the round bracket under the square bracket.
// - Nest what follows the lambda (if anything) with the lambda opening [ // - Nest what follows the lambda (if anything) with the lambda opening [