Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update other classes
  • Loading branch information
Your Name
Your Name committed Jul 7, 2026
commit 91b54182cf6cbbe9abfb441be58dbbf4d6221aec
260 changes: 130 additions & 130 deletions Makefile

Large diffs are not rendered by default.

652 changes: 326 additions & 326 deletions cli/cmdlineparser.cpp

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions cli/cmdlineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "cmdlinelogger.h"
#include "filesettings.h"
#include "nonnullptr.h"
#include "standards.h"
#include "utils.h"

Expand Down Expand Up @@ -117,11 +118,11 @@ class CmdLineParser {
T tmp;
std::string err;
if (!strToInt(arg + offset, tmp, &err)) {
mLogger.printError("argument to '" + std::string(arg, offset) + "' is not valid - " + err + ".");
mLogger->printError("argument to '" + std::string(arg, offset) + "' is not valid - " + err + ".");
return false;
}
if (mustBePositive && tmp < 0) {
mLogger.printError("argument to '" + std::string(arg, offset) + "' needs to be a positive integer.");
mLogger->printError("argument to '" + std::string(arg, offset) + "' needs to be a positive integer.");
return false;
}
num = tmp;
Expand Down Expand Up @@ -152,10 +153,10 @@ class CmdLineParser {

void outputFormatOptionMixingError() const;

CmdLineLogger &mLogger;
NonNullPtr<CmdLineLogger> mLogger;

Settings &mSettings;
Suppressions &mSuppressions;
NonNullPtr<Settings> mSettings;
NonNullPtr<Suppressions> mSuppressions;

protected:
std::vector<std::string> mPathNames;
Expand Down
18 changes: 9 additions & 9 deletions lib/checkersreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,19 @@ void CheckersReport::countCheckers()
mActiveCheckersCount = mAllCheckersCount = 0;

for (const auto& checkReq: checkers::allCheckers) {
if (mActiveCheckers.count(checkReq.first) > 0)
if (mActiveCheckers->count(checkReq.first) > 0)
++mActiveCheckersCount;
++mAllCheckersCount;
}
for (const auto& addonInfo: mSettings.addonInfos) {
for (const auto& addonInfo: mSettings->addonInfos) {
for (const auto& checkReq: addonInfo.checkers) {
if (mActiveCheckers.count(checkReq.first) > 0)
if (mActiveCheckers->count(checkReq.first) > 0)
++mActiveCheckersCount;
++mAllCheckersCount;
}
}

if (mSettings.addons.count("misra")) {
if (mSettings->addons.count("misra")) {
const bool doUnusedFunctionOnly = Settings::unusedFunctionOnly();
for (const checkers::MisraInfo& info: checkers::misraC2012Rules) {
const std::string rule = std::to_string(info.a) + "." + std::to_string(info.b);
Expand Down Expand Up @@ -185,20 +185,20 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
}
for (const auto& checkReq: checkers::allCheckers) {
const std::string& checker = checkReq.first;
const bool active = mActiveCheckers.count(checkReq.first) > 0;
const bool active = mActiveCheckers->count(checkReq.first) > 0;
const std::string& req = checkReq.second;
fout << (active ? "Yes " : "No ") << checker;
if (!active && !req.empty())
fout << std::string(maxCheckerSize + 4 - checker.size(), ' ') << "require:" + req;
fout << std::endl;
}

for (const auto& addonInfo: mSettings.addonInfos) {
for (const auto& addonInfo: mSettings->addonInfos) {
if (addonInfo.checkers.empty())
continue;
fout << std::endl << std::endl;
std::string title;
if (mSettings.premium && addonInfo.name == "premiumaddon.json")
if (mSettings->premium && addonInfo.name == "premiumaddon.json")
title = "Cppcheck Premium";
else {
title = addonInfo.name;
Expand All @@ -217,7 +217,7 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const

for (const auto& checkReq: addonInfo.checkers) {
const std::string& checker = checkReq.first;
const bool active = mActiveCheckers.count(checkReq.first) > 0;
const bool active = mActiveCheckers->count(checkReq.first) > 0;
const std::string& req = checkReq.second;
fout << (active ? "Yes " : "No ") << checker;
if (!active && !req.empty())
Expand All @@ -238,7 +238,7 @@ std::string CheckersReport::getXmlReport(const std::string& criticalErrors) cons
ret += " <critical-errors/>\n";
ret += " <checkers-report>\n";
const int misraCVersion = getMisraCVersion(mSettings);
for (std::string checker: mActiveCheckers) {
for (std::string checker: *mActiveCheckers) {
if (checker.compare(0,8,"Misra C:") == 0)
checker = "Misra C " + std::to_string(misraCVersion) + ":" + checker.substr(8);
ret += " <checker id=\"" + checker + "\"/>\n";
Expand Down
5 changes: 3 additions & 2 deletions lib/checkersreport.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define checkersReportH

#include "config.h"
#include "nonnullptr.h"

#include <set>
#include <string>
Expand All @@ -37,8 +38,8 @@ class CPPCHECKLIB CheckersReport {
std::string getXmlReport(const std::string& criticalErrors) const;

private:
const Settings& mSettings;
const std::set<std::string>& mActiveCheckers;
NonNullPtr<const Settings> mSettings;
NonNullPtr<const std::set<std::string>> mActiveCheckers;

void countCheckers();

Expand Down
2 changes: 1 addition & 1 deletion lib/clangimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ const ::Type * clangimport::AstNode::addTypeTokens(TokenList &tokenList, const s
for (const Token *typeToken = tokenList.back(); Token::Match(typeToken, "&|*|%name%"); typeToken = typeToken->previous()) {
if (!typeToken->isName())
continue;
const ::Type *recordType = scope->symdb.findVariableType(scope, typeToken);
const ::Type *recordType = scope->symdb->findVariableType(scope, typeToken);
if (recordType) {
const_cast<Token*>(typeToken)->type(recordType);
return recordType;
Expand Down
13 changes: 7 additions & 6 deletions lib/errorlogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "config.h"
#include "errortypes.h"
#include "nonnullptr.h"

#include <cstdint>
#include <ctime>
Expand Down Expand Up @@ -301,25 +302,25 @@
~ProgressReporter() {
if (mReportProgressInterval < 0)
return;
mErrorLogger.reportProgress(mFilename, mStage.c_str(), 100);
mErrorLogger->reportProgress(mFilename, mStage.c_str(), 100);
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
}

void report(int value) {
if (mReportProgressInterval < 0 || value == mLastValue)
return;
const std::time_t t = std::time(nullptr);
if (t >= mLastTime + mReportProgressInterval) {
mErrorLogger.reportProgress(mFilename, mStage.c_str(), value);
mErrorLogger->reportProgress(mFilename, mStage.c_str(), value);
mLastTime = t;
mLastValue = value;
}
}

private:
ErrorLogger& mErrorLogger;
const int mReportProgressInterval;
const std::string mFilename;
const std::string mStage;
NonNullPtr<ErrorLogger> mErrorLogger;
int mReportProgressInterval;
std::string mFilename;
std::string mStage;
std::time_t mLastTime{0};
int mLastValue{-1};
};
Expand Down
2 changes: 1 addition & 1 deletion lib/fwdanalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const Token *
while (argnr < args.size() && args[argnr] != parent)
argnr++;
if (argnr < args.size()) {
if (mSettings.library.getArgDirection(ftok->astOperand1(), argnr + 1, /*indirect*/ 1) == Library::ArgumentChecks::Direction::DIR_OUT)
if (mSettings->library.getArgDirection(ftok->astOperand1(), argnr + 1, /*indirect*/ 1) == Library::ArgumentChecks::Direction::DIR_OUT)
continue;
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/fwdanalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
//---------------------------------------------------------------------------

#include "config.h"
#include "nonnullptr.h"

#include <cstdint>
#include <set>
Expand Down Expand Up @@ -77,7 +78,7 @@ class FwdAnalysis {
Result check(const Token *expr, const Token *startToken, const Token *endToken) const;
Result checkRecursive(const Token *expr, const Token *startToken, const Token *endToken, const std::set<nonneg int> &exprVarIds, bool local, bool inInnerClass, int depth=0) const;

const Settings &mSettings;
NonNullPtr<const Settings> mSettings;
enum class What : std::uint8_t { Reassign, UnusedValue } mWhat = What::Reassign;
};

Expand Down
88 changes: 44 additions & 44 deletions lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ static void addInlineSuppressions(const simplecpp::TokenList &tokens, const Sett

void Preprocessor::inlineSuppressions(SuppressionList &suppressions)
{
if (!mSettings.inlineSuppressions)
if (!mSettings->inlineSuppressions)
return;
std::list<BadInlineSuppression> err;
::addInlineSuppressions(mTokens, mSettings, suppressions, err);
Expand Down Expand Up @@ -367,7 +367,7 @@ std::list<Directive> Preprocessor::createDirectives() const

std::vector<const simplecpp::TokenList *> list;
list.reserve(1U + mFileCache.size());
list.push_back(&mTokens);
list.push_back(mTokens.get());
std::transform(mFileCache.cbegin(), mFileCache.cend(), std::back_inserter(list),
[](const std::unique_ptr<simplecpp::FileData> &filedata) {
return &filedata->tokens;
Expand Down Expand Up @@ -773,13 +773,13 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
std::set<std::string> Preprocessor::getConfigs() const
{
std::set<std::string> ret = { "" };
if (!mTokens.cfront())
if (!mTokens->cfront())
return ret;

std::set<std::string> defined = { "__cplusplus" };

// Insert library defines
for (const auto &define : mSettings.library.defines()) {
for (const auto &define : mSettings->library.defines()) {

const std::string::size_type paren = define.find("(");
const std::string::size_type space = define.find(" ");
Expand All @@ -791,11 +791,11 @@ std::set<std::string> Preprocessor::getConfigs() const
defined.insert(define.substr(0, end));
}

::getConfigs(mTokens, defined, mSettings.userDefines, mSettings.userUndefs, ret);
::getConfigs(mTokens, defined, mSettings->userDefines, mSettings->userUndefs, ret);

for (const auto &filedata : mFileCache) {
if (!mSettings.configurationExcluded(filedata->filename))
::getConfigs(filedata->tokens, defined, mSettings.userDefines, mSettings.userUndefs, ret);
if (!mSettings->configurationExcluded(filedata->filename))
::getConfigs(filedata->tokens, defined, mSettings->userDefines, mSettings->userUndefs, ret);
}

return ret;
Expand Down Expand Up @@ -862,7 +862,7 @@ static simplecpp::DUI createDUI(const Settings &mSettings, const std::string &cf

const simplecpp::Output* Preprocessor::handleErrors(const simplecpp::OutputList& outputList)
{
const bool showerror = (!mSettings.userDefines.empty() && !mSettings.force);
const bool showerror = (!mSettings->userDefines.empty() && !mSettings->force);
return reportOutput(outputList, showerror);
}

Expand All @@ -877,30 +877,30 @@ bool Preprocessor::loadFiles(std::vector<std::string> &files)

void Preprocessor::removeComments()
{
mTokens.removeComments();
mTokens->removeComments();
for (const auto &filedata : mFileCache) {
filedata->tokens.removeComments();
}
}

void Preprocessor::setPlatformInfo()
{
mTokens.sizeOfType["bool"] = mSettings.platform.sizeof_bool;
mTokens.sizeOfType["short"] = mSettings.platform.sizeof_short;
mTokens.sizeOfType["int"] = mSettings.platform.sizeof_int;
mTokens.sizeOfType["long"] = mSettings.platform.sizeof_long;
mTokens.sizeOfType["long long"] = mSettings.platform.sizeof_long_long;
mTokens.sizeOfType["float"] = mSettings.platform.sizeof_float;
mTokens.sizeOfType["double"] = mSettings.platform.sizeof_double;
mTokens.sizeOfType["long double"] = mSettings.platform.sizeof_long_double;
mTokens.sizeOfType["bool *"] = mSettings.platform.sizeof_pointer;
mTokens.sizeOfType["short *"] = mSettings.platform.sizeof_pointer;
mTokens.sizeOfType["int *"] = mSettings.platform.sizeof_pointer;
mTokens.sizeOfType["long *"] = mSettings.platform.sizeof_pointer;
mTokens.sizeOfType["long long *"] = mSettings.platform.sizeof_pointer;
mTokens.sizeOfType["float *"] = mSettings.platform.sizeof_pointer;
mTokens.sizeOfType["double *"] = mSettings.platform.sizeof_pointer;
mTokens.sizeOfType["long double *"] = mSettings.platform.sizeof_pointer;
mTokens->sizeOfType["bool"] = mSettings->platform.sizeof_bool;
mTokens->sizeOfType["short"] = mSettings->platform.sizeof_short;
mTokens->sizeOfType["int"] = mSettings->platform.sizeof_int;
mTokens->sizeOfType["long"] = mSettings->platform.sizeof_long;
mTokens->sizeOfType["long long"] = mSettings->platform.sizeof_long_long;
mTokens->sizeOfType["float"] = mSettings->platform.sizeof_float;
mTokens->sizeOfType["double"] = mSettings->platform.sizeof_double;
mTokens->sizeOfType["long double"] = mSettings->platform.sizeof_long_double;
mTokens->sizeOfType["bool *"] = mSettings->platform.sizeof_pointer;
mTokens->sizeOfType["short *"] = mSettings->platform.sizeof_pointer;
mTokens->sizeOfType["int *"] = mSettings->platform.sizeof_pointer;
mTokens->sizeOfType["long *"] = mSettings->platform.sizeof_pointer;
mTokens->sizeOfType["long long *"] = mSettings->platform.sizeof_pointer;
mTokens->sizeOfType["float *"] = mSettings->platform.sizeof_pointer;
mTokens->sizeOfType["double *"] = mSettings->platform.sizeof_pointer;
mTokens->sizeOfType["long double *"] = mSettings->platform.sizeof_pointer;
}

simplecpp::TokenList Preprocessor::preprocess(const std::string &cfgStr, std::vector<std::string> &files, simplecpp::OutputList& outputList)
Expand Down Expand Up @@ -929,7 +929,7 @@ std::string Preprocessor::getcode(const std::string &cfgStr, std::vector<std::st
std::ostringstream ret;
for (const simplecpp::Token *tok = tokens2.cfront(); tok; tok = tok->next) {
if (writeLocations && tok->location.fileIndex != prevfile) {
ret << "\n#line " << tok->location.line << " \"" << mTokens.file(tok->location) << "\"\n";
ret << "\n#line " << tok->location.line << " \"" << mTokens->file(tok->location) << "\"\n";
prevfile = tok->location.fileIndex;
line = tok->location.line;
}
Expand Down Expand Up @@ -1024,39 +1024,39 @@ void Preprocessor::error(const simplecpp::Location& loc, const std::string &msg,
void Preprocessor::error(const simplecpp::Location& loc, const std::string &msg, const std::string& id)
{
std::list<ErrorMessage::FileLocation> locationList;
if (!mTokens.file(loc).empty()) {
std::string file = Path::fromNativeSeparators(mTokens.file(loc));
if (mSettings.relativePaths)
file = Path::getRelativePath(file, mSettings.basePaths);
if (!mTokens->file(loc).empty()) {
std::string file = Path::fromNativeSeparators(mTokens->file(loc));
if (mSettings->relativePaths)
file = Path::getRelativePath(file, mSettings->basePaths);

locationList.emplace_back(file, loc.line, loc.col);
}
mErrorLogger.reportErr(ErrorMessage(std::move(locationList),
mFile0,
Severity::error,
msg,
id,
Certainty::normal));
mErrorLogger->reportErr(ErrorMessage(std::move(locationList),
mFile0,
Severity::error,
msg,
id,
Certainty::normal));
}

// Report that include is missing
void Preprocessor::missingInclude(const simplecpp::Location& loc, const std::string &header, HeaderTypes headerType)
{
if (!mSettings.checks.isEnabled(Checks::missingInclude))
if (!mSettings->checks.isEnabled(Checks::missingInclude))
return;

std::list<ErrorMessage::FileLocation> locationList;
if (!mTokens.file(loc).empty()) {
if (!mTokens->file(loc).empty()) {
// TODO: add relative path handling?
locationList.emplace_back(mTokens.file(loc), loc.line, loc.col);
locationList.emplace_back(mTokens->file(loc), loc.line, loc.col);
}
ErrorMessage errmsg(std::move(locationList), mFile0, Severity::information,
(headerType==SystemHeader) ?
"Include file: <" + header + "> not found. Please note: Standard library headers do not need to be provided to get proper results." :
"Include file: \"" + header + "\" not found.",
(headerType==SystemHeader) ? "missingIncludeSystem" : "missingInclude",
Certainty::normal);
mErrorLogger.reportErr(errmsg);
mErrorLogger->reportErr(errmsg);
}

void Preprocessor::invalidSuppression(const simplecpp::Location& loc, const std::string &msg)
Expand Down Expand Up @@ -1092,10 +1092,10 @@ void Preprocessor::dump(std::ostream &out) const
for (const simplecpp::MacroUsage &macroUsage: mMacroUsage) {
out << " <macro"
<< " name=\"" << macroUsage.macroName << "\""
<< " file=\"" << ErrorLogger::toxml(mTokens.file(macroUsage.macroLocation)) << "\""
<< " file=\"" << ErrorLogger::toxml(mTokens->file(macroUsage.macroLocation)) << "\""
<< " line=\"" << macroUsage.macroLocation.line << "\""
<< " column=\"" << macroUsage.macroLocation.col << "\""
<< " usefile=\"" << ErrorLogger::toxml(mTokens.file(macroUsage.useLocation)) << "\""
<< " usefile=\"" << ErrorLogger::toxml(mTokens->file(macroUsage.useLocation)) << "\""
<< " useline=\"" << macroUsage.useLocation.line << "\""
<< " usecolumn=\"" << macroUsage.useLocation.col << "\""
<< " is-known-value=\"" << bool_to_string(macroUsage.macroValueKnown) << "\""
Expand All @@ -1108,7 +1108,7 @@ void Preprocessor::dump(std::ostream &out) const
out << " <simplecpp-if-cond>" << std::endl;
for (const simplecpp::IfCond &ifCond: mIfCond) {
out << " <if-cond"
<< " file=\"" << ErrorLogger::toxml(mTokens.file(ifCond.location)) << "\""
<< " file=\"" << ErrorLogger::toxml(mTokens->file(ifCond.location)) << "\""
<< " line=\"" << ifCond.location.line << "\""
<< " column=\"" << ifCond.location.col << "\""
<< " E=\"" << ErrorLogger::toxml(ifCond.E) << "\""
Expand All @@ -1122,7 +1122,7 @@ void Preprocessor::dump(std::ostream &out) const
std::size_t Preprocessor::calculateHash(const std::string &toolinfo) const
{
std::string hashData = toolinfo;
for (const simplecpp::Token *tok = mTokens.cfront(); tok; tok = tok->next) {
for (const simplecpp::Token *tok = mTokens->cfront(); tok; tok = tok->next) {
if (!tok->comment) {
hashData += tok->str();
hashData += static_cast<char>(tok->location.line);
Expand Down
Loading
Loading