@@ -24,8 +24,8 @@ using namespace llvm;
24
24
25
25
namespace {
26
26
struct DocumentedOption {
27
- Record *Option;
28
- std::vector<Record*> Aliases;
27
+ const Record *Option;
28
+ std::vector<const Record *> Aliases;
29
29
};
30
30
struct DocumentedGroup ;
31
31
struct Documentation {
@@ -37,7 +37,7 @@ struct Documentation {
37
37
}
38
38
};
39
39
struct DocumentedGroup : Documentation {
40
- Record *Group;
40
+ const Record *Group;
41
41
};
42
42
43
43
static bool hasFlag (const Record *Option, StringRef OptionFlag,
@@ -63,25 +63,25 @@ static bool isOptionVisible(const Record *Option, const Record *DocInfo) {
63
63
}
64
64
65
65
// Reorganize the records into a suitable form for emitting documentation.
66
- Documentation extractDocumentation (RecordKeeper &Records,
66
+ Documentation extractDocumentation (const RecordKeeper &Records,
67
67
const Record *DocInfo) {
68
68
Documentation Result;
69
69
70
70
// Build the tree of groups. The root in the tree is the fake option group
71
71
// (Record*)nullptr, which contains all top-level groups and options.
72
- std::map<Record*, std::vector<Record*> > OptionsInGroup;
73
- std::map<Record*, std::vector<Record*> > GroupsInGroup;
74
- std::map<Record*, std::vector<Record*> > Aliases;
72
+ std::map<const Record *, std::vector<const Record *> > OptionsInGroup;
73
+ std::map<const Record *, std::vector<const Record *> > GroupsInGroup;
74
+ std::map<const Record *, std::vector<const Record *> > Aliases;
75
75
76
- std::map<std::string, Record*> OptionsByName;
77
- for (Record *R : Records.getAllDerivedDefinitions (" Option" ))
76
+ std::map<std::string, const Record *> OptionsByName;
77
+ for (const Record *R : Records.getAllDerivedDefinitions (" Option" ))
78
78
OptionsByName[std::string (R->getValueAsString (" Name" ))] = R;
79
79
80
- auto Flatten = [](Record *R) {
80
+ auto Flatten = [](const Record *R) {
81
81
return R->getValue (" DocFlatten" ) && R->getValueAsBit (" DocFlatten" );
82
82
};
83
83
84
- auto SkipFlattened = [&](Record *R) -> Record* {
84
+ auto SkipFlattened = [&](const Record *R) -> const Record * {
85
85
while (R && Flatten (R)) {
86
86
auto *G = dyn_cast<DefInit>(R->getValueInit (" Group" ));
87
87
if (!G)
@@ -91,17 +91,17 @@ Documentation extractDocumentation(RecordKeeper &Records,
91
91
return R;
92
92
};
93
93
94
- for (Record *R : Records.getAllDerivedDefinitions (" OptionGroup" )) {
94
+ for (const Record *R : Records.getAllDerivedDefinitions (" OptionGroup" )) {
95
95
if (Flatten (R))
96
96
continue ;
97
97
98
- Record *Group = nullptr ;
98
+ const Record *Group = nullptr ;
99
99
if (auto *G = dyn_cast<DefInit>(R->getValueInit (" Group" )))
100
100
Group = SkipFlattened (G->getDef ());
101
101
GroupsInGroup[Group].push_back (R);
102
102
}
103
103
104
- for (Record *R : Records.getAllDerivedDefinitions (" Option" )) {
104
+ for (const Record *R : Records.getAllDerivedDefinitions (" Option" )) {
105
105
if (auto *A = dyn_cast<DefInit>(R->getValueInit (" Alias" ))) {
106
106
Aliases[A->getDef ()].push_back (R);
107
107
continue ;
@@ -120,33 +120,33 @@ Documentation extractDocumentation(RecordKeeper &Records,
120
120
}
121
121
}
122
122
123
- Record *Group = nullptr ;
123
+ const Record *Group = nullptr ;
124
124
if (auto *G = dyn_cast<DefInit>(R->getValueInit (" Group" )))
125
125
Group = SkipFlattened (G->getDef ());
126
126
OptionsInGroup[Group].push_back (R);
127
127
}
128
128
129
- auto CompareByName = [](Record *A, Record *B) {
129
+ auto CompareByName = [](const Record *A, const Record *B) {
130
130
return A->getValueAsString (" Name" ) < B->getValueAsString (" Name" );
131
131
};
132
132
133
- auto CompareByLocation = [](Record *A, Record *B) {
133
+ auto CompareByLocation = [](const Record *A, const Record *B) {
134
134
return A->getLoc ()[0 ].getPointer () < B->getLoc ()[0 ].getPointer ();
135
135
};
136
136
137
- auto DocumentationForOption = [&](Record *R) -> DocumentedOption {
137
+ auto DocumentationForOption = [&](const Record *R) -> DocumentedOption {
138
138
auto &A = Aliases[R];
139
139
llvm::sort (A, CompareByName);
140
140
return {R, std::move (A)};
141
141
};
142
142
143
- std::function<Documentation (Record *)> DocumentationForGroup =
144
- [&](Record *R) -> Documentation {
143
+ std::function<Documentation (const Record *)> DocumentationForGroup =
144
+ [&](const Record *R) -> Documentation {
145
145
Documentation D;
146
146
147
147
auto &Groups = GroupsInGroup[R];
148
148
llvm::sort (Groups, CompareByLocation);
149
- for (Record *G : Groups) {
149
+ for (const Record *G : Groups) {
150
150
D.Groups .emplace_back ();
151
151
D.Groups .back ().Group = G;
152
152
Documentation &Base = D.Groups .back ();
@@ -157,7 +157,7 @@ Documentation extractDocumentation(RecordKeeper &Records,
157
157
158
158
auto &Options = OptionsInGroup[R];
159
159
llvm::sort (Options, CompareByName);
160
- for (Record *O : Options)
160
+ for (const Record *O : Options)
161
161
if (isOptionVisible (O, DocInfo))
162
162
D.Options .push_back (DocumentationForOption (O));
163
163
@@ -444,7 +444,7 @@ void emitDocumentation(int Depth, const Documentation &Doc,
444
444
445
445
} // namespace
446
446
447
- void clang::EmitClangOptDocs (RecordKeeper &Records, raw_ostream &OS) {
447
+ void clang::EmitClangOptDocs (const RecordKeeper &Records, raw_ostream &OS) {
448
448
const Record *DocInfo = Records.getDef (" GlobalDocumentation" );
449
449
if (!DocInfo) {
450
450
PrintFatalError (" The GlobalDocumentation top-level definition is missing, "
0 commit comments