[PATCH] D123682: [clang-tblgen] Automatically document options values
serge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 13 06:55:43 PDT 2022
serge-sans-paille created this revision.
serge-sans-paille added a reviewer: MaskRay.
Herald added a subscriber: StephenFan.
Herald added a project: All.
serge-sans-paille requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This is a port of f5c666742f7bb4ae79ec79c8acf61dced4d37cc9 <https://reviews.llvm.org/rGf5c666742f7bb4ae79ec79c8acf61dced4d37cc9> to clang's tablegen.
The code duplication is a bit sad there :-/
Related to https://reviews.llvm.org/D122378
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D123682
Files:
clang/utils/TableGen/ClangOptionDocEmitter.cpp
Index: clang/utils/TableGen/ClangOptionDocEmitter.cpp
===================================================================
--- clang/utils/TableGen/ClangOptionDocEmitter.cpp
+++ clang/utils/TableGen/ClangOptionDocEmitter.cpp
@@ -238,6 +238,8 @@
}
}
+static StringRef 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,33 @@
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 + " can be ").str();
+
+ if (Values.size() == 1) {
+ Description += ("'" + Values.front() + "'.").str();
+ } else {
+ Description += "one of '";
+ Description += join(Values.begin(), Values.end() - 1, "', '");
+ Description += ("' or '" + Values.back() + "'.").str();
+ }
+ }
+
if (!Description.empty())
OS << Description << "\n\n";
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123682.422501.patch
Type: text/x-patch
Size: 2043 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220413/1812c586/attachment-0001.bin>
More information about the cfe-commits
mailing list