@@ -81,8 +81,7 @@ TGLexer::TGLexer(SourceMgr &SM, ArrayRef<std::string> Macros) : SrcMgr(SM) {
81
81
TokStart = nullptr ;
82
82
83
83
// Pretend that we enter the "top-level" include file.
84
- PrepIncludeStack.push_back (
85
- std::make_unique<std::vector<PreprocessorControlDesc>>());
84
+ PrepIncludeStack.emplace_back ();
86
85
87
86
// Add all macros defined on the command line to the DefinedMacros set.
88
87
// Check invalid macro names and print fatal error if we find one.
@@ -453,8 +452,7 @@ bool TGLexer::LexInclude() {
453
452
CurBuf = SrcMgr.getMemoryBuffer (CurBuffer)->getBuffer ();
454
453
CurPtr = CurBuf.begin ();
455
454
456
- PrepIncludeStack.push_back (
457
- std::make_unique<std::vector<PreprocessorControlDesc>>());
455
+ PrepIncludeStack.emplace_back ();
458
456
return false ;
459
457
}
460
458
@@ -656,17 +654,13 @@ tgtok::TokKind TGLexer::LexExclaim() {
656
654
bool TGLexer::prepExitInclude (bool IncludeStackMustBeEmpty) {
657
655
// Report an error, if preprocessor control stack for the current
658
656
// file is not empty.
659
- if (!PrepIncludeStack.back ()-> empty ()) {
657
+ if (!PrepIncludeStack.back (). empty ()) {
660
658
prepReportPreprocessorStackError ();
661
659
662
660
return false ;
663
661
}
664
662
665
663
// Pop the preprocessing controls from the include stack.
666
- if (PrepIncludeStack.empty ()) {
667
- PrintFatalError (" preprocessor include stack is empty" );
668
- }
669
-
670
664
PrepIncludeStack.pop_back ();
671
665
672
666
if (IncludeStackMustBeEmpty) {
@@ -761,7 +755,7 @@ tgtok::TokKind TGLexer::lexPreprocessor(tgtok::TokKind Kind,
761
755
// Regardless of whether we are processing tokens or not,
762
756
// we put the #ifdef control on stack.
763
757
// Note that MacroIsDefined has been canonicalized against ifdef.
764
- PrepIncludeStack.back ()-> push_back (
758
+ PrepIncludeStack.back (). push_back (
765
759
{tgtok::Ifdef, MacroIsDefined, SMLoc::getFromPointer (TokStart)});
766
760
767
761
if (!prepSkipDirectiveEnd ())
@@ -789,10 +783,10 @@ tgtok::TokKind TGLexer::lexPreprocessor(tgtok::TokKind Kind,
789
783
} else if (Kind == tgtok::Else) {
790
784
// Check if this #else is correct before calling prepSkipDirectiveEnd(),
791
785
// which will move CurPtr away from the beginning of #else.
792
- if (PrepIncludeStack.back ()-> empty ())
786
+ if (PrepIncludeStack.back (). empty ())
793
787
return ReturnError (TokStart, " #else without #ifdef or #ifndef" );
794
788
795
- PreprocessorControlDesc IfdefEntry = PrepIncludeStack.back ()-> back ();
789
+ PreprocessorControlDesc IfdefEntry = PrepIncludeStack.back (). back ();
796
790
797
791
if (IfdefEntry.Kind != tgtok::Ifdef) {
798
792
PrintError (TokStart, " double #else" );
@@ -801,9 +795,8 @@ tgtok::TokKind TGLexer::lexPreprocessor(tgtok::TokKind Kind,
801
795
802
796
// Replace the corresponding #ifdef's control with its negation
803
797
// on the control stack.
804
- PrepIncludeStack.back ()->pop_back ();
805
- PrepIncludeStack.back ()->push_back (
806
- {Kind, !IfdefEntry.IsDefined , SMLoc::getFromPointer (TokStart)});
798
+ PrepIncludeStack.back ().back () = {Kind, !IfdefEntry.IsDefined ,
799
+ SMLoc::getFromPointer (TokStart)};
807
800
808
801
if (!prepSkipDirectiveEnd ())
809
802
return ReturnError (CurPtr, " only comments are supported after #else" );
@@ -822,10 +815,10 @@ tgtok::TokKind TGLexer::lexPreprocessor(tgtok::TokKind Kind,
822
815
} else if (Kind == tgtok::Endif) {
823
816
// Check if this #endif is correct before calling prepSkipDirectiveEnd(),
824
817
// which will move CurPtr away from the beginning of #endif.
825
- if (PrepIncludeStack.back ()-> empty ())
818
+ if (PrepIncludeStack.back (). empty ())
826
819
return ReturnError (TokStart, " #endif without #ifdef" );
827
820
828
- auto &IfdefOrElseEntry = PrepIncludeStack.back ()-> back ();
821
+ auto &IfdefOrElseEntry = PrepIncludeStack.back (). back ();
829
822
830
823
if (IfdefOrElseEntry.Kind != tgtok::Ifdef &&
831
824
IfdefOrElseEntry.Kind != tgtok::Else) {
@@ -836,7 +829,7 @@ tgtok::TokKind TGLexer::lexPreprocessor(tgtok::TokKind Kind,
836
829
if (!prepSkipDirectiveEnd ())
837
830
return ReturnError (CurPtr, " only comments are supported after #endif" );
838
831
839
- PrepIncludeStack.back ()-> pop_back ();
832
+ PrepIncludeStack.back (). pop_back ();
840
833
841
834
// If we were processing tokens before this #endif, then
842
835
// we should continue it.
@@ -1055,20 +1048,16 @@ bool TGLexer::prepSkipDirectiveEnd() {
1055
1048
}
1056
1049
1057
1050
bool TGLexer::prepIsProcessingEnabled () {
1058
- for (const PreprocessorControlDesc &I :
1059
- llvm::reverse (*PrepIncludeStack.back ()))
1060
- if (!I.IsDefined )
1061
- return false ;
1062
-
1063
- return true ;
1051
+ return all_of (PrepIncludeStack.back (),
1052
+ [](const PreprocessorControlDesc &I) { return I.IsDefined ; });
1064
1053
}
1065
1054
1066
1055
void TGLexer::prepReportPreprocessorStackError () {
1067
- if (PrepIncludeStack.back ()-> empty ())
1056
+ if (PrepIncludeStack.back (). empty ())
1068
1057
PrintFatalError (" prepReportPreprocessorStackError() called with "
1069
1058
" empty control stack" );
1070
1059
1071
- auto &PrepControl = PrepIncludeStack.back ()-> back ();
1060
+ auto &PrepControl = PrepIncludeStack.back (). back ();
1072
1061
PrintError (CurBuf.end (), " reached EOF without matching #endif" );
1073
1062
PrintError (PrepControl.SrcPos , " the latest preprocessor control is here" );
1074
1063
0 commit comments