-
Notifications
You must be signed in to change notification settings - Fork 23
feat: uniform attribute extraction #1237
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
Merged
alandefreitas
merged 1 commit into
cppalliance:develop
from
alandefreitas:feat/document-attributes
Jun 22, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,41 @@ | ||
| // | ||
| // 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) 2026 Alan de Freitas (alandefreitas@gmail.com) | ||
| // | ||
| // Official repository: https://github.com/cppalliance/mrdocs | ||
| // | ||
|
|
||
| #ifndef MRDOCS_API_METADATA_ATTRIBUTE_ASSUMEATTRIBUTE_HPP | ||
| #define MRDOCS_API_METADATA_ATTRIBUTE_ASSUMEATTRIBUTE_HPP | ||
|
|
||
| #include <mrdocs/Platform.hpp> | ||
| #include <mrdocs/Metadata/Attribute/AttributeBase.hpp> | ||
| #include <mrdocs/Support/Describe.hpp> | ||
| #include <string> | ||
|
|
||
| namespace mrdocs { | ||
|
|
||
| /** The `[[assume(expression)]]` attribute (C++23). | ||
|
|
||
| States that the expression always evaluates to true at this point. | ||
| */ | ||
| struct AssumeAttribute final | ||
| : AttributeCommonBase<AttributeKind::Assume> | ||
| { | ||
| /** The assumed expression, as written. | ||
| */ | ||
| std::string Expression; | ||
| }; | ||
|
|
||
| MRDOCS_DESCRIBE_STRUCT( | ||
| AssumeAttribute, | ||
| (Attribute), | ||
| (Expression) | ||
| ) | ||
|
|
||
| } // mrdocs | ||
|
|
||
| #endif // MRDOCS_API_METADATA_ATTRIBUTE_ASSUMEATTRIBUTE_HPP |
This file contains hidden or 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,179 @@ | ||
| // | ||
| // 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) 2026 Alan de Freitas (alandefreitas@gmail.com) | ||
| // | ||
| // Official repository: https://github.com/cppalliance/mrdocs | ||
| // | ||
|
|
||
| #ifndef MRDOCS_API_METADATA_ATTRIBUTE_ATTRIBUTEBASE_HPP | ||
| #define MRDOCS_API_METADATA_ATTRIBUTE_ATTRIBUTEBASE_HPP | ||
|
|
||
| #include <mrdocs/Platform.hpp> | ||
| #include <mrdocs/ADT/Polymorphic.hpp> | ||
| #include <mrdocs/Metadata/Attribute/AttributeKind.hpp> | ||
| #include <mrdocs/Support/CompareReflectedType.hpp> | ||
| #include <mrdocs/Support/Describe.hpp> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| namespace mrdocs { | ||
|
|
||
| class DomCorpus; | ||
|
|
||
| /* Forward declarations | ||
| */ | ||
| #define INFO(PascalName) struct PascalName##Attribute; | ||
| #include <mrdocs/Metadata/Attribute/AttributeNodes.inc> | ||
|
|
||
| /** A C++ attribute attached to a symbol. | ||
|
|
||
| This base class stores the information common to every | ||
| attribute: the kind, the spelling name, and the raw | ||
| balanced-token sequence written between the parentheses. | ||
| Derived classes add the evaluated arguments for the | ||
| attributes that take them. | ||
| */ | ||
| struct Attribute { | ||
| /** The kind of attribute. | ||
| */ | ||
| AttributeKind Kind; | ||
|
|
||
| /** The attribute name as it appears in the standard form. | ||
|
|
||
| For recognized attributes this is the normalized spelling | ||
| (e.g. `deprecated`, `no_unique_address`). For unrecognized | ||
| attributes (the `Other` kind) it is the spelling as written, | ||
| including any scope (e.g. `gnu::custom`). | ||
| */ | ||
| std::string Name; | ||
|
|
||
| /** The attribute arguments as a balanced-token sequence. | ||
|
|
||
| Each element is one top-level argument as rendered by Clang, | ||
| e.g. `{"printf", "1", "2"}` for `[[gnu::format(printf, 1, 2)]]`. | ||
| Empty for attributes that take no arguments. This is the raw | ||
| token form; derived classes expose evaluated arguments. | ||
| */ | ||
| std::vector<std::string> balancedTokens; | ||
|
|
||
| /** View this instance as a const Attribute reference. | ||
| */ | ||
| constexpr Attribute const& asAttribute() const noexcept | ||
| { | ||
| return *this; | ||
| } | ||
|
|
||
| /** View this instance as a mutable Attribute reference. | ||
| */ | ||
| constexpr Attribute& asAttribute() noexcept | ||
| { | ||
| return *this; | ||
| } | ||
|
|
||
| #define INFO(PascalName) constexpr bool is##PascalName() const noexcept { \ | ||
| return Kind == AttributeKind::PascalName; \ | ||
| } | ||
| #include <mrdocs/Metadata/Attribute/AttributeNodes.inc> | ||
|
|
||
| #define INFO(PascalName) \ | ||
| constexpr PascalName##Attribute const& as##PascalName() const noexcept { \ | ||
| if (Kind == AttributeKind::PascalName) \ | ||
| return reinterpret_cast<PascalName##Attribute const&>(*this); \ | ||
| MRDOCS_UNREACHABLE(); \ | ||
| } | ||
| #include <mrdocs/Metadata/Attribute/AttributeNodes.inc> | ||
|
|
||
| #define INFO(PascalName) \ | ||
| constexpr PascalName##Attribute & as##PascalName() noexcept { \ | ||
| if (Kind == AttributeKind::PascalName) \ | ||
| return reinterpret_cast<PascalName##Attribute&>(*this); \ | ||
| MRDOCS_UNREACHABLE(); \ | ||
| } | ||
| #include <mrdocs/Metadata/Attribute/AttributeNodes.inc> | ||
|
|
||
| #define INFO(PascalName) \ | ||
| constexpr PascalName##Attribute const* as##PascalName##Ptr() const noexcept { \ | ||
| if (Kind == AttributeKind::PascalName) { return reinterpret_cast<PascalName##Attribute const*>(this); } \ | ||
| return nullptr; \ | ||
| } | ||
| #include <mrdocs/Metadata/Attribute/AttributeNodes.inc> | ||
|
|
||
| #define INFO(PascalName) \ | ||
| constexpr PascalName##Attribute * as##PascalName##Ptr() noexcept { \ | ||
| if (Kind == AttributeKind::PascalName) { return reinterpret_cast<PascalName##Attribute *>(this); } \ | ||
| return nullptr; \ | ||
| } | ||
| #include <mrdocs/Metadata/Attribute/AttributeNodes.inc> | ||
|
|
||
| protected: | ||
| /** Virtual destructor for polymorphic base. | ||
| */ | ||
| constexpr virtual ~Attribute() = default; | ||
|
|
||
| /** Construct with a concrete attribute kind. | ||
| */ | ||
| constexpr explicit Attribute(AttributeKind kind) noexcept | ||
| : Kind(kind) | ||
| { | ||
| } | ||
| }; | ||
|
|
||
| MRDOCS_DESCRIBE_STRUCT( | ||
| Attribute, | ||
| (), | ||
| (Kind, Name, balancedTokens) | ||
| ) | ||
|
|
||
| /** Serialize an Attribute into a DOM value. | ||
| */ | ||
| MRDOCS_DECL | ||
| void | ||
| tag_invoke( | ||
| dom::ValueFromTag, | ||
| dom::Value& v, | ||
| Attribute const& I, | ||
| DomCorpus const* domCorpus); | ||
|
|
||
| /** CRTP base that ties a concrete attribute to a fixed AttributeKind. | ||
| */ | ||
| template<AttributeKind K> | ||
| struct AttributeCommonBase : Attribute { | ||
| /** Static discriminator for the concrete attribute. | ||
| */ | ||
| static constexpr AttributeKind kind_id = K; | ||
|
|
||
| #define INFO(PascalName) \ | ||
| static constexpr bool is##PascalName() noexcept { return K == AttributeKind::PascalName; } | ||
| #include <mrdocs/Metadata/Attribute/AttributeNodes.inc> | ||
|
|
||
| MRDOCS_DESCRIBE_CLASS(AttributeCommonBase, (Attribute), ()) | ||
|
|
||
| protected: | ||
| /** Construct the base with the fixed kind. | ||
| */ | ||
| constexpr AttributeCommonBase() noexcept | ||
| : Attribute(K) | ||
| { | ||
| } | ||
| }; | ||
|
|
||
| /** Compare two polymorphic attributes by visitor dispatch. | ||
| */ | ||
| MRDOCS_DECL | ||
| std::strong_ordering | ||
| operator<=>(Polymorphic<Attribute> const&, Polymorphic<Attribute> const&); | ||
|
|
||
| /** Equality for two polymorphic attributes. | ||
| */ | ||
| inline bool | ||
| operator==(Polymorphic<Attribute> const& a, Polymorphic<Attribute> const& b) | ||
| { | ||
| return std::is_eq(a <=> b); | ||
| } | ||
|
|
||
| } // mrdocs | ||
|
|
||
| #endif // MRDOCS_API_METADATA_ATTRIBUTE_ATTRIBUTEBASE_HPP |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.