@@ -120,9 +120,6 @@ enum class TriviaKind {
120
120
121
121
// / A backtick '`' character, used to escape identifiers.
122
122
Backtick,
123
-
124
- // / A semicolon ';' character, used for delimiting statements.
125
- Semicolon
126
123
};
127
124
128
125
// / A contiguous stretch of a single kind of trivia. The constiuent part of
@@ -187,11 +184,6 @@ struct TriviaPiece {
187
184
return TriviaPiece {TriviaKind::Backtick, 1 , OwnedString{}};
188
185
}
189
186
190
- // / Return a piece of trivia for some number of semicolons in a row.
191
- static TriviaPiece semicolon (unsigned Count) {
192
- return TriviaPiece {TriviaKind::Semicolon, Count, OwnedString{}};
193
- }
194
-
195
187
void accumulateAbsolutePosition (AbsolutePosition &Pos) const ;
196
188
197
189
// / Print a debug representation of this trivia piece to the provided output
@@ -200,6 +192,16 @@ struct TriviaPiece {
200
192
201
193
// / Print this piece of trivia to the provided output stream.
202
194
void print (llvm::raw_ostream &OS) const ;
195
+
196
+ bool operator ==(const TriviaPiece &Other) const {
197
+ return Kind == Other.Kind &&
198
+ Count == Other.Count &&
199
+ Text.str ().compare (Other.Text .str ()) == 0 ;
200
+ }
201
+
202
+ bool operator !=(const TriviaPiece &Other) const {
203
+ return !(*this == Other);
204
+ }
203
205
};
204
206
205
207
using TriviaList = std::deque<TriviaPiece>;
@@ -233,20 +235,23 @@ struct Trivia {
233
235
// /
234
236
// / Precondition: !empty()
235
237
const TriviaPiece &front () const {
238
+ assert (!empty ());
236
239
return Pieces.front ();
237
240
}
238
241
239
242
// / Return a reference to the last piece.
240
243
// /
241
244
// / Precondition: !empty()
242
245
const TriviaPiece &back () const {
246
+ assert (!empty ());
243
247
return Pieces.back ();
244
248
}
245
249
246
250
// / Remove the last piece from the Trivia collection.
247
251
// /
248
252
// / Precondition: !empty()
249
253
void pop_back () {
254
+ assert (!empty ());
250
255
Pieces.pop_back ();
251
256
}
252
257
@@ -283,41 +288,74 @@ struct Trivia {
283
288
return find (Kind) != end ();
284
289
}
285
290
291
+ bool operator ==(const Trivia &Other) const {
292
+ if (Pieces.size () != Other.size ()) {
293
+ return false ;
294
+ }
295
+
296
+ for (size_t i = 0 ; i < Pieces.size (); ++i) {
297
+ if (Pieces[i] != Other.Pieces [i]) {
298
+ return false ;
299
+ }
300
+ }
301
+
302
+ return true ;
303
+ }
304
+
305
+ bool operator !=(const Trivia &Other) const {
306
+ return !(*this == Other);
307
+ }
308
+
286
309
// / Return a collection of trivia of some number of space characters in a row.
287
310
static Trivia spaces (unsigned Count) {
311
+ if (Count == 0 ) {
312
+ return {};
313
+ }
288
314
return {{ TriviaPiece {TriviaKind::Space, Count, OwnedString{}} }};
289
315
}
290
316
291
317
// / Return a collection of trivia of some number of tab characters in a row.
292
318
static Trivia tabs (unsigned Count) {
319
+ if (Count == 0 ) {
320
+ return {};
321
+ }
293
322
return {{ TriviaPiece {TriviaKind::Tab, Count, OwnedString{}} }};
294
323
}
295
324
296
325
// / Return a collection of trivia of some number of newline characters
297
326
// in a row.
298
327
static Trivia newlines (unsigned Count) {
328
+ if (Count == 0 ) {
329
+ return {};
330
+ }
299
331
return {{ TriviaPiece {TriviaKind::Newline, Count, OwnedString{}} }};
300
332
}
301
333
302
334
// / Return a collection of trivia with a single line of ('//')
303
335
// developer comment.
304
336
static Trivia lineComment (const OwnedString Text) {
337
+ assert (Text.str ().startswith (" //" ));
305
338
return {{ TriviaPiece {TriviaKind::LineComment, 1 , Text} }};
306
339
}
307
340
308
341
// / Return a collection of trivia with a block comment ('/* ... */')
309
342
static Trivia blockComment (const OwnedString Text) {
343
+ assert (Text.str ().startswith (" /*" ));
344
+ assert (Text.str ().endswith (" */" ));
310
345
return {{ TriviaPiece {TriviaKind::BlockComment, 1 , Text} }};
311
346
}
312
347
313
348
// / Return a collection of trivia with a single line of ('///') doc comment.
314
349
static Trivia docLineComment (const OwnedString Text) {
350
+ assert (Text.str ().startswith (" ///" ));
315
351
return {{ TriviaPiece {TriviaKind::DocLineComment, 1 , Text} }};
316
352
}
317
353
318
354
// / Return a collection of trivia with a documentation block
319
355
// comment ('/** ... */')
320
356
static Trivia docBlockComment (const OwnedString Text) {
357
+ assert (Text.str ().startswith (" /**" ));
358
+ assert (Text.str ().endswith (" */" ));
321
359
return {{ TriviaPiece {TriviaKind::DocBlockComment, 1 , Text} }};
322
360
}
323
361
@@ -326,11 +364,6 @@ struct Trivia {
326
364
static Trivia backtick () {
327
365
return {{ TriviaPiece {TriviaKind::Backtick, 1 , OwnedString{}} }};
328
366
}
329
-
330
- // / Return a piece of trivia for some number of semicolons in a row.
331
- static Trivia semicolon () {
332
- return {{ TriviaPiece {TriviaKind::Semicolon, 1 , OwnedString{}} }};
333
- }
334
367
};
335
368
}
336
369
}
0 commit comments