From 2ab89e98513f7d3bf449aa9d78ef982c6bde72b5 Mon Sep 17 00:00:00 2001 From: Zach Laine Date: Mon, 7 Nov 2016 21:40:24 -0600 Subject: [PATCH] Cruft removal. --- expression.hpp | 8 +++ sketch.cpp | 157 ------------------------------------------------- 2 files changed, 8 insertions(+), 157 deletions(-) diff --git a/expression.hpp b/expression.hpp index cc6f402..055dd50 100644 --- a/expression.hpp +++ b/expression.hpp @@ -123,6 +123,14 @@ namespace boost::proto17 { } }; + template + auto make_terminal (F && f) + { + return expression{ + hana::tuple{static_cast(f)} + }; + } + } #endif diff --git a/sketch.cpp b/sketch.cpp index 190132a..30286a0 100644 --- a/sketch.cpp +++ b/sketch.cpp @@ -9,124 +9,6 @@ #include #include #include - - -// TODO: Verbose debugging mode for matching. -// TODO: Proto-style "Fuzzy and Exact Matches of Terminals". - -namespace boost::proto17 { - - namespace match { - - template - struct expression - { - KindMatches kind_matches; - hana::tuple elements; - }; - - // TODO: Use this to detect identical types within a match. - template - struct placeholder : hana::llong {}; - - } - - template - constexpr bool is_match_expression (hana::basic_type) - { return false; } - template - constexpr bool is_match_expression (hana::basic_type>) - { return true; } - - namespace literals { - - template - constexpr auto operator"" _T () - { return match::placeholder({c...})>{}; } - - } - - namespace detail { - - inline bool matches (...) - { return false; } - - template - bool matches (MatchExpr const & match_subtree, TreeExpr const & subtree); - - template - void recursive_match_impl (MatchExpr const & match_subtree, TreeExpr const & subtree, bool & result) - { - if (!matches(match_subtree[hana::size_c], subtree[hana::size_c])) { - result = false; - } - if constexpr (0 < I) { - recursive_match_impl(match_subtree, subtree, result); - } - } - - template - 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( - match_subtree.elements, - subtree.elements, - children_match - ); - return children_match; - } - } - } - - template - auto mutate_subtrees_of ( - Matcher const & match_subtree, - expression & 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(mutation)); - }; - auto return_elements = hana::transform(tree.elements, mutate_child); - return make_expression(Kind, std::move(return_elements)); - } - } - - } - - template - auto make_terminal (F && f) - { - return expression{ - hana::tuple{static_cast(f)} - }; - } - -} - - #include @@ -1482,43 +1364,4 @@ int main () call_expr(); reference_returns(); - -#if 0 // TODO - { - bp17::terminal 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 a{1.0}; - bp17::terminal x{2.0}; - bp17::terminal 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 a{1.0}; - bp17::terminal x{2.0}; - bp17::terminal b{3}; - - auto match_double_2 = [] (auto && terminal) { - if constexpr (hana::typeid_(terminal) == hana::type{}) - return terminal == 2.0; - else - return false; - }; - - auto unevaluated_expr = a * x + b; - auto match_expr = bp17::match * match_double_2 + 0_T; - auto mutated_expr = mutate(unevaluated_expr, match_expr, mutation); - auto result = bp17::eval(mutated_expr); - } -#endif }