Skip to content

Commit

Permalink
feat: represent possibly-qualified names with NameInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkrystian committed Dec 13, 2023
1 parent 0faf7a9 commit aa4e6ff
Show file tree
Hide file tree
Showing 15 changed files with 1,123 additions and 505 deletions.
1 change: 1 addition & 0 deletions include/mrdocs/Metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <mrdocs/Metadata/Info.hpp>
#include <mrdocs/Metadata/Interface.hpp>
#include <mrdocs/Metadata/Javadoc.hpp>
#include <mrdocs/Metadata/Name.hpp>
#include <mrdocs/Metadata/Namespace.hpp>
#include <mrdocs/Metadata/Overloads.hpp>
#include <mrdocs/Metadata/Record.hpp>
Expand Down
112 changes: 112 additions & 0 deletions include/mrdocs/Metadata/Name.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
//
// 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/mrdocs
//

#ifndef MRDOCS_API_METADATA_NAME_HPP
#define MRDOCS_API_METADATA_NAME_HPP

#include <mrdocs/Platform.hpp>
#include <mrdocs/Metadata/Info.hpp>
#include <mrdocs/Metadata/Type.hpp>
#include <mrdocs/Metadata/Template.hpp>
#include <memory>

namespace clang {
namespace mrdocs {

enum class NameKind
{
Identifier = 1, // for bitstream
Specialization
};

MRDOCS_DECL
dom::String
toString(NameKind kind) noexcept;

/** Represents a (possibly qualified) symbol name.
*/
struct NameInfo
{
/** The kind of name this is.
*/
NameKind Kind;

/** The SymbolID of the named symbol, if it exists.
*/
SymbolID id = SymbolID::invalid;

/** The unqualified name.
*/
std::string Name;

/** The parent name info, if any.
*/
std::unique_ptr<NameInfo> Prefix;

constexpr
NameInfo() noexcept
: NameInfo(NameKind::Identifier)
{
}

constexpr
NameInfo(NameKind kind) noexcept
: Kind(kind)
{
}

virtual ~NameInfo() = default;
};

/** Represents a (possibly qualified) symbol name with template arguments.
*/
struct SpecializationNameInfo
: NameInfo
{
/** The template arguments.
*/
std::vector<std::unique_ptr<TArg>> TemplateArgs;

constexpr
SpecializationNameInfo() noexcept
: NameInfo(NameKind::Specialization)
{
}
};

template<
class NameInfoTy,
class Fn,
class... Args>
requires std::derived_from<NameInfoTy, NameInfo>
decltype(auto)
visit(
NameInfoTy& info,
Fn&& fn,
Args&&... args)
{
auto visitor = makeVisitor<NameInfo>(
info, std::forward<Fn>(fn),
std::forward<Args>(args)...);
switch(info.Kind)
{
case NameKind::Identifier:
return visitor.template visit<NameInfo>();
case NameKind::Specialization:
return visitor.template visit<SpecializationNameInfo>();
default:
MRDOCS_UNREACHABLE();
}
}

} // mrdocs
} // clang

#endif
6 changes: 6 additions & 0 deletions include/mrdocs/Metadata/Type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ struct BuiltinTypeInfo
{
QualifierKind CVQualifiers = QualifierKind::None;
std::string Name;

std::unique_ptr<NameInfo> Name_;
};

struct TagTypeInfo
Expand All @@ -131,6 +133,8 @@ struct TagTypeInfo
std::unique_ptr<TypeInfo> ParentType;
std::string Name;
SymbolID id = SymbolID::invalid;

std::unique_ptr<NameInfo> Name_;
};

struct SpecializationTypeInfo
Expand All @@ -141,6 +145,8 @@ struct SpecializationTypeInfo
std::string Name;
SymbolID id = SymbolID::invalid;
std::vector<std::unique_ptr<TArg>> TemplateArgs;

std::unique_ptr<NameInfo> Name_;
};

struct DecltypeTypeInfo
Expand Down
1 change: 1 addition & 0 deletions include/mrdocs/MetadataFwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct Info;
class Javadoc;
struct Location;
struct NamespaceInfo;
struct NameInfo;
struct RecordInfo;
struct Param;
struct SpecializationInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
{{#if cv-qualifiers~}}
{{#if pointee-type}} {{cv-qualifiers}}{{else}}{{cv-qualifiers}} {{/if~}}
{{/if~}}
{{#if (and symbol (not parent-type))}}{{>qualified-path symbol=symbol.parent nolink=nolink}}{{/if~}}
{{#if prefix~}}{{>name-info prefix nolink=nolink}}{{/if~}}
{{!-- {{#if (and symbol (not parent-type))}}{{>qualified-path symbol=symbol.parent nolink=nolink}}{{/if~}} --~}}
{{#if (and symbol (not nolink))~}}
xref:{{symbol.ref}}[{{name}}]
{{~else if name}}{{name~}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{#unless (or (contains @root.symbol.namespace symbol) (eq @root.symbol symbol))~}}
{{#if prefix~}}
{{>name-info prefix nolink=nolink~}}
{{else~}}
{{/if~}}
{{#if (and symbol.ref (not nolink))}}xref:{{symbol.ref}}[{{name}}]{{else~}}
{{name}}{{/if}}{{#if args}}{{>template-args args=args nolink=nolink}}{{/if}}::
{{~/unless}}
Loading

0 comments on commit aa4e6ff

Please sign in to comment.