@@ -610,7 +610,9 @@ void CheckClass::privateFunctions()
610610 if (!func->hasBody )
611611 {
612612 // empty private copy constructors and assignment operators are OK
613- if ((func->type == Function::eCopyConstructor || func->type == Function::eOperatorEqual) && func->access == Private)
613+ if ((func->type == Function::eCopyConstructor ||
614+ func->type == Function::eOperatorEqual) &&
615+ func->access == Private)
614616 continue ;
615617
616618 whole = false ;
@@ -630,98 +632,37 @@ void CheckClass::privateFunctions()
630632 for (func = scope->functionList .begin (); func != scope->functionList .end (); ++func)
631633 {
632634 // Get private functions..
633- if (func->type == Function::eFunction &&
634- func->access == Private && func->hasBody )
635+ if (func->type == Function::eFunction && func->access == Private)
635636 FuncList.push_back (func->tokenDef );
636637 }
637638 }
638639
639640 // Check that all private functions are used..
640- bool HasFuncImpl = false ;
641- bool inclass = false ;
642- int indent_level = 0 ;
643- for (const Token *ftok = _tokenizer->tokens (); ftok; ftok = ftok->next ())
641+ for (func = scope->functionList .begin (); func != scope->functionList .end (); ++func)
644642 {
645- if (ftok->str () == " {" )
646- ++indent_level;
647- else if (ftok->str () == " }" )
648- {
649- if (indent_level > 0 )
650- --indent_level;
651- if (indent_level == 0 )
652- inclass = false ;
653- }
654-
655- else if (ftok->str () == " class" &&
656- ftok->next ()->str () == classname &&
657- Token::Match (ftok->tokAt (2 ), " :|{" ))
658- {
659- indent_level = 0 ;
660- inclass = true ;
661- }
662-
663- // Check member class functions to see what functions are used..
664- else if ((inclass && indent_level == 1 && Token::Match (ftok, " %var% (" )) ||
665- (ftok->str () == classname && Token::Match (ftok->next (), " :: ~| %var% (" )))
643+ const Token *ftok = func->arg ->link ()->next ();
644+ while (ftok->str () != " {" )
645+ ftok = ftok->next ();
646+ const Token *etok = ftok->link ();
647+
648+ for (; ftok != etok; ftok = ftok->next ())
666649 {
667- while (ftok && ftok->str () != " )" )
668- ftok = ftok->next ();
669- if (!ftok)
670- break ;
671- if (Token::Match (ftok, " ) : %var% (" ))
650+ if (Token::Match (ftok, " %var% (" ))
672651 {
673- while (!Token::Match (ftok->next (), " [{};]" ))
652+ // Remove function from FuncList
653+ std::list<const Token *>::iterator it = FuncList.begin ();
654+ while (it != FuncList.end ())
674655 {
675- if (Token::Match (ftok, " ::|,|( %var% ,|)" ))
676- {
677- // Remove function from FuncList
678- std::list<const Token *>::iterator it = FuncList.begin ();
679- while (it != FuncList.end ())
680- {
681- if (ftok->next ()->str () == (*it)->str ())
682- FuncList.erase (it++);
683- else
684- ++it;
685- }
686- }
687- ftok = ftok->next ();
688- }
689- }
690- if (!Token::Match (ftok, " ) const| {" ))
691- continue ;
692-
693- if (ftok->fileIndex () == 0 )
694- HasFuncImpl = true ;
695-
696- // Parse function..
697- int indentlevel2 = 0 ;
698- for (const Token *tok2 = ftok; tok2; tok2 = tok2->next ())
699- {
700- if (tok2->str () == " {" )
701- ++indentlevel2;
702- else if (tok2->str () == " }" )
703- {
704- --indentlevel2;
705- if (indentlevel2 < 1 )
706- break ;
707- }
708- else if (Token::Match (tok2, " %var% (" ))
709- {
710- // Remove function from FuncList
711- std::list<const Token *>::iterator it = FuncList.begin ();
712- while (it != FuncList.end ())
713- {
714- if (tok2->str () == (*it)->str ())
715- FuncList.erase (it++);
716- else
717- ++it;
718- }
656+ if (ftok->str () == (*it)->str ())
657+ FuncList.erase (it++);
658+ else
659+ ++it;
719660 }
720661 }
721662 }
722663 }
723664
724- while (HasFuncImpl && !FuncList.empty ())
665+ while (!FuncList.empty ())
725666 {
726667 // Final check; check if the function pointer is used somewhere..
727668 const std::string _pattern (" return|(|)|,|= " + FuncList.front ()->str ());
0 commit comments