Browse Source

genex: Simplify cmGeneratorExpressionInterpreter

All callers were constructing with a non-empty target name using the
target whose pointer was passed anyway.  Drop this argument.  Simplify
logic accordingly.  Re-order constructor arguments to match the
cmCompiledGeneratorExpression::Evaluate arguments.

Also remove unnecessary getters.
Brad King 7 years ago
parent
commit
1b57f49586

+ 6 - 6
Source/cmExtraSublimeTextGenerator.cxx

@@ -354,8 +354,8 @@ std::string cmExtraSublimeTextGenerator::ComputeFlagsForObject(
   lg->GetTargetCompileFlags(gtgt, config, language, flags);
   lg->GetTargetCompileFlags(gtgt, config, language, flags);
 
 
   // Add source file specific flags.
   // Add source file specific flags.
-  cmGeneratorExpressionInterpreter genexInterpreter(lg, gtgt, config,
-                                                    gtgt->GetName(), language);
+  cmGeneratorExpressionInterpreter genexInterpreter(lg, config, gtgt,
+                                                    language);
 
 
   const std::string COMPILE_FLAGS("COMPILE_FLAGS");
   const std::string COMPILE_FLAGS("COMPILE_FLAGS");
   if (const char* cflags = source->GetProperty(COMPILE_FLAGS)) {
   if (const char* cflags = source->GetProperty(COMPILE_FLAGS)) {
@@ -381,8 +381,8 @@ std::string cmExtraSublimeTextGenerator::ComputeDefines(
   cmMakefile* makefile = lg->GetMakefile();
   cmMakefile* makefile = lg->GetMakefile();
   const std::string& language = source->GetLanguage();
   const std::string& language = source->GetLanguage();
   const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
   const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
-  cmGeneratorExpressionInterpreter genexInterpreter(
-    lg, target, config, target->GetName(), language);
+  cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target,
+                                                    language);
 
 
   // Add the export symbol definition for shared library objects.
   // Add the export symbol definition for shared library objects.
   if (const char* exportMacro = target->GetExportMacro()) {
   if (const char* exportMacro = target->GetExportMacro()) {
@@ -419,8 +419,8 @@ std::string cmExtraSublimeTextGenerator::ComputeIncludes(
   cmMakefile* makefile = lg->GetMakefile();
   cmMakefile* makefile = lg->GetMakefile();
   const std::string& language = source->GetLanguage();
   const std::string& language = source->GetLanguage();
   const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
   const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
-  cmGeneratorExpressionInterpreter genexInterpreter(
-    lg, target, config, target->GetName(), language);
+  cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target,
+                                                    language);
 
 
   // Add include directories for this source file
   // Add include directories for this source file
   const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES");
   const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES");

+ 9 - 6
Source/cmGeneratorExpression.cxx

@@ -13,6 +13,7 @@
 #include "cmGeneratorExpressionEvaluator.h"
 #include "cmGeneratorExpressionEvaluator.h"
 #include "cmGeneratorExpressionLexer.h"
 #include "cmGeneratorExpressionLexer.h"
 #include "cmGeneratorExpressionParser.h"
 #include "cmGeneratorExpressionParser.h"
+#include "cmGeneratorTarget.h"
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
 
 
 cmGeneratorExpression::cmGeneratorExpression(
 cmGeneratorExpression::cmGeneratorExpression(
@@ -389,14 +390,16 @@ void cmCompiledGeneratorExpression::GetMaxLanguageStandard(
 const std::string& cmGeneratorExpressionInterpreter::Evaluate(
 const std::string& cmGeneratorExpressionInterpreter::Evaluate(
   const char* expression, const std::string& property)
   const char* expression, const std::string& property)
 {
 {
-  if (this->Target.empty()) {
-    return this->EvaluateExpression(expression);
-  }
+  this->CompiledGeneratorExpression =
+    this->GeneratorExpression.Parse(expression);
 
 
   // Specify COMPILE_OPTIONS to DAGchecker, same semantic as COMPILE_FLAGS
   // Specify COMPILE_OPTIONS to DAGchecker, same semantic as COMPILE_FLAGS
   cmGeneratorExpressionDAGChecker dagChecker(
   cmGeneratorExpressionDAGChecker dagChecker(
-    this->Target, property == "COMPILE_FLAGS" ? "COMPILE_OPTIONS" : property,
-    nullptr, nullptr);
+    this->HeadTarget->GetName(),
+    property == "COMPILE_FLAGS" ? "COMPILE_OPTIONS" : property, nullptr,
+    nullptr);
 
 
-  return this->EvaluateExpression(expression, &dagChecker);
+  return this->CompiledGeneratorExpression->Evaluate(
+    this->LocalGenerator, this->Config, false, this->HeadTarget, &dagChecker,
+    this->Language);
 }
 }

+ 5 - 50
Source/cmGeneratorExpression.h

@@ -160,24 +160,15 @@ class cmGeneratorExpressionInterpreter
 
 
 public:
 public:
   cmGeneratorExpressionInterpreter(cmLocalGenerator* localGenerator,
   cmGeneratorExpressionInterpreter(cmLocalGenerator* localGenerator,
-                                   cmGeneratorTarget* generatorTarget,
-                                   const std::string& config,
-                                   const std::string& target,
-                                   const std::string& lang)
+                                   std::string const& config,
+                                   cmGeneratorTarget const* headTarget,
+                                   std::string const& lang = std::string())
     : LocalGenerator(localGenerator)
     : LocalGenerator(localGenerator)
-    , GeneratorTarget(generatorTarget)
     , Config(config)
     , Config(config)
-    , Target(target)
+    , HeadTarget(headTarget)
     , Language(lang)
     , Language(lang)
   {
   {
   }
   }
-  cmGeneratorExpressionInterpreter(cmLocalGenerator* localGenerator,
-                                   cmGeneratorTarget* generatorTarget,
-                                   const std::string& config)
-    : cmGeneratorExpressionInterpreter(localGenerator, generatorTarget, config,
-                                       std::string(), std::string())
-  {
-  }
 
 
   const std::string& Evaluate(const char* expression,
   const std::string& Evaluate(const char* expression,
                               const std::string& property);
                               const std::string& property);
@@ -188,47 +179,11 @@ public:
   }
   }
 
 
 protected:
 protected:
-  cmGeneratorExpression& GetGeneratorExpression()
-  {
-    return this->GeneratorExpression;
-  }
-
-  cmCompiledGeneratorExpression& GetCompiledGeneratorExpression()
-  {
-    return *(this->CompiledGeneratorExpression);
-  }
-
-  cmLocalGenerator* GetLocalGenerator() { return this->LocalGenerator; }
-
-  cmGeneratorTarget* GetGeneratorTarget() { return this->GeneratorTarget; }
-
-  const std::string& GetTargetName() const { return this->Target; }
-  const std::string& GetLanguage() const { return this->Language; }
-
-  const std::string& EvaluateExpression(
-    const char* expression,
-    cmGeneratorExpressionDAGChecker* dagChecker = nullptr)
-  {
-    this->CompiledGeneratorExpression =
-      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,
-      dagChecker, this->Language);
-  }
-
-private:
   cmGeneratorExpression GeneratorExpression;
   cmGeneratorExpression GeneratorExpression;
   std::unique_ptr<cmCompiledGeneratorExpression> CompiledGeneratorExpression;
   std::unique_ptr<cmCompiledGeneratorExpression> CompiledGeneratorExpression;
   cmLocalGenerator* LocalGenerator = nullptr;
   cmLocalGenerator* LocalGenerator = nullptr;
-  cmGeneratorTarget* GeneratorTarget = nullptr;
   std::string Config;
   std::string Config;
-  std::string Target;
+  cmGeneratorTarget const* HeadTarget = nullptr;
   std::string Language;
   std::string Language;
 };
 };
 
 

+ 5 - 7
Source/cmGlobalXCodeGenerator.cxx

@@ -751,11 +751,10 @@ class XCodeGeneratorExpressionInterpreter
 public:
 public:
   XCodeGeneratorExpressionInterpreter(cmSourceFile* sourceFile,
   XCodeGeneratorExpressionInterpreter(cmSourceFile* sourceFile,
                                       cmLocalGenerator* localGenerator,
                                       cmLocalGenerator* localGenerator,
-                                      cmGeneratorTarget* generatorTarget,
+                                      cmGeneratorTarget* headTarget,
                                       const std::string& lang)
                                       const std::string& lang)
-    : cmGeneratorExpressionInterpreter(localGenerator, generatorTarget,
-                                       "NO-PER-CONFIG-SUPPORT-IN-XCODE",
-                                       generatorTarget->GetName(), lang)
+    : cmGeneratorExpressionInterpreter(
+        localGenerator, "NO-PER-CONFIG-SUPPORT-IN-XCODE", headTarget, lang)
     , SourceFile(sourceFile)
     , SourceFile(sourceFile)
   {
   {
   }
   }
@@ -767,8 +766,7 @@ public:
   {
   {
     const std::string& processed =
     const std::string& processed =
       this->cmGeneratorExpressionInterpreter::Evaluate(expression, property);
       this->cmGeneratorExpressionInterpreter::Evaluate(expression, property);
-    if (this->GetCompiledGeneratorExpression()
-          .GetHadContextSensitiveCondition()) {
+    if (this->CompiledGeneratorExpression->GetHadContextSensitiveCondition()) {
       std::ostringstream e;
       std::ostringstream e;
       /* clang-format off */
       /* clang-format off */
       e <<
       e <<
@@ -777,7 +775,7 @@ public:
           "specified for source:\n"
           "specified for source:\n"
           "  " << this->SourceFile->GetFullPath() << "\n";
           "  " << this->SourceFile->GetFullPath() << "\n";
       /* clang-format on */
       /* clang-format on */
-      this->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str());
+      this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
     }
     }
 
 
     return processed;
     return processed;

+ 1 - 2
Source/cmLocalVisualStudio7Generator.cxx

@@ -1497,8 +1497,7 @@ cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo(
       lang = sourceLang;
       lang = sourceLang;
     }
     }
 
 
-    cmGeneratorExpressionInterpreter genexInterpreter(lg, gt, *i,
-                                                      gt->GetName(), lang);
+    cmGeneratorExpressionInterpreter genexInterpreter(lg, *i, gt, lang);
 
 
     bool needfc = false;
     bool needfc = false;
     if (!objectName.empty()) {
     if (!objectName.empty()) {

+ 1 - 2
Source/cmMakefileTargetGenerator.cxx

@@ -434,8 +434,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
   std::string config = this->LocalGenerator->GetConfigName();
   std::string config = this->LocalGenerator->GetConfigName();
   std::string configUpper = cmSystemTools::UpperCase(config);
   std::string configUpper = cmSystemTools::UpperCase(config);
   cmGeneratorExpressionInterpreter genexInterpreter(
   cmGeneratorExpressionInterpreter genexInterpreter(
-    this->LocalGenerator, this->GeneratorTarget, config,
-    this->GeneratorTarget->GetName(), lang);
+    this->LocalGenerator, config, this->GeneratorTarget, lang);
 
 
   // Add Fortran format flags.
   // Add Fortran format flags.
   if (lang == "Fortran") {
   if (lang == "Fortran") {

+ 4 - 7
Source/cmNinjaTargetGenerator.cxx

@@ -136,9 +136,8 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject(
 
 
   // Add source file specific flags.
   // Add source file specific flags.
   cmGeneratorExpressionInterpreter genexInterpreter(
   cmGeneratorExpressionInterpreter genexInterpreter(
-    this->LocalGenerator, this->GeneratorTarget,
-    this->LocalGenerator->GetConfigName(), this->GeneratorTarget->GetName(),
-    language);
+    this->LocalGenerator, this->LocalGenerator->GetConfigName(),
+    this->GeneratorTarget, language);
 
 
   const std::string COMPILE_FLAGS("COMPILE_FLAGS");
   const std::string COMPILE_FLAGS("COMPILE_FLAGS");
   if (const char* cflags = source->GetProperty(COMPILE_FLAGS)) {
   if (const char* cflags = source->GetProperty(COMPILE_FLAGS)) {
@@ -188,8 +187,7 @@ std::string cmNinjaTargetGenerator::ComputeDefines(cmSourceFile const* source,
   std::set<std::string> defines;
   std::set<std::string> defines;
   const std::string config = this->LocalGenerator->GetConfigName();
   const std::string config = this->LocalGenerator->GetConfigName();
   cmGeneratorExpressionInterpreter genexInterpreter(
   cmGeneratorExpressionInterpreter genexInterpreter(
-    this->LocalGenerator, this->GeneratorTarget, config,
-    this->GeneratorTarget->GetName(), language);
+    this->LocalGenerator, config, this->GeneratorTarget, language);
 
 
   const std::string COMPILE_DEFINITIONS("COMPILE_DEFINITIONS");
   const std::string COMPILE_DEFINITIONS("COMPILE_DEFINITIONS");
   if (const char* compile_defs = source->GetProperty(COMPILE_DEFINITIONS)) {
   if (const char* compile_defs = source->GetProperty(COMPILE_DEFINITIONS)) {
@@ -217,8 +215,7 @@ std::string cmNinjaTargetGenerator::ComputeIncludes(
   std::vector<std::string> includes;
   std::vector<std::string> includes;
   const std::string config = this->LocalGenerator->GetConfigName();
   const std::string config = this->LocalGenerator->GetConfigName();
   cmGeneratorExpressionInterpreter genexInterpreter(
   cmGeneratorExpressionInterpreter genexInterpreter(
-    this->LocalGenerator, this->GeneratorTarget, config,
-    this->GeneratorTarget->GetName(), language);
+    this->LocalGenerator, config, this->GeneratorTarget, language);
 
 
   const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES");
   const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES");
   if (const char* cincludes = source->GetProperty(INCLUDE_DIRECTORIES)) {
   if (const char* cincludes = source->GetProperty(INCLUDE_DIRECTORIES)) {

+ 4 - 5
Source/cmServerProtocol.cxx

@@ -722,8 +722,8 @@ static void PopulateFileGroupData(
         ? languageDataMap.at(kInterfaceSourcesLanguageDataKey)
         ? languageDataMap.at(kInterfaceSourcesLanguageDataKey)
         : languageDataMap.at(fileData.Language);
         : languageDataMap.at(fileData.Language);
       cmLocalGenerator* lg = target->GetLocalGenerator();
       cmLocalGenerator* lg = target->GetLocalGenerator();
-      cmGeneratorExpressionInterpreter genexInterpreter(
-        lg, target, config, target->GetName(), fileData.Language);
+      cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target,
+                                                        fileData.Language);
 
 
       std::string compileFlags = ld.Flags;
       std::string compileFlags = ld.Flags;
       const std::string COMPILE_FLAGS("COMPILE_FLAGS");
       const std::string COMPILE_FLAGS("COMPILE_FLAGS");
@@ -817,7 +817,7 @@ static Json::Value DumpSourceFilesList(
   auto targetProp = target->Target->GetProperty("INTERFACE_SOURCES");
   auto targetProp = target->Target->GetProperty("INTERFACE_SOURCES");
   if (targetProp != nullptr) {
   if (targetProp != nullptr) {
     cmGeneratorExpressionInterpreter genexInterpreter(
     cmGeneratorExpressionInterpreter genexInterpreter(
-      target->GetLocalGenerator(), target, config, target->GetName(), "");
+      target->GetLocalGenerator(), config, target);
 
 
     auto evaluatedSources = cmsys::SystemTools::SplitString(
     auto evaluatedSources = cmsys::SystemTools::SplitString(
       genexInterpreter.Evaluate(targetProp, "INTERFACE_SOURCES"), ';');
       genexInterpreter.Evaluate(targetProp, "INTERFACE_SOURCES"), ';');
@@ -977,8 +977,7 @@ static void CreateInterfaceSourcesEntry(
   LanguageData& ld = languageDataMap[kInterfaceSourcesLanguageDataKey];
   LanguageData& ld = languageDataMap[kInterfaceSourcesLanguageDataKey];
   ld.Language = "";
   ld.Language = "";
 
 
-  cmGeneratorExpressionInterpreter genexInterpreter(lg, target, config,
-                                                    target->GetName(), "");
+  cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target);
   std::vector<std::string> propertyValue;
   std::vector<std::string> propertyValue;
   GetTargetProperty(genexInterpreter, target, "INTERFACE_INCLUDE_DIRECTORIES",
   GetTargetProperty(genexInterpreter, target, "INTERFACE_INCLUDE_DIRECTORIES",
                     propertyValue);
                     propertyValue);

+ 1 - 2
Source/cmVisualStudio10TargetGenerator.cxx

@@ -2117,8 +2117,7 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
         flagtable = gg->GetCSharpFlagTable();
         flagtable = gg->GetCSharpFlagTable();
       }
       }
       cmGeneratorExpressionInterpreter genexInterpreter(
       cmGeneratorExpressionInterpreter genexInterpreter(
-        this->LocalGenerator, this->GeneratorTarget, config,
-        this->GeneratorTarget->GetName(), lang);
+        this->LocalGenerator, config, this->GeneratorTarget, lang);
       cmVS10GeneratorOptions clOptions(
       cmVS10GeneratorOptions clOptions(
         this->LocalGenerator, cmVisualStudioGeneratorOptions::Compiler,
         this->LocalGenerator, cmVisualStudioGeneratorOptions::Compiler,
         flagtable, this);
         flagtable, this);