bool UnaryOpExpression::preCompute(CVarRef value, Variant &result) {
  switch(m_op) {
  case '!':
    result = (!toBoolean(value)); break;
  case '+':
    result = value.unary_plus(); break;
  case '-':
    result = value.negate(); break;
  case '~':
    result = ~value; break;
  case '(':
  case '@':
    result = value; break;
  case T_INT_CAST:
    result = value.toInt64(); break;
  case T_DOUBLE_CAST:
    result = toDouble(value); break;
  case T_STRING_CAST:
    result = toString(value); break;
  case T_BOOL_CAST:
    result = toBoolean(value); break;
  case T_INC:
  case T_DEC:
    ASSERT(false);
  default:
    return false;
  }
  return true;
}
Пример #2
0
bool UnaryOpExpression::preCompute(CVarRef value, Variant &result) {
  bool ret = true;
  try {
    g_context->setThrowAllErrors(true);
    switch(m_op) {
      case '!':
        result = (!toBoolean(value)); break;
      case '+':
        result = value.unary_plus(); break;
      case '-':
        result = value.negate(); break;
      case '~':
        result = value.bitNot(); break;
      case '@':
        result = value; break;
      case T_INT_CAST:
        result = value.toInt64(); break;
      case T_DOUBLE_CAST:
        result = toDouble(value); break;
      case T_STRING_CAST:
        result = toString(value); break;
      case T_BOOL_CAST:
        result = toBoolean(value); break;
      case T_EMPTY:
        result = empty(value); break;
      case T_ISSET:
        result = isset(value); break;
      case T_INC:
      case T_DEC:
        assert(false);
      default:
        ret = false;
        break;
    }
  } catch (...) {
    ret = false;
  }
  g_context->setThrowAllErrors(false);
  return ret;
}