================ @@ -162,15 +162,264 @@ Error MustacheHTMLGenerator::generateDocs( return Error::success(); } +static json::Value +extractValue(const Location &L, + std::optional<StringRef> RepositoryUrl = std::nullopt) { + Object Obj = Object(); + // Should there be Start/End line numbers? + Obj.insert({"LineNumber", L.StartLineNumber}); + Obj.insert({"Filename", L.Filename}); + + if (!L.IsFileInRootDir || !RepositoryUrl) + return Obj; + SmallString<128> FileURL(*RepositoryUrl); + sys::path::append(FileURL, sys::path::Style::posix, L.Filename); + FileURL += "#" + std::to_string(L.StartLineNumber); + Obj.insert({"FileURL", FileURL}); + + return Obj; +} + +static json::Value extractValue(const Reference &I, + StringRef CurrentDirectory) { + SmallString<64> Path = I.getRelativeFilePath(CurrentDirectory); + sys::path::append(Path, I.getFileBaseName() + ".html"); + sys::path::native(Path, sys::path::Style::posix); + Object Obj = Object(); + Obj.insert({"Link", Path}); + Obj.insert({"Name", I.Name}); + Obj.insert({"QualName", I.QualName}); + Obj.insert({"ID", toHex(toStringRef(I.USR))}); + return Obj; +} + +static json::Value extractValue(const TypedefInfo &I) { + // Not Supported + return nullptr; +} + +static json::Value extractValue(const CommentInfo &I) { + assert((I.Kind == "BlockCommandComment" || I.Kind == "FullComment" || + I.Kind == "ParagraphComment" || I.Kind == "TextComment") && + "Unknown Comment type in CommentInfo."); + + Object Obj = Object(); + json::Value Child = Object(); + + // TextComment has no children, so return it. + if (I.Kind == "TextComment") { + Obj.insert({"TextComment", I.Text}); + return Obj; + } + + // BlockCommandComment needs to generate a Command key. + if (I.Kind == "BlockCommandComment") + Child.getAsObject()->insert({"Command", I.Name}); + + // Use the same handling for everything else. + // Only valid for: + // - BlockCommandComment + // - FullComment + // - ParagraphComment + json::Value ChildArr = Array(); + auto &CARef = *ChildArr.getAsArray(); + CARef.reserve(I.Children.size()); + for (const auto &C : I.Children) + CARef.emplace_back(extractValue(*C)); + Child.getAsObject()->insert({"Children", ChildArr}); + Obj.insert({I.Kind, Child}); + + return Obj; +} + +static void maybeInsertLocation(std::optional<Location> Loc, + const ClangDocContext &CDCtx, Object &Obj) { + if (!Loc) + return; + Location L = *Loc; + Obj.insert({"Location", extractValue(L, CDCtx.RepositoryUrl)}); +} + +static void extractDescriptionFromInfo(ArrayRef<CommentInfo> Descriptions, + json::Object &EnumValObj) { + if (Descriptions.empty()) + return; + json::Value ArrDesc = Array(); + json::Array &ADescRef = *ArrDesc.getAsArray(); + for (const CommentInfo &Child : Descriptions) + ADescRef.emplace_back(extractValue(Child)); + EnumValObj.insert({"EnumValueComments", ArrDesc}); +} + +static json::Value extractValue(const FunctionInfo &I, StringRef ParentInfoDir, + const ClangDocContext &CDCtx) { + Object Obj = Object(); + Obj.insert({"Name", I.Name}); + Obj.insert({"ID", toHex(toStringRef(I.USR))}); + Obj.insert({"Access", getAccessSpelling(I.Access).str()}); + Obj.insert({"ReturnType", extractValue(I.ReturnType.Type, ParentInfoDir)}); + + json::Value ParamArr = Array(); + for (const auto Val : enumerate(I.Params)) { + json::Value V = Object(); + auto &VRef = *V.getAsObject(); + VRef.insert({"Name", Val.value().Name}); + VRef.insert({"Type", Val.value().Type.Name}); + VRef.insert({"End", Val.index() + 1 == I.Params.size()}); + ParamArr.getAsArray()->emplace_back(V); + } + Obj.insert({"Params", ParamArr}); + + maybeInsertLocation(I.DefLoc, CDCtx, Obj); + return Obj; +} + +static json::Value extractValue(const EnumInfo &I, + const ClangDocContext &CDCtx) { + Object Obj = Object(); + std::string EnumType = I.Scoped ? "enum class " : "enum "; + EnumType += I.Name; + bool HasComment = std::any_of( + I.Members.begin(), I.Members.end(), + [](const EnumValueInfo &M) { return !M.Description.empty(); }); + Obj.insert({"EnumName", EnumType}); + Obj.insert({"HasComment", HasComment}); + Obj.insert({"ID", toHex(toStringRef(I.USR))}); + json::Value Arr = Array(); ---------------- evelez7 wrote:
```suggestion json::Value EnumArr = Array(); ``` nit: Arrays in the other `extractValue` functions have type+"Arr" names. Same for the reference. https://github.com/llvm/llvm-project/pull/138063 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits