| 36 | |
| 37 | |
| 38 | std::string Summaries::create(const Tokenizer &tokenizer, const std::string &cfg, std::size_t fsFileId) |
| 39 | { |
| 40 | const SymbolDatabase *symbolDatabase = tokenizer.getSymbolDatabase(); |
| 41 | const Settings &settings = tokenizer.getSettings(); |
| 42 | |
| 43 | std::ostringstream ostr; |
| 44 | for (const Scope *scope : symbolDatabase->functionScopes) { |
| 45 | const Function *f = scope->function; |
| 46 | if (!f) |
| 47 | continue; |
| 48 | |
| 49 | // Summarize function |
| 50 | std::set<std::string> noreturn; |
| 51 | std::set<std::string> globalVars; |
| 52 | std::set<std::string> calledFunctions; |
| 53 | for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { |
| 54 | if (tok->variable() && tok->variable()->isGlobal()) |
| 55 | globalVars.insert(tok->variable()->name()); |
| 56 | if (Token::Match(tok, "%name% (") && !Token::simpleMatch(tok->linkAt(1), ") {")) { |
| 57 | calledFunctions.insert(tok->str()); |
| 58 | if (Token::simpleMatch(tok->linkAt(1), ") ; }")) |
| 59 | noreturn.insert(tok->str()); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | // Write summary for function |
| 64 | auto join = [](const std::set<std::string> &data) -> std::string { |
| 65 | std::string ret; |
| 66 | const char *sep = ""; |
| 67 | for (const std::string &d: data) |
| 68 | { |
| 69 | ret += sep + d; |
| 70 | sep = ","; |
| 71 | } |
| 72 | return ret; |
| 73 | }; |
| 74 | |
| 75 | ostr << f->name(); |
| 76 | if (!globalVars.empty()) |
| 77 | ostr << " global:[" << join(globalVars) << "]"; |
| 78 | if (!calledFunctions.empty()) |
| 79 | ostr << " call:[" << join(calledFunctions) << "]"; |
| 80 | if (!noreturn.empty()) |
| 81 | ostr << " noreturn:[" << join(noreturn) << "]"; |
| 82 | ostr << std::endl; |
| 83 | } |
| 84 | |
| 85 | if (!settings.buildDir.empty()) { |
| 86 | std::string filename = AnalyzerInformation::getAnalyzerInfoFile(settings.buildDir, Path::simplifyPath(tokenizer.list.getSourceFilePath()), cfg, fsFileId); |
| 87 | const std::string::size_type pos = filename.rfind(".a"); |
| 88 | if (pos != std::string::npos) { |
| 89 | filename[pos+1] = 's'; |
| 90 | std::ofstream fout(filename); |
| 91 | fout << ostr.str(); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return ostr.str(); |
nothing calls this directly
no test coverage detected