Merge topic 'generator-expression-fixes'

b581be0 Genex: Don't segfault on $<FOO,>
07749e3 Genex: Ensure that $<0:...> has a parameter.
ee96dc7 Genex: Extract a method to parse parameters.
This commit is contained in:
Brad King 2012-11-27 13:35:02 -05:00 committed by CMake Topic Stage
commit 5f30a56f29
7 changed files with 75 additions and 4 deletions

View File

@ -66,6 +66,8 @@ static const struct ZeroNode : public cmGeneratorExpressionNode
virtual bool GeneratesContent() const { return false; }
virtual bool AcceptsSingleArbitraryContentParameter() const { return true; }
std::string Evaluate(const std::vector<std::string> &,
cmGeneratorExpressionContext *,
const GeneratorExpressionContent *,
@ -642,6 +644,20 @@ std::string GeneratorExpressionContent::Evaluate(
if (!node->GeneratesContent())
{
if (node->AcceptsSingleArbitraryContentParameter())
{
if (this->ParamChildren.empty())
{
reportError(context, this->GetOriginalExpression(),
"$<" + identifier + "> expression requires a parameter.");
}
}
else
{
std::vector<std::string> parameters;
this->EvaluateParameters(node, identifier, context, dagChecker,
parameters);
}
return std::string();
}
@ -677,6 +693,23 @@ std::string GeneratorExpressionContent::Evaluate(
}
std::vector<std::string> parameters;
this->EvaluateParameters(node, identifier, context, dagChecker, parameters);
if (context->HadError)
{
return std::string();
}
return node->Evaluate(parameters, context, this, dagChecker);
}
//----------------------------------------------------------------------------
std::string GeneratorExpressionContent::EvaluateParameters(
const cmGeneratorExpressionNode *node,
const std::string &identifier,
cmGeneratorExpressionContext *context,
cmGeneratorExpressionDAGChecker *dagChecker,
std::vector<std::string> &parameters) const
{
{
std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
pit = this->ParamChildren.begin();
@ -732,10 +765,8 @@ std::string GeneratorExpressionContent::Evaluate(
{
reportError(context, this->GetOriginalExpression(), "$<" + identifier
+ "> expression requires at least one parameter.");
return std::string();
}
return node->Evaluate(parameters, context, this, dagChecker);
return std::string();
}
//----------------------------------------------------------------------------

View File

@ -32,6 +32,7 @@ struct cmGeneratorExpressionContext
};
struct cmGeneratorExpressionDAGChecker;
struct cmGeneratorExpressionNode;
//----------------------------------------------------------------------------
struct cmGeneratorExpressionEvaluator
@ -116,6 +117,13 @@ struct GeneratorExpressionContent : public cmGeneratorExpressionEvaluator
~GeneratorExpressionContent();
private:
std::string EvaluateParameters(const cmGeneratorExpressionNode *node,
const std::string &identifier,
cmGeneratorExpressionContext *context,
cmGeneratorExpressionDAGChecker *dagChecker,
std::vector<std::string> &parameters) const;
private:
std::vector<cmGeneratorExpressionEvaluator*> IdentifierChildren;
std::vector<std::vector<cmGeneratorExpressionEvaluator*> > ParamChildren;

View File

@ -88,7 +88,15 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression(
while(this->it->TokenType != cmGeneratorExpressionToken::EndExpression
&& this->it->TokenType != cmGeneratorExpressionToken::ColonSeparator)
{
this->ParseContent(identifier);
if (this->it->TokenType == cmGeneratorExpressionToken::CommaSeparator)
{
extendText(identifier, this->it);
++this->it;
}
else
{
this->ParseContent(identifier);
}
if (this->it == this->Tokens.end())
{
break;

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,17 @@
CMake Error at BadZero.cmake:2 \(add_custom_target\):
Error evaluating generator expression:
\$<0>
\$<0> expression requires a parameter.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
+
CMake Error at BadZero.cmake:2 \(add_custom_target\):
Error evaluating generator expression:
\$<0,>
Expression did not evaluate to a known generator expression
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,5 @@
add_custom_target(check ALL COMMAND check
$<0>
$<0,>
VERBATIM)

View File

@ -5,3 +5,4 @@ run_cmake(BadOR)
run_cmake(BadAND)
run_cmake(BadNOT)
run_cmake(BadStrEqual)
run_cmake(BadZero)