Refactorization: Use emplace methods in CLI
This commit is contained in:
parent
32923b7ac5
commit
e92a95150a
|
@ -59,7 +59,7 @@ static void addFilesToList(const std::string& fileList, std::vector<std::string>
|
||||||
std::string fileName;
|
std::string fileName;
|
||||||
while (std::getline(*files, fileName)) { // next line
|
while (std::getline(*files, fileName)) { // next line
|
||||||
if (!fileName.empty()) {
|
if (!fileName.empty()) {
|
||||||
pathNames.push_back(fileName);
|
pathNames.emplace_back(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ static bool addIncludePathsToList(const std::string& fileList, std::list<std::st
|
||||||
if (!endsWith(pathName, '/'))
|
if (!endsWith(pathName, '/'))
|
||||||
pathName += '/';
|
pathName += '/';
|
||||||
|
|
||||||
pathNames->push_back(pathName);
|
pathNames->emplace_back(pathName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -185,7 +185,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
if (!endsWith(path,'/'))
|
if (!endsWith(path,'/'))
|
||||||
path += '/';
|
path += '/';
|
||||||
|
|
||||||
mSettings->includePaths.push_back(path);
|
mSettings->includePaths.emplace_back(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// User undef
|
// User undef
|
||||||
|
@ -207,7 +207,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
undef = 2 + argv[i];
|
undef = 2 + argv[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
mSettings->userUndefs.insert(undef);
|
mSettings->userUndefs.emplace(undef);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--addon=", 8) == 0)
|
else if (std::strncmp(argv[i], "--addon=", 8) == 0)
|
||||||
|
@ -231,9 +231,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
mSettings->clang = true;
|
mSettings->clang = true;
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--config-exclude=",17) ==0) {
|
else if (std::strncmp(argv[i], "--config-exclude=",17) ==0) {
|
||||||
std::string path = argv[i] + 17;
|
mSettings->configExcludePaths.emplace(Path::fromNativeSeparators(argv[i] + 17));
|
||||||
path = Path::fromNativeSeparators(path);
|
|
||||||
mSettings->configExcludePaths.insert(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--config-excludes-file=", 23) == 0) {
|
else if (std::strncmp(argv[i], "--config-excludes-file=", 23) == 0) {
|
||||||
|
@ -354,7 +352,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
// use a file filter
|
// use a file filter
|
||||||
else if (std::strncmp(argv[i], "--file-filter=", 14) == 0)
|
else if (std::strncmp(argv[i], "--file-filter=", 14) == 0)
|
||||||
mSettings->fileFilter = std::string(argv[i] + 14);
|
mSettings->fileFilter = argv[i] + 14;
|
||||||
|
|
||||||
// file list specified
|
// file list specified
|
||||||
else if (std::strncmp(argv[i], "--file-list=", 12) == 0)
|
else if (std::strncmp(argv[i], "--file-list=", 12) == 0)
|
||||||
|
@ -402,14 +400,12 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
if (!endsWith(path, '/'))
|
if (!endsWith(path, '/'))
|
||||||
path += '/';
|
path += '/';
|
||||||
}
|
}
|
||||||
mIgnoredPaths.push_back(path);
|
mIgnoredPaths.emplace_back(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--include=", 10) == 0) {
|
else if (std::strncmp(argv[i], "--include=", 10) == 0) {
|
||||||
std::string path = argv[i] + 10;
|
mSettings->userIncludes.emplace_back(Path::fromNativeSeparators(argv[i] + 10));
|
||||||
path = Path::fromNativeSeparators(path);
|
|
||||||
mSettings->userIncludes.push_back(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--includes-file=", 16) == 0) {
|
else if (std::strncmp(argv[i], "--includes-file=", 16) == 0) {
|
||||||
|
@ -513,8 +509,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
// --library
|
// --library
|
||||||
else if (std::strncmp(argv[i], "--library=", 10) == 0) {
|
else if (std::strncmp(argv[i], "--library=", 10) == 0) {
|
||||||
std::string lib(argv[i] + 10);
|
mSettings->libraries.emplace_back(argv[i] + 10);
|
||||||
mSettings->libraries.push_back(lib);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set maximum number of #ifdef configurations to check
|
// Set maximum number of #ifdef configurations to check
|
||||||
|
@ -588,7 +583,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
if (projType == ImportProject::Type::CPPCHECK_GUI) {
|
if (projType == ImportProject::Type::CPPCHECK_GUI) {
|
||||||
mPathNames = mSettings->project.guiProject.pathNames;
|
mPathNames = mSettings->project.guiProject.pathNames;
|
||||||
for (const std::string &lib : mSettings->project.guiProject.libraries)
|
for (const std::string &lib : mSettings->project.guiProject.libraries)
|
||||||
mSettings->libraries.push_back(lib);
|
mSettings->libraries.emplace_back(lib);
|
||||||
|
|
||||||
for (const std::string &ignorePath : mSettings->project.guiProject.excludedPaths)
|
for (const std::string &ignorePath : mSettings->project.guiProject.excludedPaths)
|
||||||
mIgnoredPaths.emplace_back(ignorePath);
|
mIgnoredPaths.emplace_back(ignorePath);
|
||||||
|
@ -660,10 +655,10 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const std::string::size_type pos = paths.find(';');
|
const std::string::size_type pos = paths.find(';');
|
||||||
if (pos == std::string::npos) {
|
if (pos == std::string::npos) {
|
||||||
mSettings->basePaths.push_back(Path::fromNativeSeparators(paths));
|
mSettings->basePaths.emplace_back(Path::fromNativeSeparators(paths));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mSettings->basePaths.push_back(Path::fromNativeSeparators(paths.substr(0, pos)));
|
mSettings->basePaths.emplace_back(Path::fromNativeSeparators(paths.substr(0, pos)));
|
||||||
paths.erase(0, pos + 1);
|
paths.erase(0, pos + 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -682,7 +677,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
else if (std::strncmp(argv[i], "--rule=", 7) == 0) {
|
else if (std::strncmp(argv[i], "--rule=", 7) == 0) {
|
||||||
Settings::Rule rule;
|
Settings::Rule rule;
|
||||||
rule.pattern = 7 + argv[i];
|
rule.pattern = 7 + argv[i];
|
||||||
mSettings->rules.push_back(rule);
|
mSettings->rules.emplace_back(rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rule file
|
// Rule file
|
||||||
|
@ -718,7 +713,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rule.pattern.empty())
|
if (!rule.pattern.empty())
|
||||||
mSettings->rules.push_back(rule);
|
mSettings->rules.emplace_back(rule);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printMessage("cppcheck: error: unable to load rule-file: " + std::string(12+argv[i]));
|
printMessage("cppcheck: error: unable to load rule-file: " + std::string(12+argv[i]));
|
||||||
|
@ -739,10 +734,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
else if (showtimeMode.empty())
|
else if (showtimeMode.empty())
|
||||||
mSettings->showtime = SHOWTIME_MODES::SHOWTIME_NONE;
|
mSettings->showtime = SHOWTIME_MODES::SHOWTIME_NONE;
|
||||||
else {
|
else {
|
||||||
std::string message("cppcheck: error: unrecognized showtime mode: \"");
|
printMessage("cppcheck: error: unrecognized showtime mode: \"" + showtimeMode + "\". Supported modes: file, summary, top5.");
|
||||||
message += showtimeMode;
|
|
||||||
message += "\". Supported modes: file, summary, top5.";
|
|
||||||
printMessage(message);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -899,9 +891,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
std::string path = Path::removeQuotationMarks(argv[i]);
|
mPathNames.emplace_back(Path::fromNativeSeparators(Path::removeQuotationMarks(argv[i])));
|
||||||
path = Path::fromNativeSeparators(path);
|
|
||||||
mPathNames.push_back(path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
|
||||||
|
|
||||||
for (const ImportProject::FileSettings &fsetting : settings.project.fileSettings) {
|
for (const ImportProject::FileSettings &fsetting : settings.project.fileSettings) {
|
||||||
if (matchglob(mSettings->fileFilter, fsetting.filename)) {
|
if (matchglob(mSettings->fileFilter, fsetting.filename)) {
|
||||||
newList.push_back(fsetting);
|
newList.emplace_back(fsetting);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!newList.empty())
|
if (!newList.empty())
|
||||||
|
@ -897,7 +897,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha
|
||||||
if (!settings.buildDir.empty()) {
|
if (!settings.buildDir.empty()) {
|
||||||
std::list<std::string> fileNames;
|
std::list<std::string> fileNames;
|
||||||
for (std::map<std::string, std::size_t>::const_iterator i = mFiles.begin(); i != mFiles.end(); ++i)
|
for (std::map<std::string, std::size_t>::const_iterator i = mFiles.begin(); i != mFiles.end(); ++i)
|
||||||
fileNames.push_back(i->first);
|
fileNames.emplace_back(i->first);
|
||||||
AnalyzerInformation::writeFilesTxt(settings.buildDir, fileNames, settings.project.fileSettings);
|
AnalyzerInformation::writeFilesTxt(settings.buildDir, fileNames, settings.project.fileSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ int ThreadExecutor::handleRead(int rpipe, unsigned int &result)
|
||||||
// Alert only about unique errors
|
// Alert only about unique errors
|
||||||
std::string errmsg = msg.toString(mSettings.verbose);
|
std::string errmsg = msg.toString(mSettings.verbose);
|
||||||
if (std::find(mErrorList.begin(), mErrorList.end(), errmsg) == mErrorList.end()) {
|
if (std::find(mErrorList.begin(), mErrorList.end(), errmsg) == mErrorList.end()) {
|
||||||
mErrorList.push_back(errmsg);
|
mErrorList.emplace_back(errmsg);
|
||||||
if (type == REPORT_ERROR)
|
if (type == REPORT_ERROR)
|
||||||
mErrorLogger.reportErr(msg);
|
mErrorLogger.reportErr(msg);
|
||||||
else
|
else
|
||||||
|
@ -522,7 +522,7 @@ void ThreadExecutor::report(const ErrorLogger::ErrorMessage &msg, MessageType ms
|
||||||
|
|
||||||
EnterCriticalSection(&mErrorSync);
|
EnterCriticalSection(&mErrorSync);
|
||||||
if (std::find(mErrorList.begin(), mErrorList.end(), errmsg) == mErrorList.end()) {
|
if (std::find(mErrorList.begin(), mErrorList.end(), errmsg) == mErrorList.end()) {
|
||||||
mErrorList.push_back(errmsg);
|
mErrorList.emplace_back(errmsg);
|
||||||
reportError = true;
|
reportError = true;
|
||||||
}
|
}
|
||||||
LeaveCriticalSection(&mErrorSync);
|
LeaveCriticalSection(&mErrorSync);
|
||||||
|
|
Loading…
Reference in New Issue