@@ -761,19 +761,10 @@ bool Preprocessor::hasErrors(const simplecpp::Output &output)
761761 return false ;
762762}
763763
764- bool Preprocessor::handleErrors (const simplecpp::OutputList& outputList, bool throwError )
764+ const simplecpp::Output* Preprocessor::handleErrors (const simplecpp::OutputList& outputList)
765765{
766766 const bool showerror = (!mSettings .userDefines .empty () && !mSettings .force );
767- const bool hasError = reportOutput (outputList, showerror);
768- if (throwError) {
769- const auto it = std::find_if (outputList.cbegin (), outputList.cend (), [](const simplecpp::Output &output){
770- return hasErrors (output);
771- });
772- if (it != outputList.cend ()) {
773- throw *it;
774- }
775- }
776- return hasError;
767+ return reportOutput (outputList, showerror);
777768}
778769
779770bool Preprocessor::loadFiles (std::vector<std::string> &files)
@@ -782,7 +773,7 @@ bool Preprocessor::loadFiles(std::vector<std::string> &files)
782773
783774 simplecpp::OutputList outputList;
784775 mFileCache = simplecpp::load (mTokens , files, dui, &outputList);
785- return !handleErrors (outputList, false );
776+ return !handleErrors (outputList);
786777}
787778
788779void Preprocessor::removeComments ()
@@ -813,28 +804,27 @@ void Preprocessor::setPlatformInfo()
813804 mTokens .sizeOfType [" long double *" ] = mSettings .platform .sizeof_pointer ;
814805}
815806
816- simplecpp::TokenList Preprocessor::preprocess (const std::string &cfg, std::vector<std::string> &files, bool throwError )
807+ simplecpp::TokenList Preprocessor::preprocess (const std::string &cfg, std::vector<std::string> &files, simplecpp::OutputList& outputList )
817808{
818809 const simplecpp::DUI dui = createDUI (mSettings , cfg, mLang );
819810
820- simplecpp::OutputList outputList;
821811 std::list<simplecpp::MacroUsage> macroUsage;
822812 std::list<simplecpp::IfCond> ifCond;
823813 simplecpp::TokenList tokens2 (files);
824814 simplecpp::preprocess (tokens2, mTokens , files, mFileCache , dui, &outputList, ¯oUsage, &ifCond);
825815 mMacroUsage = std::move (macroUsage);
826816 mIfCond = std::move (ifCond);
827817
828- (void )handleErrors (outputList, throwError);
829-
830818 tokens2.removeComments ();
831819
832820 return tokens2;
833821}
834822
835823std::string Preprocessor::getcode (const std::string &cfg, std::vector<std::string> &files, const bool writeLocations)
836824{
837- simplecpp::TokenList tokens2 = preprocess (cfg, files, false );
825+ simplecpp::OutputList outputList;
826+ simplecpp::TokenList tokens2 = preprocess (cfg, files, outputList);
827+ handleErrors (outputList);
838828 unsigned int prevfile = 0 ;
839829 unsigned int line = 1 ;
840830 std::ostringstream ret;
@@ -859,14 +849,14 @@ std::string Preprocessor::getcode(const std::string &cfg, std::vector<std::strin
859849 return ret.str ();
860850}
861851
862- bool Preprocessor::reportOutput (const simplecpp::OutputList &outputList, bool showerror)
852+ const simplecpp::Output* Preprocessor::reportOutput (const simplecpp::OutputList &outputList, bool showerror)
863853{
864- bool hasError = false ;
854+ const simplecpp::Output* out_ret = nullptr ;
865855
866856 for (const simplecpp::Output &out : outputList) {
867857 switch (out.type ) {
868858 case simplecpp::Output::ERROR:
869- hasError = true ;
859+ out_ret = &out ;
870860 if (!startsWith (out.msg ," #error" ) || showerror)
871861 error (out.location .file (), out.location .line , out.location .col , out.msg , out.type );
872862 break ;
@@ -884,19 +874,19 @@ bool Preprocessor::reportOutput(const simplecpp::OutputList &outputList, bool sh
884874 case simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY:
885875 case simplecpp::Output::SYNTAX_ERROR:
886876 case simplecpp::Output::UNHANDLED_CHAR_ERROR:
887- hasError = true ;
877+ out_ret = &out ;
888878 error (out.location .file (), out.location .line , out.location .col , out.msg , out.type );
889879 break ;
890880 case simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND:
891881 case simplecpp::Output::FILE_NOT_FOUND:
892882 case simplecpp::Output::DUI_ERROR:
893- hasError = true ;
883+ out_ret = &out ;
894884 error (" " , 0 , 0 , out.msg , out.type );
895885 break ;
896886 }
897887 }
898888
899- return hasError ;
889+ return out_ret ;
900890}
901891
902892static std::string simplecppErrToId (simplecpp::Output::Type type)
0 commit comments