[PATCH] D157146: [Clang][Docs] Consolidate option hiding in ClangOptionDocEmitter
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGce16c3cf30f5: [Clang][Docs] Consolidate option hiding in ClangOptionDocEmitter (authored by bogner). Changed prior to commit: https://reviews.llvm.org/D157146?vs=547371&id=549805#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D157146/new/ https://reviews.llvm.org/D157146 Files: clang/utils/TableGen/ClangOptionDocEmitter.cpp Index: clang/utils/TableGen/ClangOptionDocEmitter.cpp === --- clang/utils/TableGen/ClangOptionDocEmitter.cpp +++ clang/utils/TableGen/ClangOptionDocEmitter.cpp @@ -31,13 +31,41 @@ struct Documentation { std::vector Groups; std::vector Options; + + bool empty() { +return Groups.empty() && Options.empty(); + } }; struct DocumentedGroup : Documentation { Record *Group; }; +static bool hasFlag(const Record *Option, StringRef OptionFlag) { + for (const Record *Flag : Option->getValueAsListOfDefs("Flags")) +if (Flag->getName() == OptionFlag) + return true; + if (const DefInit *DI = dyn_cast(Option->getValueInit("Group"))) +for (const Record *Flag : DI->getDef()->getValueAsListOfDefs("Flags")) + if (Flag->getName() == OptionFlag) +return true; + return false; +} + +static bool isOptionVisible(const Record *Option, const Record *DocInfo) { + for (StringRef Exclusion : DocInfo->getValueAsListOfStrings("ExcludedFlags")) +if (hasFlag(Option, Exclusion)) + return false; + if (!DocInfo->getValue("IncludedFlags")) +return true; + for (StringRef Inclusion : DocInfo->getValueAsListOfStrings("IncludedFlags")) +if (hasFlag(Option, Inclusion)) + return true; + return false; +} + // Reorganize the records into a suitable form for emitting documentation. -Documentation extractDocumentation(RecordKeeper &Records) { +Documentation extractDocumentation(RecordKeeper &Records, + const Record *DocInfo) { Documentation Result; // Build the tree of groups. The root in the tree is the fake option group @@ -124,12 +152,15 @@ D.Groups.back().Group = G; Documentation &Base = D.Groups.back(); Base = DocumentationForGroup(G); + if (Base.empty()) +D.Groups.pop_back(); } auto &Options = OptionsInGroup[R]; llvm::sort(Options, CompareByName); for (Record *O : Options) - D.Options.push_back(DocumentationForOption(O)); + if (isOptionVisible(O, DocInfo)) +D.Options.push_back(DocumentationForOption(O)); return D; }; @@ -161,44 +192,6 @@ .Default(0); } -bool hasFlag(const Record *OptionOrGroup, StringRef OptionFlag) { - for (const Record *Flag : OptionOrGroup->getValueAsListOfDefs("Flags")) -if (Flag->getName() == OptionFlag) - return true; - return false; -} - -bool isIncluded(const Record *OptionOrGroup, const Record *DocInfo) { - assert(DocInfo->getValue("IncludedFlags") && "Missing includeFlags"); - for (StringRef Inclusion : DocInfo->getValueAsListOfStrings("IncludedFlags")) -if (hasFlag(OptionOrGroup, Inclusion)) - return true; - return false; -} - -bool isGroupIncluded(const DocumentedGroup &Group, const Record *DocInfo) { - if (isIncluded(Group.Group, DocInfo)) -return true; - for (auto &O : Group.Options) -if (isIncluded(O.Option, DocInfo)) - return true; - for (auto &G : Group.Groups) { -if (isIncluded(G.Group, DocInfo)) - return true; -if (isGroupIncluded(G, DocInfo)) - return true; - } - return false; -} - -bool isExcluded(const Record *OptionOrGroup, const Record *DocInfo) { - // FIXME: Provide a flag to specify the set of exclusions. - for (StringRef Exclusion : DocInfo->getValueAsListOfStrings("ExcludedFlags")) -if (hasFlag(OptionOrGroup, Exclusion)) - return true; - return false; -} - std::string escapeRST(StringRef Str) { std::string Out; for (auto K : Str) { @@ -319,16 +312,13 @@ F(Option.Option); for (auto *Alias : Option.Aliases) -if (!isExcluded(Alias, DocInfo) && canSphinxCopeWithOption(Option.Option)) +if (isOptionVisible(Alias, DocInfo) && +canSphinxCopeWithOption(Option.Option)) F(Alias); } void emitOption(const DocumentedOption &Option, const Record *DocInfo, raw_ostream &OS) { - if (isExcluded(Option.Option, DocInfo)) -return; - if (DocInfo->getValue("IncludedFlags") && !isIncluded(Option.Option, DocInfo)) -return; if (Option.Option->getValueAsDef("Kind")->getName() == "KIND_UNKNOWN" || Option.Option->getValueAsDef("Kind")->getName() == "KIND_INPUT") return; @@ -401,12 +391,6 @@ void emitGroup(int Depth, const DocumentedGroup &Group, const Record *DocInfo, raw_ostream &OS) { - if (isExcluded(Group.Group, DocInfo)) -return; - - if (DocInfo->getValue("Inc
[PATCH] D157146: [Clang][Docs] Consolidate option hiding in ClangOptionDocEmitter
MaskRay added a comment. The diff is preferable:) --- tools/clang/docs/html/ClangCommandLineReference.html2023-08-12 22:10:23.876913374 -0700 +++ tools/clang/docs/html/ClangCommandLineReference.html.old2023-08-12 22:09:58.900516809 -0700 @@ -94,8 +94,18 @@ Static analyzer options Fortran compilation options Linker options -- + + + + + + + + + + + + @@ -7868,9 +7878,21 @@ Set multiple /O flags at once; e.g. ‘/O2y-’ for ‘/O2 /Oy-’ + + ¶ + +¶ + + +¶ + + + + ¶ + - ¶ + ¶ dxc compatibility options Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D157146/new/ https://reviews.llvm.org/D157146 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D157146: [Clang][Docs] Consolidate option hiding in ClangOptionDocEmitter
MaskRay accepted this revision. MaskRay added inline comments. This revision is now accepted and ready to land. Comment at: clang/utils/TableGen/ClangOptionDocEmitter.cpp:43 +bool hasFlag(const Record *Option, StringRef OptionFlag) { + for (const Record *Flag : Option->getValueAsListOfDefs("Flags")) For new functions, consider using `static` for internal linkage functions even if they are surrounded by an anonymous namespace, per https://llvm.org/docs/CodingStandards.html#anonymous-namespaces Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D157146/new/ https://reviews.llvm.org/D157146 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D157146: [Clang][Docs] Consolidate option hiding in ClangOptionDocEmitter
bogner created this revision. bogner added a reviewer: MaskRay. Herald added a subscriber: mcrosier. Herald added a project: All. bogner requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. Update the `hasFlag` check to account for an Option's groups to better match how the option parsing logic works, and instead of checking if a group has include/exclude flags just check if there are any visible options in it. This cleans up some the empty sections that are currently emitted in clang's option docs. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D157146 Files: clang/utils/TableGen/ClangOptionDocEmitter.cpp Index: clang/utils/TableGen/ClangOptionDocEmitter.cpp === --- clang/utils/TableGen/ClangOptionDocEmitter.cpp +++ clang/utils/TableGen/ClangOptionDocEmitter.cpp @@ -31,13 +31,41 @@ struct Documentation { std::vector Groups; std::vector Options; + + bool empty() { +return Groups.empty() && Options.empty(); + } }; struct DocumentedGroup : Documentation { Record *Group; }; +bool hasFlag(const Record *Option, StringRef OptionFlag) { + for (const Record *Flag : Option->getValueAsListOfDefs("Flags")) +if (Flag->getName() == OptionFlag) + return true; + if (const DefInit *DI = dyn_cast(Option->getValueInit("Group"))) +for (const Record *Flag : DI->getDef()->getValueAsListOfDefs("Flags")) + if (Flag->getName() == OptionFlag) +return true; + return false; +} + +bool isOptionVisible(const Record *Option, const Record *DocInfo) { + for (StringRef Exclusion : DocInfo->getValueAsListOfStrings("ExcludedFlags")) +if (hasFlag(Option, Exclusion)) + return false; + if (!DocInfo->getValue("IncludedFlags")) +return true; + for (StringRef Inclusion : DocInfo->getValueAsListOfStrings("IncludedFlags")) +if (hasFlag(Option, Inclusion)) + return true; + return false; +} + // Reorganize the records into a suitable form for emitting documentation. -Documentation extractDocumentation(RecordKeeper &Records) { +Documentation extractDocumentation(RecordKeeper &Records, + const Record *DocInfo) { Documentation Result; // Build the tree of groups. The root in the tree is the fake option group @@ -124,12 +152,15 @@ D.Groups.back().Group = G; Documentation &Base = D.Groups.back(); Base = DocumentationForGroup(G); + if (Base.empty()) +D.Groups.pop_back(); } auto &Options = OptionsInGroup[R]; llvm::sort(Options, CompareByName); for (Record *O : Options) - D.Options.push_back(DocumentationForOption(O)); + if (isOptionVisible(O, DocInfo)) +D.Options.push_back(DocumentationForOption(O)); return D; }; @@ -161,44 +192,6 @@ .Default(0); } -bool hasFlag(const Record *OptionOrGroup, StringRef OptionFlag) { - for (const Record *Flag : OptionOrGroup->getValueAsListOfDefs("Flags")) -if (Flag->getName() == OptionFlag) - return true; - return false; -} - -bool isIncluded(const Record *OptionOrGroup, const Record *DocInfo) { - assert(DocInfo->getValue("IncludedFlags") && "Missing includeFlags"); - for (StringRef Inclusion : DocInfo->getValueAsListOfStrings("IncludedFlags")) -if (hasFlag(OptionOrGroup, Inclusion)) - return true; - return false; -} - -bool isGroupIncluded(const DocumentedGroup &Group, const Record *DocInfo) { - if (isIncluded(Group.Group, DocInfo)) -return true; - for (auto &O : Group.Options) -if (isIncluded(O.Option, DocInfo)) - return true; - for (auto &G : Group.Groups) { -if (isIncluded(G.Group, DocInfo)) - return true; -if (isGroupIncluded(G, DocInfo)) - return true; - } - return false; -} - -bool isExcluded(const Record *OptionOrGroup, const Record *DocInfo) { - // FIXME: Provide a flag to specify the set of exclusions. - for (StringRef Exclusion : DocInfo->getValueAsListOfStrings("ExcludedFlags")) -if (hasFlag(OptionOrGroup, Exclusion)) - return true; - return false; -} - std::string escapeRST(StringRef Str) { std::string Out; for (auto K : Str) { @@ -319,16 +312,13 @@ F(Option.Option); for (auto *Alias : Option.Aliases) -if (!isExcluded(Alias, DocInfo) && canSphinxCopeWithOption(Option.Option)) +if (isOptionVisible(Alias, DocInfo) && +canSphinxCopeWithOption(Option.Option)) F(Alias); } void emitOption(const DocumentedOption &Option, const Record *DocInfo, raw_ostream &OS) { - if (isExcluded(Option.Option, DocInfo)) -return; - if (DocInfo->getValue("IncludedFlags") && !isIncluded(Option.Option, DocInfo)) -return; if (Option.Option->getValueAsDef("Kind")->getName() == "KIND_UNKNOWN" || Option.Option->getValueAsDef("Kind")->getName() == "KIND_INPUT") return; @@ -401,12 +391,6 @@ void emitGroup(int Depth, const DocumentedGroup &Group,