00001
00070 #ifndef CMD_HUNK_H
00071 #define CMD_HUNK_H
00072
00073 #include "parser.h"
00074
00075
00076 #include <boost/preprocessor/library.hpp>
00077
00078 #define HUNK_INDEX_FOR_NIL 0
00079 #define HUNK_INDEX_FOR_string 1
00080 #define HUNK_INDEX_FOR_long 2
00081 #define HUNK_ARRAY_LETTERS (3, (NIL, s, l))
00082 #define HUNK_ARRAY_STRINGS (3, ("", "s", "d"))
00083
00084
00085 #define HUNK_TYPE_LETTER(s, _, type) \
00086 BOOST_PP_CAT(HUNK_INDEX_FOR_, type) \
00087
00088
00089 #define HUNK_TRANSFORMER(_, array, elem) \
00090 BOOST_PP_ARRAY_ELEM(elem, array) \
00091
00092
00093 #define HUNK_SEQ_TRANS_ARRAY(seq, array) \
00094 BOOST_PP_SEQ_TRANSFORM(HUNK_TRANSFORMER, array, seq) \
00095
00096
00097 #define HUNK_PARAM(_, n, seq) \
00098 args_results[n+1]. BOOST_PP_SEQ_ELEM(n, seq) \
00099
00100
00101 #define HUNK_RESULT(_, n, seq) \
00102 &args_results[n]. BOOST_PP_SEQ_ELEM(n, seq) \
00103
00104
00105 #define HUNK_IDENTITY(_, dummy, x) x
00106 #define CMD_HUNK_TEMPLATE(func) cmd_##func###_template
00107
00108 #define DECLARE_CMD_HUNK_2(func, name, param_types, result_types, flags) \
00109 static ResultCode cmd_##name##_hunk(parms args_results[]) \
00110 { \
00111 return cmd_##func( \
00112 BOOST_PP_ENUM(BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(param_types)), HUNK_PARAM, HUNK_SEQ_TRANS_ARRAY(param_types, HUNK_ARRAY_LETTERS)) \
00113 BOOST_PP_COMMA_IF(BOOST_PP_AND(BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(param_types)), BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(result_types)))) \
00114 BOOST_PP_ENUM(BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(result_types)), HUNK_RESULT, HUNK_SEQ_TRANS_ARRAY(result_types, HUNK_ARRAY_LETTERS)) \
00115 ); \
00116 } \
00117 const struct CmdTemplate CMD_HUNK_TEMPLATE(name) = { \
00118 #name, \
00119 BOOST_PP_SEQ_FOR_EACH(HUNK_IDENTITY, _, HUNK_SEQ_TRANS_ARRAY(param_types, HUNK_ARRAY_STRINGS)), \
00120 BOOST_PP_SEQ_FOR_EACH(HUNK_IDENTITY, _, HUNK_SEQ_TRANS_ARRAY(result_types, HUNK_ARRAY_STRINGS)), \
00121 cmd_##name##_hunk, \
00122 flags \
00123 } \
00124
00125
00126 #define DECLARE_CMD_HUNK(func, param_types, result_types) \
00127 DECLARE_CMD_HUNK_2(func, func, \
00128 BOOST_PP_SEQ_TRANSFORM(HUNK_TYPE_LETTER, _, param_types), \
00129 BOOST_PP_SEQ_TRANSFORM(HUNK_TYPE_LETTER, _, result_types), \
00130 0) \
00131
00132
00133 #define DECLARE_CMD_HUNK_NAME(func, name, param_types, result_types) \
00134 DECLARE_CMD_HUNK_2(func, name, \
00135 BOOST_PP_SEQ_TRANSFORM(HUNK_TYPE_LETTER, _, param_types), \
00136 BOOST_PP_SEQ_TRANSFORM(HUNK_TYPE_LETTER, _, result_types), \
00137 0) \
00138
00139
00140 #define DECLARE_CMD_HUNK_FLAGS(func, param_types, result_types, flags) \
00141 DECLARE_CMD_HUNK_2(func, func, \
00142 BOOST_PP_SEQ_TRANSFORM(HUNK_TYPE_LETTER, _, param_types), \
00143 BOOST_PP_SEQ_TRANSFORM(HUNK_TYPE_LETTER, _, result_types), \
00144 flags) \
00145
00146
00147 #endif