dastworx, two issues

+ prevent ast errors to be written to std streams
+ stream not flushed, caused incomplete results after import ana
This commit is contained in:
Basile Burg 2016-07-05 01:10:10 +02:00
parent e7d545bcad
commit e27d216bf6
5 changed files with 22 additions and 3 deletions

View File

@ -340,9 +340,19 @@ T parseAndVisit(T : ASTVisitor)(const(char)[] source)
LexerConfig config = LexerConfig("", StringBehavior.source, WhitespaceBehavior.skip);
StringCache cache = StringCache(StringCache.defaultBucketCount);
const(Token)[] tokens = getTokensForParser(cast(ubyte[]) source, config, &cache);
Module mod = parseModule(tokens, "", &allocator);
Module mod = parseModule(tokens, "", &allocator, &handleErrors);
T result = construct!(T);
result.visit(mod);
return result;
}
/**
* By default libdparse outputs errors and warnings to the standard streams.
* This function prevents that.
*/
void handleErrors(string fname, size_t line, size_t col, string message,
bool err)
{
// dont pollute output
}

View File

@ -53,19 +53,25 @@ void listFilesImports(string[] files)
{
ubyte[] source = cast(ubyte[]) std.file.read(fname);
Module mod = parseModule(getTokensForParser(source, config, &cache),
fname, &allocator);
fname, &allocator, &handleErrors);
writeln('"', mod.moduleDeclaration.moduleName.identifiers
.map!(a => a.text).join("."), '"');
il.visit(mod);
stdout.flush;
}
}
private final class ImportLister: ASTVisitor
{
alias visit = ASTVisitor.visit;
size_t mixinDepth;
override void visit(const(Module) mod)
{
mixinDepth = 0;
mod.accept(this);
}
override void visit(const ConditionalDeclaration decl)
{
const VersionCondition ver = decl.compileCondition.versionCondition;

View File

@ -25,6 +25,7 @@ void detectMainFun(const(Module) mod)
MainFunctionDetector mfd = construct!(MainFunctionDetector);
mfd.visit(mod);
write(mfd.hasMain);
stdout.flush;
}
private final class MainFunctionDetector: ASTVisitor

View File

@ -24,6 +24,7 @@ void listSymbols(const(Module) mod, AstErrors errors, bool ddeep = true)
SL sl = construct!(SL);
sl.visit(mod);
sl.serialize.writeln;
stdout.flush;
}
private:

View File

@ -26,6 +26,7 @@ void getTodos(string[] files)
}
stream.put(">end");
writeln(stream.data);
stdout.flush;
}
private void analyze(const(Token) token, string fname)