Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,14 @@ static bool isFloatSuffix(const simplecpp::Token *tok)
return c == 'f' || c == 'l';
}

static const std::string AND("and");
static const std::string BITAND("bitand");
static const std::string BITOR("bitor");
static bool isAlternativeAndBitandBitor(const simplecpp::Token* tok)
{
return isAlternativeBinaryOp(tok, AND) || isAlternativeBinaryOp(tok, BITAND) || isAlternativeBinaryOp(tok, BITOR);
}

void simplecpp::TokenList::combineOperators()
{
std::stack<bool> executableScope;
Expand Down Expand Up @@ -1040,7 +1048,7 @@ void simplecpp::TokenList::combineOperators()
if (tok->previous && tok->previous->number && sameline(tok->previous, tok) && tok->previous->str().find_first_of("._") == std::string::npos) {
tok->setstr(tok->previous->str() + '.');
deleteToken(tok->previous);
if (sameline(tok, tok->next) && (isFloatSuffix(tok->next) || (tok->next && tok->next->startsWithOneOf("AaBbCcDdEeFfPp")))) {
if (sameline(tok, tok->next) && (isFloatSuffix(tok->next) || (tok->next && tok->next->startsWithOneOf("AaBbCcDdEeFfPp") && !isAlternativeAndBitandBitor(tok->next)))) {
tok->setstr(tok->str() + tok->next->str());
deleteToken(tok->next);
}
Expand Down Expand Up @@ -1285,8 +1293,6 @@ void simplecpp::TokenList::constFoldComparison(Token *tok)
}
}

static const std::string BITAND("bitand");
static const std::string BITOR("bitor");
static const std::string XOR("xor");
void simplecpp::TokenList::constFoldBitwise(Token *tok)
{
Expand Down Expand Up @@ -1321,7 +1327,6 @@ void simplecpp::TokenList::constFoldBitwise(Token *tok)
}
}

static const std::string AND("and");
static const std::string OR("or");
void simplecpp::TokenList::constFoldLogicalOp(Token *tok)
{
Expand Down
1 change: 1 addition & 0 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ static void combineOperators_floatliteral()
ASSERT_EQUALS("1p + 3", preprocess("1p+3"));
ASSERT_EQUALS("1.0_a . b", preprocess("1.0_a.b"));
ASSERT_EQUALS("1_a . b", preprocess("1_a.b"));
ASSERT_EQUALS("bool x = d != 0. and b ;", preprocess("bool x = d != 0. and b;"));
}

static void combineOperators_increment()
Expand Down