@@ -235,8 +235,7 @@ tgtok::TokKind TGLexer::LexToken(bool FileOrLineStart) {
235
235
return tgtok::dot;
236
236
237
237
case ' \r ' :
238
- PrintFatalError (" getNextChar() must never return '\r '" );
239
- return tgtok::Error;
238
+ llvm_unreachable (" getNextChar() must never return '\r '" );
240
239
241
240
case ' ' :
242
241
case ' \t ' :
@@ -664,11 +663,10 @@ bool TGLexer::prepExitInclude(bool IncludeStackMustBeEmpty) {
664
663
PrepIncludeStack.pop_back ();
665
664
666
665
if (IncludeStackMustBeEmpty) {
667
- if (! PrepIncludeStack.empty ())
668
- PrintFatalError ( " preprocessor include stack is not empty" );
666
+ assert ( PrepIncludeStack.empty () &&
667
+ " preprocessor include stack is not empty" );
669
668
} else {
670
- if (PrepIncludeStack.empty ())
671
- PrintFatalError (" preprocessor include stack is empty" );
669
+ assert (!PrepIncludeStack.empty () && " preprocessor include stack is empty" );
672
670
}
673
671
674
672
return true ;
@@ -718,27 +716,25 @@ tgtok::TokKind TGLexer::prepIsDirective() const {
718
716
return tgtok::Error;
719
717
}
720
718
721
- bool TGLexer::prepEatPreprocessorDirective (tgtok::TokKind Kind) {
719
+ void TGLexer::prepEatPreprocessorDirective (tgtok::TokKind Kind) {
722
720
TokStart = CurPtr;
723
721
724
- for (const auto [PKind, PWord] : PreprocessorDirs)
722
+ for (const auto [PKind, PWord] : PreprocessorDirs) {
725
723
if (PKind == Kind) {
726
724
// Advance CurPtr to the end of the preprocessing word.
727
725
CurPtr += PWord.size ();
728
- return true ;
726
+ return ;
729
727
}
728
+ }
730
729
731
- PrintFatalError (" unsupported preprocessing token in "
732
- " prepEatPreprocessorDirective()" );
733
- return false ;
730
+ llvm_unreachable (
731
+ " unsupported preprocessing token in prepEatPreprocessorDirective()" );
734
732
}
735
733
736
734
tgtok::TokKind TGLexer::lexPreprocessor (tgtok::TokKind Kind,
737
735
bool ReturnNextLiveToken) {
738
736
// We must be looking at a preprocessing directive. Eat it!
739
- if (!prepEatPreprocessorDirective (Kind))
740
- PrintFatalError (" lexPreprocessor() called for unknown "
741
- " preprocessor directive" );
737
+ prepEatPreprocessorDirective (Kind);
742
738
743
739
if (Kind == tgtok::Ifdef || Kind == tgtok::Ifndef) {
744
740
StringRef MacroName = prepLexMacroName ();
@@ -820,11 +816,9 @@ tgtok::TokKind TGLexer::lexPreprocessor(tgtok::TokKind Kind,
820
816
821
817
auto &IfdefOrElseEntry = PrepIncludeStack.back ().back ();
822
818
823
- if (IfdefOrElseEntry.Kind != tgtok::Ifdef &&
824
- IfdefOrElseEntry.Kind != tgtok::Else) {
825
- PrintFatalError (" invalid preprocessor control on the stack" );
826
- return tgtok::Error;
827
- }
819
+ assert ((IfdefOrElseEntry.Kind == tgtok::Ifdef ||
820
+ IfdefOrElseEntry.Kind == tgtok::Else) &&
821
+ " invalid preprocessor control on the stack" );
828
822
829
823
if (!prepSkipDirectiveEnd ())
830
824
return ReturnError (CurPtr, " only comments are supported after #endif" );
@@ -852,21 +846,17 @@ tgtok::TokKind TGLexer::lexPreprocessor(tgtok::TokKind Kind,
852
846
return ReturnError (CurPtr,
853
847
" only comments are supported after #define NAME" );
854
848
855
- if (!ReturnNextLiveToken) {
856
- PrintFatalError (" #define must be ignored during the lines skipping" );
857
- return tgtok::Error;
858
- }
849
+ assert (ReturnNextLiveToken &&
850
+ " #define must be ignored during the lines skipping" );
859
851
860
852
return LexToken ();
861
853
}
862
854
863
- PrintFatalError (" preprocessing directive is not supported" );
864
- return tgtok::Error;
855
+ llvm_unreachable (" preprocessing directive is not supported" );
865
856
}
866
857
867
858
bool TGLexer::prepSkipRegion (bool MustNeverBeFalse) {
868
- if (!MustNeverBeFalse)
869
- PrintFatalError (" invalid recursion." );
859
+ assert (MustNeverBeFalse && " invalid recursion." );
870
860
871
861
do {
872
862
// Skip all symbols to the line end.
@@ -902,20 +892,17 @@ bool TGLexer::prepSkipRegion(bool MustNeverBeFalse) {
902
892
if (ProcessedKind == tgtok::Error)
903
893
return false ;
904
894
905
- if (Kind != ProcessedKind)
906
- PrintFatalError (" prepIsDirective() and lexPreprocessor() "
907
- " returned different token kinds" );
895
+ assert (Kind == ProcessedKind && " prepIsDirective() and lexPreprocessor() "
896
+ " returned different token kinds" );
908
897
909
898
// If this preprocessing directive enables tokens processing,
910
899
// then return to the lexPreprocessor() and get to the next token.
911
900
// We can move from line-skipping mode to processing tokens only
912
901
// due to #else or #endif.
913
902
if (prepIsProcessingEnabled ()) {
914
- if (Kind != tgtok::Else && Kind != tgtok::Endif) {
915
- PrintFatalError (" tokens processing was enabled by an unexpected "
916
- " preprocessing directive" );
917
- return false ;
918
- }
903
+ assert ((Kind == tgtok::Else || Kind == tgtok::Endif) &&
904
+ " tokens processing was enabled by an unexpected preprocessing "
905
+ " directive" );
919
906
920
907
return true ;
921
908
}
@@ -1053,10 +1040,6 @@ bool TGLexer::prepIsProcessingEnabled() {
1053
1040
}
1054
1041
1055
1042
void TGLexer::prepReportPreprocessorStackError () {
1056
- if (PrepIncludeStack.back ().empty ())
1057
- PrintFatalError (" prepReportPreprocessorStackError() called with "
1058
- " empty control stack" );
1059
-
1060
1043
auto &PrepControl = PrepIncludeStack.back ().back ();
1061
1044
PrintError (CurBuf.end (), " reached EOF without matching #endif" );
1062
1045
PrintError (PrepControl.SrcPos , " the latest preprocessor control is here" );
0 commit comments