-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: represent possibly-qualified names with NameInfo
- Loading branch information
1 parent
0faf7a9
commit aa4e6ff
Showing
15 changed files
with
1,123 additions
and
505 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
share/mrdocs/addons/generator/asciidoc/partials/name-info.adoc.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
Oops, something went wrong.