Skip to content

Commit 09b80e6

Browse files
[clang][flang][driver] Correct program names in option group descriptions (#81726)
Currently https://flang.llvm.org/docs/FlangCommandLineReference.html refers to "Clang" in several of the group descriptions for example: ``` Compilation options Flags controlling the behavior of Clang during compilation... ``` This is pretty confusing. I'm fixing this by making use of `Program` from the existing GlobalDocumentation object to substitute in the program name to these descriptions. This `Program` has been changed to a proper noun given that it's easier to lower case a string than capitalise one character (syntax wise). The tablegen backend has been changed to lower it so that links in the RST/HTML remain the same as they were before. To make sure the file is valid when not generating docs, I'm checking a #define and providing a default GlobalDocumentation if it's not defined. (I looked for a way to check if a def exists, but tablegen doesn't seem to have one) This means that if the DocBrief are used outside of documentation, they'll say "Clang", which is the same as it always was. This change does not aim fix option descriptions that refer to clang. Though we can use parts of this for that, there is only one driver library so it needs a different approach. This change also fixes the warning: ``` /home/buildbot/as-worker-4/publish-sphinx-docs/build/tools/flang/docs/Source/FlangCommandLineReference.rst:194: WARNING: unknown document: 'DiagnosticsReference' ``` Which is due to flang docs trying to link to clang docs. Now it will just tell the reader to go to Clang's page, which is not ideal but it is easy to find with Google at least.
1 parent f6f8e20 commit 09b80e6

File tree

4 files changed

+44
-15
lines changed

4 files changed

+44
-15
lines changed

clang/include/clang/Driver/ClangOptionDocs.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ GCC-compatible ``clang`` and ``clang++`` drivers.
2727

2828
}];
2929

30-
string Program = "clang";
30+
string Program = "Clang";
3131
// Note: We *must* use DefaultVis and not ClangOption, since that's
3232
// the name of the actual TableGen record. The alias will not work.
3333
list<string> VisibilityMask = ["DefaultVis"];
3434
list<string> IgnoreFlags = ["HelpHidden", "Unsupported", "Ignored"];
3535
}
3636

37+
#define GENERATING_DOCS
3738
include "Options.td"

clang/include/clang/Driver/Options.td

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@
1313
// Include the common option parsing interfaces.
1414
include "llvm/Option/OptParser.td"
1515

16+
// When generating documentation, we expect there to be a GlobalDocumentation
17+
// def containing the program name that we are generating documentation for.
18+
// This object should only be used by things that are used in documentation,
19+
// such as the group descriptions.
20+
#ifndef GENERATING_DOCS
21+
// So that this file can still be parsed without such a def, define one if there
22+
// isn't one provided.
23+
def GlobalDocumentation {
24+
// Sensible default in case of mistakes.
25+
string Program = "Clang";
26+
}
27+
#endif
28+
29+
// Use this to generate program specific documentation, for example:
30+
// StringForProgram<"Control how %Program behaves.">.str
31+
class StringForProgram<string _str> {
32+
string str = !subst("%Program", GlobalDocumentation.Program, _str);
33+
}
34+
1635
/////////
1736
// Flags
1837

@@ -100,14 +119,16 @@ def Action_Group : OptionGroup<"<action group>">, DocName<"Actions">,
100119
// Meta-group for options which are only used for compilation,
101120
// and not linking etc.
102121
def CompileOnly_Group : OptionGroup<"<CompileOnly group>">,
103-
DocName<"Compilation options">, DocBrief<[{
104-
Flags controlling the behavior of Clang during compilation. These flags have
105-
no effect during actions that do not perform compilation.}]>;
122+
DocName<"Compilation options">,
123+
DocBrief<StringForProgram<[{
124+
Flags controlling the behavior of %Program during compilation. These flags have
125+
no effect during actions that do not perform compilation.}]>.str>;
106126

