@@ -1352,13 +1352,6 @@ static bool isAnonymousReferenceParameter(const simplecpp::Token *tok)
13521352 return false ;
13531353}
13541354
1355- /* * Append the next token to tok, and delete the next token */
1356- static void combineWithNext (simplecpp::TokenList &tokens, simplecpp::Token *tok)
1357- {
1358- tok->setstr (tok->str () + tok->next ->str ());
1359- tokens.deleteToken (tok->next );
1360- }
1361-
13621355void simplecpp::TokenList::combineOperators ()
13631356{
13641357 std::stack<bool , std::vector<bool >> executableScope{{false }};
@@ -1370,28 +1363,34 @@ void simplecpp::TokenList::combineOperators()
13701363 // ellipsis ...
13711364 if (tok->next && tok->next ->op == ' .' && tok->next ->location .col == (tok->location .col + 1 ) &&
13721365 tok->next ->next && tok->next ->next ->op == ' .' && tok->next ->next ->location .col == (tok->location .col + 2 )) {
1373- combineWithNext (*this , tok);
1374- combineWithNext (*this , tok);
1366+ tok->setstr (" ..." );
1367+ deleteToken (tok->next );
1368+ deleteToken (tok->next );
13751369 continue ;
13761370 }
13771371 // float literals..
13781372 if (tok->previous && tok->previous ->number && sameline (tok->previous , tok) && tok->previous ->str ().find_first_of (" ._" ) == std::string::npos) {
13791373 tok->setstr (tok->previous ->str () + ' .' );
13801374 deleteToken (tok->previous );
1381- if (sameline (tok, tok->next ) && (isFloatSuffix (tok->next ) || (tok->next && tok->next ->startsWithOneOf (" AaBbCcDdEeFfPp" ) && !isAlternativeAndBitandBitor (tok->next ))))
1382- combineWithNext (*this , tok);
1375+ if (sameline (tok, tok->next ) && (isFloatSuffix (tok->next ) || (tok->next && tok->next ->startsWithOneOf (" AaBbCcDdEeFfPp" ) && !isAlternativeAndBitandBitor (tok->next )))) {
1376+ tok->setstr (tok->str () + tok->next ->str ());
1377+ deleteToken (tok->next );
1378+ }
1379+ }
1380+ if (tok->next && tok->next ->number ) {
1381+ tok->setstr (tok->str () + tok->next ->str ());
1382+ deleteToken (tok->next );
13831383 }
1384- if (tok->next && tok->next ->number )
1385- combineWithNext (*this , tok);
13861384 }
13871385 // match: [0-9.]+E [+-] [0-9]+
13881386 const char lastChar = tok->str ()[tok->str ().size () - 1 ];
13891387 if (tok->number && !isOct (tok->str ()) &&
13901388 ((!isHex (tok->str ()) && (lastChar == ' E' || lastChar == ' e' )) ||
13911389 (isHex (tok->str ()) && (lastChar == ' P' || lastChar == ' p' ))) &&
13921390 tok->next && tok->next ->isOneOf (" +-" ) && tok->next ->next && tok->next ->next ->number ) {
1393- combineWithNext (*this , tok);
1394- combineWithNext (*this , tok);
1391+ tok->setstr (tok->str () + tok->next ->op + tok->next ->next ->str ());
1392+ deleteToken (tok->next );
1393+ deleteToken (tok->next );
13951394 }
13961395
13971396 if (tok->op == ' \0 ' || !tok->next || tok->next ->op == ' \0 ' )
@@ -1406,17 +1405,23 @@ void simplecpp::TokenList::combineOperators()
14061405 // void f(x&=2)
14071406 if (tok->op == ' &' && !executableScope.top () && isAnonymousReferenceParameter (tok))
14081407 continue ;
1409- combineWithNext (*this , tok);
1408+ tok->setstr (tok->str () + " =" );
1409+ deleteToken (tok->next );
14101410 } else if ((tok->op == ' |' || tok->op == ' &' ) && tok->op == tok->next ->op ) {
1411- combineWithNext (*this , tok);
1411+ tok->setstr (tok->str () + tok->next ->str ());
1412+ deleteToken (tok->next );
14121413 } else if (tok->op == ' :' && tok->next ->op == ' :' ) {
1413- combineWithNext (*this , tok);
1414+ tok->setstr (tok->str () + tok->next ->str ());
1415+ deleteToken (tok->next );
14141416 } else if (tok->op == ' -' && tok->next ->op == ' >' ) {
1415- combineWithNext (*this , tok);
1417+ tok->setstr (tok->str () + tok->next ->str ());
1418+ deleteToken (tok->next );
14161419 } else if ((tok->op == ' <' || tok->op == ' >' ) && tok->op == tok->next ->op ) {
1417- combineWithNext (*this , tok);
1420+ tok->setstr (tok->str () + tok->next ->str ());
1421+ deleteToken (tok->next );
14181422 if (tok->next && tok->next ->op == ' =' && tok->next ->next && tok->next ->next ->op != ' =' ) {
1419- combineWithNext (*this , tok);
1423+ tok->setstr (tok->str () + tok->next ->str ());
1424+ deleteToken (tok->next );
14201425 }
14211426 } else if ((tok->op == ' +' || tok->op == ' -' ) && tok->op == tok->next ->op ) {
14221427 if (tok->location .col + 1U != tok->next ->location .col )
@@ -1425,7 +1430,8 @@ void simplecpp::TokenList::combineOperators()
14251430 continue ;
14261431 if (tok->next ->next && tok->next ->next ->number )
14271432 continue ;
1428- combineWithNext (*this , tok);
1433+ tok->setstr (tok->str () + tok->next ->str ());
1434+ deleteToken (tok->next );
14291435 }
14301436 }
14311437}
0 commit comments