Skip to content

Commit b447c97

Browse files
committed
white-list matching + consts + ternary in test case
1 parent bf832fb commit b447c97

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Diff for: lib/tokenlist.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,8 @@ static void compileUnaryOp(Token *&tok, AST_state& state, void (*f)(Token *&tok,
710710
static void skipGenericType(Token *&tok)
711711
{
712712
Token *skip = tok;
713-
while (skip && !Token::Match(skip, ",|)")) {
714-
if (Token::simpleMatch(skip, "(")) {
713+
while (Token::Match(skip, "%name%|*|:|(")) {
714+
if (skip->link()) {
715715
skip = skip->link()->next();
716716
continue;
717717
}
@@ -730,7 +730,7 @@ static void compileBinOp(Token *&tok, AST_state& state, void (*f)(Token *&tok, A
730730
tok = tok->next();
731731
if (Token::simpleMatch(binop, ",") && state.inGeneric)
732732
skipGenericType(tok);
733-
bool inGenericSaved = state.inGeneric;
733+
const bool inGenericSaved = state.inGeneric;
734734
state.inGeneric = false;
735735
if (Token::Match(binop, "::|. ~"))
736736
tok = tok->next();
@@ -1070,7 +1070,7 @@ static void compilePrecedence2(Token *&tok, AST_state& state)
10701070
continue;
10711071
} else if (tok->str() == "(" &&
10721072
(!iscast(tok, state.cpp) || Token::Match(tok->previous(), "if|while|for|switch|catch"))) {
1073-
bool inGenericSaved = state.inGeneric;
1073+
const bool inGenericSaved = state.inGeneric;
10741074
if (Token::simpleMatch(tok->previous(), "_Generic"))
10751075
state.inGeneric = true;
10761076
Token* tok2 = tok;

Diff for: test/testtokenize.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -8393,8 +8393,8 @@ class TestTokenizer : public TestFixture {
83938393
}
83948394

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

0 commit comments

Comments
 (0)