From 6374a44674b50d1510c98ae8a65452403393d257 Mon Sep 17 00:00:00 2001 From: alandefreitas Date: Wed, 12 Feb 2025 15:39:41 -0300 Subject: [PATCH 1/7] option name is `extract-private` #refactor --- docs/mrdocs.schema.json | 20 +++++++++---------- src/lib/AST/ASTVisitor.cpp | 2 +- src/lib/Lib/ConfigOptions.json | 2 +- .../Finalizers/BaseMembersFinalizer.cpp | 2 +- .../symbol-type/nested-private-template.yml | 2 +- .../golden-tests/metadata/record-access.yml | 2 +- .../golden-tests/metadata/record-data.yml | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/mrdocs.schema.json b/docs/mrdocs.schema.json index 9f406b335..3f8b07e1f 100644 --- a/docs/mrdocs.schema.json +++ b/docs/mrdocs.schema.json @@ -101,6 +101,16 @@ "title": "Extract all symbols", "type": "boolean" }, + "extract-private": { + "default": false, + "description": "Determine whether private class members should be extracted", + "enum": [ + true, + false + ], + "title": "Extraction policy for private class members", + "type": "boolean" + }, "file-patterns": { "default": [ "*.hpp", @@ -270,16 +280,6 @@ "title": "Extraction policy for private base classes", "type": "boolean" }, - "private-members": { - "default": false, - "description": "Determine whether private class members should be extracted", - "enum": [ - true, - false - ], - "title": "Extraction policy for private class members", - "type": "boolean" - }, "recursive": { "default": true, "description": "Recursively include files. When set to true, MrDocs includes files in subdirectories of the input directories. When set to false, MrDocs includes only the files in the input directories.", diff --git a/src/lib/AST/ASTVisitor.cpp b/src/lib/AST/ASTVisitor.cpp index a5d81d236..233008bac 100644 --- a/src/lib/AST/ASTVisitor.cpp +++ b/src/lib/AST/ASTVisitor.cpp @@ -2703,7 +2703,7 @@ bool ASTVisitor:: checkTypeFilters(Decl const* D, AccessSpecifier access) { - if (!config_->privateMembers) + if (!config_->extractPrivate) { // KRYSTIAN FIXME: this doesn't handle direct // dependencies on inaccessible declarations diff --git a/src/lib/Lib/ConfigOptions.json b/src/lib/Lib/ConfigOptions.json index 934d59af5..a87490f0f 100644 --- a/src/lib/Lib/ConfigOptions.json +++ b/src/lib/Lib/ConfigOptions.json @@ -186,7 +186,7 @@ "default": true }, { - "name": "private-members", + "name": "extract-private", "brief": "Extraction policy for private class members", "details": "Determine whether private class members should be extracted", "type": "bool", diff --git a/src/lib/Metadata/Finalizers/BaseMembersFinalizer.cpp b/src/lib/Metadata/Finalizers/BaseMembersFinalizer.cpp index c039d4c67..778f3d51f 100644 --- a/src/lib/Metadata/Finalizers/BaseMembersFinalizer.cpp +++ b/src/lib/Metadata/Finalizers/BaseMembersFinalizer.cpp @@ -46,7 +46,7 @@ inheritBaseMembers( inheritBaseMembers(derivedId, derived.Protected, base.Public); inheritBaseMembers(derivedId, derived.Protected, base.Protected); } - else if (A == AccessKind::Private && corpus_.config->privateMembers) + else if (A == AccessKind::Private && corpus_.config->extractPrivate) { // When a class uses private member access specifier to derive from a // base, all public and protected members of the base class are diff --git a/test-files/golden-tests/filters/symbol-type/nested-private-template.yml b/test-files/golden-tests/filters/symbol-type/nested-private-template.yml index 39ea3e2cb..85d1347f1 100644 --- a/test-files/golden-tests/filters/symbol-type/nested-private-template.yml +++ b/test-files/golden-tests/filters/symbol-type/nested-private-template.yml @@ -1 +1 @@ -private-members: true \ No newline at end of file +extract-private: true \ No newline at end of file diff --git a/test-files/golden-tests/metadata/record-access.yml b/test-files/golden-tests/metadata/record-access.yml index 39ea3e2cb..85d1347f1 100644 --- a/test-files/golden-tests/metadata/record-access.yml +++ b/test-files/golden-tests/metadata/record-access.yml @@ -1 +1 @@ -private-members: true \ No newline at end of file +extract-private: true \ No newline at end of file diff --git a/test-files/golden-tests/metadata/record-data.yml b/test-files/golden-tests/metadata/record-data.yml index 39ea3e2cb..85d1347f1 100644 --- a/test-files/golden-tests/metadata/record-data.yml +++ b/test-files/golden-tests/metadata/record-data.yml @@ -1 +1 @@ -private-members: true \ No newline at end of file +extract-private: true \ No newline at end of file From f7ab2438ed5431a9a682d91d6b87b0fa1ccc5230 Mon Sep 17 00:00:00 2001 From: alandefreitas Date: Wed, 12 Feb 2025 15:43:02 -0300 Subject: [PATCH 2/7] option name is `extract-private-bases` #refactor --- docs/mrdocs.schema.json | 20 ++++++++++---------- src/lib/AST/ASTVisitor.cpp | 4 ++-- src/lib/Lib/ConfigOptions.json | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/mrdocs.schema.json b/docs/mrdocs.schema.json index 3f8b07e1f..84d142a7c 100644 --- a/docs/mrdocs.schema.json +++ b/docs/mrdocs.schema.json @@ -111,6 +111,16 @@ "title": "Extraction policy for private class members", "type": "boolean" }, + "extract-private-bases": { + "default": true, + "description": "Determine whether private base classes should be extracted", + "enum": [ + true, + false + ], + "title": "Extraction policy for private base classes", + "type": "boolean" + }, "file-patterns": { "default": [ "*.hpp", @@ -270,16 +280,6 @@ "title": "Detect and group function overloads", "type": "boolean" }, - "private-bases": { - "default": true, - "description": "Determine whether private base classes should be extracted", - "enum": [ - true, - false - ], - "title": "Extraction policy for private base classes", - "type": "boolean" - }, "recursive": { "default": true, "description": "Recursively include files. When set to true, MrDocs includes files in subdirectories of the input directories. When set to false, MrDocs includes only the files in the input directories.", diff --git a/src/lib/AST/ASTVisitor.cpp b/src/lib/AST/ASTVisitor.cpp index 233008bac..8fb68c256 100644 --- a/src/lib/AST/ASTVisitor.cpp +++ b/src/lib/AST/ASTVisitor.cpp @@ -669,7 +669,7 @@ populate( { AccessSpecifier const access = B.getAccessSpecifier(); - if (!config_->privateBases && + if (!config_->extractPrivateBases && access == AS_private) { continue; @@ -2701,7 +2701,7 @@ checkFilters( bool ASTVisitor:: -checkTypeFilters(Decl const* D, AccessSpecifier access) +checkTypeFilters(Decl const* D, AccessSpecifier const access) { if (!config_->extractPrivate) { diff --git a/src/lib/Lib/ConfigOptions.json b/src/lib/Lib/ConfigOptions.json index a87490f0f..87d1e2fd3 100644 --- a/src/lib/Lib/ConfigOptions.json +++ b/src/lib/Lib/ConfigOptions.json @@ -193,7 +193,7 @@ "default": false }, { - "name": "private-bases", + "name": "extract-private-bases", "brief": "Extraction policy for private base classes", "details": "Determine whether private base classes should be extracted", "type": "bool", From 2aa6af9833d52610eb0f1599aed75e1d9b37e6d4 Mon Sep 17 00:00:00 2001 From: alandefreitas Date: Wed, 12 Feb 2025 15:47:26 -0300 Subject: [PATCH 3/7] `extract-private-bases` default is `false` #improvement --- docs/mrdocs.schema.json | 2 +- src/lib/Lib/ConfigOptions.json | 14 +++++++------- .../inherit-base-members/copy-dependencies.yml | 3 ++- .../config/inherit-base-members/copy.yml | 1 + .../config/inherit-base-members/never.yml | 1 + .../config/inherit-base-members/reference.yml | 1 + .../golden-tests/metadata/record-inheritance.yml | 1 + 7 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 test-files/golden-tests/metadata/record-inheritance.yml diff --git a/docs/mrdocs.schema.json b/docs/mrdocs.schema.json index 84d142a7c..72bf93e85 100644 --- a/docs/mrdocs.schema.json +++ b/docs/mrdocs.schema.json @@ -112,7 +112,7 @@ "type": "boolean" }, "extract-private-bases": { - "default": true, + "default": false, "description": "Determine whether private base classes should be extracted", "enum": [ true, diff --git a/src/lib/Lib/ConfigOptions.json b/src/lib/Lib/ConfigOptions.json index 87d1e2fd3..c80ca73bf 100644 --- a/src/lib/Lib/ConfigOptions.json +++ b/src/lib/Lib/ConfigOptions.json @@ -197,6 +197,13 @@ "brief": "Extraction policy for private base classes", "details": "Determine whether private base classes should be extracted", "type": "bool", + "default": false + }, + { + "name": "anonymous-namespaces", + "brief": "Extraction policy for anonymous namespaces", + "details": "Determine whether symbols in anonymous namespaces should be extracted. When set to `always`, symbols in anonymous namespaces are always extracted. When set to `dependency`, symbols in anonymous namespaces are extracted only if they are referenced by the source code. When set to `never`, symbols in anonymous namespaces are never extracted.", + "type": "bool", "default": true }, { @@ -212,13 +219,6 @@ ], "default": "copy-dependencies" }, - { - "name": "anonymous-namespaces", - "brief": "Extraction policy for anonymous namespaces", - "details": "Determine whether symbols in anonymous namespaces should be extracted. When set to `always`, symbols in anonymous namespaces are always extracted. When set to `dependency`, symbols in anonymous namespaces are extracted only if they are referenced by the source code. When set to `never`, symbols in anonymous namespaces are never extracted.", - "type": "bool", - "default": true - }, { "name": "sort-members", "brief": "Sort the members of a record or namespace", diff --git a/test-files/golden-tests/config/inherit-base-members/copy-dependencies.yml b/test-files/golden-tests/config/inherit-base-members/copy-dependencies.yml index e31d214b0..9d5f26010 100644 --- a/test-files/golden-tests/config/inherit-base-members/copy-dependencies.yml +++ b/test-files/golden-tests/config/inherit-base-members/copy-dependencies.yml @@ -1,4 +1,5 @@ inherit-base-members: copy-dependencies exclude-symbols: - excluded_base -warn-no-paramdoc: false \ No newline at end of file +extract-private-bases: true +warn-no-paramdoc: false diff --git a/test-files/golden-tests/config/inherit-base-members/copy.yml b/test-files/golden-tests/config/inherit-base-members/copy.yml index 7e1ebf462..5a9766d7f 100644 --- a/test-files/golden-tests/config/inherit-base-members/copy.yml +++ b/test-files/golden-tests/config/inherit-base-members/copy.yml @@ -1,4 +1,5 @@ inherit-base-members: copy-all exclude-symbols: - excluded_base +extract-private-bases: true warn-no-paramdoc: false \ No newline at end of file diff --git a/test-files/golden-tests/config/inherit-base-members/never.yml b/test-files/golden-tests/config/inherit-base-members/never.yml index ffb7e48ed..8ece8048c 100644 --- a/test-files/golden-tests/config/inherit-base-members/never.yml +++ b/test-files/golden-tests/config/inherit-base-members/never.yml @@ -1,4 +1,5 @@ inherit-base-members: never exclude-symbols: - excluded_base +extract-private-bases: true warn-no-paramdoc: false \ No newline at end of file diff --git a/test-files/golden-tests/config/inherit-base-members/reference.yml b/test-files/golden-tests/config/inherit-base-members/reference.yml index 32866fc1b..3bc703622 100644 --- a/test-files/golden-tests/config/inherit-base-members/reference.yml +++ b/test-files/golden-tests/config/inherit-base-members/reference.yml @@ -1,4 +1,5 @@ inherit-base-members: reference exclude-symbols: - excluded_base +extract-private-bases: true warn-no-paramdoc: false \ No newline at end of file diff --git a/test-files/golden-tests/metadata/record-inheritance.yml b/test-files/golden-tests/metadata/record-inheritance.yml new file mode 100644 index 000000000..e6e16a42a --- /dev/null +++ b/test-files/golden-tests/metadata/record-inheritance.yml @@ -0,0 +1 @@ +extract-private-bases: true \ No newline at end of file From 4b6b1abbbdd1b321ef47c383070b7de6f9617358 Mon Sep 17 00:00:00 2001 From: alandefreitas Date: Wed, 12 Feb 2025 15:56:00 -0300 Subject: [PATCH 4/7] option name is `extract-anonymous-namespaces` #refactor --- docs/mrdocs.schema.json | 20 ++++++++++---------- src/lib/AST/ASTVisitor.cpp | 25 +++++++------------------ src/lib/Lib/ConfigOptions.json | 2 +- 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/docs/mrdocs.schema.json b/docs/mrdocs.schema.json index 72bf93e85..57d9c4964 100644 --- a/docs/mrdocs.schema.json +++ b/docs/mrdocs.schema.json @@ -7,16 +7,6 @@ "title": "Path to the Addons directory", "type": "string" }, - "anonymous-namespaces": { - "default": true, - "description": "Determine whether symbols in anonymous namespaces should be extracted. When set to `always`, symbols in anonymous namespaces are always extracted. When set to `dependency`, symbols in anonymous namespaces are extracted only if they are referenced by the source code. When set to `never`, symbols in anonymous namespaces are never extracted.", - "enum": [ - true, - false - ], - "title": "Extraction policy for anonymous namespaces", - "type": "boolean" - }, "auto-brief": { "default": true, "description": "When set to `true`, MrDocs uses the first line (until the first dot, question mark, or exclamation mark) of the comment as the brief of the symbol. When set to `false`, a explicit @brief command is required.", @@ -101,6 +91,16 @@ "title": "Extract all symbols", "type": "boolean" }, + "extract-anonymous-namespaces": { + "default": true, + "description": "Determine whether symbols in anonymous namespaces should be extracted. When set to `always`, symbols in anonymous namespaces are always extracted. When set to `dependency`, symbols in anonymous namespaces are extracted only if they are referenced by the source code. When set to `never`, symbols in anonymous namespaces are never extracted.", + "enum": [ + true, + false + ], + "title": "Extraction policy for anonymous namespaces", + "type": "boolean" + }, "extract-private": { "default": false, "description": "Determine whether private class members should be extracted", diff --git a/src/lib/AST/ASTVisitor.cpp b/src/lib/AST/ASTVisitor.cpp index 8fb68c256..2d20a8626 100644 --- a/src/lib/AST/ASTVisitor.cpp +++ b/src/lib/AST/ASTVisitor.cpp @@ -2705,10 +2705,14 @@ checkTypeFilters(Decl const* D, AccessSpecifier const access) { if (!config_->extractPrivate) { - // KRYSTIAN FIXME: this doesn't handle direct - // dependencies on inaccessible declarations + MRDOCS_CHECK_OR(access != AccessSpecifier::AS_private, false); + } + if (!config_->extractAnonymousNamespaces) + { MRDOCS_CHECK_OR( - access != AccessSpecifier::AS_private, false); + !isa(D) || + !dyn_cast(D)->isAnonymousNamespace(), + false); } // Don't extract anonymous unions @@ -2716,23 +2720,8 @@ checkTypeFilters(Decl const* D, AccessSpecifier const access) MRDOCS_CHECK_OR(!RD || !RD->isAnonymousStructOrUnion(), false); // Don't extract implicitly generated declarations - // (except for IndirectFieldDecls) MRDOCS_CHECK_OR(!D->isImplicit() || isa(D), false); - // Don't extract anonymous namespaces unless configured to do so - // and the current mode is normal - if (auto const* ND = dyn_cast(D); - ND && - ND->isAnonymousNamespace() && - config_->anonymousNamespaces) - { - // Otherwise, skip extraction if this isn't a dependency - // KRYSTIAN FIXME: is this correct? a namespace should not - // be extracted as a dependency (until namespace aliases and - // using directives are supported) - MRDOCS_CHECK_OR(mode_ == TraversalMode::Regular, false); - } - return true; } diff --git a/src/lib/Lib/ConfigOptions.json b/src/lib/Lib/ConfigOptions.json index c80ca73bf..bf4c0b455 100644 --- a/src/lib/Lib/ConfigOptions.json +++ b/src/lib/Lib/ConfigOptions.json @@ -200,7 +200,7 @@ "default": false }, { - "name": "anonymous-namespaces", + "name": "extract-anonymous-namespaces", "brief": "Extraction policy for anonymous namespaces", "details": "Determine whether symbols in anonymous namespaces should be extracted. When set to `always`, symbols in anonymous namespaces are always extracted. When set to `dependency`, symbols in anonymous namespaces are extracted only if they are referenced by the source code. When set to `never`, symbols in anonymous namespaces are never extracted.", "type": "bool", From 9bd1d9dfaeb6293d510ee7743cc81b9f6da960d8 Mon Sep 17 00:00:00 2001 From: alandefreitas Date: Wed, 12 Feb 2025 16:15:48 -0300 Subject: [PATCH 5/7] `extract-private-virtual` option #feat --- docs/mrdocs.schema.json | 10 ++ src/lib/AST/ASTVisitor.cpp | 12 +- src/lib/Lib/ConfigOptions.json | 7 ++ .../extract-private-virtual.adoc | 84 ++++++++++++++ .../extract-private-virtual.cpp | 6 + .../extract-private-virtual.html | 106 ++++++++++++++++++ .../extract-private-virtual.xml | 17 +++ .../extract-private-virtual.yml | 1 + .../no-extract-private-virtual.adoc | 60 ++++++++++ .../no-extract-private-virtual.cpp | 6 + .../no-extract-private-virtual.html | 77 +++++++++++++ .../no-extract-private-virtual.xml | 13 +++ .../no-extract-private-virtual.yml | 1 + 13 files changed, 398 insertions(+), 2 deletions(-) create mode 100644 test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.adoc create mode 100644 test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.cpp create mode 100644 test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.html create mode 100644 test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.xml create mode 100644 test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.yml create mode 100644 test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.adoc create mode 100644 test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.cpp create mode 100644 test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.html create mode 100644 test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.xml create mode 100644 test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.yml diff --git a/docs/mrdocs.schema.json b/docs/mrdocs.schema.json index 57d9c4964..f17ce10af 100644 --- a/docs/mrdocs.schema.json +++ b/docs/mrdocs.schema.json @@ -121,6 +121,16 @@ "title": "Extraction policy for private base classes", "type": "boolean" }, + "extract-private-virtual": { + "default": false, + "description": "Determine whether private virtual methods of a class should be extracted", + "enum": [ + true, + false + ], + "title": "Extraction policy for private virtual methods of a class", + "type": "boolean" + }, "file-patterns": { "default": [ "*.hpp", diff --git a/src/lib/AST/ASTVisitor.cpp b/src/lib/AST/ASTVisitor.cpp index 2d20a8626..060f91a74 100644 --- a/src/lib/AST/ASTVisitor.cpp +++ b/src/lib/AST/ASTVisitor.cpp @@ -2703,12 +2703,20 @@ bool ASTVisitor:: checkTypeFilters(Decl const* D, AccessSpecifier const access) { - if (!config_->extractPrivate) + if (access == AS_private) { - MRDOCS_CHECK_OR(access != AccessSpecifier::AS_private, false); + // Don't extract private members + if (isa(D) && + dyn_cast(D)->isVirtual()) + { + // Don't extract private virtual members + return config_->extractPrivateVirtual || config_->extractPrivate; + } + return config_->extractPrivate; } if (!config_->extractAnonymousNamespaces) { + // Don't extract anonymous namespaces MRDOCS_CHECK_OR( !isa(D) || !dyn_cast(D)->isAnonymousNamespace(), diff --git a/src/lib/Lib/ConfigOptions.json b/src/lib/Lib/ConfigOptions.json index bf4c0b455..ca8f76b86 100644 --- a/src/lib/Lib/ConfigOptions.json +++ b/src/lib/Lib/ConfigOptions.json @@ -192,6 +192,13 @@ "type": "bool", "default": false }, + { + "name": "extract-private-virtual", + "brief": "Extraction policy for private virtual methods of a class", + "details": "Determine whether private virtual methods of a class should be extracted", + "type": "bool", + "default": false + }, { "name": "extract-private-bases", "brief": "Extraction policy for private base classes", diff --git a/test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.adoc b/test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.adoc new file mode 100644 index 000000000..c4cf1eb32 --- /dev/null +++ b/test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.adoc @@ -0,0 +1,84 @@ += Reference +:mrdocs: + +[#index] +== Global namespace + + +=== Types + +[cols=1] +|=== +| Name + +| <> +|=== + +[#A] +== A + + +=== Synopsis + + +Declared in `<extract‐private‐virtual.cpp>` + +[source,cpp,subs="verbatim,replacements,macros,-callouts"] +---- +class A; +---- + +=== Member Functions + +[cols=1] +|=== +| Name + +| <> [.small]#[virtual]# +|=== + + +=== Private Member Functions + +[cols=1] +|=== +| Name + +| <> [.small]#[virtual]# +|=== + +[#A-f] +== <>::f + + +=== Synopsis + + +Declared in `<extract‐private‐virtual.cpp>` + +[source,cpp,subs="verbatim,replacements,macros,-callouts"] +---- +virtual +void +f(); +---- + +[#A-g] +== <>::g + + +=== Synopsis + + +Declared in `<extract‐private‐virtual.cpp>` + +[source,cpp,subs="verbatim,replacements,macros,-callouts"] +---- +virtual +void +g(); +---- + + + +[.small]#Created with https://www.mrdocs.com[MrDocs]# diff --git a/test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.cpp b/test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.cpp new file mode 100644 index 000000000..8fa855aa8 --- /dev/null +++ b/test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.cpp @@ -0,0 +1,6 @@ +class A { +public: + virtual void f() {} +private: + virtual void g() {} +}; \ No newline at end of file diff --git a/test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.html b/test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.html new file mode 100644 index 000000000..be17690bb --- /dev/null +++ b/test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.html @@ -0,0 +1,106 @@ + + +Reference + + +
+

Reference

+
+
+

Global namespace

+
+

Types

+ + + + + + + + + + +
Name
A
+
+
+
+

A

+
+
+

Synopsis

+
+Declared in <extract-private-virtual.cpp>
+
+
+class A;
+
+
+
+

Member Functions

+ + + + + + + + + + +
Name
f [virtual]
+ + +

Private Member Functions

+ + + + + + + + + + +
Name
g [virtual]
+
+
+
+

A::f

+
+
+

Synopsis

+
+Declared in <extract-private-virtual.cpp>
+
+
+virtual
+void
+f();
+
+
+
+
+
+
+

A::g

+
+
+

Synopsis

+
+Declared in <extract-private-virtual.cpp>
+
+
+virtual
+void
+g();
+
+
+
+
+ +
+
+

Created with MrDocs

+
+ + \ No newline at end of file diff --git a/test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.xml b/test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.xml new file mode 100644 index 000000000..b8b465a8f --- /dev/null +++ b/test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + diff --git a/test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.yml b/test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.yml new file mode 100644 index 000000000..fe1a06434 --- /dev/null +++ b/test-files/golden-tests/config/extract-private-virtual/extract-private-virtual.yml @@ -0,0 +1 @@ +extract-private-virtual: true \ No newline at end of file diff --git a/test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.adoc b/test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.adoc new file mode 100644 index 000000000..a4c1d1c5b --- /dev/null +++ b/test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.adoc @@ -0,0 +1,60 @@ += Reference +:mrdocs: + +[#index] +== Global namespace + + +=== Types + +[cols=1] +|=== +| Name + +| <> +|=== + +[#A] +== A + + +=== Synopsis + + +Declared in `<no‐extract‐private‐virtual.cpp>` + +[source,cpp,subs="verbatim,replacements,macros,-callouts"] +---- +class A; +---- + +=== Member Functions + +[cols=1] +|=== +| Name + +| <> [.small]#[virtual]# +|=== + + + +[#A-f] +== <>::f + + +=== Synopsis + + +Declared in `<no‐extract‐private‐virtual.cpp>` + +[source,cpp,subs="verbatim,replacements,macros,-callouts"] +---- +virtual +void +f(); +---- + + + +[.small]#Created with https://www.mrdocs.com[MrDocs]# diff --git a/test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.cpp b/test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.cpp new file mode 100644 index 000000000..8fa855aa8 --- /dev/null +++ b/test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.cpp @@ -0,0 +1,6 @@ +class A { +public: + virtual void f() {} +private: + virtual void g() {} +}; \ No newline at end of file diff --git a/test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.html b/test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.html new file mode 100644 index 000000000..53957c36d --- /dev/null +++ b/test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.html @@ -0,0 +1,77 @@ + + +Reference + + +
+

Reference

+
+
+

Global namespace

+
+

Types

+ + + + + + + + + + +
Name
A
+
+
+
+

A

+
+
+

Synopsis

+
+Declared in <no-extract-private-virtual.cpp>
+
+
+class A;
+
+
+
+

Member Functions

+ + + + + + + + + + +
Name
f [virtual]
+ + +
+
+
+

A::f

+
+
+

Synopsis

+
+Declared in <no-extract-private-virtual.cpp>
+
+
+virtual
+void
+f();
+
+
+
+
+ +
+
+

Created with MrDocs

+
+ + \ No newline at end of file diff --git a/test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.xml b/test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.xml new file mode 100644 index 000000000..012ecce05 --- /dev/null +++ b/test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.yml b/test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.yml new file mode 100644 index 000000000..29e25140d --- /dev/null +++ b/test-files/golden-tests/config/extract-private-virtual/no-extract-private-virtual.yml @@ -0,0 +1 @@ +extract-private-virtual: false \ No newline at end of file From 757253f494afd391bd7c2ab8d757860c5cf8f216 Mon Sep 17 00:00:00 2001 From: alandefreitas Date: Wed, 12 Feb 2025 16:33:20 -0300 Subject: [PATCH 6/7] `extract-static` option #feat --- docs/mrdocs.schema.json | 10 ++++++ src/lib/AST/ASTVisitor.cpp | 12 +++---- src/lib/AST/ClangHelpers.cpp | 33 +++++++++++++++++++ src/lib/AST/ClangHelpers.hpp | 12 +++++++ src/lib/Lib/ConfigOptions.json | 7 ++++ .../golden-tests/metadata/ns-variables.yml | 1 + 6 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 test-files/golden-tests/metadata/ns-variables.yml diff --git a/docs/mrdocs.schema.json b/docs/mrdocs.schema.json index f17ce10af..47ef8ed05 100644 --- a/docs/mrdocs.schema.json +++ b/docs/mrdocs.schema.json @@ -131,6 +131,16 @@ "title": "Extraction policy for private virtual methods of a class", "type": "boolean" }, + "extract-static": { + "default": false, + "description": "Determine whether static members of a file should be extracted. This option does not refer to static members of a class.", + "enum": [ + true, + false + ], + "title": "Extraction policy for static members of a file", + "type": "boolean" + }, "file-patterns": { "default": [ "*.hpp", diff --git a/src/lib/AST/ASTVisitor.cpp b/src/lib/AST/ASTVisitor.cpp index 060f91a74..88a73a5d7 100644 --- a/src/lib/AST/ASTVisitor.cpp +++ b/src/lib/AST/ASTVisitor.cpp @@ -2706,8 +2706,7 @@ checkTypeFilters(Decl const* D, AccessSpecifier const access) if (access == AS_private) { // Don't extract private members - if (isa(D) && - dyn_cast(D)->isVirtual()) + if (isVirtualMember(D)) { // Don't extract private virtual members return config_->extractPrivateVirtual || config_->extractPrivate; @@ -2717,10 +2716,11 @@ checkTypeFilters(Decl const* D, AccessSpecifier const access) if (!config_->extractAnonymousNamespaces) { // Don't extract anonymous namespaces - MRDOCS_CHECK_OR( - !isa(D) || - !dyn_cast(D)->isAnonymousNamespace(), - false); + MRDOCS_CHECK_OR(!isAnonymousNamespace(D), false); + } + if (!config_->extractStatic) + { + MRDOCS_CHECK_OR(!isStaticFileLevelMember(D), false); } // Don't extract anonymous unions diff --git a/src/lib/AST/ClangHelpers.cpp b/src/lib/AST/ClangHelpers.cpp index dc3848cfd..e3b0b3b2f 100644 --- a/src/lib/AST/ClangHelpers.cpp +++ b/src/lib/AST/ClangHelpers.cpp @@ -344,4 +344,37 @@ isAllImplicit(Decl const* D) return isAllImplicit(P); } +bool +isVirtualMember(Decl const* D) +{ + if (auto const* MD = dyn_cast(D)) + { + return MD->isVirtual(); + } + return false; +} + +bool +isAnonymousNamespace(const Decl *D) +{ + if (auto const* ND = dyn_cast(D)) + { + return ND->isAnonymousNamespace(); + } + return false; +} + +bool +isStaticFileLevelMember(const Decl *D) +{ + if (const auto *VD = dyn_cast(D)) { + return VD->getStorageClass() == SC_Static && VD->getDeclContext()->isFileContext(); + } + if (const auto *FD = dyn_cast(D)) { + return FD->getStorageClass() == SC_Static && FD->getDeclContext()->isFileContext(); + } + return false; +} + + } // clang::mrdocs diff --git a/src/lib/AST/ClangHelpers.hpp b/src/lib/AST/ClangHelpers.hpp index f483bb315..2b8dd5587 100644 --- a/src/lib/AST/ClangHelpers.hpp +++ b/src/lib/AST/ClangHelpers.hpp @@ -832,6 +832,18 @@ MRDOCS_DECL bool isAllImplicit(Decl const* D); +MRDOCS_DECL +bool +isVirtualMember(Decl const* D); + +MRDOCS_DECL +bool +isAnonymousNamespace(Decl const* D); + +MRDOCS_DECL +bool +isStaticFileLevelMember(Decl const *D); + #ifdef NDEBUG #define MRDOCS_SYMBOL_TRACE(D, C) #else diff --git a/src/lib/Lib/ConfigOptions.json b/src/lib/Lib/ConfigOptions.json index ca8f76b86..f4d793b27 100644 --- a/src/lib/Lib/ConfigOptions.json +++ b/src/lib/Lib/ConfigOptions.json @@ -206,6 +206,13 @@ "type": "bool", "default": false }, + { + "name": "extract-static", + "brief": "Extraction policy for static members of a file", + "details": "Determine whether static members of a file should be extracted. This option does not refer to static members of a class.", + "type": "bool", + "default": false + }, { "name": "extract-anonymous-namespaces", "brief": "Extraction policy for anonymous namespaces", diff --git a/test-files/golden-tests/metadata/ns-variables.yml b/test-files/golden-tests/metadata/ns-variables.yml new file mode 100644 index 000000000..a0bcccec9 --- /dev/null +++ b/test-files/golden-tests/metadata/ns-variables.yml @@ -0,0 +1 @@ +extract-static: true \ No newline at end of file From 5420ffc577e396e1e1edfffa6ab40322ba3a8432 Mon Sep 17 00:00:00 2001 From: alandefreitas Date: Wed, 12 Feb 2025 16:48:06 -0300 Subject: [PATCH 7/7] `extract-local-classes` option #feat --- docs/mrdocs.schema.json | 10 ++ src/lib/AST/ASTVisitor.cpp | 30 ++++-- src/lib/AST/ASTVisitor.hpp | 3 + src/lib/Lib/ConfigOptions.json | 7 ++ .../extract-local-classes.adoc | 77 +++++++++++++++ .../extract-local-classes.cpp | 5 + .../extract-local-classes.html | 94 +++++++++++++++++++ .../extract-local-classes.xml | 15 +++ .../extract-local-classes.yml | 1 + .../no-extract-local-classes.adoc | 34 +++++++ .../no-extract-local-classes.cpp | 5 + .../no-extract-local-classes.html | 47 ++++++++++ .../no-extract-local-classes.xml | 9 ++ .../no-extract-local-classes.yml | 1 + 14 files changed, 332 insertions(+), 6 deletions(-) create mode 100644 test-files/golden-tests/config/extract-local-classes/extract-local-classes.adoc create mode 100644 test-files/golden-tests/config/extract-local-classes/extract-local-classes.cpp create mode 100644 test-files/golden-tests/config/extract-local-classes/extract-local-classes.html create mode 100644 test-files/golden-tests/config/extract-local-classes/extract-local-classes.xml create mode 100644 test-files/golden-tests/config/extract-local-classes/extract-local-classes.yml create mode 100644 test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.adoc create mode 100644 test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.cpp create mode 100644 test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.html create mode 100644 test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.xml create mode 100644 test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.yml diff --git a/docs/mrdocs.schema.json b/docs/mrdocs.schema.json index 47ef8ed05..aa6ad73fe 100644 --- a/docs/mrdocs.schema.json +++ b/docs/mrdocs.schema.json @@ -101,6 +101,16 @@ "title": "Extraction policy for anonymous namespaces", "type": "boolean" }, + "extract-local-classes": { + "default": true, + "description": "Determine whether records only defined locally in source files should be extracted.", + "enum": [ + true, + false + ], + "title": "Extraction policy for records defined locally in source files", + "type": "boolean" + }, "extract-private": { "default": false, "description": "Determine whether private class members should be extracted", diff --git a/src/lib/AST/ASTVisitor.cpp b/src/lib/AST/ASTVisitor.cpp index 88a73a5d7..c69fa8f1a 100644 --- a/src/lib/AST/ASTVisitor.cpp +++ b/src/lib/AST/ASTVisitor.cpp @@ -2722,6 +2722,17 @@ checkTypeFilters(Decl const* D, AccessSpecifier const access) { MRDOCS_CHECK_OR(!isStaticFileLevelMember(D), false); } + if (!config_->extractLocalClasses && isa(D)) + { + if (auto const* FI = findFileInfo(D); + FI->full_path.ends_with(".cpp") || + FI->full_path.ends_with(".cc") || + FI->full_path.ends_with(".cxx") || + FI->full_path.ends_with(".c")) + { + return false; + } + } // Don't extract anonymous unions auto const* RD = dyn_cast(D); @@ -2737,12 +2748,7 @@ bool ASTVisitor:: checkFileFilters(Decl const* D) { - clang::SourceLocation Loc = D->getBeginLoc(); - if (Loc.isInvalid()) - { - Loc = D->getLocation(); - } - FileInfo* fileInfo = findFileInfo(Loc); + FileInfo* fileInfo = findFileInfo(D); MRDOCS_CHECK_OR(fileInfo, false); // Check pre-processed file filters @@ -3146,6 +3152,18 @@ findFileInfo(clang::SourceLocation const loc) return std::addressof(it->second); } +ASTVisitor::FileInfo* +ASTVisitor:: +findFileInfo(Decl const* D) +{ + clang::SourceLocation Loc = D->getBeginLoc(); + if (Loc.isInvalid()) + { + Loc = D->getLocation(); + } + return findFileInfo(Loc); +} + std::optional ASTVisitor:: buildFileInfo(FileEntry const* entry) diff --git a/src/lib/AST/ASTVisitor.hpp b/src/lib/AST/ASTVisitor.hpp index ada6939e1..07aabc9f4 100644 --- a/src/lib/AST/ASTVisitor.hpp +++ b/src/lib/AST/ASTVisitor.hpp @@ -1109,6 +1109,9 @@ class ASTVisitor FileInfo* findFileInfo(clang::SourceLocation loc); + FileInfo* + findFileInfo(Decl const* D); + /* Build a FileInfo for a FileEntry This function will build a FileInfo object for a diff --git a/src/lib/Lib/ConfigOptions.json b/src/lib/Lib/ConfigOptions.json index f4d793b27..d21407ed5 100644 --- a/src/lib/Lib/ConfigOptions.json +++ b/src/lib/Lib/ConfigOptions.json @@ -213,6 +213,13 @@ "type": "bool", "default": false }, + { + "name": "extract-local-classes", + "brief": "Extraction policy for records defined locally in source files", + "details": "Determine whether records only defined locally in source files should be extracted.", + "type": "bool", + "default": true + }, { "name": "extract-anonymous-namespaces", "brief": "Extraction policy for anonymous namespaces", diff --git a/test-files/golden-tests/config/extract-local-classes/extract-local-classes.adoc b/test-files/golden-tests/config/extract-local-classes/extract-local-classes.adoc new file mode 100644 index 000000000..2f4d08465 --- /dev/null +++ b/test-files/golden-tests/config/extract-local-classes/extract-local-classes.adoc @@ -0,0 +1,77 @@ += Reference +:mrdocs: + +[#index] +== Global namespace + + +=== Types + +[cols=1] +|=== +| Name + +| <> +| <> +|=== +=== Functions + +[cols=1] +|=== +| Name + +| <> +|=== + +[#local_class] +== local_class + + +=== Synopsis + + +Declared in `<extract‐local‐classes.cpp>` + +[source,cpp,subs="verbatim,replacements,macros,-callouts"] +---- +class local_class; +---- + + + + +[#local_struct] +== local_struct + + +=== Synopsis + + +Declared in `<extract‐local‐classes.cpp>` + +[source,cpp,subs="verbatim,replacements,macros,-callouts"] +---- +struct local_struct; +---- + + + + +[#local_function] +== local_function + + +=== Synopsis + + +Declared in `<extract‐local‐classes.cpp>` + +[source,cpp,subs="verbatim,replacements,macros,-callouts"] +---- +void +local_function(); +---- + + + +[.small]#Created with https://www.mrdocs.com[MrDocs]# diff --git a/test-files/golden-tests/config/extract-local-classes/extract-local-classes.cpp b/test-files/golden-tests/config/extract-local-classes/extract-local-classes.cpp new file mode 100644 index 000000000..989229f70 --- /dev/null +++ b/test-files/golden-tests/config/extract-local-classes/extract-local-classes.cpp @@ -0,0 +1,5 @@ +// Already a cpp file so this is a local class +struct local_struct {}; +class local_class {}; +void local_function(); + diff --git a/test-files/golden-tests/config/extract-local-classes/extract-local-classes.html b/test-files/golden-tests/config/extract-local-classes/extract-local-classes.html new file mode 100644 index 000000000..571572105 --- /dev/null +++ b/test-files/golden-tests/config/extract-local-classes/extract-local-classes.html @@ -0,0 +1,94 @@ + + +Reference + + +
+

Reference

+
+
+

Global namespace

+
+

Types

+ + + + + + + + + + + +
Name
local_class
local_struct
+

Functions

+ + + + + + + + + + +
Name
local_function
+
+
+
+

local_class

+
+
+

Synopsis

+
+Declared in <extract-local-classes.cpp>
+
+
+class local_class;
+
+
+
+ + +
+
+
+

local_struct

+
+
+

Synopsis

+
+Declared in <extract-local-classes.cpp>
+
+
+struct local_struct;
+
+
+
+ + +
+
+
+

local_function

+
+
+

Synopsis

+
+Declared in <extract-local-classes.cpp>
+
+
+void
+local_function();
+
+
+
+
+ +
+
+

Created with MrDocs

+
+ + \ No newline at end of file diff --git a/test-files/golden-tests/config/extract-local-classes/extract-local-classes.xml b/test-files/golden-tests/config/extract-local-classes/extract-local-classes.xml new file mode 100644 index 000000000..181122d33 --- /dev/null +++ b/test-files/golden-tests/config/extract-local-classes/extract-local-classes.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + diff --git a/test-files/golden-tests/config/extract-local-classes/extract-local-classes.yml b/test-files/golden-tests/config/extract-local-classes/extract-local-classes.yml new file mode 100644 index 000000000..6e8913408 --- /dev/null +++ b/test-files/golden-tests/config/extract-local-classes/extract-local-classes.yml @@ -0,0 +1 @@ +extract-local-classes: true \ No newline at end of file diff --git a/test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.adoc b/test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.adoc new file mode 100644 index 000000000..bc926ce02 --- /dev/null +++ b/test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.adoc @@ -0,0 +1,34 @@ += Reference +:mrdocs: + +[#index] +== Global namespace + + +=== Functions + +[cols=1] +|=== +| Name + +| <> +|=== + +[#local_function] +== local_function + + +=== Synopsis + + +Declared in `<no‐extract‐local‐classes.cpp>` + +[source,cpp,subs="verbatim,replacements,macros,-callouts"] +---- +void +local_function(); +---- + + + +[.small]#Created with https://www.mrdocs.com[MrDocs]# diff --git a/test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.cpp b/test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.cpp new file mode 100644 index 000000000..989229f70 --- /dev/null +++ b/test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.cpp @@ -0,0 +1,5 @@ +// Already a cpp file so this is a local class +struct local_struct {}; +class local_class {}; +void local_function(); + diff --git a/test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.html b/test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.html new file mode 100644 index 000000000..12d0dc10e --- /dev/null +++ b/test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.html @@ -0,0 +1,47 @@ + + +Reference + + +
+

Reference

+
+
+

Global namespace

+
+

Functions

+ + + + + + + + + + +
Name
local_function
+
+
+
+

local_function

+
+
+

Synopsis

+
+Declared in <no-extract-local-classes.cpp>
+
+
+void
+local_function();
+
+
+
+
+ +
+
+

Created with MrDocs

+
+ + \ No newline at end of file diff --git a/test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.xml b/test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.xml new file mode 100644 index 000000000..08df5f32a --- /dev/null +++ b/test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.xml @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.yml b/test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.yml new file mode 100644 index 000000000..a0dd405a3 --- /dev/null +++ b/test-files/golden-tests/config/extract-local-classes/no-extract-local-classes.yml @@ -0,0 +1 @@ +extract-local-classes: false \ No newline at end of file