sprout/weed/context/parse_context/operator/minus.hpp 追加

sprout/weed/context/parse_context/operator/negate.hpp 追加
This commit is contained in:
bolero-MURAKAMI 2011-11-14 19:45:59 +09:00
parent 005f8a9a87
commit a7698fa6e9
13 changed files with 291 additions and 1 deletions

View file

@ -3,6 +3,7 @@
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/weed/attr_cnv/times.hpp> #include <sprout/weed/attr_cnv/times.hpp>
#include <sprout/weed/attr_cnv/negate.hpp>
#include <sprout/weed/attr_cnv/shift_left.hpp> #include <sprout/weed/attr_cnv/shift_left.hpp>
#include <sprout/weed/attr_cnv/modulus.hpp> #include <sprout/weed/attr_cnv/modulus.hpp>
#include <sprout/weed/attr_cnv/bitwise_or.hpp> #include <sprout/weed/attr_cnv/bitwise_or.hpp>

View file

@ -0,0 +1,28 @@
#ifndef SPROUT_WEED_ATTR_CNV_NEGATE_HPP
#define SPROUT_WEED_ATTR_CNV_NEGATE_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/traits/type/is_unused.hpp>
#include <sprout/weed/attr_cnv/result_of/negate.hpp>
namespace sprout {
namespace weed {
namespace attr_cnv {
//
// negate
//
// !unused -> unused
template<typename T>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::traits::is_unused<T>::value,
typename sprout::weed::attr_cnv::result_of::negate<T>::type
>::type negate(T const& t, bool cond) {
return sprout::weed::unused();
}
} // namespace attr_cnv
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_ATTR_CNV_NEGATE_HPP

View file

@ -3,6 +3,7 @@
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/weed/attr_cnv/result_of/times.hpp> #include <sprout/weed/attr_cnv/result_of/times.hpp>
#include <sprout/weed/attr_cnv/result_of/negate.hpp>
#include <sprout/weed/attr_cnv/result_of/shift_left.hpp> #include <sprout/weed/attr_cnv/result_of/shift_left.hpp>
#include <sprout/weed/attr_cnv/result_of/modulus.hpp> #include <sprout/weed/attr_cnv/result_of/modulus.hpp>
#include <sprout/weed/attr_cnv/result_of/bitwise_or.hpp> #include <sprout/weed/attr_cnv/result_of/bitwise_or.hpp>

View file

@ -0,0 +1,34 @@
#ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_NEGATE_HPP
#define SPROUT_WEED_ATTR_CNV_RESULT_OF_NEGATE_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/traits/type/is_unused.hpp>
namespace sprout {
namespace weed {
namespace attr_cnv {
namespace result_of {
//
// negate
//
template<typename T, typename = void>
struct negate;
// -unused -> unused
template<typename T>
struct negate<
T,
typename std::enable_if<
sprout::weed::traits::is_unused<T>::value
>::type
> {
public:
typedef sprout::weed::unused type;
};
} // namespace result_of
} // namespace attr_cnv
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_NEGATE_HPP

View file

@ -3,11 +3,13 @@
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/weed/context/parse_context/operator/unary_plus.hpp> #include <sprout/weed/context/parse_context/operator/unary_plus.hpp>
#include <sprout/weed/context/parse_context/operator/negate.hpp>
#include <sprout/weed/context/parse_context/operator/dereference.hpp> #include <sprout/weed/context/parse_context/operator/dereference.hpp>
#include <sprout/weed/context/parse_context/operator/address_of.hpp> #include <sprout/weed/context/parse_context/operator/address_of.hpp>
#include <sprout/weed/context/parse_context/operator/logical_not.hpp> #include <sprout/weed/context/parse_context/operator/logical_not.hpp>
#include <sprout/weed/context/parse_context/operator/shift_left.hpp> #include <sprout/weed/context/parse_context/operator/shift_left.hpp>
#include <sprout/weed/context/parse_context/operator/modulus.hpp> #include <sprout/weed/context/parse_context/operator/modulus.hpp>
#include <sprout/weed/context/parse_context/operator/minus.hpp>
#include <sprout/weed/context/parse_context/operator/bitwise_or.hpp> #include <sprout/weed/context/parse_context/operator/bitwise_or.hpp>
#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_OPERATOR_HPP #endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_OPERATOR_HPP

View file

@ -0,0 +1,67 @@
#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_MINUS_HPP
#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_MINUS_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/weed/eval_result.hpp>
#include <sprout/weed/expr/tag.hpp>
#include <sprout/weed/expr/eval.hpp>
#include <sprout/weed/traits/expr/tag_of.hpp>
#include <sprout/weed/traits/parser/attribute_of.hpp>
#include <sprout/weed/context/parse_context_fwd.hpp>
namespace sprout {
namespace weed {
//
// parse_context::eval
//
template<typename Iterator>
template<typename Expr>
struct parse_context<Iterator>::eval<
Expr,
typename std::enable_if<
std::is_same<
typename sprout::weed::traits::tag_of<Expr>::type,
sprout::weed::tag::minus
>::value
>::type
> {
private:
typedef sprout::weed::parse_context<Iterator> context_type;
public:
typedef typename sprout::weed::traits::attribute_of<Expr, Iterator, context_type>::type attribute_type;
typedef sprout::weed::eval_result<context_type, Iterator, attribute_type> result_type;
private:
template<typename Result1>
SPROUT_CONSTEXPR result_type call_1(
typename Expr::args_type const& args,
context_type const& ctx,
Result1 const& res
) const
{
return res.success() && !sprout::weed::eval(sprout::tuples::get<1>(args), ctx).success()
? res
: result_type(false, ctx.begin(), attribute_type(), ctx)
;
}
SPROUT_CONSTEXPR result_type call(
typename Expr::args_type const& args,
context_type const& ctx
) const
{
return call_1(args, ctx, sprout::weed::eval(sprout::tuples::get<0>(args), ctx));
}
public:
SPROUT_CONSTEXPR result_type operator()(
Expr const& expr,
context_type const& ctx
) const
{
return call(expr.args(), ctx);
}
};
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_MINUS_HPP

View file

@ -0,0 +1,62 @@
#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_NEGATE_HPP
#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_NEGATE_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/weed/eval_result.hpp>
#include <sprout/weed/expr/tag.hpp>
#include <sprout/weed/expr/eval.hpp>
#include <sprout/weed/attr_cnv/negate.hpp>
#include <sprout/weed/traits/expr/tag_of.hpp>
#include <sprout/weed/traits/parser/attribute_of.hpp>
#include <sprout/weed/context/parse_context_fwd.hpp>
namespace sprout {
namespace weed {
//
// parse_context::eval
//
template<typename Iterator>
template<typename Expr>
struct parse_context<Iterator>::eval<
Expr,
typename std::enable_if<
std::is_same<
typename sprout::weed::traits::tag_of<Expr>::type,
sprout::weed::tag::negate
>::value
>::type
> {
private:
typedef sprout::weed::parse_context<Iterator> context_type;
public:
typedef typename sprout::weed::traits::attribute_of<Expr, Iterator, context_type>::type attribute_type;
typedef sprout::weed::eval_result<context_type, Iterator, attribute_type> result_type;
private:
template<typename Result>
SPROUT_CONSTEXPR result_type call(
context_type const& ctx,
Result const& res
) const
{
return result_type(
true,
res.current(),
sprout::weed::attr_cnv::negate(res.attr(), res.success()),
res.success() ? context_type(ctx, res.current()) : ctx
);
}
public:
SPROUT_CONSTEXPR result_type operator()(
Expr const& expr,
context_type const& ctx
) const
{
return call(ctx, sprout::weed::eval(sprout::tuples::get<0>(expr.args()), ctx));
}
};
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_NEGATE_HPP

View file

@ -8,11 +8,13 @@ namespace sprout {
namespace tag { namespace tag {
struct terminal {}; struct terminal {};
struct unary_plus {}; struct unary_plus {};
struct negate {};
struct dereference {}; struct dereference {};
struct address_of {}; struct address_of {};
struct logical_not {}; struct logical_not {};
struct shift_left {}; struct shift_left {};
struct modulus {}; struct modulus {};
struct minus {};
struct bitwise_or {}; struct bitwise_or {};
} // namespace tag } // namespace tag
} // namespace weed } // namespace weed

View file

@ -3,11 +3,13 @@
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/weed/operator/unary_plus.hpp> #include <sprout/weed/operator/unary_plus.hpp>
#include <sprout/weed/operator/negate.hpp>
#include <sprout/weed/operator/dereference.hpp> #include <sprout/weed/operator/dereference.hpp>
#include <sprout/weed/operator/address_of.hpp> #include <sprout/weed/operator/address_of.hpp>
#include <sprout/weed/operator/logical_not.hpp> #include <sprout/weed/operator/logical_not.hpp>
#include <sprout/weed/operator/shift_left.hpp> #include <sprout/weed/operator/shift_left.hpp>
#include <sprout/weed/operator/modulus.hpp> #include <sprout/weed/operator/modulus.hpp>
#include <sprout/weed/operator/minus.hpp>
#include <sprout/weed/operator/bitwise_or.hpp> #include <sprout/weed/operator/bitwise_or.hpp>
#endif // #ifndef SPROUT_WEED_OPERATOR_HPP #endif // #ifndef SPROUT_WEED_OPERATOR_HPP

View file

@ -26,7 +26,7 @@ namespace sprout {
SPROUT_CONSTEXPR inline typename sprout::weed::traits::expr_of< SPROUT_CONSTEXPR inline typename sprout::weed::traits::expr_of<
sprout::weed::tag::address_of, sprout::weed::tag::address_of,
Arg Arg
>::type operator!(Arg&& arg) { >::type operator&(Arg&& arg) {
return sprout::weed::make_expr<sprout::weed::tag::address_of>( return sprout::weed::make_expr<sprout::weed::tag::address_of>(
sprout::forward<Arg>(arg) sprout::forward<Arg>(arg)
); );

View file

@ -0,0 +1,43 @@
#ifndef SPROUT_WEED_OPERATOR_MINUS_HPP
#define SPROUT_WEED_OPERATOR_MINUS_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/weed/expr/tag.hpp>
#include <sprout/weed/expr/make_expr.hpp>
#include <sprout/weed/traits/expr/expr_of.hpp>
#include <sprout/weed/traits/parser/is_parser.hpp>
#include <sprout/weed/detail/uncvref.hpp>
namespace sprout {
namespace weed {
//
// operator-
//
template<
typename Arg1,
typename Arg2,
typename = typename std::enable_if<
sprout::weed::traits::is_parser<
typename sprout::weed::detail::uncvref<Arg1>::type
>::value
&& sprout::weed::traits::is_parser<
typename sprout::weed::detail::uncvref<Arg2>::type
>::value
>::type
>
SPROUT_CONSTEXPR inline typename sprout::weed::traits::expr_of<
sprout::weed::tag::minus,
Arg1,
Arg2
>::type operator-(Arg1&& arg1, Arg2&& arg2) {
return sprout::weed::make_expr<sprout::weed::tag::minus>(
sprout::forward<Arg1>(arg1),
sprout::forward<Arg2>(arg2)
);
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_OPERATOR_MINUS_HPP

View file

@ -0,0 +1,37 @@
#ifndef SPROUT_WEED_OPERATOR_NEGATE_HPP
#define SPROUT_WEED_OPERATOR_NEGATE_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/weed/expr/tag.hpp>
#include <sprout/weed/expr/make_expr.hpp>
#include <sprout/weed/traits/expr/expr_of.hpp>
#include <sprout/weed/traits/parser/is_parser.hpp>
#include <sprout/weed/detail/uncvref.hpp>
namespace sprout {
namespace weed {
//
// operator-
//
template<
typename Arg,
typename = typename std::enable_if<
sprout::weed::traits::is_parser<
typename sprout::weed::detail::uncvref<Arg>::type
>::value
>::type
>
SPROUT_CONSTEXPR inline typename sprout::weed::traits::expr_of<
sprout::weed::tag::negate,
Arg
>::type operator-(Arg&& arg) {
return sprout::weed::make_expr<sprout::weed::tag::negate>(
sprout::forward<Arg>(arg)
);
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_OPERATOR_NEGATE_HPP

View file

@ -71,6 +71,12 @@ namespace sprout {
> >
{}; {};
template<typename Arg, typename Iterator, typename Context> template<typename Arg, typename Iterator, typename Context>
struct attribute_of<sprout::weed::expr<sprout::weed::tag::negate, Arg>, Iterator, Context>
: public sprout::weed::attr_cnv::result_of::negate<
typename sprout::weed::traits::attribute_of<Arg, Iterator, Context>::type
>
{};
template<typename Arg, typename Iterator, typename Context>
struct attribute_of<sprout::weed::expr<sprout::weed::tag::dereference, Arg>, Iterator, Context> struct attribute_of<sprout::weed::expr<sprout::weed::tag::dereference, Arg>, Iterator, Context>
: public sprout::weed::attr_cnv::result_of::times< : public sprout::weed::attr_cnv::result_of::times<
sprout::weed::traits::limit_of<Arg, Iterator, Context>::value, sprout::weed::traits::limit_of<Arg, Iterator, Context>::value,
@ -102,6 +108,11 @@ namespace sprout {
> >
{}; {};
template<typename Arg1, typename Arg2, typename Iterator, typename Context> template<typename Arg1, typename Arg2, typename Iterator, typename Context>
struct attribute_of<sprout::weed::expr<sprout::weed::tag::minus, Arg1, Arg2>, Iterator, Context> {
public:
typedef typename sprout::weed::traits::attribute_of<Arg1, Iterator, Context>::type type;
};
template<typename Arg1, typename Arg2, typename Iterator, typename Context>
struct attribute_of<sprout::weed::expr<sprout::weed::tag::bitwise_or, Arg1, Arg2>, Iterator, Context> struct attribute_of<sprout::weed::expr<sprout::weed::tag::bitwise_or, Arg1, Arg2>, Iterator, Context>
: public sprout::weed::attr_cnv::result_of::bitwise_or< : public sprout::weed::attr_cnv::result_of::bitwise_or<
typename sprout::weed::traits::attribute_of<Arg1, Iterator, Context>::type, typename sprout::weed::traits::attribute_of<Arg1, Iterator, Context>::type,