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.modulecache : ModuleCache;
|
||||
|
||||
import readers;
|
||||
|
||||
bool first = true;
|
||||
|
||||
private alias ASTAllocator = CAllocatorImpl!(
|
||||
|
@ -112,11 +114,10 @@ void generateReport(string[] fileNames, const StaticAnalysisConfig config,
|
|||
ulong lineOfCodeCount;
|
||||
foreach (fileName; fileNames)
|
||||
{
|
||||
File f = File(fileName);
|
||||
if (f.size == 0)
|
||||
auto code = fileName == "stdin" ? readStdin() : readFile(fileName);
|
||||
// Skip files that could not be read and continue with the rest
|
||||
if (code.length == 0)
|
||||
continue;
|
||||
auto code = uninitializedArray!(ubyte[])(to!size_t(f.size));
|
||||
f.rawRead(code);
|
||||
RollbackAllocator r;
|
||||
const(Token)[] tokens;
|
||||
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;
|
||||
foreach (fileName; fileNames)
|
||||
{
|
||||
File f = File(fileName);
|
||||
if (f.size == 0)
|
||||
auto code = fileName == "stdin" ? readStdin() : readFile(fileName);
|
||||
// Skip files that could not be read and continue with the rest
|
||||
if (code.length == 0)
|
||||
continue;
|
||||
auto code = uninitializedArray!(ubyte[])(to!size_t(f.size));
|
||||
f.rawRead(code);
|
||||
RollbackAllocator r;
|
||||
uint errorCount = 0;
|
||||
uint warningCount = 0;
|
||||
|
|
36
src/main.d
36
src/main.d
|
@ -29,6 +29,7 @@ import symbol_finder;
|
|||
import analysis.run;
|
||||
import analysis.config;
|
||||
import dscanner_version;
|
||||
import readers;
|
||||
|
||||
import inifiled;
|
||||
|
||||
|
@ -160,6 +161,8 @@ else
|
|||
if (report)
|
||||
styleCheck = true;
|
||||
|
||||
immutable usingStdin = args.length == 1;
|
||||
|
||||
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
||||
if (defaultConfig)
|
||||
{
|
||||
|
@ -171,7 +174,6 @@ else
|
|||
}
|
||||
else if (tokenDump || highlight)
|
||||
{
|
||||
immutable bool usingStdin = args.length == 1;
|
||||
ubyte[] bytes = usingStdin ? readStdin() : readFile(args[1]);
|
||||
LexerConfig config;
|
||||
config.stringBehavior = StringBehavior.source;
|
||||
|
@ -221,11 +223,10 @@ else
|
|||
}
|
||||
else if (syntaxCheck)
|
||||
{
|
||||
return .syntaxCheck(expandArgs(args), cache, moduleCache) ? 1 : 0;
|
||||
return .syntaxCheck(usingStdin ? ["stdin"] : expandArgs(args), cache, moduleCache) ? 1 : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool usingStdin = args.length == 1;
|
||||
if (sloc || tokenCount)
|
||||
{
|
||||
if (usingStdin)
|
||||
|
@ -330,35 +331,6 @@ string[] expandArgs(string[] args)
|
|||
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)
|
||||
{
|
||||
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