@@ -1125,9 +1125,9 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
1125
1125
continue ;
1126
1126
}
1127
1127
1128
- TokenList tokenlist{&mSettings };
1129
-
1130
1128
try {
1129
+ TokenList tokenlist{&mSettings };
1130
+
1131
1131
// Create tokens, skip rest of iteration if failed
1132
1132
Timer::run (" Tokenizer::createTokens" , mSettings .showtime , &s_timerResults, [&]() {
1133
1133
simplecpp::TokenList tokensP = preprocessor.preprocess (tokens1, mCurrentConfig , files, true );
@@ -1136,66 +1136,71 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
1136
1136
hasValidConfig = true ;
1137
1137
1138
1138
Tokenizer tokenizer (std::move (tokenlist), mSettings , mErrorLogger );
1139
- if (mSettings .showtime != SHOWTIME_MODES::SHOWTIME_NONE)
1140
- tokenizer.setTimerResults (&s_timerResults);
1141
- tokenizer.setDirectives (directives); // TODO: how to avoid repeated copies?
1142
-
1143
- // locations macros
1144
- mLogger ->setLocationMacros (tokenizer.tokens (), files);
1145
-
1146
- // If only errors are printed, print filename after the check
1147
- if (!mSettings .quiet && (!mCurrentConfig .empty () || checkCount > 1 )) {
1148
- std::string fixedpath = Path::toNativeSeparators (file.spath ());
1149
- mErrorLogger .reportOut (" Checking " + fixedpath + " : " + mCurrentConfig + " ..." , Color::FgGreen);
1150
- }
1139
+ try {
1140
+ if (mSettings .showtime != SHOWTIME_MODES::SHOWTIME_NONE)
1141
+ tokenizer.setTimerResults (&s_timerResults);
1142
+ tokenizer.setDirectives (directives); // TODO: how to avoid repeated copies?
1143
+
1144
+ // locations macros
1145
+ mLogger ->setLocationMacros (tokenizer.tokens (), files);
1146
+
1147
+ // If only errors are printed, print filename after the check
1148
+ if (!mSettings .quiet && (!mCurrentConfig .empty () || checkCount > 1 )) {
1149
+ std::string fixedpath = Path::toNativeSeparators (file.spath ());
1150
+ mErrorLogger .reportOut (" Checking " + fixedpath + " : " + mCurrentConfig + " ..." , Color::FgGreen);
1151
+ }
1151
1152
1152
- if (!tokenizer.tokens ())
1153
- continue ;
1153
+ if (!tokenizer.tokens ())
1154
+ continue ;
1154
1155
1155
- // skip rest of iteration if just checking configuration
1156
- if (mSettings .checkConfiguration )
1157
- continue ;
1156
+ // skip rest of iteration if just checking configuration
1157
+ if (mSettings .checkConfiguration )
1158
+ continue ;
1158
1159
1159
1160
#ifdef HAVE_RULES
1160
- // Execute rules for "raw" code
1161
- executeRules (" raw" , tokenizer.list );
1161
+ // Execute rules for "raw" code
1162
+ executeRules (" raw" , tokenizer.list );
1162
1163
#endif
1163
1164
1164
- // Simplify tokens into normal form, skip rest of iteration if failed
1165
- if (!tokenizer.simplifyTokens1 (mCurrentConfig ))
1166
- continue ;
1165
+ // Simplify tokens into normal form, skip rest of iteration if failed
1166
+ if (!tokenizer.simplifyTokens1 (mCurrentConfig ))
1167
+ continue ;
1167
1168
1168
- // dump xml if --dump
1169
- if ((mSettings .dump || !mSettings .addons .empty ()) && fdump.is_open ()) {
1170
- fdump << " <dump cfg=\" " << ErrorLogger::toxml (mCurrentConfig ) << " \" >" << std::endl;
1171
- fdump << " <standards>" << std::endl;
1172
- fdump << " <c version=\" " << mSettings .standards .getC () << " \" />" << std::endl;
1173
- fdump << " <cpp version=\" " << mSettings .standards .getCPP () << " \" />" << std::endl;
1174
- fdump << " </standards>" << std::endl;
1175
- fdump << getLibraryDumpData ();
1176
- preprocessor.dump (fdump);
1177
- tokenizer.dump (fdump);
1178
- fdump << " </dump>" << std::endl;
1179
- }
1169
+ // dump xml if --dump
1170
+ if ((mSettings .dump || !mSettings .addons .empty ()) && fdump.is_open ()) {
1171
+ fdump << " <dump cfg=\" " << ErrorLogger::toxml (mCurrentConfig ) << " \" >" << std::endl;
1172
+ fdump << " <standards>" << std::endl;
1173
+ fdump << " <c version=\" " << mSettings .standards .getC () << " \" />" << std::endl;
1174
+ fdump << " <cpp version=\" " << mSettings .standards .getCPP () << " \" />" << std::endl;
1175
+ fdump << " </standards>" << std::endl;
1176
+ fdump << getLibraryDumpData ();
1177
+ preprocessor.dump (fdump);
1178
+ tokenizer.dump (fdump);
1179
+ fdump << " </dump>" << std::endl;
1180
+ }
1180
1181
1181
- if (mSettings .inlineSuppressions ) {
1182
- // Need to call this even if the hash will skip this configuration
1183
- mSuppressions .nomsg .markUnmatchedInlineSuppressionsAsChecked (tokenizer);
1184
- }
1182
+ if (mSettings .inlineSuppressions ) {
1183
+ // Need to call this even if the hash will skip this configuration
1184
+ mSuppressions .nomsg .markUnmatchedInlineSuppressionsAsChecked (tokenizer);
1185
+ }
1185
1186
1186
- // Skip if we already met the same simplified token list
1187
- if (mSettings .force || mSettings .maxConfigs > 1 ) {
1188
- const std::size_t hash = tokenizer.list .calculateHash ();
1189
- if (hashes.find (hash) != hashes.end ()) {
1190
- if (mSettings .debugwarnings )
1191
- purgedConfigurationMessage (file.spath (), mCurrentConfig );
1192
- continue ;
1187
+ // Skip if we already met the same simplified token list
1188
+ if (mSettings .force || mSettings .maxConfigs > 1 ) {
1189
+ const std::size_t hash = tokenizer.list .calculateHash ();
1190
+ if (hashes.find (hash) != hashes.end ()) {
1191
+ if (mSettings .debugwarnings )
1192
+ purgedConfigurationMessage (file.spath (), mCurrentConfig );
1193
+ continue ;
1194
+ }
1195
+ hashes.insert (hash);
1193
1196
}
1194
- hashes.insert (hash);
1195
- }
1196
1197
1197
- // Check normal tokens
1198
- checkNormalTokens (tokenizer, analyzerInformation.get ());
1198
+ // Check normal tokens
1199
+ checkNormalTokens (tokenizer, analyzerInformation.get ());
1200
+ } catch (const InternalError &e) {
1201
+ ErrorMessage errmsg = ErrorMessage::fromInternalError (e, &tokenizer.list , file.spath ());
1202
+ mErrorLogger .reportErr (errmsg);
1203
+ }
1199
1204
} catch (const simplecpp::Output &o) {
1200
1205
// #error etc during preprocessing
1201
1206
configurationError.push_back ((mCurrentConfig .empty () ? " \'\' " : mCurrentConfig ) + " : [" + o.location .file () + ' :' + std::to_string (o.location .line ) + " ] " + o.msg );
@@ -1225,7 +1230,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
1225
1230
mLogger ->setAnalyzerInfo (nullptr );
1226
1231
return mLogger ->exitcode ();
1227
1232
} catch (const InternalError &e) {
1228
- ErrorMessage errmsg = ErrorMessage::fromInternalError (e, &tokenlist , file.spath ());
1233
+ ErrorMessage errmsg = ErrorMessage::fromInternalError (e, nullptr , file.spath ());
1229
1234
mErrorLogger .reportErr (errmsg);
1230
1235
}
1231
1236
}
0 commit comments