From 73d7705416a29ab75789cfe5d37ab5720b00d98d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 22 Oct 2013 01:02:49 +0200 Subject: [PATCH 1/3] Add some templates for cleaner array iteration. --- Source/cmStandardIncludes.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Source/cmStandardIncludes.h b/Source/cmStandardIncludes.h index d09b3047d..6c7714481 100644 --- a/Source/cmStandardIncludes.h +++ b/Source/cmStandardIncludes.h @@ -377,6 +377,34 @@ static thisClass* SafeDownCast(cmObject *c) \ return 0;\ } +#if defined(_MSC_VER) && _MSC_VER < 1300 +#define cmArrayBegin(a) a +#define cmArraySize(a) (sizeof(a)/sizeof(*a)) +#define cmArrayEnd(a) a + cmArraySize(a) + +#else + +template +const T* cmArrayBegin(const T (&a)[N]) { return a; } +template +const T* cmArrayEnd(const T (&a)[N]) { return a + N; } +template +size_t cmArraySize(const T (&)[N]) { return N; } + +#endif + +struct cmStrCmp { + cmStrCmp(const char *test) : m_test(test) {} + cmStrCmp(std::string &test) : m_test(test.c_str()) {} + + bool operator()(const char * input) + { + return strcmp(input, m_test) == 0; + } + +private: + const char *m_test; +}; #endif From 86d5d808c812357e13085f39439453d225a5b9e2 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 22 Oct 2013 01:12:24 +0200 Subject: [PATCH 2/3] Genex: Remove use of TransitiveWhitelistCompare Replace with generic solution based on cmArray* for better readability. --- Source/cmGeneratorExpressionEvaluator.cxx | 30 +++++++---------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index 7fd0fdcef..bc873e020 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -703,17 +703,6 @@ std::string getLinkedTargetsContent(const std::vector &libraries, return linkedTargetsContent; } -//---------------------------------------------------------------------------- -struct TransitiveWhitelistCompare -{ - explicit TransitiveWhitelistCompare(const std::string &needle) - : Needle(needle) {} - bool operator() (const char *item) - { return strcmp(item, this->Needle.c_str()) == 0; } -private: - std::string Needle; -}; - //---------------------------------------------------------------------------- static const struct TargetPropertyNode : public cmGeneratorExpressionNode { @@ -864,8 +853,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode return std::string(); case cmGeneratorExpressionDAGChecker::ALREADY_SEEN: for (size_t i = 1; - i < (sizeof(targetPropertyTransitiveWhitelist) / - sizeof(*targetPropertyTransitiveWhitelist)); + i < cmArraySize(targetPropertyTransitiveWhitelist); ++i) { if (targetPropertyTransitiveWhitelist[i] == propertyName) @@ -928,12 +916,13 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode cmTarget *headTarget = context->HeadTarget ? context->HeadTarget : target; - const char **transBegin = targetPropertyTransitiveWhitelist + 1; - const char **transEnd = targetPropertyTransitiveWhitelist - + (sizeof(targetPropertyTransitiveWhitelist) / - sizeof(*targetPropertyTransitiveWhitelist)); + const char * const *transBegin = + cmArrayBegin(targetPropertyTransitiveWhitelist) + 1; + const char * const *transEnd = + cmArrayEnd(targetPropertyTransitiveWhitelist); + if (std::find_if(transBegin, transEnd, - TransitiveWhitelistCompare(propertyName)) != transEnd) + cmStrCmp(propertyName)) != transEnd) { std::vector libs; @@ -949,7 +938,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode } } else if (std::find_if(transBegin, transEnd, - TransitiveWhitelistCompare(interfacePropertyName)) != transEnd) + cmStrCmp(interfacePropertyName)) != transEnd) { const cmTarget::LinkImplementation *impl = target->GetLinkImplementation( context->Config, @@ -996,8 +985,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode } for (size_t i = 1; - i < (sizeof(targetPropertyTransitiveWhitelist) / - sizeof(*targetPropertyTransitiveWhitelist)); + i < cmArraySize(targetPropertyTransitiveWhitelist); ++i) { if (targetPropertyTransitiveWhitelist[i] == interfacePropertyName) From d169b1f0372e8d6d44406d308381941513f0349a Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 22 Oct 2013 01:14:03 +0200 Subject: [PATCH 3/3] Genex: Use cmArraySize for targetPolicyWhitelist For better readability. --- Source/cmGeneratorExpressionEvaluator.cxx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index bc873e020..d13d0ddcf 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -1101,10 +1101,7 @@ static const struct TargetPolicyNode : public cmGeneratorExpressionNode context->HadContextSensitiveCondition = true; - for (size_t i = 1; - i < (sizeof(targetPolicyWhitelist) / - sizeof(*targetPolicyWhitelist)); - ++i) + for (size_t i = 1; i < cmArraySize(targetPolicyWhitelist); ++i) { const char *policy = targetPolicyWhitelist[i]; if (parameters.front() == policy)