Skip to content

Commit c4441d4

Browse files
committed
refactor: don't represent using-directives as Info
1 parent 995c8ac commit c4441d4

File tree

19 files changed

+61
-89
lines changed

19 files changed

+61
-89
lines changed

include/mrdocs/Metadata/Info.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ enum class InfoKind
6969
Guide,
7070
/// The symbol is a namespace alias
7171
Alias,
72-
/// The symbol is a using declaration and using directive
72+
/// The symbol is a using declaration
7373
Using,
7474
};
7575

@@ -187,7 +187,7 @@ struct MRDOCS_VISIBLE
187187
/// Determine if this symbol is a namespace alias.
188188
constexpr bool isAlias() const noexcept { return Kind == InfoKind::Alias; }
189189

190-
/// Determine if this symbol is a using declaration or using directive.
190+
/// Determine if this symbol is a using declaration.
191191
constexpr bool isUsing() const noexcept { return Kind == InfoKind::Using; }
192192
};
193193

@@ -245,7 +245,7 @@ struct IsInfo : Info
245245
/// Determine if this symbol is a namespace alias.
246246
static constexpr bool isAlias() noexcept { return K == InfoKind::Alias; }
247247

248-
/// Determine if this symbol is a using declaration or using directive.
248+
/// Determine if this symbol is a using declaration.
249249
static constexpr bool isUsing() noexcept { return K == InfoKind::Using; }
250250

251251
protected:

include/mrdocs/Metadata/Namespace.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ struct NamespaceInfo
3737
{
3838
NamespaceFlags specs;
3939

40+
/** Namespaces nominated by using-directives.
41+
*/
42+
std::vector<SymbolID> UsingDirectives;
43+
4044
//--------------------------------------------
4145

4246
explicit NamespaceInfo(SymbolID ID) noexcept

include/mrdocs/Metadata/Using.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ enum class UsingClass
2626
Normal = 0, // using
2727
Typename, // using typename
2828
Enum, // using enum
29-
Namespace // using namespace (using directive)
3029
};
3130

3231
static constexpr
@@ -38,24 +37,26 @@ toString(UsingClass const& value)
3837
case UsingClass::Normal: return "normal";
3938
case UsingClass::Typename: return "typename";
4039
case UsingClass::Enum: return "enum";
41-
case UsingClass::Namespace: return "namespace";
4240
}
4341
return "unknown";
4442
}
4543

46-
/** Info for using declarations and directives.
44+
/** Info for using declarations.
4745
*/
4846
struct UsingInfo
4947
: IsInfo<InfoKind::Using>,
5048
SourceInfo
5149
{
52-
/** The kind of using declaration/directive. */
50+
/** The kind of using declaration.
51+
*/
5352
UsingClass Class = UsingClass::Normal;
5453

55-
/** The symbols being "used". */
54+
/** The symbols being "used".
55+
*/
5656
std::vector<SymbolID> UsingSymbols;
5757

58-
/** The qualifier for a using declaration/directive. */
58+
/** The qualifier for a using declaration.
59+
*/
5960
std::unique_ptr<NameInfo> Qualifier;
6061

6162
//--------------------------------------------

mrdocs.rnc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ grammar
3535
attribute is-inline { "1" }?,
3636
attribute is-anonymous { "1" }?,
3737
Javadoc?,
38+
element using-directive { ID } *,
3839
Scope
3940
}
4041

