Skip to content

Commit

Permalink
Fix AST, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Feb 24, 2024
1 parent cc5f3e1 commit 72586e2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ static void compileUnaryOp(Token *&tok, AST_state& state, void (*f)(Token *&tok,
state.depth--;
}

if (!state.op.empty()) {
if (!state.op.empty() && !(unaryop->str() == "&" && precedes(state.op.top(), unaryop))) {
unaryop->astOperand1(state.op.top());
state.op.pop();
}
Expand Down Expand Up @@ -998,7 +998,7 @@ static void compilePrecedence2(Token *&tok, AST_state& state)
|| (tok->strAt(-1) == ">" && tok->linkAt(-1))
|| (tok->strAt(-1) == ")" && !iscast(tok->linkAt(-1), state.cpp)) // Don't treat brackets to clarify precedence as function calls
|| (tok->strAt(-1) == "}" && opPrevTopSquare)) {
const bool operandInside = oldOpSize < state.op.size() || (state.cpp && Token::simpleMatch(tok, "( & )"));
const bool operandInside = oldOpSize < state.op.size();
if (operandInside)
compileBinOp(tok, state, nullptr);
else
Expand Down
1 change: 1 addition & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6586,6 +6586,7 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS("abc;(", testAst("a(b;c)"));
ASSERT_EQUALS("x{( forbc;;(", testAst("x({ for(a;b;c){} });"));
ASSERT_EQUALS("PT.(", testAst("P->~T();")); // <- The "T" token::function() will be a destructor
ASSERT_EQUALS("double&(4[", testAst("void f(double(&)[4]) {}"));
}

void asttemplate() { // uninstantiated templates will have <,>,etc..
Expand Down

0 comments on commit 72586e2

Please sign in to comment.