================ @@ -191,6 +191,60 @@ static MarshallingInfo createMarshallingInfo(const Record &R) { return Ret; } +static void EmitHelpTextsForVariants( + raw_ostream &OS, std::vector<std::pair<std::vector<std::string>, StringRef>> + HelpTextsForVariants) { + // OptTable must be constexpr so it uses std::arrays with these capacities. + const unsigned MaxVisibilityPerHelp = 2; + const unsigned MaxVisibilityHelp = 1; + + // This function must initialise any unused elements of those arrays. + for (auto [Visibilities, _] : HelpTextsForVariants) + while (Visibilities.size() < MaxVisibilityPerHelp) + Visibilities.push_back("0"); + + while (HelpTextsForVariants.size() < MaxVisibilityHelp) + HelpTextsForVariants.push_back( + {std::vector<std::string>(MaxVisibilityPerHelp, "0"), ""}); + + OS << ", (std::array<std::pair<std::array<unsigned, " << MaxVisibilityPerHelp + << ">, const char*>, " << MaxVisibilityHelp << ">{{ "; + + assert(HelpTextsForVariants.size() <= MaxVisibilityHelp && + "Too many help text variants to store in " + "OptTable::HelpTextsForVariants"); + + for (auto VisibilityHelp = HelpTextsForVariants.cbegin(); + VisibilityHelp != HelpTextsForVariants.cend(); ++VisibilityHelp) { ---------------- luporl wrote:
Nit: save `HelpTextsForVariants.cend()` in a variable. https://llvm.org/docs/CodingStandards.html#don-t-evaluate-end-every-time-through-a-loop https://github.com/llvm/llvm-project/pull/81869 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits