mirror of https://gitlab.com/basile.b/dexed.git
update submodule and use iz AA in the halstead tool
This commit is contained in:
parent
ac88730621
commit
63ce8feb7f
|
@ -7,7 +7,7 @@ import
|
||||||
import
|
import
|
||||||
dparse.ast, dparse.lexer, dparse.parser, dparse.rollback_allocator;
|
dparse.ast, dparse.lexer, dparse.parser, dparse.rollback_allocator;
|
||||||
import
|
import
|
||||||
iz.memory;
|
iz.memory, iz.containers;
|
||||||
version(unittest){} else import
|
version(unittest){} else import
|
||||||
common;
|
common;
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ private final class HalsteadMetric: ASTVisitor
|
||||||
alias visit = ASTVisitor.visit;
|
alias visit = ASTVisitor.visit;
|
||||||
|
|
||||||
Function[] functions;
|
Function[] functions;
|
||||||
size_t[string] operators;
|
HashMap_AB!(string, size_t) operators;
|
||||||
size_t[string] operands;
|
HashMap_AB!(string, size_t) operands;
|
||||||
BinaryExprFlags[] binExprFlag;
|
BinaryExprFlags[] binExprFlag;
|
||||||
size_t functionNesting;
|
size_t functionNesting;
|
||||||
bool[] inFunctionCallChain;
|
bool[] inFunctionCallChain;
|
||||||
|
@ -74,9 +74,9 @@ private final class HalsteadMetric: ASTVisitor
|
||||||
foreach(i, ident; chain)
|
foreach(i, ident; chain)
|
||||||
{
|
{
|
||||||
if (i == chain.length-1)
|
if (i == chain.length-1)
|
||||||
++operators[getIdent(ident).text];
|
operators[getIdent(ident).text] +=1;
|
||||||
else
|
else
|
||||||
++operands[getIdent(ident).text];
|
operands[getIdent(ident).text] +=1;
|
||||||
}
|
}
|
||||||
chain.length = 0;
|
chain.length = 0;
|
||||||
}
|
}
|
||||||
|
@ -87,9 +87,9 @@ private final class HalsteadMetric: ASTVisitor
|
||||||
if (isLiteral(tk.type))
|
if (isLiteral(tk.type))
|
||||||
{
|
{
|
||||||
alias immutHexStr = toHexString!(Order.increasing, LetterCase.upper);
|
alias immutHexStr = toHexString!(Order.increasing, LetterCase.upper);
|
||||||
++operands["literal" ~ immutHexStr(tk.text.crc32Of)];
|
operands["literal" ~ immutHexStr(tk.text.crc32Of)] +=1;
|
||||||
}
|
}
|
||||||
else ++operands[tk.text];
|
else operands[tk.text] +=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pushExprFlags(bool leftFlag = false, bool rightFlag = false)
|
void pushExprFlags(bool leftFlag = false, bool rightFlag = false)
|
||||||
|
@ -138,15 +138,15 @@ private final class HalsteadMetric: ASTVisitor
|
||||||
functions[$-1].name = name;
|
functions[$-1].name = name;
|
||||||
functions[$-1].line = line;
|
functions[$-1].line = line;
|
||||||
|
|
||||||
if (operators.length)
|
if (operators.count)
|
||||||
{
|
{
|
||||||
functions[$-1].N1 = operators.byValue.fold!((a,b) => b = a + b);
|
functions[$-1].N1 = operators.byValue.fold!((a,b) => b = a + b);
|
||||||
functions[$-1].n1 = operators.length;
|
functions[$-1].n1 = operators.count;
|
||||||
}
|
}
|
||||||
if (operands.length)
|
if (operands.count)
|
||||||
{
|
{
|
||||||
functions[$-1].N2 = operands.byValue.fold!((a,b) => b = a + b);
|
functions[$-1].N2 = operands.byValue.fold!((a,b) => b = a + b);
|
||||||
functions[$-1].n2 = operands.length;
|
functions[$-1].n2 = operands.count;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONValue f;
|
JSONValue f;
|
||||||
|
@ -253,7 +253,7 @@ private final class HalsteadMetric: ASTVisitor
|
||||||
(inFunctionCallChain[$-1] & exprLeftIsFunction) ||
|
(inFunctionCallChain[$-1] & exprLeftIsFunction) ||
|
||||||
(inFunctionCallChain[$-1] & exprRightIsFunction))
|
(inFunctionCallChain[$-1] & exprRightIsFunction))
|
||||||
{
|
{
|
||||||
++operands[primary.identifierOrTemplateInstance.identifier.text];
|
operands[primary.identifierOrTemplateInstance.identifier.text] +=1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else addOperandFromToken(primary.primary);
|
else addOperandFromToken(primary.primary);
|
||||||
|
@ -274,29 +274,29 @@ private final class HalsteadMetric: ASTVisitor
|
||||||
|
|
||||||
if (expr.identifierOrTemplateInstance)
|
if (expr.identifierOrTemplateInstance)
|
||||||
{
|
{
|
||||||
++operators["."];
|
operators["."] += 1;
|
||||||
|
|
||||||
if (inFunctionCallChain[$-1])
|
if (inFunctionCallChain[$-1])
|
||||||
chain ~= expr.identifierOrTemplateInstance;
|
chain ~= expr.identifierOrTemplateInstance;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (expr.identifierOrTemplateInstance.identifier != tok!"")
|
if (expr.identifierOrTemplateInstance.identifier != tok!"")
|
||||||
++operands[expr.identifierOrTemplateInstance.identifier.text];
|
operands[expr.identifierOrTemplateInstance.identifier.text] +=1;
|
||||||
else
|
else
|
||||||
++operands[expr.identifierOrTemplateInstance.templateInstance.identifier.text];
|
operands[expr.identifierOrTemplateInstance.templateInstance.identifier.text] +=1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expr.prefix.type)
|
if (expr.prefix.type)
|
||||||
++operators[str(expr.prefix.type)];
|
operators[str(expr.prefix.type)] += 1;
|
||||||
if (expr.suffix.type)
|
if (expr.suffix.type)
|
||||||
++operators[str(expr.suffix.type)];
|
operators[str(expr.suffix.type)] += 1;
|
||||||
}
|
}
|
||||||
override void visit(const(AsmInstruction) ai)
|
override void visit(const(AsmInstruction) ai)
|
||||||
{
|
{
|
||||||
if (ai.identifierOrIntegerOrOpcode != tok!"")
|
if (ai.identifierOrIntegerOrOpcode != tok!"")
|
||||||
{
|
{
|
||||||
++operators[ai.identifierOrIntegerOrOpcode.text];
|
operators[ai.identifierOrIntegerOrOpcode.text] += 1;
|
||||||
}
|
}
|
||||||
ai.accept(this);
|
ai.accept(this);
|
||||||
}
|
}
|
||||||
|
@ -305,7 +305,7 @@ private final class HalsteadMetric: ASTVisitor
|
||||||
{
|
{
|
||||||
if (reg.identifier != tok!"")
|
if (reg.identifier != tok!"")
|
||||||
{
|
{
|
||||||
++operands[reg.identifier.text];
|
operands[reg.identifier.text] +=1;
|
||||||
}
|
}
|
||||||
if (reg.hasIntegerLiteral)
|
if (reg.hasIntegerLiteral)
|
||||||
{
|
{
|
||||||
|
@ -328,154 +328,154 @@ private final class HalsteadMetric: ASTVisitor
|
||||||
|
|
||||||
override void visit(const(IndexExpression) expr)
|
override void visit(const(IndexExpression) expr)
|
||||||
{
|
{
|
||||||
++operators["[]"];
|
operators["[]"] += 1;
|
||||||
expr.accept(this);
|
expr.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(NewExpression) expr)
|
override void visit(const(NewExpression) expr)
|
||||||
{
|
{
|
||||||
++operators["new"];
|
operators["new"] += 1;
|
||||||
expr.accept(this);
|
expr.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(NewAnonClassExpression) expr)
|
override void visit(const(NewAnonClassExpression) expr)
|
||||||
{
|
{
|
||||||
++operators["new"];
|
operators["new"] += 1;
|
||||||
expr.accept(this);
|
expr.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(DeleteExpression) expr)
|
override void visit(const(DeleteExpression) expr)
|
||||||
{
|
{
|
||||||
++operators["delete"];
|
operators["delete"] += 1;
|
||||||
expr.accept(this);
|
expr.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(CastExpression) expr)
|
override void visit(const(CastExpression) expr)
|
||||||
{
|
{
|
||||||
++operators["cast"];
|
operators["cast"] += 1;
|
||||||
expr.accept(this);
|
expr.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(IsExpression) expr)
|
override void visit(const(IsExpression) expr)
|
||||||
{
|
{
|
||||||
++operators["is"];
|
operators["is"] += 1;
|
||||||
expr.accept(this);
|
expr.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(TernaryExpression) expr)
|
override void visit(const(TernaryExpression) expr)
|
||||||
{
|
{
|
||||||
if (expr.orOrExpression)
|
if (expr.orOrExpression)
|
||||||
++operators["if"];
|
operators["if"] += 1;
|
||||||
if (expr.expression)
|
if (expr.expression)
|
||||||
++operators["else"];
|
operators["else"] += 1;
|
||||||
expr.accept(this);
|
expr.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(TypeidExpression) expr)
|
override void visit(const(TypeidExpression) expr)
|
||||||
{
|
{
|
||||||
++operators["typeid"];
|
operators["typeid"] += 1;
|
||||||
expr.accept(this);
|
expr.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(IfStatement) st)
|
override void visit(const(IfStatement) st)
|
||||||
{
|
{
|
||||||
++operators["if"];
|
operators["if"] += 1;
|
||||||
st.accept(this);
|
st.accept(this);
|
||||||
if (st.thenStatement)
|
if (st.thenStatement)
|
||||||
++operators["then"];
|
operators["then"] += 1;
|
||||||
if (st.elseStatement)
|
if (st.elseStatement)
|
||||||
++operators["else"];
|
operators["else"] += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(WhileStatement) st)
|
override void visit(const(WhileStatement) st)
|
||||||
{
|
{
|
||||||
++operators["while"];
|
operators["while"] +=1;
|
||||||
st.accept(this);
|
st.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(ForStatement) st)
|
override void visit(const(ForStatement) st)
|
||||||
{
|
{
|
||||||
++operators["for"];
|
operators["for"] +=1;
|
||||||
st.accept(this);
|
st.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(ForeachStatement) st)
|
override void visit(const(ForeachStatement) st)
|
||||||
{
|
{
|
||||||
++operators["foreach"];
|
operators["foreach"] +=1;
|
||||||
if (st.foreachTypeList)
|
if (st.foreachTypeList)
|
||||||
foreach(ft; st.foreachTypeList.items)
|
foreach(ft; st.foreachTypeList.items)
|
||||||
++operands[ft.identifier.text];
|
operands[ft.identifier.text] +=1;
|
||||||
if (st.foreachType)
|
if (st.foreachType)
|
||||||
++operands[st.foreachType.identifier.text];
|
operands[st.foreachType.identifier.text] +=1;
|
||||||
st.accept(this);
|
st.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(ReturnStatement) st)
|
override void visit(const(ReturnStatement) st)
|
||||||
{
|
{
|
||||||
++operators["return"];
|
operators["return"] +=1;
|
||||||
st.accept(this);
|
st.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(BreakStatement) st)
|
override void visit(const(BreakStatement) st)
|
||||||
{
|
{
|
||||||
++operators["break"];
|
operators["break"] +=1;
|
||||||
st.accept(this);
|
st.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(ContinueStatement) st)
|
override void visit(const(ContinueStatement) st)
|
||||||
{
|
{
|
||||||
++operators["continue"];
|
operators["continue"] +=1;
|
||||||
st.accept(this);
|
st.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(GotoStatement) st)
|
override void visit(const(GotoStatement) st)
|
||||||
{
|
{
|
||||||
++operators["goto"];
|
operators["goto"] +=1;
|
||||||
st.accept(this);
|
st.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(SwitchStatement) st)
|
override void visit(const(SwitchStatement) st)
|
||||||
{
|
{
|
||||||
++operators["switch"];
|
operators["switch"] +=1;
|
||||||
st.accept(this);
|
st.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(CaseStatement) st)
|
override void visit(const(CaseStatement) st)
|
||||||
{
|
{
|
||||||
++operators["case"];
|
operators["case"] +=1;
|
||||||
st.accept(this);
|
st.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(CaseRangeStatement) st)
|
override void visit(const(CaseRangeStatement) st)
|
||||||
{
|
{
|
||||||
++++operators["case"];
|
operators["case"] +=2;
|
||||||
st.accept(this);
|
st.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(DefaultStatement) st)
|
override void visit(const(DefaultStatement) st)
|
||||||
{
|
{
|
||||||
++operators["case"];
|
operators["case"] +=1;
|
||||||
st.accept(this);
|
st.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(ThrowStatement) st)
|
override void visit(const(ThrowStatement) st)
|
||||||
{
|
{
|
||||||
++operators["throw"];
|
operators["throw"] +=1;
|
||||||
st.accept(this);
|
st.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(TryStatement) st)
|
override void visit(const(TryStatement) st)
|
||||||
{
|
{
|
||||||
++operators["try"];
|
operators["try"] +=1;
|
||||||
st.accept(this);
|
st.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(Catch) c)
|
override void visit(const(Catch) c)
|
||||||
{
|
{
|
||||||
++operators["catch"];
|
operators["catch"] +=1;
|
||||||
c.accept(this);
|
c.accept(this);
|
||||||
if (c.identifier.text)
|
if (c.identifier.text)
|
||||||
++operands[c.identifier.text];
|
operands[c.identifier.text] +=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const(VariableDeclaration) decl)
|
override void visit(const(VariableDeclaration) decl)
|
||||||
|
@ -483,9 +483,9 @@ private final class HalsteadMetric: ASTVisitor
|
||||||
if (decl.declarators)
|
if (decl.declarators)
|
||||||
foreach (elem; decl.declarators)
|
foreach (elem; decl.declarators)
|
||||||
{
|
{
|
||||||
++operands[elem.name.text];
|
operands[elem.name.text] +=1;
|
||||||
if (elem.initializer)
|
if (elem.initializer)
|
||||||
++operators["="];
|
operators["="] +=1;
|
||||||
}
|
}
|
||||||
else if (decl.autoDeclaration)
|
else if (decl.autoDeclaration)
|
||||||
visit(decl.autoDeclaration);
|
visit(decl.autoDeclaration);
|
||||||
|
@ -494,8 +494,8 @@ private final class HalsteadMetric: ASTVisitor
|
||||||
|
|
||||||
override void visit(const AutoDeclarationPart decl)
|
override void visit(const AutoDeclarationPart decl)
|
||||||
{
|
{
|
||||||
++operands[decl.identifier.text];
|
operands[decl.identifier.text] +=1;
|
||||||
++operators["="];
|
operators["="] +=1;
|
||||||
decl.accept(this);
|
decl.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -538,7 +538,7 @@ private final class HalsteadMetric: ASTVisitor
|
||||||
else static if (is(T == XorExpression)) op = `^`;
|
else static if (is(T == XorExpression)) op = `^`;
|
||||||
else static assert(0, T.stringof);
|
else static assert(0, T.stringof);
|
||||||
}
|
}
|
||||||
++operators[op];
|
operators[op] +=1;
|
||||||
|
|
||||||
pushExprFlags(leftArgIsFunctFlag, rightArgIsFunctFlag);
|
pushExprFlags(leftArgIsFunctFlag, rightArgIsFunctFlag);
|
||||||
expr.accept(this);
|
expr.accept(this);
|
||||||
|
|
2
etc/iz
2
etc/iz
|
@ -1 +1 @@
|
||||||
Subproject commit 331717f64fb359e76d94e25ee3389e148fc077f3
|
Subproject commit 36a3d69f2f30fe7c3c5993a954afa6983102137f
|
Loading…
Reference in New Issue