@@ -326,7 +326,7 @@ void Preprocessor::inlineSuppressions(SuppressionList &suppressions)
326326 ::addInlineSuppressions (filedata->tokens, mSettings , suppressions, err);
327327 }
328328 for (const BadInlineSuppression &bad : err) {
329- error (bad.location , bad.errmsg , simplecpp::Output::ERROR);
329+ error (mSettings , mErrorLogger , bad.location , bad.errmsg , simplecpp::Output::ERROR);
330330 }
331331}
332332
@@ -770,7 +770,7 @@ bool Preprocessor::hasErrors(const simplecpp::Output &output)
770770bool Preprocessor::handleErrors (const simplecpp::OutputList& outputList, bool throwError)
771771{
772772 const bool showerror = (!mSettings .userDefines .empty () && !mSettings .force );
773- const bool hasError = reportOutput (outputList, showerror);
773+ const bool hasError = reportOutput (mSettings , mErrorLogger , outputList, showerror);
774774 if (throwError) {
775775 const auto it = std::find_if (outputList.cbegin (), outputList.cend (), [](const simplecpp::Output &output){
776776 return hasErrors (output);
@@ -865,7 +865,7 @@ std::string Preprocessor::getcode(const std::string &cfg, std::vector<std::strin
865865 return ret.str ();
866866}
867867
868- bool Preprocessor::reportOutput (const simplecpp::OutputList &outputList, bool showerror)
868+ bool Preprocessor::reportOutput (const Settings& settings, ErrorLogger& errorLogger, const simplecpp::OutputList &outputList, bool showerror)
869869{
870870 bool hasError = false ;
871871
@@ -874,7 +874,7 @@ bool Preprocessor::reportOutput(const simplecpp::OutputList &outputList, bool sh
874874 case simplecpp::Output::ERROR:
875875 hasError = true ;
876876 if (!startsWith (out.msg ," #error" ) || showerror)
877- error (out.location , out.msg , out.type );
877+ error (settings, errorLogger, out.location , out.msg , out.type );
878878 break ;
879879 case simplecpp::Output::WARNING:
880880 case simplecpp::Output::PORTABILITY_BACKSLASH:
@@ -883,22 +883,22 @@ bool Preprocessor::reportOutput(const simplecpp::OutputList &outputList, bool sh
883883 const std::string::size_type pos1 = out.msg .find_first_of (" <\" " );
884884 const std::string::size_type pos2 = out.msg .find_first_of (" >\" " , pos1 + 1U );
885885 if (pos1 < pos2 && pos2 != std::string::npos)
886- missingInclude (out.location , out.msg .substr (pos1+1 , pos2-pos1-1 ), out.msg [pos1] == ' \" ' ? UserHeader : SystemHeader);
886+ missingInclude (settings, errorLogger, out.location , out.msg .substr (pos1+1 , pos2-pos1-1 ), out.msg [pos1] == ' \" ' ? UserHeader : SystemHeader);
887887 }
888888 break ;
889889 case simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY:
890890 case simplecpp::Output::SYNTAX_ERROR:
891891 case simplecpp::Output::UNHANDLED_CHAR_ERROR:
892892 hasError = true ;
893- error (out.location , out.msg , out.type );
893+ error (settings, errorLogger, out.location , out.msg , out.type );
894894 break ;
895895 case simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND:
896896 case simplecpp::Output::FILE_NOT_FOUND:
897897 case simplecpp::Output::DUI_ERROR:
898898 hasError = true ;
899899 std::vector<std::string> f;
900900 simplecpp::Location loc (f);
901- error (loc, out.msg , out.type );
901+ error (settings, errorLogger, loc, out.msg , out.type );
902902 break ;
903903 }
904904 }
@@ -929,55 +929,53 @@ static std::string simplecppErrToId(simplecpp::Output::Type type)
929929 }
930930}
931931
932- void Preprocessor::error (const simplecpp::Location& loc, const std::string &msg, simplecpp::Output::Type type)
932+ void Preprocessor::error (const Settings& settings, ErrorLogger& errorLogger, const simplecpp::Location& loc, const std::string &msg, simplecpp::Output::Type type)
933933{
934934 std::list<ErrorMessage::FileLocation> locationList;
935935 if (!loc.file ().empty ()) {
936936 std::string file = Path::fromNativeSeparators (loc.file ());
937- if (mSettings .relativePaths )
938- file = Path::getRelativePath (file, mSettings .basePaths );
937+ if (settings .relativePaths )
938+ file = Path::getRelativePath (file, settings .basePaths );
939939
940940 locationList.emplace_back (file, loc.line , loc.col );
941941 }
942- mErrorLogger .reportErr (ErrorMessage (std::move (locationList),
943- mFile0 ,
944- Severity::error,
945- msg,
946- simplecppErrToId (type),
947- Certainty::normal));
942+ errorLogger .reportErr (ErrorMessage (std::move (locationList),
943+ " " ,
944+ Severity::error,
945+ msg,
946+ simplecppErrToId (type),
947+ Certainty::normal));
948948}
949949
950950// Report that include is missing
951- void Preprocessor::missingInclude (const simplecpp::Location& loc, const std::string &header, HeaderTypes headerType)
951+ void Preprocessor::missingInclude (const Settings& settings, ErrorLogger& errorLogger, const simplecpp::Location& loc, const std::string &header, HeaderTypes headerType)
952952{
953- if (!mSettings .checks .isEnabled (Checks::missingInclude))
953+ if (!settings .checks .isEnabled (Checks::missingInclude))
954954 return ;
955955
956956 std::list<ErrorMessage::FileLocation> locationList;
957957 if (!loc.file ().empty ()) {
958958 locationList.emplace_back (loc.file (), loc.line , loc.col );
959959 }
960- ErrorMessage errmsg (std::move (locationList), mFile0 , Severity::information,
960+ ErrorMessage errmsg (std::move (locationList), " " , Severity::information,
961961 (headerType==SystemHeader) ?
962962 " Include file: <" + header + " > not found. Please note: Cppcheck does not need standard library headers to get proper results." :
963963 " Include file: \" " + header + " \" not found." ,
964964 (headerType==SystemHeader) ? " missingIncludeSystem" : " missingInclude" ,
965965 Certainty::normal);
966- mErrorLogger .reportErr (errmsg);
966+ errorLogger .reportErr (errmsg);
967967}
968968
969969void Preprocessor::getErrorMessages (ErrorLogger &errorLogger, const Settings &settings)
970970{
971971 std::vector<std::string> files;
972- simplecpp::TokenList tokens (files);
973- Preprocessor preprocessor (tokens, settings, errorLogger, Standards::Language::CPP);
974972 simplecpp::Location loc (files);
975- preprocessor. missingInclude (loc, " " , UserHeader);
976- preprocessor. missingInclude (loc, " " , SystemHeader);
977- preprocessor. error (loc, " message" , simplecpp::Output::ERROR);
978- preprocessor. error (loc, " message" , simplecpp::Output::SYNTAX_ERROR);
979- preprocessor. error (loc, " message" , simplecpp::Output::UNHANDLED_CHAR_ERROR);
980- preprocessor. error (loc, " message" , simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY);
973+ missingInclude (settings, errorLogger, loc, " " , UserHeader);
974+ missingInclude (settings, errorLogger, loc, " " , SystemHeader);
975+ error (settings, errorLogger, loc, " message" , simplecpp::Output::ERROR);
976+ error (settings, errorLogger, loc, " message" , simplecpp::Output::SYNTAX_ERROR);
977+ error (settings, errorLogger, loc, " message" , simplecpp::Output::UNHANDLED_CHAR_ERROR);
978+ error (settings, errorLogger, loc, " message" , simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY);
981979}
982980
983981void Preprocessor::dump (std::ostream &out) const
0 commit comments