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;
|
||||
|
||||
import
|
||||
std.stdio, std.algorithm, std.array;
|
||||
std.stdio, std.algorithm, std.array, std.file;
|
||||
import
|
||||
iz.memory;
|
||||
import
|
||||
dparse.lexer, dparse.ast, dparse.parser;
|
||||
dparse.lexer, dparse.ast, dparse.parser, dparse.rollback_allocator;
|
||||
import
|
||||
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 deactivated by a static condition neither.
|
||||
*
|
||||
|
@ -27,9 +28,39 @@ in
|
|||
body
|
||||
{
|
||||
mixin(logCall);
|
||||
writeln('"', mod.moduleDeclaration.moduleName.identifiers
|
||||
.map!(a => a.text).join("."), '"');
|
||||
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
|
||||
{
|
||||
alias visit = ASTVisitor.visit;
|
||||
|
|
|
@ -97,10 +97,17 @@ void handleRunnableFlags()
|
|||
void handleImportsOption()
|
||||
{
|
||||
mixin(logCall);
|
||||
storeAstErrors = false;
|
||||
lex!false;
|
||||
parseTokens;
|
||||
listImports(module_);
|
||||
if (files.length)
|
||||
{
|
||||
listFilesImports(files);
|
||||
}
|
||||
else
|
||||
{
|
||||
storeAstErrors = false;
|
||||
lex!false;
|
||||
parseTokens;
|
||||
listImports(module_);
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles the "-m" option: writes if a main() is present in the module
|
||||
|
|
Loading…
Reference in New Issue