diff --git a/changelog/ddoc-shared-static-ctor.dd b/changelog/ddoc-shared-static-ctor.dd new file mode 100644 index 0000000000..de4f4fd552 --- /dev/null +++ b/changelog/ddoc-shared-static-ctor.dd @@ -0,0 +1,9 @@ +DMD's JSON output now have distinct types for [shared] module constructor/destructor + +Previously, module constructors and destructors (shared or not) would be output as +functions, and the only way for documentation generators to recognize them was +to search for the pattern that was used for their naming. +This means that external tools would need to depend on internal compiler details +for generating documentation. +From this release, 4 new values have been introduced for `kind`: +`shared static constructor`, `shared static destructor`, `static constructor`, `static destructor`. diff --git a/src/dmd/json.d b/src/dmd/json.d index 18c9247d4d..a00f3c57cf 100644 --- a/src/dmd/json.d +++ b/src/dmd/json.d @@ -418,7 +418,18 @@ public: if (!s.isTemplateDeclaration()) // TemplateDeclaration::kind() acts weird sometimes { property("name", s.toString()); - property("kind", s.kind.toDString); + if (s.isStaticCtorDeclaration()) + { + property("kind", s.isSharedStaticCtorDeclaration() + ? "shared static constructor" : "static constructor"); + } + else if (s.isStaticDtorDeclaration()) + { + property("kind", s.isSharedStaticDtorDeclaration() + ? "shared static destructor" : "static destructor"); + } + else + property("kind", s.kind.toDString); } // TODO: How about package(names)? property("protection", protectionToString(s.prot().kind)); diff --git a/test/compilable/extra-files/json.out b/test/compilable/extra-files/json.out index 247ce33fa6..2fdafa3667 100644 --- a/test/compilable/extra-files/json.out +++ b/test/compilable/extra-files/json.out @@ -3,12 +3,25 @@ "file": "VALUE_REMOVED_FOR_TEST", "kind": "module", "members": [ + { + "char": 1, + "deco": "VALUE_REMOVED_FOR_TEST", + "endchar": 23, + "endline": 12, + "kind": "shared static constructor", + "line": 12, + "name": "_sharedStaticCtor_L12_C1", + "protection": "public", + "storageClass": [ + "static" + ] + }, { "char": 1, "deco": "VALUE_REMOVED_FOR_TEST", "endchar": 16, "endline": 13, - "kind": "function", + "kind": "static constructor", "line": 13, "name": "_staticCtor_L13_C1", "protection": "public", @@ -16,12 +29,25 @@ "static" ] }, + { + "char": 1, + "deco": "VALUE_REMOVED_FOR_TEST", + "endchar": 24, + "endline": 14, + "kind": "shared static destructor", + "line": 14, + "name": "_sharedStaticDtor_L14_C1", + "protection": "public", + "storageClass": [ + "static" + ] + }, { "char": 1, "deco": "VALUE_REMOVED_FOR_TEST", "endchar": 17, "endline": 15, - "kind": "function", + "kind": "static destructor", "line": 15, "name": "_staticDtor_L15_C1", "protection": "public", @@ -29,6 +55,134 @@ "static" ] }, + { + "char": 1, + "kind": "template", + "line": 17, + "members": [ + { + "char": 5, + "endchar": 27, + "endline": 19, + "kind": "shared static constructor", + "line": 19, + "name": "_sharedStaticCtor_L19_C5", + "storageClass": [ + "static" + ] + }, + { + "char": 5, + "endchar": 20, + "endline": 20, + "kind": "static constructor", + "line": 20, + "name": "_staticCtor_L20_C5", + "storageClass": [ + "static" + ] + }, + { + "char": 5, + "endchar": 28, + "endline": 21, + "kind": "shared static destructor", + "line": 21, + "name": "_sharedStaticDtor_L21_C5", + "storageClass": [ + "static" + ] + }, + { + "char": 5, + "endchar": 21, + "endline": 22, + "kind": "static destructor", + "line": 22, + "name": "_staticDtor_L22_C5", + "storageClass": [ + "static" + ] + } + ], + "name": "X", + "parameters": [ + { + "kind": "type", + "name": "T" + } + ], + "protection": "public" + }, + { + "char": 1, + "kind": "alias", + "line": 25, + "name": "SSCDX", + "originalType": "X!int", + "protection": "public" + }, + { + "char": 1, + "kind": "class", + "line": 27, + "members": [ + { + "char": 5, + "deco": "VALUE_REMOVED_FOR_TEST", + "endchar": 27, + "endline": 29, + "kind": "shared static constructor", + "line": 29, + "name": "_sharedStaticCtor_L29_C5", + "protection": "public", + "storageClass": [ + "static" + ] + }, + { + "char": 5, + "deco": "VALUE_REMOVED_FOR_TEST", + "endchar": 20, + "endline": 30, + "kind": "static constructor", + "line": 30, + "name": "_staticCtor_L30_C5", + "protection": "public", + "storageClass": [ + "static" + ] + }, + { + "char": 5, + "deco": "VALUE_REMOVED_FOR_TEST", + "endchar": 28, + "endline": 31, + "kind": "shared static destructor", + "line": 31, + "name": "_sharedStaticDtor_L31_C5", + "protection": "public", + "storageClass": [ + "static" + ] + }, + { + "char": 5, + "deco": "VALUE_REMOVED_FOR_TEST", + "endchar": 21, + "endline": 32, + "kind": "static destructor", + "line": 32, + "name": "_staticDtor_L32_C5", + "protection": "public", + "storageClass": [ + "static" + ] + } + ], + "name": "SSCDClass", + "protection": "public" + }, { "char": 11, "deco": "VALUE_REMOVED_FOR_TEST", @@ -943,7 +1097,7 @@ "char": 15, "deco": "VALUE_REMOVED_FOR_TEST", "kind": "function", - "line": 194, + "line": 193, "name": "flinkageD", "protection": "public" }, diff --git a/test/compilable/json.d b/test/compilable/json.d index ce0fb4ea76..9884148138 100644 --- a/test/compilable/json.d +++ b/test/compilable/json.d @@ -9,11 +9,30 @@ module json; - +shared static this() {} static this() {} - +shared static ~this() {} static ~this() {} +template X(T) +{ + shared static this() {} + static this() {} + shared static ~this() {} + static ~this() {} +} + +alias SSCDX = X!int; + +class SSCDClass +{ + shared static this() {} + static this() {} + shared static ~this() {} + static ~this() {} +} + +#line 17 alias int myInt; myInt x; // https://issues.dlang.org/show_bug.cgi?id=3404