42 std::ostringstream ostr;
49 std::set<std::string> noreturn;
50 std::set<std::string> globalVars;
51 std::set<std::string> calledFunctions;
53 if (tok->variable() && tok->variable()->isGlobal())
54 globalVars.insert(tok->variable()->name());
56 calledFunctions.insert(tok->str());
58 noreturn.insert(tok->str());
63 auto join = [](
const std::set<std::string> &data) -> std::string {
66 for (
const std::string &d: data)
75 if (!globalVars.empty())
76 ostr <<
" global:[" <<
join(globalVars) <<
"]";
77 if (!calledFunctions.empty())
78 ostr <<
" call:[" <<
join(calledFunctions) <<
"]";
79 if (!noreturn.empty())
80 ostr <<
" noreturn:[" <<
join(noreturn) <<
"]";
86 const std::string::size_type pos = filename.rfind(
".a");
87 if (pos != std::string::npos) {
88 filename[pos+1] =
's';
89 std::ofstream fout(filename);
102 std::vector<std::string> ret;
103 std::ifstream fin(filename);
107 while (std::getline(fin, line)) {
108 const std::string::size_type dotA = line.find(
".a");
109 const std::string::size_type colon = line.find(
':');
110 if (colon > line.size() || dotA > colon)
112 std::string f = line.substr(0,colon);
114 ret.push_back(std::move(f));
119 static std::vector<std::string>
getSummaryData(
const std::string &line,
const std::string &data)
121 std::vector<std::string> ret;
122 const std::string::size_type start = line.find(
" " + data +
":[");
123 if (start == std::string::npos)
125 const std::string::size_type end = line.find(
']', start);
126 if (end >= line.size())
129 std::string::size_type pos1 = start + 3 + data.size();
131 const std::string::size_type pos2 = line.find_first_of(
",]",pos1);
132 ret.push_back(line.substr(pos1, pos2-pos1-1));
140 std::map<std::string, std::vector<std::string>> &functionCalledBy,
141 std::map<std::string, std::vector<std::string>> &functionCalls,
142 std::vector<std::string> &add)
144 std::vector<std::string> calledBy = functionCalledBy[calledFunction];
145 functionCalledBy.erase(calledFunction);
146 for (
const std::string &c: calledBy) {
147 std::vector<std::string> &calls = functionCalls[c];
148 calls.erase(std::remove(calls.begin(), calls.end(), calledFunction), calls.end());
150 add.push_back(calledFunction);
158 if (buildDir.empty())
161 std::vector<std::string> return1;
162 std::map<std::string, std::vector<std::string>> functionCalls;
163 std::map<std::string, std::vector<std::string>> functionCalledBy;
166 std::vector<std::string> summaryFiles =
getSummaryFiles(buildDir +
"/files.txt");
167 for (
const std::string &filename: summaryFiles) {
168 std::ifstream fin(buildDir +
'/' + filename);
172 while (std::getline(fin, line)) {
174 constexpr std::string::size_type pos1 = 0;
175 const std::string::size_type pos2 = line.find(
' ', pos1);
176 const std::string functionName = (pos2 == std::string::npos) ? line : line.substr(0, pos2);
178 functionCalls[functionName] = call;
180 return1.push_back(functionName);
182 for (
const std::string &c: call) {
183 functionCalledBy[c].push_back(functionName);
188 summaryReturn.insert(return1.cbegin(), return1.cend());
191 for (
const std::string &f: return1) {
192 std::vector<std::string> return2;
194 summaryReturn.insert(return2.cbegin(), return2.cend());
const std::string & name() const
Function * function
function info for this function
const Token * bodyStart
'{' token
const Token * bodyEnd
'}' token
This is just a container for general settings so that we don't need to pass individual values to func...
std::string buildDir
–cppcheck-build-dir.
std::vector< const Scope * > functionScopes
Fast access to function scopes.
const std::string & getSourceFilePath() const
The token list that the TokenList generates is a linked-list of this class.
static bool Match(const Token *tok, const char pattern[], nonneg int varid=0)
Match given token (or list of tokens) to a pattern list.
static bool simpleMatch(const Token *tok, const char(&pattern)[count])
Match given token (or list of tokens) to a pattern list.
The main purpose is to tokenize the source code.
const Settings & getSettings() const
TokenList list
Token list: stores all tokens.
const SymbolDatabase * getSymbolDatabase() const
static std::string join(const std::list< std::string > &strlist, const char *sep)
CPPCHECKLIB std::string create(const Tokenizer &tokenizer, const std::string &cfg)
CPPCHECKLIB void loadReturn(const std::string &buildDir, std::set< std::string > &summaryReturn)
static std::string cfg(const std::vector< std::string > &configs, const std::string &userDefines)
static void removeFunctionCalls(const std::string &calledFunction, std::map< std::string, std::vector< std::string >> &functionCalledBy, std::map< std::string, std::vector< std::string >> &functionCalls, std::vector< std::string > &add)
static std::vector< std::string > getSummaryData(const std::string &line, const std::string &data)
static std::vector< std::string > getSummaryFiles(const std::string &filename)