Ejemplo n.º 1
0
static ExpressionPtr makeIsNull(AnalysisResultConstPtr ar,
                                LocationPtr loc, ExpressionPtr exp,
                                bool invert) {
  /* Replace "$x === null" with an is_null call; this requires slightly
   * less work at runtime. */
  ExpressionListPtr expList =
    ExpressionListPtr(new ExpressionList(exp->getScope(), loc));
  expList->insertElement(exp);

  SimpleFunctionCallPtr call
    (new SimpleFunctionCall(exp->getScope(), loc,
                            "is_null", false, expList, ExpressionPtr()));

  call->setValid();
  call->setActualType(Type::Boolean);
  call->setupScopes(ar);

  ExpressionPtr result(call);
  if (invert) {
    result = ExpressionPtr(new UnaryOpExpression(
                             exp->getScope(), loc,
                             result, '!', true));
  }

  return result;
}
Ejemplo n.º 2
0
static ExpressionPtr makeIsNull(LocationPtr loc, ExpressionPtr exp,
                                bool invert) {
  /* Replace "$x === null" with an is_null call; this requires slightly
   * less work at runtime. */
  ExpressionListPtr expList =
    ExpressionListPtr(new ExpressionList(loc,
      Expression::KindOfExpressionList));
  expList->insertElement(exp);

  SimpleFunctionCallPtr call
    (new SimpleFunctionCall(loc, Expression::KindOfSimpleFunctionCall,
                            "is_null", expList, ExpressionPtr()));

  call->setValid();
  call->setActualType(Type::Boolean);

  ExpressionPtr result(call);
  if (invert) {
    result = ExpressionPtr(new UnaryOpExpression(
                             loc, Expression::KindOfUnaryOpExpression,
                             result, '!', true));
  }

  return result;
}
Ejemplo n.º 3
0
void AnalysisResult::resolveNSFallbackFuncs() {
  for (auto &pair : m_nsFallbackFuncs) {
    SimpleFunctionCallPtr sfc =
      static_pointer_cast<SimpleFunctionCall>(pair.first);
    sfc->resolveNSFallbackFunc(
      shared_from_this(),
      pair.second
    );
  }
}
Ejemplo n.º 4
0
void Parser::onCall(Token *out, bool dynamic, Token *name, Token *params,
                    Token *className) {
  if (dynamic) {
    out->exp = NEW_EXP(DynamicFunctionCall, name->exp,
                       dynamic_pointer_cast<ExpressionList>(params->exp),
                       className ? &className->text() : NULL);
  } else {
    SimpleFunctionCallPtr call =
      NEW_EXP(SimpleFunctionCall, name->text(),
              dynamic_pointer_cast<ExpressionList>(params->exp),
              className ? &className->text() : NULL);
    out->exp = call;
    call->onParse(m_ar);
  }
}
Ejemplo n.º 5
0
/**
 * If one or more of the arguments of the function call depend on query only
 * state (query local but not a query parameter reference), then rewrite
 * all of the arguments to be query local and return the rewritten
 * function call (the query processor has to either figure out a way to call
 * the function or must cause a runtime error when faced with the call).
 * Otherwise, rewrite the call as a query parameter reference.
 */
ExpressionPtr CaptureExtractor::rewriteCall(SimpleFunctionCallPtr sfc) {
  assert(sfc != nullptr);
  if (sfc->hadBackslash() || sfc->getClass() || sfc->hasStaticClass()) {
    return newQueryParamRef(sfc);
  }
  auto args = sfc->getParams();
  auto pc = args == nullptr ? 0 : args->getCount();
  bool isQueryCall = false;
  for (int i = 0; i < pc; i++) {
    auto arg = (*args)[i];
    assert(arg != nullptr);
    isQueryCall |= this->dependsOnQueryOnlyState(arg);
  }
  if (!isQueryCall) return newQueryParamRef(sfc);
  auto newArgs =
    std::make_shared<ExpressionList>(args->getScope(), args->getRange());
  bool noRewrites = true;
  for (int i = 0; i < pc; i++) {
    auto arg = (*args)[i];
    auto newArg = rewrite(arg);
    if (arg != newArg) noRewrites = false;
    newArgs->addElement(newArg);
  }
  if (noRewrites) return sfc;
  return std::make_shared<SimpleFunctionCall>(
    sfc->getScope(), sfc->getRange(),
    sfc->getOriginalName(), false, newArgs, ExpressionPtr());
}
Ejemplo n.º 6
0
ExpressionPtr AssignmentExpression::makeIdCall(AnalysisResultPtr ar) {
  ExpressionListPtr arg =
    ExpressionListPtr(new ExpressionList(getLocation(),
                                         Expression::KindOfExpressionList));
  arg->insertElement(m_value);
  SimpleFunctionCallPtr result =
    SimpleFunctionCallPtr(
      new SimpleFunctionCall(getLocation(),
                             Expression::KindOfSimpleFunctionCall,
                             "id", arg, NULL));
  result->setFunctionAndClassScope(ar->findHelperFunction("id"),
                                   ClassScopePtr());
  result->setValid();
  result->setNoPrefix();
  result->setActualType(m_value->getActualType());
  result->setExpectedType(m_expectedType);
  return result;
}