CheckHeaders: Check for unnecessary headers. some fixes.
This commit is contained in:
parent
eade228c24
commit
eb24a6fecd
|
@ -76,10 +76,10 @@ void WarningIncludeHeader()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!tok1->next)
|
if (!tok1->next)
|
||||||
continue;
|
break;
|
||||||
|
|
||||||
if (!tok1->next->next)
|
if (!tok1->next->next)
|
||||||
continue;
|
break;
|
||||||
|
|
||||||
// I'm only interested in stuff that is declared at indentlevel 0
|
// I'm only interested in stuff that is declared at indentlevel 0
|
||||||
if (tok1->str[0] == '{')
|
if (tok1->str[0] == '{')
|
||||||
|
@ -125,41 +125,49 @@ void WarningIncludeHeader()
|
||||||
varname = getstr(tok1, 1);
|
varname = getstr(tok1, 1);
|
||||||
if (match(tok1, "type * var ;") || match(tok1, "type * var ["))
|
if (match(tok1, "type * var ;") || match(tok1, "type * var ["))
|
||||||
varname = getstr(tok1, 2);
|
varname = getstr(tok1, 2);
|
||||||
if (!varname.empty())
|
if (match(tok1, "const type var =") || match(tok1, "const type var ["))
|
||||||
{
|
varname = getstr(tok1, 2);
|
||||||
for (TOKEN *tok2 = tokens; tok2; tok2 = tok2->next)
|
if (match(tok1, "const type * var =") || match(tok1, "const type * var ["))
|
||||||
{
|
varname = getstr(tok1, 3);
|
||||||
if (tok2->FileIndex != includetok->FileIndex)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
NeedDeclaration |= (tok2->str == varname);
|
// enum..
|
||||||
Needed |= match(tok2, varname + " .");
|
std::string enumname = "";
|
||||||
Needed |= match(tok2, varname + " ->");
|
|
||||||
Needed |= match(tok2, varname + " =");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Needed | NeedDeclaration)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// enum
|
|
||||||
if (match(tok1,"enum var {"))
|
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);
|
if (tok2->FileIndex == includetok->FileIndex &&
|
||||||
|
tok2->str == varname)
|
||||||
// Try to find enum usage in "parent" file..
|
|
||||||
for (TOKEN *tok2 = tokens; tok2; tok2 = tok2->next)
|
|
||||||
{
|
{
|
||||||
if (tok2->FileIndex != includetok->FileIndex)
|
Needed = true;
|
||||||
continue;
|
|
||||||
|
|
||||||
Needed |= (enumname == tok2->str);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Needed)
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Needed | NeedDeclaration)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
10
main.cpp
10
main.cpp
|
@ -71,6 +71,13 @@ static void CppCheck(const char FileName[])
|
||||||
CheckMemset();
|
CheckMemset();
|
||||||
|
|
||||||
|
|
||||||
|
if ( ShowWarnings )
|
||||||
|
{
|
||||||
|
// Including header which is not needed
|
||||||
|
WarningIncludeHeader();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SimplifyTokenList();
|
SimplifyTokenList();
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,9 +111,6 @@ static void CppCheck(const char FileName[])
|
||||||
// Use standard functions instead
|
// Use standard functions instead
|
||||||
WarningIsDigit();
|
WarningIsDigit();
|
||||||
|
|
||||||
// Including header
|
|
||||||
//WarningIncludeHeader();
|
|
||||||
|
|
||||||
CheckOperatorEq1();
|
CheckOperatorEq1();
|
||||||
|
|
||||||
// Check that all class constructors are ok.
|
// Check that all class constructors are ok.
|
||||||
|
|
Loading…
Reference in New Issue