@@ -31,13 +31,41 @@ struct DocumentedGroup;
31
31
struct Documentation {
32
32
std::vector<DocumentedGroup> Groups;
33
33
std::vector<DocumentedOption> Options;
34
+
35
+ bool empty () {
36
+ return Groups.empty () && Options.empty ();
37
+ }
34
38
};
35
39
struct DocumentedGroup : Documentation {
36
40
Record *Group;
37
41
};
38
42
43
+ static bool hasFlag (const Record *Option, StringRef OptionFlag) {
44
+ for (const Record *Flag : Option->getValueAsListOfDefs (" Flags" ))
45
+ if (Flag->getName () == OptionFlag)
46
+ return true ;
47
+ if (const DefInit *DI = dyn_cast<DefInit>(Option->getValueInit (" Group" )))
48
+ for (const Record *Flag : DI->getDef ()->getValueAsListOfDefs (" Flags" ))
49
+ if (Flag->getName () == OptionFlag)
50
+ return true ;
51
+ return false ;
52
+ }
53
+
54
+ static bool isOptionVisible (const Record *Option, const Record *DocInfo) {
55
+ for (StringRef Exclusion : DocInfo->getValueAsListOfStrings (" ExcludedFlags" ))
56
+ if (hasFlag (Option, Exclusion))
57
+ return false ;
58
+ if (!DocInfo->getValue (" IncludedFlags" ))
59
+ return true ;
60
+ for (StringRef Inclusion : DocInfo->getValueAsListOfStrings (" IncludedFlags" ))
61
+ if (hasFlag (Option, Inclusion))
62
+ return true ;
63
+ return false ;
64
+ }
65
+
39
66
// Reorganize the records into a suitable form for emitting documentation.
40
- Documentation extractDocumentation (RecordKeeper &Records) {
67
+ Documentation extractDocumentation (RecordKeeper &Records,
68
+ const Record *DocInfo) {
41
69
Documentation Result;
42
70
43
71
// Build the tree of groups. The root in the tree is the fake option group
@@ -124,12 +152,15 @@ Documentation extractDocumentation(RecordKeeper &Records) {
124
152
D.Groups .back ().Group = G;
125
153
Documentation &Base = D.Groups .back ();
126
154
Base = DocumentationForGroup (G);
155
+ if (Base.empty ())
156
+ D.Groups .pop_back ();
127
157
}
128
158
129
159
auto &Options = OptionsInGroup[R];
130
160
llvm::sort (Options, CompareByName);
131
161
for (Record *O : Options)
132
- D.Options .push_back (DocumentationForOption (O));
162
+ if (isOptionVisible (O, DocInfo))
163
+ D.Options .push_back (DocumentationForOption (O));
133
164
134
165
return D;
135
166
};
@@ -161,44 +192,6 @@ unsigned getNumArgsForKind(Record *OptionKind, const Record *Option) {
161
192
.Default (0 );
162
193
}
163
194
164
- bool hasFlag (const Record *OptionOrGroup, StringRef OptionFlag) {
165
- for (const Record *Flag : OptionOrGroup->getValueAsListOfDefs (" Flags" ))
166
- if (Flag->getName () == OptionFlag)
167
- return true ;
168
- return false ;
169
- }
170
-
171
- bool isIncluded (const Record *OptionOrGroup, const Record *DocInfo) {
172
- assert (DocInfo->getValue (" IncludedFlags" ) && " Missing includeFlags" );
173
- for (StringRef Inclusion : DocInfo->getValueAsListOfStrings (" IncludedFlags" ))
174
- if (hasFlag (OptionOrGroup, Inclusion))
175
- return true ;
176
- return false ;
177
- }
178
-
179
- bool isGroupIncluded (const DocumentedGroup &Group, const Record *DocInfo) {
180
- if (isIncluded (Group.Group , DocInfo))
181
- return true ;
182
- for (auto &O : Group.Options )
183
- if (isIncluded (O.Option , DocInfo))
184
- return true ;
185
- for (auto &G : Group.Groups ) {
186
- if (isIncluded (G.Group , DocInfo))
187
- return true ;
188
- if (isGroupIncluded (G, DocInfo))
189
- return true ;
190
- }
191
- return false ;
192
- }
193
-
194
- bool isExcluded (const Record *OptionOrGroup, const Record *DocInfo) {
195
- // FIXME: Provide a flag to specify the set of exclusions.
196
- for (StringRef Exclusion : DocInfo->getValueAsListOfStrings (" ExcludedFlags" ))
197
- if (hasFlag (OptionOrGroup, Exclusion))
198
- return true ;
199
- return false ;
200
- }
201
-
202
195
std::string escapeRST (StringRef Str) {
203
196
std::string Out;
204
197
for (auto K : Str) {
@@ -319,16 +312,13 @@ void forEachOptionName(const DocumentedOption &Option, const Record *DocInfo,
319
312
F (Option.Option );
320
313
321
314
for (auto *Alias : Option.Aliases )
322
- if (!isExcluded (Alias, DocInfo) && canSphinxCopeWithOption (Option.Option ))
315
+ if (isOptionVisible (Alias, DocInfo) &&
316
+ canSphinxCopeWithOption (Option.Option ))
323
317
F (Alias);
324
318
}
325
319
326
320
void emitOption (const DocumentedOption &Option, const Record *DocInfo,
327
321
raw_ostream &OS) {
328
- if (isExcluded (Option.Option , DocInfo))
329
- return ;
330
- if (DocInfo->getValue (" IncludedFlags" ) && !isIncluded (Option.Option , DocInfo))
331
- return ;
332
322
if (Option.Option ->getValueAsDef (" Kind" )->getName () == " KIND_UNKNOWN" ||
333
323
Option.Option ->getValueAsDef (" Kind" )->getName () == " KIND_INPUT" )
334
324
return ;
@@ -401,12 +391,6 @@ void emitDocumentation(int Depth, const Documentation &Doc,
401
391
402
392
void emitGroup (int Depth, const DocumentedGroup &Group, const Record *DocInfo,
403
393
raw_ostream &OS) {
404
- if (isExcluded (Group.Group , DocInfo))
405
- return ;
406
-
407
- if (DocInfo->getValue (" IncludedFlags" ) && !isGroupIncluded (Group, DocInfo))
408
- return ;
409
-
410
394
emitHeading (Depth,
411
395
getRSTStringWithTextFallback (Group.Group , " DocName" , " Name" ), OS);
412
396
@@ -440,5 +424,5 @@ void clang::EmitClangOptDocs(RecordKeeper &Records, raw_ostream &OS) {
440
424
OS << DocInfo->getValueAsString (" Intro" ) << " \n " ;
441
425
OS << " .. program:: " << DocInfo->getValueAsString (" Program" ) << " \n " ;
442
426
443
- emitDocumentation (0 , extractDocumentation (Records), DocInfo, OS);
427
+ emitDocumentation (0 , extractDocumentation (Records, DocInfo ), DocInfo, OS);
444
428
}
0 commit comments