static void initDocGenericParams(const Decl *D, DocEntityInfo &Info) {
  GenericParamList *GenParams = nullptr;
  if (auto *NTD = dyn_cast<NominalTypeDecl>(D)) {
    GenParams = NTD->getGenericParams();
  } else if (auto *AFD = dyn_cast<AbstractFunctionDecl>(D)) {
    GenParams = AFD->getGenericParams();
  } else if (auto *ExtD = dyn_cast<ExtensionDecl>(D)) {
    GenParams = ExtD->getGenericParams();
  }

  if (!GenParams)
    return;

  for (auto *GP : GenParams->getParams()) {
    if (GP->isImplicit())
      continue;
    DocGenericParam Param;
    Param.Name = GP->getNameStr();
    if (!GP->getInherited().empty()) {
      llvm::raw_string_ostream OS(Param.Inherits);
      GP->getInherited()[0].getType().print(OS);
    }

    Info.GenericParams.push_back(Param);
  }
  for (auto &Req : GenParams->getRequirements()) {
    std::string ReqStr;
    llvm::raw_string_ostream OS(ReqStr);
    Req.printAsWritten(OS);
    OS.flush();
    Info.GenericRequirements.push_back(std::move(ReqStr));
  }
}
Example #2
0
GenericTypeParamType *DeclContext::getProtocolSelfType() const {
  assert(getSelfProtocolDecl() && "not a protocol");

  GenericParamList *genericParams;
  if (auto proto = dyn_cast<ProtocolDecl>(this)) {
    genericParams = proto->getGenericParams();
  } else {
    genericParams = cast<ExtensionDecl>(this)->getGenericParams();
  }

  if (genericParams == nullptr)
    return nullptr;

  return genericParams->getParams().front()
      ->getDeclaredInterfaceType()
      ->castTo<GenericTypeParamType>();
}
Example #3
0
static Substitution getSimpleSubstitution(GenericParamList &generics,
                                          CanType typeArg) {
  assert(generics.getParams().size() == 1);
  auto typeParamDecl = generics.getParams().front();
  return Substitution{typeParamDecl->getArchetype(), typeArg, {}};
}
Example #4
0
static Substitution getSimpleSubstitution(GenericParamList &generics,
                                          CanType typeArg) {
  assert(generics.getParams().size() == 1);
  return Substitution{typeArg, {}};
}