当前位置: 首页>>代码示例>>C++>>正文


C++ ExpressionPtr::isScalar方法代码示例

本文整理汇总了C++中ExpressionPtr::isScalar方法的典型用法代码示例。如果您正苦于以下问题:C++ ExpressionPtr::isScalar方法的具体用法?C++ ExpressionPtr::isScalar怎么用?C++ ExpressionPtr::isScalar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExpressionPtr的用法示例。


在下文中一共展示了ExpressionPtr::isScalar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: wrapValue

static void wrapValue(CodeGenerator &cg, AnalysisResultPtr ar,
                      ExpressionPtr exp, bool ref, bool array, bool varnr) {
  bool close = false;
  if (ref) {
    cg_printf("ref(");
    close = true;
  } else if (array && !exp->hasCPPTemp() &&
             !exp->isTemporary() && !exp->isScalar() &&
             exp->getActualType() && !exp->getActualType()->isPrimitive() &&
             exp->getActualType()->getKindOf() != Type::KindOfString) {
    cg_printf("wrap_variant(");
    close = true;
  } else if (varnr && exp->getCPPType()->isExactType()) {
    bool isScalar = exp->isScalar();
    if (!isScalar || !Option::UseScalarVariant) {
      cg_printf("VarNR(");
      close = true;
    } else if (isScalar) {
      ASSERT(!cg.hasScalarVariant());
      cg.setScalarVariant();
    }
  }
  exp->outputCPP(cg, ar);
  cg.clearScalarVariant();
  if (close) cg_printf(")");
}
开发者ID:HyeongKyu,项目名称:hiphop-php,代码行数:26,代码来源:assignment_expression.cpp

示例2: preOptimize

ExpressionPtr ClassConstantExpression::preOptimize(AnalysisResultConstPtr ar) {
  if (ar->getPhase() < AnalysisResult::FirstPreOptimize) {
    return ExpressionPtr();
  }
  if (m_class) {
    updateClassName();
    if (m_class) {
      return ExpressionPtr();
    }
  }

  ClassScopePtr cls = resolveClass();
  if (!cls || (cls->isVolatile() && !isPresent())) {
    if (cls && !m_depsSet) {
      cls->addUse(getScope(), BlockScope::UseKindConstRef);
      m_depsSet = true;
    }
    return ExpressionPtr();
  }

  ConstantTablePtr constants = cls->getConstants();
  ClassScopePtr defClass = cls;
  ConstructPtr decl = constants->getValueRecur(ar, m_varName, defClass);
  if (decl) {
    BlockScope::s_constMutex.lock();
    ExpressionPtr value = dynamic_pointer_cast<Expression>(decl);
    BlockScope::s_constMutex.unlock();

    if (!value->isScalar() &&
        (value->is(KindOfClassConstantExpression) ||
         value->is(KindOfConstantExpression))) {
      std::set<ExpressionPtr> seen;
      do {
        if (!seen.insert(value).second) return ExpressionPtr();
        value = value->preOptimize(ar);
        if (!value) return ExpressionPtr();
      } while (!value->isScalar() &&
               (value->is(KindOfClassConstantExpression) ||
                value->is(KindOfConstantExpression)));
    }

    ExpressionPtr rep = Clone(value, getScope());
    rep->setComment(getText());
    copyLocationTo(rep);
    return replaceValue(rep);
  }
  return ExpressionPtr();
}
开发者ID:jaggedsoft,项目名称:hhvm,代码行数:48,代码来源:class_constant_expression.cpp

示例3: preOutputCPP

