TODO: rename - it is not C++ specific
| 1181 | |
| 1182 | // TODO: rename - it is not C++ specific |
| 1183 | void Tokenizer::simplifyTypedefCpp() |
| 1184 | { |
| 1185 | const bool cpp = isCPP(); |
| 1186 | bool isNamespace = false; |
| 1187 | std::string className, fullClassName; |
| 1188 | bool hasClass = false; |
| 1189 | bool goback = false; |
| 1190 | |
| 1191 | // add global namespace |
| 1192 | std::vector<Space> spaceInfo(1); |
| 1193 | |
| 1194 | const std::time_t maxTime = mSettings.typedefMaxTime > 0 ? std::time(nullptr) + mSettings.typedefMaxTime: 0; |
| 1195 | ProgressReporter progressReporter(mErrorLogger, mSettings.reportProgress, list.getSourceFilePath(), "Tokenize (typedef)"); |
| 1196 | |
| 1197 | for (Token *tok = list.front(); tok; tok = tok->next()) { |
| 1198 | progressReporter.report(tok->progressValue()); |
| 1199 | |
| 1200 | if (Settings::terminated()) |
| 1201 | return; |
| 1202 | |
| 1203 | if (maxTime > 0 && std::time(nullptr) > maxTime) { |
| 1204 | if (mSettings.debugwarnings) { |
| 1205 | ErrorMessage::FileLocation loc(list.getFiles()[0], 0, 0); |
| 1206 | ErrorMessage errmsg({std::move(loc)}, |
| 1207 | "", |
| 1208 | Severity::debug, |
| 1209 | "Typedef simplification instantiation maximum time exceeded", |
| 1210 | "typedefMaxTime", |
| 1211 | Certainty::normal); |
| 1212 | mErrorLogger.reportErr(errmsg); |
| 1213 | } |
| 1214 | return; |
| 1215 | } |
| 1216 | |
| 1217 | if (goback) { |
| 1218 | //jump back once, see the comment at the end of the function |
| 1219 | goback = false; |
| 1220 | tok = tok->previous(); |
| 1221 | } |
| 1222 | |
| 1223 | if (tok->str() != "typedef") { |
| 1224 | if (Token::simpleMatch(tok, "( typedef")) { |
| 1225 | // Skip typedefs inside parentheses (#2453 and #4002) |
| 1226 | tok = tok->next(); |
| 1227 | } else if (Token::Match(tok, "class|struct|namespace %any%") && |
| 1228 | (!tok->previous() || tok->strAt(-1) != "enum")) { |
| 1229 | isNamespace = (tok->str() == "namespace"); |
| 1230 | hasClass = true; |
| 1231 | className = tok->strAt(1); |
| 1232 | const Token *tok1 = tok->next(); |
| 1233 | fullClassName = className; |
| 1234 | while (Token::Match(tok1, "%name% :: %name%")) { |
| 1235 | tok1 = tok1->tokAt(2); |
| 1236 | fullClassName += " :: " + tok1->str(); |
| 1237 | } |
| 1238 | } else if (hasClass && tok->str() == ";") { |
| 1239 | hasClass = false; |
| 1240 | } else if (hasClass && tok->str() == "{") { |
nothing calls this directly
no test coverage detected