@@ -819,20 +819,17 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
819819
820820#ifdef HAVE_RULES
821821 // Run define rules on raw code
822- const auto rules_it = std::find_if (mSettings .rules .cbegin (), mSettings .rules .cend (), [](const Settings::Rule& rule) {
823- return rule.tokenlist == " define" ;
824- });
825- if (rules_it != mSettings .rules .cend ()) {
822+ if (hasRule (" define" )) {
826823 std::string code;
827- const std::list<Directive> &directives = preprocessor.getDirectives ();
828- for (const Directive &dir : directives) {
824+ for (const Directive &dir : preprocessor.getDirectives ()) {
829825 if (startsWith (dir.str ," #define " ) || startsWith (dir.str ," #include " ))
830826 code += " #line " + std::to_string (dir.linenr ) + " \" " + dir.file + " \"\n " + dir.str + ' \n ' ;
831827 }
832- Tokenizer tokenizer2 ( mSettings , this );
828+ TokenList tokenlist (& mSettings );
833829 std::istringstream istr2 (code);
834- tokenizer2.list .createTokens (istr2, Path::identify (*files.begin ()));
835- executeRules (" define" , tokenizer2);
830+ // TODO: asserts when file has unknown extension
831+ tokenlist.createTokens (istr2, Path::identify (*files.begin ())); // TODO: check result?
832+ executeRules (" define" , tokenlist);
836833 }
837834#endif
838835
@@ -924,8 +921,10 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
924921 if (mSettings .checkConfiguration )
925922 continue ;
926923
927- // Check raw tokens
928- checkRawTokens (tokenizer);
924+ #ifdef HAVE_RULES
925+ // Execute rules for "raw" code
926+ executeRules (" raw" , tokenizer.list );
927+ #endif
929928
930929 // Simplify tokens into normal form, skip rest of iteration if failed
931930 if (!tokenizer.simplifyTokens1 (mCurrentConfig ))
@@ -959,13 +958,6 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
959958
960959 // Check normal tokens
961960 checkNormalTokens (tokenizer);
962-
963- #ifdef HAVE_RULES
964- // handling of "simple" rules has been removed.
965- if (hasRule (" simple" ))
966- throw InternalError (nullptr , " Handling of \" simple\" rules has been removed in Cppcheck. Use --addon instead." );
967- #endif
968-
969961 } catch (const simplecpp::Output &o) {
970962 // #error etc during preprocessing
971963 configurationError.push_back ((mCurrentConfig .empty () ? " \'\' " : mCurrentConfig ) + " : [" + o.location .file () + ' :' + std::to_string (o.location .line ) + " ] " + o.msg );
@@ -1072,19 +1064,6 @@ void CppCheck::internalError(const std::string &filename, const std::string &msg
10721064 mErrorLogger .reportErr (errmsg);
10731065}
10741066
1075- // ---------------------------------------------------------------------------
1076- // CppCheck - A function that checks a raw token list
1077- // ---------------------------------------------------------------------------
1078- void CppCheck::checkRawTokens (const Tokenizer &tokenizer)
1079- {
1080- #ifdef HAVE_RULES
1081- // Execute rules for "raw" code
1082- executeRules (" raw" , tokenizer);
1083- #else
1084- (void )tokenizer;
1085- #endif
1086- }
1087-
10881067// ---------------------------------------------------------------------------
10891068// CppCheck - A function that checks a normal token list
10901069// ---------------------------------------------------------------------------
@@ -1169,7 +1148,7 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
11691148 }
11701149
11711150#ifdef HAVE_RULES
1172- executeRules (" normal" , tokenizer);
1151+ executeRules (" normal" , tokenizer. list );
11731152#endif
11741153}
11751154
@@ -1312,15 +1291,15 @@ static const char * pcreErrorCodeToString(const int pcreExecRet)
13121291 return " " ;
13131292}
13141293
1315- void CppCheck::executeRules (const std::string &tokenlist, const Tokenizer &tokenizer )
1294+ void CppCheck::executeRules (const std::string &tokenlist, const TokenList &list )
13161295{
13171296 // There is no rule to execute
13181297 if (!hasRule (tokenlist))
13191298 return ;
13201299
13211300 // Write all tokens in a string that can be parsed by pcre
13221301 std::ostringstream ostr;
1323- for (const Token *tok = tokenizer. tokens (); tok; tok = tok->next ())
1302+ for (const Token *tok = list. front (); tok; tok = tok->next ())
13241303 ostr << " " << tok->str ();
13251304 const std::string str (ostr.str ());
13261305
@@ -1400,14 +1379,14 @@ void CppCheck::executeRules(const std::string &tokenlist, const Tokenizer &token
14001379 pos = (int )pos2;
14011380
14021381 // determine location..
1403- std::string file = tokenizer. list .getSourceFilePath ();
1382+ std::string file = list.getSourceFilePath ();
14041383 int line = 0 ;
14051384
14061385 std::size_t len = 0 ;
1407- for (const Token *tok = tokenizer. tokens (); tok; tok = tok->next ()) {
1386+ for (const Token *tok = list. front (); tok; tok = tok->next ()) {
14081387 len = len + 1U + tok->str ().size ();
14091388 if (len > pos1) {
1410- file = tokenizer. list .getFiles ().at (tok->fileIndex ());
1389+ file = list.getFiles ().at (tok->fileIndex ());
14111390 line = tok->linenr ();
14121391 break ;
14131392 }
@@ -1421,7 +1400,7 @@ void CppCheck::executeRules(const std::string &tokenlist, const Tokenizer &token
14211400 summary = " found '" + str.substr (pos1, pos2 - pos1) + " '" ;
14221401 else
14231402 summary = rule.summary ;
1424- const ErrorMessage errmsg ({std::move (loc)}, tokenizer. list .getSourceFilePath (), rule.severity , summary, rule.id , Certainty::normal);
1403+ const ErrorMessage errmsg ({std::move (loc)}, list.getSourceFilePath (), rule.severity , summary, rule.id , Certainty::normal);
14251404
14261405 // Report error
14271406 reportErr (errmsg);
0 commit comments