Skip to content

Commit 18b2d18

Browse files
committed
Fix dump for misra verify
1 parent 3c3c27b commit 18b2d18

4 files changed

Lines changed: 39 additions & 9 deletions

File tree

lib/cppcheck.cpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,11 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
10061006
mLogger->openPlist(filename2);
10071007
}
10081008

1009+
std::string dumpFooter;
1010+
if (mSettings.dump || !mSettings.addons.empty()) {
1011+
dumpFooter += getDumpFileContentsRawTokensFooter(tokens1);
1012+
}
1013+
10091014
// Parse comments and then remove them
10101015
preprocessor.addRemarkComments(tokens1, mLogger->remarkComments());
10111016
preprocessor.inlineSuppressions(tokens1, mSuppressions.nomsg);
@@ -1289,7 +1294,8 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
12891294
// TODO: will not be closed if we encountered an exception
12901295
if (fdump.is_open()) {
12911296
// dump all filenames, raw tokens, suppressions
1292-
fdump << getDumpFileContentsRawTokens(files, tokens1);
1297+
std::string dumpHeader = getDumpFileContentsRawTokensHeader(files);
1298+
fdump << getDumpFileContentsRawTokens(dumpHeader, dumpFooter);
12931299
mSuppressions.nomsg.dump(fdump);
12941300
// dumped all configs, close root </dumps> element now
12951301
fdump << "</dumps>" << std::endl;
@@ -1974,14 +1980,36 @@ bool CppCheck::isPremiumCodingStandardId(const std::string& id) const {
19741980
std::string CppCheck::getDumpFileContentsRawTokens(const std::vector<std::string>& files, const simplecpp::TokenList& tokens1) const {
19751981
std::string dumpProlog;
19761982
dumpProlog += " <rawtokens>\n";
1983+
dumpProlog += getDumpFileContentsRawTokensHeader(files);
1984+
dumpProlog += getDumpFileContentsRawTokensFooter(tokens1);
1985+
dumpProlog += " </rawtokens>\n";
1986+
return dumpProlog;
1987+
}
1988+
1989+
std::string CppCheck::getDumpFileContentsRawTokens(const std::string& header, const std::string& footer) const {
1990+
std::string dumpProlog;
1991+
dumpProlog += " <rawtokens>\n";
1992+
dumpProlog += header;
1993+
dumpProlog += footer;
1994+
dumpProlog += " </rawtokens>\n";
1995+
return dumpProlog;
1996+
}
1997+
1998+
std::string CppCheck::getDumpFileContentsRawTokensHeader(const std::vector<std::string>& files) const {
1999+
std::string dumpProlog;
19772000
for (unsigned int i = 0; i < files.size(); ++i) {
19782001
dumpProlog += " <file index=\"";
19792002
dumpProlog += std::to_string(i);
19802003
dumpProlog += "\" name=\"";
19812004
dumpProlog += ErrorLogger::toxml(Path::getRelativePath(files[i], mSettings.basePaths));
19822005
dumpProlog += "\"/>\n";
19832006
}
1984-
for (const simplecpp::Token *tok = tokens1.cfront(); tok; tok = tok->next) {
2007+
return dumpProlog;
2008+
}
2009+
2010+
std::string CppCheck::getDumpFileContentsRawTokensFooter(const simplecpp::TokenList& tokens1) const {
2011+
std::string dumpProlog;
2012+
for (const simplecpp::Token* tok = tokens1.cfront(); tok; tok = tok->next) {
19852013
dumpProlog += " <tok ";
19862014

19872015
dumpProlog += "fileIndex=\"";
@@ -1992,7 +2020,7 @@ std::string CppCheck::getDumpFileContentsRawTokens(const std::vector<std::string
19922020
dumpProlog += std::to_string(tok->location.line);
19932021
dumpProlog += "\" ";
19942022

1995-
dumpProlog +="column=\"";
2023+
dumpProlog += "column=\"";
19962024
dumpProlog += std::to_string(tok->location.col);
19972025
dumpProlog += "\" ";
19982026

@@ -2002,6 +2030,5 @@ std::string CppCheck::getDumpFileContentsRawTokens(const std::vector<std::string
20022030

20032031
dumpProlog += "/>\n";
20042032
}
2005-
dumpProlog += " </rawtokens>\n";
20062033
return dumpProlog;
20072034
}

lib/cppcheck.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ class CPPCHECKLIB CppCheck {
154154
* @brief Get dumpfile <rawtokens> contents, this is only public for testing purposes
155155
*/
156156
std::string getDumpFileContentsRawTokens(const std::vector<std::string>& files, const simplecpp::TokenList& tokens1) const;
157+
std::string CppCheck::getDumpFileContentsRawTokens(const std::string& header, const std::string& footer) const;
158+
std::string getDumpFileContentsRawTokensHeader(const std::vector<std::string>& files) const;
159+
std::string getDumpFileContentsRawTokensFooter(const simplecpp::TokenList& tokens1) const;
157160

158161
std::string getLibraryDumpData() const;
159162

lib/cppcheck.vcxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,25 +200,25 @@
200200
<ConfigurationType>DynamicLibrary</ConfigurationType>
201201
<CharacterSet>Unicode</CharacterSet>
202202
<WholeProgramOptimization>false</WholeProgramOptimization>
203-
<PlatformToolset>v142</PlatformToolset>
203+
<PlatformToolset>v143</PlatformToolset>
204204
</PropertyGroup>
205205
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-PCRE|x64'" Label="Configuration">
206206
<ConfigurationType>DynamicLibrary</ConfigurationType>
207207
<CharacterSet>Unicode</CharacterSet>
208208
<WholeProgramOptimization>false</WholeProgramOptimization>
209-
<PlatformToolset>v142</PlatformToolset>
209+
<PlatformToolset>v143</PlatformToolset>
210210
</PropertyGroup>
211211
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
212212
<ConfigurationType>DynamicLibrary</ConfigurationType>
213213
<CharacterSet>Unicode</CharacterSet>
214214
<WholeProgramOptimization>false</WholeProgramOptimization>
215-
<PlatformToolset>v142</PlatformToolset>
215+
<PlatformToolset>v143</PlatformToolset>
216216
</PropertyGroup>
217217
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-PCRE|x64'" Label="Configuration">
218218
<ConfigurationType>DynamicLibrary</ConfigurationType>
219219
<CharacterSet>Unicode</CharacterSet>
220220
<WholeProgramOptimization>false</WholeProgramOptimization>
221-
<PlatformToolset>v142</PlatformToolset>
221+
<PlatformToolset>v143</PlatformToolset>
222222
</PropertyGroup>
223223
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
224224
<ImportGroup Label="ExtensionSettings" />

lib/preprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ std::vector<RemarkComment> Preprocessor::getRemarkComments(const simplecpp::Toke
323323
return ret;
324324
}
325325

326-
void Preprocessor::createDirectives(const simplecpp::TokenList &tokens, std::list<Directive>& directives) const
326+
void Preprocessor::createDirectives(const simplecpp::TokenList &tokens, std::list<Directive>& directives)
327327
{
328328
for (const simplecpp::Token *tok = tokens.cfront(); tok; tok = tok->next) {
329329
if ((tok->op != '#') || (tok->previous && tok->previous->location.line == tok->location.line))

0 commit comments

Comments
 (0)