2
0
mirror of https://github.com/boostorg/yap.git synced 2026-02-23 16:22:09 +00:00

Cruft removal.

This commit is contained in:
Zach Laine
2016-11-07 21:40:24 -06:00
parent 7845b14d4e
commit 2ab89e9851
2 changed files with 8 additions and 157 deletions

View File

@@ -123,6 +123,14 @@ namespace boost::proto17 {
}
};
template <typename F>
auto make_terminal (F && f)
{
return expression<expr_kind::terminal, F>{
hana::tuple<F>{static_cast<F &&>(f)}
};
}
}
#endif

View File

@@ -9,124 +9,6 @@
#include <boost/hana/tuple.hpp>
#include <boost/hana/type.hpp>
#include <boost/hana/size.hpp>
// TODO: Verbose debugging mode for matching.
// TODO: Proto-style "Fuzzy and Exact Matches of Terminals".
namespace boost::proto17 {
namespace match {
template <typename KindMatches, typename ...T>
struct expression
{
KindMatches kind_matches;
hana::tuple<T...> elements;
};
// TODO: Use this to detect identical types within a match.
template <long long I>
struct placeholder : hana::llong<I> {};
}
template <typename KindMatches, typename T>
constexpr bool is_match_expression (hana::basic_type<T>)
{ return false; }
template <typename KindMatches, typename ...T>
constexpr bool is_match_expression (hana::basic_type<match::expression<KindMatches, T...>>)
{ return true; }
namespace literals {
template <char ...c>
constexpr auto operator"" _T ()
{ return match::placeholder<hana::ic_detail::parse<sizeof...(c)>({c...})>{}; }
}
namespace detail {
inline bool matches (...)
{ return false; }
template <typename MatchExpr, typename TreeExpr>
bool matches (MatchExpr const & match_subtree, TreeExpr const & subtree);
template <std::size_t I, typename MatchExpr, typename TreeExpr>
void recursive_match_impl (MatchExpr const & match_subtree, TreeExpr const & subtree, bool & result)
{
if (!matches(match_subtree[hana::size_c<I>], subtree[hana::size_c<I>])) {
result = false;
}
if constexpr (0 < I) {
recursive_match_impl<I - 1>(match_subtree, subtree, result);
}
}
template <typename MatchExpr, typename TreeExpr>
bool matches (MatchExpr const & match_subtree, TreeExpr const & subtree)
{
static_assert(is_match_expression(hana::typeid_(match_subtree)),
"Attempted to use a non-tree as a match expression.");
static_assert(is_expression(hana::typeid_(subtree)),
"Attempted to use find a match in a non-tree.");
// TODO: Verbose mode.
if (!match_subtree.kind_matches(subtree)) {
return false;
} else {
auto constexpr subtree_size = hana::size(subtree.elements);
if constexpr (hana::size(match_subtree.elements) != subtree_size) {
// TODO: Verbose mode.
return false;
} else {
bool children_match = true;
recursive_match_impl<subtree_size - 1>(
match_subtree.elements,
subtree.elements,
children_match
);
return children_match;
}
}
}
template <typename Matcher, typename Callable, expr_kind Kind, typename ...T>
auto mutate_subtrees_of (
Matcher const & match_subtree,
expression<Kind, T...> & tree,
Callable && mutation
) {
// TODO: Process children first.
if (matches(match_subtree, tree)) {
return mutation(tree);
} else if (Kind == expr_kind::terminal) {
return tree;
} else {
auto mutate_child = [&match_subtree, &mutation] (auto & t) {
return mutate_subtrees_of(match_subtree, t, static_cast<Callable &&>(mutation));
};
auto return_elements = hana::transform(tree.elements, mutate_child);
return make_expression(Kind, std::move(return_elements));
}
}
}
template <typename F>
auto make_terminal (F && f)
{
return expression<expr_kind::terminal, F>{
hana::tuple<F>{static_cast<F &&>(f)}
};
}
}
#include <string>
@@ -1482,43 +1364,4 @@ int main ()
call_expr();
reference_returns();
#if 0 // TODO
{
bp17::terminal<double> unity{1.0};
auto unevaluated_expr = unity + "3";
auto mutated_expr = mutate(unevaluated_expr, match_expr, mutation);
auto result = bp17::eval(unevaluated_expr);
}
{
bp17::terminal<double> a{1.0};
bp17::terminal<double> x{2.0};
bp17::terminal<int> b{3};
auto unevaluated_expr = a * x + b;
auto match_expr = 0_T * 0_T + 1_T;
auto mutated_expr = mutate(unevaluated_expr, match_expr, mutation);
auto result = bp17::eval(mutated_expr);
}
{
bp17::terminal<double> a{1.0};
bp17::terminal<double> x{2.0};
bp17::terminal<int> b{3};
auto match_double_2 = [] (auto && terminal) {
if constexpr (hana::typeid_(terminal) == hana::type<double>{})
return terminal == 2.0;
else
return false;
};
auto unevaluated_expr = a * x + b;
auto match_expr = bp17::match<double> * match_double_2 + 0_T;
auto mutated_expr = mutate(unevaluated_expr, match_expr, mutation);
auto result = bp17::eval(mutated_expr);
}
#endif
}