Commit d36b4894 authored by Stephen Kelly's avatar Stephen Kelly
Browse files

Genex: Allow single param expressions to accept arbirary input.

Existing single-parameter expressions work due to special casing
which assumes that if there is only one parameter, and the node
accepts arbitrary content, then the result is the input.

This is true for the existing expressions matching that
pattern - namely the "1" and "TARGET_NAME" expressions. However,
the LOWER_CASE, and UPPER_CASE expressions should also accept
arbitrary content, and in their case, the result is not the input.

Refactor the cmGeneratorExpressionEvaluator to allow that extension.
Actually evaluate the "1" and "0" nodes.
parent 218ad35f
......@@ -82,7 +82,6 @@ static const struct ZeroNode : public cmGeneratorExpressionNode
const GeneratorExpressionContent *,
cmGeneratorExpressionDAGChecker *) const
{
// Unreachable
return std::string();
}
} zeroNode;
......@@ -94,13 +93,12 @@ static const struct OneNode : public cmGeneratorExpressionNode
virtual bool AcceptsArbitraryContentParameter() const { return true; }
std::string Evaluate(const std::vector<std::string> &,
std::string Evaluate(const std::vector<std::string> &parameters,
cmGeneratorExpressionContext *,
const GeneratorExpressionContent *,
cmGeneratorExpressionDAGChecker *) const
{
// Unreachable
return std::string();
return parameters.front();
}
} oneNode;
......@@ -1634,14 +1632,6 @@ std::string GeneratorExpressionContent::Evaluate(
return std::string();
}
if (node->NumExpectedParameters() == 1
&& node->AcceptsArbitraryContentParameter())
{
return this->ProcessArbitraryContent(node, identifier, context,
dagChecker,
this->ParamChildren.begin());
}
std::vector<std::string> parameters;
this->EvaluateParameters(node, identifier, context, dagChecker, parameters);
if (context->HadError)
......@@ -1669,33 +1659,35 @@ std::string GeneratorExpressionContent::EvaluateParameters(
pend = this->ParamChildren.end();
const bool acceptsArbitraryContent
= node->AcceptsArbitraryContentParameter();
for ( ; pit != pend; ++pit)
int counter = 1;
for ( ; pit != pend; ++pit, ++counter)
{
std::string parameter;
std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it =
pit->begin();
const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end =
pit->end();
for ( ; it != end; ++it)
{
parameter += (*it)->Evaluate(context, dagChecker);
if (context->HadError)
{
return std::string();
}
}
parameters.push_back(parameter);
if (acceptsArbitraryContent
&& parameters.size() == (unsigned int)numExpected - 1)
if (acceptsArbitraryContent && counter == numExpected)
{
assert(pit != pend);
std::string lastParam = this->ProcessArbitraryContent(node, identifier,
context,
dagChecker,
pit + 1);
pit);
parameters.push_back(lastParam);
return std::string();
}
else
{
std::string parameter;
std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it =
pit->begin();
const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end =
pit->end();
for ( ; it != end; ++it)
{
parameter += (*it)->Evaluate(context, dagChecker);
if (context->HadError)
{
return std::string();
}
}
parameters.push_back(parameter);
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment