Cleanup Solaris support
[ACE_TAO.git] / ACE / ace / Monitor_Control / Constraint_Visitor.cpp
blob786ffe5ee72942eea7fbac11461fef30f92bcf06
1 #include "ace/Monitor_Control/Constraint_Visitor.h"
3 #if defined (ACE_HAS_MONITOR_FRAMEWORK) && (ACE_HAS_MONITOR_FRAMEWORK == 1)
5 #include "ace/ETCL/ETCL_y.h"
6 #include "ace/ETCL/ETCL_Constraint.h"
8 #include "ace/OS_NS_string.h"
10 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
12 namespace ACE
14 namespace Monitor_Control
16 Constraint_Visitor::Constraint_Visitor (
17 const Monitor_Control_Types::Data& data)
18 : data_ (data)
21 ACE_CDR::Boolean
22 Constraint_Visitor::evaluate_constraint (ETCL_Constraint *root)
24 ACE_CDR::Boolean result = false;
25 this->queue_.reset ();
27 // Evaluate the constraint in root_;
28 if (root != 0)
30 if (root->accept (this) == 0 && !this->queue_.is_empty ())
32 ETCL_Literal_Constraint top;
33 this->queue_.dequeue_head (top);
34 result = (ACE_CDR::Boolean) top;
38 // If a property couldn't be evaluated we must return FALSE.
39 return result;
42 int
43 Constraint_Visitor::visit_literal (ETCL_Literal_Constraint *constraint)
45 this->queue_.enqueue_head (*constraint);
46 return 0;
49 int
50 Constraint_Visitor::visit_identifier (ETCL_Identifier *ident)
52 /// TODO - check for strings related to other identifiers
53 /// relevant in MonitorControl, for example the data timestamp.
54 if (ACE_OS::strcmp (ident->value (), "value") == 0)
56 this->queue_.enqueue_head (
57 ETCL_Literal_Constraint (this->data_.value_));
59 return 0;
62 return -1;
65 int
66 Constraint_Visitor::visit_unary_expr (ETCL_Unary_Expr *unary_expr)
68 ETCL_Constraint *subexpression = unary_expr->subexpr ();
70 /// Call to accept() puts the subexpression's evaluation on our queue.
71 if (subexpression->accept (this) == 0)
73 ETCL_Literal_Constraint subexpr_result;
74 ACE_CDR::Boolean result = 0;
75 int op_type = unary_expr->type ();
77 switch (op_type)
79 case ETCL_NOT:
80 this->queue_.dequeue_head (subexpr_result);
81 result = ! (ACE_CDR::Boolean) subexpr_result;
82 this->queue_.enqueue_head (ETCL_Literal_Constraint (result));
83 return 0;
84 case ETCL_MINUS:
85 /// The leading '-' was parsed separately, so we have to pull
86 /// the literal constraint off the queue, apply the class' own
87 /// unary minus operator, and put it back.
88 this->queue_.dequeue_head (subexpr_result);
89 this->queue_.enqueue_head (-subexpr_result);
90 return 0;
91 case ETCL_PLUS:
92 /// Leave the literal constraint on the queue. The leading
93 /// '+' was just syntactic sugar - no action is necessary.
94 return 0;
95 default:
96 /// The parser should never construct a ETCL_Unary_Constraint
97 /// behind any operators except the above three.
98 return -1;
102 return -1;
106 Constraint_Visitor::visit_binary_expr (ETCL_Binary_Expr *binary_expr)
108 int bin_op_type = binary_expr->type ();
110 switch (bin_op_type)
112 case ETCL_OR:
113 return this->visit_or (binary_expr);
114 case ETCL_AND:
115 return this->visit_and (binary_expr);
116 case ETCL_LT:
117 case ETCL_LE:
118 case ETCL_GT:
119 case ETCL_GE:
120 case ETCL_EQ:
121 case ETCL_NE:
122 case ETCL_PLUS:
123 case ETCL_MINUS:
124 case ETCL_MULT:
125 case ETCL_DIV:
126 return this->visit_binary_op (binary_expr, bin_op_type);
127 /// These last two are not supported in non_CORBA ETCL.
128 case ETCL_TWIDDLE:
129 case ETCL_IN:
130 default:
131 return -1;
136 Constraint_Visitor::visit_or (ETCL_Binary_Expr *binary)
138 int return_value = -1;
139 ACE_CDR::Boolean result = false;
140 ETCL_Constraint *lhs = binary->lhs ();
142 /// Call to accept() puts the lhs (or its evaluation) on our queue.
143 if (lhs->accept (this) == 0)
145 ETCL_Literal_Constraint lhs_result;
146 this->queue_.dequeue_head (lhs_result);
147 result = (ACE_CDR::Boolean) lhs_result;
149 /// Short-circuiting OR.
150 if (!result)
152 ETCL_Constraint *rhs = binary->rhs ();
154 if (rhs->accept (this) == 0)
156 ETCL_Literal_Constraint rhs_result;
157 this->queue_.dequeue_head (rhs_result);
158 result = (ACE_CDR::Boolean) rhs_result;
159 return_value = 0;
162 else
164 return_value = 0;
168 if (return_value == 0)
170 this->queue_.enqueue_head (ETCL_Literal_Constraint (result));
173 return return_value;
177 Constraint_Visitor::visit_and (ETCL_Binary_Expr *binary)
179 int return_value = -1;
180 ACE_CDR::Boolean result = false;
181 ETCL_Constraint *lhs = binary->lhs ();
183 /// Call to accept() puts the lhs (or its evaluation) on our queue.
184 if (lhs->accept (this) == 0)
186 ETCL_Literal_Constraint lhs_result;
187 this->queue_.dequeue_head (lhs_result);
188 result = (ACE_CDR::Boolean) lhs_result;
190 /// Short-circuiting AND.
191 if (result == true)
193 ETCL_Constraint *rhs = binary->rhs ();
195 if (rhs->accept (this) == 0)
197 ETCL_Literal_Constraint rhs_result;
198 this->queue_.dequeue_head (rhs_result);
199 result = (ACE_CDR::Boolean) rhs_result;
200 return_value = 0;
203 else
205 return_value = 0;
209 if (return_value == 0)
211 this->queue_.enqueue_head (ETCL_Literal_Constraint (result));
214 return return_value;
218 Constraint_Visitor::visit_binary_op (ETCL_Binary_Expr *binary,
219 int op_type)
221 int return_value = -1;
222 ETCL_Constraint *lhs = binary->lhs ();
223 ACE_CDR::Boolean result = false;
225 /// Perform an operation on the results of evaluating the left and
226 /// right branches of this subtree. The evaluations go on our queue.
227 if (lhs->accept (this) == 0)
229 ETCL_Literal_Constraint left_operand;
230 this->queue_.dequeue_head (left_operand);
231 ETCL_Constraint *rhs = binary->rhs ();
233 if (rhs->accept (this) == 0)
235 ETCL_Literal_Constraint right_operand;
236 this->queue_.dequeue_head (right_operand);
237 return_value = 0;
239 switch (op_type)
241 case ETCL_LT:
242 result = left_operand < right_operand;
243 this->queue_.enqueue_head (
244 ETCL_Literal_Constraint (result));
245 break;
246 case ETCL_LE:
247 result = left_operand <= right_operand;
248 this->queue_.enqueue_head (
249 ETCL_Literal_Constraint (result));
250 break;
251 case ETCL_GT:
252 result = left_operand > right_operand;
253 this->queue_.enqueue_head (
254 ETCL_Literal_Constraint (result));
255 break;
256 case ETCL_GE:
257 result = left_operand >= right_operand;
258 this->queue_.enqueue_head (
259 ETCL_Literal_Constraint (result));
260 break;
261 case ETCL_EQ:
262 result = left_operand == right_operand;
263 this->queue_.enqueue_head (
264 ETCL_Literal_Constraint (result));
265 break;
266 case ETCL_NE:
267 result = left_operand != right_operand;
268 this->queue_.enqueue_head (
269 ETCL_Literal_Constraint (result));
270 break;
271 case ETCL_PLUS:
272 this->queue_.enqueue_head (
273 left_operand + right_operand);
274 break;
275 case ETCL_MINUS:
276 this->queue_.enqueue_head (
277 left_operand - right_operand);
278 break;
279 case ETCL_MULT:
280 this->queue_.enqueue_head (
281 left_operand * right_operand);
282 break;
283 case ETCL_DIV:
284 this->queue_.enqueue_head (
285 left_operand / right_operand);
286 break;
287 default:
288 return_value = -1;
289 break;
294 return return_value;
299 ACE_END_VERSIONED_NAMESPACE_DECL
301 #endif /* ACE_HAS_MONITOR_FRAMEWORK==1 */