bool AssignmentExpression::preOutputCPP(CodeGenerator &cg, AnalysisResultPtr ar,
                                        int state) {
  if (m_variable->is(Expression::KindOfArrayElementExpression)) {
    ExpressionPtr exp = m_value;
    ExpressionPtr vv(
      static_pointer_cast<ArrayElementExpression>(m_variable)->getVariable());
    if ((vv->is(KindOfArrayElementExpression) ||
         vv->is(KindOfObjectPropertyExpression)) &&
        (vv->getContainedEffects() && (CreateEffect|AccessorEffect))) {
      /*
        We are in a case such as
          $a->b['c'] = ...;
          $a['b']['c'] = ...;
        Where evaluating m_variable may modify $a. Unless we can prove that
        the rhs is not referring to the same thing as $a, we must generate
        a temporary for it (note that we could do better with the following
        checks).
      */
      if (!(m_ref && exp->isRefable()) &&
          !exp->isTemporary() && !exp->isScalar() &&
          exp->getActualType() && !exp->getActualType()->isPrimitive() &&
          exp->getActualType()->getKindOf() != Type::KindOfString) {
        state |= Expression::StashAll;
      }
    }
  }

  return Expression::preOutputCPP(cg, ar, state);
}
开发者ID:jhockly,项目名称:RED-COLOR-IS-MY-FAVORITE-COLOR,代码行数:29,代码来源:assignment_expression.cpp

示例4: analyzeProgram

void SwitchStatement::analyzeProgram(AnalysisResultPtr ar) {
    m_exp->analyzeProgram(ar);
    if (m_cases) m_cases->analyzeProgram(ar);

    if (ar->getPhase() == AnalysisResult::AnalyzeAll &&
            m_exp->is(Expression::KindOfSimpleVariable)) {
        auto exp = dynamic_pointer_cast<SimpleVariable>(m_exp);
        if (exp && exp->getSymbol() && exp->getSymbol()->isClassName()) {
            // Mark some classes as volatile since the name is used in switch
            for (int i = 0; i < m_cases->getCount(); i++) {
                auto stmt = dynamic_pointer_cast<CaseStatement>((*m_cases)[i]);
                assert(stmt);
                ExpressionPtr caseCond = stmt->getCondition();
                if (caseCond && caseCond->isScalar()) {
                    auto name = dynamic_pointer_cast<ScalarExpression>(caseCond);
                    if (name && name->isLiteralString()) {
                        string className = name->getLiteralString();
                        ClassScopePtr cls = ar->findClass(toLower(className));
                        if (cls && cls->isUserClass()) {
                            cls->setVolatile();
                        }
                    }
                }
            }
            // Also note this down as code error
            ConstructPtr self = shared_from_this();
            Compiler::Error(Compiler::ConditionalClassLoading, self);
        }
    }
}
开发者ID:Cosmoskittle,项目名称:hhvm,代码行数:30,代码来源:switch_statement.cpp

示例5: optimizeArgArray

void FunctionCall::optimizeArgArray(AnalysisResultPtr ar) {
  if (m_extraArg <= 0) return;
  int paramCount = m_params->getOutputCount();
  int iMax = paramCount - m_extraArg;
  bool isScalar = true;
  for (int i = iMax; i < paramCount; i++) {
    ExpressionPtr param = (*m_params)[i];
    if (!param->isScalar()) {
      isScalar = false;
      break;
    }
  }
  if (isScalar) {
    ExpressionPtr argArrayPairs =
      ExpressionListPtr(new ExpressionList(getLocation(),
                                           Expression::KindOfExpressionList));
    for (int i = iMax; i < paramCount; i++) {
      ExpressionPtr param = (*m_params)[i];
      argArrayPairs->addElement(ArrayPairExpressionPtr(
        new ArrayPairExpression(param->getLocation(),
                                Expression::KindOfArrayPairExpression,
                                ExpressionPtr(), param, false)));
    }
    m_argArrayId = ar->registerScalarArray(argArrayPairs);
  }
}
开发者ID:sumitk,项目名称:hiphop-php,代码行数:26,代码来源:function_call.cpp

示例6: preOptimize

ExpressionPtr AssignmentExpression::preOptimize(AnalysisResultConstPtr ar) {
    if (m_variable->getContainedEffects() & ~(CreateEffect|AccessorEffect)) {
        return ExpressionPtr();
    }
    ExpressionPtr val = m_value;
    while (val) {
        if (val->is(KindOfExpressionList)) {
            val = static_pointer_cast<ExpressionList>(val)->listValue();
            continue;
        }
        if (val->is(KindOfAssignmentExpression)) {
            val = static_pointer_cast<AssignmentExpression>(val)->m_value;
            continue;
        }
        break;
    }
    if (val && val->isScalar()) {
        if (val != m_value) {
            ExpressionListPtr rep(new ExpressionList(
                                      getScope(), getRange(),
                                      ExpressionList::ListKindWrapped));
            rep->addElement(m_value);
            m_value = val->clone();
            rep->addElement(static_pointer_cast<Expression>(shared_from_this()));
            return replaceValue(rep);
        }
    }
    return ExpressionPtr();
}
开发者ID:neuroidss,项目名称:hhvm,代码行数:29,代码来源:assignment_expression.cpp

示例7: ExpressionPtr

TypePtr AssignmentExpression::
inferTypesImpl(AnalysisResultPtr ar, TypePtr type, bool coerce,
               ExpressionPtr variable,
               ExpressionPtr value /* = ExpressionPtr() */) {
  TypePtr ret = type;
  if (value) {
    if (coerce) {
      ret = value->inferAndCheck(ar, type, coerce);
    } else {
      ret = value->inferAndCheck(ar, NEW_TYPE(Some), coerce);
    }
  }

  BlockScopePtr scope = ar->getScope();
  if (variable->is(Expression::KindOfConstantExpression)) {
    // ...as in ClassConstant statement
    ConstantExpressionPtr exp =
      dynamic_pointer_cast<ConstantExpression>(variable);
    bool p;
    scope->getConstants()->check(exp->getName(), ret, true, ar, variable, p);
  } else if (variable->is(Expression::KindOfDynamicVariable)) {
    // simptodo: not too sure about this
    ar->getFileScope()->setAttribute(FileScope::ContainsLDynamicVariable);
  } else if (variable->is(Expression::KindOfSimpleVariable)) {
    SimpleVariablePtr var = dynamic_pointer_cast<SimpleVariable>(variable);
    if (var->getName() == "this" && ar->getClassScope()) {
      if (ar->isFirstPass()) {
        ar->getCodeError()->record(variable, CodeError::ReassignThis,
                                   variable);
      }
    }
    if (ar->getPhase() == AnalysisResult::LastInference && value) {
      if (!value->getExpectedType()) {
        value->setExpectedType(variable->getActualType());
      }
    }
  }
  // if the value may involve object, consider the variable as "referenced"
  // so that objects are not destructed prematurely.
  bool referenced = true;
  if (value && value->isScalar()) referenced = false;
  if (ret && ret->isNoObjectInvolved()) referenced = false;
  if (referenced && variable->is(Expression::KindOfSimpleVariable)) {
    SimpleVariablePtr var =
      dynamic_pointer_cast<SimpleVariable>(variable);
    const std::string &name = var->getName();
    VariableTablePtr variables = ar->getScope()->getVariables();
    variables->addReferenced(name);
  }

  TypePtr vt = variable->inferAndCheck(ar, ret, true);
  if (!coerce && type->is(Type::KindOfAny)) {
    ret = vt;
  }

  return ret;
}
开发者ID:Neomeng,项目名称:hiphop-php,代码行数:57,代码来源:assignment_expression.cpp

示例8: CheckNeededRHS

bool Expression::CheckNeededRHS(ExpressionPtr value) {
  bool needed = true;
  always_assert(value);
  while (value->is(KindOfAssignmentExpression)) {
    value = dynamic_pointer_cast<AssignmentExpression>(value)->getValue();
  }
  if (value->isScalar()) {
    needed = false;
  }
  return needed;
}
开发者ID:HilayPatel,项目名称:hhvm,代码行数:11,代码来源:expression.cpp

