semantic.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef META_HS_SEMANTIC_HPP
  2. #define META_HS_SEMANTIC_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2012.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include <ast.hpp>
  8. #include <curry.hpp>
  9. #include <boost/mpl/if.hpp>
  10. #include <boost/mpl/apply_wrap.hpp>
  11. #include <boost/mpl/front.hpp>
  12. #include <boost/mpl/back.hpp>
  13. #include <boost/mpl/at.hpp>
  14. #include <boost/mpl/pair.hpp>
  15. namespace semantic
  16. {
  17. struct ref
  18. {
  19. typedef ref type;
  20. template <class Name>
  21. struct apply : ast::ref<Name> {};
  22. };
  23. struct value
  24. {
  25. typedef value type;
  26. template <class V>
  27. struct apply : ast::value<V> {};
  28. };
  29. struct lambda
  30. {
  31. typedef lambda type;
  32. template <class F, class ArgName>
  33. struct apply : ast::lambda<F, ArgName> {};
  34. };
  35. struct application
  36. {
  37. typedef application type;
  38. template <class F, class Arg>
  39. struct apply : ast::application<F, Arg> {};
  40. };
  41. class if_
  42. {
  43. private:
  44. template <class C, class T, class F>
  45. struct lazy_if : boost::mpl::if_<typename C::type, T, F> {};
  46. public:
  47. typedef if_ type;
  48. template <class Seq>
  49. struct apply :
  50. boost::mpl::apply_wrap2<
  51. application,
  52. typename boost::mpl::apply_wrap2<
  53. application,
  54. typename boost::mpl::apply_wrap2<
  55. application,
  56. ast::value<curry3<lazy_if> >,
  57. typename boost::mpl::at_c<Seq, 0>::type
  58. >::type,
  59. typename boost::mpl::at_c<Seq, 1>::type
  60. >::type,
  61. typename boost::mpl::at_c<Seq, 2>::type
  62. >
  63. {};
  64. };
  65. struct binary_op
  66. {
  67. typedef binary_op type;
  68. template <class Exp, class C>
  69. struct apply :
  70. boost::mpl::apply_wrap2<
  71. application,
  72. typename boost::mpl::apply_wrap2<
  73. application,
  74. typename boost::mpl::apply_wrap1<
  75. ref,
  76. typename boost::mpl::front<C>::type
  77. >::type,
  78. Exp
  79. >::type,
  80. typename boost::mpl::back<C>::type
  81. >
  82. {};
  83. };
  84. struct pair
  85. {
  86. typedef pair type;
  87. template <class Seq>
  88. struct apply :
  89. boost::mpl::pair<
  90. typename boost::mpl::front<Seq>::type,
  91. ast::top_bound<typename boost::mpl::back<Seq>::type>
  92. >
  93. {};
  94. };
  95. }
  96. #endif