diff options
author | Sebastian Holtermann <sebholt@xwmw.org> | 2019-08-22 14:34:40 (GMT) |
---|---|---|
committer | Sebastian Holtermann <sebholt@xwmw.org> | 2019-08-22 14:38:10 (GMT) |
commit | 9b334397f55b70689ff1d8f7d6767a34834e85b6 (patch) | |
tree | bc33e4dc90eef2c351e278219bc9743d40af632c /Source/cmNinjaNormalTargetGenerator.cxx | |
parent | 130dbe4a5d49baa4404a399860bd3a6182783ece (diff) | |
download | CMake-9b334397f55b70689ff1d8f7d6767a34834e85b6.zip CMake-9b334397f55b70689ff1d8f7d6767a34834e85b6.tar.gz CMake-9b334397f55b70689ff1d8f7d6767a34834e85b6.tar.bz2 |
Source sweep: Use cmStrCat for string concatenation
This patch is generated by a python script that uses regular expressions to
search for string concatenation patterns of the kind
```
std::string str = <ARG0>;
str += <ARG1>;
str += <ARG2>;
...
```
and replaces them with a single `cmStrCat` call
```
std::string str = cmStrCat(<ARG0>, <ARG1>, <ARG2>, ...);
```
If any `<ARGX>` is itself a concatenated string of the kind
```
a + b + c + ...;
```
then `<ARGX>` is split into multiple arguments for the `cmStrCat` call.
If there's a sequence of literals in the `<ARGX>`, then all literals in the
sequence are concatenated and merged into a single literal argument for
the `cmStrCat` call.
Single character strings are converted to single char arguments for
the `cmStrCat` call.
`std::to_string(...)` wrappings are removed from `cmStrCat` arguments,
because it supports numeric types as well as string types.
`arg.substr(x)` arguments to `cmStrCat` are replaced with
`cm::string_view(arg).substr(x)`
Diffstat (limited to 'Source/cmNinjaNormalTargetGenerator.cxx')
-rw-r--r-- | Source/cmNinjaNormalTargetGenerator.cxx | 92 |
1 files changed, 33 insertions, 59 deletions
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 15c6580..2841245 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -218,8 +218,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkRule(bool useResponseFile) const char* val = this->GetLocalGenerator()->GetRuleLauncher( this->GetGeneratorTarget(), "RULE_LAUNCH_LINK"); if (val && *val) { - launcher = val; - launcher += " "; + launcher = cmStrCat(val, ' '); } std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander( @@ -239,16 +238,10 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkRule(bool useResponseFile) rule.Command = this->GetLocalGenerator()->BuildCommandLine(linkCmds); // Write the linker rule with response file if needed. - rule.Comment = "Rule for linking "; - rule.Comment += this->TargetLinkLanguage; - rule.Comment += " "; - rule.Comment += this->GetVisibleTypeName(); - rule.Comment += "."; - rule.Description = "Linking "; - rule.Description += this->TargetLinkLanguage; - rule.Description += " "; - rule.Description += this->GetVisibleTypeName(); - rule.Description += " $TARGET_FILE"; + rule.Comment = cmStrCat("Rule for linking ", this->TargetLinkLanguage, ' ', + this->GetVisibleTypeName(), '.'); + rule.Description = cmStrCat("Linking ", this->TargetLinkLanguage, ' ', + this->GetVisibleTypeName(), " $TARGET_FILE"); rule.Restat = "$RESTAT"; this->GetGlobalGenerator()->AddRule(rule); @@ -282,8 +275,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) std::string responseFlag; - std::string cmakeVarLang = "CMAKE_"; - cmakeVarLang += this->TargetLinkLanguage; + std::string cmakeVarLang = cmStrCat("CMAKE_", this->TargetLinkLanguage); // build response file name std::string cmakeLinkVar = cmakeVarLang + "_RESPONSE_FILE_LINK_FLAG"; @@ -357,8 +349,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) const char* val = this->GetLocalGenerator()->GetRuleLauncher( this->GetGeneratorTarget(), "RULE_LAUNCH_LINK"); if (val && *val) { - launcher = val; - launcher += " "; + launcher = cmStrCat(val, ' '); } std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander( @@ -380,16 +371,10 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) rule.Command = this->GetLocalGenerator()->BuildCommandLine(linkCmds); // Write the linker rule with response file if needed. - rule.Comment = "Rule for linking "; - rule.Comment += this->TargetLinkLanguage; - rule.Comment += " "; - rule.Comment += this->GetVisibleTypeName(); - rule.Comment += "."; - rule.Description = "Linking "; - rule.Description += this->TargetLinkLanguage; - rule.Description += " "; - rule.Description += this->GetVisibleTypeName(); - rule.Description += " $TARGET_FILE"; + rule.Comment = cmStrCat("Rule for linking ", this->TargetLinkLanguage, ' ', + this->GetVisibleTypeName(), '.'); + rule.Description = cmStrCat("Linking ", this->TargetLinkLanguage, ' ', + this->GetVisibleTypeName(), " $TARGET_FILE"); rule.Restat = "$RESTAT"; this->GetGlobalGenerator()->AddRule(rule); } @@ -467,19 +452,19 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd() if (linkCmd) { std::string linkCmdStr = linkCmd; if (this->GetGeneratorTarget()->HasImplibGNUtoMS(this->ConfigName)) { - std::string ruleVar = "CMAKE_"; - ruleVar += this->GeneratorTarget->GetLinkerLanguage(this->ConfigName); - ruleVar += "_GNUtoMS_RULE"; + std::string ruleVar = cmStrCat( + "CMAKE_", this->GeneratorTarget->GetLinkerLanguage(this->ConfigName), + "_GNUtoMS_RULE"); if (const char* rule = this->Makefile->GetDefinition(ruleVar)) { linkCmdStr += rule; } } cmExpandList(linkCmdStr, linkCmds); if (this->GetGeneratorTarget()->GetPropertyAsBool("LINK_WHAT_YOU_USE")) { - std::string cmakeCommand = + std::string cmakeCommand = cmStrCat( this->GetLocalGenerator()->ConvertToOutputFormat( - cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL); - cmakeCommand += " -E __run_co_compile --lwyu="; + cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL), + " -E __run_co_compile --lwyu="); cmGeneratorTarget& gt = *this->GetGeneratorTarget(); const std::string cfgName = this->GetConfigName(); std::string targetOutputReal = this->ConvertToNinjaPath( @@ -502,9 +487,8 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd() } // TODO: Use ARCHIVE_APPEND for archives over a certain size. { - std::string linkCmdVar = "CMAKE_"; - linkCmdVar += this->TargetLinkLanguage; - linkCmdVar += "_ARCHIVE_CREATE"; + std::string linkCmdVar = + cmStrCat("CMAKE_", this->TargetLinkLanguage, "_ARCHIVE_CREATE"); linkCmdVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable( linkCmdVar, this->TargetLinkLanguage, this->GetConfigName()); @@ -513,9 +497,8 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd() cmExpandList(linkCmd, linkCmds); } { - std::string linkCmdVar = "CMAKE_"; - linkCmdVar += this->TargetLinkLanguage; - linkCmdVar += "_ARCHIVE_FINISH"; + std::string linkCmdVar = + cmStrCat("CMAKE_", this->TargetLinkLanguage, "_ARCHIVE_FINISH"); linkCmdVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable( linkCmdVar, this->TargetLinkLanguage, this->GetConfigName()); @@ -590,10 +573,8 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement() // Compute the comment. cmNinjaBuild build(this->LanguageLinkerDeviceRule()); - build.Comment = "Link the "; - build.Comment += this->GetVisibleTypeName(); - build.Comment += " "; - build.Comment += targetOutputReal; + build.Comment = + cmStrCat("Link the ", this->GetVisibleTypeName(), ' ', targetOutputReal); cmNinjaVars& vars = build.Variables; @@ -728,13 +709,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() outpath); // Calculate the output path - targetOutput = outpath; - targetOutput += "/"; - targetOutput += this->TargetNames.Output; + targetOutput = cmStrCat(outpath, '/', this->TargetNames.Output); targetOutput = this->ConvertToNinjaPath(targetOutput); - targetOutputReal = outpath; - targetOutputReal += "/"; - targetOutputReal += this->TargetNames.Real; + targetOutputReal = cmStrCat(outpath, '/', this->TargetNames.Real); targetOutputReal = this->ConvertToNinjaPath(targetOutputReal); } else if (gt->IsFrameworkOnApple()) { // Create the library framework. @@ -757,10 +734,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() cmNinjaVars& vars = linkBuild.Variables; // Compute the comment. - linkBuild.Comment = "Link the "; - linkBuild.Comment += this->GetVisibleTypeName(); - linkBuild.Comment += " "; - linkBuild.Comment += targetOutputReal; + linkBuild.Comment = + cmStrCat("Link the ", this->GetVisibleTypeName(), ' ', targetOutputReal); // Compute outputs. linkBuild.Outputs.push_back(targetOutputReal); @@ -990,11 +965,11 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() std::string cmakeCommand = this->GetLocalGenerator()->ConvertToOutputFormat( cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL); - std::string cmd = cmakeCommand; - cmd += " -E __create_def "; - cmd += this->GetLocalGenerator()->ConvertToOutputFormat( - mdi->DefFile, cmOutputConverter::SHELL); - cmd += " "; + std::string cmd = + cmStrCat(cmakeCommand, " -E __create_def ", + this->GetLocalGenerator()->ConvertToOutputFormat( + mdi->DefFile, cmOutputConverter::SHELL), + ' '); std::string obj_list_file = mdi->DefFile + ".objs"; cmd += this->GetLocalGenerator()->ConvertToOutputFormat( obj_list_file, cmOutputConverter::SHELL); @@ -1039,8 +1014,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() symlinkVars["POST_BUILD"] = postBuildCmdLine; } - std::string cmakeVarLang = "CMAKE_"; - cmakeVarLang += this->TargetLinkLanguage; + std::string cmakeVarLang = cmStrCat("CMAKE_", this->TargetLinkLanguage); // build response file name std::string cmakeLinkVar = cmakeVarLang + "_RESPONSE_FILE_LINK_FLAG"; |