File indexing completed on 2025-01-31 09:21:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 #ifndef CEXMC_AST_HH
0045 #define CEXMC_AST_HH
0046
0047 #ifdef CEXMC_USE_CUSTOM_FILTER
0048
0049 #include <vector>
0050 #include <boost/variant/recursive_variant.hpp>
0051
0052
0053 namespace CexmcAST
0054 {
0055 using boost::variant;
0056 using boost::recursive_wrapper;
0057
0058 enum OperatorType
0059 {
0060 Uninitialized,
0061 Top,
0062 UMinus,
0063 Not,
0064 Mult,
0065 Div,
0066 Plus,
0067 Minus,
0068 Less,
0069 LessEq,
0070 More,
0071 MoreEq,
0072 Eq,
0073 NotEq,
0074 And,
0075 Or
0076 };
0077
0078
0079 struct Operator
0080 {
0081 Operator( OperatorType type_ = Uninitialized, int priority_ = 0,
0082 bool hasRLAssoc_ = false ) :
0083 type( type_ ), priority( priority_ ), hasRLAssoc( hasRLAssoc_ )
0084 {}
0085
0086 OperatorType type;
0087
0088 int priority;
0089
0090 bool hasRLAssoc;
0091 };
0092
0093
0094 struct Variable
0095 {
0096 Variable() : index1( 0 ), index2( 0 ), addr( ( const int * ) NULL )
0097 {}
0098
0099 std::string name;
0100
0101 int index1;
0102
0103 int index2;
0104
0105 variant< const int *, const double * > addr;
0106 };
0107
0108
0109 struct Subtree;
0110
0111 typedef std::string Function;
0112
0113 typedef variant< int, double > Constant;
0114
0115 typedef variant< Variable, Constant > Leaf;
0116
0117 typedef recursive_wrapper< Subtree > Tree;
0118
0119 typedef variant< Tree, Leaf > Node;
0120
0121 typedef variant< Operator, Function > NodeType;
0122
0123
0124 struct Subtree
0125 {
0126 Subtree() : type( Operator( Uninitialized ) )
0127 {}
0128
0129 void Print( int level = 0 ) const;
0130
0131 void PrintLeaf( const Leaf * leaf, int level = 0 ) const;
0132
0133 std::vector< Node > children;
0134
0135 NodeType type;
0136
0137 static const int printIndent = 4;
0138 };
0139
0140
0141 class BasicEval
0142 {
0143 protected:
0144 typedef variant< int, double > ScalarValueType;
0145
0146 protected:
0147 virtual ~BasicEval();
0148
0149 public:
0150 bool operator()( const Subtree & ast ) const;
0151
0152 protected:
0153 ScalarValueType GetScalarValue( const Node & node ) const;
0154
0155 virtual ScalarValueType GetFunScalarValue( const Subtree & ast )
0156 const;
0157
0158 virtual ScalarValueType GetVarScalarValue( const Variable & var )
0159 const;
0160
0161 ScalarValueType GetBasicFunScalarValue(
0162 const Subtree & ast, bool & result )
0163 const;
0164 };
0165 }
0166
0167 #endif
0168
0169 #endif
0170