Ejemplo n.º 1
0
void TypeAnnotation::accessTypeName(std::string &name) const {
  name += m_name;
  TypeAnnotationPtr typeEl = m_typeArgs;
  while (typeEl) {
    folly::toAppend("::", typeEl->fullName(), &name);
    typeEl = typeEl->m_typeList;
  }
}
void TypeAnnotation::tupleTypeName(std::string &name) const {
  name += "(";
  TypeAnnotationPtr typeEl = m_typeArgs;
  while (typeEl) {
    name += typeEl->fullName();
    typeEl = typeEl->m_typeList;
    name += ", ";
  }
  // replace the trailing ", " with ")"
  name.replace(name.size() - 2, 2, ")");
}
Ejemplo n.º 3
0
void TypeAnnotation::genericTypeName(std::string &name) const {
  folly::toAppend(m_name, "<", &name);
  TypeAnnotationPtr typeEl = m_typeArgs;
  auto sep = "";
  while (typeEl) {
    folly::toAppend(sep, typeEl->fullName(), &name);
    typeEl = typeEl->m_typeList;
    sep = ", ";
  }
  name += ">";
}
Ejemplo n.º 4
0
void TypeAnnotation::tupleTypeName(std::string &name) const {
  name += "(";
  TypeAnnotationPtr typeEl = m_typeArgs;
  auto sep = "";
  while (typeEl) {
    folly::toAppend(sep, typeEl->fullName(), &name);
    typeEl = typeEl->m_typeList;
    sep = ", ";
  }
  name += ")";
}
Ejemplo n.º 5
0
void TypeAnnotation::functionTypeName(std::string &name) const {
  name += "(function (";
  // return value of function types is the first element of type list
  TypeAnnotationPtr retType = m_typeArgs;
  TypeAnnotationPtr typeEl = m_typeArgs->m_typeList;
  auto sep = "";
  while (typeEl) {
    folly::toAppend(sep, typeEl->fullName(), &name);
    typeEl = typeEl->m_typeList;
    sep = ", ";
  }
  // add function return value
  folly::toAppend("): ", retType->fullName(), ")", &name);
}
Ejemplo n.º 6
0
ParameterExpression::ParameterExpression(
     EXPRESSION_CONSTRUCTOR_PARAMETERS,
     TypeAnnotationPtr type,
     bool hhType,
     const std::string &name,
     bool ref,
     TokenID modifier,
     ExpressionPtr defaultValue,
     ExpressionPtr attributeList,
     bool variadic)
  : Expression(EXPRESSION_CONSTRUCTOR_PARAMETER_VALUES(ParameterExpression))
  , m_originalType(type)
  , m_name(name)
  , m_hhType(hhType)
  , m_ref(ref)
  , m_modifier(modifier)
  , m_defaultValue(defaultValue)
  , m_attributeList(attributeList)
  , m_variadic(variadic)
{
  m_type = toLower(type ? type->vanillaName() : "");
  if (m_defaultValue) {
    m_defaultValue->setContext(InParameterExpression);
  }
}
Ejemplo n.º 7
0
void TypeAnnotation::outputCodeModel(CodeGenerator& cg) {
    TypeAnnotationPtr typeArgsElem = m_typeArgs;
    auto numTypeArgs = 0;
    while (typeArgsElem != nullptr) {
        numTypeArgs++;
        typeArgsElem = typeArgsElem->m_typeList;
    }
    typeArgsElem = m_typeArgs;

    auto numProps = 1;
    if (m_nullable) numProps++;
    if (m_soft) numProps++;
    if (m_function) numProps++;
    if (numTypeArgs > 0) numProps++;
    cg.printObjectHeader("TypeExpression", numProps);
    cg.printPropertyHeader("name");
    cg.printValue(m_tuple ? "tuple" : m_name);
    if (m_nullable) {
        cg.printPropertyHeader("isNullable");
        cg.printBool(true);
    }
    if (m_soft) {
        cg.printPropertyHeader("isSoft");
        cg.printBool(true);
    }
    if (m_function) {
        cg.printPropertyHeader("returnType");
        typeArgsElem->outputCodeModel(cg);
        typeArgsElem = typeArgsElem->m_typeList;
        numTypeArgs--;
    }
    if (numTypeArgs > 0) {
        cg.printPropertyHeader("typeArguments");
        cg.printf("V:9:\"HH\\Vector\":%d:{", numTypeArgs);
        while (typeArgsElem != nullptr) {
            typeArgsElem->outputCodeModel(cg);
            typeArgsElem = typeArgsElem->m_typeList;
        }
        cg.printf("}");
    }
    cg.printObjectFooter();
}
void TypeAnnotation::functionTypeName(std::string &name) const {
  name += "(function (";
  // return value of function types is the first element of type list
  TypeAnnotationPtr retType = m_typeArgs;
  TypeAnnotationPtr typeEl = m_typeArgs->m_typeList;
  bool hasArgs = (typeEl != nullptr);
  while (typeEl) {
    name += typeEl->fullName();
    typeEl = typeEl->m_typeList;
    name += ", ";
  }
  // replace the trailing ", " (if any) with "): "
  if (hasArgs) {
    name.replace(name.size() - 2, 2, "): ");
  } else {
    name += "): ";
  }
  // add function return value
  name += retType->fullName();
  name += ")";
}
Ejemplo n.º 9
0
void TypeAnnotation::shapeTypeName(std::string& name) const {
  name += "HH\\shape(";
  TypeAnnotationPtr shapeField = m_typeArgs;
  auto sep = "";
  while (shapeField) {
    name += sep;

    if (shapeField->isClsCnsShapeField()) {
      folly::toAppend(shapeField->m_name, &name);
    } else {
      folly::toAppend("'", shapeField->m_name, "'", &name);
    }
    auto fieldValue = shapeField->m_typeArgs;
    assert(fieldValue);
    folly::toAppend("=>", fieldValue->fullName(), &name);

    sep = ", ";
    shapeField = shapeField->m_typeList;
  }

  name += ")";
}