File indexing completed on 2025-02-27 09:18:07
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 #ifdef CEXMC_USE_CUSTOM_FILTER
0045
0046 #include "CexmcCustomFilter.hh"
0047
0048
0049 namespace CexmcCustomFilter
0050 {
0051 void Compiler::operator()( ParseResult & parseResult, Action value )
0052 const
0053 {
0054 parseResult.action = value;
0055 }
0056
0057
0058 void Compiler::operator()( ParseResult & parseResult, Subtree & value )
0059 const
0060 {
0061 parseResult.expression = value;
0062 }
0063
0064
0065 void Compiler::operator()( Subtree & ast, Node & node ) const
0066 {
0067 try
0068 {
0069 ast = boost::get< Subtree >( node );
0070 }
0071 catch ( const boost::bad_get & )
0072 {
0073 ast.type = Operator( Top );
0074 ast.children.push_back( node );
0075 }
0076 }
0077
0078
0079 void Compiler::operator()( Node & self, Node & left, Node & right,
0080 Operator value ) const
0081 {
0082 Subtree & ast( boost::get< Subtree >( self ) );
0083
0084 ast.children.push_back( left );
0085 ast.type = value;
0086
0087 Subtree * astRight( boost::get< Subtree >( &right ) );
0088
0089 if ( ! astRight )
0090 {
0091 ast.children.push_back( right );
0092 return;
0093 }
0094
0095 bool haveSamePriorities( false );
0096 Operator * rightOp( boost::get< Operator >( &astRight->type ) );
0097
0098 if ( rightOp )
0099 haveSamePriorities = value.priority == rightOp->priority;
0100
0101 if ( value.hasRLAssoc || ! haveSamePriorities )
0102 {
0103 ast.children.push_back( right );
0104 return;
0105 }
0106
0107 Subtree * astDeepestRight( astRight );
0108
0109
0110
0111
0112
0113 while ( true )
0114 {
0115 Subtree * candidate = boost::get< Subtree >(
0116 &astDeepestRight->children[ 0 ] );
0117 if ( ! candidate )
0118 break;
0119
0120 if ( candidate->children.size() < 2 )
0121 break;
0122
0123 bool haveSamePriorities_( false );
0124 Operator * candidateOp( boost::get< Operator >(
0125 &candidate->type ) );
0126
0127 if ( candidateOp )
0128 haveSamePriorities_ = value.priority == candidateOp->priority;
0129
0130
0131
0132 if ( ! haveSamePriorities_ )
0133 break;
0134
0135 astDeepestRight = candidate;
0136 }
0137
0138 Subtree astResult;
0139 astResult.children.push_back( ast.children[ 0 ] );
0140 astResult.children.push_back( astDeepestRight->children[ 0 ] );
0141 astResult.type = value;
0142 astDeepestRight->children[ 0 ] = astResult;
0143 self = right;
0144 }
0145
0146
0147 void Compiler::operator()( Node & self, Node & child, Operator value )
0148 const
0149 {
0150 Subtree & ast( boost::get< Subtree >( self ) );
0151 ast.children.push_back( child );
0152 ast.type = value;
0153 }
0154
0155
0156 void Compiler::operator()( Node & self, Node & primary ) const
0157 {
0158 self = primary;
0159
0160 Subtree * ast( boost::get< Subtree >( &self ) );
0161
0162 if ( ! ast )
0163 return;
0164
0165 Operator * op( boost::get< Operator >( &ast->type ) );
0166
0167 if ( op )
0168 op->priority = 0;
0169 }
0170
0171
0172 void Compiler::operator()( Node & self, Node & child,
0173 std::string & value ) const
0174 {
0175 Subtree & ast( boost::get< Subtree >( self ) );
0176
0177 ast.children.push_back( child );
0178 ast.type = value;
0179 }
0180
0181
0182 void Compiler::operator()( Leaf & self, std::string & name ) const
0183 {
0184 Variable & variable( boost::get< Variable >( self ) );
0185 variable.name = name;
0186 }
0187
0188
0189 void Compiler::operator()( Leaf & self, int value, size_t index ) const
0190 {
0191 Variable & variable( boost::get< Variable >( self ) );
0192 switch ( index )
0193 {
0194 case 0 :
0195 variable.index1 = value;
0196 break;
0197 case 1 :
0198 variable.index2 = value;
0199 break;
0200 default :
0201 break;
0202 }
0203 }
0204 }
0205
0206 #endif
0207