107127
def Preprocessor_Group : OptionGroup<"<Preprocessor group>">,
108128
Group<CompileOnly_Group>,
109-
DocName<"Preprocessor options">, DocBrief<[{
110-
Flags controlling the behavior of the Clang preprocessor.}]>;
129+
DocName<"Preprocessor options">,
130+
DocBrief<StringForProgram<[{
131+
Flags controlling the behavior of the %Program preprocessor.}]>.str>;
111132

112133
def IncludePath_Group : OptionGroup<"<I/i group>">, Group<Preprocessor_Group>,
113134
DocName<"Include path management">,
@@ -128,9 +149,15 @@ def d_Group : OptionGroup<"<d group>">, Group<Preprocessor_Group>,
128149
Flags allowing the state of the preprocessor to be dumped in various ways.}]>;
129150

130151
def Diag_Group : OptionGroup<"<W/R group>">, Group<CompileOnly_Group>,
131-
DocName<"Diagnostic options">, DocBrief<[{
132-
Flags controlling which warnings, errors, and remarks Clang will generate.
133-
See the :doc:`full list of warning and remark flags <DiagnosticsReference>`.}]>;
152+
DocName<"Diagnostic options">,
153+
DocBrief<!strconcat(StringForProgram<
154+
"Flags controlling which warnings, errors, and remarks %Program will generate. ">.str,
155+
// When in clang link directly to the page.
156+
!cond(!eq(GlobalDocumentation.Program, "Clang"):
157+
"See the :doc:`full list of warning and remark flags <DiagnosticsReference>`.",
158+
// When elsewhere the link will not work.
159+
true:
160+
"See Clang's Diagnostic Reference for a full list of warning and remark flags."))>;
134161

135162
def R_Group : OptionGroup<"<R group>">, Group<Diag_Group>, DocFlatten;
136163
def R_value_Group : OptionGroup<"<R (with value) group>">, Group<R_Group>,

clang/utils/TableGen/ClangOptionDocEmitter.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,10 @@ void emitOption(const DocumentedOption &Option, const Record *DocInfo,
342342
})];
343343
for (auto &S : SphinxOptionIDs)
344344
NextSuffix[S] = SphinxWorkaroundSuffix + 1;
345+
346+
std::string Program = DocInfo->getValueAsString("Program").lower();
345347
if (SphinxWorkaroundSuffix)
346-
OS << ".. program:: " << DocInfo->getValueAsString("Program")
347-
<< SphinxWorkaroundSuffix << "\n";
348+
OS << ".. program:: " << Program << SphinxWorkaroundSuffix << "\n";
348349

349350
// Emit the names of the option.
350351
OS << ".. option:: ";
@@ -353,7 +354,7 @@ void emitOption(const DocumentedOption &Option, const Record *DocInfo,
353354
EmittedAny = emitOptionNames(Option, OS, EmittedAny);
354355
});
355356
if (SphinxWorkaroundSuffix)
356-
OS << "\n.. program:: " << DocInfo->getValueAsString("Program");
357+
OS << "\n.. program:: " << Program;
357358
OS << "\n\n";
358359

359360
// Emit the description, if we have one.
@@ -421,7 +422,7 @@ void clang::EmitClangOptDocs(RecordKeeper &Records, raw_ostream &OS) {
421422
return;
422423
}
423424
OS << DocInfo->getValueAsString("Intro") << "\n";
424-
OS << ".. program:: " << DocInfo->getValueAsString("Program") << "\n";
425+
OS << ".. program:: " << DocInfo->getValueAsString("Program").lower() << "\n";
425426

426427
emitDocumentation(0, extractDocumentation(Records, DocInfo), DocInfo, OS);
427428
}

flang/docs/FlangOptionsDocs.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ Introduction
2424

2525
}];
2626

27-
string Program = "flang";
27+
string Program = "Flang";
2828
list<string> VisibilityMask = ["FlangOption"];
2929
list<string> IgnoreFlags = ["HelpHidden", "Unsupported", "Ignored"];
3030
}
3131

32-
32+
#define GENERATING_DOCS
3333
include "Options.td"

0 commit comments

Comments
 (0)