Skip to content

Commit

Permalink
Fix formatting and global paths in run.d
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladiwostok committed Oct 29, 2023
1 parent 8360dab commit 197a389
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions src/dscanner/analysis/run.d
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ else
enum ut = false;

private alias ASTAllocator = CAllocatorImpl!(
AllocatorList!(n => Region!Mallocator(1024 * 128), Mallocator));
AllocatorList!(n => Region!Mallocator(1024 * 128), Mallocator));

immutable string defaultErrorFormat = "{filepath}({line}:{column})[{type}]: {message}";

Expand All @@ -118,7 +118,7 @@ void messageFunctionFormat(string format, Message message, bool isError)
s = s.replace("{column}", to!string(message.column));
s = s.replace("{type}", isError ? "error" : "warn");
s = s.replace("{message}", message.message);
s = s.replace("{name}", message.checkName);
s = s.replace("{name}", message.checkName);

writefln("%s", s);
}
Expand Down Expand Up @@ -159,7 +159,7 @@ bool syntaxCheck(string[] fileNames, string errorFormat, ref StringCache stringC
}

void generateReport(string[] fileNames, const StaticAnalysisConfig config,
ref StringCache cache, ref ModuleCache moduleCache, string reportFile = "")
ref StringCache cache, ref ModuleCache moduleCache, string reportFile = "")
{
auto reporter = new DScannerJsonReporter();

Expand Down Expand Up @@ -197,7 +197,7 @@ void generateReport(string[] fileNames, const StaticAnalysisConfig config,
}

void generateSonarQubeGenericIssueDataReport(string[] fileNames, const StaticAnalysisConfig config,
ref StringCache cache, ref ModuleCache moduleCache, string reportFile = "")
ref StringCache cache, ref ModuleCache moduleCache, string reportFile = "")
{
auto reporter = new SonarQubeGenericIssueDataReporter();

Expand Down Expand Up @@ -236,7 +236,7 @@ void generateSonarQubeGenericIssueDataReport(string[] fileNames, const StaticAna
* Returns: true if there were errors or if there were warnings and `staticAnalyze` was true.
*/
bool analyze(string[] fileNames, const StaticAnalysisConfig config, string errorFormat,
ref StringCache cache, ref ModuleCache moduleCache, bool staticAnalyze = true)
ref StringCache cache, ref ModuleCache moduleCache, bool staticAnalyze = true)
{
import dmd.parse : Parser;
import dmd.astbase : ASTBase;
Expand All @@ -254,8 +254,8 @@ bool analyze(string[] fileNames, const StaticAnalysisConfig config, string error

global.params.useUnitTests = true;
global.path = new Strings();
global.path.push((dmdParentDir ~ "/dmd").ptr);
global.path.push((dmdParentDir ~ "/dmd/druntime/src").ptr);
global.path.push((dmdParentDir ~ "/dmd" ~ "\0").ptr);
global.path.push((dmdParentDir ~ "/dmd/druntime/src" ~ "\0").ptr);

initDMD();

Expand All @@ -274,7 +274,7 @@ bool analyze(string[] fileNames, const StaticAnalysisConfig config, string error
uint warningCount;
const(Token)[] tokens;
const Module m = parseModule(fileName, code, &r, errorFormat, cache, false, tokens,
null, &errorCount, &warningCount);
null, &errorCount, &warningCount);
assert(m);
if (errorCount > 0 || (staticAnalyze && warningCount > 0))
hasErrors = true;
Expand All @@ -296,9 +296,9 @@ bool analyze(string[] fileNames, const StaticAnalysisConfig config, string error
}

const(Module) parseModule(string fileName, ubyte[] code, RollbackAllocator* p,
ref StringCache cache, ref const(Token)[] tokens,
MessageDelegate dlgMessage, ulong* linesOfCode = null,
uint* errorCount = null, uint* warningCount = null)
ref StringCache cache, ref const(Token)[] tokens,
MessageDelegate dlgMessage, ulong* linesOfCode = null,
uint* errorCount = null, uint* warningCount = null)
{
import dscanner.stats : isLineOfCode;

Expand All @@ -307,22 +307,22 @@ const(Module) parseModule(string fileName, ubyte[] code, RollbackAllocator* p,
config.stringBehavior = StringBehavior.source;
tokens = getTokensForParser(code, config, &cache);
if (linesOfCode !is null)
(*linesOfCode) += count!(a => isLineOfCode(a.type))(tokens);
(*linesOfCode) += count!(a => isLineOfCode(a.type))(tokens);

return dparse.parser.parseModule(tokens, fileName, p, dlgMessage, errorCount, warningCount);
}

const(Module) parseModule(string fileName, ubyte[] code, RollbackAllocator* p,
string errorFormat, ref StringCache cache, bool report, ref const(Token)[] tokens,
ulong* linesOfCode = null, uint* errorCount = null, uint* warningCount = null)
string errorFormat, ref StringCache cache, bool report, ref const(Token)[] tokens,
ulong* linesOfCode = null, uint* errorCount = null, uint* warningCount = null)
{
auto writeMessages = delegate(string fileName, size_t line, size_t column, string message, bool isError){
return messageFunctionFormat(errorFormat, Message(fileName, line, column, "dscanner.syntax", message), isError);
};

return parseModule(fileName, code, p, cache, tokens,
report ? toDelegate(&messageFunctionJSON) : writeMessages,
linesOfCode, errorCount, warningCount);
report ? toDelegate(&messageFunctionJSON) : writeMessages,
linesOfCode, errorCount, warningCount);
}

/**
Expand Down Expand Up @@ -439,7 +439,7 @@ unittest
}

MessageSet analyze(string fileName, const Module m, const StaticAnalysisConfig analysisConfig,
ref ModuleCache moduleCache, const(Token)[] tokens, bool staticAnalyze = true)
ref ModuleCache moduleCache, const(Token)[] tokens, bool staticAnalyze = true)
{
import dsymbol.symbol : DSymbol;

Expand All @@ -448,8 +448,8 @@ MessageSet analyze(string fileName, const Module m, const StaticAnalysisConfig a

string moduleName;
if (m !is null && m.moduleDeclaration !is null &&
m.moduleDeclaration.moduleName !is null &&
m.moduleDeclaration.moduleName.identifiers !is null)
m.moduleDeclaration.moduleName !is null &&
m.moduleDeclaration.moduleName.identifiers !is null)
moduleName = m.moduleDeclaration.moduleName.identifiers.map!(e => e.text).join(".");

scope first = new FirstPass(m, internString(fileName), &moduleCache, null);
Expand Down Expand Up @@ -596,7 +596,7 @@ MessageSet analyzeDmd(string fileName, ASTCodegen.Module m, const char[] moduleN

if (moduleName.shouldRunDmd!(FinalAttributeChecker!ASTCodegen)(config))
visitors ~= new FinalAttributeChecker!ASTCodegen(fileName);

if (moduleName.shouldRunDmd!(ImportSortednessCheck!ASTCodegen)(config))
visitors ~= new ImportSortednessCheck!ASTCodegen(fileName);

Expand All @@ -605,10 +605,10 @@ MessageSet analyzeDmd(string fileName, ASTCodegen.Module m, const char[] moduleN

if (moduleName.shouldRunDmd!(RedundantAttributesCheck!ASTCodegen)(config))
visitors ~= new RedundantAttributesCheck!ASTCodegen(fileName);

if (moduleName.shouldRunDmd!(LengthSubtractionCheck!ASTCodegen)(config))
visitors ~= new LengthSubtractionCheck!ASTCodegen(fileName);

if (moduleName.shouldRunDmd!(AliasSyntaxCheck!ASTCodegen)(config))
visitors ~= new AliasSyntaxCheck!ASTCodegen(fileName);

Expand All @@ -617,7 +617,7 @@ MessageSet analyzeDmd(string fileName, ASTCodegen.Module m, const char[] moduleN

if (moduleName.shouldRunDmd!(ConstructorCheck!ASTCodegen)(config))
visitors ~= new ConstructorCheck!ASTCodegen(fileName);

if (moduleName.shouldRunDmd!(AssertWithoutMessageCheck!ASTCodegen)(config))
visitors ~= new AssertWithoutMessageCheck!ASTCodegen(
fileName,
Expand All @@ -638,22 +638,22 @@ MessageSet analyzeDmd(string fileName, ASTCodegen.Module m, const char[] moduleN
fileName,
config.trust_too_much == Check.skipTests && !ut
);

if (moduleName.shouldRunDmd!(AutoRefAssignmentCheck!ASTCodegen)(config))
visitors ~= new AutoRefAssignmentCheck!ASTCodegen(fileName);

if (moduleName.shouldRunDmd!(LogicPrecedenceCheck!ASTCodegen)(config))
visitors ~= new LogicPrecedenceCheck!ASTCodegen(
fileName,
config.logical_precedence_check == Check.skipTests && !ut
);

if (moduleName.shouldRunDmd!(UnusedLabelCheck!ASTCodegen)(config))
visitors ~= new UnusedLabelCheck!ASTCodegen(
fileName,
config.unused_label_check == Check.skipTests && !ut
);

if (moduleName.shouldRunDmd!(BuiltinPropertyNameCheck!ASTCodegen)(config))
visitors ~= new BuiltinPropertyNameCheck!ASTCodegen(fileName);

Expand Down Expand Up @@ -686,7 +686,7 @@ MessageSet analyzeDmd(string fileName, ASTCodegen.Module m, const char[] moduleN
fileName,
config.static_if_else_check == Check.skipTests && !ut
);

if (moduleName.shouldRunDmd!(UselessAssertCheck!ASTCodegen)(config))
visitors ~= new UselessAssertCheck!ASTCodegen(
fileName,
Expand All @@ -696,7 +696,7 @@ MessageSet analyzeDmd(string fileName, ASTCodegen.Module m, const char[] moduleN
foreach (visitor; visitors)
{
m.accept(visitor);

foreach (message; visitor.messages)
set.insert(message);
}
Expand Down

0 comments on commit 197a389

Please sign in to comment.