[llvm] af7b98c - [clang-tblgen] Automatically document options values
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 20 13:00:28 PDT 2022
Author: serge-sans-paille
Date: 2022-04-20T22:00:06+02:00
New Revision: af7b98c383df62c0a749c3394b1670a1ed54c9d4
URL: https://github.com/llvm/llvm-project/commit/af7b98c383df62c0a749c3394b1670a1ed54c9d4
DIFF: https://github.com/llvm/llvm-project/commit/af7b98c383df62c0a749c3394b1670a1ed54c9d4.diff
LOG: [clang-tblgen] Automatically document options values
This is a port of f5c666742f7bb4ae79ec79c8acf61dced4d37cc9 to clang's tablegen,
with a better wording.
Differential Revision: https://reviews.llvm.org/D123682
Added:
Modified:
clang/utils/TableGen/ClangOptionDocEmitter.cpp
llvm/utils/TableGen/OptRSTEmitter.cpp
Removed:
################################################################################
diff --git a/clang/utils/TableGen/ClangOptionDocEmitter.cpp b/clang/utils/TableGen/ClangOptionDocEmitter.cpp
index 0e079b6b505ad..6c24ad2bdcc53 100644
--- a/clang/utils/TableGen/ClangOptionDocEmitter.cpp
+++ b/clang/utils/TableGen/ClangOptionDocEmitter.cpp
@@ -238,6 +238,8 @@ void emitOptionWithArgs(StringRef Prefix, const Record *Option,
}
}
+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 @@ void emitOptionName(StringRef Prefix, const Record *Option, raw_ostream &OS) {
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 @@ void emitOption(const DocumentedOption &Option, const Record *DocInfo,
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";
}
diff --git a/llvm/utils/TableGen/OptRSTEmitter.cpp b/llvm/utils/TableGen/OptRSTEmitter.cpp
index ee330a253eddb..03c7326e817a8 100644
--- a/llvm/utils/TableGen/OptRSTEmitter.cpp
+++ b/llvm/utils/TableGen/OptRSTEmitter.cpp
@@ -85,15 +85,13 @@ void EmitOptRST(RecordKeeper &Records, raw_ostream &OS) {
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()) {
More information about the llvm-commits
mailing list