halstead, show full func sig

This commit is contained in:
Basile Burg 2021-07-14 23:20:11 +02:00
parent b95eb67b8f
commit 5c4152c99b
4 changed files with 20 additions and 14 deletions

View File

@ -2,6 +2,7 @@
## Enhancement
- Halstead metrics: show full function signatures.
- DUB projects: added support for the _syntax_ build type. (#83)
# v3.9.11

View File

@ -501,3 +501,20 @@ unittest
assert(fpcString.length == test.length);
assert(fpcString.data[0..fpcString.length] == test);
}
string funcDeclText(const FunctionDeclaration fd)
{
import dparse.formatter : Formatter;
alias Fmt = Formatter!(Array!char*);
__gshared Array!char app;
__gshared Fmt fmt;
if (!fmt)
fmt = construct!Fmt(&app);
app.length = 0;
app.put(cast() fd.name.text);
fmt.format(fd.parameters);
return app[].idup;
}

View File

@ -222,7 +222,7 @@ private final class HalsteadMetric: ASTVisitor
if (!decl.functionBody)
return;
decl.accept(this);
endFunction(decl.name.text, decl.name.line);
endFunction(patchPascalString(funcDeclText(decl)), decl.name.line);
}
void visitFunction(T)(const(T) decl)

View File

@ -110,8 +110,6 @@ static assert (!MustAddGcRange!(SymbolListBuilder!(ListFmt.Pas)));
JSONValue* jarray;
}
Array!char funcNameApp;
Formatter!(Array!char*) fmtVisitor;
uint utc;
this(Appender!(AstErrors) errors, bool deep)
@ -126,14 +124,11 @@ static assert (!MustAddGcRange!(SymbolListBuilder!(ListFmt.Pas)));
json = parseJSON("[]");
jarray = &json;
}
fmtVisitor = construct!(typeof(fmtVisitor))(&funcNameApp);
addAstErrors(errors.data);
}
~this()
{
destruct(funcNameApp);
destruct(fmtVisitor);
static if (Fmt == ListFmt.Pas)
{
destruct(pasStream);
@ -199,14 +194,7 @@ static assert (!MustAddGcRange!(SymbolListBuilder!(ListFmt.Pas)));
pasStream.put(format("col=%d\r", dt.name.column));
static if (is(DT == FunctionDeclaration))
{
if (dt.parameters && dt.parameters.parameters &&
dt.parameters.parameters.length)
{
funcNameApp.length = 0;
fmtVisitor.format(dt.parameters);
pasStream.put(format("name='%s%s'\r", dt.name.text, patchPascalString(funcNameApp[])));
}
else pasStream.put(format("name='%s'\r", dt.name.text));
pasStream.put(format("name='%s'\r", funcDeclText(dt).patchPascalString()));
}
else
{