Browse Source

cmCompiledGeneratorExpression::Evaluate(): return const std::string&

Vitaly Stakhovsky 7 years ago
parent
commit
c530e2f74f

+ 5 - 6
Source/cmGeneratorExpression.cxx

@@ -38,7 +38,7 @@ cmGeneratorExpression::~cmGeneratorExpression()
 {
 }
 
-const char* cmCompiledGeneratorExpression::Evaluate(
+const std::string& cmCompiledGeneratorExpression::Evaluate(
   cmLocalGenerator* lg, const std::string& config, bool quiet,
   const cmGeneratorTarget* headTarget,
   cmGeneratorExpressionDAGChecker* dagChecker,
@@ -48,7 +48,7 @@ const char* cmCompiledGeneratorExpression::Evaluate(
                         language);
 }
 
-const char* cmCompiledGeneratorExpression::Evaluate(
+const std::string& cmCompiledGeneratorExpression::Evaluate(
   cmLocalGenerator* lg, const std::string& config, bool quiet,
   const cmGeneratorTarget* headTarget, const cmGeneratorTarget* currentTarget,
   cmGeneratorExpressionDAGChecker* dagChecker,
@@ -61,12 +61,12 @@ const char* cmCompiledGeneratorExpression::Evaluate(
   return this->EvaluateWithContext(context, dagChecker);
 }
 
-const char* cmCompiledGeneratorExpression::EvaluateWithContext(
+const std::string& cmCompiledGeneratorExpression::EvaluateWithContext(
   cmGeneratorExpressionContext& context,
   cmGeneratorExpressionDAGChecker* dagChecker) const
 {
   if (!this->NeedsEvaluation) {
-    return this->Input.c_str();
+    return this->Input;
   }
 
   this->Output.clear();
@@ -97,8 +97,7 @@ const char* cmCompiledGeneratorExpression::EvaluateWithContext(
 
   this->DependTargets = context.DependTargets;
   this->AllTargetsSeen = context.AllTargets;
-  // TODO: Return a std::string from here instead?
-  return this->Output.c_str();
+  return this->Output;
 }
 
 cmCompiledGeneratorExpression::cmCompiledGeneratorExpression(

+ 20 - 16
Source/cmGeneratorExpression.h

@@ -72,16 +72,17 @@ class cmCompiledGeneratorExpression
   CM_DISABLE_COPY(cmCompiledGeneratorExpression)
 
 public:
-  const char* Evaluate(cmLocalGenerator* lg, const std::string& config,
-                       bool quiet = false,
-                       cmGeneratorTarget const* headTarget = nullptr,
-                       cmGeneratorTarget const* currentTarget = nullptr,
-                       cmGeneratorExpressionDAGChecker* dagChecker = nullptr,
-                       std::string const& language = std::string()) const;
-  const char* Evaluate(cmLocalGenerator* lg, const std::string& config,
-                       bool quiet, cmGeneratorTarget const* headTarget,
-                       cmGeneratorExpressionDAGChecker* dagChecker,
-                       std::string const& language = std::string()) const;
+  const std::string& Evaluate(
+    cmLocalGenerator* lg, const std::string& config, bool quiet = false,
+    cmGeneratorTarget const* headTarget = nullptr,
+    cmGeneratorTarget const* currentTarget = nullptr,
+    cmGeneratorExpressionDAGChecker* dagChecker = nullptr,
+    std::string const& language = std::string()) const;
+  const std::string& Evaluate(
+    cmLocalGenerator* lg, const std::string& config, bool quiet,
+    cmGeneratorTarget const* headTarget,
+    cmGeneratorExpressionDAGChecker* dagChecker,
+    std::string const& language = std::string()) const;
 
   /** Get set of targets found during evaluations.  */
   std::set<cmGeneratorTarget*> const& GetTargets() const
@@ -126,7 +127,7 @@ public:
                               std::map<std::string, std::string>& mapping);
 
 private:
-  const char* EvaluateWithContext(
+  const std::string& EvaluateWithContext(
     cmGeneratorExpressionContext& context,
     cmGeneratorExpressionDAGChecker* dagChecker) const;
 
@@ -219,13 +220,16 @@ protected:
       this->GeneratorExpression.Parse(expression);
 
     if (dagChecker == nullptr) {
-      return this->CompiledGeneratorExpression->Evaluate(
-        this->LocalGenerator, this->Config, false, this->GeneratorTarget);
+      return this->CompiledGeneratorExpression
+        ->Evaluate(this->LocalGenerator, this->Config, false,
+                   this->GeneratorTarget)
+        .c_str();
     }
 
-    return this->CompiledGeneratorExpression->Evaluate(
-      this->LocalGenerator, this->Config, false, this->GeneratorTarget,
-      dagChecker, this->Language);
+    return this->CompiledGeneratorExpression
+      ->Evaluate(this->LocalGenerator, this->Config, false,
+                 this->GeneratorTarget, dagChecker, this->Language)
+      .c_str();
   }
 
 private:

+ 1 - 1
Source/cmGeneratorExpressionEvaluationFile.cxx

@@ -55,7 +55,7 @@ void cmGeneratorExpressionEvaluationFile::Generate(
 
   std::string outputFileName = this->OutputFileExpr->Evaluate(
     lg, config, false, nullptr, nullptr, nullptr, lang);
-  const std::string outputContent = inputExpression->Evaluate(
+  const std::string& outputContent = inputExpression->Evaluate(
     lg, config, false, nullptr, nullptr, nullptr, lang);
 
   if (cmSystemTools::FileIsFullPath(outputFileName)) {

+ 1 - 1
Source/cmGeneratorTarget.cxx

@@ -5519,7 +5519,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
       this->GetName(), "LINK_LIBRARIES", nullptr, nullptr);
     cmGeneratorExpression ge(*btIt);
     std::unique_ptr<cmCompiledGeneratorExpression> const cge = ge.Parse(*le);
-    std::string const evaluated =
+    std::string const& evaluated =
       cge->Evaluate(this->LocalGenerator, config, false, head, &dagChecker);
     cmSystemTools::ExpandListArgument(evaluated, llibs);
     if (cge->GetHadHeadSensitiveCondition()) {

+ 1 - 1
Source/cmGlobalVisualStudio7Generator.cxx

@@ -679,7 +679,7 @@ std::set<std::string> cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
           std::unique_ptr<cmCompiledGeneratorExpression> cge =
             ge.Parse(propertyValue);
           if (cmSystemTools::IsOn(
-                cge->Evaluate(target->GetLocalGenerator(), i))) {
+                cge->Evaluate(target->GetLocalGenerator(), i).c_str())) {
             activeConfigs.insert(i);
           }
         }

+ 3 - 4
Source/cmServerProtocol.cxx

@@ -797,9 +797,8 @@ static Json::Value DumpCTestInfo(cmLocalGenerator* lg, cmTest* testInfo,
 
   // Remove any config specific variables from the output.
   cmGeneratorExpression ge;
-  auto cge = ge.Parse(command.c_str());
-  const char* processed = cge->Evaluate(lg, config);
-
+  auto cge = ge.Parse(command);
+  const std::string& processed = cge->Evaluate(lg, config);
   result[kCTEST_COMMAND] = processed;
 
   // Build up the list of properties that may have been specified
@@ -810,7 +809,7 @@ static Json::Value DumpCTestInfo(cmLocalGenerator* lg, cmTest* testInfo,
 
     // Remove config variables from the value too.
     auto cge_value = ge.Parse(prop.second.GetValue());
-    const char* processed_value = cge_value->Evaluate(lg, config);
+    const std::string& processed_value = cge_value->Evaluate(lg, config);
     entry[kVALUE_KEY] = processed_value;
     properties.append(entry);
   }

+ 1 - 1
Source/cmTestGenerator.cxx

@@ -103,7 +103,7 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
     }
   } else {
     // Use the command name given.
-    exe = ge.Parse(exe.c_str())->Evaluate(this->LG, config);
+    exe = ge.Parse(exe)->Evaluate(this->LG, config);
     cmSystemTools::ConvertToUnixSlashes(exe);
   }
 

+ 9 - 10
Source/cmVisualStudio10TargetGenerator.cxx

@@ -1742,10 +1742,8 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1,
         e2.Element("Link", deployLocation + "\\%(FileName)%(Extension)");
       }
       for (size_t i = 0; i != this->Configurations.size(); ++i) {
-        if (0 ==
-            strcmp(
-              cge->Evaluate(this->LocalGenerator, this->Configurations[i]),
-              "1")) {
+        if (cge->Evaluate(this->LocalGenerator, this->Configurations[i]) ==
+            "1") {
           e2.WritePlatformConfigTag("DeploymentContent",
                                     "'$(Configuration)|$(Platform)'=='" +
                                       this->Configurations[i] + "|" +
@@ -1793,14 +1791,14 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1,
         ge.Parse(shaderEnableDebug);
 
       for (size_t i = 0; i != this->Configurations.size(); ++i) {
-        const char* enableDebug =
+        const std::string& enableDebug =
           cge->Evaluate(this->LocalGenerator, this->Configurations[i]);
-        if (strlen(enableDebug) > 0) {
+        if (!enableDebug.empty()) {
           e2.WritePlatformConfigTag(
             "EnableDebuggingInformation",
             "'$(Configuration)|$(Platform)'=='" + this->Configurations[i] +
               "|" + this->Platform + "'",
-            cmSystemTools::IsOn(enableDebug) ? "true" : "false");
+            cmSystemTools::IsOn(enableDebug.c_str()) ? "true" : "false");
         }
       }
     }
@@ -1810,14 +1808,15 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1,
         ge.Parse(shaderDisableOptimizations);
 
       for (size_t i = 0; i != this->Configurations.size(); ++i) {
-        const char* disableOptimizations =
+        const std::string& disableOptimizations =
           cge->Evaluate(this->LocalGenerator, this->Configurations[i]);
-        if (strlen(disableOptimizations) > 0) {
+        if (!disableOptimizations.empty()) {
           e2.WritePlatformConfigTag(
             "DisableOptimizations",
             "'$(Configuration)|$(Platform)'=='" + this->Configurations[i] +
               "|" + this->Platform + "'",
-            (cmSystemTools::IsOn(disableOptimizations) ? "true" : "false"));
+            (cmSystemTools::IsOn(disableOptimizations.c_str()) ? "true"
+                                                               : "false"));
         }
       }
     }