Fix #314
This commit is contained in:
parent
8671674cd5
commit
a78c4610a2
|
@ -66,6 +66,8 @@ import dsymbol.conversion.first;
|
||||||
import dsymbol.conversion.second;
|
import dsymbol.conversion.second;
|
||||||
import dsymbol.modulecache : ModuleCache;
|
import dsymbol.modulecache : ModuleCache;
|
||||||
|
|
||||||
|
import readers;
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
|
||||||
private alias ASTAllocator = CAllocatorImpl!(
|
private alias ASTAllocator = CAllocatorImpl!(
|
||||||
|
@ -112,11 +114,10 @@ void generateReport(string[] fileNames, const StaticAnalysisConfig config,
|
||||||
ulong lineOfCodeCount;
|
ulong lineOfCodeCount;
|
||||||
foreach (fileName; fileNames)
|
foreach (fileName; fileNames)
|
||||||
{
|
{
|
||||||
File f = File(fileName);
|
auto code = fileName == "stdin" ? readStdin() : readFile(fileName);
|
||||||
if (f.size == 0)
|
// Skip files that could not be read and continue with the rest
|
||||||
|
if (code.length == 0)
|
||||||
continue;
|
continue;
|
||||||
auto code = uninitializedArray!(ubyte[])(to!size_t(f.size));
|
|
||||||
f.rawRead(code);
|
|
||||||
RollbackAllocator r;
|
RollbackAllocator r;
|
||||||
const(Token)[] tokens;
|
const(Token)[] tokens;
|
||||||
const Module m = parseModule(fileName, code, &r, cache, true, tokens, &lineOfCodeCount);
|
const Module m = parseModule(fileName, code, &r, cache, true, tokens, &lineOfCodeCount);
|
||||||
|
@ -151,11 +152,10 @@ bool analyze(string[] fileNames, const StaticAnalysisConfig config,
|
||||||
bool hasErrors = false;
|
bool hasErrors = false;
|
||||||
foreach (fileName; fileNames)
|
foreach (fileName; fileNames)
|
||||||
{
|
{
|
||||||
File f = File(fileName);
|
auto code = fileName == "stdin" ? readStdin() : readFile(fileName);
|
||||||
if (f.size == 0)
|
// Skip files that could not be read and continue with the rest
|
||||||
|
if (code.length == 0)
|
||||||
continue;
|
continue;
|
||||||
auto code = uninitializedArray!(ubyte[])(to!size_t(f.size));
|
|
||||||
f.rawRead(code);
|
|
||||||
RollbackAllocator r;
|
RollbackAllocator r;
|
||||||
uint errorCount = 0;
|
uint errorCount = 0;
|
||||||
uint warningCount = 0;
|
uint warningCount = 0;
|
||||||
|
|
36
src/main.d
36
src/main.d
|
@ -29,6 +29,7 @@ import symbol_finder;
|
||||||
import analysis.run;
|
import analysis.run;
|
||||||
import analysis.config;
|
import analysis.config;
|
||||||
import dscanner_version;
|
import dscanner_version;
|
||||||
|
import readers;
|
||||||
|
|
||||||
import inifiled;
|
import inifiled;
|
||||||
|
|
||||||
|
@ -160,6 +161,8 @@ else
|
||||||
if (report)
|
if (report)
|
||||||
styleCheck = true;
|
styleCheck = true;
|
||||||
|
|
||||||
|
immutable usingStdin = args.length == 1;
|
||||||
|
|
||||||
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
||||||
if (defaultConfig)
|
if (defaultConfig)
|
||||||
{
|
{
|
||||||
|
@ -171,7 +174,6 @@ else
|
||||||
}
|
}
|
||||||
else if (tokenDump || highlight)
|
else if (tokenDump || highlight)
|
||||||
{
|
{
|
||||||
immutable bool usingStdin = args.length == 1;
|
|
||||||
ubyte[] bytes = usingStdin ? readStdin() : readFile(args[1]);
|
ubyte[] bytes = usingStdin ? readStdin() : readFile(args[1]);
|
||||||
LexerConfig config;
|
LexerConfig config;
|
||||||
config.stringBehavior = StringBehavior.source;
|
config.stringBehavior = StringBehavior.source;
|
||||||
|
@ -221,11 +223,10 @@ else
|
||||||
}
|
}
|
||||||
else if (syntaxCheck)
|
else if (syntaxCheck)
|
||||||
{
|
{
|
||||||
return .syntaxCheck(expandArgs(args), cache, moduleCache) ? 1 : 0;
|
return .syntaxCheck(usingStdin ? ["stdin"] : expandArgs(args), cache, moduleCache) ? 1 : 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool usingStdin = args.length == 1;
|
|
||||||
if (sloc || tokenCount)
|
if (sloc || tokenCount)
|
||||||
{
|
{
|
||||||
if (usingStdin)
|
if (usingStdin)
|
||||||
|
@ -330,35 +331,6 @@ string[] expandArgs(string[] args)
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
ubyte[] readStdin()
|
|
||||||
{
|
|
||||||
auto sourceCode = appender!(ubyte[])();
|
|
||||||
ubyte[4096] buf;
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
auto b = stdin.rawRead(buf);
|
|
||||||
if (b.length == 0)
|
|
||||||
break;
|
|
||||||
sourceCode.put(b);
|
|
||||||
}
|
|
||||||
return sourceCode.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
ubyte[] readFile(string fileName)
|
|
||||||
{
|
|
||||||
if (!exists(fileName))
|
|
||||||
{
|
|
||||||
stderr.writefln("%s does not exist", fileName);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
File f = File(fileName);
|
|
||||||
if (f.size == 0)
|
|
||||||
return [];
|
|
||||||
ubyte[] sourceCode = uninitializedArray!(ubyte[])(to!size_t(f.size));
|
|
||||||
f.rawRead(sourceCode);
|
|
||||||
return sourceCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
void printHelp(string programName)
|
void printHelp(string programName)
|
||||||
{
|
{
|
||||||
stderr.writefln(`
|
stderr.writefln(`
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
module readers;
|
||||||
|
|
||||||
|
import std.array : appender, uninitializedArray;
|
||||||
|
import std.stdio : stdin, stderr, File;
|
||||||
|
import std.conv : to;
|
||||||
|
import std.file : exists;
|
||||||
|
|
||||||
|
ubyte[] readStdin()
|
||||||
|
{
|
||||||
|
auto sourceCode = appender!(ubyte[])();
|
||||||
|
ubyte[4096] buf;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
auto b = stdin.rawRead(buf);
|
||||||
|
if (b.length == 0)
|
||||||
|
break;
|
||||||
|
sourceCode.put(b);
|
||||||
|
}
|
||||||
|
return sourceCode.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
ubyte[] readFile(string fileName)
|
||||||
|
{
|
||||||
|
if (!exists(fileName))
|
||||||
|
{
|
||||||
|
stderr.writefln("%s does not exist", fileName);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
File f = File(fileName);
|
||||||
|
if (f.size == 0)
|
||||||
|
return [];
|
||||||
|
ubyte[] sourceCode = uninitializedArray!(ubyte[])(to!size_t(f.size));
|
||||||
|
f.rawRead(sourceCode);
|
||||||
|
return sourceCode;
|
||||||
|
}
|
Loading…
Reference in New Issue