From 8721c3c67eca0a424021fb8a54639ca9ce4563ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 15 Aug 2024 11:14:35 +0200 Subject: [PATCH] test2 --- gui/test/resultstree/testresultstree.cpp | 8 ++-- lib/tokenize.cpp | 60 ++++++++++++++---------- lib/tokenize.h | 19 ++++---- test/testsimplifytypedef.cpp | 12 +++-- 4 files changed, 54 insertions(+), 45 deletions(-) diff --git a/gui/test/resultstree/testresultstree.cpp b/gui/test/resultstree/testresultstree.cpp index 0c83d52c6a9..16c2ad090da 100644 --- a/gui/test/resultstree/testresultstree.cpp +++ b/gui/test/resultstree/testresultstree.cpp @@ -33,10 +33,12 @@ #include -class TestReport: public Report { +class TestReport : public Report { public: TestReport(QString format) : Report(QString()), format(format) {} - void writeHeader() override { output.clear(); } + void writeHeader() override { + output.clear(); + } void writeFooter() override {} void writeError(const ErrorItem &error) override { QString line = format; @@ -125,7 +127,7 @@ void TestResultsTree::testReportType() const TestReport report("{id},{classification},{guideline}"); int msgCount = 0; - auto createErrorItem = [&msgCount](const Severity severity, const QString& errorId) -> ErrorItem { + auto createErrorItem = [&msgCount](const Severity severity, const QString& errorId) -> ErrorItem { ++msgCount; ErrorItem errorItem; errorItem.errorPath << QErrorPathItem(ErrorMessage::FileLocation("file1.c", msgCount, 1)); diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index f4bcf957477..c954ca0eba7 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6158,41 +6158,49 @@ void Tokenizer::dump(std::ostream &out) const if (list.front()) list.front()->printValueFlow(true, out); - if (!mTypedefInfo.empty()) { - outs += " "; - outs += '\n'; - for (const TypedefInfo &typedefInfo: mTypedefInfo) { - outs += " dump(); - outs += " file=\""; - outs += ErrorLogger::toxml(typedefInfo.filename); - outs += "\""; + out << outs; +} - outs += " line=\""; - outs += std::to_string(typedefInfo.lineNumber); - outs += "\""; +std::string Tokenizer::dumpTypedefInfo() const +{ + if (mTypedefInfo.empty()) + return ""; + std::string outs = " "; + outs += '\n'; + for (const TypedefInfo &typedefInfo: mTypedefInfo) { + outs += " dump(); + outs += " "; + outs += '\n'; - out << outs; + return outs; } void Tokenizer::simplifyHeadersAndUnusedTemplates() diff --git a/lib/tokenize.h b/lib/tokenize.h index 1f5d2abdd6d..cb66342797e 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -627,17 +627,7 @@ class CPPCHECKLIB Tokenizer { void setDirectives(std::list directives); - struct TypedefInfo { - std::string name; - std::string filename; - int lineNumber; - int column; - bool used; - }; - std::vector getTypedefInfo() { - return mTypedefInfo; - } - + std::string dumpTypedefInfo() const; private: const Token *processFunc(const Token *tok2, bool inOperator) const; Token *processFunc(Token *tok2, bool inOperator); @@ -671,6 +661,13 @@ class CPPCHECKLIB Tokenizer { /** sizeof information for known types */ std::map mTypeSize; + struct TypedefInfo { + std::string name; + std::string filename; + int lineNumber; + int column; + bool used; + }; std::vector mTypedefInfo; std::list mDirectives; diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index aecd30bab77..cff9c763ab0 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -309,7 +309,7 @@ class TestSimplifyTypedef : public TestFixture { return tokenizer.tokens()->stringifyList(nullptr, false); } - std::vector getTypedefInfo(const char code[]) { + std::string dumpTypedefInfo(const char code[]) { Tokenizer tokenizer(settings1, *this); std::istringstream istr(code); @@ -322,7 +322,7 @@ class TestSimplifyTypedef : public TestFixture { } catch (const InternalError&) { return {}; } - return tokenizer.getTypedefInfo(); + return tokenizer.dumpTypedefInfo(); } void c1() { @@ -4400,9 +4400,11 @@ class TestSimplifyTypedef : public TestFixture { } void typedefInfo1() { - const auto& t = getTypedefInfo("typedef int A;\nA x;"); - ASSERT_EQUALS(1, t.size()); - ASSERT_EQUALS("A", t[0].name); + const std::string xml = dumpTypedefInfo("typedef int A;\nA x;"); + ASSERT_EQUALS(" \n" + " \n" + " \n", + xml); } };