MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / create

Method create

lib/summaries.cpp:38–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36
37
38std::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();

Callers

nothing calls this directly

Calls 10

joinFunction · 0.85
simplifyPathFunction · 0.85
nextMethod · 0.80
variableMethod · 0.80
linkAtMethod · 0.80
simpleMatchFunction · 0.70
isGlobalMethod · 0.45
nameMethod · 0.45
strMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected