Skip to content

Commit 5846627

Browse files
committed
Fix getDumpFileContentsRawTokens, change Preprocessor::removeComments
1 parent 5493920 commit 5846627

3 files changed

Lines changed: 7 additions & 13 deletions

File tree

lib/cppcheck.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
10141014
// Parse comments and then remove them
10151015
preprocessor.addRemarkComments(tokens1, mLogger->remarkComments());
10161016
preprocessor.inlineSuppressions(tokens1, mSuppressions.nomsg);
1017-
tokens1.removeComments();
1017+
preprocessor.removeComments(tokens1);
10181018

10191019
if (!mSettings.buildDir.empty()) {
10201020
analyzerInformation.reset(new AnalyzerInformation);
@@ -1049,7 +1049,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
10491049
// Do preprocessing on included file
10501050
preprocessor.addRemarkComments(data.tokens, mLogger->remarkComments());
10511051
preprocessor.inlineSuppressions(data.tokens, mSuppressions.nomsg);
1052-
data.tokens.removeComments();
1052+
preprocessor.removeComments(data.tokens);
10531053
preprocessor.createDirectives(data.tokens, directives);
10541054
preprocessor.simplifyPragmaAsm(data.tokens);
10551055
// Discover new configurations from included file
@@ -1978,12 +1978,9 @@ bool CppCheck::isPremiumCodingStandardId(const std::string& id) const {
19781978
}
19791979

19801980
std::string CppCheck::getDumpFileContentsRawTokens(const std::vector<std::string>& files, const simplecpp::TokenList& tokens1) const {
1981-
std::string dumpProlog;
1982-
dumpProlog += " <rawtokens>\n";
1983-
dumpProlog += getDumpFileContentsRawTokensHeader(files);
1984-
dumpProlog += getDumpFileContentsRawTokensFooter(tokens1);
1985-
dumpProlog += " </rawtokens>\n";
1986-
return dumpProlog;
1981+
std::string header = getDumpFileContentsRawTokensHeader(files);
1982+
std::string footer = getDumpFileContentsRawTokensFooter(tokens1);
1983+
return getDumpFileContentsRawTokens(header, footer);
19871984
}
19881985

19891986
std::string CppCheck::getDumpFileContentsRawTokens(const std::string& header, const std::string& footer) const {

lib/preprocessor.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -764,12 +764,9 @@ bool Preprocessor::loadFiles(const simplecpp::TokenList &rawtokens, std::vector<
764764
return !hasErrors(outputList);
765765
}
766766

767-
void Preprocessor::removeComments(simplecpp::TokenList &tokens) const
767+
void Preprocessor::removeComments(simplecpp::TokenList &tokens)
768768
{
769769
tokens.removeComments();
770-
for (const auto &filedata : mFileCache) {
771-
filedata->tokens.removeComments();
772-
}
773770
}
774771

775772
void Preprocessor::setPlatformInfo(simplecpp::TokenList &tokens, const Settings& settings)

lib/preprocessor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor {
122122

123123
bool loadFiles(const simplecpp::TokenList& rawtokens, std::vector<std::string>& files);
124124

125-
void removeComments(simplecpp::TokenList &tokens) const;
125+
static void removeComments(simplecpp::TokenList &tokens);
126126

127127
static void setPlatformInfo(simplecpp::TokenList &tokens, const Settings& settings);
128128

0 commit comments

Comments
 (0)