Browse Source

Merge topic 'genex-cleanup'

50840902ce cmGeneratorExpressionDAGChecker: Simplify finding evaluation graph root
304f4c261e cmGeneratorExpressionDAGChecker: Simplify member initialization
c620d8d9cf cmGeneratorExpressionDAGChecker: Clarify COMPILE_DEFINITIONS special case
a585e410c0 cmGeneratorExpressionDAGChecker: Inline initialization in constructor
40788cb1e6 cmGeneratorExpressionDAGChecker: Reduce duplication in constructor

Acked-by: Kitware Robot <[email protected]>
Acked-by: buildbot <[email protected]>
Merge-request: !9413
Brad King 1 năm trước cách đây
mục cha
commit
1a315c55e3

+ 23 - 46
Source/cmGeneratorExpressionDAGChecker.cxx

@@ -18,38 +18,26 @@
 #include "cmake.h"
 
 cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker(
-  cmListFileBacktrace backtrace, cmGeneratorTarget const* target,
-  std::string property, const GeneratorExpressionContent* content,
+  cmGeneratorTarget const* target, std::string property,
+  const GeneratorExpressionContent* content,
   cmGeneratorExpressionDAGChecker* parent)
-  : Parent(parent)
-  , Target(target)
-  , Property(std::move(property))
-  , Content(content)
-  , Backtrace(std::move(backtrace))
-  , TransitivePropertiesOnly(false)
-  , CMP0131(false)
+  : cmGeneratorExpressionDAGChecker(cmListFileBacktrace(), target,
+                                    std::move(property), content, parent)
 {
-  this->Initialize();
 }
 
 cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker(
-  cmGeneratorTarget const* target, std::string property,
-  const GeneratorExpressionContent* content,
+  cmListFileBacktrace backtrace, cmGeneratorTarget const* target,
+  std::string property, const GeneratorExpressionContent* content,
   cmGeneratorExpressionDAGChecker* parent)
   : Parent(parent)
+  , Top(parent ? parent->Top : this)
   , Target(target)
   , Property(std::move(property))
   , Content(content)
