From 9ba47ee49b41569555f0ef85d7a5fce7ad09f0dc Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 31 Dec 2013 14:28:52 +0100 Subject: [PATCH] Genex: Reform error-checking for nullary/unary expressions. The error messages were incorrect (reporting that the expression requires one or two parameters), and repeated. Remove the now-unused ZeroOrMoreParameters enum value. --- Source/cmGeneratorExpressionEvaluator.cxx | 39 ++++++----------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index 83d341efe..1ddafca44 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -49,7 +49,7 @@ struct cmGeneratorExpressionNode enum { DynamicParameters = 0, OneOrMoreParameters = -1, - ZeroOrMoreParameters = -2 + OneOrZeroParameters = -2 }; virtual ~cmGeneratorExpressionNode() {} @@ -384,7 +384,7 @@ struct CompilerIdNode : public cmGeneratorExpressionNode { CompilerIdNode() {} - virtual int NumExpectedParameters() const { return ZeroOrMoreParameters; } + virtual int NumExpectedParameters() const { return OneOrZeroParameters; } std::string EvaluateWithLanguage(const std::vector ¶meters, cmGeneratorExpressionContext *context, @@ -430,12 +430,6 @@ static const struct CCompilerIdNode : public CompilerIdNode const GeneratorExpressionContent *content, cmGeneratorExpressionDAGChecker *dagChecker) const { - if (parameters.size() != 0 && parameters.size() != 1) - { - reportError(context, content->GetOriginalExpression(), - "$ expression requires one or two parameters"); - return std::string(); - } if (!context->HeadTarget) { reportError(context, content->GetOriginalExpression(), @@ -458,12 +452,6 @@ static const struct CXXCompilerIdNode : public CompilerIdNode const GeneratorExpressionContent *content, cmGeneratorExpressionDAGChecker *dagChecker) const { - if (parameters.size() != 0 && parameters.size() != 1) - { - reportError(context, content->GetOriginalExpression(), - "$ expression requires one or two parameters"); - return std::string(); - } if (!context->HeadTarget) { reportError(context, content->GetOriginalExpression(), @@ -481,7 +469,7 @@ struct CompilerVersionNode : public cmGeneratorExpressionNode { CompilerVersionNode() {} - virtual int NumExpectedParameters() const { return ZeroOrMoreParameters; } + virtual int NumExpectedParameters() const { return OneOrZeroParameters; } std::string EvaluateWithLanguage(const std::vector ¶meters, cmGeneratorExpressionContext *context, @@ -526,12 +514,6 @@ static const struct CCompilerVersionNode : public CompilerVersionNode const GeneratorExpressionContent *content, cmGeneratorExpressionDAGChecker *dagChecker) const { - if (parameters.size() != 0 && parameters.size() != 1) - { - reportError(context, content->GetOriginalExpression(), - "$ expression requires one or two parameters"); - return std::string(); - } if (!context->HeadTarget) { reportError(context, content->GetOriginalExpression(), @@ -554,13 +536,6 @@ static const struct CxxCompilerVersionNode : public CompilerVersionNode const GeneratorExpressionContent *content, cmGeneratorExpressionDAGChecker *dagChecker) const { - if (parameters.size() != 0 && parameters.size() != 1) - { - reportError(context, content->GetOriginalExpression(), - "$ expression requires one or two " - "parameters"); - return std::string(); - } if (!context->HeadTarget) { reportError(context, content->GetOriginalExpression(), @@ -579,7 +554,7 @@ struct PlatformIdNode : public cmGeneratorExpressionNode { PlatformIdNode() {} - virtual int NumExpectedParameters() const { return ZeroOrMoreParameters; } + virtual int NumExpectedParameters() const { return OneOrZeroParameters; } std::string Evaluate(const std::vector ¶meters, cmGeneratorExpressionContext *context, @@ -1822,6 +1797,12 @@ std::string GeneratorExpressionContent::EvaluateParameters( reportError(context, this->GetOriginalExpression(), "$<" + identifier + "> expression requires at least one parameter."); } + if (numExpected == cmGeneratorExpressionNode::OneOrZeroParameters + && parameters.size() > 2) + { + reportError(context, this->GetOriginalExpression(), "$<" + identifier + + "> expression requires one or zero parameters."); + } return std::string(); }