@@ -93,9 +93,7 @@ TGLexer::TGLexer(SourceMgr &SM, ArrayRef<std::string> Macros) : SrcMgr(SM) {
93
93
}
94
94
}
95
95
96
- SMLoc TGLexer::getLoc () const {
97
- return SMLoc::getFromPointer (TokStart);
98
- }
96
+ SMLoc TGLexer::getLoc () const { return SMLoc::getFromPointer (TokStart); }
99
97
100
98
SMRange TGLexer::getLocRange () const {
101
99
return {getLoc (), SMLoc::getFromPointer (CurPtr)};
@@ -162,16 +160,13 @@ int TGLexer::getNextChar() {
162
160
// Handle the newline character by ignoring it and incrementing the line
163
161
// count. However, be careful about 'dos style' files with \n\r in them.
164
162
// Only treat a \n\r or \r\n as a single line.
165
- if ((*CurPtr == ' \n ' || (*CurPtr == ' \r ' )) &&
166
- *CurPtr != CurChar)
167
- ++CurPtr; // Eat the two char newline sequence.
163
+ if ((*CurPtr == ' \n ' || (*CurPtr == ' \r ' )) && *CurPtr != CurChar)
164
+ ++CurPtr; // Eat the two char newline sequence.
168
165
return ' \n ' ;
169
166
}
170
167
}
171
168
172
- int TGLexer::peekNextChar (int Index) const {
173
- return *(CurPtr + Index);
174
- }
169
+ int TGLexer::peekNextChar (int Index) const { return *(CurPtr + Index); }
175
170
176
171
tgtok::TokKind TGLexer::LexToken (bool FileOrLineStart) {
177
172
while (true ) {
@@ -367,7 +362,9 @@ tgtok::TokKind TGLexer::LexString() {
367
362
++CurPtr;
368
363
369
364
switch (*CurPtr) {
370
- case ' \\ ' : case ' \' ' : case ' "' :
365
+ case ' \\ ' :
366
+ case ' \' ' :
367
+ case ' "' :
371
368
// These turn into their literal character.
372
369
CurStrVal += *CurPtr++;
373
370
break ;
@@ -421,7 +418,7 @@ tgtok::TokKind TGLexer::LexIdentifier() {
421
418
++CurPtr;
422
419
423
420
// Check to see if this identifier is a reserved keyword.
424
- StringRef Str (IdentStart, CurPtr- IdentStart);
421
+ StringRef Str (IdentStart, CurPtr - IdentStart);
425
422
426
423
tgtok::TokKind Kind = StringSwitch<tgtok::TokKind>(Str)
427
424
.Case (" int" , tgtok::Int)
@@ -454,14 +451,15 @@ tgtok::TokKind TGLexer::LexIdentifier() {
454
451
455
452
// A couple of tokens require special processing.
456
453
switch (Kind) {
457
- case tgtok::Include:
458
- if (LexInclude ()) return tgtok::Error;
459
- return Lex ();
460
- case tgtok::Id:
461
- CurStrVal.assign (Str.begin (), Str.end ());
462
- break ;
463
- default :
464
- break ;
454
+ case tgtok::Include:
455
+ if (LexInclude ())
456
+ return tgtok::Error;
457
+ return Lex ();
458
+ case tgtok::Id:
459
+ CurStrVal.assign (Str.begin (), Str.end ());
460
+ break ;
461
+ default :
462
+ break ;
465
463
}
466
464
467
465
return Kind;
@@ -472,7 +470,8 @@ tgtok::TokKind TGLexer::LexIdentifier() {
472
470
bool TGLexer::LexInclude () {
473
471
// The token after the include must be a string.
474
472
tgtok::TokKind Tok = LexToken ();
475
- if (Tok == tgtok::Error) return true ;
473
+ if (Tok == tgtok::Error)
474
+ return true ;
476
475
if (Tok != tgtok::StrVal) {
477
476
PrintError (getLoc (), " expected filename after include" );
478
477
return true ;
@@ -501,15 +500,15 @@ bool TGLexer::LexInclude() {
501
500
// / SkipBCPLComment - Skip over the comment by finding the next CR or LF.
502
501
// / Or we may end up at the end of the buffer.
503
502
void TGLexer::SkipBCPLComment () {
504
- ++CurPtr; // skip the second slash.
503
+ ++CurPtr; // skip the second slash.
505
504
auto EOLPos = CurBuf.find_first_of (" \r\n " , CurPtr - CurBuf.data ());
506
505
CurPtr = (EOLPos == StringRef::npos) ? CurBuf.end () : CurBuf.data () + EOLPos;
507
506
}
508
507
509
508
// / SkipCComment - This skips C-style /**/ comments. The only difference from C
510
509
// / is that we allow nesting.
511
510
bool TGLexer::SkipCComment () {
512
- ++CurPtr; // skip the star.
511
+ ++CurPtr; // skip the star.
513
512
unsigned CommentDepth = 1 ;
514
513
515
514
while (true ) {
@@ -520,15 +519,17 @@ bool TGLexer::SkipCComment() {
520
519
return true ;
521
520
case ' *' :
522
521
// End of the comment?
523
- if (CurPtr[0 ] != ' /' ) break ;
522
+ if (CurPtr[0 ] != ' /' )
523
+ break ;
524
524
525
- ++CurPtr; // End the */.
525
+ ++CurPtr; // End the */.
526
526
if (--CommentDepth == 0 )
527
527
return false ;
528
528
break ;
529
529
case ' /' :
530
530
// Start of a nested comment?
531
- if (CurPtr[0 ] != ' *' ) break ;
531
+ if (CurPtr[0 ] != ' *' )
532
+ break ;
532
533
++CurPtr;
533
534
++CommentDepth;
534
535
break ;
@@ -608,14 +609,17 @@ tgtok::TokKind TGLexer::LexBracket() {
608
609
const char *CodeStart = CurPtr;
609
610
while (true ) {
610
611
int Char = getNextChar ();
611
- if (Char == EOF) break ;
612
+ if (Char == EOF)
613
+ break ;
612
614
613
- if (Char != ' }' ) continue ;
615
+ if (Char != ' }' )
616
+ continue ;
614
617
615
618
Char = getNextChar ();
616
- if (Char == EOF) break ;
619
+ if (Char == EOF)
620
+ break ;
617
621
if (Char == ' ]' ) {
618
- CurStrVal.assign (CodeStart, CurPtr- 2 );
622
+ CurStrVal.assign (CodeStart, CurPtr - 2 );
619
623
return tgtok::CodeFragment;
620
624
}
621
625
}
0 commit comments