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 nodefine attribute #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions include/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ namespace broma {
std::string docs; ///< Any docstring pulled from a `[[docs(...)]]` attribute.
Platform links = Platform::None; ///< All the platforms that link the class or function
Platform missing = Platform::None; ///< All the platforms that are missing the class or function
Platform nodefine = Platform::None; ///< All the platforms that should not define the class or function
std::vector<std::string> depends; ///< List of classes that this class or function depends on
};

Expand Down
27 changes: 26 additions & 1 deletion src/attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ namespace broma {
>
>> {};

struct nodefine_attribute : basic_attribute<TAO_PEGTL_KEYWORD("nodefine"), tagged_rule<nodefine_attribute,
seq<
rule_begin<nodefine_attribute>,
opt<platform_list<nodefine_attribute>>
>
>> {};

/// @brief All allowed C++ attributes.
///
/// Currently, this includes the `docs(...)`, `depends(...)`, `link(...)` and `missing(...)` attributes.
Expand All @@ -64,7 +71,7 @@ namespace broma {
success,
list<seq<
sep,
sor<depends_attribute, link_attribute, missing_attribute>,
sor<depends_attribute, link_attribute, missing_attribute, nodefine_attribute>,
sep
>, one<','>>
>,
Expand Down Expand Up @@ -134,4 +141,22 @@ namespace broma {
}
};

// nodefine

template <>
struct run_action<rule_begin<nodefine_attribute>> {
template <typename T>
static void apply(T& input, Root* root, ScratchData* scratch) {
scratch->wip_attributes.nodefine = Platform::None;
}
};

template <>
struct run_action<tagged_platform<nodefine_attribute>> {
template <typename T>
static void apply(T& input, Root* root, ScratchData* scratch) {
scratch->wip_attributes.nodefine |= str_to_platform(input.string());
}
};

} // namespace broma
1 change: 1 addition & 0 deletions src/function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ namespace broma {
scratch->wip_attributes = Attributes();
scratch->wip_attributes.links = scratch->wip_class.attributes.links;
scratch->wip_attributes.missing = scratch->wip_class.attributes.missing;
scratch->wip_attributes.nodefine = scratch->wip_class.attributes.nodefine;

scratch->wip_mem_fn_proto = MemberFunctionProto();
}
Expand Down