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


C++ ArrayPairExpressionPtr类代码示例

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


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

示例1: init

bool ExpressionList::getScalarValue(Variant &value) {
  if (m_arrayElements) {
    if (isScalarArrayPairs()) {
      ArrayInit init(m_exps.size());
      for (unsigned int i = 0; i < m_exps.size(); i++) {
        ArrayPairExpressionPtr exp =
          dynamic_pointer_cast<ArrayPairExpression>(m_exps[i]);
        ExpressionPtr name = exp->getName();
        ExpressionPtr val = exp->getValue();
        if (!name) {
          Variant v;
          bool ret = val->getScalarValue(v);
          if (!ret) ASSERT(false);
          init.set(v);
        } else {
          Variant n;
          Variant v;
          bool ret1 = name->getScalarValue(n);
          bool ret2 = val->getScalarValue(v);
          if (!(ret1 && ret2)) return ExpressionPtr();
          init.set(n, v);
        }
      }
      value = Array(init.create());
      return true;
    }
    return false;
  }
  if (m_kind != ListKindParam && !hasEffect()) {
    ExpressionPtr v(listValue());
    return v ? v->getScalarValue(value) : false;
  }
  return false;
}
开发者ID:DenisBazhan,项目名称:hiphop-php,代码行数:34,代码来源:expression_list.cpp

示例2: cg_printf

void ExpressionList::outputCPPUniqLitKeyArrayInit(
  CodeGenerator &cg, AnalysisResultPtr ar, int64 max,
  bool arrayElements /* = true */, unsigned int start /* = 0 */) {
  if (arrayElements) ASSERT(m_arrayElements);
  unsigned int n =  m_exps.size();
  cg_printf("array_create%d(%lu, ", n - start, max);
  for (unsigned int i = start; i < n; i++) {
    if (ExpressionPtr exp = m_exps[i]) {
      ExpressionPtr name;
      ExpressionPtr value = exp;
      if (arrayElements) {
        ArrayPairExpressionPtr ap =
          dynamic_pointer_cast<ArrayPairExpression>(m_exps[i]);
        name = ap->getName();
        value = ap->getValue();
      }
      if (name) {
        name->outputCPP(cg, ar);
      } else {
        cg_printf("%d", i - start);
      }
      cg_printf(", ");
      value->outputCPP(cg, ar);
      if (i < n-1) {
        cg_printf(", ");
      } else {
        cg_printf(")");
      }
    }
  }
}
开发者ID:eliotsolomon,项目名称:hiphop-php,代码行数:31,代码来源:expression_list.cpp

示例3: if

bool
ExpressionList::flattenLiteralStrings(vector<ExpressionPtr> &literals) const {
  for (unsigned i = 0; i < m_exps.size(); i++) {
    ExpressionPtr e = m_exps[i];
    if (e->is(Expression::KindOfArrayPairExpression)) {
      ArrayPairExpressionPtr ap = dynamic_pointer_cast<ArrayPairExpression>(e);
      if (ap->getName()) return false;
      e = ap->getValue();
    }
    if (e->is(Expression::KindOfUnaryOpExpression)) {
      UnaryOpExpressionPtr unary = dynamic_pointer_cast<UnaryOpExpression>(e);
      if (unary->getOp() == T_ARRAY) {
        ExpressionListPtr el =
          dynamic_pointer_cast<ExpressionList>(unary->getExpression());
        if (!el->flattenLiteralStrings(literals)) {
          return false;
        }
      }
    }
    else if (e->isLiteralString()) {
      literals.push_back(e);
    } else {
      return false;
    }
  }
  return true;
}
开发者ID:DenisBazhan,项目名称:hiphop-php,代码行数:27,代码来源:expression_list.cpp

示例4: init

bool ExpressionList::getScalarValue(Variant &value) {
  if (m_elems_kind != ElemsKind::None) {
    if (isScalarArrayPairs()) {
      ArrayInit init(m_exps.size(), ArrayInit::Mixed{});
      for (unsigned int i = 0; i < m_exps.size(); i++) {
        ArrayPairExpressionPtr exp =
          dynamic_pointer_cast<ArrayPairExpression>(m_exps[i]);
        ExpressionPtr name = exp->getName();
        ExpressionPtr val = exp->getValue();
        if (!name) {
          Variant v;
          bool ret = val->getScalarValue(v);
          if (!ret) assert(false);
          init.append(v);
        } else {
          Variant n;
          Variant v;
          bool ret1 = name->getScalarValue(n);
          bool ret2 = val->getScalarValue(v);
          if (!(ret1 && ret2)) return false;
          init.setKeyUnconverted(n, v);
        }
      }
      value = Array(init.create());
      return true;
    }
    return false;
  }
  if (m_kind != ListKindParam && !hasEffect()) {
    ExpressionPtr v(listValue());
    return v ? v->getScalarValue(value) : false;
  }
  return false;
}
开发者ID:AmritanshuRanjan,项目名称:hhvm,代码行数:34,代码来源:expression_list.cpp

示例5: ASSERT

unsigned int ExpressionList::checkIntegerKeys(int64 &max) const {
  ASSERT(m_arrayElements);
  max = 0;
  set<int64> keys;
  for (unsigned int i = 0; i < m_exps.size(); i++) {
    ArrayPairExpressionPtr ap =
      dynamic_pointer_cast<ArrayPairExpression>(m_exps[i]);
    ExpressionPtr name = ap->getName();
    if (!name) return 0;
    Variant value;
    bool ret = name->getScalarValue(value);
    if (!ret) return 0;
    if (!value.isInteger()) return 0;
    int64 v = value.toInt64();
    if (i == 0) {
      max = v;
    } else if (max < v) {
      max = v;
    }
    keys.insert(v);
  }
  if (max >= 0) {
    max++;
  } else {
    max = 0;
  }
  return keys.size();
}
开发者ID:eliotsolomon,项目名称:hiphop-php,代码行数:28,代码来源:expression_list.cpp

示例6: init

bool ExpressionList::getScalarValue(Variant &value) {
  if (!isScalarArrayPairs()) return false;
  ArrayInit init(m_exps.size());
  for (unsigned int i = 0; i < m_exps.size(); i++) {
    ArrayPairExpressionPtr exp =
      dynamic_pointer_cast<ArrayPairExpression>(m_exps[i]);
    ExpressionPtr name = exp->getName();
    ExpressionPtr val = exp->getValue();
    if (!name) {
      Variant v;
      bool ret = val->getScalarValue(v);
      if (!ret) ASSERT(false);
      init.set(i, v);
    } else {
      Variant n;
      Variant v;
      bool ret1 = name->getScalarValue(n);
      bool ret2 = val->getScalarValue(v);
      if (!(ret1 && ret2)) ASSERT(false);
      init.set(i, n, v);
    }
  }
  value = Array(init.create());
  return true;
}
开发者ID:yigithub,项目名称:hiphop-php,代码行数:25,代码来源:expression_list.cpp

示例7: isScalarArrayPairs

bool ExpressionList::isScalarArrayPairs() const {
  for (unsigned int i = 0; i < m_exps.size(); i++) {
    ArrayPairExpressionPtr exp =
      dynamic_pointer_cast<ArrayPairExpression>(m_exps[i]);
    if (!exp || !exp->isScalarArrayPair()) {
      return false;
    }
  }
  return true;
}
开发者ID:yigithub,项目名称:hiphop-php,代码行数:10,代码来源:expression_list.cpp

示例8: hasNonArrayCreateValue

bool ExpressionList::hasNonArrayCreateValue(
  bool arrayElements /* = true */, unsigned int start /* = 0 */) const {
  for (unsigned int i = start; i < m_exps.size(); i++) {
    ExpressionPtr value = m_exps[i];
    if (arrayElements) {
      ArrayPairExpressionPtr ap =
        dynamic_pointer_cast<ArrayPairExpression>(m_exps[i]);
      value = ap->getValue();
    }
    ASSERT(value);
    if (value->hasContext(RefValue)) {
      return true;
    }
  }
  return false;
}
开发者ID:DenisBazhan,项目名称:hiphop-php,代码行数:16,代码来源:expression_list.cpp

示例9: cg_printf

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

示例10: Load

bool Option::Load(map<string, int> &option, ExpressionPtr value) {
  ExpressionListPtr elements;
  if (!GetArrayElements(value, elements)) return false;

  for (int i = 0; i < elements->getCount(); i++) {
    ExpressionPtr e = (*elements)[i];
    ArrayPairExpressionPtr pair = dynamic_pointer_cast<ArrayPairExpression>(e);

    bool negative = false;
    ScalarExpressionPtr n, v;
    if (pair) n = dynamic_pointer_cast<ScalarExpression>(pair->getName());
    if (pair) {
      if (pair->getValue()->is(Expression::KindOfUnaryOpExpression)) {
        UnaryOpExpressionPtr una =
          dynamic_pointer_cast<UnaryOpExpression>(pair->getValue());
        if (una->getOp() != '+' && una->getOp() != '-') {
          Logger::Error("Line %d: invalid integer: %s",
                        una->getLocation()->line1, una->getText().c_str());
          return false;
        }

        v = dynamic_pointer_cast<ScalarExpression>(una->getExpression());
        if (una->getOp() == '-') {
          negative = true;
        }
      } else {
        v = dynamic_pointer_cast<ScalarExpression>(pair->getValue());
      }
    }

    if (!pair || !n || !v || !n->isLiteralString() || !v->isLiteralInteger()) {
      Logger::Error("Line %d: invalid element: %s", e->getLocation()->line1,
                    e->getText().c_str());
      return false;
    }

    if (negative) {
      option[n->getLiteralString()] = - v->getLiteralInteger();
    } else {
      option[n->getLiteralString()] = v->getLiteralInteger();
    }
  }

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

示例11: ASSERT

unsigned int ExpressionList::checkLitstrKeys() const {
  ASSERT(m_arrayElements);
  std::set<string> keys;
  for (unsigned int i = 0; i < m_exps.size(); i++) {
    ArrayPairExpressionPtr ap =
      dynamic_pointer_cast<ArrayPairExpression>(m_exps[i]);
    ExpressionPtr name = ap->getName();
    if (!name) return 0;
    Variant value;
    bool ret = name->getScalarValue(value);
    if (!ret) return 0;
    if (!value.isString()) return 0;
    String str = value.toString();
    if (str->isInteger()) return 0;
    string s(str.data(), str.size());
    keys.insert(s);
  }
  return keys.size();
}
开发者ID:DenisBazhan,项目名称:hiphop-php,代码行数:19,代码来源:expression_list.cpp

示例12: cg_printf

bool ExpressionList::outputCPPInternal(CodeGenerator &cg,
                                       AnalysisResultPtr ar,
                                       bool needed, bool pre) {
  bool needsComma = false;
  bool anyOutput = false;
  if (m_arrayElements) {
    bool isVector = true;
    for (unsigned int i = 0; i < m_exps.size(); i++) {
      ArrayPairExpressionPtr ap =
        dynamic_pointer_cast<ArrayPairExpression>(m_exps[i]);
      if (ap->getName()) {
        isVector = false;
        break;
      }
    }
    if (outputCPPArrayCreate(cg, ar, isVector, pre)) return true;
    cg_printf("ArrayInit");
    if (pre) {
      cg_printf(" %s", m_cppTemp.c_str());
    }
    cg_printf("(%d, %s)", m_exps.size(), isVector ? "true" : "false");
    if (pre) cg_printf(";\n");
    needsComma = true;
    anyOutput = true;
  }

  bool trailingComma = false;
  unsigned i = 0, s = m_exps.size();
  unsigned ix = m_kind == ListKindLeft ? 0 : s - 1;
  for ( ; i < s; i++) {
    if (ExpressionPtr exp = m_exps[i]) {
      if (pre) {
        exp->preOutputCPP(cg, ar, 0);
        cg_printf("%s", m_cppTemp.c_str());
      }
      if (needsComma) {
        cg_printf(m_arrayElements ? "." : ", ");
        trailingComma = true;
      }
      if (m_arrayElements) {
        ArrayPairExpressionPtr ap =
          dynamic_pointer_cast<ArrayPairExpression>(exp);
        if (ap->isRef()) {
          cg_printf("setRef(");
          // The value itself shouldn't be wrapped with ref() any more.
          ap->getValue()->setContext(NoRefWrapper);
        } else {
          cg_printf("set(");
        }
        exp->outputCPP(cg, ar);
        cg_printf(")");
        if (pre) {
          cg_printf(";\n");
        }
        needsComma = true;
      } else if (m_kind != ListKindParam && (i != ix || !needed)) {
        needsComma = exp->outputCPPUnneeded(cg, ar);
      } else {
        exp->outputCPP(cg, ar);
        needsComma = true;
      }
      if (needsComma) {
        trailingComma = false;
        anyOutput = true;
      }
    }
  }
  if (trailingComma) {
    cg_printf("id(0)");
  }
  if (m_arrayElements && !pre) {
    cg_printf(".create()");
    anyOutput = true;
  }
  return anyOutput;
}
开发者ID:mayank245,项目名称:hiphop-php,代码行数:76,代码来源:expression_list.cpp


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