refact dastworx with safeAccess

This commit is contained in:
Basile Burg 2018-03-30 13:50:43 +02:00
parent 682150df1f
commit 4216d02542
5 changed files with 20 additions and 25 deletions

View File

@ -3,7 +3,7 @@ module ddoc_template;
import
std.stdio;
import
iz.memory;
iz.memory, iz.sugar;
import
dparse.ast, dparse.lexer, dparse.parser, dparse.rollback_allocator;
@ -55,15 +55,15 @@ public:
decl.accept(this);
writeln("/", c2, "\n ", c1, " <short description> \n ", c1, " \n ", c1, " <detailed description>", c1);
if ((decl.templateParameters && decl.templateParameters.templateParameterList && decl.templateParameters.templateParameterList.items.length) ||
const TemplateParameterList tpl = safeAccess(decl).templateParameters.templateParameterList;
if ((tpl && tpl.items.length) ||
(decl.parameters && decl.parameters.parameters.length))
{
writeln(" ", c1, " \n ", c1, " Params:");
if (decl.templateParameters && decl.templateParameters.templateParameterList)
if (tpl)
{
foreach(const TemplateParameter p; decl.templateParameters
.templateParameterList.items)
foreach(const TemplateParameter p; tpl.items)
{
if (p.templateAliasParameter)
writeln(" ", c1, " ", p.templateAliasParameter.identifier.text, " = <description>");
@ -87,11 +87,10 @@ public:
}
}
if (decl.returnType)
if (const Type2 tp2 = safeAccess(decl).returnType.type2)
{
if (decl.returnType.type2 && decl.returnType.type2
&& decl.returnType.type2.builtinType != tok!"void")
writeln(" ", c1, " \n ", c1, " Returns: <return description>");
if (tp2.builtinType != tok!"void")
writeln(" ", c1, " \n ", c1, " Returns: <return description>");
}
if (_throws)
@ -144,13 +143,12 @@ public:
{
writeln("/", c2, "\n ", c1, " <short description> \n ", c1, " \n ", c1, " <detailed description>", c1);
if (decl.templateParameters && decl.templateParameters.templateParameterList &&
decl.templateParameters.templateParameterList.items.length)
const TemplateParameterList tpl = safeAccess(decl).templateParameters.templateParameterList;
if (tpl && tpl.items.length)
{
writeln(" ", c1, " \n ", c1, " Params:");
foreach(const TemplateParameter p; decl.templateParameters
.templateParameterList.items)
foreach(const TemplateParameter p; tpl.items)
{
if (p.templateAliasParameter)
writeln(" ", c1, " ", p.templateAliasParameter.identifier.text, " = <description>");

View File

@ -7,7 +7,7 @@ import
import
dparse.ast, dparse.lexer, dparse.parser, dparse.rollback_allocator;
import
iz.memory, iz.containers;
iz.memory, iz.containers, iz.sugar;
version(unittest){} else import
common;
@ -183,11 +183,9 @@ private final class HalsteadMetric: ASTVisitor
inFunctionCallChain.length++;
inFunctionCallChain[$-1] = true;
if (expr.templateArguments)
{
if (expr.templateArguments.templateSingleArgument)
addOperandFromToken(expr.templateArguments.templateSingleArgument.token);
}
if (const TemplateSingleArgument tsi = safeAccess(expr)
.templateArguments.templateSingleArgument)
addOperandFromToken(tsi.token);
expr.accept(this);

View File

@ -3,7 +3,7 @@ module mainfun;
import
std.stdio, std.algorithm;
import
iz.memory;
iz.memory, iz.sugar;
import
dparse.lexer, dparse.ast, dparse.parser;
import
@ -36,10 +36,9 @@ private final class MainFunctionDetector: ASTVisitor
override void visit(const ConditionalDeclaration decl)
{
bool acc = true;
if (decl.compileCondition)
if (const VersionCondition vc = safeAccess(decl).compileCondition.versionCondition)
{
const ver = decl.compileCondition.versionCondition;
if (ver && ver.token.text in badVersions)
if (vc.token.text in badVersions())
acc = false;
}
if (acc)

2
etc/iz

@ -1 +1 @@
Subproject commit 4edb02337493c1f931a892c1c0831513334483fd
Subproject commit 52288791debfe9b5ebf8691f91178dd525a38661

@ -1 +1 @@
Subproject commit ee0fa01ab74b6bf27bed3c7bdb9d6fb789963342
Subproject commit 82290cb64bfb4cd7d645dad1cfbf077f75272356