@@ -451,6 +451,7 @@ namespace {
451
451
bool cpp;
452
452
int assign{};
453
453
bool inCase{}; // true from case to :
454
+ bool inGeneric{};
454
455
bool stopAtColon{}; // help to properly parse ternary operators
455
456
const Token* functionCallEndPar{};
456
457
explicit AST_state (bool cpp) : cpp(cpp) {}
@@ -706,11 +707,31 @@ static void compileUnaryOp(Token *&tok, AST_state& state, void (*f)(Token *&tok,
706
707
state.op .push (unaryop);
707
708
}
708
709
710
+ static void skipGenericType (Token *&tok)
711
+ {
712
+ Token *skip = tok;
713
+ while (skip && !Token::Match (skip, " ,|)" )) {
714
+ if (Token::simpleMatch (skip, " (" )) {
715
+ skip = skip->link ()->next ();
716
+ continue ;
717
+ }
718
+ if (Token::simpleMatch (skip, " :" )) {
719
+ tok = skip->next ();
720
+ return ;
721
+ }
722
+ skip = skip->next ();
723
+ }
724
+ }
725
+
709
726
static void compileBinOp (Token *&tok, AST_state& state, void (*f)(Token *&tok, AST_state& state))
710
727
{
711
728
Token *binop = tok;
712
729
if (f) {
713
730
tok = tok->next ();
731
+ if (Token::simpleMatch (binop, " ," ) && state.inGeneric )
732
+ skipGenericType (tok);
733
+ bool inGenericSaved = state.inGeneric ;
734
+ state.inGeneric = false ;
714
735
if (Token::Match (binop, " ::|. ~" ))
715
736
tok = tok->next ();
716
737
state.depth ++;
@@ -719,6 +740,7 @@ static void compileBinOp(Token *&tok, AST_state& state, void (*f)(Token *&tok, A
719
740
if (state.depth > AST_MAX_DEPTH)
720
741
throw InternalError (tok, " maximum AST depth exceeded" , InternalError::AST);
721
742
state.depth --;
743
+ state.inGeneric = inGenericSaved;
722
744
}
723
745
724
746
// TODO: Should we check if op is empty.
@@ -1048,6 +1070,9 @@ static void compilePrecedence2(Token *&tok, AST_state& state)
1048
1070
continue ;
1049
1071
} else if (tok->str () == " (" &&
1050
1072
(!iscast (tok, state.cpp ) || Token::Match (tok->previous (), " if|while|for|switch|catch" ))) {
1073
+ bool inGenericSaved = state.inGeneric ;
1074
+ if (Token::simpleMatch (tok->previous (), " _Generic" ))
1075
+ state.inGeneric = true ;
1051
1076
Token* tok2 = tok;
1052
1077
tok = tok->next ();
1053
1078
const bool opPrevTopSquare = !state.op .empty () && state.op .top () && state.op .top ()->str () == " [" ;
@@ -1066,6 +1091,7 @@ static void compilePrecedence2(Token *&tok, AST_state& state)
1066
1091
else
1067
1092
compileUnaryOp (tok, state, nullptr );
1068
1093
}
1094
+ state.inGeneric = inGenericSaved;
1069
1095
tok = tok->link ()->next ();
1070
1096
if (Token::simpleMatch (tok, " ::" ))
1071
1097
compileBinOp (tok, state, compileTerm);
0 commit comments