[PATCH] D123682: [clang-tblgen] Automatically document options values
serge via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 20 06:32:57 PDT 2022
serge-sans-paille updated this revision to Diff 423890.
serge-sans-paille marked an inline comment as done.
serge-sans-paille added a comment.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Adopt a better wording.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D123682/new/
https://reviews.llvm.org/D123682
Files:
clang/utils/TableGen/ClangOptionDocEmitter.cpp
llvm/utils/TableGen/OptRSTEmitter.cpp
Index: llvm/utils/TableGen/OptRSTEmitter.cpp
===================================================================
--- llvm/utils/TableGen/OptRSTEmitter.cpp
+++ llvm/utils/TableGen/OptRSTEmitter.cpp
@@ -85,15 +85,13 @@
if (!isa<UnsetInit>(R->getValueInit("Values"))) {
SmallVector<StringRef> Values;
SplitString(R->getValueAsString("Values"), Values, ",");
- HelpText += (" " + MetaVarName + " can be ").str();
+ HelpText += (" " + MetaVarName + " must be '").str();
- if (Values.size() == 1) {
- HelpText += ("'" + Values.front() + "'.").str();
- } else {
- HelpText += "one of '";
+ if (Values.size() > 1) {
HelpText += join(Values.begin(), Values.end() - 1, "', '");
- HelpText += ("' or '" + Values.back() + "'.").str();
+ HelpText += "' or '";
}
+ HelpText += (Values.front() + "'.").str();
}
if (!HelpText.empty()) {
Index: clang/utils/TableGen/ClangOptionDocEmitter.cpp
===================================================================
--- clang/utils/TableGen/ClangOptionDocEmitter.cpp
+++ clang/utils/TableGen/ClangOptionDocEmitter.cpp
@@ -238,6 +238,8 @@
}
}
+constexpr StringLiteral DefaultMetaVarName = "<arg>";
+
void emitOptionName(StringRef Prefix, const Record *Option, raw_ostream &OS) {
// Find the arguments to list after the option.
unsigned NumArgs = getNumArgsForKind(Option->getValueAsDef("Kind"), Option);
@@ -247,7 +249,7 @@
if (HasMetaVarName)
Args.push_back(std::string(Option->getValueAsString("MetaVarName")));
else if (NumArgs == 1)
- Args.push_back("<arg>");
+ Args.push_back(DefaultMetaVarName.str());
// Fill up arguments if this option didn't provide a meta var name or it
// supports an unlimited number of arguments. We can't see how many arguments
@@ -341,8 +343,30 @@
OS << "\n\n";
// Emit the description, if we have one.
+ const Record *R = Option.Option;
std::string Description =
- getRSTStringWithTextFallback(Option.Option, "DocBrief", "HelpText");
+ getRSTStringWithTextFallback(R, "DocBrief", "HelpText");
+
+ if (!isa<UnsetInit>(R->getValueInit("Values"))) {
+ if (!Description.empty() && Description.back() != '.')
+ Description.push_back('.');
+
+ StringRef MetaVarName;
+ if (!isa<UnsetInit>(R->getValueInit("MetaVarName")))
+ MetaVarName = R->getValueAsString("MetaVarName");
+ else
+ MetaVarName = DefaultMetaVarName;
+
+ SmallVector<StringRef> Values;
+ SplitString(R->getValueAsString("Values"), Values, ",");
+ Description += (" " + MetaVarName + " must be '").str();
+ if (Values.size() > 1) {
+ Description += join(Values.begin(), Values.end() - 1, "', '");
+ Description += "' or '";
+ }
+ Description += (Values.back() + "'.").str();
+ }
+
if (!Description.empty())
OS << Description << "\n\n";
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123682.423890.patch
Type: text/x-patch
Size: 2923 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220420/a32210bd/attachment.bin>
More information about the llvm-commits
mailing list