mirror of https://gitlab.com/basile.b/dexed.git
dastworx, remove usage of globals
This commit is contained in:
parent
28ac7bbbef
commit
7d0f3212c1
|
@ -41,7 +41,6 @@ object CurrentProject: TCENativeProject
|
||||||
'src/imports.d'
|
'src/imports.d'
|
||||||
'src/mainfun.d'
|
'src/mainfun.d'
|
||||||
'src/common.d'
|
'src/common.d'
|
||||||
'src/runnableflags.d'
|
|
||||||
)
|
)
|
||||||
ConfigurationIndex = 1
|
ConfigurationIndex = 1
|
||||||
end
|
end
|
||||||
|
|
|
@ -348,7 +348,7 @@ T parseAndVisit(T : ASTVisitor)(const(char)[] source)
|
||||||
LexerConfig config = LexerConfig("", StringBehavior.source, WhitespaceBehavior.skip);
|
LexerConfig config = LexerConfig("", StringBehavior.source, WhitespaceBehavior.skip);
|
||||||
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
||||||
const(Token)[] tokens = getTokensForParser(cast(ubyte[]) source, config, &cache);
|
const(Token)[] tokens = getTokensForParser(cast(ubyte[]) source, config, &cache);
|
||||||
Module mod = parseModule(tokens, "", &allocator, &handleErrors);
|
Module mod = parseModule(tokens, "", &allocator, &ignoreErrors);
|
||||||
T result = construct!(T);
|
T result = construct!(T);
|
||||||
result.visit(mod);
|
result.visit(mod);
|
||||||
return result;
|
return result;
|
||||||
|
@ -358,7 +358,7 @@ T parseAndVisit(T : ASTVisitor)(const(char)[] source)
|
||||||
* By default libdparse outputs errors and warnings to the standard streams.
|
* By default libdparse outputs errors and warnings to the standard streams.
|
||||||
* This function prevents that.
|
* This function prevents that.
|
||||||
*/
|
*/
|
||||||
void handleErrors(string fname, size_t line, size_t col, string message,
|
void ignoreErrors(string fname, size_t line, size_t col, string message,
|
||||||
bool err)
|
bool err)
|
||||||
{
|
{
|
||||||
// dont pollute output
|
// dont pollute output
|
||||||
|
|
|
@ -53,7 +53,7 @@ void listFilesImports(string[] files)
|
||||||
{
|
{
|
||||||
ubyte[] source = cast(ubyte[]) std.file.read(fname);
|
ubyte[] source = cast(ubyte[]) std.file.read(fname);
|
||||||
Module mod = parseModule(getTokensForParser(source, config, &cache),
|
Module mod = parseModule(getTokensForParser(source, config, &cache),
|
||||||
fname, &allocator, &handleErrors);
|
fname, &allocator, &ignoreErrors);
|
||||||
writeln('"', mod.moduleDeclaration.moduleName.identifiers
|
writeln('"', mod.moduleDeclaration.moduleName.identifiers
|
||||||
.map!(a => a.text).join("."), '"');
|
.map!(a => a.text).join("."), '"');
|
||||||
il.visit(mod);
|
il.visit(mod);
|
||||||
|
|
|
@ -9,20 +9,14 @@ import
|
||||||
import
|
import
|
||||||
dparse.lexer, dparse.parser, dparse.ast, dparse.rollback_allocator;
|
dparse.lexer, dparse.parser, dparse.ast, dparse.rollback_allocator;
|
||||||
import
|
import
|
||||||
common, todos, symlist, imports, mainfun, runnableflags;
|
common, todos, symlist, imports, mainfun;
|
||||||
|
|
||||||
|
|
||||||
private __gshared bool storeAstErrors = void, deepSymList;
|
private __gshared bool deepSymList;
|
||||||
private __gshared const(Token)[] tokens;
|
|
||||||
private __gshared Module module_ = void;
|
|
||||||
private __gshared static Appender!(ubyte[]) source;
|
private __gshared static Appender!(ubyte[]) source;
|
||||||
private __gshared RollbackAllocator allocator;
|
|
||||||
private __gshared LexerConfig config;
|
|
||||||
private __gshared StringCache* cache;
|
|
||||||
private __gshared static Appender!(AstErrors) errors;
|
private __gshared static Appender!(AstErrors) errors;
|
||||||
private __gshared string[] files;
|
private __gshared string[] files;
|
||||||
|
|
||||||
|
|
||||||
static this()
|
static this()
|
||||||
{
|
{
|
||||||
GC.disable;
|
GC.disable;
|
||||||
|
@ -35,8 +29,6 @@ void main(string[] args)
|
||||||
version(devel)
|
version(devel)
|
||||||
{
|
{
|
||||||
mixin(logCall);
|
mixin(logCall);
|
||||||
config = LexerConfig("", StringBehavior.source, WhitespaceBehavior.skip);
|
|
||||||
cache = construct!(StringCache)(StringCache.defaultBucketCount);
|
|
||||||
File f = File(__FILE__, "r");
|
File f = File(__FILE__, "r");
|
||||||
foreach(ref buffer; f.byChunk(4096))
|
foreach(ref buffer; f.byChunk(4096))
|
||||||
source.put(buffer);
|
source.put(buffer);
|
||||||
|
@ -53,24 +45,17 @@ void main(string[] args)
|
||||||
files = args[1].splitter(pathSeparator).array;
|
files = args[1].splitter(pathSeparator).array;
|
||||||
version(devel) writeln(files);
|
version(devel) writeln(files);
|
||||||
}
|
}
|
||||||
// when files are passed, the global cache & config cant be used
|
|
||||||
else
|
|
||||||
{
|
|
||||||
config = LexerConfig("", StringBehavior.source, WhitespaceBehavior.skip);
|
|
||||||
cache = construct!(StringCache)(StringCache.defaultBucketCount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// options for the worxs
|
// options for the work
|
||||||
getopt(args, std.getopt.config.passThrough,
|
getopt(args, std.getopt.config.passThrough,
|
||||||
"d", &deepSymList
|
"d", &deepSymList
|
||||||
);
|
);
|
||||||
|
|
||||||
// launch a worx directly
|
// launch directly a work
|
||||||
getopt(args, std.getopt.config.passThrough,
|
getopt(args, std.getopt.config.passThrough,
|
||||||
"i", &handleImportsOption,
|
"i", &handleImportsOption,
|
||||||
"m", &handleMainfunOption,
|
"m", &handleMainfunOption,
|
||||||
"r", &handleRunnableFlags,
|
|
||||||
"s", &handleSymListOption,
|
"s", &handleSymListOption,
|
||||||
"t", &handleTodosOption,
|
"t", &handleTodosOption,
|
||||||
);
|
);
|
||||||
|
@ -81,10 +66,15 @@ void main(string[] args)
|
||||||
void handleSymListOption()
|
void handleSymListOption()
|
||||||
{
|
{
|
||||||
mixin(logCall);
|
mixin(logCall);
|
||||||
storeAstErrors = true;
|
|
||||||
lex!false;
|
RollbackAllocator alloc;
|
||||||
parseTokens;
|
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
||||||
listSymbols(module_, errors.data, deepSymList);
|
LexerConfig config = LexerConfig("", StringBehavior.source);
|
||||||
|
|
||||||
|
source.data
|
||||||
|
.getTokensForParser(config, &cache)
|
||||||
|
.parseModule("", &alloc, &handleErrors)
|
||||||
|
.listSymbols(errors.data, deepSymList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles the "-t" option: create the list of todo comments in the output
|
/// Handles the "-t" option: create the list of todo comments in the output
|
||||||
|
@ -94,14 +84,6 @@ void handleTodosOption()
|
||||||
getTodos(files);
|
getTodos(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles the "-r" option:
|
|
||||||
void handleRunnableFlags()
|
|
||||||
{
|
|
||||||
mixin(logCall);
|
|
||||||
lex!true;
|
|
||||||
getRunnableFlags(tokens);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Handles the "-i" option: create the import list in the output
|
/// Handles the "-i" option: create the import list in the output
|
||||||
void handleImportsOption()
|
void handleImportsOption()
|
||||||
{
|
{
|
||||||
|
@ -112,10 +94,14 @@ void handleImportsOption()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
storeAstErrors = false;
|
RollbackAllocator alloc;
|
||||||
lex!false;
|
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
||||||
parseTokens;
|
LexerConfig config = LexerConfig("", StringBehavior.source);
|
||||||
listImports(module_);
|
|
||||||
|
source.data
|
||||||
|
.getTokensForParser(config, &cache)
|
||||||
|
.parseModule("", &alloc, &ignoreErrors)
|
||||||
|
.listImports();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,31 +109,21 @@ void handleImportsOption()
|
||||||
void handleMainfunOption()
|
void handleMainfunOption()
|
||||||
{
|
{
|
||||||
mixin(logCall);
|
mixin(logCall);
|
||||||
storeAstErrors = false;
|
|
||||||
lex!false;
|
RollbackAllocator alloc;
|
||||||
parseTokens;
|
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
||||||
detectMainFun(module_);
|
LexerConfig config = LexerConfig("", StringBehavior.source);
|
||||||
|
|
||||||
|
source.data
|
||||||
|
.getTokensForParser(config, &cache)
|
||||||
|
.parseModule("", &alloc, &ignoreErrors)
|
||||||
|
.detectMainFun();
|
||||||
}
|
}
|
||||||
|
|
||||||
private 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);
|
||||||
errors ~= construct!(AstError)(cast(ErrorType) err, message, line, col);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void lex(bool keepComments = false)()
|
|
||||||
{
|
|
||||||
static if (keepComments)
|
|
||||||
tokens = DLexer(source.data, config, cache).array;
|
|
||||||
else
|
|
||||||
tokens = getTokensForParser(source.data, config, cache);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void parseTokens()
|
|
||||||
{
|
|
||||||
mixin(logCall);
|
|
||||||
if (!module_)
|
|
||||||
module_ = parseModule(tokens, "", &allocator, &handleErrors);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
version(devel)
|
version(devel)
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
module runnableflags;
|
|
||||||
|
|
||||||
import
|
|
||||||
std.stdio;
|
|
||||||
import
|
|
||||||
dparse.lexer;
|
|
||||||
import
|
|
||||||
common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the compiler switch defined in the comments located before a
|
|
||||||
* ModuleDeclaration and that are passed to the compiler when a runnable is
|
|
||||||
* launched.
|
|
||||||
*
|
|
||||||
* each line of the output contains an option.
|
|
||||||
*/
|
|
||||||
void getRunnableFlags(const(Token)[] tokens)
|
|
||||||
{
|
|
||||||
mixin(logCall);
|
|
||||||
}
|
|
|
@ -15,10 +15,10 @@ private __gshared bool deep = void;
|
||||||
/**
|
/**
|
||||||
* Serializes the symbols in the standard output
|
* Serializes the symbols in the standard output
|
||||||
*/
|
*/
|
||||||
void listSymbols(const(Module) mod, AstErrors errors, bool ddeep = true)
|
void listSymbols(const(Module) mod, AstErrors errors, bool deep = true)
|
||||||
{
|
{
|
||||||
mixin(logCall);
|
mixin(logCall);
|
||||||
symlist.deep = ddeep;
|
symlist.deep = deep;
|
||||||
alias SL = SymbolListBuilder!(ListFmt.Pas);
|
alias SL = SymbolListBuilder!(ListFmt.Pas);
|
||||||
SL.addAstErrors(errors);
|
SL.addAstErrors(errors);
|
||||||
SL sl = construct!(SL);
|
SL sl = construct!(SL);
|
||||||
|
|
Loading…
Reference in New Issue