@@ -113,14 +113,39 @@ class BaseRecord {
113
113
114
114
// Returns the name of the directive formatted for output. Whitespace are
115
115
// replaced with underscores.
116
- static std::string formatName (StringRef Name) {
116
+ static std::string getSnakeName (StringRef Name) {
117
117
std::string N = Name.str ();
118
118
llvm::replace (N, ' ' , ' _' );
119
119
return N;
120
120
}
121
121
122
+ static std::string getUpperCamelName (StringRef Name, StringRef Sep) {
123
+ std::string Camel = Name.str ();
124
+ // Convert to uppercase
125
+ bool Cap = true ;
126
+ llvm::transform (Camel, Camel.begin (), [&](unsigned char C) {
127
+ if (Sep.contains (C)) {
128
+ assert (!Cap && " No initial or repeated separators" );
129
+ Cap = true ;
130
+ } else if (Cap) {
131
+ C = llvm::toUpper (C);
132
+ Cap = false ;
133
+ }
134
+ return C;
135
+ });
136
+ size_t Out = 0 ;
137
+ // Remove separators
138
+ for (size_t In = 0 , End = Camel.size (); In != End; ++In) {
139
+ unsigned char C = Camel[In];
140
+ if (!Sep.contains (C))
141
+ Camel[Out++] = C;
142
+ }
143
+ Camel.resize (Out);
144
+ return Camel;
145
+ }
146
+
122
147
std::string getFormattedName () const {
123
- return formatName (Def->getValueAsString (" name" ));
148
+ return getSnakeName (Def->getValueAsString (" name" ));
124
149
}
125
150
126
151
bool isDefault () const { return Def->getValueAsBit (" isDefault" ); }
@@ -172,26 +197,13 @@ class Directive : public BaseRecord {
172
197
173
198
// Clang uses a different format for names of its directives enum.
174
199
std::string getClangAccSpelling () const {
175
- std::string Name = Def->getValueAsString (" name" ). str ( );
200
+ StringRef Name = Def->getValueAsString (" name" );
176
201
177
202
// Clang calls the 'unknown' value 'invalid'.
178
203
if (Name == " unknown" )
179
204
return " Invalid" ;
180
205
181
- // Clang entries all start with a capital letter, so apply that.
182
- Name[0 ] = std::toupper (Name[0 ]);
183
- // Additionally, spaces/underscores are handled by capitalizing the next
184
- // letter of the name and removing the space/underscore.
185
- for (unsigned I = 0 ; I < Name.size (); ++I) {
186
- if (Name[I] == ' ' || Name[I] == ' _' ) {
187
- Name.erase (I, 1 );
188
- assert (Name[I] != ' ' && Name[I] != ' _' &&
189
- " No double spaces/underscores" );
190
- Name[I] = std::toupper (Name[I]);
191
- }
192
- }
193
-
194
- return Name;
206
+ return BaseRecord::getUpperCamelName (Name, " _" );
195
207
}
196
208
};
197
209
@@ -218,19 +230,7 @@ class Clause : public BaseRecord {
218
230
// num_threads -> NumThreads
219
231
std::string getFormattedParserClassName () const {
220
232
StringRef Name = Def->getValueAsString (" name" );
221
- std::string N = Name.str ();
222
- bool Cap = true ;
223
- llvm::transform (N, N.begin (), [&Cap](unsigned char C) {
224
- if (Cap == true ) {
225
- C = toUpper (C);
226
- Cap = false ;
227
- } else if (C == ' _' ) {
228
- Cap = true ;
229
- }
230
- return C;
231
- });
232
- erase (N, ' _' );
233
- return N;
233
+ return BaseRecord::getUpperCamelName (Name, " _" );
234
234
}
235
235
236
236
// Clang uses a different format for names of its clause enum, which can be
@@ -241,20 +241,8 @@ class Clause : public BaseRecord {
241
241
!ClangSpelling.empty ())
242
242
return ClangSpelling.str ();
243
243
244
- std::string Name = Def->getValueAsString (" name" ).str ();
245
- // Clang entries all start with a capital letter, so apply that.
246
- Name[0 ] = std::toupper (Name[0 ]);
247
- // Additionally, underscores are handled by capitalizing the next letter of
248
- // the name and removing the underscore.
249
- for (unsigned I = 0 ; I < Name.size (); ++I) {
250
- if (Name[I] == ' _' ) {
251
- Name.erase (I, 1 );
252
- assert (Name[I] != ' _' && " No double underscores" );
253
- Name[I] = std::toupper (Name[I]);
254
- }
255
- }
256
-
257
- return Name;
244
+ StringRef Name = Def->getValueAsString (" name" );
245
+ return BaseRecord::getUpperCamelName (Name, " _" );
258
246
}
259
247
260
248
// Optional field.
0 commit comments