@@ -422,7 +422,7 @@ class FileStream : public simplecpp::TokenList::Stream {
422422 {
423423 if (!file) {
424424 files.push_back (filename);
425- throw simplecpp::Output (files, simplecpp::Output::FILE_NOT_FOUND, " File is missing: " + filename);
425+ throw simplecpp::Output (simplecpp::Output::FILE_NOT_FOUND, simplecpp::Location (files) , " File is missing: " + filename);
426426 }
427427 init ();
428428 }
@@ -615,14 +615,15 @@ static std::string escapeString(const std::string &str)
615615 return ostr.str ();
616616}
617617
618- static void portabilityBackslash (simplecpp::OutputList *outputList, const std::vector<std::string> &files, const simplecpp::Location &location)
618+ static void portabilityBackslash (simplecpp::OutputList *outputList, const simplecpp::Location &location)
619619{
620620 if (!outputList)
621621 return ;
622- simplecpp::Output err (files);
623- err.type = simplecpp::Output::PORTABILITY_BACKSLASH;
624- err.location = location;
625- err.msg = " Combination 'backslash space newline' is not portable." ;
622+ simplecpp::Output err = {
623+ simplecpp::Output::PORTABILITY_BACKSLASH,
624+ location,
625+ " Combination 'backslash space newline' is not portable."
626+ };
626627 outputList->push_back (std::move (err));
627628}
628629
@@ -670,13 +671,12 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
670671
671672 if (ch >= 0x80 ) {
672673 if (outputList) {
673- simplecpp::Output err (files);
674- err.type = simplecpp::Output::UNHANDLED_CHAR_ERROR;
675- err.location = location;
676- std::ostringstream s;
677- s << static_cast <int >(ch);
678- err.msg = " The code contains unhandled character(s) (character code=" + s.str () + " ). Neither unicode nor extended ascii is supported." ;
679- outputList->push_back (err);
674+ simplecpp::Output err = {
675+ simplecpp::Output::UNHANDLED_CHAR_ERROR,
676+ location,
677+ " The code contains unhandled character(s) (character code=" + std::to_string (static_cast <int >(ch)) + " ). Neither unicode nor extended ascii is supported."
678+ };
679+ outputList->push_back (std::move (err));
680680 }
681681 clear ();
682682 return ;
@@ -685,7 +685,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
685685 if (ch == ' \n ' ) {
686686 if (cback () && cback ()->op == ' \\ ' ) {
687687 if (location.col > cback ()->location .col + 1U )
688- portabilityBackslash (outputList, files, cback ()->location );
688+ portabilityBackslash (outputList, cback ()->location );
689689 ++multiline;
690690 deleteToken (back ());
691691 } else {
@@ -790,7 +790,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
790790 const TokenString check_portability = currentToken + tmp;
791791 const std::string::size_type pos = check_portability.find_last_not_of (" \t " );
792792 if (pos < check_portability.size () - 1U && check_portability[pos] == ' \\ ' )
793- portabilityBackslash (outputList, files, location);
793+ portabilityBackslash (outputList, location);
794794 ++multiline;
795795 tmp_ch = stream.readChar ();
796796 currentToken += ' \n ' ;
@@ -850,11 +850,12 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
850850 }
851851 if (!stream.good () || ch == ' \n ' ) {
852852 if (outputList) {
853- Output err (files);
854- err.type = Output::SYNTAX_ERROR;
855- err.location = location;
856- err.msg = " Invalid newline in raw string delimiter." ;
857- outputList->push_back (err);
853+ Output err = {
854+ Output::SYNTAX_ERROR,
855+ location,
856+ " Invalid newline in raw string delimiter."
857+ };
858+ outputList->push_back (std::move (err));
858859 }
859860 return ;
860861 }
@@ -863,10 +864,11 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
863864 currentToken += stream.readChar ();
864865 if (!endsWith (currentToken, endOfRawString)) {
865866 if (outputList) {
866- Output err (files);
867- err.type = Output::SYNTAX_ERROR;
868- err.location = location;
869- err.msg = " Raw string missing terminating delimiter." ;
867+ Output err = {
868+ Output::SYNTAX_ERROR,
869+ location,
870+ " Raw string missing terminating delimiter."
871+ };
870872 outputList->push_back (std::move (err));
871873 }
872874 return ;
@@ -1406,10 +1408,11 @@ std::string simplecpp::TokenList::readUntil(Stream &stream, const Location &loca
14061408 if (!stream.good () || ch != end) {
14071409 clear ();
14081410 if (outputList) {
1409- Output err (files);
1410- err.type = Output::SYNTAX_ERROR;
1411- err.location = location;
1412- err.msg = std::string (" No pair for character (" ) + start + " ). Can't process file. File is either invalid or unicode, which is currently not supported." ;
1411+ Output err = {
1412+ Output::SYNTAX_ERROR,
1413+ location,
1414+ std::string (" No pair for character (" ) + start + " ). Can't process file. File is either invalid or unicode, which is currently not supported."
1415+ };
14131416 outputList->push_back (std::move (err));
14141417 }
14151418 return " " ;
@@ -3164,10 +3167,11 @@ simplecpp::FileDataCache simplecpp::load(const simplecpp::TokenList &rawtokens,
31643167
31653168 if (filedata == nullptr ) {
31663169 if (outputList) {
3167- simplecpp::Output err (filenames);
3168- err.type = simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND;
3169- err.location = Location (filenames);
3170- err.msg = " Can not open include file '" + filename + " ' that is explicitly included." ;
3170+ simplecpp::Output err = {
3171+ simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND,
3172+ Location (filenames),
3173+ " Can not open include file '" + filename + " ' that is explicitly included."
3174+ };
31713175 outputList->push_back (std::move (err));
31723176 }
31733177 continue ;
@@ -3235,12 +3239,13 @@ static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token
32353239 simplecpp::TokenList value (files);
32363240 try {
32373241 *tok1 = it->second .expand (value, tok, macros, files);
3238- } catch (simplecpp::Macro::Error &err) {
3242+ } catch (const simplecpp::Macro::Error &err) {
32393243 if (outputList) {
3240- simplecpp::Output out (files);
3241- out.type = simplecpp::Output::SYNTAX_ERROR;
3242- out.location = err.location ;
3243- out.msg = " failed to expand \' " + tok->str () + " \' , " + err.what ;
3244+ simplecpp::Output out = {
3245+ simplecpp::Output::SYNTAX_ERROR,
3246+ err.location ,
3247+ " failed to expand \' " + tok->str () + " \' , " + err.what
3248+ };
32443249 outputList->push_back (std::move (out));
32453250 }
32463251 return false ;
@@ -3352,10 +3357,12 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
33523357 const cppstd_t cpp_std = simplecpp::getCppStd (dui.std );
33533358 if (cpp_std == CPPUnknown) {
33543359 if (outputList) {
3355- simplecpp::Output err (files);
3356- err.type = Output::DUI_ERROR;
3357- err.msg = " unknown standard specified: '" + dui.std + " '" ;
3358- outputList->push_back (err);
3360+ simplecpp::Output err = {
3361+ Output::DUI_ERROR,
3362+ Location (files),
3363+ " unknown standard specified: '" + dui.std + " '"
3364+ };
3365+ outputList->push_back (std::move (err));
33593366 }
33603367 output.clear ();
33613368 return ;
@@ -3407,27 +3414,32 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
34073414
34083415 if (ifstates.size () <= 1U && (rawtok->str () == ELIF || rawtok->str () == ELSE || rawtok->str () == ENDIF)) {
34093416 if (outputList) {
3410- simplecpp::Output err (files);
3411- err.type = Output::SYNTAX_ERROR;
3412- err.location = rawtok->location ;
3413- err.msg = " #" + rawtok->str () + " without #if" ;
3414- outputList->push_back (err);
3417+ simplecpp::Output err = {
3418+ Output::SYNTAX_ERROR,
3419+ rawtok->location ,
3420+ " #" + rawtok->str () + " without #if"
3421+ };
3422+ outputList->push_back (std::move (err));
34153423 }
34163424 output.clear ();
34173425 return ;
34183426 }
34193427
34203428 if (ifstates.top () == True && (rawtok->str () == ERROR || rawtok->str () == WARNING)) {
34213429 if (outputList) {
3422- simplecpp::Output err (rawtok->location .files );
3423- err.type = rawtok->str () == ERROR ? Output::ERROR : Output::WARNING;
3424- err.location = rawtok->location ;
3430+ std::string msg;
34253431 for (const Token *tok = rawtok->next ; tok && sameline (rawtok,tok); tok = tok->next ) {
3426- if (!err. msg .empty () && isNameChar (tok->str ()[0 ]))
3427- err. msg += ' ' ;
3428- err. msg += tok->str ();
3432+ if (!msg.empty () && isNameChar (tok->str ()[0 ]))
3433+ msg += ' ' ;
3434+ msg += tok->str ();
34293435 }
3430- err.msg = ' #' + rawtok->str () + ' ' + err.msg ;
3436+ msg = ' #' + rawtok->str () + ' ' + msg;
3437+ simplecpp::Output err = {
3438+ rawtok->str () == ERROR ? Output::ERROR : Output::WARNING,
3439+ rawtok->location ,
3440+ std::move (msg)
3441+ };
3442+
34313443 outputList->push_back (std::move (err));
34323444 }
34333445 if (rawtok->str () == ERROR) {
@@ -3450,21 +3462,23 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
34503462 }
34513463 } catch (const std::runtime_error &) {
34523464 if (outputList) {
3453- simplecpp::Output err (files);
3454- err.type = Output::SYNTAX_ERROR;
3455- err.location = rawtok->location ;
3456- err.msg = " Failed to parse #define" ;
3457- outputList->push_back (err);
3465+ simplecpp::Output err = {
3466+ Output::SYNTAX_ERROR,
3467+ rawtok->location ,
3468+ " Failed to parse #define"
3469+ };
3470+ outputList->push_back (std::move (err));
34583471 }
34593472 output.clear ();
34603473 return ;
3461- } catch (simplecpp::Macro::Error &err) {
3474+ } catch (const simplecpp::Macro::Error &err) {
34623475 if (outputList) {
3463- simplecpp::Output out (files);
3464- out.type = simplecpp::Output::SYNTAX_ERROR;
3465- out.location = err.location ;
3466- out.msg = " Failed to parse #define, " + err.what ;
3467- outputList->push_back (out);
3476+ simplecpp::Output out = {
3477+ simplecpp::Output::SYNTAX_ERROR,
3478+ err.location ,
3479+ " Failed to parse #define, " + err.what
3480+ };
3481+ outputList->push_back (std::move (out));
34683482 }
34693483 output.clear ();
34703484 return ;
@@ -3500,11 +3514,12 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
35003514
35013515 if (inc2.empty () || inc2.cfront ()->str ().size () <= 2U ) {
35023516 if (outputList) {
3503- simplecpp::Output err (files);
3504- err.type = Output::SYNTAX_ERROR;
3505- err.location = rawtok->location ;
3506- err.msg = " No header in #include" ;
3507- outputList->push_back (err);
3517+ simplecpp::Output err = {
3518+ Output::SYNTAX_ERROR,
3519+ rawtok->location ,
3520+ " No header in #include"
3521+ };
3522+ outputList->push_back (std::move (err));
35083523 }
35093524 output.clear ();
35103525 return ;
@@ -3517,19 +3532,21 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
35173532 const FileData *const filedata = cache.get (rawtok->location .file (), header, dui, systemheader, files, outputList).first ;
35183533 if (filedata == nullptr ) {
35193534 if (outputList) {
3520- simplecpp::Output out (files);
3521- out.type = Output::MISSING_HEADER;
3522- out.location = rawtok->location ;
3523- out.msg = " Header not found: " + inctok->str ();
3524- outputList->push_back (out);
3535+ simplecpp::Output out = {
3536+ simplecpp::Output::MISSING_HEADER,
3537+ rawtok->location ,
3538+ " Header not found: " + inctok->str ()
3539+ };
3540+ outputList->push_back (std::move (out));
35253541 }
35263542 } else if (includetokenstack.size () >= 400 ) {
35273543 if (outputList) {
3528- simplecpp::Output out (files);
3529- out.type = Output::INCLUDE_NESTED_TOO_DEEPLY;
3530- out.location = rawtok->location ;
3531- out.msg = " #include nested too deeply" ;
3532- outputList->push_back (out);
3544+ simplecpp::Output out = {
3545+ simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY,
3546+ rawtok->location ,
3547+ " #include nested too deeply"
3548+ };
3549+ outputList->push_back (std::move (out));
35333550 }
35343551 } else if (pragmaOnce.find (filedata->filename ) == pragmaOnce.end ()) {
35353552 includetokenstack.push (gotoNextLine (rawtok));
@@ -3539,11 +3556,12 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
35393556 } else if (rawtok->str () == IF || rawtok->str () == IFDEF || rawtok->str () == IFNDEF || rawtok->str () == ELIF) {
35403557 if (!sameline (rawtok,rawtok->next )) {
35413558 if (outputList) {
3542- simplecpp::Output out (files);
3543- out.type = Output::SYNTAX_ERROR;
3544- out.location = rawtok->location ;
3545- out.msg = " Syntax error in #" + rawtok->str ();
3546- outputList->push_back (out);
3559+ simplecpp::Output out = {
3560+ simplecpp::Output::SYNTAX_ERROR,
3561+ rawtok->location ,
3562+ " Syntax error in #" + rawtok->str ()
3563+ };
3564+ outputList->push_back (std::move (out));
35473565 }
35483566 output.clear ();
35493567 return ;
@@ -3584,10 +3602,11 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
35843602 tok = tok ? tok->next : nullptr ;
35853603 if (!tok || !sameline (rawtok,tok) || (par && tok->op != ' )' )) {
35863604 if (outputList) {
3587- Output out (rawtok->location .files );
3588- out.type = Output::SYNTAX_ERROR;
3589- out.location = rawtok->location ;
3590- out.msg = " failed to evaluate " + std::string (rawtok->str () == IF ? " #if" : " #elif" ) + " condition" ;
3605+ Output out = {
3606+ Output::SYNTAX_ERROR,
3607+ rawtok->location ,
3608+ " failed to evaluate " + std::string (rawtok->str () == IF ? " #if" : " #elif" ) + " condition"
3609+ };
35913610 outputList->push_back (std::move (out));
35923611 }
35933612 output.clear ();
@@ -3626,11 +3645,12 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
36263645 tok = tok ? tok->next : nullptr ;
36273646 if (!tok || !sameline (rawtok,tok) || (par && tok->op != ' )' ) || (!closingAngularBracket)) {
36283647 if (outputList) {
3629- Output out (rawtok->location .files );
3630- out.type = Output::SYNTAX_ERROR;
3631- out.location = rawtok->location ;
3632- out.msg = " failed to evaluate " + std::string (rawtok->str () == IF ? " #if" : " #elif" ) + " condition" ;
3633- outputList->push_back (out);
3648+ Output out = {
3649+ Output::SYNTAX_ERROR,
3650+ rawtok->location ,
3651+ " failed to evaluate " + std::string (rawtok->str () == IF ? " #if" : " #elif" ) + " condition"
3652+ };
3653+ outputList->push_back (std::move (out));
36343654 }
36353655 output.clear ();
36363656 return ;
@@ -3663,13 +3683,15 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
36633683 }
36643684 } catch (const std::exception &e) {
36653685 if (outputList) {
3666- Output out (rawtok->location .files );
3667- out.type = Output::SYNTAX_ERROR;
3668- out.location = rawtok->location ;
3669- out.msg = " failed to evaluate " + std::string (rawtok->str () == IF ? " #if" : " #elif" ) + " condition" ;
3686+ std::string msg = " failed to evaluate " + std::string (rawtok->str () == IF ? " #if" : " #elif" ) + " condition" ;
36703687 if (e.what () && *e.what ())
3671- out.msg += std::string (" , " ) + e.what ();
3672- outputList->push_back (out);
3688+ msg += std::string (" , " ) + e.what ();
3689+ Output out = {
3690+ Output::SYNTAX_ERROR,
3691+ rawtok->location ,
3692+ std::move (msg)
3693+ };
3694+ outputList->push_back (std::move (out));
36733695 }
36743696 output.clear ();
36753697 return ;
0 commit comments