Skip to content

Commit

Permalink
feat: ExtractOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkrystian committed Oct 6, 2023
1 parent dddfeed commit 7a1e1dd
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 28 deletions.
41 changes: 23 additions & 18 deletions include/mrdox/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,29 @@ class MRDOX_DECL
*/
Policy referencedDeclarations = Policy::Dependency;

/** Extraction policy for anonymous namespace.
@li `Policy::Always`: anonymous namespaces and their
members will always be extracted.
@li `Policy::Dependency`: members of anonymous namespaces will only
be extracted via dependency.
@li `Policy::Never`: members of anonymous namespace will
never be extracted, regardless of how they are referenced.
*/
Policy anonymousNamespaces = Policy::Always;

/** Extraction policy for inaccessible members.
@li `Policy::Always`: all `private` and `protected` members
will be extracted.
@li `Policy::Dependency`: `private` and `protected` members will only
be extracted via dependency.
@li `Policy::Never`: `private` and `protected` will never be extracted.
*/
Policy inaccessibleMembers = Policy::Always;

Policy inaccessibleBases = Policy::Always;
Expand All @@ -71,25 +92,9 @@ class MRDOX_DECL
struct Settings
{

ExtractOptions extractOptions;

/** `true` if anonymous namespace members should be extracted and displayed.
In some cases anonymous namespace members will
be listed even if this configuration value is set to
`false`. For example, this may occur for a class derived
from one declared within an anonymous namespace.
*/
bool includeAnonymous = true;

/** `true` if private members should be extracted and displayed.
In some cases private members will be listed
even if this configuration value is set to
`false`. For example, when extracting private
virtual functions in a base class.
/** Options controlling when declarations are extracted.
*/
bool includePrivate = false;
ExtractOptions extract;

/** `true` if output should consist of multiple files.
*/
Expand Down
24 changes: 19 additions & 5 deletions src/lib/AST/ASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ class ASTVisitor
SymbolID id = extractSymbolID(D);
Info* info = getInfo(id);

if(config_->extractOptions.referencedDeclarations ==
if(config_->extract.referencedDeclarations ==
Config::ExtractOptions::Policy::Never)
return info;

if(config_->extractOptions.referencedDeclarations ==
if(config_->extract.referencedDeclarations ==
Config::ExtractOptions::Policy::Dependency)
{
// if(currentMode() == ExtractMode::Normal)
Expand Down Expand Up @@ -2348,9 +2348,23 @@ traverse(NamespaceDecl* D)
{
if(! shouldExtract(D))
return true;
if(! config_->includeAnonymous &&
D->isAnonymousNamespace())
return true;

if(D->isAnonymousNamespace() &&
config_->extract.anonymousNamespaces !=
Config::ExtractOptions::Policy::Always)
{
// always skip anonymous namespaces if so configured
if(config_->extract.anonymousNamespaces ==
Config::ExtractOptions::Policy::Never)
return true;

// 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)
if(currentMode() == ExtractMode::Normal)
return true;
}

SymbolID id;
if(! extractSymbolID(D, id))
Expand Down
4 changes: 1 addition & 3 deletions src/lib/Lib/ConfigImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,8 @@ struct llvm::yaml::MappingTraits<
io.mapOptional("defines", cfg.defines);
io.mapOptional("ignore-failures", cfg.ignoreFailures);

io.mapOptional("extract-options", cfg.extractOptions);
io.mapOptional("extract", cfg.extract);

io.mapOptional("include-anonymous", cfg.includeAnonymous);
io.mapOptional("include-private", cfg.includePrivate);
io.mapOptional("multipage", cfg.multiPage);
io.mapOptional("source-root", cfg.sourceRoot);

Expand Down
4 changes: 3 additions & 1 deletion src/lib/Metadata/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class Interface::Build
Corpus const& corpus) noexcept
: I_(I)
, corpus_(corpus)
, includePrivate_(corpus_.config->includePrivate)
, includePrivate_(
corpus_.config->extract.inaccessibleMembers !=
Config::ExtractOptions::Policy::Never)
{
// treat `Derived` as a public base,
append(AccessKind::Public, Derived);
Expand Down
3 changes: 2 additions & 1 deletion test-files/adoc/mrdox.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ignore-failures: true
with-private: false
extract:
inaccessible-members: never
concurrency: 1
source-root: .
single-page: true
Expand Down

0 comments on commit 7a1e1dd

Please sign in to comment.