-  , Backtrace()
-  , TransitivePropertiesOnly(false)
-  , CMP0131(false)
-{
-  this->Initialize();
-}
-
-void cmGeneratorExpressionDAGChecker::Initialize()
+  , Backtrace(std::move(backtrace))
 {
-  const auto* top = this->Top();
+  const auto* top = this->Top;
   this->CheckResult = this->CheckGraph();
 
 #define TEST_TRANSITIVE_PROPERTY_METHOD(METHOD) top->METHOD() ||
@@ -142,13 +130,13 @@ cmGeneratorExpressionDAGChecker::CheckGraph() const
 
 bool cmGeneratorExpressionDAGChecker::GetTransitivePropertiesOnly() const
 {
-  return this->Top()->TransitivePropertiesOnly;
+  return this->Top->TransitivePropertiesOnly;
 }
 
 bool cmGeneratorExpressionDAGChecker::GetTransitivePropertiesOnlyCMP0131()
   const
 {
-  return this->Top()->CMP0131;
+  return this->Top->CMP0131;
 }
 
 bool cmGeneratorExpressionDAGChecker::EvaluatingGenexExpression() const
@@ -159,12 +147,12 @@ bool cmGeneratorExpressionDAGChecker::EvaluatingGenexExpression() const
 
 bool cmGeneratorExpressionDAGChecker::EvaluatingPICExpression() const
 {
-  return this->Top()->Property == "INTERFACE_POSITION_INDEPENDENT_CODE";
+  return this->Top->Property == "INTERFACE_POSITION_INDEPENDENT_CODE";
 }
 
 bool cmGeneratorExpressionDAGChecker::EvaluatingCompileExpression() const
 {
-  cm::string_view property(this->Top()->Property);
+  cm::string_view property(this->Top->Property);
 
   return property == "INCLUDE_DIRECTORIES"_s ||
     property == "COMPILE_DEFINITIONS"_s || property == "COMPILE_OPTIONS"_s;
@@ -172,7 +160,7 @@ bool cmGeneratorExpressionDAGChecker::EvaluatingCompileExpression() const
 
 bool cmGeneratorExpressionDAGChecker::EvaluatingLinkExpression() const
 {
-  cm::string_view property(this->Top()->Property);
+  cm::string_view property(this->Top->Property);
 
   return property == "LINK_DIRECTORIES"_s || property == "LINK_OPTIONS"_s ||
     property == "LINK_DEPENDS"_s || property == "LINK_LIBRARY_OVERRIDE"_s ||
@@ -181,14 +169,14 @@ bool cmGeneratorExpressionDAGChecker::EvaluatingLinkExpression() const
 
 bool cmGeneratorExpressionDAGChecker::EvaluatingLinkOptionsExpression() const
 {
-  cm::string_view property(this->Top()->Property);
+  cm::string_view property(this->Top->Property);
 
   return property == "LINK_OPTIONS"_s || property == "LINKER_TYPE"_s;
 }
 
 bool cmGeneratorExpressionDAGChecker::EvaluatingLinkerLauncher() const
 {
-  cm::string_view property(this->Top()->Property);
+  cm::string_view property(this->Top->Property);
 
   return property.length() > cmStrLen("_LINKER_LAUNCHER") &&
     property.substr(property.length() - cmStrLen("_LINKER_LAUNCHER")) ==
@@ -198,7 +186,7 @@ bool cmGeneratorExpressionDAGChecker::EvaluatingLinkerLauncher() const
 bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries(
   cmGeneratorTarget const* tgt, ForGenex genex) const
 {
-  const auto* top = this->Top();
+  const auto* top = this->Top;
 
   cm::string_view prop(top->Property);
 
@@ -219,29 +207,17 @@ bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries(
     : (result || prop == "INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE"_s);
 }
 
-cmGeneratorExpressionDAGChecker const* cmGeneratorExpressionDAGChecker::Top()
-  const
-{
-  const cmGeneratorExpressionDAGChecker* top = this;
-  const cmGeneratorExpressionDAGChecker* parent = this->Parent;
-  while (parent) {
-    top = parent;
-    parent = parent->Parent;
-  }
-  return top;
-}
-
 cmGeneratorTarget const* cmGeneratorExpressionDAGChecker::TopTarget() const
 {
-  return this->Top()->Target;
+  return this->Top->Target;
 }
 
-enum TransitiveProperty
+enum class TransitiveProperty
 {
 #define DEFINE_ENUM_ENTRY(NAME) NAME,
   CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(DEFINE_ENUM_ENTRY)
 #undef DEFINE_ENUM_ENTRY
-    TransitivePropertyTerminal
+    Terminal
 };
 
 template <TransitiveProperty>
@@ -251,7 +227,8 @@ bool additionalTest(const char* const /*unused*/)
 }
 
 template <>
-bool additionalTest<COMPILE_DEFINITIONS>(const char* const prop)
+bool additionalTest<TransitiveProperty::COMPILE_DEFINITIONS>(
+  const char* const prop)
 {
   return cmHasLiteralPrefix(prop, "COMPILE_DEFINITIONS_");
 }
@@ -264,7 +241,7 @@ bool additionalTest<COMPILE_DEFINITIONS>(const char* const prop)
         strcmp(prop, "INTERFACE_" #PROPERTY) == 0) {                          \
       return true;                                                            \
     }                                                                         \
-    return additionalTest<PROPERTY>(prop);                                    \
+    return additionalTest<TransitiveProperty::PROPERTY>(prop);                \
   }
 
 CM_FOR_EACH_TRANSITIVE_PROPERTY(DEFINE_TRANSITIVE_PROPERTY_METHOD)

+ 3 - 4
Source/cmGeneratorExpressionDAGChecker.h

@@ -94,20 +94,19 @@ struct cmGeneratorExpressionDAGChecker
   bool GetTransitivePropertiesOnlyCMP0131() const;
   void SetTransitivePropertiesOnlyCMP0131() { this->CMP0131 = true; }
 
-  cmGeneratorExpressionDAGChecker const* Top() const;
   cmGeneratorTarget const* TopTarget() const;
 
 private:
   Result CheckGraph() const;
-  void Initialize();
 
   const cmGeneratorExpressionDAGChecker* const Parent;
+  const cmGeneratorExpressionDAGChecker* const Top;
   cmGeneratorTarget const* Target;
   const std::string Property;
   mutable std::map<cmGeneratorTarget const*, std::set<std::string>> Seen;
   const GeneratorExpressionContent* const Content;
   const cmListFileBacktrace Backtrace;
   Result CheckResult;
-  bool TransitivePropertiesOnly;
-  bool CMP0131;
+  bool TransitivePropertiesOnly = false;
+  bool CMP0131 = false;
 };