@@ -720,8 +720,8 @@ bool Prescanner::NextToken(TokenSequence &tokens) {
720
720
} else if (*at_ == ' .' ) {
721
721
while (IsDecimalDigit (EmitCharAndAdvance (tokens, *at_))) {
722
722
}
723
- ExponentAndKind (tokens);
724
- } else if (ExponentAndKind (tokens)) {
723
+ HandleExponentAndOrKindSuffix (tokens);
724
+ } else if (HandleExponentAndOrKindSuffix (tokens)) {
725
725
} else if (digits == 1 && n == 0 && (*at_ == ' x' || *at_ == ' X' ) &&
726
726
inPreprocessorDirective_) {
727
727
do {
@@ -743,7 +743,7 @@ bool Prescanner::NextToken(TokenSequence &tokens) {
743
743
if (!inPreprocessorDirective_ && IsDecimalDigit (nch)) {
744
744
while (IsDecimalDigit (EmitCharAndAdvance (tokens, *at_))) {
745
745
}
746
- ExponentAndKind (tokens);
746
+ HandleExponentAndOrKindSuffix (tokens);
747
747
} else if (nch == ' .' && EmitCharAndAdvance (tokens, ' .' ) == ' .' ) {
748
748
EmitCharAndAdvance (tokens, ' .' ); // variadic macro definition ellipsis
749
749
}
@@ -839,40 +839,52 @@ bool Prescanner::NextToken(TokenSequence &tokens) {
839
839
return true ;
840
840
}
841
841
842
- bool Prescanner::ExponentAndKind (TokenSequence &tokens) {
843
- char ed{ToLowerCaseLetter (*at_)};
844
- if (ed != ' e' && ed != ' d' ) {
845
- return false ;
846
- }
847
- // Do some look-ahead to ensure that this 'e'/'d' is an exponent,
848
- // not the start of an identifier that could be a macro.
849
- const char *p{at_};
850
- if (int n{IsSpace (++p)}) {
851
- p += n;
852
- }
853
- if (*p == ' +' || *p == ' -' ) {
854
- if (int n{IsSpace (++p)}) {
855
- p += n;
842
+ bool Prescanner::HandleExponent (TokenSequence &tokens) {
843
+ if (char ed{ToLowerCaseLetter (*at_)}; ed == ' e' || ed == ' d' ) {
844
+ // Do some look-ahead to ensure that this 'e'/'d' is an exponent,
845
+ // not the start of an identifier that could be a macro.
846
+ const char *p{SkipWhiteSpace (at_ + 1 )};
847
+ if (*p == ' +' || *p == ' -' ) {
848
+ p = SkipWhiteSpace (p + 1 );
849
+ }
850
+ if (IsDecimalDigit (*p)) { // it's an exponent
851
+ EmitCharAndAdvance (tokens, ed);
852
+ if (*at_ == ' +' || *at_ == ' -' ) {
853
+ EmitCharAndAdvance (tokens, *at_);
854
+ }
855
+ while (IsDecimalDigit (*at_)) {
856
+ EmitCharAndAdvance (tokens, *at_);
857
+ }
858
+ return true ;
856
859
}
857
860
}
858
- if (IsDecimalDigit (*p)) { // it's an exponent
859
- EmitCharAndAdvance (tokens, ed);
860
- if (*at_ == ' +' || *at_ == ' -' ) {
861
- EmitCharAndAdvance (tokens, *at_);
862
- }
863
- while (IsDecimalDigit (*at_)) {
864
- EmitCharAndAdvance (tokens, *at_);
861
+ return false ;
862
+ }
863
+
864
+ bool Prescanner::HandleKindSuffix (TokenSequence &tokens) {
865
+ if (*at_ == ' _' && IsLegalInIdentifier (*SkipWhiteSpace (at_ + 1 ))) {
866
+ EmitCharAndAdvance (tokens, *at_);
867
+ if (IsLegalIdentifierStart (*at_)) {
868
+ // The kind specifier might be a macro, so put it into its own token.
869
+ tokens.CloseToken ();
865
870
}
866
- if (*at_ == ' _' ) {
867
- while (IsLegalInIdentifier (EmitCharAndAdvance (tokens, *at_))) {
868
- }
871
+ while (IsLegalInIdentifier (EmitCharAndAdvance (tokens, *at_))) {
869
872
}
870
873
return true ;
871
874
} else {
872
875
return false ;
873
876
}
874
877
}
875
878
879
+ bool Prescanner::HandleExponentAndOrKindSuffix (TokenSequence &tokens) {
880
+ bool hadExponent{HandleExponent (tokens)};
881
+ if (HandleKindSuffix (tokens)) {
882
+ return true ;
883
+ } else {
884
+ return hadExponent;
885
+ }
886
+ }
887
+
876
888
void Prescanner::QuotedCharacterLiteral (
877
889
TokenSequence &tokens, const char *start) {
878
890
char quote{*at_};
0 commit comments