int
TAO_Log_Constraint_Visitor::visit_twiddle (
    ETCL_Binary_Expr *binary)
{
  int return_value = -1;
  ETCL_Constraint *lhs = binary->lhs ();

  // Determine if the left operand is a substring of the right.
  if (lhs->accept (this) == 0)
    {
      TAO_ETCL_Literal_Constraint left;
      this->queue_.dequeue_head (left);
      ETCL_Constraint *rhs = binary->rhs ();

      if (rhs->accept (this) == 0)
        {
          TAO_ETCL_Literal_Constraint right;
          this->queue_.dequeue_head (right);
          CORBA::Boolean result =
            (ACE_OS::strstr ((const char *) left,
                             (const char *) right) != 0);
          this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
          return_value = 0;
        }
    }

  return return_value;
}
int
TAO_Log_Constraint_Visitor::visit_identifier (ETCL_Identifier *ident)
{
  int return_value = -1;
  const char *name = ident->value ();
  ACE_CString key (name, 0, false);

  CORBA::Any any;

  if (this->property_lookup_.find (key, any) == 0)
    {
      if (any.impl() != 0)
        {
          this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (&any));
          return_value = 0;
        }
    }

  return return_value;
}
示例#3
0
int
TAO_Log_Constraint_Visitor::visit_and (
    ETCL_Binary_Expr *binary
)
{
    int return_value = -1;
    CORBA::Boolean result = false;
    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)
        {
            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;
}
示例#4
0
int
TAO_Log_Constraint_Visitor::visit_unary_expr (
    ETCL_Unary_Expr *unary_expr
)
{
    ETCL_Constraint *subexpr = unary_expr->subexpr ();

    if (subexpr->accept (this) == 0)
    {
        TAO_ETCL_Literal_Constraint subexpr_result;
        CORBA::Boolean result = false;
        int op_type = unary_expr->type ();

        switch (op_type)
        {
        case 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 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 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 ETCL_Unary_Constraint
            // behind any operators except the above three.
            return -1;
        }
    }

    return -1;
}
int
TAO_Log_Constraint_Visitor::visit_exist (ETCL_Exist *exist)
{
  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, false);

      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_in (
    ETCL_Binary_Expr *binary)
{
  int return_value = -1;
  ETCL_Constraint *lhs = binary->lhs ();

  // Determine if the left operand is contained in the right.

  if (lhs->accept (this) == 0)
    {
      TAO_ETCL_Literal_Constraint left;
      this->queue_.dequeue_head (left);

      ETCL_Constraint *rhs = binary->rhs ();

      if (rhs->accept (this) == 0)
        {
          TAO_ETCL_Literal_Constraint bag;
          this->queue_.dequeue_head (bag);

          if (bag.expr_type () == ETCL_COMPONENT)
            {
              CORBA::Any_ptr any_ptr = 0;
              ACE_NEW_RETURN (any_ptr,
                              CORBA::Any,
                              -1);

              CORBA::Any_var component = any_ptr;
              component->replace (bag);
              component->impl ()->_add_ref ();
              CORBA::TCKind kind = CORBA::tk_null;

              try
                {
                  CORBA::TypeCode_var tc = component->type ();
                  kind = TAO_DynAnyFactory::unalias (tc.in ());
                }
              catch (const CORBA::Exception&)
                {
                  return return_value;
                }

              CORBA::Boolean result = 0;

              switch (kind)
              {
                case CORBA::tk_sequence:
                  result = this->sequence_does_contain (&component.in (),
                                                        left);
                  break;
                case CORBA::tk_array:
                  result = this->array_does_contain (&component.in (),
                                                     left);
                  break;
                case CORBA::tk_struct:
                  result = this->struct_does_contain (&component.in (),
                                                      left);
                  break;
                case CORBA::tk_union:
                  result = this->union_does_contain (&component.in (),
                                                     left);
                  break;
                case CORBA::tk_any:
                  result = this->any_does_contain (&component.in (),
                                                   left);
                  break;
                default:
                  return return_value;
              }

              this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
              return_value = 0;
            }
        }
    }

  return return_value;
}
int
TAO_Log_Constraint_Visitor::visit_binary_op (
    ETCL_Binary_Expr *binary,
    int op_type)
{
  int return_value = -1;
  ETCL_Constraint *lhs = binary->lhs ();
  CORBA::Boolean result = false;

  // Evaluate the constraint
  // Perform an operation on the results of evaluating the left and
  // right branches of this subtree.
  if (lhs->accept (this) == 0)
    {
      TAO_ETCL_Literal_Constraint left_operand;
      this->queue_.dequeue_head (left_operand);
      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 ETCL_LT:
              result = left_operand < right_operand;
              this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
              break;
            case ETCL_LE:
              result = left_operand <= right_operand;
              this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
              break;
            case ETCL_GT:
              result = left_operand > right_operand;
              this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
              break;
            case ETCL_GE:
              result = left_operand >= right_operand;
              this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
              break;
            case ETCL_EQ:
              result = left_operand == right_operand;
              this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
              break;
            case ETCL_NE:
              result = left_operand != right_operand;
              this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (result));
              break;
            case ETCL_PLUS:
              this->queue_.enqueue_head (left_operand + right_operand);
              break;
            case ETCL_MINUS:
              this->queue_.enqueue_head (left_operand - right_operand);
              break;
            case ETCL_MULT:
              this->queue_.enqueue_head (left_operand * right_operand);
              break;
            case ETCL_DIV:
              this->queue_.enqueue_head (left_operand / right_operand);
              break;
            default:
              return_value = -1;
          }
        }
    }

  return return_value;
}