Skip to content

Commit c69f121

Browse files
committed
extract-static option
#feat
1 parent 7e99c39 commit c69f121

File tree

6 files changed

+69
-6
lines changed

6 files changed

+69
-6
lines changed

docs/mrdocs.schema.json

+10
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@
131131
"title": "Extraction policy for private virtual methods of a class",
132132
"type": "boolean"
133133
},
134+
"extract-static": {
135+
"default": false,
136+
"description": "Determine whether static members of a file should be extracted. This option does not refer to static members of a class.",
137+
"enum": [
138+
true,
139+
false
140+
],
141+
"title": "Extraction policy for static members of a file",
142+
"type": "boolean"
143+
},
134144
"file-patterns": {
135145
"default": [
136146
"*.hpp",

src/lib/AST/ASTVisitor.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -2706,8 +2706,7 @@ checkTypeFilters(Decl const* D, AccessSpecifier const access)
27062706
if (access == AS_private)
27072707
{
27082708
// Don't extract private members
2709-
if (isa<CXXMethodDecl>(D) &&
2710-
dyn_cast<CXXMethodDecl>(D)->isVirtual())
2709+
if (isVirtualMember(D))
27112710
{
27122711
// Don't extract private virtual members
27132712
return config_->extractPrivateVirtual || config_->extractPrivate;
@@ -2717,10 +2716,11 @@ checkTypeFilters(Decl const* D, AccessSpecifier const access)
27172716
if (!config_->extractAnonymousNamespaces)
27182717
{
27192718
// Don't extract anonymous namespaces
2720-
MRDOCS_CHECK_OR(
2721-
!isa<NamespaceDecl>(D) ||
2722-
!dyn_cast<NamespaceDecl>(D)->isAnonymousNamespace(),
2723-
false);
2719+
MRDOCS_CHECK_OR(!isAnonymousNamespace(D), false);
2720+
}
2721+
if (!config_->extractStatic)
2722+
{
2723+
MRDOCS_CHECK_OR(!isStaticFileLevelMember(D), false);
27242724
}
27252725

27262726
// Don't extract anonymous unions

src/lib/AST/ClangHelpers.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,37 @@ isAllImplicit(Decl const* D)
344344
return isAllImplicit(P);
345345
}
346346

347+
bool
348+
isVirtualMember(Decl const* D)
349+
{
350+
if (auto const* MD = dyn_cast<CXXMethodDecl>(D))
351+
{
352+
return MD->isVirtual();
353+
}
354+
return false;
355+
}
356+
357+
bool
358+
isAnonymousNamespace(const Decl *D)
359+
{
360+
if (auto const* ND = dyn_cast<NamespaceDecl>(D))
361+
{
362+
return ND->isAnonymousNamespace();
363+
}
364+
return false;
365+
}
366+
367+
bool
368+
isStaticFileLevelMember(const Decl *D)
369+
{
370+
if (const auto *VD = dyn_cast<VarDecl>(D)) {
371+
return VD->getStorageClass() == SC_Static && VD->getDeclContext()->isFileContext();
372+
}
373+
if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
374+
return FD->getStorageClass() == SC_Static && FD->getDeclContext()->isFileContext();
375+
}
376+
return false;
377+
}
378+
379+
347380
} // clang::mrdocs

src/lib/AST/ClangHelpers.hpp

+12
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,18 @@ MRDOCS_DECL
832832
bool
833833
isAllImplicit(Decl const* D);
834834

835+
MRDOCS_DECL
836+
bool
837+
isVirtualMember(Decl const* D);
838+
839+
MRDOCS_DECL
840+
bool
841+
isAnonymousNamespace(Decl const* D);
842+
843+
MRDOCS_DECL
844+
bool
845+
isStaticFileLevelMember(Decl const *D);
846+
835847
#ifdef NDEBUG
836848
#define MRDOCS_SYMBOL_TRACE(D, C)
837849
#else

src/lib/Lib/ConfigOptions.json

+7
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,13 @@
206206
"type": "bool",
207207
"default": false
208208
},
209+
{
210+
"name": "extract-static",
211+
"brief": "Extraction policy for static members of a file",
212+
"details": "Determine whether static members of a file should be extracted. This option does not refer to static members of a class.",
213+
"type": "bool",
214+
"default": false
215+
},
209216
{
210217
"name": "extract-anonymous-namespaces",
211218
"brief": "Extraction policy for anonymous namespaces",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extract-static: true

0 commit comments

Comments
 (0)