Răsfoiți Sursa

cmGeneratorExpressionDAGChecker: introduce method Top()

Marc Chevrier 5 ani în urmă
părinte
comite
38332fc4fa

+ 18 - 43
Source/cmGeneratorExpressionDAGChecker.cxx

@@ -48,12 +48,7 @@ cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker(
 
 void cmGeneratorExpressionDAGChecker::Initialize()
 {
-  const cmGeneratorExpressionDAGChecker* top = this;
-  const cmGeneratorExpressionDAGChecker* p = this->Parent;
-  while (p) {
-    top = p;
-    p = p->Parent;
-  }
+  const auto* top = this->Top();
   this->CheckResult = this->CheckGraph();
 
 #define TEST_TRANSITIVE_PROPERTY_METHOD(METHOD) top->METHOD() ||
@@ -144,60 +139,34 @@ cmGeneratorExpressionDAGChecker::CheckGraph() const
   return DAG;
 }
 
-bool cmGeneratorExpressionDAGChecker::GetTransitivePropertiesOnly()
+bool cmGeneratorExpressionDAGChecker::GetTransitivePropertiesOnly() const
 {
-  const cmGeneratorExpressionDAGChecker* top = this;
-  const cmGeneratorExpressionDAGChecker* parent = this->Parent;
-  while (parent) {
-    top = parent;
-    parent = parent->Parent;
-  }
-
-  return top->TransitivePropertiesOnly;
+  return this->Top()->TransitivePropertiesOnly;
 }
 
-bool cmGeneratorExpressionDAGChecker::EvaluatingGenexExpression()
+bool cmGeneratorExpressionDAGChecker::EvaluatingGenexExpression() const
 {
   return cmHasLiteralPrefix(this->Property, "TARGET_GENEX_EVAL:") ||
     cmHasLiteralPrefix(this->Property, "GENEX_EVAL:");
 }
 
-bool cmGeneratorExpressionDAGChecker::EvaluatingPICExpression()
+bool cmGeneratorExpressionDAGChecker::EvaluatingPICExpression() const
 {
-  const cmGeneratorExpressionDAGChecker* top = this;
-  const cmGeneratorExpressionDAGChecker* parent = this->Parent;
-  while (parent) {
-    top = parent;
-    parent = parent->Parent;
-  }
-
-  return top->Property == "INTERFACE_POSITION_INDEPENDENT_CODE";
+  return this->Top()->Property == "INTERFACE_POSITION_INDEPENDENT_CODE";
 }
 
-bool cmGeneratorExpressionDAGChecker::EvaluatingLinkExpression()
+bool cmGeneratorExpressionDAGChecker::EvaluatingLinkExpression() const
 {
-  const cmGeneratorExpressionDAGChecker* top = this;
-  const cmGeneratorExpressionDAGChecker* parent = this->Parent;
-  while (parent) {
-    top = parent;
-    parent = parent->Parent;
-  }
-
-  cm::string_view property(top->Property);
+  cm::string_view property(this->Top()->Property);
 
   return property == "LINK_DIRECTORIES"_s || property == "LINK_OPTIONS"_s ||
     property == "LINK_DEPENDS"_s;
 }
 
 bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries(
-  cmGeneratorTarget const* tgt)
+  cmGeneratorTarget const* tgt) const
 {
-  const cmGeneratorExpressionDAGChecker* top = this;
-  const cmGeneratorExpressionDAGChecker* parent = this->Parent;
-  while (parent) {
-    top = parent;
-    parent = parent->Parent;
-  }
+  const auto* top = this->Top();
 
   cm::string_view prop(top->Property);
 
@@ -212,7 +181,8 @@ bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries(
     prop == "INTERFACE_LINK_LIBRARIES"_s;
 }
 
-cmGeneratorTarget const* cmGeneratorExpressionDAGChecker::TopTarget() const
+cmGeneratorExpressionDAGChecker const* cmGeneratorExpressionDAGChecker::Top()
+  const
 {
   const cmGeneratorExpressionDAGChecker* top = this;
   const cmGeneratorExpressionDAGChecker* parent = this->Parent;
@@ -220,7 +190,12 @@ cmGeneratorTarget const* cmGeneratorExpressionDAGChecker::TopTarget() const
     top = parent;
     parent = parent->Parent;
   }
-  return top->Target;
+  return top;
+}
+
+cmGeneratorTarget const* cmGeneratorExpressionDAGChecker::TopTarget() const
+{
+  return this->Top()->Target;
 }
 
 enum TransitiveProperty

+ 7 - 5
Source/cmGeneratorExpressionDAGChecker.h

@@ -66,10 +66,11 @@ struct cmGeneratorExpressionDAGChecker
   void ReportError(cmGeneratorExpressionContext* context,
                    const std::string& expr);
 
-  bool EvaluatingGenexExpression();
-  bool EvaluatingPICExpression();
-  bool EvaluatingLinkExpression();
-  bool EvaluatingLinkLibraries(cmGeneratorTarget const* tgt = nullptr);
+  bool EvaluatingGenexExpression() const;
+  bool EvaluatingPICExpression() const;
+  bool EvaluatingLinkExpression() const;
+
+  bool EvaluatingLinkLibraries(cmGeneratorTarget const* tgt = nullptr) const;
 
 #define DECLARE_TRANSITIVE_PROPERTY_METHOD(METHOD) bool METHOD() const;
 
@@ -77,9 +78,10 @@ struct cmGeneratorExpressionDAGChecker
 
 #undef DECLARE_TRANSITIVE_PROPERTY_METHOD
 
-  bool GetTransitivePropertiesOnly();
+  bool GetTransitivePropertiesOnly() const;
   void SetTransitivePropertiesOnly() { this->TransitivePropertiesOnly = true; }
 
+  cmGeneratorExpressionDAGChecker const* Top() const;
   cmGeneratorTarget const* TopTarget() const;
 
 private: