@@ -105,8 +105,11 @@ static bool parseInlineSuppressionCommentToken(const simplecpp::Token *tok, std:
105105
106106 // determine prefix if specified
107107 if (posEndComment >= (pos1 + cppchecksuppress.size () + 1 )) {
108- if (comment.at (pos1 + cppchecksuppress.size ()) != ' -' )
108+ const std::string suppressCmdString = comment.substr (pos1, pos2-pos1-1 );
109+ if (comment.at (pos1 + cppchecksuppress.size ()) != ' -' ) {
110+ bad.emplace_back (tok->location .file (), tok->location .line , 0 , " unknown suppression type '" + suppressCmdString + " '" ); // TODO: set column
109111 return false ;
112+ }
110113
111114 const unsigned int argumentLength =
112115 posEndComment - (pos1 + cppchecksuppress.size () + 1 );
@@ -122,8 +125,10 @@ static bool parseInlineSuppressionCommentToken(const simplecpp::Token *tok, std:
122125 errorType = SuppressionList::Type::blockEnd;
123126 else if (" macro" == suppressTypeString)
124127 errorType = SuppressionList::Type::macro;
125- else
128+ else {
129+ bad.emplace_back (tok->location .file (), tok->location .line , 0 , " unknown suppression type '" + suppressCmdString + " '" ); // TODO: set column
126130 return false ;
131+ }
127132 }
128133
129134 if (comment[pos2] == ' [' ) {
@@ -742,38 +747,10 @@ static simplecpp::DUI createDUI(const Settings &mSettings, const std::string &cf
742747 return dui;
743748}
744749
745- bool Preprocessor::hasErrors (const simplecpp::Output &output)
746- {
747- switch (output.type ) {
748- case simplecpp::Output::ERROR:
749- case simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY:
750- case simplecpp::Output::SYNTAX_ERROR:
751- case simplecpp::Output::UNHANDLED_CHAR_ERROR:
752- case simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND:
753- case simplecpp::Output::FILE_NOT_FOUND:
754- case simplecpp::Output::DUI_ERROR:
755- return true ;
756- case simplecpp::Output::WARNING:
757- case simplecpp::Output::MISSING_HEADER:
758- case simplecpp::Output::PORTABILITY_BACKSLASH:
759- break ;
760- }
761- return false ;
762- }
763-
764- bool Preprocessor::handleErrors (const simplecpp::OutputList& outputList, bool throwError)
750+ const simplecpp::Output* Preprocessor::handleErrors (const simplecpp::OutputList& outputList)
765751{
766752 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;
753+ return reportOutput (outputList, showerror);
777754}
778755
779756bool Preprocessor::loadFiles (std::vector<std::string> &files)
@@ -782,7 +759,7 @@ bool Preprocessor::loadFiles(std::vector<std::string> &files)
782759
783760 simplecpp::OutputList outputList;
784761 mFileCache = simplecpp::load (mTokens , files, dui, &outputList);
785- return !handleErrors (outputList, false );
762+ return !handleErrors (outputList);
786763}
787764
788765void Preprocessor::removeComments ()
@@ -813,28 +790,27 @@ void Preprocessor::setPlatformInfo()
813790 mTokens .sizeOfType [" long double *" ] = mSettings .platform .sizeof_pointer ;
814791}
815792
816- simplecpp::TokenList Preprocessor::preprocess (const std::string &cfg, std::vector<std::string> &files, bool throwError )
793+ simplecpp::TokenList Preprocessor::preprocess (const std::string &cfg, std::vector<std::string> &files, simplecpp::OutputList& outputList )
817794{
818795 const simplecpp::DUI dui = createDUI (mSettings , cfg, mLang );
819796
820- simplecpp::OutputList outputList;
821797 std::list<simplecpp::MacroUsage> macroUsage;
822798 std::list<simplecpp::IfCond> ifCond;
823799 simplecpp::TokenList tokens2 (files);
824800 simplecpp::preprocess (tokens2, mTokens , files, mFileCache , dui, &outputList, ¯oUsage, &ifCond);
825801 mMacroUsage = std::move (macroUsage);
826802 mIfCond = std::move (ifCond);
827803
828- (void )handleErrors (outputList, throwError);
829-
830804 tokens2.removeComments ();
831805
832806 return tokens2;
833807}
834808
835809std::string Preprocessor::getcode (const std::string &cfg, std::vector<std::string> &files, const bool writeLocations)
836810{
837- simplecpp::TokenList tokens2 = preprocess (cfg, files, false );
811+ simplecpp::OutputList outputList;
812+ simplecpp::TokenList tokens2 = preprocess (cfg, files, outputList);
813+ handleErrors (outputList);
838814 unsigned int prevfile = 0 ;
839815 unsigned int line = 1 ;
840816 std::ostringstream ret;
@@ -859,14 +835,14 @@ std::string Preprocessor::getcode(const std::string &cfg, std::vector<std::strin
859835 return ret.str ();
860836}
861837
862- bool Preprocessor::reportOutput (const simplecpp::OutputList &outputList, bool showerror)
838+ const simplecpp::Output* Preprocessor::reportOutput (const simplecpp::OutputList &outputList, bool showerror)
863839{
864- bool hasError = false ;
840+ const simplecpp::Output* out_ret = nullptr ;
865841
866842 for (const simplecpp::Output &out : outputList) {
867843 switch (out.type ) {
868844 case simplecpp::Output::ERROR:
869- hasError = true ;
845+ out_ret = &out ;
870846 if (!startsWith (out.msg ," #error" ) || showerror)
871847 error (out.location .file (), out.location .line , out.location .col , out.msg , out.type );
872848 break ;
@@ -884,19 +860,19 @@ bool Preprocessor::reportOutput(const simplecpp::OutputList &outputList, bool sh
884860 case simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY:
885861 case simplecpp::Output::SYNTAX_ERROR:
886862 case simplecpp::Output::UNHANDLED_CHAR_ERROR:
887- hasError = true ;
863+ out_ret = &out ;
888864 error (out.location .file (), out.location .line , out.location .col , out.msg , out.type );
889865 break ;
890866 case simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND:
891867 case simplecpp::Output::FILE_NOT_FOUND:
892868 case simplecpp::Output::DUI_ERROR:
893- hasError = true ;
869+ out_ret = &out ;
894870 error (" " , 0 , 0 , out.msg , out.type );
895871 break ;
896872 }
897873 }
898874
899- return hasError ;
875+ return out_ret ;
900876}
901877
902878static std::string simplecppErrToId (simplecpp::Output::Type type)
0 commit comments