Exemplo n.º 1
0
PhpClass::PhpClass(const folly::dynamic &c) :
  m_class(c),
  m_idlName(c["name"].asString()),
  m_phpName(toPhpName(m_idlName)),
  m_cppName(toCppName(m_idlName)),
  m_flags(parseFlags(m_class["flags"])),
  m_desc(getFollyDynamicDefaultString(c, "desc", "")) {

  auto ifacesIt = m_class.find("ifaces");
  if (ifacesIt != m_class.items().end()) {
    auto ifaces = ifacesIt->second;
    if (!ifaces.isArray()) {
      throw std::logic_error(
        folly::format("Class {0}.ifaces field must be an array",
          m_idlName).str()
      );
    }
    for (auto &interface : ifaces) {
      m_ifaces.push_back(interface.asString());
    }
  }

  for (auto const& f : c["funcs"]) {
    PhpFunc func(f, getCppName());
    m_methods.push_back(func);
  }

  if (c.find("consts") != c.items().end()) {
    for (auto const& cns : c["consts"]) {
      PhpConst cons(cns, getCppName());
      m_constants.push_back(cons);
    }
  }

  if (c.find("properties") != c.items().end()) {
    for (auto const& prp : c["properties"]) {
      PhpProp prop(prp, getCppName());
      m_properties.push_back(prop);
    }
  }
}
Exemplo n.º 2
0
fbstring PhpFunc::getCppSig() const {
  std::ostringstream out;

  fbstring nm = getCppName();
  fbstring lowername = nm;
  std::transform(nm.begin(), nm.end(), lowername.begin(),
                 std::ptr_fun<int, int>(std::tolower));

  if (!isMethod()) {
    out << "HPHP::f_" << lowername << "(";
  } else {
    if (isStatic()) {
      out << "HPHP::c_" << className() << "::ti_" << lowername << "(";
    } else {
      out << "HPHP::c_" << className() << "::t_" << lowername << "(";
    }
  }

  bool firstParam = true;
  if (isVarArgs()) {
    if (!firstParam) {
      out << ", ";
    }
    out << "int";
    firstParam = false;
  }

  for (auto const& param : m_params) {
    if (!firstParam) {
      out << ", ";
    }
    out << param.getCppType();
    firstParam = false;
  }

  if (isVarArgs()) {
    assert(!firstParam);
    out << ", HPHP::Array const&";
  }

  out << ")";
  return out.str();
}
Exemplo n.º 3
0
fbstring
PhpFunc::getPrefixedCppName(bool fullyQualified /* = true */) const {
  std::ostringstream out;

  fbstring nm = getCppName();
  fbstring lowername = nm;
  std::transform(nm.begin(), nm.end(), lowername.begin(),
                 std::ptr_fun<int, int>(std::tolower));

  if (fullyQualified) {
    out << "HPHP::";
  }
  if (!isMethod()) {
    out << "f_" << lowername;
  } else {
    if (isStatic()) {
      out << "c_" << className() << "::ti_" << lowername;
    } else {
      out << "c_" << className() << "::t_" << lowername;
    }
  }

  return out.str();
}