Skip to content

Commit e0a82fb

Browse files
committed
chore: add toString for InfoKind and RecordKeyKind
1 parent 7246747 commit e0a82fb

File tree

7 files changed

+51
-48
lines changed

7 files changed

+51
-48
lines changed

addons/generator/asciidoc/partials/symbol.adoc.hbs

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
{{>namespace}}
33
{{else if (eq symbol.kind "function")}}
44
{{>function}}
5-
{{else if (eq symbol.kind "class")}}
6-
{{>record}}
7-
{{else if (eq symbol.kind "struct")}}
8-
{{>record}}
9-
{{else if (eq symbol.kind "union")}}
5+
{{else if (eq symbol.kind "record")}}
106
{{>record}}
117
{{/if}}

include/mrdox/Metadata/Info.hpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ enum class InfoKind
4747
Specialization
4848
};
4949

50+
MRDOX_DECL
51+
std::string_view
52+
toString(InfoKind kind) noexcept;
53+
5054
/** Common properties of all symbols
5155
*/
5256
struct MRDOX_VISIBLE
@@ -106,14 +110,6 @@ struct MRDOX_VISIBLE
106110
std::string
107111
extractName() const;
108112

109-
/** Return a string representing the symbol type.
110-
111-
For example, "namespace", "class", et. al.
112-
*/
113-
MRDOX_DECL
114-
std::string_view
115-
symbolType() const noexcept;
116-
117113
constexpr bool isNamespace() const noexcept { return Kind == InfoKind::Namespace; }
118114
constexpr bool isRecord() const noexcept { return Kind == InfoKind::Record; }
119115
constexpr bool isFunction() const noexcept { return Kind == InfoKind::Function; }

include/mrdox/Metadata/Record.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ enum class RecordKeyKind
6868
Union
6969
};
7070

71+
MRDOX_DECL
72+
std::string_view
73+
toString(RecordKeyKind kind) noexcept;
74+
7175
/** Metadata for struct, class, or union.
7276
*/
7377
struct RecordInfo

source/-XML/XMLWriter.cpp

+3-9
Original file line numberDiff line numberDiff line change
@@ -335,15 +335,9 @@ writeRecord(
335335
{
336336
openTemplate(I.Template);
337337

338-
llvm::StringRef tagName;
339-
switch(I.KeyKind)
340-
{
341-
case RecordKeyKind::Class: tagName = classTagName; break;
342-
case RecordKeyKind::Struct: tagName = structTagName; break;
343-
case RecordKeyKind::Union: tagName = unionTagName; break;
344-
default:
345-
MRDOX_ASSERT(false);
346-
}
338+
llvm::StringRef tagName =
339+
toString(I.KeyKind);
340+
347341
tags_.open(tagName, {
348342
{ "name", I.Name },
349343
{ I.Access },

source/Dom/DomSymbol.cpp

+2-11
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ get(std::string_view key) const
4141
if(key == "id")
4242
return toBase16(I_->id);
4343
if(key == "kind")
44-
return I_->symbolType();
44+
return toString(I_->Kind);
4545
if(key == "access")
4646
return toString(I_->Access);
4747
if(key == "name")
@@ -72,16 +72,7 @@ get(std::string_view key) const
7272
if constexpr(T::isRecord())
7373
{
7474
if(key == "tag")
75-
{
76-
switch(I_->KeyKind)
77-
{
78-
case RecordKeyKind::Class: return "class";
79-
case RecordKeyKind::Struct: return "struct";
80-
case RecordKeyKind::Union: return "union";
81-
default:
82-
MRDOX_UNREACHABLE();
83-
}
84-
}
75+
return toString(I_->KeyKind);
8576
if(key == "is-typedef")
8677
return I_->IsTypeDef;
8778
if(key == "bases")

source/Metadata/Info.cpp

+3-15
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,14 @@ getFullyQualifiedName(
8585
#endif
8686

8787
std::string_view
88-
Info::
89-
symbolType() const noexcept
88+
toString(InfoKind kind) noexcept
9089
{
91-
switch(this->Kind)
90+
switch(kind)
9291
{
9392
case InfoKind::Namespace:
9493
return "namespace";
9594
case InfoKind::Record:
96-
switch(static_cast<RecordInfo const*>(this)->KeyKind)
97-
{
98-
case RecordKeyKind::Struct:
99-
return "struct";
100-
case RecordKeyKind::Class:
101-
return "class";
102-
case RecordKeyKind::Union:
103-
return "union";
104-
default:
105-
// unknown RecordKeyKind
106-
MRDOX_UNREACHABLE();
107-
}
95+
return "record";
10896
case InfoKind::Field:
10997
return "data";
11098
case InfoKind::Function:

source/Metadata/Record.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
3+
// See https://llvm.org/LICENSE.txt for license information.
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
//
6+
// Copyright (c) 2023 Krystian Stasiowski (sdkrystian@gmail.com)
7+
//
8+
// Official repository: https://github.com/cppalliance/mrdox
9+
//
10+
11+
#include <mrdox/Metadata/Record.hpp>
12+
13+
namespace clang {
14+
namespace mrdox {
15+
16+
std::string_view
17+
toString(RecordKeyKind kind) noexcept
18+
{
19+
switch(kind)
20+
{
21+
case RecordKeyKind::Struct:
22+
return "struct";
23+
case RecordKeyKind::Class:
24+
return "class";
25+
case RecordKeyKind::Union:
26+
return "union";
27+
default:
28+
// unknown RecordKeyKind
29+
MRDOX_UNREACHABLE();
30+
}
31+
}
32+
33+
} // mrdox
34+
} // clang

0 commit comments

Comments
 (0)