@@ -466,20 +466,13 @@ simplecpp::TokenList::TokenList(std::istream &istr, std::vector<std::string> &fi
466
466
readfile (stream,filename,outputList);
467
467
}
468
468
469
- simplecpp::TokenList::TokenList (const unsigned char * data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename, OutputList *outputList)
469
+ simplecpp::TokenList::TokenList (const unsigned char * data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename, OutputList *outputList, int /* unused */ )
470
470
: frontToken(nullptr ), backToken(nullptr ), files(filenames)
471
471
{
472
472
StdCharBufStream stream (data, size);
473
473
readfile (stream,filename,outputList);
474
474
}
475
475
476
- simplecpp::TokenList::TokenList (const char * data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename, OutputList *outputList)
477
- : frontToken(nullptr ), backToken(nullptr ), files(filenames)
478
- {
479
- StdCharBufStream stream (reinterpret_cast <const unsigned char *>(data), size);
480
- readfile (stream,filename,outputList);
481
- }
482
-
483
476
simplecpp::TokenList::TokenList (const std::string &filename, std::vector<std::string> &filenames, OutputList *outputList)
484
477
: frontToken(nullptr ), backToken(nullptr ), files(filenames)
485
478
{
@@ -611,7 +604,7 @@ static void portabilityBackslash(simplecpp::OutputList *outputList, const std::v
611
604
err.type = simplecpp::Output::PORTABILITY_BACKSLASH;
612
605
err.location = location;
613
606
err.msg = " Combination 'backslash space newline' is not portable." ;
614
- outputList->push_back (err);
607
+ outputList->push_back (std::move ( err) );
615
608
}
616
609
617
610
static bool isStringLiteralPrefix (const std::string &str)
@@ -761,18 +754,18 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
761
754
while (stream.good () && ch != ' \n ' ) {
762
755
currentToken += ch;
763
756
ch = stream.readChar ();
764
- if (ch == ' \\ ' ) {
757
+ if (ch == ' \\ ' ) {
765
758
TokenString tmp;
766
759
char tmp_ch = ch;
767
- while ((stream.good ()) && (tmp_ch == ' \\ ' || tmp_ch == ' ' || tmp_ch == ' \t ' )) {
760
+ while ((stream.good ()) && (tmp_ch == ' \\ ' || tmp_ch == ' ' || tmp_ch == ' \t ' )) {
768
761
tmp += tmp_ch;
769
762
tmp_ch = stream.readChar ();
770
763
}
771
- if (!stream.good ()) {
764
+ if (!stream.good ()) {
772
765
break ;
773
766
}
774
767
775
- if (tmp_ch != ' \n ' ) {
768
+ if (tmp_ch != ' \n ' ) {
776
769
currentToken += tmp;
777
770
} else {
778
771
const TokenString check_portability = currentToken + tmp;
@@ -855,7 +848,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
855
848
err.type = Output::SYNTAX_ERROR;
856
849
err.location = location;
857
850
err.msg = " Raw string missing terminating delimiter." ;
858
- outputList->push_back (err);
851
+ outputList->push_back (std::move ( err) );
859
852
}
860
853
return ;
861
854
}
@@ -1397,7 +1390,7 @@ std::string simplecpp::TokenList::readUntil(Stream &stream, const Location &loca
1397
1390
err.type = Output::SYNTAX_ERROR;
1398
1391
err.location = location;
1399
1392
err.msg = std::string (" No pair for character (" ) + start + " ). Can't process file. File is either invalid or unicode, which is currently not supported." ;
1400
- outputList->push_back (err);
1393
+ outputList->push_back (std::move ( err) );
1401
1394
}
1402
1395
return " " ;
1403
1396
}
@@ -1667,7 +1660,7 @@ namespace simplecpp {
1667
1660
}
1668
1661
1669
1662
invalidHashHash (const Location &loc, const std::string ¯oName, const std::string &message)
1670
- : Error(loc, format(macroName, message)) { }
1663
+ : Error(loc, format(macroName, message)) {}
1671
1664
1672
1665
static inline invalidHashHash unexpectedToken (const Location &loc, const std::string ¯oName, const Token *tokenA) {
1673
1666
return invalidHashHash (loc, macroName, " Unexpected token '" + tokenA->str ()+" '" );
@@ -2178,7 +2171,7 @@ namespace simplecpp {
2178
2171
if (it != macros.end () && !partok->isExpandedFrom (&it->second ) && (partok->str () == name () || expandedmacros.find (partok->str ()) == expandedmacros.end ())) {
2179
2172
std::set<TokenString> expandedmacros2 (expandedmacros); // temporary amnesia to allow reexpansion of currently expanding macros during argument evaluation
2180
2173
expandedmacros2.erase (name ());
2181
- partok = it->second .expand (output, loc, partok, macros, expandedmacros2);
2174
+ partok = it->second .expand (output, loc, partok, macros, std::move ( expandedmacros2) );
2182
2175
} else {
2183
2176
output->push_back (newMacroToken (partok->str (), loc, isReplaced (expandedmacros), partok));
2184
2177
output->back ()->macro = partok->macro ;
@@ -2385,12 +2378,17 @@ namespace simplecpp {
2385
2378
namespace simplecpp {
2386
2379
2387
2380
#ifdef __CYGWIN__
2381
+ static bool startsWith (const std::string &s, const std::string &p)
2382
+ {
2383
+ return (s.size () >= p.size ()) && std::equal (p.begin (), p.end (), s.begin ());
2384
+ }
2385
+
2388
2386
std::string convertCygwinToWindowsPath (const std::string &cygwinPath)
2389
2387
{
2390
2388
std::string windowsPath;
2391
2389
2392
2390
std::string::size_type pos = 0 ;
2393
- if (cygwinPath.size () >= 11 && startsWith_ (cygwinPath, " /cygdrive/" )) {
2391
+ if (cygwinPath.size () >= 11 && startsWith (cygwinPath, " /cygdrive/" )) {
2394
2392
const unsigned char driveLetter = cygwinPath[10 ];
2395
2393
if (std::isalpha (driveLetter)) {
2396
2394
if (cygwinPath.size () == 11 ) {
@@ -2667,7 +2665,7 @@ static unsigned long long stringToULLbounded(
2667
2665
int base = 0 ,
2668
2666
std::ptrdiff_t minlen = 1 ,
2669
2667
std::size_t maxlen = std::string::npos
2670
- )
2668
+ )
2671
2669
{
2672
2670
const std::string sub = s.substr (pos, maxlen);
2673
2671
const char * const start = sub.c_str ();
@@ -3024,8 +3022,7 @@ std::pair<simplecpp::FileData *, bool> simplecpp::FileDataCache::tryload(FileDat
3024
3022
return {id_it->second , false };
3025
3023
}
3026
3024
3027
- std::ifstream f (path);
3028
- FileData *const data = new FileData {path, TokenList (f, filenames, path, outputList)};
3025
+ FileData *const data = new FileData {path, TokenList (path, filenames, outputList)};
3029
3026
3030
3027
if (dui.removeComments )
3031
3028
data->tokens .removeComments ();
@@ -3132,7 +3129,7 @@ simplecpp::FileDataCache simplecpp::load(const simplecpp::TokenList &rawtokens,
3132
3129
err.type = simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND;
3133
3130
err.location = Location (filenames);
3134
3131
err.msg = " Can not open include file '" + filename + " ' that is explicitly included." ;
3135
- outputList->push_back (err);
3132
+ outputList->push_back (std::move ( err) );
3136
3133
}
3137
3134
continue ;
3138
3135
}
@@ -3205,7 +3202,7 @@ static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token
3205
3202
out.type = simplecpp::Output::SYNTAX_ERROR;
3206
3203
out.location = err.location ;
3207
3204
out.msg = " failed to expand \' " + tok->str () + " \' , " + err.what ;
3208
- outputList->push_back (out);
3205
+ outputList->push_back (std::move ( out) );
3209
3206
}
3210
3207
return false ;
3211
3208
}
@@ -3349,7 +3346,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
3349
3346
includetokenstack.push (filedata->tokens .cfront ());
3350
3347
}
3351
3348
3352
- std::map<std::string, std::list<Location> > maybeUsedMacros;
3349
+ std::map<std::string, std::list<Location>> maybeUsedMacros;
3353
3350
3354
3351
for (const Token *rawtok = nullptr ; rawtok || !includetokenstack.empty ();) {
3355
3352
if (rawtok == nullptr ) {
@@ -3392,7 +3389,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
3392
3389
err.msg += tok->str ();
3393
3390
}
3394
3391
err.msg = ' #' + rawtok->str () + ' ' + err.msg ;
3395
- outputList->push_back (err);
3392
+ outputList->push_back (std::move ( err) );
3396
3393
}
3397
3394
/* Patched for PythonQt generator: Do not stop on #error directive:
3398
3395
if (rawtok->str() == ERROR) {
@@ -3554,7 +3551,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
3554
3551
out.type = Output::SYNTAX_ERROR;
3555
3552
out.location = rawtok->location ;
3556
3553
out.msg = " failed to evaluate " + std::string (rawtok->str () == IF ? " #if" : " #elif" ) + " condition" ;
3557
- outputList->push_back (out);
3554
+ outputList->push_back (std::move ( out) );
3558
3555
}
3559
3556
output.clear ();
3560
3557
return ;
@@ -3733,7 +3730,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
3733
3730
mu.macroName = macro.name ();
3734
3731
mu.macroLocation = macro.defineLocation ();
3735
3732
mu.useLocation = *usageIt;
3736
- macroUsage->push_back (mu );
3733
+ macroUsage->push_back (std::move (mu) );
3737
3734
}
3738
3735
}
3739
3736
}
@@ -3748,11 +3745,11 @@ simplecpp::cstd_t simplecpp::getCStd(const std::string &std)
3748
3745
{
3749
3746
if (std == " c90" || std == " c89" || std == " iso9899:1990" || std == " iso9899:199409" || std == " gnu90" || std == " gnu89" )
3750
3747
return C89;
3751
- if (std == " c99" || std == " c9x" || std == " iso9899:1999" || std == " iso9899:199x" || std == " gnu99" || std == " gnu9x" )
3748
+ if (std == " c99" || std == " c9x" || std == " iso9899:1999" || std == " iso9899:199x" || std == " gnu99" || std == " gnu9x" )
3752
3749
return C99;
3753
3750
if (std == " c11" || std == " c1x" || std == " iso9899:2011" || std == " gnu11" || std == " gnu1x" )
3754
3751
return C11;
3755
- if (std == " c17" || std == " c18" || std == " iso9899:2017" || std == " iso9899:2018" || std == " gnu17" || std == " gnu18" )
3752
+ if (std == " c17" || std == " c18" || std == " iso9899:2017" || std == " iso9899:2018" || std == " gnu17" || std == " gnu18" )
3756
3753
return C17;
3757
3754
if (std == " c23" || std == " gnu23" || std == " c2x" || std == " gnu2x" )
3758
3755
return C23;
0 commit comments