mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
JSON output: Do not output module ctors/dtors as functions
In order for clients code to recognize [shared] static ctor, it must currently find a name matching a specific pattern. This exposes the internal of the compilers to documentation generators, and even forces them to build based on it. Using a specific "kind" type instead allows to simplify this and gives us the chance to change the internal name.
This commit is contained in:
parent
aac22b78ba
commit
02f3bc3252
4 changed files with 199 additions and 6 deletions
9
changelog/ddoc-shared-static-ctor.dd
Normal file
9
changelog/ddoc-shared-static-ctor.dd
Normal file
|
@ -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`.
|
|
@ -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));
|
||||
|
|
|
@ -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"
|
||||
},
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue