Skip to content

Commit

Permalink
feat: configurable see-below and implementation-defined namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkrystian committed Jun 3, 2024
1 parent 05938ab commit c476746
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{#if prefix~}}
{{>name-info prefix nolink=nolink~}}::
{{~/if~}}
{{#if (or (eq name "see-below") (eq name "implementation-defined"))~}}pass:q[_{{name}}_]{{else~}}
{{#if (and symbol.ref (not nolink))}}xref:{{symbol.ref}}[{{name}}]{{else~}}
{{name}}{{/if}}{{#if args}}{{>template-args args=args nolink=nolink}}{{/if~}}
{{name}}{{/if}}{{#if args}}{{>template-args args=args nolink=nolink}}{{/if~}}{{/if~}}{{/if~}}
103 changes: 103 additions & 0 deletions src/lib/AST/ASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2455,6 +2455,85 @@ class ASTVisitor
*/
void
traverseContext(DeclContext* DC);


bool
isInSpecialNamespace(
const Decl* D,
std::string_view Namespace)
{
if(! D || Namespace.empty())
return false;
const DeclContext* DC = isa<DeclContext>(D) ?
dyn_cast<DeclContext>(D) : D->getDeclContext();
for(; DC; DC = DC->getParent())
{
const NamespaceDecl* ND = dyn_cast<NamespaceDecl>(DC);
if(! ND)
continue;
if(ND->getQualifiedNameAsString() == Namespace)
return true;
}
return false;
}

bool
isInSpecialNamespace(
const NestedNameSpecifier* NNS,
std::string_view Namespace)
{
const NamedDecl* ND = nullptr;
while(NNS)
{
if((ND = NNS->getAsNamespace()))
break;
if((ND = NNS->getAsNamespaceAlias()))
break;
NNS = NNS->getPrefix();
}
return ND && isInSpecialNamespace(ND, Namespace);
}

bool
checkSpecialNamespace(
std::unique_ptr<NameInfo>& I,
const NestedNameSpecifier* NNS,
const Decl* D)
{
if(isInSpecialNamespace(NNS, config_->seeBelow) ||
isInSpecialNamespace(D, config_->seeBelow))
{
I = std::make_unique<NameInfo>();
I->Name = "see-below";
return true;
}

if(isInSpecialNamespace(NNS, config_->implementationDefined) ||
isInSpecialNamespace(D, config_->implementationDefined))
{
I = std::make_unique<NameInfo>();
I->Name = "implementation-defined";
return true;
}
return false;
}

bool
checkSpecialNamespace(
std::unique_ptr<TypeInfo>& I,
const NestedNameSpecifier* NNS,
const Decl* D)
{
std::unique_ptr<NameInfo> Name;
if(checkSpecialNamespace(Name, NNS, D))
{
auto T = std::make_unique<NamedTypeInfo>();
T->Name = std::move(Name);
I = std::move(T);
return true;
}
return false;
}
};

//------------------------------------------------
Expand Down Expand Up @@ -3557,6 +3636,9 @@ class TypeInfoBuilder
unsigned quals,
bool pack)
{
if(getASTVisitor().checkSpecialNamespace(*Inner, NNS, nullptr))
return;

auto I = std::make_unique<NamedTypeInfo>();
I->CVQualifiers = convertToQualifierKind(quals);

Expand All @@ -3577,6 +3659,9 @@ class TypeInfoBuilder
bool pack)
{
ASTVisitor& V = getASTVisitor();
if(V.checkSpecialNamespace(*Inner, NNS, nullptr))
return;

auto I = std::make_unique<NamedTypeInfo>();
I->CVQualifiers = convertToQualifierKind(quals);

Expand Down Expand Up @@ -3610,6 +3695,9 @@ class TypeInfoBuilder
bool pack)
{
ASTVisitor& V = getASTVisitor();
if(V.checkSpecialNamespace(*Inner, NNS, D))
return;

auto I = std::make_unique<NamedTypeInfo>();
I->CVQualifiers = convertToQualifierKind(quals);

Expand Down Expand Up @@ -3687,6 +3775,9 @@ class NameInfoBuilder
unsigned quals,
bool pack)
{
if(getASTVisitor().checkSpecialNamespace(Result, NNS, nullptr))
return;

auto I = std::make_unique<NameInfo>();
I->Name = getASTVisitor().getTypeAsString(T);
Result = std::move(I);
Expand All @@ -3703,6 +3794,9 @@ class NameInfoBuilder
bool pack)
{
ASTVisitor& V = getASTVisitor();
if(V.checkSpecialNamespace(Result, NNS, nullptr))
return;

if(TArgs)
{
auto I = std::make_unique<SpecializationNameInfo>();
Expand Down Expand Up @@ -3731,6 +3825,9 @@ class NameInfoBuilder
bool pack)
{
ASTVisitor& V = getASTVisitor();
if(V.checkSpecialNamespace(Result, NNS, D))
return;

const IdentifierInfo* II = D->getIdentifier();
if(TArgs)
{
Expand Down Expand Up @@ -3765,6 +3862,10 @@ buildNameInfo(
std::unique_ptr<NameInfo> I = nullptr;
if(! NNS)
return I;

if(checkSpecialNamespace(I, NNS, nullptr))
return I;

if(const Type* T = NNS->getAsType())
{
NameInfoBuilder Builder(*this, NNS->getPrefix());
Expand Down Expand Up @@ -3804,6 +3905,8 @@ buildNameInfo(
if(! ND || ND->getKind() == Decl::TranslationUnit)
return nullptr;
auto I = std::make_unique<NameInfo>();
if(checkSpecialNamespace(I, nullptr, ND))
return I;
if(const IdentifierInfo* II = ND->getIdentifier())
I->Name = II->getName();
getDependencyID(getInstantiatedFrom(D), I->id);
Expand Down
3 changes: 3 additions & 0 deletions src/lib/Lib/ConfigImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ struct llvm::yaml::MappingTraits<SettingsImpl>
io.mapOptional("input", cfg.input);

io.mapOptional("filters", cfg.filters);

io.mapOptional("see-below", cfg.seeBelow);
io.mapOptional("implementation-defined", cfg.implementationDefined);
}
};

Expand Down
8 changes: 8 additions & 0 deletions src/lib/Lib/ConfigImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ class ConfigImpl
files referenced in the documentation.
*/
std::string baseURL;

/** Namespace for symbols rendered as "see-below".
*/
std::string seeBelow;

/** Namespace for symbols rendered as "implementation-defined".
*/
std::string implementationDefined;
};

/// @copydoc Config::settings()
Expand Down

0 comments on commit c476746

Please sign in to comment.