@@ -312,7 +312,7 @@ void Preprocessor::inlineSuppressions(SuppressionList &suppressions)
312312 ::addInlineSuppressions (filedata->tokens, mSettings , suppressions, err);
313313 }
314314 for (const BadInlineSuppression &bad : err) {
315- error (bad.file , bad.line , bad.errmsg );
315+ error (bad.file , bad.line , bad.errmsg , simplecpp::Output::ERROR); // TODO: use individual (non-fatal) ID
316316 }
317317}
318318
@@ -860,7 +860,7 @@ bool Preprocessor::reportOutput(const simplecpp::OutputList &outputList, bool sh
860860 case simplecpp::Output::ERROR:
861861 hasError = true ;
862862 if (!startsWith (out.msg ," #error" ) || showerror)
863- error (out.location .file (), out.location .line , out.msg );
863+ error (out.location .file (), out.location .line , out.msg , out. type );
864864 break ;
865865 case simplecpp::Output::WARNING:
866866 case simplecpp::Output::PORTABILITY_BACKSLASH:
@@ -877,35 +877,59 @@ bool Preprocessor::reportOutput(const simplecpp::OutputList &outputList, bool sh
877877 case simplecpp::Output::SYNTAX_ERROR:
878878 case simplecpp::Output::UNHANDLED_CHAR_ERROR:
879879 hasError = true ;
880- error (out.location .file (), out.location .line , out.msg );
880+ error (out.location .file (), out.location .line , out.msg , out. type );
881881 break ;
882882 case simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND:
883883 case simplecpp::Output::FILE_NOT_FOUND:
884884 case simplecpp::Output::DUI_ERROR:
885885 hasError = true ;
886- error (" " , 0 , out.msg );
886+ error (" " , 0 , out.msg , out. type );
887887 break ;
888888 }
889889 }
890890
891891 return hasError;
892892}
893893
894- void Preprocessor::error (const std::string &filename, unsigned int linenr, const std::string &msg)
894+ static std::string simplecppErrToId (simplecpp::Output::Type type)
895+ {
896+ switch (type) {
897+ case simplecpp::Output::ERROR:
898+ return " preprocessorErrorDirective" ;
899+ case simplecpp::Output::SYNTAX_ERROR:
900+ return " syntaxError" ;
901+ case simplecpp::Output::UNHANDLED_CHAR_ERROR:
902+ return " unhandledChar" ;
903+ case simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY:
904+ return " includeNestedTooDeeply" ;
905+ // should never occur
906+ case simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND:
907+ case simplecpp::Output::FILE_NOT_FOUND:
908+ case simplecpp::Output::DUI_ERROR:
909+ // handled separately
910+ case simplecpp::Output::MISSING_HEADER:
911+ // no handled at all (warnings)
912+ case simplecpp::Output::WARNING:
913+ case simplecpp::Output::PORTABILITY_BACKSLASH:
914+ throw std::runtime_error (" unexpected simplecpp::Output type" );
915+ }
916+ }
917+
918+ void Preprocessor::error (const std::string &filename, unsigned int linenr, const std::string &msg, simplecpp::Output::Type type)
895919{
896920 std::list<ErrorMessage::FileLocation> locationList;
897921 if (!filename.empty ()) {
898922 std::string file = Path::fromNativeSeparators (filename);
899923 if (mSettings .relativePaths )
900924 file = Path::getRelativePath (file, mSettings .basePaths );
901925
902- locationList.emplace_back (file, linenr, 0 );
926+ locationList.emplace_back (file, linenr, 0 ); // TODO: set column
903927 }
904928 mErrorLogger .reportErr (ErrorMessage (std::move (locationList),
905929 mFile0 ,
906930 Severity::error,
907931 msg,
908- " preprocessorErrorDirective " ,
932+ simplecppErrToId (type) ,
909933 Certainty::normal));
910934}
911935
@@ -935,7 +959,10 @@ void Preprocessor::getErrorMessages(ErrorLogger &errorLogger, const Settings &se
935959 Preprocessor preprocessor (tokens, settings, errorLogger, Standards::Language::CPP);
936960 preprocessor.missingInclude (" " , 1 , 2 , " " , UserHeader);
937961 preprocessor.missingInclude (" " , 1 , 2 , " " , SystemHeader);
938- preprocessor.error (" " , 1 , " #error message" ); // #error ..
962+ preprocessor.error (" " , 1 , " message" , simplecpp::Output::ERROR);
963+ preprocessor.error (" " , 1 , " message" , simplecpp::Output::SYNTAX_ERROR);
964+ preprocessor.error (" " , 1 , " message" , simplecpp::Output::UNHANDLED_CHAR_ERROR);
965+ preprocessor.error (" " , 1 , " message" , simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY);
939966}
940967
941968void Preprocessor::dump (std::ostream &out) const
0 commit comments