📄 log_constraint_visitors.cpp
字号:
case CORBA::tk_array:
{
TAO_DynEnum_i dyn_array;
dyn_array.init (this->current_member_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
success = dyn_array.seek (slot
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if (success == 0)
{
return -1;
}
member = dyn_array.current_component (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
break;
}
case CORBA::tk_sequence:
{
TAO_DynStruct_i dyn_sequence;
dyn_sequence.init (this->current_member_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
success = dyn_sequence.seek (slot
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if (success == 0)
{
return -1;
}
member =
dyn_sequence.current_component (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
break;
}
// Enums and sequences are the only two cases handled
// by Component_Array.
default:
return -1;
}
CORBA::Any_var value = member->to_any (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
TAO_ETCL_Constraint *comp = array->component ();
if (comp == 0)
{
TAO_ETCL_Literal_Constraint result (value);
this->queue_.enqueue_head (result);
return 0;
}
else
{
this->current_member_ = value._retn ();
return comp->accept (this);
}
}
ACE_CATCHANY
{
return -1;
}
ACE_ENDTRY;
ACE_CHECK_RETURN (-1);
return 0;
}
int
TAO_Log_Constraint_Visitor::visit_special (TAO_ETCL_Special *special)
{
ACE_DECLARE_NEW_CORBA_ENV;
ACE_TRY
{
CORBA::TypeCode_var tc = this->current_member_->type ();
switch (special->type ())
{
case TAO_ETCL_LENGTH:
{
// If the TCKind is not a sequence or an array, the
// call to length() will raise an exception, and the
// catch block will return -1;
CORBA::ULong length = tc->length (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
TAO_ETCL_Literal_Constraint lit (length);
this->queue_.enqueue_head (lit);
return 0;
}
case TAO_ETCL_DISCRIMINANT:
{
// If the TCKind is not a union, the
// call to init() will raise an exception, and the
// catch block will return -1;
TAO_DynUnion_i dyn_union;
dyn_union.init (this->current_member_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
DynamicAny::DynAny_var disc =
dyn_union.get_discriminator (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
CORBA::Any_var disc_any = disc->to_any (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
TAO_ETCL_Literal_Constraint lit (disc_any);
this->queue_.enqueue_head (lit);
return 0;
}
case TAO_ETCL_TYPE_ID:
{
const char *name = tc->name (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
TAO_ETCL_Literal_Constraint lit (name);
this->queue_.enqueue_head (lit);
return 0;
}
case TAO_ETCL_REPOS_ID:
{
const char *id = tc->id (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
TAO_ETCL_Literal_Constraint lit (id);
this->queue_.enqueue_head (lit);
return 0;
}
default:
return -1;
}
}
ACE_CATCHANY
{
return -1;
}
ACE_ENDTRY;
ACE_CHECK_RETURN (-1);
return 0;
}
int
TAO_Log_Constraint_Visitor::visit_component (
TAO_ETCL_Component *component
)
{
// If this component has no sub-component, only an identifier,
// then we just visit the identifier, which puts a literal on
// the queue to be handled upon returning from this method call.
// If there is a sub-component, we store the literal's value
// in our member _var for possible examination at a more
// nested level, and visit the sub-component.
TAO_ETCL_Constraint *nested = component->component ();
int result = component->identifier ()->accept (this);
if (nested == 0 || result != 0)
{
return result;
}
else
{
TAO_ETCL_Literal_Constraint id;
this->queue_.dequeue_head (id);
CORBA::Any *any_ptr = 0;
ACE_NEW_RETURN (any_ptr,
CORBA::Any (*(const CORBA::Any *) id),
-1);
this->current_member_ = any_ptr;
return nested->accept (this);
}
}
int
TAO_Log_Constraint_Visitor::visit_dot (TAO_ETCL_Dot *dot)
{
// If we are here, we know we're headed for a more nested
// level, so we just visit it, there's nothing else in this
// constraint.
return dot->component ()->accept (this);
}
int
TAO_Log_Constraint_Visitor::visit_eval (TAO_ETCL_Eval *eval)
{
// Nothing to do but visit the contained component.
return eval->component ()->accept (this);
}
int
TAO_Log_Constraint_Visitor::visit_default (TAO_ETCL_Default *def)
{
TAO_ETCL_Constraint *comp = def->component ();
if (comp == 0)
{
return -1;
}
if (comp->accept (this) != 0)
{
return -1;
}
ACE_DECLARE_NEW_CORBA_ENV;
ACE_TRY
{
CORBA::TypeCode_var tc = this->current_member_->type ();
// If the current member is not a union, this call will
// throw BadKind and the catch block will return -1.
CORBA::Long default_index = tc->default_index (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
// No default index.
if (default_index == -1)
{
TAO_ETCL_Literal_Constraint result ((CORBA::Boolean) 0);
this->queue_.enqueue_head (result);
return 0;
}
// Okay, there's a default index, but is it active?
TAO_ETCL_Literal_Constraint disc;
this->queue_.dequeue_head (disc);
TAO_ETCL_Literal_Constraint default_index_value (default_index);
return (disc == default_index_value);
}
ACE_CATCHANY
{
return -1;
}
ACE_ENDTRY;
ACE_CHECK_RETURN (-1);
return 0;
}
int
TAO_Log_Constraint_Visitor::visit_exist (TAO_ETCL_Exist *exist)
{
TAO_ETCL_Constraint *component = exist->component ();
if (component->accept (this) == 0)
{
TAO_ETCL_Literal_Constraint top;
this->queue_.dequeue_head (top);
const char *value = (const char *) top;
ACE_CString key (value, 0, 0);
CORBA::Boolean result = (this->property_lookup_.find (key) == 0);
this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
return 0;
}
return -1;
}
int
TAO_Log_Constraint_Visitor::visit_unary_expr (
TAO_ETCL_Unary_Expr *unary_expr
)
{
TAO_ETCL_Constraint *subexpr = unary_expr->subexpr ();
if (subexpr->accept (this) == 0)
{
TAO_ETCL_Literal_Constraint subexpr_result;
CORBA::Boolean result = 0;
int op_type = unary_expr->type ();
switch (op_type)
{
case TAO_ETCL_NOT:
this->queue_.dequeue_head (subexpr_result);
result = ! (CORBA::Boolean) subexpr_result;
this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
return 0;
case TAO_ETCL_MINUS:
// The leading '-' was parsed separately, so we have to pull
// the literal constraint off the queue, apply the class' own
// unary minus operator, and put it back.
this->queue_.dequeue_head (subexpr_result);
this->queue_.enqueue_head (-subexpr_result);
return 0;
case TAO_ETCL_PLUS:
// Leave the literal constraint on the queue. The leading
// '+' was just syntactic sugar - no action is necessary.
return 0;
default:
// The parser should never construct a TAO_ETCL_Unary_Constraint
// behind any operators except the above three.
return -1;
}
}
return -1;
}
int
TAO_Log_Constraint_Visitor::visit_binary_expr (
TAO_ETCL_Binary_Expr *binary_expr
)
{
// Evaluate the constraint
int bin_op_type = binary_expr->type ();
switch (bin_op_type)
{
case TAO_ETCL_OR:
return this->visit_or (binary_expr);
case TAO_ETCL_AND:
return this->visit_and (binary_expr);
case TAO_ETCL_LT:
case TAO_ETCL_LE:
case TAO_ETCL_GT:
case TAO_ETCL_GE:
case TAO_ETCL_EQ:
case TAO_ETCL_NE:
case TAO_ETCL_PLUS:
case TAO_ETCL_MINUS:
case TAO_ETCL_MULT:
case TAO_ETCL_DIV:
return this->visit_binary_op (binary_expr,
bin_op_type);
case TAO_ETCL_TWIDDLE:
return this->visit_twiddle (binary_expr);
case TAO_ETCL_IN:
return this->visit_in (binary_expr);
default:
return -1;
}
}
int
TAO_Log_Constraint_Visitor::visit_or (
TAO_ETCL_Binary_Expr *binary
)
{
int return_value = -1;
CORBA::Boolean result = 0;
TAO_ETCL_Constraint *lhs = binary->lhs ();
if (lhs->accept (this) == 0)
{
TAO_ETCL_Literal_Constraint lhs_result;
this->queue_.dequeue_head (lhs_result);
result = (CORBA::Boolean) lhs_result;
// Short-circuiting OR.
if (result == 0)
{
TAO_ETCL_Constraint *rhs = binary->rhs ();
if (rhs->accept (this) == 0)
{
TAO_ETCL_Literal_Constraint rhs_result;
this->queue_.dequeue_head (rhs_result);
result = (CORBA::Boolean) rhs_result;
return_value = 0;
}
}
else
{
return_value = 0;
}
}
if (return_value == 0)
{
this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
}
return return_value;
}
int
TAO_Log_Constraint_Visitor::visit_and (
TAO_ETCL_Binary_Expr *binary
)
{
int return_value = -1;
CORBA::Boolean result = 0;
TAO_ETCL_Constraint *lhs = binary->lhs ();
if (lhs->accept (this) == 0)
{
TAO_ETCL_Literal_Constraint lhs_result;
this->queue_.dequeue_head (lhs_result);
result = (CORBA::Boolean) lhs_result;
// Short-circuiting AND.
if (result == 1)
{
TAO_ETCL_Constraint *rhs = binary->rhs ();
if (rhs->accept (this) == 0)
{
TAO_ETCL_Literal_Constraint rhs_result;
this->queue_.dequeue_head (rhs_result);
result = (CORBA::Boolean) rhs_result;
return_value = 0;
}
}
else
{
return_value = 0;
}
}
if (return_value == 0)
{
this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
}
return return_value;
}
int
TAO_Log_Constraint_Visitor::visit_binary_op (
TAO_ETCL_Binary_Expr *binary,
int op_type
)
{
int return_value = -1;
TAO_ETCL_Constraint *lhs = binary->lhs ();
CORBA::Boolean result = 0;
// Evaluate the constraint
// Perform an operation on the results of evaluating the left and
// right branches of this subtree.
if (lhs->accept (this) == 0)
{
// Evaluate the constraint
TAO_ETCL_Literal_Constraint left_operand;
this->queue_.dequeue_head (left_operand);
TAO_ETCL_Constraint *rhs = binary->rhs ();
if (rhs->accept (this) == 0)
{
TAO_ETCL_Literal_Constraint right_operand;
this->queue_.dequeue_head (right_operand);
return_value = 0;
switch (op_type)
{
case TAO_ETCL_LT:
result = left_operand < right_operand;
this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -