Skip to content

Commit

Permalink
fixed #12715 - made Visual Studio conditions work again (#6389)
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave authored May 14, 2024
1 parent eb4ceac commit 994c015
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/clangimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Token *> lpar;
for (const std::string &s: splitString(type)) {
Token *tok = addtoken(tokenList, s, false);
Expand Down
17 changes: 17 additions & 0 deletions lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <iostream>
#include <iterator>
#include <sstream>
#include <stack>
#include <unordered_set>
#include <utility>

Expand Down Expand Up @@ -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<Token*> 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()
Expand Down
1 change: 1 addition & 0 deletions lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,7 @@ std::shared_ptr<Token> createTokenFromExpression(const std::string& returnValue,
return nullptr;
}

// TODO: put in a helper?
// combine operators, set links, etc..
std::stack<Token*> lpar;
for (Token* tok2 = tokenList->front(); tok2; tok2 = tok2->next()) {
Expand Down
1 change: 1 addition & 0 deletions lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Token *> link;

while (n > 0) {
Expand Down
26 changes: 26 additions & 0 deletions test/testtokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "tokenlist.h"

#include <sstream>
#include <stack>
#include <string>

#include <simplecpp.h>
Expand All @@ -43,6 +44,7 @@ class TestTokenList : public TestFixture {
TEST_CASE(inc);
TEST_CASE(isKeyword);
TEST_CASE(notokens);
TEST_CASE(ast1);
}

// inspired by #5895
Expand Down Expand Up @@ -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<Token*> 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)

0 comments on commit 994c015

Please sign in to comment.