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()
{
if (_tokenizer->isC())
return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size();

View File

@ -38,6 +38,9 @@ namespace {
//---------------------------------------------------------------------------
void CheckIO::checkCoutCerrMisusage()
{
if (_tokenizer->isC())
return;
const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase();
std::size_t functions = symbolDatabase->functionScopes.size();
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
for (std::list<Type>::iterator it = typeList.begin(); it != typeList.end(); ++it) {
// finish filling in base class info
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);
if (!_tokenizer->isC()) {
// fill in base class info
for (std::list<Type>::iterator it = typeList.begin(); it != typeList.end(); ++it) {
// finish filling in base class info
for (unsigned int i = 0; i < it->derivedFrom.size(); ++i)
it->derivedFrom[i].type = findType(it->derivedFrom[i].nameTok, it->enclosingScope);
}
}
// fill in using info
for (std::list<Scope>::iterator it = scopeList.begin(); it != scopeList.end(); ++it) {
for (std::list<Scope::UsingInfo>::iterator i = it->usingList.begin(); i != it->usingList.end(); ++i) {
// 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;
// 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
for (std::list<Scope>::iterator it = scopeList.begin(); it != scopeList.end(); ++it) {
for (std::list<Scope::UsingInfo>::iterator i = it->usingList.begin(); i != it->usingList.end(); ++i) {
// 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)
{
const bool isCPP = scope->check->isCPP();
if (!isCPP) // C does not support overloads
return true;
// skip "struct" if it is C++
if (isCPP) {
if (first->str() == "struct")
first = first->next();
if (second->str() == "struct")
second = second->next();
}
// skip "struct"
if (first->str() == "struct")
first = first->next();
if (second->str() == "struct")
second = second->next();
// skip const on type passed by value
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();
second = second->next();
// skip "struct" if it is C++
if (isCPP) {
if (first->str() == "struct")
first = first->next();
if (second->str() == "struct")
second = second->next();
}
// skip "struct"
if (first->str() == "struct")
first = first->next();
if (second->str() == "struct")
second = second->next();
// skip const on type passed by value
if (Token::Match(first, "const %type% %var%|,|)"))

View File

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

View File

@ -563,7 +563,7 @@ static void compilePrecedence2(Token *&tok, AST_state& state)
} else
compileBinOp(tok, state, compileScope);
} 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:
// - Nest the round bracket under the square bracket.
// - Nest what follows the lambda (if anything) with the lambda opening [