mirror of https://gitlab.com/basile.b/dexed.git
#104, handle identifier chains
This commit is contained in:
parent
ad248a84be
commit
5a81971bb8
|
@ -1,13 +1,13 @@
|
||||||
module halstead;
|
module halstead;
|
||||||
|
|
||||||
import
|
import
|
||||||
std.meta, std.algorithm.iteration, std.json, std.conv;
|
std.algorithm.iteration, std.conv, std.json, std.meta;
|
||||||
import
|
import
|
||||||
std.range: iota;
|
std.range: iota;
|
||||||
import
|
import
|
||||||
dparse.lexer, dparse.parser, dparse.ast, dparse.rollback_allocator;
|
dparse.ast, dparse.lexer, dparse.parser, dparse.rollback_allocator;
|
||||||
import
|
import
|
||||||
iz.memory, iz.containers;
|
iz.memory;
|
||||||
version(unittest){} else import
|
version(unittest){} else import
|
||||||
common;
|
common;
|
||||||
|
|
||||||
|
@ -144,15 +144,17 @@ private final class HalsteadMetric: ASTVisitor
|
||||||
++operators[p.identifierOrTemplateInstance.identifier.text];
|
++operators[p.identifierOrTemplateInstance.identifier.text];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (expr.unaryExpression.identifierOrTemplateInstance)
|
||||||
|
{
|
||||||
|
if (expr.unaryExpression.identifierOrTemplateInstance.templateInstance)
|
||||||
|
++operators[expr.unaryExpression.identifierOrTemplateInstance.templateInstance.identifier.text];
|
||||||
|
else
|
||||||
|
++operators[expr.unaryExpression.identifierOrTemplateInstance.identifier.text];
|
||||||
|
}
|
||||||
if (expr.templateArguments)
|
if (expr.templateArguments)
|
||||||
{
|
{
|
||||||
if (expr.templateArguments.templateSingleArgument)
|
if (expr.templateArguments.templateSingleArgument)
|
||||||
++operands[expr.templateArguments.templateSingleArgument.token.text];
|
++operands[expr.templateArguments.templateSingleArgument.token.text];
|
||||||
else if (expr.templateArguments.templateArgumentList)
|
|
||||||
{
|
|
||||||
foreach(arg; expr.templateArguments.templateArgumentList.items)
|
|
||||||
{}//++operands[arg.token.text];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
expr.accept(this);
|
expr.accept(this);
|
||||||
}
|
}
|
||||||
|
@ -224,6 +226,13 @@ private final class HalsteadMetric: ASTVisitor
|
||||||
|
|
||||||
override void visit(const(UnaryExpression) expr)
|
override void visit(const(UnaryExpression) expr)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (expr.identifierOrTemplateInstance && !expr.primaryExpression)
|
||||||
|
{
|
||||||
|
++operators["."];
|
||||||
|
++operands[expr.identifierOrTemplateInstance.identifier.text];
|
||||||
|
}
|
||||||
|
|
||||||
if (expr.prefix.type)
|
if (expr.prefix.type)
|
||||||
++operators[str(expr.prefix.type)];
|
++operators[str(expr.prefix.type)];
|
||||||
if (expr.suffix.type)
|
if (expr.suffix.type)
|
||||||
|
@ -1067,3 +1076,46 @@ unittest
|
||||||
assert(r.operatorsKinds == 0);
|
assert(r.operatorsKinds == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
Function r =
|
||||||
|
q{
|
||||||
|
void foo()
|
||||||
|
{
|
||||||
|
a.b.c = d.e;
|
||||||
|
}
|
||||||
|
}.test;
|
||||||
|
assert(r.operandsKinds == 5);
|
||||||
|
assert(r.operatorsKinds == 2);
|
||||||
|
assert(r.operatorsSum == 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
//FIXME: operands 'c' instead of 'a'
|
||||||
|
Function r =
|
||||||
|
q{
|
||||||
|
void foo()
|
||||||
|
{
|
||||||
|
a.b.c(d.e);
|
||||||
|
}
|
||||||
|
}.test;
|
||||||
|
assert(r.operandsKinds == 4);
|
||||||
|
assert(r.operatorsKinds == 2);
|
||||||
|
assert(r.operatorsSum == 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
//FIXME: operands 'c' instead of 'a'
|
||||||
|
Function r =
|
||||||
|
q{
|
||||||
|
void foo()
|
||||||
|
{
|
||||||
|
a.b.c(d(e.f));
|
||||||
|
}
|
||||||
|
}.test;
|
||||||
|
assert(r.operandsKinds == 4);
|
||||||
|
assert(r.operatorsKinds == 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue