Beispiel #1
0
void staticStreamer(const TypedValue* tv, std::string& out) {
  switch (tv->m_type) {
    case KindOfUninit:
    case KindOfNull:
      out += "null";
      return;
    case KindOfBoolean:
      out += (tv->m_data.num ? "true" : "false");
      return;
    case KindOfInt64:
      out += folly::to<std::string>(tv->m_data.num);
      return;
    case KindOfDouble:
      out += folly::to<std::string>(tv->m_data.dbl);
      return;
    case KindOfPersistentString:
    case KindOfString:
      folly::format(&out, "\"{}\"",
                    escapeStringForCPP(tv->m_data.pstr->data(),
                                       tv->m_data.pstr->size()));
      return;
    case KindOfPersistentVec:
    case KindOfVec:
    case KindOfPersistentDict:
    case KindOfDict:
    case KindOfPersistentKeyset:
    case KindOfKeyset:
    case KindOfPersistentArray:
    case KindOfArray:
      staticArrayStreamer(tv->m_data.parr, out);
      return;
    case KindOfObject:
    case KindOfResource:
    case KindOfRef:
    case KindOfFunc:
    case KindOfClass:
      break;
  }
  not_reached();
}
Beispiel #2
0
std::string show(MemberKey mk) {
  std::string ret = memberCodeString(mk.mcode);

  switch (mk.mcode) {
    case MEL: case MEC: case MPL: case MPC:
      folly::toAppend(':', mk.iva, &ret);
      break;
    case MEI:
      folly::toAppend(':', mk.int64, &ret);
      break;
    case MET: case MPT: case MQT:
      folly::toAppend(
        ":\"", escapeStringForCPP(mk.litstr->data(), mk.litstr->size()), '"',
        &ret
      );
      break;
    case MW:
      break;
  }

  return ret;
}
Beispiel #3
0
void staticArrayStreamer(ArrayData* ad, std::ostream& out) {
  out << "array(";
  if (!ad->empty()) {
    bool comma = false;
    for (ArrayIter it(ad); !it.end(); it.next()) {
      if (comma) {
        out << ",";
      } else {
        comma = true;
      }
      Variant key = it.first();

      // Key.
      if (IS_INT_TYPE(key.getType())) {
        out << *key.getInt64Data();
      } else if (IS_STRING_TYPE(key.getType())) {
        out << "\""
            << escapeStringForCPP(key.getStringData()->data(),
                                  key.getStringData()->size())
            << "\"";
      } else {
        assert(false);
      }

      out << "=>";

      Variant val = it.second();

      // Value.
      [&] {
        switch (val.getType()) {
          case KindOfUninit:
          case KindOfNull:
            out << "null";
            return;
          case KindOfBoolean:
            out << (val.toBoolean() ? "true" : "false");
            return;
          case KindOfInt64:
            out << *val.getInt64Data();
            return;
          case KindOfDouble:
            out << *val.getDoubleData();
            return;
          case KindOfStaticString:
          case KindOfString:
            out << "\""
                << escapeStringForCPP(val.getStringData()->data(),
                                      val.getStringData()->size())
                << "\"";
            return;
          case KindOfArray:
            staticArrayStreamer(val.getArrayData(), out);
            return;
          case KindOfObject:
          case KindOfResource:
          case KindOfRef:
          case KindOfClass:
            not_reached();
        }
      }();
    }
  }
  out << ")";
}
Beispiel #4
0
/**
 * print_string will decRef the string
 */
void print_string(StringData* s) {
  g_context->write(s->data(), s->size());
  TRACE(1, "t-x64 output(str): (%p) %43s\n", s->data(),
        escapeStringForCPP(s->data(), s->size()).data());
  decRefStr(s);
}
Beispiel #5
0
void staticArrayStreamer(ArrayData* ad, std::ostream& out) {
  out << "array(";
  if (!ad->empty()) {
    bool comma = false;
    for (ArrayIter it(ad); !it.end(); it.next()) {
      if (comma) {
        out << ",";
      } else {
        comma = true;
      }
      Variant key = it.first();
      // Key.
      switch (key.getType()) {
      case KindOfInt64: {
        out << *key.getInt64Data();
        break;
      }
      case KindOfStaticString:
      case KindOfString: {
        out << "\""
            << escapeStringForCPP(key.getStringData()->data(),
                                  key.getStringData()->size())
            << "\"";
        break;
      }
      default: assert(false);
      }
      out << "=>";
      // Value.
      Variant val = it.second();
      switch (val.getType()) {
      case KindOfUninit:
      case KindOfNull: {
        out << "null";
        break;
      }
      case KindOfBoolean: {
        out << (val.toBoolean() ? "true" : "false");
        break;
      }
      case KindOfStaticString:
      case KindOfString: {
        out << "\""
            << escapeStringForCPP(val.getStringData()->data(),
                                  val.getStringData()->size())
            << "\"";
        break;
      }
      case KindOfInt64: {
        out << *val.getInt64Data();
        break;
      }
      case KindOfDouble: {
        out << *val.getDoubleData();
        break;
      }
      case KindOfArray: {
        staticArrayStreamer(val.getArrayData(), out);
        break;
      }
      default: assert(false);
      }
    }
  }
  out << ")";
}
Beispiel #6
0
void staticArrayStreamer(const ArrayData* ad, std::ostream& out) {
  if (ad->isVecArray()) out << "vec(";
  else if (ad->isDict()) out << "dict(";
  else if (ad->isKeyset()) out << "keyset(";
  else {
    assert(ad->isPHPArray());
    out << "array(";
  }

  if (!ad->empty()) {
    bool comma = false;
    for (ArrayIter it(ad); !it.end(); it.next()) {
      if (comma) {
        out << ",";
      } else {
        comma = true;
      }
      Variant key = it.first();

      if (!ad->isVecArray() && !ad->isKeyset()) {
        // Key.
        if (isIntType(key.getType())) {
          out << *key.getInt64Data();
        } else if (isStringType(key.getType())) {
          out << "\""
              << escapeStringForCPP(key.getStringData()->data(),
                                    key.getStringData()->size())
              << "\"";
        } else {
          assert(false);
        }

        out << "=>";
      }

      Variant val = it.second();

      // Value.
      [&] {
        switch (val.getType()) {
          case KindOfUninit:
          case KindOfNull:
            out << "null";
            return;
          case KindOfBoolean:
            out << (val.toBoolean() ? "true" : "false");
            return;
          case KindOfInt64:
            out << *val.getInt64Data();
            return;
          case KindOfDouble:
            out << *val.getDoubleData();
            return;
          case KindOfPersistentString:
          case KindOfString:
            out << "\""
                << escapeStringForCPP(val.getStringData()->data(),
                                      val.getStringData()->size())
                << "\"";
            return;
          case KindOfPersistentVec:
          case KindOfVec:
          case KindOfPersistentDict:
          case KindOfDict:
          case KindOfPersistentKeyset:
          case KindOfKeyset:
          case KindOfPersistentArray:
          case KindOfArray:
            staticArrayStreamer(val.getArrayData(), out);
            return;
          case KindOfObject:
          case KindOfResource:
          case KindOfRef:
          case KindOfClass:
            not_reached();
        }
      }();
    }
  }
  out << ")";
}