Refactored apply_if helper functions
This commit is contained in:
@@ -499,7 +499,7 @@ template_parameter template_builder::process_template_expansion(
|
||||
|
||||
LOG_DBG("Processing template expansion argument: {}", arg_name);
|
||||
|
||||
util::apply_if_not_null(
|
||||
util::if_not_null(
|
||||
arg.getAsTemplate().getAsTemplateDecl(), [&arg_name](const auto *decl) {
|
||||
arg_name = decl->getQualifiedNameAsString();
|
||||
});
|
||||
|
||||
@@ -495,7 +495,7 @@ void translation_unit_visitor::process_constraint_requirements(
|
||||
llvm::dyn_cast<clang::concepts::ExprRequirement>(req);
|
||||
|
||||
if (simple_req != nullptr) {
|
||||
util::apply_if_not_null(
|
||||
util::if_not_null(
|
||||
simple_req->getExpr(), [&concept_model](const auto *e) {
|
||||
auto simple_expr = common::to_string(e);
|
||||
|
||||
@@ -507,7 +507,7 @@ void translation_unit_visitor::process_constraint_requirements(
|
||||
}
|
||||
}
|
||||
else if (req->getKind() == clang::concepts::Requirement::RK_Type) {
|
||||
util::apply_if_not_null(
|
||||
util::if_not_null(
|
||||
llvm::dyn_cast<clang::concepts::TypeRequirement>(req),
|
||||
[&concept_model, cpt](const auto *t) {
|
||||
auto type_name = common::to_string(
|
||||
@@ -525,7 +525,7 @@ void translation_unit_visitor::process_constraint_requirements(
|
||||
llvm::dyn_cast<clang::concepts::NestedRequirement>(req);
|
||||
|
||||
if (nested_req != nullptr) {
|
||||
util::apply_if_not_null(
|
||||
util::if_not_null(
|
||||
nested_req->getConstraintExpr(), [](const auto *e) {
|
||||
LOG_DBG("=== Processing nested requirement: {}",
|
||||
common::to_string(e));
|
||||
@@ -805,7 +805,7 @@ std::unique_ptr<class_> translation_unit_visitor::create_record_declaration(
|
||||
|
||||
#if LLVM_VERSION_MAJOR < 16
|
||||
if (record_name == "(anonymous)") {
|
||||
util::apply_if_not_null(rec->getTypedefNameForAnonDecl(),
|
||||
util::if_not_null(rec->getTypedefNameForAnonDecl(),
|
||||
[&record_name](const clang::TypedefNameDecl *name) {
|
||||
record_name = name->getNameAsString();
|
||||
});
|
||||
@@ -985,9 +985,8 @@ bool translation_unit_visitor::process_template_parameters(
|
||||
default_arg, template_type_parameter->isParameterPack());
|
||||
|
||||
if (template_type_parameter->getTypeConstraint() != nullptr) {
|
||||
util::apply_if_not_null(
|
||||
template_type_parameter->getTypeConstraint()
|
||||
->getNamedConcept(),
|
||||
util::if_not_null(template_type_parameter->getTypeConstraint()
|
||||
->getNamedConcept(),
|
||||
[this, &ct, &templated_element](
|
||||
const clang::ConceptDecl *named_concept) mutable {
|
||||
ct.set_concept_constraint(
|
||||
|
||||
@@ -163,7 +163,7 @@ std::string to_string(const clang::QualType &type, const clang::ASTContext &ctx,
|
||||
|
||||
// Try to get rid of 'type-parameter-X-Y' ugliness
|
||||
if (result.find("type-parameter-") != std::string::npos) {
|
||||
util::apply_if_not_null(
|
||||
util::if_not_null(
|
||||
common::dereference(type)->getAs<clang::TypedefType>(),
|
||||
[&result, &type](auto *p) {
|
||||
auto [unqualified_type, context] =
|
||||
|
||||
@@ -194,8 +194,13 @@ bool translation_unit_visitor::VisitClassTemplateDecl(
|
||||
|
||||
found_relationships_t relationships;
|
||||
|
||||
process_class_declaration(*decl->getTemplatedDecl(), relationships);
|
||||
add_relationships(decl, relationships);
|
||||
util::if_not_null(decl->getTemplatedDecl(),
|
||||
[this, &relationships, decl](const auto *template_decl) {
|
||||
if (template_decl->isCompleteDefinition()) {
|
||||
process_class_declaration(*template_decl, relationships);
|
||||
add_relationships(decl, relationships);
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ void for_each_if(const T &collection, C &&cond, F &&func)
|
||||
}
|
||||
|
||||
template <typename T, typename F, typename FElse>
|
||||
void apply_if_not_null(const T *pointer, F &&func, FElse &&func_else)
|
||||
void if_not_null(const T *pointer, F &&func, FElse &&func_else)
|
||||
{
|
||||
if (pointer != nullptr) {
|
||||
std::forward<F>(func)(pointer);
|
||||
@@ -264,14 +264,13 @@ void apply_if_not_null(const T *pointer, F &&func, FElse &&func_else)
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename F>
|
||||
void apply_if_not_null(const T *pointer, F &&func)
|
||||
template <typename T, typename F> void if_not_null(const T *pointer, F &&func)
|
||||
{
|
||||
apply_if_not_null(pointer, std::forward<F>(func), []() {});
|
||||
if_not_null(pointer, std::forward<F>(func), []() {});
|
||||
}
|
||||
|
||||
template <typename F, typename FElse>
|
||||
void apply_if(const bool condition, F &&func, FElse &&func_else)
|
||||
void _if(const bool condition, F &&func, FElse &&func_else)
|
||||
{
|
||||
if (condition) {
|
||||
std::forward<F>(func)();
|
||||
@@ -281,9 +280,9 @@ void apply_if(const bool condition, F &&func, FElse &&func_else)
|
||||
}
|
||||
}
|
||||
|
||||
template <typename F> void apply_if(const bool condition, F &&func)
|
||||
template <typename F> void _if(const bool condition, F &&func)
|
||||
{
|
||||
apply_if(condition, std::forward<F>(func), []() {});
|
||||
_if(condition, std::forward<F>(func), []() {});
|
||||
}
|
||||
|
||||
std::size_t hash_seed(std::size_t seed);
|
||||
|
||||
Reference in New Issue
Block a user