@@ -238,7 +239,7 @@ grammar
238239
ID,
239240
Location *,
240241
Javadoc ?,
241-
attribute class { "using" | "using typename" | "using enum" | "using namespace" },
242+
attribute class { "using" | "using typename" | "using enum" },
242243
attribute qualifier { text } ?,
243244
element named { ID } *
244245
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{{#if (eq symbol.class "namespace")}}
2-
using namespace {{#if symbol.qualifier}}{{>name-info symbol.qualifier}}::{{/if}}{{symbol.name}}
3-
{{else}}
4-
using {{#if (eq symbol.class "typename")}}typename {{/if}}{{#if (eq symbol.class "enum")}}enum {{/if}}{{#if symbol.qualifier}}{{>name-info symbol.qualifier}}::{{/if}}{{symbol.name}}
5-
{{/if}}
1+
using {{#if (eq symbol.class "typename")}}typename {{/if}}{{#if (eq symbol.class "enum")}}enum {{/if}}{{#if symbol.qualifier}}{{>name-info symbol.qualifier}}::{{/if}}{{symbol.name~}}

share/mrdocs/addons/generator/asciidoc/partials/symbols/namespace.adoc.hbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
= {{#if symbol.name}}Namespace {{>nested-name-specifier symbol=symbol.parent}}{{symbol.name}}{{else if symbol.parent}}Unnamed namespace{{else}}Global namespace{{/if}}
33

44
{{> tranche tranche=symbol.interface label="" is-namespace=true}}
5+
6+
{{>info-list members=symbol.usingDirectives title="Using Directives"}}

share/mrdocs/addons/generator/asciidoc/partials/symbols/using.adoc.hbs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{!-- symbols/using.adoc.hbs --}}
2-
= Using {{#if (eq symbol.class "namespace")}}Directive: {{symbol.qualifier.name}}{{else}}Declaration: {{symbol.name}}{{/if}}
2+
= Using Declaration {{symbol.name}}
33

44
{{symbol.doc.brief}}
55

@@ -19,13 +19,14 @@
1919
2020
{{/if}}
2121
22-
{{#unless (eq symbol.class "namespace")}}
22+
{{#if symbol.shadows}}
2323
== Introduced Symbols
2424
2525
|===
2626
| Name
27-
{{#each symbol.symbols}}
27+
{{#each symbol.shadows}}
2828
| {{name}}
2929
{{/each}}
3030
|===
31-
{{/unless}}
31+
32+
{{/if}}

share/mrdocs/addons/generator/asciidoc/partials/tranche.adoc.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
{{>info-list members=tranche.variables title=(concat label " " "Static Data Members")}}
1212
{{>info-list members=tranche.friends title=(concat label " " "Friends")}}
1313
{{>info-list members=tranche.aliases title=(concat label " " "Aliases")}}
14-
{{>info-list members=tranche.usings title=(concat label " " "Usings Declarations/Directives")}}
14+
{{>info-list members=tranche.usings title=(concat label " " "Usings Declarations")}}
1515
{{/if}}
1616
{{>info-list members=tranche.guides title=(concat label " " "Deduction Guides")}}

src/lib/AST/ASTVisitor.cpp

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,8 @@ class ASTVisitor
436436
std::pair<InfoTy&, bool>
437437
getOrCreateInfo(const SymbolID& id)
438438
{
439+
assert(id != SymbolID::invalid &&
440+
"creating symbol with invalid SymbolID?");
439441
Info* info = getInfo(id);
440442
bool created = ! info;
441443
if(! info)
@@ -535,17 +537,6 @@ class ASTVisitor
535537
return false;
536538
}
537539

538-
// Handling UsingDirectiveDecl
539-
if (const auto* UDD = dyn_cast<UsingDirectiveDecl>(D))
540-
{
541-
if (index::generateUSRForDecl(UDD->getNominatedNamespace(), usr_)) {
542-
return true;
543-
}
544-
usr_.append("@UD");
545-
usr_.append(UDD->getQualifiedNameAsString());
546-
return false;
547-
}
548-
549540
// Handling UsingDecl
550541
if (const auto* UD = dyn_cast<UsingDecl>(D))
551542
{
@@ -2194,39 +2185,6 @@ class ASTVisitor
21942185
getParentNamespaces(I, D);
21952186
}
21962187

2197-
2198-
//------------------------------------------------
2199-
2200-
void
2201-
buildUsingDirective(
2202-
UsingInfo& I,
2203-
bool created,
2204-
UsingDirectiveDecl* D)
2205-
{
2206-
bool documented = parseRawComment(I.javadoc, D);
2207-
addSourceLocation(I, D->getBeginLoc(), true, documented);
2208-
2209-
if(! created)
2210-
return;
2211-
2212-
I.Class = UsingClass::Namespace;
2213-
2214-
if (D->getQualifier())
2215-
{
2216-
I.Qualifier = buildNameInfo(D->getQualifier());
2217-
}
2218-
2219-
if (NamedDecl* ND = D->getNominatedNamespace())
2220-
{
2221-
I.Name = extractName(ND);
2222-
SymbolID id;
2223-
getDependencyID(ND, id);
2224-
I.UsingSymbols.emplace_back(id);
2225-
}
2226-
getParentNamespaces(I, D);
2227-
}
2228-
2229-
22302188
//------------------------------------------------
22312189

22322190
void
@@ -2601,12 +2559,23 @@ void
26012559
ASTVisitor::
26022560
traverse(UsingDirectiveDecl* D)
26032561
{
2604-
auto exp = getAsMrDocsInfo(D);
2605-
if(! exp) { return; }
2606-
auto [I, created] = *exp;
2607-
buildUsingDirective(I, created, D);
2608-
}
2562+
if(! shouldExtract(D, getAccess(D)))
2563+
return;
26092564

2565+
Decl* PD = getParentDecl(D);
2566+
// only extract using-directives in namespace scope
2567+
if(! cast<DeclContext>(PD)->isFileContext())
2568+
return;
2569+
2570+
if(Info* PI = getInfo(extractSymbolID(PD)))
2571+
{
2572+
assert(PI->isNamespace());
2573+
NamespaceInfo* NI = static_cast<NamespaceInfo*>(PI);
2574+
getDependencyID(
2575+
D->getNominatedNamespaceAsWritten(),
2576+
NI->UsingDirectives.emplace_back());
2577+
}
2578+
}
26102579

26112580
//------------------------------------------------
26122581
// UsingDecl

src/lib/AST/ASTVisitorHelpers.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ struct MrDocsType<CXXDeductionGuideDecl> : std::type_identity<GuideInfo> {};
5858
template <>
5959
struct MrDocsType<NamespaceAliasDecl> : std::type_identity<AliasInfo> {};
6060

61-
template <>
62-
struct MrDocsType<UsingDirectiveDecl> : std::type_identity<UsingInfo> {};
63-
6461
template <>
6562
struct MrDocsType<UsingDecl> : std::type_identity<UsingInfo> {};
6663

0 commit comments

Comments
 (0)