mirror of https://gitlab.com/basile.b/dexed.git
dastworx, add support for listing imports of several files
+ always include the module name on the first line
This commit is contained in:
parent
4ea80a8ac4
commit
31d2f6d724
|
@ -1,18 +1,19 @@
|
||||||
module imports;
|
module imports;
|
||||||
|
|
||||||
import
|
import
|
||||||
std.stdio, std.algorithm, std.array;
|
std.stdio, std.algorithm, std.array, std.file;
|
||||||
import
|
import
|
||||||
iz.memory;
|
iz.memory;
|
||||||
import
|
import
|
||||||
dparse.lexer, dparse.ast, dparse.parser;
|
dparse.lexer, dparse.ast, dparse.parser, dparse.rollback_allocator;
|
||||||
import
|
import
|
||||||
common;
|
common;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists the modules imported b y a module
|
* Lists the modules imported by a module
|
||||||
*
|
*
|
||||||
* Each import is written in a new line. Import detection is not accurate,
|
* On the first line writes the module name between double quotes then
|
||||||
|
* each import is written in a new line. Import detection is not accurate,
|
||||||
* the imports injected by a mixin template or by a string variable are not detected,
|
* the imports injected by a mixin template or by a string variable are not detected,
|
||||||
* the imports deactivated by a static condition neither.
|
* the imports deactivated by a static condition neither.
|
||||||
*
|
*
|
||||||
|
@ -27,9 +28,39 @@ in
|
||||||
body
|
body
|
||||||
{
|
{
|
||||||
mixin(logCall);
|
mixin(logCall);
|
||||||
|
writeln('"', mod.moduleDeclaration.moduleName.identifiers
|
||||||
|
.map!(a => a.text).join("."), '"');
|
||||||
construct!(ImportLister).visit(mod);
|
construct!(ImportLister).visit(mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists the modules imported by several modules
|
||||||
|
*
|
||||||
|
* The output consists of several consecutive lists, as formated for
|
||||||
|
* listImports.
|
||||||
|
*
|
||||||
|
* The results are used by to detect which are the static libraries used by a
|
||||||
|
* runnable module.
|
||||||
|
*/
|
||||||
|
void listFilesImports(string[] files)
|
||||||
|
{
|
||||||
|
mixin(logCall);
|
||||||
|
RollbackAllocator allocator;
|
||||||
|
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
||||||
|
LexerConfig config = LexerConfig("", StringBehavior.source);
|
||||||
|
ImportLister il = construct!(ImportLister);
|
||||||
|
foreach(fname; files)
|
||||||
|
{
|
||||||
|
ubyte[] source = cast(ubyte[]) std.file.read(fname);
|
||||||
|
Module mod = parseModule(getTokensForParser(source, config, &cache),
|
||||||
|
fname, &allocator);
|
||||||
|
writeln('"', mod.moduleDeclaration.moduleName.identifiers
|
||||||
|
.map!(a => a.text).join("."), '"');
|
||||||
|
il.visit(mod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private final class ImportLister: ASTVisitor
|
private final class ImportLister: ASTVisitor
|
||||||
{
|
{
|
||||||
alias visit = ASTVisitor.visit;
|
alias visit = ASTVisitor.visit;
|
||||||
|
|
|
@ -97,10 +97,17 @@ void handleRunnableFlags()
|
||||||
void handleImportsOption()
|
void handleImportsOption()
|
||||||
{
|
{
|
||||||
mixin(logCall);
|
mixin(logCall);
|
||||||
storeAstErrors = false;
|
if (files.length)
|
||||||
lex!false;
|
{
|
||||||
parseTokens;
|
listFilesImports(files);
|
||||||
listImports(module_);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
storeAstErrors = false;
|
||||||
|
lex!false;
|
||||||
|
parseTokens;
|
||||||
|
listImports(module_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles the "-m" option: writes if a main() is present in the module
|
/// Handles the "-m" option: writes if a main() is present in the module
|
||||||
|
|
Loading…
Reference in New Issue