From 37a5ec8cd5bf971b242dae3a8997cd04736b8090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 20 Dec 2020 19:53:58 +0100 Subject: [PATCH] Summaries: Moved to its own files --- Makefile | 12 ++- lib/cppcheck.vcxproj | 2 + lib/lib.pri | 2 + lib/settings.cpp | 100 +---------------------- lib/settings.h | 1 - lib/summaries.cpp | 175 ++++++++++++++++++++++++++++++++++++++++ lib/summaries.h | 36 +++++++++ lib/tokenize.cpp | 62 +------------- lib/tokenize.h | 2 - test/testrunner.vcxproj | 3 +- test/testsummaries.cpp | 64 +++++++++++++++ test/testtokenize.cpp | 28 ------- 12 files changed, 295 insertions(+), 192 deletions(-) create mode 100644 lib/summaries.cpp create mode 100644 lib/summaries.h create mode 100644 test/testsummaries.cpp diff --git a/Makefile b/Makefile index 0ff5a0fbb..cd134ca9a 100644 --- a/Makefile +++ b/Makefile @@ -203,6 +203,7 @@ LIBOBJ = $(libcppdir)/analyzerinfo.o \ $(libcppdir)/programmemory.o \ $(libcppdir)/reverseanalyzer.o \ $(libcppdir)/settings.o \ + $(libcppdir)/summaries.o \ $(libcppdir)/suppressions.o \ $(libcppdir)/symboldatabase.o \ $(libcppdir)/templatesimplifier.o \ @@ -270,6 +271,7 @@ TESTOBJ = test/options.o \ test/teststl.o \ test/teststring.o \ test/testsuite.o \ + test/testsummaries.o \ test/testsuppressions.o \ test/testsymboldatabase.o \ test/testthreadexecutor.o \ @@ -542,9 +544,12 @@ $(libcppdir)/programmemory.o: lib/programmemory.cpp lib/astutils.h lib/config.h $(libcppdir)/reverseanalyzer.o: lib/reverseanalyzer.cpp lib/analyzer.h lib/astutils.h lib/config.h lib/errortypes.h lib/forwardanalyzer.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/reverseanalyzer.h lib/settings.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/utils.h lib/valueflow.h lib/valueptr.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/reverseanalyzer.o $(libcppdir)/reverseanalyzer.cpp -$(libcppdir)/settings.o: lib/settings.cpp lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h lib/valueflow.h +$(libcppdir)/settings.o: lib/settings.cpp lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/summaries.h lib/suppressions.h lib/timer.h lib/utils.h lib/valueflow.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/settings.o $(libcppdir)/settings.cpp +$(libcppdir)/summaries.o: lib/summaries.cpp lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/summaries.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/utils.h lib/valueflow.h + $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/summaries.o $(libcppdir)/summaries.cpp + $(libcppdir)/suppressions.o: lib/suppressions.cpp externals/tinyxml2/tinyxml2.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/mathlib.h lib/path.h lib/suppressions.h lib/utils.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/suppressions.o $(libcppdir)/suppressions.cpp @@ -560,7 +565,7 @@ $(libcppdir)/timer.o: lib/timer.cpp lib/config.h lib/timer.h $(libcppdir)/token.o: lib/token.cpp lib/astutils.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenlist.h lib/utils.h lib/valueflow.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/token.o $(libcppdir)/token.cpp -$(libcppdir)/tokenize.o: lib/tokenize.cpp externals/simplecpp/simplecpp.h lib/check.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h +$(libcppdir)/tokenize.o: lib/tokenize.cpp externals/simplecpp/simplecpp.h lib/analyzerinfo.h lib/check.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/tokenize.o $(libcppdir)/tokenize.cpp $(libcppdir)/tokenlist.o: lib/tokenlist.cpp externals/simplecpp/simplecpp.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenlist.h lib/utils.h lib/valueflow.h @@ -731,6 +736,9 @@ test/teststring.o: test/teststring.cpp lib/check.h lib/checkstring.h lib/config. test/testsuite.o: test/testsuite.cpp lib/config.h lib/errorlogger.h lib/errortypes.h lib/suppressions.h test/options.h test/redirect.h test/testsuite.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testsuite.o test/testsuite.cpp +test/testsummaries.o: test/testsummaries.cpp lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/summaries.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h test/testsuite.h + $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testsummaries.o test/testsummaries.cpp + test/testsuppressions.o: test/testsuppressions.cpp cli/threadexecutor.h lib/analyzerinfo.h lib/check.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h test/testsuite.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testsuppressions.o test/testsuppressions.cpp diff --git a/lib/cppcheck.vcxproj b/lib/cppcheck.vcxproj index f4d1e87ff..10437c25b 100644 --- a/lib/cppcheck.vcxproj +++ b/lib/cppcheck.vcxproj @@ -91,6 +91,7 @@ + @@ -150,6 +151,7 @@ + diff --git a/lib/lib.pri b/lib/lib.pri index 16d0f2df0..164686bc6 100644 --- a/lib/lib.pri +++ b/lib/lib.pri @@ -50,6 +50,7 @@ HEADERS += $${PWD}/analyzerinfo.h \ $${PWD}/programmemory.h \ $${PWD}/reverseanalyzer.h \ $${PWD}/settings.h \ + $${PWD}/summaries.h \ $${PWD}/suppressions.h \ $${PWD}/symboldatabase.h \ $${PWD}/templatesimplifier.h \ @@ -107,6 +108,7 @@ SOURCES += $${PWD}/analyzerinfo.cpp \ $${PWD}/programmemory.cpp \ $${PWD}/reverseanalyzer.cpp \ $${PWD}/settings.cpp \ + $${PWD}/summaries.cpp \ $${PWD}/suppressions.cpp \ $${PWD}/symboldatabase.cpp \ $${PWD}/templatesimplifier.cpp \ diff --git a/lib/settings.cpp b/lib/settings.cpp index e93c2031f..f891c7d7d 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -17,12 +17,9 @@ */ #include "settings.h" - +#include "summaries.h" #include "valueflow.h" -#include -#include - std::atomic Settings::mTerminated; const char Settings::SafeChecks::XmlRootName[] = "safe-checks"; @@ -159,100 +156,7 @@ bool Settings::isEnabled(const ValueFlow::Value *value, bool inconclusiveCheck) return true; } -static std::vector getSummaryFiles(const std::string &filename) -{ - std::vector ret; - std::ifstream fin(filename); - if (!fin.is_open()) - return ret; - std::string line; - while (std::getline(fin, line)) { - std::string::size_type dotA = line.find(".a"); - std::string::size_type colon = line.find(":"); - if (colon > line.size() || dotA > colon) - continue; - std::string f = line.substr(0,colon); - f[dotA + 1] = 's'; - ret.push_back(f); - } - return ret; -} - -static std::vector getSummaryData(const std::string &line, const std::string &data) -{ - std::vector ret; - const std::string::size_type start = line.find(" " + data + ":["); - if (start == std::string::npos) - return ret; - const std::string::size_type end = line.find("]", start); - if (end >= line.size()) - return ret; - - std::string::size_type pos1 = start + 3 + data.size(); - while (pos1 < end) { - std::string::size_type pos2 = line.find_first_of(",]",pos1); - ret.push_back(line.substr(pos1, pos2-pos1-1)); - pos1 = pos2 + 1; - } - - return ret; -} - -static void removeFunctionCalls(const std::string& calledFunction, - std::map> &functionCalledBy, - std::map> &functionCalls, - std::vector &add) -{ - std::vector calledBy = functionCalledBy[calledFunction]; - functionCalledBy.erase(calledFunction); - for (const std::string &c: calledBy) { - std::vector &calls = functionCalls[c]; - calls.erase(std::remove(calls.begin(), calls.end(), calledFunction), calls.end()); - if (calls.empty()) { - add.push_back(calledFunction); - removeFunctionCalls(c, functionCalledBy, functionCalls, add); - } - } -} - void Settings::loadSummaries() { - if (buildDir.empty()) - return; - - std::vector return1; - std::map> functionCalls; - std::map> functionCalledBy; - - // extract "functionNoreturn" and "functionCalledBy" from summaries - std::vector summaryFiles = getSummaryFiles(buildDir + "/files.txt"); - for (const std::string &filename: summaryFiles) { - std::ifstream fin(buildDir + '/' + filename); - if (!fin.is_open()) - continue; - std::string line; - while (std::getline(fin, line)) { - // Get function name - const std::string::size_type pos1 = 0; - const std::string::size_type pos2 = line.find(" ", pos1); - const std::string functionName = (pos2 == std::string::npos) ? line : line.substr(0, pos2); - std::vector call = getSummaryData(line, "call"); - functionCalls[functionName] = call; - if (call.empty()) - return1.push_back(functionName); - else { - for (const std::string &c: call) { - functionCalledBy[c].push_back(functionName); - } - } - } - } - summaryReturn.insert(return1.cbegin(), return1.cend()); - - // recursively set "summaryNoreturn" - for (const std::string &f: return1) { - std::vector return2; - removeFunctionCalls(f, functionCalledBy, functionCalls, return2); - summaryReturn.insert(return2.cbegin(), return2.cend()); - } + Summaries::loadReturn(buildDir, summaryReturn); } diff --git a/lib/settings.h b/lib/settings.h index f8f0152d6..0300e589d 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -419,7 +419,6 @@ public: std::set summaryReturn; void loadSummaries(); - }; /// @} diff --git a/lib/summaries.cpp b/lib/summaries.cpp new file mode 100644 index 000000000..39497ed15 --- /dev/null +++ b/lib/summaries.cpp @@ -0,0 +1,175 @@ + +#include "summaries.h" + +#include "analyzerinfo.h" +#include "settings.h" +#include "symboldatabase.h" +#include "tokenize.h" + +#include +#include +#include +#include + + + +std::string Summaries::create(const Tokenizer *tokenizer, const std::string &cfg) +{ + const SymbolDatabase *symbolDatabase = tokenizer->getSymbolDatabase(); + const Settings *settings = tokenizer->getSettings(); + + std::ostringstream ostr; + for (const Scope *scope : symbolDatabase->functionScopes) { + const Function *f = scope->function; + if (!f) + continue; + + // Summarize function + std::set noreturn; + std::set globalVars; + std::set calledFunctions; + for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { + if (tok->variable() && tok->variable()->isGlobal()) + globalVars.insert(tok->variable()->name()); + if (Token::Match(tok, "%name% (") && !Token::simpleMatch(tok->linkAt(1), ") {")) { + calledFunctions.insert(tok->str()); + if (Token::simpleMatch(tok->linkAt(1), ") ; }")) + noreturn.insert(tok->str()); + } + } + + // Write summary for function + auto join = [](const std::set &data) -> std::string { + std::string ret; + const char *sep = ""; + for (std::string d: data) + { + ret += sep + d; + sep = ","; + } + return ret; + }; + + ostr << f->name(); + if (!globalVars.empty()) + ostr << " global:[" << join(globalVars) << "]"; + if (!calledFunctions.empty()) + ostr << " call:[" << join(calledFunctions) << "]"; + if (!noreturn.empty()) + ostr << " noreturn:[" << join(noreturn) << "]"; + ostr << std::endl; + } + + if (!settings->buildDir.empty()) { + std::string filename = AnalyzerInformation::getAnalyzerInfoFile(settings->buildDir, tokenizer->list.getSourceFilePath(), cfg); + std::string::size_type pos = filename.rfind(".a"); + if (pos != std::string::npos) { + filename[pos+1] = 's'; + std::ofstream fout(filename); + fout << ostr.str(); + } + } + + return ostr.str(); +} + + + + +static std::vector getSummaryFiles(const std::string &filename) +{ + std::vector ret; + std::ifstream fin(filename); + if (!fin.is_open()) + return ret; + std::string line; + while (std::getline(fin, line)) { + std::string::size_type dotA = line.find(".a"); + std::string::size_type colon = line.find(":"); + if (colon > line.size() || dotA > colon) + continue; + std::string f = line.substr(0,colon); + f[dotA + 1] = 's'; + ret.push_back(f); + } + return ret; +} + +static std::vector getSummaryData(const std::string &line, const std::string &data) +{ + std::vector ret; + const std::string::size_type start = line.find(" " + data + ":["); + if (start == std::string::npos) + return ret; + const std::string::size_type end = line.find("]", start); + if (end >= line.size()) + return ret; + + std::string::size_type pos1 = start + 3 + data.size(); + while (pos1 < end) { + std::string::size_type pos2 = line.find_first_of(",]",pos1); + ret.push_back(line.substr(pos1, pos2-pos1-1)); + pos1 = pos2 + 1; + } + + return ret; +} + +static void removeFunctionCalls(const std::string& calledFunction, + std::map> &functionCalledBy, + std::map> &functionCalls, + std::vector &add) +{ + std::vector calledBy = functionCalledBy[calledFunction]; + functionCalledBy.erase(calledFunction); + for (const std::string &c: calledBy) { + std::vector &calls = functionCalls[c]; + calls.erase(std::remove(calls.begin(), calls.end(), calledFunction), calls.end()); + if (calls.empty()) { + add.push_back(calledFunction); + removeFunctionCalls(c, functionCalledBy, functionCalls, add); + } + } +} + +void Summaries::loadReturn(const std::string &buildDir, std::set &summaryReturn) +{ + if (buildDir.empty()) + return; + + std::vector return1; + std::map> functionCalls; + std::map> functionCalledBy; + + // extract "functionNoreturn" and "functionCalledBy" from summaries + std::vector summaryFiles = getSummaryFiles(buildDir + "/files.txt"); + for (const std::string &filename: summaryFiles) { + std::ifstream fin(buildDir + '/' + filename); + if (!fin.is_open()) + continue; + std::string line; + while (std::getline(fin, line)) { + // Get function name + const std::string::size_type pos1 = 0; + const std::string::size_type pos2 = line.find(" ", pos1); + const std::string functionName = (pos2 == std::string::npos) ? line : line.substr(0, pos2); + std::vector call = getSummaryData(line, "call"); + functionCalls[functionName] = call; + if (call.empty()) + return1.push_back(functionName); + else { + for (const std::string &c: call) { + functionCalledBy[c].push_back(functionName); + } + } + } + } + summaryReturn.insert(return1.cbegin(), return1.cend()); + + // recursively set "summaryNoreturn" + for (const std::string &f: return1) { + std::vector return2; + removeFunctionCalls(f, functionCalledBy, functionCalls, return2); + summaryReturn.insert(return2.cbegin(), return2.cend()); + } +} diff --git a/lib/summaries.h b/lib/summaries.h new file mode 100644 index 000000000..d8bdb6130 --- /dev/null +++ b/lib/summaries.h @@ -0,0 +1,36 @@ +/* +* Cppcheck - A tool for static C/C++ code analysis +* Copyright (C) 2007-2020 Cppcheck team. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +//--------------------------------------------------------------------------- +#ifndef summariesH +#define summariesH +//--------------------------------------------------------------------------- + +#include +#include + +class Tokenizer; + +namespace Summaries { + std::string create(const Tokenizer *tokenizer, const std::string &cfg); + void loadReturn(const std::string &buildDir, std::set &summaryReturn); +} + +//--------------------------------------------------------------------------- +#endif +//--------------------------------------------------------------------------- diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 571e658e3..a4a13d21a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -19,7 +19,6 @@ //--------------------------------------------------------------------------- #include "tokenize.h" -#include "analyzerinfo.h" #include "check.h" #include "errorlogger.h" #include "library.h" @@ -28,6 +27,7 @@ #include "preprocessor.h" #include "settings.h" #include "standards.h" +#include "summaries.h" #include "symboldatabase.h" #include "templatesimplifier.h" #include "timer.h" @@ -2379,7 +2379,7 @@ bool Tokenizer::simplifyTokens1(const std::string &configuration) } if (!mSettings->buildDir.empty()) - createSummaries(configuration); + Summaries::create(this, configuration); if (mTimerResults) { Timer t("Tokenizer::simplifyTokens1::ValueFlow", mSettings->showtime, mTimerResults); @@ -12070,61 +12070,3 @@ bool Tokenizer::hasIfdef(const Token *start, const Token *end) const } return false; } - -std::string Tokenizer::createSummaries(const std::string &configuration) const -{ - std::ostringstream ostr; - for (const Scope *scope : mSymbolDatabase->functionScopes) { - const Function *f = scope->function; - if (!f) - continue; - - // Summarize function - std::set noreturn; - std::set globalVars; - std::set calledFunctions; - for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { - if (tok->variable() && tok->variable()->isGlobal()) - globalVars.insert(tok->variable()->name()); - if (Token::Match(tok, "%name% (") && !Token::simpleMatch(tok->linkAt(1), ") {")) { - calledFunctions.insert(tok->str()); - if (Token::simpleMatch(tok->linkAt(1), ") ; }")) - noreturn.insert(tok->str()); - } - } - - // Write summary for function - auto join = [](const std::set &data) -> std::string { - std::string ret; - const char *sep = ""; - for (std::string d: data) - { - ret += sep + d; - sep = ","; - } - return ret; - }; - - ostr << f->name(); - if (!globalVars.empty()) - ostr << " global:[" << join(globalVars) << "]"; - if (!calledFunctions.empty()) - ostr << " call:[" << join(calledFunctions) << "]"; - if (!noreturn.empty()) - ostr << " noreturn:[" << join(noreturn) << "]"; - ostr << std::endl; - } - - if (!mSettings->buildDir.empty()) { - std::string filename = AnalyzerInformation::getAnalyzerInfoFile(mSettings->buildDir, list.getSourceFilePath(), configuration); - std::string::size_type pos = filename.rfind(".a"); - if (pos != std::string::npos) { - filename[pos+1] = 's'; - std::ofstream fout(filename); - fout << ostr.str(); - } - } - - return ostr.str(); -} - diff --git a/lib/tokenize.h b/lib/tokenize.h index a123f41df..5a21be2aa 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -585,8 +585,6 @@ public: bool hasIfdef(const Token *start, const Token *end) const; - std::string createSummaries(const std::string &configuration) const; - private: /** diff --git a/test/testrunner.vcxproj b/test/testrunner.vcxproj index 41b64e74c..2c82f24f8 100755 --- a/test/testrunner.vcxproj +++ b/test/testrunner.vcxproj @@ -80,6 +80,7 @@ Create Create + @@ -312,4 +313,4 @@ - \ No newline at end of file + diff --git a/test/testsummaries.cpp b/test/testsummaries.cpp new file mode 100644 index 000000000..c2dadb030 --- /dev/null +++ b/test/testsummaries.cpp @@ -0,0 +1,64 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2020 Cppcheck team. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include "summaries.h" +#include "testsuite.h" + +#include "settings.h" +#include "tokenize.h" + + +class TestSummaries : public TestFixture { +public: + TestSummaries() : TestFixture("TestSummaries") {} + +private: + void run() OVERRIDE { + + TEST_CASE(createSummaries1); + TEST_CASE(createSummariesGlobal); + TEST_CASE(createSummariesNoreturn); + } + + std::string createSummaries(const char code[], const char filename[] = "test.cpp") { + // Clear the error buffer.. + errout.str(""); + + // tokenize.. + Settings settings; + Tokenizer tokenizer(&settings, this); + std::istringstream istr(code); + tokenizer.tokenize(istr, filename); + return Summaries::create(&tokenizer, ""); + } + + void createSummaries1() { + ASSERT_EQUALS("foo\n", createSummaries("void foo() {}")); + } + + void createSummariesGlobal() { + ASSERT_EQUALS("foo global:[x]\n", createSummaries("int x; void foo() { x=0; }")); + } + + void createSummariesNoreturn() { + ASSERT_EQUALS("foo call:[bar] noreturn:[bar]\n", createSummaries("void foo() { bar(); }")); + } +}; + +REGISTER_TEST(TestSummaries) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 8073b3203..0f862740d 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -520,10 +520,6 @@ private: TEST_CASE(checkHeader1); TEST_CASE(removeExtraTemplateKeywords); - - TEST_CASE(createSummaries1); - TEST_CASE(createSummariesGlobal); - TEST_CASE(createSummariesNoreturn); } std::string tokenizeAndStringify(const char code[], bool simplify = false, bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", bool cpp11 = true) { @@ -8753,30 +8749,6 @@ private: const char expected2[] = "GridView :: Codim < 0 > :: Iterator it ; it = gv . begin < 0 > ( ) ;"; ASSERT_EQUALS(expected2, tokenizeAndStringify(code2, false)); } - - std::string createSummaries(const char code[], const char filename[] = "test.cpp") { - // Clear the error buffer.. - errout.str(""); - - // tokenize.. - Settings settings; - Tokenizer tokenizer(&settings, this); - std::istringstream istr(code); - tokenizer.tokenize(istr, filename); - return tokenizer.createSummaries(""); - } - - void createSummaries1() { - ASSERT_EQUALS("foo\n", createSummaries("void foo() {}")); - } - - void createSummariesGlobal() { - ASSERT_EQUALS("foo global:[x]\n", createSummaries("int x; void foo() { x=0; }")); - } - - void createSummariesNoreturn() { - ASSERT_EQUALS("foo call:[bar] noreturn:[bar]\n", createSummaries("void foo() { bar(); }")); - } }; REGISTER_TEST(TestTokenizer)