@@ -2640,46 +2640,48 @@ void Tokenizer::setVarId()
26402640 functionDeclEndStack.push (newFunctionDeclEnd);
26412641 scopeInfo.push (variableId);
26422642 }
2643- } else if (tok->str () == " {" ) {
2643+ } else if (Token::Match (tok, " {|}" )) {
2644+ const Token * const startToken = (tok->str () == " {" ) ? tok : tok->link ();
2645+
26442646 // parse anonymous unions as part of the current scope
2645- if (!(initlist && Token::Match (tok->previous (), " %name%|>|>>" ) && Token::Match (tok->link (), " } ,|{" ))) {
2646- bool isExecutable;
2647- if (tok->strAt (-1 ) == " )" || Token::Match (tok->tokAt (-2 ), " ) %type%" ) ||
2648- (initlist && tok->strAt (-1 ) == " }" )) {
2649- isExecutable = true ;
2650- } else {
2651- isExecutable = ((scopeStack.top ().isExecutable || initlist || tok->strAt (-1 ) == " else" ) &&
2652- !isClassStructUnionEnumStart (tok));
2653- scopeInfo.push (variableId);
2654- }
2655- initlist = false ;
2656- scopeStack.push (scopeStackEntryType (isExecutable, _varId));
2657- }
2658- } else if (tok->str () == " }" ) {
2659- // parse anonymous unions/structs as part of the current scope
2660- if (!(Token::simpleMatch (tok, " } ;" ) && tok->link () && Token::Match (tok->link ()->previous (), " union|struct|enum {" )) &&
2661- !(initlist && Token::Match (tok, " } ,|{" ) && Token::Match (tok->link ()->previous (), " %name%|>|>> {" ))) {
2662- bool isNamespace = false ;
2663- for (const Token *tok1 = tok->link ()->previous (); tok1 && tok1->isName (); tok1 = tok1->previous ())
2664- isNamespace |= (tok1->str () == " namespace" );
2665- // Set variable ids in class declaration..
2666- if (!initlist && !isC () && !scopeStack.top ().isExecutable && tok->link () && !isNamespace) {
2667- setVarIdClassDeclaration (tok->link (),
2668- variableId,
2669- scopeStack.top ().startVarid ,
2670- structMembers);
2671- }
2672-
2673- if (scopeInfo.empty ()) {
2674- variableId.clear ();
2675- } else {
2676- variableId.swap (scopeInfo.top ());
2677- scopeInfo.pop ();
2678- }
2647+ if (!Token::Match (startToken->previous (), " union|struct|enum {" ) &&
2648+ !(initlist && Token::Match (startToken->previous (), " %name%|>|>>" ) && Token::Match (startToken->link (), " } ,|{" ))) {
2649+
2650+ if (tok->str () == " {" ) {
2651+ bool isExecutable;
2652+ if (tok->strAt (-1 ) == " )" || Token::Match (tok->tokAt (-2 ), " ) %type%" ) ||
2653+ (initlist && tok->strAt (-1 ) == " }" )) {
2654+ isExecutable = true ;
2655+ } else {
2656+ isExecutable = ((scopeStack.top ().isExecutable || initlist || tok->strAt (-1 ) == " else" ) &&
2657+ !isClassStructUnionEnumStart (tok));
2658+ scopeInfo.push (variableId);
2659+ }
2660+ initlist = false ;
2661+ scopeStack.push (scopeStackEntryType (isExecutable, _varId));
2662+ } else { /* if (tok->str() == "}") */
2663+ bool isNamespace = false ;
2664+ for (const Token *tok1 = tok->link ()->previous (); tok1 && tok1->isName (); tok1 = tok1->previous ())
2665+ isNamespace |= (tok1->str () == " namespace" );
2666+ // Set variable ids in class declaration..
2667+ if (!initlist && !isC () && !scopeStack.top ().isExecutable && tok->link () && !isNamespace) {
2668+ setVarIdClassDeclaration (tok->link (),
2669+ variableId,
2670+ scopeStack.top ().startVarid ,
2671+ structMembers);
2672+ }
26792673
2680- scopeStack.pop ();
2681- if (scopeStack.empty ()) { // should be impossible
2682- scopeStack.push (scopeStackEntryType ());
2674+ if (scopeInfo.empty ()) {
2675+ variableId.clear ();
2676+ } else {
2677+ variableId.swap (scopeInfo.top ());
2678+ scopeInfo.pop ();
2679+ }
2680+
2681+ scopeStack.pop ();
2682+ if (scopeStack.empty ()) { // should be impossible
2683+ scopeStack.push (scopeStackEntryType ());
2684+ }
26832685 }
26842686 }
26852687 }
0 commit comments