Skip to content

Commit

Permalink
Remove matchit dependency for users. (#60)
Browse files Browse the repository at this point in the history
* Remove matchit dependency for users.

* Fix build.

Co-authored-by: Bowen Fu <missing>
  • Loading branch information
BowenFu authored Jul 18, 2021
1 parent a8bc2b5 commit 145f741
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 71 deletions.
65 changes: 1 addition & 64 deletions include/mathiu/core.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef CORE_H
#define CORE_H

#include "matchit.h"
#include <variant>
#include <memory>
#include <string>
Expand All @@ -10,13 +9,7 @@
#include <map>
#include <set>
#include <list>

#define VERBOSE_DEBUG 0
#define DEBUG 1

#if DEBUG
#include <iostream>
#endif // DEBUG
#include <array>

namespace mathiu::impl
{
Expand All @@ -27,48 +20,6 @@ namespace mathiu::impl

} // namespace mathiu::impl

namespace matchit::impl
{
template <>
class PatternTraits<mathiu::impl::ExprPtr>
{
using Pattern = mathiu::impl::ExprPtr;
public:
template <typename Value>
using AppResultTuple = std::tuple<>;

constexpr static auto nbIdV = 0;

template <typename Value, typename ContextT>
constexpr static auto matchPatternImpl(Value &&value, Pattern const &pattern,
int32_t /* depth */,
ContextT & /*context*/)
{
return mathiu::impl::equal(pattern, std::forward<Value>(value));
}
constexpr static void processIdImpl(Pattern const &, int32_t /*depth*/,
IdProcess) {}
};

template <>
class IdTraits<mathiu::impl::ExprPtr>
{
using Type = mathiu::impl::ExprPtr;
public:
static auto
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
__attribute__((no_sanitize_address))
#endif
#endif
equal(Type const &lhs, Type const &rhs)
{
return mathiu::impl::equal(lhs, rhs);
}
};

} // namespace matchit::impl

namespace mathiu
{
namespace impl
Expand Down Expand Up @@ -333,8 +284,6 @@ namespace mathiu

double evald(ExprPtr const &ex);

inline constexpr auto isRational = matchit::or_(matchit::as<int>(matchit::_), matchit::as<Fraction>(matchit::_));

// The <| order relation
// for basic commutative transformation
bool less(ExprPtr const &lhs, ExprPtr const &rhs);
Expand Down Expand Up @@ -414,18 +363,6 @@ namespace mathiu
return substitute(substitute(ex, srcDstPairs), seqPairs...);
}

inline auto const asDouble = matchit::meet([](auto&& e)
{
try{
evald(e);
return true;
}
catch (...)
{
return false;
}
});

inline ExprPtr interval(ExprPtr const& l, bool const lClose, ExprPtr const& r, bool const rClose)
{
return std::make_shared<impl::Expr const>(impl::Interval{{l, lClose}, {r, rClose}});
Expand Down
2 changes: 1 addition & 1 deletion src/core.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "mathiu/core.h"
#include "matchit.h"
#include "internal.h"
#include <numeric>

namespace mathiu::impl
Expand Down
2 changes: 1 addition & 1 deletion src/diff.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "matchit.h"
#include "mathiu/core.h"
#include "internal.h"
#include "mathiu/diff.h"
#include <numeric>

Expand Down
2 changes: 1 addition & 1 deletion src/function_range.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "matchit.h"
#include "mathiu/core.h"
#include "internal.h"
#include "mathiu/solve.h"
#include "mathiu/diff.h"
#include "mathiu/inequation.h"
Expand Down
2 changes: 1 addition & 1 deletion src/inequation.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "matchit.h"
#include "mathiu/core.h"
#include "internal.h"
#include "mathiu/inequation.h"
#include "mathiu/diff.h"
#include "mathiu/solve.h"
Expand Down
78 changes: 78 additions & 0 deletions src/internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#ifndef INTERNAL_H
#define INTERNAL_H

#include "mathiu/core.h"
#include "matchit.h"

#define VERBOSE_DEBUG 0
#define DEBUG 1

#if DEBUG
#include <iostream>
#endif // DEBUG

namespace matchit::impl
{
template <>
class PatternTraits<mathiu::impl::ExprPtr>
{
using Pattern = mathiu::impl::ExprPtr;
public:
template <typename Value>
using AppResultTuple = std::tuple<>;

constexpr static auto nbIdV = 0;

template <typename Value, typename ContextT>
constexpr static auto matchPatternImpl(Value &&value, Pattern const &pattern,
int32_t /* depth */,
ContextT & /*context*/)
{
return mathiu::impl::equal(pattern, std::forward<Value>(value));
}
constexpr static void processIdImpl(Pattern const &, int32_t /*depth*/,
IdProcess) {}
};

template <>
class IdTraits<mathiu::impl::ExprPtr>
{
using Type = mathiu::impl::ExprPtr;
public:
static auto
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
__attribute__((no_sanitize_address))
#endif
#endif
equal(Type const &lhs, Type const &rhs)
{
return mathiu::impl::equal(lhs, rhs);
}
};

} // namespace matchit::impl

namespace mathiu
{
namespace impl
{
inline constexpr auto isRational = matchit::or_(matchit::as<int>(matchit::_), matchit::as<Fraction>(matchit::_));


inline auto const asDouble = matchit::meet([](auto&& e)
{
try{
evald(e);
return true;
}
catch (...)
{
return false;
}
});

} // namespace impl
} // namespace mathiu

#endif // INTERNAL_H
2 changes: 1 addition & 1 deletion src/polynomial.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "matchit.h"
#include "mathiu/core.h"
#include "internal.h"
#include "mathiu/diff.h"
#include "mathiu/polynomial.h"
#include <cmath>
Expand Down
2 changes: 1 addition & 1 deletion src/setOp.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <iterator>
#include "matchit.h"
#include "mathiu/core.h"
#include "internal.h"
#include "mathiu/setOp.h"

namespace mathiu::impl
Expand Down
2 changes: 1 addition & 1 deletion src/solve.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <iterator>
#include "matchit.h"
#include "mathiu/core.h"
#include "internal.h"
#include "mathiu/diff.h"
#include "mathiu/polynomial.h"
#include "mathiu/setOp.h"
Expand Down
2 changes: 2 additions & 0 deletions test/mathiu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ solve.cpp polynomial.cpp relational.cpp freeOf.cpp
substitute.cpp functionRange.cpp inequation.cpp
interval-comp.cpp
)
target_include_directories(unittests PRIVATE
${PROJECT_SOURCE_DIR}/src PRIVATE matchit)
target_compile_options(unittests PRIVATE ${BASE_COMPILE_FLAGS})
target_link_libraries(unittests PRIVATE mathiu gtest_main matchit)
set_target_properties(unittests PROPERTIES CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS OFF)
Expand Down
2 changes: 2 additions & 0 deletions test/mathiu/auto-simplification.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "internal.h"
#include "mathiu.h"
#include "matchit.h"
#include "gtest/gtest.h"
#include <iostream>
using namespace mathiu;
Expand Down
1 change: 1 addition & 0 deletions test/mathiu/expr.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "mathiu.h"
#include "matchit.h"
#include "gtest/gtest.h"
#include <string>
using namespace mathiu;
Expand Down

0 comments on commit 145f741

Please sign in to comment.