示例9: preOutputCPP

bool AssignmentExpression::preOutputCPP(CodeGenerator &cg, AnalysisResultPtr ar,
                                        int state) {
  if (m_variable->is(Expression::KindOfArrayElementExpression)) {
    ExpressionPtr exp = m_value;
    if (!(m_ref && exp->isRefable()) &&
        !exp->isTemporary() && !exp->isScalar() &&
        exp->getActualType() && !exp->getActualType()->isPrimitive() &&
        exp->getActualType()->getKindOf() != Type::KindOfString) {
      state |= Expression::StashAll;
    }
  }
  return Expression::preOutputCPP(cg, ar, state);
}
开发者ID:brianmn,项目名称:hiphop-php_packaged,代码行数:13,代码来源:assignment_expression.cpp

示例10: preOptimize

ExpressionPtr ConstantExpression::preOptimize(AnalysisResultConstPtr ar) {
    if (ar->getPhase() < AnalysisResult::FirstPreOptimize) {
        return ExpressionPtr();
    }
    ConstructPtr decl;
    while (!isScalar() && !m_dynamic && !(m_context & LValue)) {
        const Symbol *sym = resolveNS(ar);
        if (sym &&
                (!const_cast<Symbol*>(sym)->checkDefined() || sym->isDynamic())) {
            sym = 0;
            m_dynamic = true;
        }
        if (!sym) break;
        if (!sym->isSystem()) BlockScope::s_constMutex.lock();
        ExpressionPtr value = dynamic_pointer_cast<Expression>(sym->getValue());
        if (!sym->isSystem()) BlockScope::s_constMutex.unlock();

        if (!value || !value->isScalar()) {
            if (!m_depsSet && sym->getDeclaration()) {
                sym->getDeclaration()->getScope()->addUse(
                    getScope(), BlockScope::UseKindConstRef);
                m_depsSet = true;
            }
            break;
        }

        Variant scalarValue;
        if (value->getScalarValue(scalarValue) &&
                !scalarValue.isAllowedAsConstantValue()) {
            // block further optimization
            const_cast<Symbol*>(sym)->setDynamic();
            m_dynamic = true;
            break;
        }

        if (sym->isSystem() && !value->is(KindOfScalarExpression)) {
            if (ExpressionPtr opt = value->preOptimize(ar)) {
                value = opt;
            }
        }
        ExpressionPtr rep = Clone(value, getScope());
        rep->setComment(getText());
        copyLocationTo(rep);
        return replaceValue(rep);
    }

    return ExpressionPtr();
}
开发者ID:nurulimamnotes,项目名称:hhvm,代码行数:48,代码来源:constant_expression.cpp

示例11: getEffectiveImpl

ExpressionPtr StatementList::getEffectiveImpl(AnalysisResultConstPtr ar) const {
  for (unsigned int i = 0; i < m_stmts.size(); i++) {
    StatementPtr s = m_stmts[i];
    if (s->is(KindOfReturnStatement)) {
      ExpressionPtr e = static_pointer_cast<ReturnStatement>(s)->getRetExp();
      if (!e) {
        e = CONSTANT("null");
      } else if (!e->isScalar()) {
        break;
      }
      return e;
    }
    if (m_stmts[i]->hasImpl()) break;
  }
  return ExpressionPtr();
}
开发者ID:eliotsolomon,项目名称:hiphop-php,代码行数:16,代码来源:statement_list.cpp

示例12: wrapValue

static void wrapValue(CodeGenerator &cg, AnalysisResultPtr ar,
                      ExpressionPtr exp, bool ref, bool array) {
  bool close = false;
  if (ref) {
    cg_printf("ref(");
    close = true;
  } else if (array && !exp->hasCPPTemp() &&
             !exp->isTemporary() && !exp->isScalar() &&
             exp->getActualType() && !exp->getActualType()->isPrimitive() &&
             exp->getActualType()->getKindOf() != Type::KindOfString) {
    cg_printf("wrap_variant(");
    close = true;
  }
  exp->outputCPP(cg, ar);
  if (close) cg_printf(")");
}
开发者ID:jhockly,项目名称:RED-COLOR-IS-MY-FAVORITE-COLOR,代码行数:16,代码来源:assignment_expression.cpp

