mirror of https://gitlab.com/basile.b/dexed.git
#104, refact ctors and dtors + add tests
This commit is contained in:
parent
3ad9b0f682
commit
394b96bf2a
|
@ -2,6 +2,8 @@ module halstead;
|
||||||
|
|
||||||
import
|
import
|
||||||
std.meta, std.algorithm.iteration, std.json, std.conv;
|
std.meta, std.algorithm.iteration, std.json, std.conv;
|
||||||
|
import
|
||||||
|
std.range: iota;
|
||||||
import
|
import
|
||||||
dparse.lexer, dparse.parser, dparse.ast, dparse.rollback_allocator;
|
dparse.lexer, dparse.parser, dparse.ast, dparse.rollback_allocator;
|
||||||
import
|
import
|
||||||
|
@ -155,8 +157,6 @@ private final class HalsteadMetric: ASTVisitor
|
||||||
expr.accept(this);
|
expr.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO-crefactor: function-dtor-ctor-... should use a common template
|
|
||||||
|
|
||||||
override void visit(const(FunctionDeclaration) decl)
|
override void visit(const(FunctionDeclaration) decl)
|
||||||
{
|
{
|
||||||
beginFunction;
|
beginFunction;
|
||||||
|
@ -166,54 +166,42 @@ private final class HalsteadMetric: ASTVisitor
|
||||||
endFunction(decl.name.text, decl.name.line);
|
endFunction(decl.name.text, decl.name.line);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(SharedStaticConstructor) ssc)
|
void visitFunction(T)(const(T) decl)
|
||||||
{
|
{
|
||||||
beginFunction;
|
beginFunction;
|
||||||
ssc.accept(this);
|
decl.accept(this);
|
||||||
endFunction("sharedStaticCtorL" ~ to!string(ssc.line), ssc.line);
|
endFunction(T.stringof ~ to!string(decl.line), decl.line);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(StaticConstructor) sc)
|
static string funDeclString()
|
||||||
{
|
{
|
||||||
beginFunction;
|
alias FunDecl = AliasSeq!(
|
||||||
sc.accept(this);
|
SharedStaticConstructor,
|
||||||
endFunction("staticCtorL" ~ to!string(sc.line), sc.line);
|
StaticConstructor,
|
||||||
|
Constructor,
|
||||||
|
SharedStaticDestructor,
|
||||||
|
StaticDestructor,
|
||||||
|
Destructor,
|
||||||
|
Postblit
|
||||||
|
);
|
||||||
|
|
||||||
|
string result;
|
||||||
|
|
||||||
|
enum funDeclOverride(T) =
|
||||||
|
"override void visit(const(" ~ T.stringof ~ ") decl)
|
||||||
|
{
|
||||||
|
visitFunction(decl);
|
||||||
|
}";
|
||||||
|
|
||||||
|
foreach(i; aliasSeqOf!(iota(0,FunDecl.length)))
|
||||||
|
{
|
||||||
|
result ~= funDeclOverride!(FunDecl[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(Constructor) sc)
|
return result;
|
||||||
{
|
|
||||||
beginFunction;
|
|
||||||
sc.accept(this);
|
|
||||||
endFunction("ctorL" ~ to!string(sc.line), sc.line);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(SharedStaticDestructor) ssc)
|
mixin(funDeclString);
|
||||||
{
|
|
||||||
beginFunction;
|
|
||||||
ssc.accept(this);
|
|
||||||
endFunction("sharedStaticDtorL" ~ to!string(ssc.line), ssc.line);
|
|
||||||
}
|
|
||||||
|
|
||||||
override void visit(const(StaticDestructor) sc)
|
|
||||||
{
|
|
||||||
beginFunction;
|
|
||||||
sc.accept(this);
|
|
||||||
endFunction("staticDtorL" ~ to!string(sc.line), sc.line);
|
|
||||||
}
|
|
||||||
|
|
||||||
override void visit(const(Destructor) sc)
|
|
||||||
{
|
|
||||||
beginFunction;
|
|
||||||
sc.accept(this);
|
|
||||||
endFunction("dtorL" ~ to!string(sc.line), sc.line);
|
|
||||||
}
|
|
||||||
|
|
||||||
override void visit(const(Postblit) pb)
|
|
||||||
{
|
|
||||||
beginFunction;
|
|
||||||
pb.accept(this);
|
|
||||||
endFunction("postblit" ~ to!string(pb.line), pb.line);
|
|
||||||
}
|
|
||||||
|
|
||||||
override void visit(const(PrimaryExpression) primary)
|
override void visit(const(PrimaryExpression) primary)
|
||||||
{
|
{
|
||||||
|
@ -464,8 +452,6 @@ private final class HalsteadMetric: ASTVisitor
|
||||||
|
|
||||||
static string binExprsString()
|
static string binExprsString()
|
||||||
{
|
{
|
||||||
import std.range: iota;
|
|
||||||
|
|
||||||
alias SeqOfBinExpr = AliasSeq!(
|
alias SeqOfBinExpr = AliasSeq!(
|
||||||
AddExpression,
|
AddExpression,
|
||||||
AndExpression,
|
AndExpression,
|
||||||
|
@ -978,3 +964,84 @@ unittest
|
||||||
assert(r.operatorsKinds == 3);
|
assert(r.operatorsKinds == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
Function r =
|
||||||
|
q{
|
||||||
|
this(){a = 0;}
|
||||||
|
}.test;
|
||||||
|
assert(r.operandsKinds == 2);
|
||||||
|
assert(r.operatorsKinds == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
Function r =
|
||||||
|
q{
|
||||||
|
static this(){a = 0;}
|
||||||
|
}.test;
|
||||||
|
assert(r.operandsKinds == 2);
|
||||||
|
assert(r.operatorsKinds == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
Function r =
|
||||||
|
q{
|
||||||
|
shared static this(){a = 0;}
|
||||||
|
}.test;
|
||||||
|
assert(r.operandsKinds == 2);
|
||||||
|
assert(r.operatorsKinds == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
Function r =
|
||||||
|
q{
|
||||||
|
~this(){a = 0;}
|
||||||
|
}.test;
|
||||||
|
assert(r.operandsKinds == 2);
|
||||||
|
assert(r.operatorsKinds == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
Function r =
|
||||||
|
q{
|
||||||
|
static ~this(){a = 0;}
|
||||||
|
}.test;
|
||||||
|
assert(r.operandsKinds == 2);
|
||||||
|
assert(r.operatorsKinds == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
Function r =
|
||||||
|
q{
|
||||||
|
shared static ~this(){a = 0;}
|
||||||
|
}.test;
|
||||||
|
assert(r.operandsKinds == 2);
|
||||||
|
assert(r.operatorsKinds == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
Function r =
|
||||||
|
q{
|
||||||
|
struct S{this(this){a = 0;}}
|
||||||
|
}.test;
|
||||||
|
assert(r.operandsKinds == 2);
|
||||||
|
assert(r.operatorsKinds == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
Function r =
|
||||||
|
q{
|
||||||
|
struct S{@disable this(this);}
|
||||||
|
}.test;
|
||||||
|
assert(r.operandsKinds == 0);
|
||||||
|
assert(r.operatorsKinds == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue