Fixed AST problem for 'if ((a.b&c)==d){}'
This commit is contained in:
parent
bbdfd8b5c7
commit
c505f5ea23
|
@ -1160,9 +1160,14 @@ void Token::astHandleParentheses()
|
||||||
innerTop = _previous;
|
innerTop = _previous;
|
||||||
else if (_next && _next->_str == ")")
|
else if (_next && _next->_str == ")")
|
||||||
return;
|
return;
|
||||||
else // _str = "("
|
else { // _str = "("
|
||||||
innerTop = _next;
|
innerTop = _next;
|
||||||
while (innerTop->_astParent)
|
while (Token::simpleMatch(innerTop->link(),") )"))
|
||||||
|
innerTop = innerTop->_next;
|
||||||
|
if (innerTop && innerTop->_str == "(")
|
||||||
|
innerTop = innerTop->_link->_next;
|
||||||
|
}
|
||||||
|
while (innerTop && innerTop->_astParent)
|
||||||
innerTop = innerTop->_astParent;
|
innerTop = innerTop->_astParent;
|
||||||
|
|
||||||
if (_astParent) {
|
if (_astParent) {
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <stack>
|
||||||
|
|
||||||
extern std::ostringstream errout;
|
extern std::ostringstream errout;
|
||||||
class TestTokenizer : public TestFixture {
|
class TestTokenizer : public TestFixture {
|
||||||
|
@ -9926,6 +9927,17 @@ private:
|
||||||
if (!tokenList.createTokens(istr,"test.cpp"))
|
if (!tokenList.createTokens(istr,"test.cpp"))
|
||||||
return "ERROR";
|
return "ERROR";
|
||||||
|
|
||||||
|
// Set links..
|
||||||
|
std::stack<Token *> links;
|
||||||
|
for (Token *tok = tokenList.front(); tok; tok = tok->next()) {
|
||||||
|
if (Token::Match(tok, "(|["))
|
||||||
|
links.push(tok);
|
||||||
|
else if (!links.empty() && Token::Match(tok,")|]")) {
|
||||||
|
Token::createMutualLinks(links.top(), tok);
|
||||||
|
links.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create AST..
|
// Create AST..
|
||||||
tokenList.createAst();
|
tokenList.createAst();
|
||||||
|
|
||||||
|
@ -9956,6 +9968,7 @@ private:
|
||||||
ASSERT_EQUALS("12+3*", testAst("(1+2)*3"));
|
ASSERT_EQUALS("12+3*", testAst("(1+2)*3"));
|
||||||
ASSERT_EQUALS("123+*", testAst("1*(2+3)"));
|
ASSERT_EQUALS("123+*", testAst("1*(2+3)"));
|
||||||
ASSERT_EQUALS("123+*4*", testAst("1*(2+3)*4"));
|
ASSERT_EQUALS("123+*4*", testAst("1*(2+3)*4"));
|
||||||
|
ASSERT_EQUALS("ab.c&d==if", testAst("if((a.b&c)==d){}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void astbrackets() const { // []
|
void astbrackets() const { // []
|
||||||
|
|
Loading…
Reference in New Issue