@@ -81,8 +81,7 @@ TGLexer::TGLexer(SourceMgr &SM, ArrayRef<std::string> Macros) : SrcMgr(SM) {
8181 TokStart = nullptr ;
8282
8383 // Pretend that we enter the "top-level" include file.
84- PrepIncludeStack.push_back (
85- std::make_unique<std::vector<PreprocessorControlDesc>>());
84+ PrepIncludeStack.emplace_back ();
8685
8786 // Add all macros defined on the command line to the DefinedMacros set.
8887 // Check invalid macro names and print fatal error if we find one.
@@ -453,8 +452,7 @@ bool TGLexer::LexInclude() {
453452 CurBuf = SrcMgr.getMemoryBuffer (CurBuffer)->getBuffer ();
454453 CurPtr = CurBuf.begin ();
455454
456- PrepIncludeStack.push_back (
457- std::make_unique<std::vector<PreprocessorControlDesc>>());
455+ PrepIncludeStack.emplace_back ();
458456 return false ;
459457}
460458
@@ -656,17 +654,13 @@ tgtok::TokKind TGLexer::LexExclaim() {
656654bool TGLexer::prepExitInclude (bool IncludeStackMustBeEmpty) {
657655 // Report an error, if preprocessor control stack for the current
658656 // file is not empty.
659- if (!PrepIncludeStack.back ()-> empty ()) {
657+ if (!PrepIncludeStack.back (). empty ()) {
660658 prepReportPreprocessorStackError ();
661659
662660 return false ;
663661 }
664662
665663 // Pop the preprocessing controls from the include stack.
666- if (PrepIncludeStack.empty ()) {
667- PrintFatalError (" preprocessor include stack is empty" );
668- }
669-
670664 PrepIncludeStack.pop_back ();
671665
672666 if (IncludeStackMustBeEmpty) {
@@ -761,7 +755,7 @@ tgtok::TokKind TGLexer::lexPreprocessor(tgtok::TokKind Kind,
761755 // Regardless of whether we are processing tokens or not,
762756 // we put the #ifdef control on stack.
763757 // Note that MacroIsDefined has been canonicalized against ifdef.
764- PrepIncludeStack.back ()-> push_back (
758+ PrepIncludeStack.back (). push_back (
765759 {tgtok::Ifdef, MacroIsDefined, SMLoc::getFromPointer (TokStart)});
766760
767761 if (!prepSkipDirectiveEnd ())
@@ -789,10 +783,10 @@ tgtok::TokKind TGLexer::lexPreprocessor(tgtok::TokKind Kind,
789783 } else if (Kind == tgtok::Else) {
790784 // Check if this #else is correct before calling prepSkipDirectiveEnd(),
791785 // which will move CurPtr away from the beginning of #else.
792- if (PrepIncludeStack.back ()-> empty ())
786+ if (PrepIncludeStack.back (). empty ())
793787 return ReturnError (TokStart, " #else without #ifdef or #ifndef" );
794788
795- PreprocessorControlDesc IfdefEntry = PrepIncludeStack.back ()-> back ();
789+ PreprocessorControlDesc IfdefEntry = PrepIncludeStack.back (). back ();
796790
797791 if (IfdefEntry.Kind != tgtok::Ifdef) {
798792 PrintError (TokStart, " double #else" );
@@ -801,9 +795,8 @@ tgtok::TokKind TGLexer::lexPreprocessor(tgtok::TokKind Kind,
801795
802796 // Replace the corresponding #ifdef's control with its negation
803797 // 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)};
807800
808801 if (!prepSkipDirectiveEnd ())
809802 return ReturnError (CurPtr, " only comments are supported after #else" );
@@ -822,10 +815,10 @@ tgtok::TokKind TGLexer::lexPreprocessor(tgtok::TokKind Kind,
822815 } else if (Kind == tgtok::Endif) {
823816 // Check if this #endif is correct before calling prepSkipDirectiveEnd(),
824817 // which will move CurPtr away from the beginning of #endif.
825- if (PrepIncludeStack.back ()-> empty ())
818+ if (PrepIncludeStack.back (). empty ())
826819 return ReturnError (TokStart, " #endif without #ifdef" );
827820
828- auto &IfdefOrElseEntry = PrepIncludeStack.back ()-> back ();
821+ auto &IfdefOrElseEntry = PrepIncludeStack.back (). back ();
829822
830823 if (IfdefOrElseEntry.Kind != tgtok::Ifdef &&
831824 IfdefOrElseEntry.Kind != tgtok::Else) {
@@ -836,7 +829,7 @@ tgtok::TokKind TGLexer::lexPreprocessor(tgtok::TokKind Kind,
836829 if (!prepSkipDirectiveEnd ())
837830 return ReturnError (CurPtr, " only comments are supported after #endif" );
838831
839- PrepIncludeStack.back ()-> pop_back ();
832+ PrepIncludeStack.back (). pop_back ();
840833
841834 // If we were processing tokens before this #endif, then
842835 // we should continue it.
@@ -1055,20 +1048,16 @@ bool TGLexer::prepSkipDirectiveEnd() {
10551048}
10561049
10571050bool 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 ; });
10641053}
10651054
10661055void TGLexer::prepReportPreprocessorStackError () {
1067- if (PrepIncludeStack.back ()-> empty ())
1056+ if (PrepIncludeStack.back (). empty ())
10681057 PrintFatalError (" prepReportPreprocessorStackError() called with "
10691058 " empty control stack" );
10701059
1071- auto &PrepControl = PrepIncludeStack.back ()-> back ();
1060+ auto &PrepControl = PrepIncludeStack.back (). back ();
10721061 PrintError (CurBuf.end (), " reached EOF without matching #endif" );
10731062 PrintError (PrepControl.SrcPos , " the latest preprocessor control is here" );
10741063
0 commit comments