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)); } }
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>(); }
static Substitution getSimpleSubstitution(GenericParamList &generics, CanType typeArg) { assert(generics.getParams().size() == 1); auto typeParamDecl = generics.getParams().front(); return Substitution{typeParamDecl->getArchetype(), typeArg, {}}; }
static Substitution getSimpleSubstitution(GenericParamList &generics, CanType typeArg) { assert(generics.getParams().size() == 1); return Substitution{typeArg, {}}; }