diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index fc021758f5c..430771cdea2 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -566,6 +566,7 @@ const ::Type * clangimport::AstNode::addTypeTokens(TokenList &tokenList, const s if (type.find('(') != std::string::npos) type.erase(type.find('(')); + // TODO: put in a helper? std::stack lpar; for (const std::string &s: splitString(type)) { Token *tok = addtoken(tokenList, s, false); diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 6a30ae46850..42c21613c57 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -568,6 +569,22 @@ namespace { TokenList tokenlist(&s); std::istringstream istr(c); tokenlist.createTokens(istr, Standards::Language::C); // TODO: check result + // TODO: put in a helper + // generate links + { + std::stack lpar; + for (Token* tok2 = tokenlist.front(); tok2; tok2 = tok2->next()) { + if (tok2->str() == "(") + lpar.push(tok2); + else if (tok2->str() == ")") { + if (lpar.empty()) + break; + Token::createMutualLinks(lpar.top(), tok2); + lpar.pop(); + } + } + } + tokenlist.createAst(); for (const Token *tok = tokenlist.front(); tok; tok = tok->next()) { if (tok->str() == "(" && tok->astOperand1() && tok->astOperand2()) { // TODO: this is wrong - it is Contains() not Equals() diff --git a/lib/library.cpp b/lib/library.cpp index ddd2a13ed90..0974e27bcea 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -1774,6 +1774,7 @@ std::shared_ptr createTokenFromExpression(const std::string& returnValue, return nullptr; } + // TODO: put in a helper? // combine operators, set links, etc.. std::stack lpar; for (Token* tok2 = tokenList->front(); tok2; tok2 = tok2->next()) { diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 786647aa4ab..0535bf5af3b 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -303,6 +303,7 @@ Token *TokenList::copyTokens(Token *dest, const Token *first, const Token *last, void TokenList::insertTokens(Token *dest, const Token *src, nonneg int n) { + // TODO: put the linking in a helper? std::stack link; while (n > 0) { diff --git a/test/testtokenlist.cpp b/test/testtokenlist.cpp index 4b11c5c37db..ec4058cfe9c 100644 --- a/test/testtokenlist.cpp +++ b/test/testtokenlist.cpp @@ -26,6 +26,7 @@ #include "tokenlist.h" #include +#include #include #include @@ -43,6 +44,7 @@ class TestTokenList : public TestFixture { TEST_CASE(inc); TEST_CASE(isKeyword); TEST_CASE(notokens); + TEST_CASE(ast1); } // inspired by #5895 @@ -161,6 +163,30 @@ class TestTokenList : public TestFixture { TokenList tokenlist(&settingsDefault); tokenlist.createTokens(std::move(tokensP)); // do not assert } + + void ast1() const { + const std::string s = "('Release|x64' == 'Release|x64');"; + + TokenList tokenlist(&settings); + std::istringstream istr(s); + tokenlist.createTokens(istr, Standards::Language::C); + // TODO: put this logic in TokenList + // generate links + { + std::stack lpar; + for (Token* tok2 = tokenlist.front(); tok2; tok2 = tok2->next()) { + if (tok2->str() == "(") + lpar.push(tok2); + else if (tok2->str() == ")") { + if (lpar.empty()) + break; + Token::createMutualLinks(lpar.top(), tok2); + lpar.pop(); + } + } + } + tokenlist.createAst(); // do not crash + } }; REGISTER_TEST(TestTokenList)