This commit is contained in:
Hackerpilot 2014-07-22 15:14:46 -07:00
commit 4197b0c829
5 changed files with 50 additions and 28 deletions

View File

@ -40,17 +40,35 @@ class PokemonExceptionCheck : BaseAnalyzer
lc.accept(this); lc.accept(this);
} }
bool ignoreType = true;
override void visit(const Catch c) override void visit(const Catch c)
{ {
if (c.type.type2.symbol.identifierOrTemplateChain.identifiersOrTemplateInstances.length != 1) ignoreType = false;
c.type.accept(this);
ignoreType = true;
c.accept(this);
}
override void visit(const Type2 type2)
{
if (ignoreType) return;
if (type2.type !is null)
{ {
c.accept(this); type2.type.accept(this);
return; return;
} }
auto identOrTemplate = c.type.type2.symbol.identifierOrTemplateChain.identifiersOrTemplateInstances[0];
if (type2.symbol.identifierOrTemplateChain.identifiersOrTemplateInstances.length != 1)
{
return;
}
auto identOrTemplate = type2.symbol.identifierOrTemplateChain.identifiersOrTemplateInstances[0];
if (identOrTemplate.templateInstance !is null) if (identOrTemplate.templateInstance !is null)
{ {
c.accept(this);
return; return;
} }
if (identOrTemplate.identifier.text == "Throwable" if (identOrTemplate.identifier.text == "Throwable"
@ -60,7 +78,6 @@ class PokemonExceptionCheck : BaseAnalyzer
immutable line = identOrTemplate.identifier.line; immutable line = identOrTemplate.identifier.line;
addErrorMessage(line, column, message); addErrorMessage(line, column, message);
} }
c.accept(this);
} }
} }
@ -83,6 +100,10 @@ unittest
catch (Exception err) // ok catch (Exception err) // ok
{ {
}
catch (shared(Exception) err) // ok
{
} }
catch (Error err) // [warn]: Catching Error or Throwable is almost always a bad idea. catch (Error err) // [warn]: Catching Error or Throwable is almost always a bad idea.
{ {
@ -91,9 +112,14 @@ unittest
catch (Throwable err) // [warn]: Catching Error or Throwable is almost always a bad idea. catch (Throwable err) // [warn]: Catching Error or Throwable is almost always a bad idea.
{ {
}
catch (shared(Error) err) // [warn]: Catching Error or Throwable is almost always a bad idea.
{
} }
catch // [warn]: Catching Error or Throwable is almost always a bad idea. catch // [warn]: Catching Error or Throwable is almost always a bad idea.
{ {
} }
} }
}c, sac); }c, sac);

View File

@ -74,18 +74,23 @@ class BackwardsRangeCheck : BaseAnalyzer
override void visit(const PrimaryExpression primary) override void visit(const PrimaryExpression primary)
{ {
import std.conv;
if (state == State.ignore || !isNumberLiteral(primary.primary.type)) if (state == State.ignore || !isNumberLiteral(primary.primary.type))
return; return;
if (state == State.left) if (state == State.left)
{ {
line = primary.primary.line; line = primary.primary.line;
this.column = primary.primary.column; this.column = primary.primary.column;
left = parseNumber(primary.primary.text);
try left = parseNumber(primary.primary.text);
catch (ConvException e) return;
hasLeft = true; hasLeft = true;
} }
else else
{ {
right = parseNumber(primary.primary.text); try right = parseNumber(primary.primary.text);
catch (ConvException e) return;
hasRight = true; hasRight = true;
} }
} }

View File

@ -1422,14 +1422,15 @@ class XMLPrinter : ASTVisitor
output.writeln("<unaryExpression>"); output.writeln("<unaryExpression>");
if (unaryExpression.prefix != tok!"") if (unaryExpression.prefix != tok!"")
{ {
output.writeln("<prefix>", xmlEscape(unaryExpression.prefix.text), output.writeln("<prefix>", xmlEscape(str(unaryExpression.prefix.type)),
"</prefix>"); "</prefix>");
unaryExpression.unaryExpression.accept(this); unaryExpression.unaryExpression.accept(this);
} }
if (unaryExpression.suffix != tok!"") if (unaryExpression.suffix != tok!"")
{ {
assert(unaryExpression.suffix.text == "");
unaryExpression.unaryExpression.accept(this); unaryExpression.unaryExpression.accept(this);
output.writeln("<suffix>", unaryExpression.suffix.text, output.writeln("<suffix>", str(unaryExpression.suffix.type),
"</suffix>"); "</suffix>");
} }
else else

View File

@ -9,8 +9,8 @@ set ANALYSIS=
set INIFILED= set INIFILED=
for %%x in (*.d) do set CORE=!CORE! %%x for %%x in (*.d) do set CORE=!CORE! %%x
for %%x in (std/*.d) do set STD=!STD! std/%%x for %%x in (libdparse/src/std/*.d) do set STD=!STD! libdparse/src/std/%%x
for %%x in (std/d/*.d) do set STDD=!STDD! std/d/%%x for %%x in (libdparse/src/std/d/*.d) do set STDD=!STDD! libdparse/src/std/d/%%x
for %%x in (analysis/*.d) do set ANALYSIS=!ANALYSIS! analysis/%%x for %%x in (analysis/*.d) do set ANALYSIS=!ANALYSIS! analysis/%%x
for %%x in (inifiled/source/*.d) do set INIFILED=!INIFILED! inifiled/source/%%x for %%x in (inifiled/source/*.d) do set INIFILED=!INIFILED! inifiled/source/%%x

View File

@ -1,20 +1,10 @@
{ {
"name": "dscanner", "name": "dscanner",
"description": "Swiss-army knife for D source code", "description": "Swiss-army knife for D source code",
"copyright": "© Brian Schott", "copyright": "© Brian Schott",
"authors": ["Brian Schott"], "authors": ["Brian Schott"],
"importPaths": ["."],
"license" : "Boost Software License - Version 1.0", "license" : "Boost Software License - Version 1.0",
"configurations": [ "targetType": "executable",
{ "sourcePaths": ["."],
"name": "library", "excludedSourceFiles": ["inifiled/inifiled.d", "inifiled/test.d"],
"targetType": "library",
"sourcePaths": ["std"],
},
{
"name": "dscanner",
"targetType": "executable",
"sourcePaths": ["."],
},
],
} }