CheckHeaders: Check for unnecessary headers. some fixes.

This commit is contained in:
Daniel Marjamäki 2007-06-04 06:31:57 +00:00
parent eade228c24
commit eb24a6fecd
2 changed files with 45 additions and 33 deletions

View File

@ -76,10 +76,10 @@ void WarningIncludeHeader()
continue;
if (!tok1->next)
continue;
break;
if (!tok1->next->next)
continue;
break;
// I'm only interested in stuff that is declared at indentlevel 0
if (tok1->str[0] == '{')
@ -125,41 +125,49 @@ void WarningIncludeHeader()
varname = getstr(tok1, 1);
if (match(tok1, "type * var ;") || match(tok1, "type * var ["))
varname = getstr(tok1, 2);
if (!varname.empty())
{
for (TOKEN *tok2 = tokens; tok2; tok2 = tok2->next)
{
if (tok2->FileIndex != includetok->FileIndex)
continue;
if (match(tok1, "const type var =") || match(tok1, "const type var ["))
varname = getstr(tok1, 2);
if (match(tok1, "const type * var =") || match(tok1, "const type * var ["))
varname = getstr(tok1, 3);
NeedDeclaration |= (tok2->str == varname);
Needed |= match(tok2, varname + " .");
Needed |= match(tok2, varname + " ->");
Needed |= match(tok2, varname + " =");
}
if (Needed | NeedDeclaration)
break;
}
// enum
// enum..
std::string enumname = "";
if (match(tok1,"enum var {"))
enumname = getstr(tok1, 1);
// function..
std::string funcname = "";
if (match(tok1,"type var ("))
funcname = getstr(tok1, 1);
else if (match(tok1,"type * var ("))
funcname = getstr(tok1, 2);
else if (match(tok1,"const type var ("))
funcname = getstr(tok1, 2);
else if (match(tok1,"const type * var ("))
funcname = getstr(tok1, 3);
if ( varname.empty() && enumname.empty() && funcname.empty() )
continue;
// Check if the parent contains the enum/var/function..
if ( ! enumname.empty() )
varname = enumname;
else if ( ! funcname.empty() )
varname = funcname;
for (TOKEN *tok2 = tokens; tok2; tok2 = tok2->next)
{
std::string enumname = getstr(tok1, 1);
// Try to find enum usage in "parent" file..
for (TOKEN *tok2 = tokens; tok2; tok2 = tok2->next)
if (tok2->FileIndex == includetok->FileIndex &&
tok2->str == varname)
{
if (tok2->FileIndex != includetok->FileIndex)
continue;
Needed |= (enumname == tok2->str);
}
if (Needed)
Needed = true;
break;
}
}
if (Needed | NeedDeclaration)
break;
}

View File

@ -71,6 +71,13 @@ static void CppCheck(const char FileName[])
CheckMemset();
if ( ShowWarnings )
{
// Including header which is not needed
WarningIncludeHeader();
}
SimplifyTokenList();
@ -104,9 +111,6 @@ static void CppCheck(const char FileName[])
// Use standard functions instead
WarningIsDigit();
// Including header
//WarningIncludeHeader();
CheckOperatorEq1();
// Check that all class constructors are ok.