Fixed several issues with the unused variable finder and relaxed the number format rule

This commit is contained in:
Hackerpilot 2014-05-12 16:03:05 -07:00
parent 5df5716993
commit e0dc18a8b5
2 changed files with 40 additions and 59 deletions

View File

@ -34,6 +34,6 @@ class NumberStyleCheck : BaseAnalyzer
} }
} }
auto badBinaryRegex = ctRegex!(`0b[01]{9,}`); auto badBinaryRegex = ctRegex!(`^0b[01]{9,}`);
auto badDecimalRegex = ctRegex!(`\d{5,}`); auto badDecimalRegex = ctRegex!(`^\d{5,}`);
} }

View File

@ -39,45 +39,36 @@ class UnusedVariableCheck : BaseAnalyzer
override void visit(const FunctionDeclaration functionDec) override void visit(const FunctionDeclaration functionDec)
{ {
if (functionDec.functionBody is null) pushScope();
if (isOverride)
functionDec.functionBody.accept(this);
else if (functionDec.functionBody !is null)
{ {
functionDec.accept(this); functionDec.parameters.accept(this);
functionDec.functionBody.accept(this);
} }
else if (!isOverride) popScope();
}
mixin template PartsUseVariables(NodeType)
{
override void visit(const NodeType node)
{ {
pushScope(); interestDepth++;
functionDec.accept(this); node.accept(this);
popScope(); interestDepth--;
} }
} }
override void visit(const AssertExpression assertExpression) mixin PartsUseVariables!AssertExpression;
{ mixin PartsUseVariables!FunctionCallExpression;
interestDepth++; mixin PartsUseVariables!NewExpression;
assertExpression.accept(this); mixin PartsUseVariables!TemplateArgumentList;
interestDepth--; mixin PartsUseVariables!MixinExpression;
} mixin PartsUseVariables!ArgumentList;
mixin PartsUseVariables!Initializer;
override void visit(const FunctionCallExpression functionCallExpression) mixin PartsUseVariables!SliceExpression;
{ mixin PartsUseVariables!StaticIfCondition;
interestDepth++;
functionCallExpression.accept(this);
interestDepth--;
}
override void visit(const NewExpression newExpression)
{
interestDepth++;
newExpression.accept(this);
interestDepth--;
}
override void visit(const TemplateArgumentList argumentList)
{
interestDepth++;
argumentList.accept(this);
interestDepth--;
}
override void visit(const SwitchStatement switchStatement) override void visit(const SwitchStatement switchStatement)
{ {
@ -138,8 +129,6 @@ class UnusedVariableCheck : BaseAnalyzer
ifStatement.elseStatement.accept(this); ifStatement.elseStatement.accept(this);
} }
override void visit(const TypeofExpression typeofExpression) {}
override void visit(const ForeachStatement foreachStatement) override void visit(const ForeachStatement foreachStatement)
{ {
if (foreachStatement.low !is null) if (foreachStatement.low !is null)
@ -157,20 +146,6 @@ class UnusedVariableCheck : BaseAnalyzer
foreachStatement.accept(this); foreachStatement.accept(this);
} }
override void visit(const ArgumentList argumentList)
{
interestDepth++;
argumentList.accept(this);
interestDepth--;
}
override void visit(const Initializer initializer)
{
interestDepth++;
initializer.accept(this);
interestDepth--;
}
override void visit(const AssignExpression assignExp) override void visit(const AssignExpression assignExp)
{ {
assignExp.ternaryExpression.accept(this); assignExp.ternaryExpression.accept(this);
@ -184,7 +159,6 @@ class UnusedVariableCheck : BaseAnalyzer
override void visit(const TemplateDeclaration templateDeclaration) override void visit(const TemplateDeclaration templateDeclaration)
{ {
bool addScope = templateDeclaration.declarations.length > 0;
auto inAgg = inAggregateScope; auto inAgg = inAggregateScope;
inAggregateScope = true; inAggregateScope = true;
templateDeclaration.accept(this); templateDeclaration.accept(this);
@ -243,13 +217,6 @@ class UnusedVariableCheck : BaseAnalyzer
variableDeclaration.accept(this); variableDeclaration.accept(this);
} }
override void visit(const SliceExpression sliceExpression)
{
interestDepth++;
sliceExpression.accept(this);
interestDepth--;
}
override void visit(const AutoDeclaration autoDeclaration) override void visit(const AutoDeclaration autoDeclaration)
{ {
foreach (t; autoDeclaration.identifiers) foreach (t; autoDeclaration.identifiers)
@ -257,6 +224,14 @@ class UnusedVariableCheck : BaseAnalyzer
autoDeclaration.accept(this); autoDeclaration.accept(this);
} }
override void visit(const WithStatement withStatetement)
{
interestDepth++;
withStatetement.expression.accept(this);
interestDepth--;
withStatetement.statementNoCaseNoDefault.accept(this);
}
override void visit(const Parameter parameter) override void visit(const Parameter parameter)
{ {
import std.algorithm; import std.algorithm;
@ -268,6 +243,12 @@ class UnusedVariableCheck : BaseAnalyzer
variableDeclared(parameter.name.text, parameter.name.line, variableDeclared(parameter.name.text, parameter.name.line,
parameter.name.column, true, canFind(parameter.parameterAttributes, parameter.name.column, true, canFind(parameter.parameterAttributes,
cast(IdType) tok!"ref")); cast(IdType) tok!"ref"));
if (parameter.default_ !is null)
{
interestDepth++;
parameter.default_.accept(this);
interestDepth--;
}
} }
} }