[Issue 19800] JSON output does not include scoped imports

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Apr 19 08:43:06 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=19800

RazvanN <razvan.nitu1305 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #4 from RazvanN <razvan.nitu1305 at gmail.com> ---
(In reply to GoaLitiuM from comment #3)
> I'm trying to build a dependency tree of the imported modules for a build
> tool to find out which modules are needed to rebuild after one of the files
> are changed. This works with the -X switch and having the imports outside
> the functions, but are missed when imported in a scope.
> 
> I don't know what the intended output should be but I assumed the import
> would be listed under the members of the main function (in this particular
> case), but they are only listed under the members of the modules if the
> module is imported outside any functions.

The json generator is ran after the parsing phase, so semantic analysis is not
yet done. This means that function bodies have not yet been analyzed, therefore
the json will not include the declarations inside them. This is the expected
behavior.

If you want to have all the imports (recursively) you need to compile with the
-deps option; this will give all the imports recursively, but this may be a bit
verbose because you will also get the standard library dependency tree.

Another way to do this is to write your own tool that uses dmd as a library and
print whatever declarations you are interested in. If its just imports that you
are interested in then this little example program [1] using dmd as a library
will simply print the imports (ImportVisitor2 prints all imports, ImportVisitor
prints only toplevel imports). The bad part is that the imports are not printed
as a json.

I will close this as invalid, as the json generater works as expected.

[1] https://github.com/dlang/dmd/blob/master/src/examples/impvisitor.d#L14

--


More information about the Digitalmars-d-bugs mailing list