Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EnumeratorInfo and FriendInfo #477

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions include/mrdocs/Corpus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ class MRDOCS_VISIBLE
RecordInfo const& I,
F&& f, Args&&... args) const;

template<class F, class... Args>
void traverse(
EnumInfo const& I,
F&& f, Args&&... args) const;

template<class F, class... Args>
void traverse(
SpecializationInfo const& I,
Expand Down Expand Up @@ -178,6 +183,18 @@ traverse(
std::forward<Args>(args)...);
}

template<class F, class... Args>
void
Corpus::
traverse(
EnumInfo const& I,
F&& f, Args&&... args) const
{
for(auto const& id : I.Members)
visit(get(id), std::forward<F>(f),
std::forward<Args>(args)...);
}

template<class F, class... Args>
void
Corpus::
Expand Down
2 changes: 2 additions & 0 deletions include/mrdocs/Metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
// metadata extracted from AST

#include <mrdocs/Metadata/Enum.hpp>
#include <mrdocs/Metadata/Enumerator.hpp>
#include <mrdocs/Metadata/Expression.hpp>
#include <mrdocs/Metadata/Field.hpp>
#include <mrdocs/Metadata/Friend.hpp>
#include <mrdocs/Metadata/Function.hpp>
#include <mrdocs/Metadata/Info.hpp>
#include <mrdocs/Metadata/Interface.hpp>
Expand Down
30 changes: 2 additions & 28 deletions include/mrdocs/Metadata/Enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,6 @@
namespace clang {
namespace mrdocs {

// Information for a single possible value of an enumeration.
struct EnumValueInfo
{
std::string Name;

/** The initializer expression, if any */
ConstantExprInfo<std::uint64_t> Initializer;

/** The documentation for the value, if any.
*/
std::unique_ptr<Javadoc> javadoc;

//--------------------------------------------

explicit
EnumValueInfo(
std::string_view Name = "")
: Name(Name)
{
}
};

//------------------------------------------------

// TODO: Expand to allow for documenting templating.
// Info for types.
struct EnumInfo
Expand All @@ -64,13 +40,11 @@ struct EnumInfo
std::unique_ptr<TypeInfo> UnderlyingType;

// Enumeration members.
std::vector<EnumValueInfo> Members;
std::vector<SymbolID> Members;

//--------------------------------------------

explicit
EnumInfo(
SymbolID ID = SymbolID::invalid)
explicit EnumInfo(SymbolID ID) noexcept
: IsInfo(ID)
{
}
Expand Down
45 changes: 45 additions & 0 deletions include/mrdocs/Metadata/Enumerator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// 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 (sdkrystian@gmail.com)
//
// Official repository: https://github.com/cppalliance/mrdocs
//

#ifndef MRDOCS_API_METADATA_ENUMERATOR_HPP
#define MRDOCS_API_METADATA_ENUMERATOR_HPP

#include <mrdocs/Platform.hpp>
#include <mrdocs/Metadata/Expression.hpp>
#include <mrdocs/Metadata/Info.hpp>
#include <mrdocs/Metadata/Source.hpp>
#include <mrdocs/Metadata/Type.hpp>
#include <utility>

namespace clang {
namespace mrdocs {

/** Info for enumerators.
*/
struct EnumeratorInfo
: IsInfo<InfoKind::Enumerator>
, SourceInfo
{
/** The initializer expression, if any
*/
ConstantExprInfo<std::uint64_t> Initializer;

//--------------------------------------------

explicit EnumeratorInfo(SymbolID ID) noexcept
: IsInfo(ID)
{
}
};

} // mrdocs
} // clang

#endif
4 changes: 1 addition & 3 deletions include/mrdocs/Metadata/Field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ struct FieldInfo

//--------------------------------------------

explicit
FieldInfo(
SymbolID ID = SymbolID::invalid) noexcept
explicit FieldInfo(SymbolID ID) noexcept
: IsInfo(ID)
{
}
Expand Down
48 changes: 48 additions & 0 deletions include/mrdocs/Metadata/Friend.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// 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 (sdkrystian@gmail.com)
//
// Official repository: https://github.com/cppalliance/mrdocs
//

#ifndef MRDOCS_API_METADATA_FRIEND_HPP
#define MRDOCS_API_METADATA_FRIEND_HPP

#include <mrdocs/Platform.hpp>
#include <mrdocs/Metadata/Info.hpp>
#include <mrdocs/Metadata/Source.hpp>
#include <mrdocs/Metadata/Type.hpp>
#include <utility>

namespace clang {
namespace mrdocs {

/** Info for friend declarations.
*/
struct FriendInfo
: IsInfo<InfoKind::Friend>
, SourceInfo
{
/** Befriended symbol.
*/
SymbolID FriendSymbol = SymbolID::invalid;

/** Befriended type.
*/
std::unique_ptr<TypeInfo> FriendType;

//--------------------------------------------

explicit FriendInfo(SymbolID ID) noexcept
: IsInfo(ID)
{
}
};

} // mrdocs
} // clang

#endif
4 changes: 1 addition & 3 deletions include/mrdocs/Metadata/Function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ struct FunctionInfo

//--------------------------------------------

explicit
FunctionInfo(
SymbolID ID = SymbolID::invalid)
explicit FunctionInfo(SymbolID ID) noexcept
: IsInfo(ID)
{
}
Expand Down
35 changes: 17 additions & 18 deletions include/mrdocs/Metadata/Info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,23 @@ struct FieldInfo;
struct TypedefInfo;
struct VariableInfo;
struct SpecializationInfo;
struct FriendInfo;
struct EnumeratorInfo;

/** Info variant discriminator
*/
enum class InfoKind
{
Namespace = 0,
Namespace = 1, // for bitstream
Record,
Function,
Enum,
Typedef,
Variable,
Field,
Specialization
Specialization,
Friend,
Enumerator
};

MRDOCS_DECL dom::String toString(InfoKind kind) noexcept;
Expand All @@ -59,7 +63,7 @@ struct MRDOCS_VISIBLE
{
/** The unique identifier for this symbol.
*/
SymbolID id = SymbolID::invalid;
SymbolID id;

/** The unqualified name.
*/
Expand Down Expand Up @@ -91,7 +95,7 @@ struct MRDOCS_VISIBLE
conditions for extraction, but was extracted due to it being used
by a primary `Info`.
*/
bool Implicit = true;
bool Implicit = false;

/** In-order List of parent namespaces.
*/
Expand All @@ -110,20 +114,12 @@ struct MRDOCS_VISIBLE
explicit
Info(
InfoKind kind,
SymbolID ID = SymbolID::invalid) noexcept
SymbolID ID) noexcept
: id(ID)
, Kind(kind)
{
}

//
// Observers
//

MRDOCS_DECL
std::string
extractName() const;

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 All @@ -132,6 +128,8 @@ struct MRDOCS_VISIBLE
constexpr bool isVariable() const noexcept { return Kind == InfoKind::Variable; }
constexpr bool isField() const noexcept { return Kind == InfoKind::Field; }
constexpr bool isSpecialization() const noexcept { return Kind == InfoKind::Specialization; }
constexpr bool isFriend() const noexcept { return Kind == InfoKind::Friend; }
constexpr bool isEnumerator() const noexcept { return Kind == InfoKind::Enumerator; }
};

//------------------------------------------------
Expand All @@ -157,13 +155,10 @@ struct IsInfo : Info
static constexpr bool isVariable() noexcept { return K == InfoKind::Variable; }
static constexpr bool isField() noexcept { return K == InfoKind::Field; }
static constexpr bool isSpecialization() noexcept { return K == InfoKind::Specialization; }
static constexpr bool isFriend() noexcept { return K == InfoKind::Friend; }
static constexpr bool isEnumerator() noexcept { return K == InfoKind::Enumerator; }

protected:
constexpr IsInfo()
: Info(K)
{
}

constexpr explicit IsInfo(SymbolID ID)
: Info(K, ID)
{
Expand Down Expand Up @@ -204,6 +199,10 @@ visit(
return visitor.template visit<FieldInfo>();
case InfoKind::Specialization:
return visitor.template visit<SpecializationInfo>();
case InfoKind::Friend:
return visitor.template visit<FriendInfo>();
case InfoKind::Enumerator:
return visitor.template visit<EnumeratorInfo>();
default:
MRDOCS_UNREACHABLE();
}
Expand Down
2 changes: 2 additions & 0 deletions include/mrdocs/Metadata/Interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Interface
std::span<FieldInfo const*> Data;
std::span<FunctionInfo const*> StaticFunctions;
std::span<VariableInfo const*> StaticData;
std::span<FriendInfo const*> Friends;
};

Corpus const& corpus;
Expand Down Expand Up @@ -74,6 +75,7 @@ class Interface
std::vector<FieldInfo const*> data_;
std::vector<FunctionInfo const*> staticfuncs_;
std::vector<VariableInfo const*> staticdata_;
std::vector<FriendInfo const*> friends_;
};

