dastworks, fix several issues

+ spped up compilation, disable inlining
+ improve todolist & symlist streams size
+ deep option of the symlist was broken
This commit is contained in:
Basile Burg 2016-07-03 21:27:41 +02:00
parent 693c1324f8
commit 94eddd0ca8
5 changed files with 53 additions and 55 deletions

View File

@ -20,7 +20,6 @@ object CurrentProject: TCENativeProject
end
item
name = 'release'
outputOptions.inlining = True
outputOptions.boundsCheck = offAlways
outputOptions.optimizations = True
outputOptions.release = True

View File

@ -50,9 +50,13 @@ q{
else version(unittest) log();
};
/**
* Contains all the D version identifiers that are not valid
* for this operating system.
*/
immutable string[] badVersions;
private enum predefinedVersions = [
private static immutable predefinedVersions = [
"AArch64",
"AIX",
"all",
@ -183,7 +187,7 @@ string patchPascalString(string value)
bool skip;
foreach (immutable i; 0..value.length)
{
char c = value[i];
const char c = value[i];
if (c > 0x7F)
{
app ~= value[i];

View File

@ -12,7 +12,7 @@ import
common, todos, symlist, imports, mainfun, runnableflags;
private __gshared bool storeAstErrors = void, deepSymList = true;
private __gshared bool storeAstErrors = void, deepSymList;
private __gshared const(Token)[] tokens;
private __gshared Module module_ = void;
private __gshared static Appender!(ubyte[]) source;
@ -36,13 +36,13 @@ void main(string[] args)
{
mixin(logCall);
File f = File(__FILE__, "r");
foreach(buffer; f.byChunk(4096))
foreach(ref buffer; f.byChunk(4096))
source.put(buffer);
f.close;
}
else
{
foreach(buffer; stdin.byChunk(4096))
foreach(ref buffer; stdin.byChunk(4096))
source.put(buffer);
}
@ -68,22 +68,24 @@ void main(string[] args)
);
}
/// Handles the "-s" option: create the symbol list in the output
void handleSymListOption()
{
mixin(logCall);
bool deep;
storeAstErrors = true;
lex!false;
parseTokens;
listSymbols(module_, errors.data, deepSymList);
}
/// Handles the "-t" option: create the list of todo comments in the output
void handleTodosOption()
{
mixin(logCall);
getTodos(files);
}
/// Handles the "-r" option:
void handleRunnableFlags()
{
mixin(logCall);
@ -91,6 +93,7 @@ void handleRunnableFlags()
getRunnableFlags(tokens);
}
/// Handles the "-i" option: create the import list in the output
void handleImportsOption()
{
mixin(logCall);
@ -100,6 +103,7 @@ void handleImportsOption()
listImports(module_);
}
/// Handles the "-m" option: writes if a main() is present in the module
void handleMainfunOption()
{
mixin(logCall);
@ -109,24 +113,21 @@ void handleMainfunOption()
detectMainFun(module_);
}
void handleErrors(string fname, size_t line, size_t col, string message, bool err)
private void handleErrors(string fname, size_t line, size_t col, string message, bool err)
{
if (storeAstErrors)
errors ~= construct!(AstError)(cast(ErrorType) err, message, line, col);
}
void lex(bool keepComments = false)()
private void lex(bool keepComments = false)()
{
static if (keepComments)
{
DLexer dlx = DLexer(source.data, config, cache);
tokens = dlx.array;
}
tokens = DLexer(source.data, config, cache).array;
else
tokens = getTokensForParser(source.data, config, cache);
}
void parseTokens()
private void parseTokens()
{
mixin(logCall);
if (!module_)

View File

@ -15,10 +15,10 @@ private __gshared bool deep = void;
/**
* Serializes the symbols in the standard output
*/
void listSymbols(const(Module) mod, AstErrors errors, bool deep = true)
void listSymbols(const(Module) mod, AstErrors errors, bool ddeep = true)
{
mixin(logCall);
symlist.deep = deep;
symlist.deep = ddeep;
alias SL = SymbolListBuilder!(ListFmt.Pas);
SL.addAstErrors(errors);
SL sl = construct!(SL);
@ -26,6 +26,8 @@ void listSymbols(const(Module) mod, AstErrors errors, bool deep = true)
sl.serialize.writeln;
}
private:
enum ListFmt
{
Pas,
@ -81,7 +83,7 @@ class SymbolListBuilder(ListFmt Fmt): ASTVisitor
{
static if (Fmt == ListFmt.Pas)
{
pasStream.put("object TSymbolList\rsymbols = <");
pasStream.put("object TSymbolList\rsymbols=<");
}
else
{
@ -100,10 +102,10 @@ class SymbolListBuilder(ListFmt Fmt): ASTVisitor
static if (Fmt == ListFmt.Pas)
{
pasStream.put("\ritem\r");
pasStream.put(format("line = %d\r", error.line));
pasStream.put(format("col = %d\r", error.column));
pasStream.put(format("name = '%s'\r", patchPascalString(error.message)));
pasStream.put(format("symType = %s\r", type));
pasStream.put(format("line=%d\r", error.line));
pasStream.put(format("col=%d\r", error.column));
pasStream.put(format("name='%s'\r", patchPascalString(error.message)));
pasStream.put(format("symType=%s\r", type));
pasStream.put("end");
}
else
@ -122,7 +124,7 @@ class SymbolListBuilder(ListFmt Fmt): ASTVisitor
{
static if (Fmt == ListFmt.Pas)
{
pasStream.put(">\rend\r\n");
pasStream.put(">\rend");
return pasStream.data;
}
else
@ -143,10 +145,10 @@ class SymbolListBuilder(ListFmt Fmt): ASTVisitor
static if (Fmt == ListFmt.Pas)
{
pasStream.put("\ritem\r");
pasStream.put(format("line = %d\r", dt.name.line));
pasStream.put(format("col = %d\r", dt.name.column));
pasStream.put(format("name = '%s'\r", dt.name.text));
pasStream.put("symType = " ~ symbolTypeStrings[st] ~ "\r");
pasStream.put(format("line=%d\r", dt.name.line));
pasStream.put(format("col=%d\r", dt.name.column));
pasStream.put(format("name='%s'\r", dt.name.text));
pasStream.put("symType=" ~ symbolTypeStrings[st] ~ "\r");
static if (dig) if (deep)
{
pasStream.put("subs = <");
@ -165,7 +167,7 @@ class SymbolListBuilder(ListFmt Fmt): ASTVisitor
static if (dig) if (deep)
{
JSONValue subs = parseJSON("[]");
JSONValue* old = jarray;
const JSONValue* old = jarray;
jarray = &subs;
dt.accept(this);
item["items"] = subs;
@ -182,10 +184,10 @@ class SymbolListBuilder(ListFmt Fmt): ASTVisitor
static if (Fmt == ListFmt.Pas)
{
pasStream.put("\ritem\r");
pasStream.put(format("line = %d\r", line));
pasStream.put(format("col = %d\r", col));
pasStream.put(format("name = '%s'\r", name));
pasStream.put("symType = " ~ symbolTypeStrings[st] ~ "\r");
pasStream.put(format("line=%d\r", line));
pasStream.put(format("col=%d\r", col));
pasStream.put(format("name='%s'\r", name));
pasStream.put("symType=" ~ symbolTypeStrings[st] ~ "\r");
static if (dig)
{
pasStream.put("subs = <");
@ -204,7 +206,7 @@ class SymbolListBuilder(ListFmt Fmt): ASTVisitor
static if (dig)
{
JSONValue subs = parseJSON("[]");
JSONValue* old = jarray;
const JSONValue* old = jarray;
jarray = &subs;
dt.accept(this);
item["items"] = subs;

View File

@ -2,7 +2,7 @@ module todos;
import
std.stdio, std.string, std.algorithm, std.array, std.conv, std.traits,
std.ascii, std.range;
std.ascii, std.range, std.file;
import
dparse.lexer;
import
@ -10,27 +10,21 @@ import
private __gshared Appender!string stream;
//TODO: sdfsfd
void getTodos(string[] files)
{
mixin(logCall);
//stream.reserve(2^^16);
stream.put("object TTodoItems\r items = <");
stream.reserve(32 + 256 * files.length);
stream.put("object TTodoItems\ritems=<");
foreach(fname; files)
{
ubyte[] source;
StringCache cache = StringCache(StringCache.defaultBucketCount);
LexerConfig config = LexerConfig(fname, StringBehavior.source);
File f = File(fname, "r");
foreach (buffer; f.byChunk(4096))
source ~= buffer;
f.close;
foreach(token; DLexer(source, config, &cache).array
ubyte[] source = cast(ubyte[]) std.file.read(fname);
foreach(ref token; DLexer(source, config, &cache).array
.filter!((a) => a.type == tok!"comment"))
analyze(token, fname);
}
stream.put(">\rend\r\n");
stream.put(">end");
writeln(stream.data);
}
@ -101,7 +95,7 @@ private void analyze(const(Token) token, string fname)
fields.popFront;
if ((front == '-' || fields.empty) && identifier.length > 2)
{
string fieldContent = identifier[2..$].strip;
const string fieldContent = identifier[2..$].strip;
switch(identifier[0..2].toUpper)
{
default: break;
@ -118,19 +112,17 @@ private void analyze(const(Token) token, string fname)
if (text.length > 1 && text[$-2..$].among("*/", "+/"))
text.length -=2;
stream.put("\r item\r");
stream.put(format("filename = '%s'\r", fname));
stream.put(format("line = '%s'\r", token.line));
stream.put(format("text = '%s'\r", text));
stream.put("\ritem\r");
stream.put(format("filename='%s'\r", fname));
stream.put(format("line='%s'\r", token.line));
stream.put(format("text='%s'\r", text));
if (c.length)
stream.put(format("category = '%s'\r", c));
stream.put(format("category='%s'\r", c));
if (a.length)
stream.put(format("assignee = '%s'\r", a));
stream.put(format("assignee='%s'\r", a));
if (p.length)
stream.put(format("priority = '%s'\r", p));
stream.put(format("priority='%s'\r", p));
if (s.length)
stream.put(format("status = '%s'\r", s));
stream.put(format("status='%s'\r", s));
stream.put("end");
}