Refactoring; Use range for loops

This commit is contained in:
Daniel Marjamäki 2018-08-19 17:27:41 +02:00
parent 4d78a2e178
commit a30941d885
1 changed files with 19 additions and 19 deletions

View File

@ -138,12 +138,12 @@ void ImportProject::FileSettings::setIncludePaths(const std::string &basepath, c
uniqueIncludePaths.sort(); uniqueIncludePaths.sort();
uniqueIncludePaths.unique(); uniqueIncludePaths.unique();
for (std::list<std::string>::const_iterator it = uniqueIncludePaths.begin(); it != uniqueIncludePaths.end(); ++it) { for (const std::string &it : uniqueIncludePaths) {
if (it->empty()) if (it.empty())
continue; continue;
if (it->compare(0,2,"%(")==0) if (it.compare(0,2,"%(")==0)
continue; continue;
std::string s(Path::fromNativeSeparators(*it)); std::string s(Path::fromNativeSeparators(it));
if (s[0] == '/' || (s.size() > 1U && s.compare(1,2,":/") == 0)) { if (s[0] == '/' || (s.size() > 1U && s.compare(1,2,":/") == 0)) {
if (!endsWith(s,'/')) if (!endsWith(s,'/'))
s += '/'; s += '/';
@ -154,10 +154,10 @@ void ImportProject::FileSettings::setIncludePaths(const std::string &basepath, c
if (endsWith(s,'/')) // this is a temporary hack, simplifyPath can crash if path ends with '/' if (endsWith(s,'/')) // this is a temporary hack, simplifyPath can crash if path ends with '/'
s.erase(s.size() - 1U); // TODO: Use std::string::pop_back() as soon as travis supports it s.erase(s.size() - 1U); // TODO: Use std::string::pop_back() as soon as travis supports it
if (s.find("$(")==std::string::npos) { if (s.find("$(") == std::string::npos) {
s = Path::simplifyPath(basepath + s); s = Path::simplifyPath(basepath + s);
} else { } else {
if (!simplifyPathWithVariables(s,variables)) if (!simplifyPathWithVariables(s, variables))
continue; continue;
} }
if (s.empty()) if (s.empty())
@ -551,26 +551,26 @@ void ImportProject::importVcxproj(const std::string &filename, std::map<std::str
} }
} }
for (std::list<std::string>::const_iterator c = compileList.begin(); c != compileList.end(); ++c) { for (const std::string &c : compileList) {
for (std::list<ProjectConfiguration>::const_iterator p = projectConfigurationList.begin(); p != projectConfigurationList.end(); ++p) { for (const ProjectConfiguration &p : projectConfigurationList) {
FileSettings fs; FileSettings fs;
fs.filename = Path::simplifyPath(Path::isAbsolute(*c) ? *c : Path::getPathFromFilename(filename) + *c); fs.filename = Path::simplifyPath(Path::isAbsolute(c) ? c : Path::getPathFromFilename(filename) + c);
fs.cfg = p->name; fs.cfg = p.name;
fs.msc = true; fs.msc = true;
fs.useMfc = useOfMfc; fs.useMfc = useOfMfc;
fs.defines = "_WIN32=1"; fs.defines = "_WIN32=1";
if (p->platform == ProjectConfiguration::Win32) if (p.platform == ProjectConfiguration::Win32)
fs.platformType = cppcheck::Platform::Win32W; fs.platformType = cppcheck::Platform::Win32W;
else if (p->platform == ProjectConfiguration::x64) { else if (p.platform == ProjectConfiguration::x64) {
fs.platformType = cppcheck::Platform::Win64; fs.platformType = cppcheck::Platform::Win64;
fs.defines += ";_WIN64=1"; fs.defines += ";_WIN64=1";
} }
std::string additionalIncludePaths; std::string additionalIncludePaths;
for (std::list<ItemDefinitionGroup>::const_iterator i = itemDefinitionGroupList.begin(); i != itemDefinitionGroupList.end(); ++i) { for (const ItemDefinitionGroup &i : itemDefinitionGroupList) {
if (!i->conditionIsTrue(*p)) if (!i.conditionIsTrue(p))
continue; continue;
fs.defines += ';' + i->preprocessorDefinitions; fs.defines += ';' + i.preprocessorDefinitions;
additionalIncludePaths += ';' + i->additionalIncludePaths; additionalIncludePaths += ';' + i.additionalIncludePaths;
} }
fs.setDefines(fs.defines); fs.setDefines(fs.defines);
fs.setIncludePaths(Path::getPathFromFilename(filename), toStringList(includePath + ';' + additionalIncludePaths), variables); fs.setIncludePaths(Path::getPathFromFilename(filename), toStringList(includePath + ';' + additionalIncludePaths), variables);
@ -820,7 +820,7 @@ void ImportProject::importBcb6Prj(const std::string &projectFilename)
const std::string cppDefines = cppPredefines + ";" + defines; const std::string cppDefines = cppPredefines + ";" + defines;
const bool forceCppMode = (cflags.find("-P") != cflags.end()); const bool forceCppMode = (cflags.find("-P") != cflags.end());
for (std::list<std::string>::const_iterator c = compileList.begin(); c != compileList.end(); ++c) { for (const std::string &c : compileList) {
// C++ compilation is selected by file extension by default, so these // C++ compilation is selected by file extension by default, so these
// defines have to be configured on a per-file base. // defines have to be configured on a per-file base.
// //
@ -830,11 +830,11 @@ void ImportProject::importBcb6Prj(const std::string &projectFilename)
// (http://docwiki.embarcadero.com/RADStudio/Tokyo/en/BCC32.EXE,_the_C%2B%2B_32-bit_Command-Line_Compiler) // (http://docwiki.embarcadero.com/RADStudio/Tokyo/en/BCC32.EXE,_the_C%2B%2B_32-bit_Command-Line_Compiler)
// //
// We can also force C++ compilation for all files using the -P command line switch. // We can also force C++ compilation for all files using the -P command line switch.
const bool cppMode = forceCppMode || Path::getFilenameExtensionInLowerCase(*c) == ".cpp"; const bool cppMode = forceCppMode || Path::getFilenameExtensionInLowerCase(c) == ".cpp";
FileSettings fs; FileSettings fs;
fs.setIncludePaths(projectDir, toStringList(includePath), variables); fs.setIncludePaths(projectDir, toStringList(includePath), variables);
fs.setDefines(cppMode ? cppDefines : defines); fs.setDefines(cppMode ? cppDefines : defines);
fs.filename = Path::simplifyPath(Path::isAbsolute(*c) ? *c : projectDir + *c); fs.filename = Path::simplifyPath(Path::isAbsolute(c) ? c : projectDir + c);
fileSettings.push_back(fs); fileSettings.push_back(fs);
} }
} }