//------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions include/mrdocs/Metadata/Namespace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ struct NamespaceInfo

//--------------------------------------------

explicit
NamespaceInfo(
SymbolID ID = SymbolID::invalid)
explicit NamespaceInfo(SymbolID ID) noexcept
: IsInfo(ID)
{
}
Expand Down
8 changes: 1 addition & 7 deletions include/mrdocs/Metadata/Record.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ struct RecordInfo
*/
std::vector<BaseInfo> Bases;

/** List of friend functions.
*/
std::vector<SymbolID> Friends;

/** Record members
*/
std::vector<SymbolID> Members;
Expand All @@ -111,9 +107,7 @@ struct RecordInfo

//--------------------------------------------

explicit
RecordInfo(
SymbolID ID = SymbolID::invalid)
explicit RecordInfo(SymbolID ID) noexcept
: IsInfo(ID)
{
}
Expand Down
4 changes: 1 addition & 3 deletions include/mrdocs/Metadata/Specialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ struct SpecializationInfo
*/
std::vector<SpecializedMember> Members;

explicit
SpecializationInfo(
SymbolID ID = SymbolID::invalid)
explicit SpecializationInfo(SymbolID ID) noexcept
: IsInfo(ID)
{
}
Expand Down
4 changes: 1 addition & 3 deletions include/mrdocs/Metadata/Typedef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ struct TypedefInfo

//--------------------------------------------

explicit
TypedefInfo(
SymbolID ID = SymbolID::invalid)
explicit TypedefInfo(SymbolID ID) noexcept
: IsInfo(ID)
{
}
Expand Down
4 changes: 1 addition & 3 deletions include/mrdocs/Metadata/Variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ struct VariableInfo

//--------------------------------------------

explicit
VariableInfo(
SymbolID ID = SymbolID::invalid) noexcept
explicit VariableInfo(SymbolID ID) noexcept
: IsInfo(ID)
{
}
Expand Down
Loading