Skip to content

Commit

Permalink
chore: add toString for InfoKind and RecordKeyKind
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkrystian committed Jun 19, 2023
1 parent 7246747 commit e0a82fb
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 48 deletions.
6 changes: 1 addition & 5 deletions addons/generator/asciidoc/partials/symbol.adoc.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
{{>namespace}}
{{else if (eq symbol.kind "function")}}
{{>function}}
{{else if (eq symbol.kind "class")}}
{{>record}}
{{else if (eq symbol.kind "struct")}}
{{>record}}
{{else if (eq symbol.kind "union")}}
{{else if (eq symbol.kind "record")}}
{{>record}}
{{/if}}
12 changes: 4 additions & 8 deletions include/mrdox/Metadata/Info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ enum class InfoKind
Specialization
};

MRDOX_DECL
std::string_view
toString(InfoKind kind) noexcept;

/** Common properties of all symbols
*/
struct MRDOX_VISIBLE
Expand Down Expand Up @@ -106,14 +110,6 @@ struct MRDOX_VISIBLE
std::string
extractName() const;

/** Return a string representing the symbol type.
For example, "namespace", "class", et. al.
*/
MRDOX_DECL
std::string_view
symbolType() const noexcept;

constexpr bool isNamespace() const noexcept { return Kind == InfoKind::Namespace; }
constexpr bool isRecord() const noexcept { return Kind == InfoKind::Record; }
constexpr bool isFunction() const noexcept { return Kind == InfoKind::Function; }
Expand Down
4 changes: 4 additions & 0 deletions include/mrdox/Metadata/Record.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ enum class RecordKeyKind
Union
};

MRDOX_DECL
std::string_view
toString(RecordKeyKind kind) noexcept;

/** Metadata for struct, class, or union.
*/
struct RecordInfo
Expand Down
12 changes: 3 additions & 9 deletions source/-XML/XMLWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,9 @@ writeRecord(
{
openTemplate(I.Template);

llvm::StringRef tagName;
switch(I.KeyKind)
{
case RecordKeyKind::Class: tagName = classTagName; break;
case RecordKeyKind::Struct: tagName = structTagName; break;
case RecordKeyKind::Union: tagName = unionTagName; break;
default:
MRDOX_ASSERT(false);
}
llvm::StringRef tagName =
toString(I.KeyKind);

tags_.open(tagName, {
{ "name", I.Name },
{ I.Access },
Expand Down
13 changes: 2 additions & 11 deletions source/Dom/DomSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ get(std::string_view key) const
if(key == "id")
return toBase16(I_->id);
if(key == "kind")
return I_->symbolType();
return toString(I_->Kind);
if(key == "access")
return toString(I_->Access);
if(key == "name")
Expand Down Expand Up @@ -72,16 +72,7 @@ get(std::string_view key) const
if constexpr(T::isRecord())
{
if(key == "tag")
{
switch(I_->KeyKind)
{
case RecordKeyKind::Class: return "class";
case RecordKeyKind::Struct: return "struct";
case RecordKeyKind::Union: return "union";
default:
MRDOX_UNREACHABLE();
}
}
return toString(I_->KeyKind);
if(key == "is-typedef")
return I_->IsTypeDef;
if(key == "bases")
Expand Down
18 changes: 3 additions & 15 deletions source/Metadata/Info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,14 @@ getFullyQualifiedName(
#endif

std::string_view
Info::
symbolType() const noexcept
toString(InfoKind kind) noexcept
{
switch(this->Kind)
switch(kind)
{
case InfoKind::Namespace:
return "namespace";
case InfoKind::Record:
switch(static_cast<RecordInfo const*>(this)->KeyKind)
{
case RecordKeyKind::Struct:
return "struct";
case RecordKeyKind::Class:
return "class";
case RecordKeyKind::Union:
return "union";
default:
// unknown RecordKeyKind
MRDOX_UNREACHABLE();
}
return "record";
case InfoKind::Field:
return "data";
case InfoKind::Function:
Expand Down
34 changes: 34 additions & 0 deletions source/Metadata/Record.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2023 Krystian Stasiowski ([email protected])
//
// Official repository: https://github.com/cppalliance/mrdox
//

#include <mrdox/Metadata/Record.hpp>

namespace clang {
namespace mrdox {

std::string_view
toString(RecordKeyKind kind) noexcept
{
switch(kind)
{
case RecordKeyKind::Struct:
return "struct";
case RecordKeyKind::Class:
return "class";
case RecordKeyKind::Union:
return "union";
default:
// unknown RecordKeyKind
MRDOX_UNREACHABLE();
}
}

} // mrdox
} // clang

0 comments on commit e0a82fb

Please sign in to comment.