diff --git a/src/dmd/dmodule.d b/src/dmd/dmodule.d index 579e13e3b370..20220ae4b811 100644 --- a/src/dmd/dmodule.d +++ b/src/dmd/dmodule.d @@ -322,6 +322,7 @@ extern (C++) final class Module : Package uint numlines; // number of lines in source file int isDocFile; // if it is a documentation input file, not D source bool isPackageFile; // if it is a package.d + Strings contentImportedFiles; // array of files whose content was imported int needmoduleinfo; /** How many unit tests have been seen so far in this module. Makes it so the diff --git a/src/dmd/expressionsem.d b/src/dmd/expressionsem.d index f1173b547866..3c84d6094671 100644 --- a/src/dmd/expressionsem.d +++ b/src/dmd/expressionsem.d @@ -4275,6 +4275,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor return setError(); } + sc._module.contentImportedFiles.push(name); if (global.params.verbose) fprintf(global.stdmsg, "file %.*s\t(%s)\n", cast(int)se.len, se.string, name); if (global.params.moduleDeps !is null) diff --git a/src/dmd/json.d b/src/dmd/json.d index 8a1014b43ffe..bd005526ef7a 100644 --- a/src/dmd/json.d +++ b/src/dmd/json.d @@ -793,6 +793,35 @@ public: jsonProperties(d); objectEnd(); } + + private void generateSemantics() + { + objectStart(); + property("kind", "semantics"); + propertyStart("modules"); + arrayStart(); + foreach (m; Module.amodules) + { + objectStart(); + if(m.md) + property("name", m.md.toChars()); + property("file", m.srcfile.toChars()); + propertyBool("isRoot", m.isRoot()); + if(m.contentImportedFiles.dim > 0) + { + propertyStart("contentImports"); + arrayStart(); + foreach (file; m.contentImportedFiles) + { + value(file); + } + arrayEnd(); + } + objectEnd(); + } + arrayEnd(); + objectEnd(); + } } extern (C++) void json_generate(OutBuffer* buf, Modules* modules) @@ -806,6 +835,7 @@ extern (C++) void json_generate(OutBuffer* buf, Modules* modules) fprintf(global.stdmsg, "json gen %s\n", m.toChars()); m.accept(json); } + json.generateSemantics(); json.arrayEnd(); json.removeComma(); } diff --git a/src/dmd/module.h b/src/dmd/module.h index 7a40308b8b2d..54f85e7aefdf 100644 --- a/src/dmd/module.h +++ b/src/dmd/module.h @@ -85,6 +85,7 @@ class Module : public Package unsigned numlines; // number of lines in source file int isDocFile; // if it is a documentation input file, not D source bool isPackageFile; // if it is a package.d + Strings contentImportedFiles; // array of files whose content was imported int needmoduleinfo; /** How many unit tests have been seen so far in this module. Makes it so the diff --git a/test/compilable/extra-files/json.out b/test/compilable/extra-files/gen_json_out.d similarity index 94% rename from test/compilable/extra-files/json.out rename to test/compilable/extra-files/gen_json_out.d index fdcb60c5187f..630fa4e737ab 100644 --- a/test/compilable/extra-files/json.out +++ b/test/compilable/extra-files/gen_json_out.d @@ -1,4 +1,8 @@ -[ +import std.stdio : write; +void main() +{ + write( +`[ { "name" : "json", "kind" : "module", @@ -926,5 +930,51 @@ "deco" : "YZi" } ] + }, + { + "kind" : "semantics", + "modules" : [ + { + "name" : "json", + "file" : "compilable/json.d", + "isRoot" : true + }, + { + "name" : "imports.jsonimport1", + "file" : "compilable/imports/jsonimport1.d", + "isRoot" : false + }, + { + "name" : "object", + "file" : "../../druntime/import/object.d", + "isRoot" : false + },`); + version(OSX) version(X86_64) + { + write(` + { + "name" : "core.attribute", + "file" : "../../druntime/import/core/attribute.d", + "isRoot" : false + },`); + } + write(` + { + "name" : "imports.jsonimport2", + "file" : "compilable/imports/jsonimport2.d", + "isRoot" : false + }, + { + "name" : "imports.jsonimport3", + "file" : "compilable/imports/jsonimport3.d", + "isRoot" : false + }, + { + "name" : "imports.jsonimport4", + "file" : "compilable/imports/jsonimport4.d", + "isRoot" : false + } + ] } -] \ No newline at end of file +]`); +} diff --git a/test/compilable/extra-files/json-postscript.sh b/test/compilable/extra-files/json-postscript.sh index 5fa936d5cf4c..c88631206f3e 100755 --- a/test/compilable/extra-files/json-postscript.sh +++ b/test/compilable/extra-files/json-postscript.sh @@ -1,5 +1,15 @@ #!/usr/bin/env bash + +echo GENERATING compilable/extra-files/json.out +set +x +${DMD} -m${MODEL} -run compilable/extra-files/gen_json_out.d > compilable/extra-files/json.out +if [ $? -ne 0 ]; then + cat compilable/extra-files/json.out + exit 1; +fi + + grep -v "\"file\" : " ${RESULTS_DIR}/compilable/json.out | grep -v "\"offset\" : " | grep -v "\"deco\" : " > ${RESULTS_DIR}/compilable/json.out.2 grep -v "\"file\" : " compilable/extra-files/json.out | grep -v "\"offset\" : " | grep -v "\"deco\" : " > ${RESULTS_DIR}/compilable/json.out.3 @@ -8,4 +18,5 @@ if [ $? -ne 0 ]; then exit 1; fi +rm compilable/extra-files/json.out rm ${RESULTS_DIR}/compilable/json.out{.2,.3}