Constify some code as suggested by clang-tidy

This commit is contained in:
Cengizhan Pasaoglu 2020-10-18 02:00:29 +03:00
parent c05e561474
commit bd705788f6
19 changed files with 61 additions and 59 deletions

View File

@ -182,7 +182,7 @@ void cmFindCommon::SelectDefaultSearchModes()
{ this->NoCMakeSystemPath, "CMAKE_FIND_USE_CMAKE_SYSTEM_PATH" } }
};
for (auto& path : search_paths) {
for (auto const& path : search_paths) {
cmProp def = this->Makefile->GetDefinition(path.second);
if (def) {
path.first = !cmIsOn(*def);

View File

@ -60,7 +60,7 @@ struct TextContent : public cmGeneratorExpressionEvaluator
void Extend(size_t length) { this->Length += length; }
size_t GetLength() { return this->Length; }
size_t GetLength() const { return this->Length; }
private:
const char* Content;

View File

@ -677,7 +677,7 @@ struct CompilerIdNode : public cmGeneratorExpressionNode
}
static cmsys::RegularExpression compilerIdValidator("^[A-Za-z0-9_]*$");
for (auto& param : parameters) {
for (auto const& param : parameters) {
if (!compilerIdValidator.find(param)) {
reportError(context, content->GetOriginalExpression(),
@ -805,7 +805,7 @@ struct PlatformIdNode : public cmGeneratorExpressionNode
return parameters.front().empty() ? "1" : "0";
}
for (auto& param : parameters) {
for (auto const& param : parameters) {
if (param == platformId) {
return "1";
}
@ -901,7 +901,7 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
return std::string();
}
context->HadContextSensitiveCondition = true;
for (auto& param : parameters) {
for (auto const& param : parameters) {
if (context->Config.empty()) {
if (param.empty()) {
return "1";
@ -927,7 +927,7 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
if (cmProp mapValue = context->CurrentTarget->GetProperty(mapProp)) {
cmExpandList(cmSystemTools::UpperCase(*mapValue), mappedConfigs);
for (auto& param : parameters) {
for (auto const& param : parameters) {
if (cm::contains(mappedConfigs, cmSystemTools::UpperCase(param))) {
return "1";
}
@ -995,7 +995,7 @@ static const struct CompileLanguageNode : public cmGeneratorExpressionNode
return context->Language;
}
for (auto& param : parameters) {
for (auto const& param : parameters) {
if (context->Language == param) {
return "1";
}
@ -1101,7 +1101,7 @@ static const struct LinkLanguageNode : public cmGeneratorExpressionNode
return context->Language;
}
for (auto& param : parameters) {
for (auto const& param : parameters) {
if (context->Language == param) {
return "1";
}
@ -1129,7 +1129,7 @@ struct LinkerId
}
static cmsys::RegularExpression linkerIdValidator("^[A-Za-z0-9_]*$");
for (auto& param : parameters) {
for (auto const& param : parameters) {
if (!linkerIdValidator.find(param)) {
reportError(context, content->GetOriginalExpression(),
"Expression syntax not recognized.");

View File

@ -254,7 +254,7 @@ EvaluatedTargetPropertyEntries EvaluateTargetPropertyEntries(
{
EvaluatedTargetPropertyEntries out;
out.Entries.reserve(in.size());
for (auto& entry : in) {
for (auto const& entry : in) {
out.Entries.emplace_back(EvaluateTargetPropertyEntry(
thisTarget, config, lang, dagChecker, *entry));
}
@ -332,7 +332,7 @@ cmGeneratorTarget::~cmGeneratorTarget() = default;
const std::string& cmGeneratorTarget::GetSourcesProperty() const
{
std::vector<std::string> values;
for (auto& se : this->SourceEntries) {
for (auto const& se : this->SourceEntries) {
values.push_back(se->GetInput());
}
static std::string value;
@ -2504,7 +2504,7 @@ public:
}
}
bool GetHadLinkLanguageSensitiveCondition()
bool GetHadLinkLanguageSensitiveCondition() const
{
return HadLinkLanguageSensitiveCondition;
}

View File

@ -2601,7 +2601,7 @@ void cmGlobalGenerator::AddGlobalTarget_Test(
}
void cmGlobalGenerator::AddGlobalTarget_EditCache(
std::vector<GlobalTargetInfo>& targets)
std::vector<GlobalTargetInfo>& targets) const
{
const char* editCacheTargetName = this->GetEditCacheTargetName();
if (!editCacheTargetName) {
@ -2635,7 +2635,7 @@ void cmGlobalGenerator::AddGlobalTarget_EditCache(
}
void cmGlobalGenerator::AddGlobalTarget_RebuildCache(
std::vector<GlobalTargetInfo>& targets)
std::vector<GlobalTargetInfo>& targets) const
{
const char* rebuildCacheTargetName = this->GetRebuildCacheTargetName();
if (!rebuildCacheTargetName) {
@ -2758,7 +2758,7 @@ void cmGlobalGenerator::AddGlobalTarget_Install(
}
}
std::string cmGlobalGenerator::GetPredefinedTargetsFolder()
std::string cmGlobalGenerator::GetPredefinedTargetsFolder() const
{
cmProp prop = this->GetCMakeInstance()->GetState()->GetGlobalProperty(
"PREDEFINED_TARGETS_FOLDER");

View File

@ -574,8 +574,9 @@ protected:
void AddGlobalTarget_Package(std::vector<GlobalTargetInfo>& targets);
void AddGlobalTarget_PackageSource(std::vector<GlobalTargetInfo>& targets);
void AddGlobalTarget_Test(std::vector<GlobalTargetInfo>& targets);
void AddGlobalTarget_EditCache(std::vector<GlobalTargetInfo>& targets);
void AddGlobalTarget_RebuildCache(std::vector<GlobalTargetInfo>& targets);
void AddGlobalTarget_EditCache(std::vector<GlobalTargetInfo>& targets) const;
void AddGlobalTarget_RebuildCache(
std::vector<GlobalTargetInfo>& targets) const;
void AddGlobalTarget_Install(std::vector<GlobalTargetInfo>& targets);
cmTarget CreateGlobalTarget(GlobalTargetInfo const& gti, cmMakefile* mf);
@ -601,7 +602,7 @@ protected:
cmGeneratorTarget* FindGeneratorTargetImpl(std::string const& name) const;
std::string GetPredefinedTargetsFolder();
std::string GetPredefinedTargetsFolder() const;
private:
using TargetMap = std::unordered_map<std::string, cmTarget*>;

View File

@ -704,7 +704,7 @@ bool cmGlobalGhsMultiGenerator::ComputeTargetBuildOrder(
std::set<cmGeneratorTarget const*> temp;
std::set<cmGeneratorTarget const*> perm;
for (auto ti : tgt) {
for (auto const ti : tgt) {
bool r = VisitTarget(temp, perm, build, ti);
if (r) {
return r;
@ -726,7 +726,7 @@ bool cmGlobalGhsMultiGenerator::VisitTarget(
* in the same order */
OrderedTargetDependSet sortedTargets(this->GetTargetDirectDepends(ti),
"");
for (auto& di : sortedTargets) {
for (auto const& di : sortedTargets) {
if (this->VisitTarget(temp, perm, order, di)) {
return true;
}

View File

@ -1057,7 +1057,7 @@ void cmGlobalNinjaGenerator::CloseCompileCommandsStream()
}
}
void cmGlobalNinjaGenerator::WriteDisclaimer(std::ostream& os)
void cmGlobalNinjaGenerator::WriteDisclaimer(std::ostream& os) const
{
os << "# CMAKE generated file: DO NOT EDIT!\n"
<< "# Generated by \"" << this->GetName() << "\""
@ -1088,7 +1088,7 @@ std::string cmGlobalNinjaGenerator::OrderDependsTargetForTarget(
void cmGlobalNinjaGenerator::AppendTargetOutputs(
cmGeneratorTarget const* target, cmNinjaDeps& outputs,
const std::string& config, cmNinjaTargetDepends depends)
const std::string& config, cmNinjaTargetDepends depends) const
{
// for frameworks, we want the real name, not smple name
// frameworks always appear versioned, and the build.ninja

View File

@ -252,7 +252,7 @@ public:
: GG(gg)
{
}
std::string operator()(std::string const& path)
std::string operator()(std::string const& path) const
{
return this->GG->ConvertToNinjaPath(path);
}
@ -323,7 +323,7 @@ public:
void AppendTargetOutputs(cmGeneratorTarget const* target,
cmNinjaDeps& outputs, const std::string& config,
cmNinjaTargetDepends depends);
cmNinjaTargetDepends depends) const;
void AppendTargetDepends(cmGeneratorTarget const* target,
cmNinjaDeps& outputs, const std::string& config,
const std::string& fileConfig,
@ -463,7 +463,7 @@ private:
void CleanMetaData();
/// Write the common disclaimer text at the top of each build file.
void WriteDisclaimer(std::ostream& os);
void WriteDisclaimer(std::ostream& os) const;
void WriteAssumedSourceDependencies();

View File

@ -279,7 +279,7 @@ static void MoveSystemIncludesToEnd(std::vector<BT<std::string>>& includeDirs,
});
}
void cmLocalGenerator::TraceDependencies()
void cmLocalGenerator::TraceDependencies() const
{
// Generate the rule files for each target.
const auto& targets = this->GetGeneratorTargets();
@ -3210,7 +3210,7 @@ std::string cmLocalGenerator::GetProjectName() const
}
std::string cmLocalGenerator::ConstructComment(
cmCustomCommandGenerator const& ccg, const char* default_comment)
cmCustomCommandGenerator const& ccg, const char* default_comment) const
{
// Check for a comment provided with the command.
if (ccg.GetComment()) {

View File

@ -77,7 +77,7 @@ public:
/**
* Calls TraceVSDependencies() on all targets of this generator.
*/
void TraceDependencies();
void TraceDependencies() const;
virtual void AddHelperCommands() {}
@ -451,7 +451,7 @@ public:
const std::string& fname);
/** Construct a comment for a custom command. */
std::string ConstructComment(cmCustomCommandGenerator const& ccg,
const char* default_comment = "");
const char* default_comment = "") const;
// Compute object file names.
std::string GetObjectFileNameWithoutTarget(
const cmSourceFile& source, std::string const& dir_max,

View File

@ -178,11 +178,11 @@ public:
/** Get whether to create rules to generate preprocessed and
assembly sources. This could be converted to a variable lookup
later. */
bool GetCreatePreprocessedSourceRules()
bool GetCreatePreprocessedSourceRules() const
{
return !this->SkipPreprocessedSourceRules;
}
bool GetCreateAssemblySourceRules()
bool GetCreateAssemblySourceRules() const
{
return !this->SkipAssemblySourceRules;
}

View File

@ -2029,7 +2029,7 @@ void cmMakefile::RemoveDefinition(const std::string& name)
#endif
}
void cmMakefile::RemoveCacheDefinition(const std::string& name)
void cmMakefile::RemoveCacheDefinition(const std::string& name) const
{
this->GetState()->RemoveCacheEntry(name);
}
@ -2839,7 +2839,7 @@ void cmMakefile::SetRecursionDepth(int recursionDepth)
this->RecursionDepth = recursionDepth;
}
std::string cmMakefile::NewDeferId()
std::string cmMakefile::NewDeferId() const
{
return this->GetGlobalGenerator()->NewDeferId();
}
@ -4039,7 +4039,7 @@ cmTest* cmMakefile::GetTest(const std::string& testName) const
}
void cmMakefile::GetTests(const std::string& config,
std::vector<cmTest*>& tests)
std::vector<cmTest*>& tests) const
{
for (const auto& generator : this->GetTestGenerators()) {
if (generator->TestsForConfig(config)) {
@ -4389,7 +4389,7 @@ cmPolicies::PolicyStatus cmMakefile::GetPolicyStatus(cmPolicies::PolicyID id,
return this->StateSnapshot.GetPolicy(id, parent_scope);
}
bool cmMakefile::PolicyOptionalWarningEnabled(std::string const& var)
bool cmMakefile::PolicyOptionalWarningEnabled(std::string const& var) const
{
// Check for an explicit CMAKE_POLICY_WARNING_CMP<NNNN> setting.
if (cmProp val = this->GetDefinition(var)) {
@ -4494,7 +4494,7 @@ bool cmMakefile::HasCMP0054AlreadyBeenReported(
return !this->CMP0054ReportedIds.insert(context).second;
}
void cmMakefile::RecordPolicies(cmPolicies::PolicyMap& pm)
void cmMakefile::RecordPolicies(cmPolicies::PolicyMap& pm) const
{
/* Record the setting of every policy. */
using PolicyID = cmPolicies::PolicyID;

View File

@ -304,7 +304,7 @@ public:
*/
void RemoveDefinition(const std::string& name);
//! Remove a definition from the cache.
void RemoveCacheDefinition(const std::string& name);
void RemoveCacheDefinition(const std::string& name) const;
/**
* Specify the name of the project for this build.
@ -345,7 +345,7 @@ public:
bool parent_scope = false) const;
bool SetPolicyVersion(std::string const& version_min,
std::string const& version_max);
void RecordPolicies(cmPolicies::PolicyMap& pm);
void RecordPolicies(cmPolicies::PolicyMap& pm) const;
//@}
/** Helper class to push and pop policies automatically. */
@ -738,7 +738,7 @@ public:
/**
* Get all tests that run under the given configuration.
*/
void GetTests(const std::string& config, std::vector<cmTest*>& tests);
void GetTests(const std::string& config, std::vector<cmTest*>& tests) const;
/**
* Return a location of a file in cmake or custom modules directory
@ -885,7 +885,7 @@ public:
return this->SystemIncludeDirectories;
}
bool PolicyOptionalWarningEnabled(std::string const& var);
bool PolicyOptionalWarningEnabled(std::string const& var) const;
void PushLoopBlock();
void PopLoopBlock();
@ -926,7 +926,7 @@ public:
int GetRecursionDepth() const;
void SetRecursionDepth(int recursionDepth);
std::string NewDeferId();
std::string NewDeferId() const;
bool DeferCall(std::string id, std::string fileName, cmListFileFunction lff);
bool DeferCancelCall(std::string const& id);
cm::optional<std::string> DeferGetCallIds() const;

View File

@ -29,13 +29,13 @@ public:
{
}
bool operator>(IntegerVersion const version)
bool operator>(IntegerVersion const version) const
{
return (this->Major > version.Major) ||
((this->Major == version.Major) && (this->Minor > version.Minor));
}
bool operator>=(IntegerVersion const version)
bool operator>=(IntegerVersion const version) const
{
return (this->Major > version.Major) ||
((this->Major == version.Major) && (this->Minor >= version.Minor));

View File

@ -213,7 +213,7 @@ public:
bool CheckImportedLibName(std::string const& prop,
std::string const& value) const;
std::string ProcessSourceItemCMP0049(const std::string& s);
std::string ProcessSourceItemCMP0049(const std::string& s) const;
};
namespace {
@ -740,7 +740,8 @@ void cmTarget::AddSources(std::vector<std::string> const& srcs)
}
}
std::string cmTargetInternals::ProcessSourceItemCMP0049(const std::string& s)
std::string cmTargetInternals::ProcessSourceItemCMP0049(
const std::string& s) const
{
std::string src = s;
@ -791,7 +792,7 @@ struct CreateLocation
{
}
cmSourceFileLocation operator()(const std::string& filename)
cmSourceFileLocation operator()(const std::string& filename) const
{
return cmSourceFileLocation(this->Makefile, filename);
}
@ -857,7 +858,7 @@ cmSourceFile* cmTarget::AddSource(const std::string& src, bool before)
cmSourceFileLocationKind::Known);
}
void cmTarget::ClearDependencyInformation(cmMakefile& mf)
void cmTarget::ClearDependencyInformation(cmMakefile& mf) const
{
std::string depname = cmStrCat(this->GetName(), "_LIB_DEPENDS");
mf.RemoveCacheDefinition(depname);

View File

@ -114,7 +114,7 @@ public:
LinkLibraryVectorType const& GetOriginalLinkLibraries() const;
//! Clear the dependency information recorded for this target, if any.
void ClearDependencyInformation(cmMakefile& mf);
void ClearDependencyInformation(cmMakefile& mf) const;
void AddLinkLibrary(cmMakefile& mf, std::string const& lib,
cmTargetLinkLibraryType llt);

View File

@ -1938,7 +1938,7 @@ int cmake::ActualConfigure()
}
}
auto& mf = this->GlobalGenerator->GetMakefiles()[0];
const auto& mf = this->GlobalGenerator->GetMakefiles()[0];
if (mf->IsOn("CTEST_USE_LAUNCHERS") &&
!this->State->GetGlobalProperty("RULE_LAUNCH_COMPILE")) {
cmSystemTools::Error(
@ -2280,12 +2280,12 @@ cmProp cmake::GetCacheDefinition(const std::string& name) const
return this->State->GetInitializedCacheValue(name);
}
void cmake::AddScriptingCommands()
void cmake::AddScriptingCommands() const
{
GetScriptingCommands(this->GetState());
}
void cmake::AddProjectCommands()
void cmake::AddProjectCommands() const
{
GetProjectCommands(this->GetState());
}

View File

@ -411,7 +411,7 @@ public:
WorkingMode GetWorkingMode() { return this->CurrentWorkingMode; }
//! Debug the try compile stuff by not deleting the files
bool GetDebugTryCompile() { return this->DebugTryCompile; }
bool GetDebugTryCompile() const { return this->DebugTryCompile; }
void DebugTryCompileOn() { this->DebugTryCompile = true; }
/**
@ -456,11 +456,11 @@ public:
void SetShowLogContext(bool b) { this->LogContext = b; }
//! Do we want debug output during the cmake run.
bool GetDebugOutput() { return this->DebugOutput; }
bool GetDebugOutput() const { return this->DebugOutput; }
void SetDebugOutputOn(bool b) { this->DebugOutput = b; }
//! Do we want debug output from the find commands during the cmake run.
bool GetDebugFindOutput() { return this->DebugFindOutput; }
bool GetDebugFindOutput() const { return this->DebugFindOutput; }
void SetDebugFindOutputOn(bool b) { this->DebugFindOutput = b; }
//! Do we want trace output during the cmake run.
@ -482,11 +482,11 @@ public:
void SetTraceFile(std::string const& file);
void PrintTraceFormatVersion();
bool GetWarnUninitialized() { return this->WarnUninitialized; }
bool GetWarnUninitialized() const { return this->WarnUninitialized; }
void SetWarnUninitialized(bool b) { this->WarnUninitialized = b; }
bool GetWarnUnusedCli() { return this->WarnUnusedCli; }
bool GetWarnUnusedCli() const { return this->WarnUnusedCli; }
void SetWarnUnusedCli(bool b) { this->WarnUnusedCli = b; }
bool GetCheckSystemVars() { return this->CheckSystemVars; }
bool GetCheckSystemVars() const { return this->CheckSystemVars; }
void SetCheckSystemVars(bool b) { this->CheckSystemVars = b; }
void MarkCliAsUsed(const std::string& variable);
@ -591,8 +591,8 @@ protected:
using RegisteredExtraGeneratorsVector =
std::vector<cmExternalMakefileProjectGeneratorFactory*>;
RegisteredExtraGeneratorsVector ExtraGenerators;
void AddScriptingCommands();
void AddProjectCommands();
void AddScriptingCommands() const;
void AddProjectCommands() const;
void AddDefaultGenerators();
void AddDefaultExtraGenerators();