Go to the documentation of this file.00001
00002
00003 #include "ace/Monitor_Control/Constraint_Visitor.h"
00004
00005 #if defined (ACE_HAS_MONITOR_FRAMEWORK) && (ACE_HAS_MONITOR_FRAMEWORK == 1)
00006
00007 #include "ace/ETCL/ETCL_y.h"
00008 #include "ace/ETCL/ETCL_Constraint.h"
00009
00010 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00011
00012 namespace ACE
00013 {
00014 namespace Monitor_Control
00015 {
00016 Constraint_Visitor::Constraint_Visitor (
00017 const Monitor_Control_Types::Data& data)
00018 : data_ (data)
00019 {}
00020
00021 Constraint_Visitor::~Constraint_Visitor (void)
00022 {}
00023
00024 ACE_CDR::Boolean
00025 Constraint_Visitor::evaluate_constraint (ETCL_Constraint *root)
00026 {
00027 ACE_CDR::Boolean result = false;
00028 this->queue_.reset ();
00029
00030
00031 if (root != 0)
00032 {
00033 if (root->accept (this) == 0 && !this->queue_.is_empty ())
00034 {
00035 ETCL_Literal_Constraint top;
00036 this->queue_.dequeue_head (top);
00037 result = (ACE_CDR::Boolean) top;
00038 }
00039 }
00040
00041
00042 return result;
00043 }
00044
00045 int
00046 Constraint_Visitor::visit_literal (ETCL_Literal_Constraint *constraint)
00047 {
00048 this->queue_.enqueue_head (*constraint);
00049 return 0;
00050 }
00051
00052 int
00053 Constraint_Visitor::visit_identifier (ETCL_Identifier *ident)
00054 {
00055
00056
00057 if (ACE_OS::strcmp (ident->value (), "value") == 0)
00058 {
00059 this->queue_.enqueue_head (
00060 ETCL_Literal_Constraint (this->data_.value_));
00061
00062 return 0;
00063 }
00064
00065 return -1;
00066 }
00067
00068 int
00069 Constraint_Visitor::visit_unary_expr (ETCL_Unary_Expr *unary_expr)
00070 {
00071 ETCL_Constraint *subexpression = unary_expr->subexpr ();
00072
00073
00074 if (subexpression->accept (this) == 0)
00075 {
00076 ETCL_Literal_Constraint subexpr_result;
00077 ACE_CDR::Boolean result = 0;
00078 int op_type = unary_expr->type ();
00079
00080 switch (op_type)
00081 {
00082 case ETCL_NOT:
00083 this->queue_.dequeue_head (subexpr_result);
00084 result = ! (ACE_CDR::Boolean) subexpr_result;
00085 this->queue_.enqueue_head (ETCL_Literal_Constraint (result));
00086 return 0;
00087 case ETCL_MINUS:
00088
00089
00090
00091 this->queue_.dequeue_head (subexpr_result);
00092 this->queue_.enqueue_head (-subexpr_result);
00093 return 0;
00094 case ETCL_PLUS:
00095
00096
00097 return 0;
00098 default:
00099
00100
00101 return -1;
00102 }
00103 }
00104
00105 return -1;
00106 }
00107
00108 int
00109 Constraint_Visitor::visit_binary_expr (ETCL_Binary_Expr *binary_expr)
00110 {
00111 int bin_op_type = binary_expr->type ();
00112
00113 switch (bin_op_type)
00114 {
00115 case ETCL_OR:
00116 return this->visit_or (binary_expr);
00117 case ETCL_AND:
00118 return this->visit_and (binary_expr);
00119 case ETCL_LT:
00120 case ETCL_LE:
00121 case ETCL_GT:
00122 case ETCL_GE:
00123 case ETCL_EQ:
00124 case ETCL_NE:
00125 case ETCL_PLUS:
00126 case ETCL_MINUS:
00127 case ETCL_MULT:
00128 case ETCL_DIV:
00129 return this->visit_binary_op (binary_expr, bin_op_type);
00130
00131 case ETCL_TWIDDLE:
00132 case ETCL_IN:
00133 default:
00134 return -1;
00135 }
00136 }
00137
00138 int
00139 Constraint_Visitor::visit_or (ETCL_Binary_Expr *binary)
00140 {
00141 int return_value = -1;
00142 ACE_CDR::Boolean result = false;
00143 ETCL_Constraint *lhs = binary->lhs ();
00144
00145
00146 if (lhs->accept (this) == 0)
00147 {
00148 ETCL_Literal_Constraint lhs_result;
00149 this->queue_.dequeue_head (lhs_result);
00150 result = (ACE_CDR::Boolean) lhs_result;
00151
00152
00153 if (!result)
00154 {
00155 ETCL_Constraint *rhs = binary->rhs ();
00156
00157 if (rhs->accept (this) == 0)
00158 {
00159 ETCL_Literal_Constraint rhs_result;
00160 this->queue_.dequeue_head (rhs_result);
00161 result = (ACE_CDR::Boolean) rhs_result;
00162 return_value = 0;
00163 }
00164 }
00165 else
00166 {
00167 return_value = 0;
00168 }
00169 }
00170
00171 if (return_value == 0)
00172 {
00173 this->queue_.enqueue_head (ETCL_Literal_Constraint (result));
00174 }
00175
00176 return return_value;
00177 }
00178
00179 int
00180 Constraint_Visitor::visit_and (ETCL_Binary_Expr *binary)
00181 {
00182 int return_value = -1;
00183 ACE_CDR::Boolean result = false;
00184 ETCL_Constraint *lhs = binary->lhs ();
00185
00186
00187 if (lhs->accept (this) == 0)
00188 {
00189 ETCL_Literal_Constraint lhs_result;
00190 this->queue_.dequeue_head (lhs_result);
00191 result = (ACE_CDR::Boolean) lhs_result;
00192
00193
00194 if (result == true)
00195 {
00196 ETCL_Constraint *rhs = binary->rhs ();
00197
00198 if (rhs->accept (this) == 0)
00199 {
00200 ETCL_Literal_Constraint rhs_result;
00201 this->queue_.dequeue_head (rhs_result);
00202 result = (ACE_CDR::Boolean) rhs_result;
00203 return_value = 0;
00204 }
00205 }
00206 else
00207 {
00208 return_value = 0;
00209 }
00210 }
00211
00212 if (return_value == 0)
00213 {
00214 this->queue_.enqueue_head (ETCL_Literal_Constraint (result));
00215 }
00216
00217 return return_value;
00218 }
00219
00220 int
00221 Constraint_Visitor::visit_binary_op (ETCL_Binary_Expr *binary,
00222 int op_type)
00223 {
00224 int return_value = -1;
00225 ETCL_Constraint *lhs = binary->lhs ();
00226 ACE_CDR::Boolean result = false;
00227
00228
00229
00230 if (lhs->accept (this) == 0)
00231 {
00232 ETCL_Literal_Constraint left_operand;
00233 this->queue_.dequeue_head (left_operand);
00234 ETCL_Constraint *rhs = binary->rhs ();
00235
00236 if (rhs->accept (this) == 0)
00237 {
00238 ETCL_Literal_Constraint right_operand;
00239 this->queue_.dequeue_head (right_operand);
00240 return_value = 0;
00241
00242 switch (op_type)
00243 {
00244 case ETCL_LT:
00245 result = left_operand < right_operand;
00246 this->queue_.enqueue_head (
00247 ETCL_Literal_Constraint (result));
00248 break;
00249 case ETCL_LE:
00250 result = left_operand <= right_operand;
00251 this->queue_.enqueue_head (
00252 ETCL_Literal_Constraint (result));
00253 break;
00254 case ETCL_GT:
00255 result = left_operand > right_operand;
00256 this->queue_.enqueue_head (
00257 ETCL_Literal_Constraint (result));
00258 break;
00259 case ETCL_GE:
00260 result = left_operand >= right_operand;
00261 this->queue_.enqueue_head (
00262 ETCL_Literal_Constraint (result));
00263 break;
00264 case ETCL_EQ:
00265 result = left_operand == right_operand;
00266 this->queue_.enqueue_head (
00267 ETCL_Literal_Constraint (result));
00268 break;
00269 case ETCL_NE:
00270 result = left_operand != right_operand;
00271 this->queue_.enqueue_head (
00272 ETCL_Literal_Constraint (result));
00273 break;
00274 case ETCL_PLUS:
00275 this->queue_.enqueue_head (
00276 left_operand + right_operand);
00277 break;
00278 case ETCL_MINUS:
00279 this->queue_.enqueue_head (
00280 left_operand - right_operand);
00281 break;
00282 case ETCL_MULT:
00283 this->queue_.enqueue_head (
00284 left_operand * right_operand);
00285 break;
00286 case ETCL_DIV:
00287 this->queue_.enqueue_head (
00288 left_operand / right_operand);
00289 break;
00290 default:
00291 return_value = -1;
00292 break;
00293 }
00294 }
00295 }
00296
00297 return return_value;
00298 }
00299 }
00300 }
00301
00302 ACE_END_VERSIONED_NAMESPACE_DECL
00303
00304 #endif