Skip to content

Commit 91b5418

Browse files
author
Your Name
committed
Update other classes
1 parent 266b2ae commit 91b5418

24 files changed

Lines changed: 831 additions & 821 deletions

Makefile

Lines changed: 130 additions & 130 deletions
Large diffs are not rendered by default.

cli/cmdlineparser.cpp

Lines changed: 326 additions & 326 deletions
Large diffs are not rendered by default.

cli/cmdlineparser.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "cmdlinelogger.h"
2929
#include "filesettings.h"
30+
#include "nonnullptr.h"
3031
#include "standards.h"
3132
#include "utils.h"
3233

@@ -117,11 +118,11 @@ class CmdLineParser {
117118
T tmp;
118119
std::string err;
119120
if (!strToInt(arg + offset, tmp, &err)) {
120-
mLogger.printError("argument to '" + std::string(arg, offset) + "' is not valid - " + err + ".");
121+
mLogger->printError("argument to '" + std::string(arg, offset) + "' is not valid - " + err + ".");
121122
return false;
122123
}
123124
if (mustBePositive && tmp < 0) {
124-
mLogger.printError("argument to '" + std::string(arg, offset) + "' needs to be a positive integer.");
125+
mLogger->printError("argument to '" + std::string(arg, offset) + "' needs to be a positive integer.");
125126
return false;
126127
}
127128
num = tmp;
@@ -152,10 +153,10 @@ class CmdLineParser {
152153

153154
void outputFormatOptionMixingError() const;
154155

155-
CmdLineLogger &mLogger;
156+
NonNullPtr<CmdLineLogger> mLogger;
156157

157-
Settings &mSettings;
158-
Suppressions &mSuppressions;
158+
NonNullPtr<Settings> mSettings;
159+
NonNullPtr<Suppressions> mSuppressions;
159160

160161
protected:
161162
std::vector<std::string> mPathNames;

lib/checkersreport.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,19 @@ void CheckersReport::countCheckers()
129129
mActiveCheckersCount = mAllCheckersCount = 0;
130130

131131
for (const auto& checkReq: checkers::allCheckers) {
132-
if (mActiveCheckers.count(checkReq.first) > 0)
132+
if (mActiveCheckers->count(checkReq.first) > 0)
133133
++mActiveCheckersCount;
134134
++mAllCheckersCount;
135135
}
136-
for (const auto& addonInfo: mSettings.addonInfos) {
136+
for (const auto& addonInfo: mSettings->addonInfos) {
137137
for (const auto& checkReq: addonInfo.checkers) {
138-
if (mActiveCheckers.count(checkReq.first) > 0)
138+
if (mActiveCheckers->count(checkReq.first) > 0)
139139
++mActiveCheckersCount;
140140
++mAllCheckersCount;
141141
}
142142
}
143143

144-
if (mSettings.addons.count("misra")) {
144+
if (mSettings->addons.count("misra")) {
145145
const bool doUnusedFunctionOnly = Settings::unusedFunctionOnly();
146146
for (const checkers::MisraInfo& info: checkers::misraC2012Rules) {
147147
const std::string rule = std::to_string(info.a) + "." + std::to_string(info.b);
@@ -185,20 +185,20 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
185185
}
186186
for (const auto& checkReq: checkers::allCheckers) {
187187
const std::string& checker = checkReq.first;
188-
const bool active = mActiveCheckers.count(checkReq.first) > 0;
188+
const bool active = mActiveCheckers->count(checkReq.first) > 0;
189189
const std::string& req = checkReq.second;
190190
fout << (active ? "Yes " : "No ") << checker;
191191
if (!active && !req.empty())
192192
fout << std::string(maxCheckerSize + 4 - checker.size(), ' ') << "require:" + req;
193193
fout << std::endl;
194194
}
195195

196-
for (const auto& addonInfo: mSettings.addonInfos) {
196+
for (const auto& addonInfo: mSettings->addonInfos) {
197197
if (addonInfo.checkers.empty())
198198
continue;
199199
fout << std::endl << std::endl;
200200
std::string title;
201-
if (mSettings.premium && addonInfo.name == "premiumaddon.json")
201+
if (mSettings->premium && addonInfo.name == "premiumaddon.json")
202202
title = "Cppcheck Premium";
203203
else {
204204
title = addonInfo.name;
@@ -217,7 +217,7 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
217217

218218
for (const auto& checkReq: addonInfo.checkers) {
219219
const std::string& checker = checkReq.first;
220-
const bool active = mActiveCheckers.count(checkReq.first) > 0;
220+
const bool active = mActiveCheckers->count(checkReq.first) > 0;
221221
const std::string& req = checkReq.second;
222222
fout << (active ? "Yes " : "No ") << checker;
223223
if (!active && !req.empty())
@@ -238,7 +238,7 @@ std::string CheckersReport::getXmlReport(const std::string& criticalErrors) cons
238238
ret += " <critical-errors/>\n";
239239
ret += " <checkers-report>\n";
240240
const int misraCVersion = getMisraCVersion(mSettings);
241-
for (std::string checker: mActiveCheckers) {
241+
for (std::string checker: *mActiveCheckers) {
242242
if (checker.compare(0,8,"Misra C:") == 0)
243243
checker = "Misra C " + std::to_string(misraCVersion) + ":" + checker.substr(8);
244244
ret += " <checker id=\"" + checker + "\"/>\n";

lib/checkersreport.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define checkersReportH
2121

2222
#include "config.h"
23+
#include "nonnullptr.h"
2324

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

3940
private:
40-
const Settings& mSettings;
41-
const std::set<std::string>& mActiveCheckers;
41+
NonNullPtr<const Settings> mSettings;
42+
NonNullPtr<const std::set<std::string>> mActiveCheckers;
4243

4344
void countCheckers();
4445

lib/clangimport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ const ::Type * clangimport::AstNode::addTypeTokens(TokenList &tokenList, const s
644644
for (const Token *typeToken = tokenList.back(); Token::Match(typeToken, "&|*|%name%"); typeToken = typeToken->previous()) {
645645
if (!typeToken->isName())
646646
continue;
647-
const ::Type *recordType = scope->symdb.findVariableType(scope, typeToken);
647+
const ::Type *recordType = scope->symdb->findVariableType(scope, typeToken);
648648
if (recordType) {
649649
const_cast<Token*>(typeToken)->type(recordType);
650650
return recordType;

lib/errorlogger.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "config.h"
2525
#include "errortypes.h"
26+
#include "nonnullptr.h"
2627

2728
#include <cstdint>
2829
#include <ctime>
@@ -301,25 +302,25 @@ class CPPCHECKLIB ProgressReporter {
301302
~ProgressReporter() {
302303
if (mReportProgressInterval < 0)
303304
return;
304-
mErrorLogger.reportProgress(mFilename, mStage.c_str(), 100);
305+
mErrorLogger->reportProgress(mFilename, mStage.c_str(), 100);
305306
}
306307

307308
void report(int value) {
308309
if (mReportProgressInterval < 0 || value == mLastValue)
309310
return;
310311
const std::time_t t = std::time(nullptr);
311312
if (t >= mLastTime + mReportProgressInterval) {
312-
mErrorLogger.reportProgress(mFilename, mStage.c_str(), value);
313+
mErrorLogger->reportProgress(mFilename, mStage.c_str(), value);
313314
mLastTime = t;
314315
mLastValue = value;
315316
}
316317
}
317318

318319
private:
319-
ErrorLogger& mErrorLogger;
320-
const int mReportProgressInterval;
321-
const std::string mFilename;
322-
const std::string mStage;
320+
NonNullPtr<ErrorLogger> mErrorLogger;
321+
int mReportProgressInterval;
322+
std::string mFilename;
323+
std::string mStage;
323324
std::time_t mLastTime{0};
324325
int mLastValue{-1};
325326
};

lib/fwdanalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const Token *
293293
while (argnr < args.size() && args[argnr] != parent)
294294
argnr++;
295295
if (argnr < args.size()) {
296-
if (mSettings.library.getArgDirection(ftok->astOperand1(), argnr + 1, /*indirect*/ 1) == Library::ArgumentChecks::Direction::DIR_OUT)
296+
if (mSettings->library.getArgDirection(ftok->astOperand1(), argnr + 1, /*indirect*/ 1) == Library::ArgumentChecks::Direction::DIR_OUT)
297297
continue;
298298
}
299299
}

lib/fwdanalysis.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
//---------------------------------------------------------------------------
2323

2424
#include "config.h"
25+
#include "nonnullptr.h"
2526

2627
#include <cstdint>
2728
#include <set>
@@ -77,7 +78,7 @@ class FwdAnalysis {
7778
Result check(const Token *expr, const Token *startToken, const Token *endToken) const;
7879
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;
7980

80-
const Settings &mSettings;
81+
NonNullPtr<const Settings> mSettings;
8182
enum class What : std::uint8_t { Reassign, UnusedValue } mWhat = What::Reassign;
8283
};
8384

lib/preprocessor.cpp

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ static void addInlineSuppressions(const simplecpp::TokenList &tokens, const Sett
338338

339339
void Preprocessor::inlineSuppressions(SuppressionList &suppressions)
340340
{
341-
if (!mSettings.inlineSuppressions)
341+
if (!mSettings->inlineSuppressions)
342342
return;
343343
std::list<BadInlineSuppression> err;
344344
::addInlineSuppressions(mTokens, mSettings, suppressions, err);
@@ -367,7 +367,7 @@ std::list<Directive> Preprocessor::createDirectives() const
367367

368368
std::vector<const simplecpp::TokenList *> list;
369369
list.reserve(1U + mFileCache.size());
370-
list.push_back(&mTokens);
370+
list.push_back(mTokens.get());
371371
std::transform(mFileCache.cbegin(), mFileCache.cend(), std::back_inserter(list),
372372
[](const std::unique_ptr<simplecpp::FileData> &filedata) {
373373
return &filedata->tokens;
@@ -773,13 +773,13 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
773773
std::set<std::string> Preprocessor::getConfigs() const
774774
{
775775
std::set<std::string> ret = { "" };
776-
if (!mTokens.cfront())
776+
if (!mTokens->cfront())
777777
return ret;
778778

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

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

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

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

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

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

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

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

878878
void Preprocessor::removeComments()
879879
{
880-
mTokens.removeComments();
880+
mTokens->removeComments();
881881
for (const auto &filedata : mFileCache) {
882882
filedata->tokens.removeComments();
883883
}
884884
}
885885

886886
void Preprocessor::setPlatformInfo()
887887
{
888-
mTokens.sizeOfType["bool"] = mSettings.platform.sizeof_bool;
889-
mTokens.sizeOfType["short"] = mSettings.platform.sizeof_short;
890-
mTokens.sizeOfType["int"] = mSettings.platform.sizeof_int;
891-
mTokens.sizeOfType["long"] = mSettings.platform.sizeof_long;
892-
mTokens.sizeOfType["long long"] = mSettings.platform.sizeof_long_long;
893-
mTokens.sizeOfType["float"] = mSettings.platform.sizeof_float;
894-
mTokens.sizeOfType["double"] = mSettings.platform.sizeof_double;
895-
mTokens.sizeOfType["long double"] = mSettings.platform.sizeof_long_double;
896-
mTokens.sizeOfType["bool *"] = mSettings.platform.sizeof_pointer;
897-
mTokens.sizeOfType["short *"] = mSettings.platform.sizeof_pointer;
898-
mTokens.sizeOfType["int *"] = mSettings.platform.sizeof_pointer;
899-
mTokens.sizeOfType["long *"] = mSettings.platform.sizeof_pointer;
900-
mTokens.sizeOfType["long long *"] = mSettings.platform.sizeof_pointer;
901-
mTokens.sizeOfType["float *"] = mSettings.platform.sizeof_pointer;
902-
mTokens.sizeOfType["double *"] = mSettings.platform.sizeof_pointer;
903-
mTokens.sizeOfType["long double *"] = mSettings.platform.sizeof_pointer;
888+
mTokens->sizeOfType["bool"] = mSettings->platform.sizeof_bool;
889+
mTokens->sizeOfType["short"] = mSettings->platform.sizeof_short;
890+
mTokens->sizeOfType["int"] = mSettings->platform.sizeof_int;
891+
mTokens->sizeOfType["long"] = mSettings->platform.sizeof_long;
892+
mTokens->sizeOfType["long long"] = mSettings->platform.sizeof_long_long;
893+
mTokens->sizeOfType["float"] = mSettings->platform.sizeof_float;
894+
mTokens->sizeOfType["double"] = mSettings->platform.sizeof_double;
895+
mTokens->sizeOfType["long double"] = mSettings->platform.sizeof_long_double;
896+
mTokens->sizeOfType["bool *"] = mSettings->platform.sizeof_pointer;
897+
mTokens->sizeOfType["short *"] = mSettings->platform.sizeof_pointer;
898+
mTokens->sizeOfType["int *"] = mSettings->platform.sizeof_pointer;
899+
mTokens->sizeOfType["long *"] = mSettings->platform.sizeof_pointer;
900+
mTokens->sizeOfType["long long *"] = mSettings->platform.sizeof_pointer;
901+
mTokens->sizeOfType["float *"] = mSettings->platform.sizeof_pointer;
902+
mTokens->sizeOfType["double *"] = mSettings->platform.sizeof_pointer;
903+
mTokens->sizeOfType["long double *"] = mSettings->platform.sizeof_pointer;
904904
}
905905

906906
simplecpp::TokenList Preprocessor::preprocess(const std::string &cfgStr, std::vector<std::string> &files, simplecpp::OutputList& outputList)
@@ -929,7 +929,7 @@ std::string Preprocessor::getcode(const std::string &cfgStr, std::vector<std::st
929929
std::ostringstream ret;
930930
for (const simplecpp::Token *tok = tokens2.cfront(); tok; tok = tok->next) {
931931
if (writeLocations && tok->location.fileIndex != prevfile) {
932-
ret << "\n#line " << tok->location.line << " \"" << mTokens.file(tok->location) << "\"\n";
932+
ret << "\n#line " << tok->location.line << " \"" << mTokens->file(tok->location) << "\"\n";
933933
prevfile = tok->location.fileIndex;
934934
line = tok->location.line;
935935
}
@@ -1024,39 +1024,39 @@ void Preprocessor::error(const simplecpp::Location& loc, const std::string &msg,
10241024
void Preprocessor::error(const simplecpp::Location& loc, const std::string &msg, const std::string& id)
10251025
{
10261026
std::list<ErrorMessage::FileLocation> locationList;
1027-
if (!mTokens.file(loc).empty()) {
1028-
std::string file = Path::fromNativeSeparators(mTokens.file(loc));
1029-
if (mSettings.relativePaths)
1030-
file = Path::getRelativePath(file, mSettings.basePaths);
1027+
if (!mTokens->file(loc).empty()) {
1028+
std::string file = Path::fromNativeSeparators(mTokens->file(loc));
1029+
if (mSettings->relativePaths)
1030+
file = Path::getRelativePath(file, mSettings->basePaths);
10311031

10321032
locationList.emplace_back(file, loc.line, loc.col);
10331033
}
1034-
mErrorLogger.reportErr(ErrorMessage(std::move(locationList),
1035-
mFile0,
1036-
Severity::error,
1037-
msg,
1038-
id,
1039-
Certainty::normal));
1034+
mErrorLogger->reportErr(ErrorMessage(std::move(locationList),
1035+
mFile0,
1036+
Severity::error,
1037+
msg,
1038+
id,
1039+
Certainty::normal));
10401040
}
10411041

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

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

10621062
void Preprocessor::invalidSuppression(const simplecpp::Location& loc, const std::string &msg)
@@ -1092,10 +1092,10 @@ void Preprocessor::dump(std::ostream &out) const
10921092
for (const simplecpp::MacroUsage &macroUsage: mMacroUsage) {
10931093
out << " <macro"
10941094
<< " name=\"" << macroUsage.macroName << "\""
1095-
<< " file=\"" << ErrorLogger::toxml(mTokens.file(macroUsage.macroLocation)) << "\""
1095+
<< " file=\"" << ErrorLogger::toxml(mTokens->file(macroUsage.macroLocation)) << "\""
10961096
<< " line=\"" << macroUsage.macroLocation.line << "\""
10971097
<< " column=\"" << macroUsage.macroLocation.col << "\""
1098-
<< " usefile=\"" << ErrorLogger::toxml(mTokens.file(macroUsage.useLocation)) << "\""
1098+
<< " usefile=\"" << ErrorLogger::toxml(mTokens->file(macroUsage.useLocation)) << "\""
10991099
<< " useline=\"" << macroUsage.useLocation.line << "\""
11001100
<< " usecolumn=\"" << macroUsage.useLocation.col << "\""
11011101
<< " is-known-value=\"" << bool_to_string(macroUsage.macroValueKnown) << "\""
@@ -1108,7 +1108,7 @@ void Preprocessor::dump(std::ostream &out) const
11081108
out << " <simplecpp-if-cond>" << std::endl;
11091109
for (const simplecpp::IfCond &ifCond: mIfCond) {
11101110
out << " <if-cond"
1111-
<< " file=\"" << ErrorLogger::toxml(mTokens.file(ifCond.location)) << "\""
1111+
<< " file=\"" << ErrorLogger::toxml(mTokens->file(ifCond.location)) << "\""
11121112
<< " line=\"" << ifCond.location.line << "\""
11131113
<< " column=\"" << ifCond.location.col << "\""
11141114
<< " E=\"" << ErrorLogger::toxml(ifCond.E) << "\""
@@ -1122,7 +1122,7 @@ void Preprocessor::dump(std::ostream &out) const
11221122
std::size_t Preprocessor::calculateHash(const std::string &toolinfo) const
11231123
{
11241124
std::string hashData = toolinfo;
1125-
for (const simplecpp::Token *tok = mTokens.cfront(); tok; tok = tok->next) {
1125+
for (const simplecpp::Token *tok = mTokens->cfront(); tok; tok = tok->next) {
11261126
if (!tok->comment) {
11271127
hashData += tok->str();
11281128
hashData += static_cast<char>(tok->location.line);

0 commit comments

Comments
 (0)