Skip to content

Commit 33841b4

Browse files
committed
remove type signatures from AST in generic selections
1 parent 0c4564a commit 33841b4

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

lib/tokenlist.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,7 @@ void TokenList::createAst() const
18041804
throw InternalError(tok, "Syntax Error: Infinite loop when creating AST.", InternalError::AST);
18051805
tok = nextTok;
18061806
}
1807+
removeGenericTypes();
18071808
}
18081809

18091810
namespace {
@@ -2245,3 +2246,25 @@ void TokenList::setLang(Standards::Language lang, bool force)
22452246

22462247
mLang = lang;
22472248
}
2249+
2250+
void TokenList::removeGenericTypes() const
2251+
{
2252+
for (Token *tok = mTokensFrontBack.front; tok != mTokensFrontBack.back; tok = tok->next()) {
2253+
if (!Token::simpleMatch(tok, "_Generic"))
2254+
continue;
2255+
tok = tok->next();
2256+
Token *link = tok->link();
2257+
tok = tok->astOperand2();
2258+
2259+
while (tok) {
2260+
if (Token::simpleMatch(tok->astOperand2(), ":")) {
2261+
Token *tok2 = tok->astOperand2()->astOperand2();
2262+
tok2->astParent(nullptr);
2263+
tok->astOperand2(tok2);
2264+
}
2265+
tok = tok->astOperand1();
2266+
}
2267+
2268+
tok = link;
2269+
}
2270+
}

lib/tokenlist.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ class CPPCHECKLIB TokenList {
206206

207207
bool createTokensInternal(std::istream &code, const std::string& file0);
208208

209+
void removeGenericTypes() const;
210+
209211
/** Token list */
210212
TokensFrontBack mTokensFrontBack;
211213

test/testtokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8394,7 +8394,7 @@ class TestTokenizer : public TestFixture {
83948394

83958395
void genericInIf() { // #13561
83968396
const char code[] = " if (_Generic(s, char * : 1, const float * : 2, volatile int * : 3, default : 0)) {}";
8397-
const char ast[] = "(( if (( _Generic (, (, (, (, s (: char 1)) (: float 2)) (: int 3)) (: default 0))))";
8397+
const char ast[] = "(( if (( _Generic (, (, (, (, s 1) 2) 3) 0)))";
83988398
ASSERT_EQUALS(ast, testAst(code, AstStyle::Z3));
83998399
}
84008400
};

0 commit comments

Comments
 (0)