示例13: isDefineWithoutImpl

bool SimpleFunctionCall::isDefineWithoutImpl(AnalysisResultPtr ar) {
  if (!m_className.empty()) return false;
  if (m_type == DefineFunction && m_params && m_params->getCount() >= 2) {
    if (m_dynamicConstant) return false;
    ScalarExpressionPtr name =
      dynamic_pointer_cast<ScalarExpression>((*m_params)[0]);
    if (!name) return false;
    string varName = name->getIdentifier();
    if (varName.empty()) return false;
    if (ar->getConstants()->isSystem(varName)) return true;
    ExpressionPtr value = (*m_params)[1];
    return (!ar->isConstantRedeclared(varName)) && value->isScalar();
  } else {
    return false;
  }
}
开发者ID:scottmac,项目名称:hiphop-dev,代码行数:16,代码来源:simple_function_call.cpp

示例14: outputCPPUniqLitKeyArrayInit

void ExpressionList::outputCPPUniqLitKeyArrayInit(
  CodeGenerator &cg, AnalysisResultPtr ar, bool litstrKeys, int64 num,
  bool arrayElements /* = true */, unsigned int start /* = 0 */) {
  if (arrayElements) ASSERT(m_arrayElements);
  unsigned int n =  m_exps.size();
  cg_printf("array_createv%c(%lld, ", litstrKeys ? 's' : 'i', num);
  assert(n - start == num);
  for (unsigned int i = start; i < n; i++) {
    ExpressionPtr exp = m_exps[i];
    assert(exp);
    ExpressionPtr name;
    ExpressionPtr value = exp;
    if (arrayElements) {
      ArrayPairExpressionPtr ap =
        dynamic_pointer_cast<ArrayPairExpression>(m_exps[i]);
      name = ap->getName();
      value = ap->getValue();
    }
    if (name) {
      assert(litstrKeys);
      cg_printf("toSPOD(");
      name->outputCPP(cg, ar);
      cg_printf("), ");
    }
    cg_printf("toVPOD(");
    if (value->isScalar()) {
      assert(!cg.hasScalarVariant());
      cg.setScalarVariant();
      if (!Option::UseScalarVariant) cg_printf("VarNR(");
      value->outputCPP(cg, ar);
      if (!Option::UseScalarVariant) cg_printf(")");
      cg.clearScalarVariant();
    } else {
      bool wrap = Expression::CheckVarNR(value, Type::Variant);
      if (wrap) cg_printf("VarNR(");
      value->outputCPP(cg, ar);
      if (wrap) cg_printf(")");
    }
    cg_printf(")");
    if (i < n-1) {
      cg_printf(", ");
    } else {
      cg_printf(")");
    }
  }
}
开发者ID:DenisBazhan,项目名称:hiphop-php,代码行数:46,代码来源:expression_list.cpp

示例15: CheckNeededRHS

bool Expression::CheckNeededRHS(ExpressionPtr value) {
  bool needed = true;
  always_assert(value);
  while (value->is(KindOfAssignmentExpression)) {
    value = dynamic_pointer_cast<AssignmentExpression>(value)->getValue();
  }
  if (value->isScalar()) {
    needed = false;
  } else {
    TypePtr type = value->getType();
    if (type && (type->is(Type::KindOfSome) || type->is(Type::KindOfAny))) {
      type = value->getActualType();
    }
    if (type && type->isNoObjectInvolved()) needed = false;
  }
  return needed;
}
开发者ID:andyanx,项目名称:hhvm,代码行数:17,代码来源:expression.cpp


注:本文中的ExpressionPtr::isScalar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。