@@ -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 {
19741980std::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}
0 commit comments