Skip to content

Commit c03afd1

Browse files
committed
fixed #12715 - made Visual Studio conditions work again
1 parent ac626a2 commit c03afd1

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

lib/clangimport.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ const ::Type * clangimport::AstNode::addTypeTokens(TokenList &tokenList, const s
566566
if (type.find('(') != std::string::npos)
567567
type.erase(type.find('('));
568568

569+
// TODO: put in a helper?
569570
std::stack<Token *> lpar;
570571
for (const std::string &s: splitString(type)) {
571572
Token *tok = addtoken(tokenList, s, false);

lib/importproject.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,22 @@ namespace {
568568
TokenList tokenlist(&s);
569569
std::istringstream istr(c);
570570
tokenlist.createTokens(istr, Standards::Language::C); // TODO: check result
571+
// TODO: put in a helper
572+
// generate links
573+
{
574+
std::stack<Token*> lpar;
575+
for (Token* tok2 = tokenlist.front(); tok2; tok2 = tok2->next()) {
576+
if (tok2->str() == "(")
577+
lpar.push(tok2);
578+
else if (tok2->str() == ")") {
579+
if (lpar.empty())
580+
break;
581+
Token::createMutualLinks(lpar.top(), tok2);
582+
lpar.pop();
583+
}
584+
}
585+
}
586+
tokenlist.createAst();
571587
for (const Token *tok = tokenlist.front(); tok; tok = tok->next()) {
572588
if (tok->str() == "(" && tok->astOperand1() && tok->astOperand2()) {
573589
// TODO: this is wrong - it is Contains() not Equals()

lib/library.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,7 @@ std::shared_ptr<Token> createTokenFromExpression(const std::string& returnValue,
17741774
return nullptr;
17751775
}
17761776

1777+
// TODO: put in a helper?
17771778
// combine operators, set links, etc..
17781779
std::stack<Token*> lpar;
17791780
for (Token* tok2 = tokenList->front(); tok2; tok2 = tok2->next()) {

lib/tokenlist.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ Token *TokenList::copyTokens(Token *dest, const Token *first, const Token *last,
303303

304304
void TokenList::insertTokens(Token *dest, const Token *src, nonneg int n)
305305
{
306+
// TODO: put the linking in a helper?
306307
std::stack<Token *> link;
307308

308309
while (n > 0) {

test/testtokenlist.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "tokenlist.h"
2727

2828
#include <sstream>
29+
#include <stack>
2930
#include <string>
3031

3132
#include <simplecpp.h>
@@ -43,6 +44,7 @@ class TestTokenList : public TestFixture {
4344
TEST_CASE(inc);
4445
TEST_CASE(isKeyword);
4546
TEST_CASE(notokens);
47+
TEST_CASE(ast1);
4648
}
4749

4850
// inspired by #5895
@@ -161,6 +163,30 @@ class TestTokenList : public TestFixture {
161163
TokenList tokenlist(&settingsDefault);
162164
tokenlist.createTokens(std::move(tokensP)); // do not assert
163165
}
166+
167+
void ast1() {
168+
const std::string s = "('Release|x64' == 'Release|x64');";
169+
170+
TokenList tokenlist(&settings);
171+
std::istringstream istr(s);
172+
tokenlist.createTokens(istr, Standards::Language::C);
173+
// TODO: put this logic in TokenList
174+
// generate links
175+
{
176+
std::stack<Token*> lpar;
177+
for (Token* tok2 = tokenlist.front(); tok2; tok2 = tok2->next()) {
178+
if (tok2->str() == "(")
179+
lpar.push(tok2);
180+
else if (tok2->str() == ")") {
181+
if (lpar.empty())
182+
break;
183+
Token::createMutualLinks(lpar.top(), tok2);
184+
lpar.pop();
185+
}
186+
}
187+
}
188+
tokenlist.createAst(); // do not crash
189+
}
164190
};
165191

166192
REGISTER_TEST(TestTokenList)

0 commit comments

Comments
 (0)