AST: fixed 'a.b++' and '*c[5]--'
This commit is contained in:
parent
ecec4b0b46
commit
9f2e37da37
|
@ -456,7 +456,7 @@ static void compileTerm(Token *& tok, std::stack<Token*> &op, unsigned int depth
|
||||||
compileUnaryOp(tok, compileExpression, op, depth);
|
compileUnaryOp(tok, compileExpression, op, depth);
|
||||||
} else if (tok->isName()) {
|
} else if (tok->isName()) {
|
||||||
const bool templatefunc = Token::Match(tok, "%var% <") && Token::simpleMatch(tok->linkAt(1), "> (");
|
const bool templatefunc = Token::Match(tok, "%var% <") && Token::simpleMatch(tok->linkAt(1), "> (");
|
||||||
if (Token::Match(tok->next(), "++|--")) { // post increment / decrement
|
if (!Token::Match(tok->previous(), ".|::") && Token::Match(tok->next(), "++|--")) { // post increment / decrement
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
tok->astOperand1(tok->previous());
|
tok->astOperand1(tok->previous());
|
||||||
op.push(tok);
|
op.push(tok);
|
||||||
|
@ -492,8 +492,13 @@ static void compileTerm(Token *& tok, std::stack<Token*> &op, unsigned int depth
|
||||||
}
|
}
|
||||||
tok1->astOperand1(prev);
|
tok1->astOperand1(prev);
|
||||||
prev = tok1;
|
prev = tok1;
|
||||||
if (Token::Match(tok, "]|)"))
|
if (Token::Match(tok, "]|)")) {
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
if (depth==1U && Token::Match(tok,"++|--") && op.empty()) {
|
||||||
|
tok->astOperand1(tok->previous()->link());
|
||||||
|
tok = tok->next();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
op.push(par);
|
op.push(par);
|
||||||
}
|
}
|
||||||
|
@ -566,6 +571,8 @@ static void compileScope(Token *&tok, std::stack<Token*> &op, unsigned int depth
|
||||||
compileBinOp(tok, compileTerm, op, depth);
|
compileBinOp(tok, compileTerm, op, depth);
|
||||||
else
|
else
|
||||||
compileUnaryOp(tok, compileDot, op, depth);
|
compileUnaryOp(tok, compileDot, op, depth);
|
||||||
|
if (depth==1U && Token::Match(tok,"++|--"))
|
||||||
|
compileTerm(tok,op,depth);
|
||||||
} else break;
|
} else break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -587,6 +594,8 @@ static void compileDot(Token *&tok, std::stack<Token*> &op, unsigned int depth)
|
||||||
while (tok) {
|
while (tok) {
|
||||||
if (tok->str() == ".") {
|
if (tok->str() == ".") {
|
||||||
compileBinOp(tok, compileParAndBrackets, op, depth);
|
compileBinOp(tok, compileParAndBrackets, op, depth);
|
||||||
|
if (depth==1U && Token::Match(tok,"++|--"))
|
||||||
|
compileTerm(tok,op,depth);
|
||||||
} else break;
|
} else break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10257,6 +10257,9 @@ private:
|
||||||
if (Token::Match(tok, "%or%|<<|>>|+|-|*|/|%|&|^ =")) {
|
if (Token::Match(tok, "%or%|<<|>>|+|-|*|/|%|&|^ =")) {
|
||||||
tok->str(tok->str() + "=");
|
tok->str(tok->str() + "=");
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
|
} else if (Token::simpleMatch(tok, ": :")) {
|
||||||
|
tok->str("::");
|
||||||
|
tok->deleteNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10407,6 +10410,10 @@ private:
|
||||||
ASSERT_EQUALS("1a--+", testAst("1 + --a"));
|
ASSERT_EQUALS("1a--+", testAst("1 + --a"));
|
||||||
ASSERT_EQUALS("1a--+", testAst("1 + a--"));
|
ASSERT_EQUALS("1a--+", testAst("1 + a--"));
|
||||||
ASSERT_EQUALS("ab+!", testAst("!(a+b)"));
|
ASSERT_EQUALS("ab+!", testAst("!(a+b)"));
|
||||||
|
ASSERT_EQUALS("ab.++", testAst("++a.b;"));
|
||||||
|
ASSERT_EQUALS("ab.++", testAst("a.b++;"));
|
||||||
|
ASSERT_EQUALS("ab::++", testAst("a::b++;"));
|
||||||
|
ASSERT_EQUALS("c5[--*", testAst("*c[5]--;"));
|
||||||
|
|
||||||
// Unary :: operator
|
// Unary :: operator
|
||||||
ASSERT_EQUALS("abc?d12,(::e/:=",testAst("a = b ? c : ::d(1,2) / e;"));
|
ASSERT_EQUALS("abc?d12,(::e/:=",testAst("a = b ? c : ::d(1,2) / e;"));
|
||||||
|
|
Loading…
Reference in New Issue