summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2012-11-27 18:35:02 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2012-11-27 18:35:02 (GMT)
commit5f30a56f290acd7abd805e32f7537957ae78377d (patch)
tree0804f6d7630fdf716014de76b7638cabc6b6c0eb
parentd5adbbcf9cf7443392a38eb980886833de104826 (diff)
parentb581be07672e08cce4c29fa279b250d8e9c7aaba (diff)
downloadCMake-5f30a56f290acd7abd805e32f7537957ae78377d.zip
CMake-5f30a56f290acd7abd805e32f7537957ae78377d.tar.gz
CMake-5f30a56f290acd7abd805e32f7537957ae78377d.tar.bz2
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.
-rw-r--r--Source/cmGeneratorExpressionEvaluator.cxx37
-rw-r--r--Source/cmGeneratorExpressionEvaluator.h8
-rw-r--r--Source/cmGeneratorExpressionParser.cxx10
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadZero-result.txt1
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadZero-stderr.txt17
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadZero.cmake5
-rw-r--r--Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake1
7 files changed, 75 insertions, 4 deletions
diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx
index c609000..102927e 100644
--- a/Source/cmGeneratorExpressionEvaluator.cxx
+++ b/Source/cmGeneratorExpressionEvaluator.cxx
@@ -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();
}
//----------------------------------------------------------------------------
diff --git a/Source/cmGeneratorExpressionEvaluator.h b/Source/cmGeneratorExpressionEvaluator.h
index d37337e..d904b02 100644
--- a/Source/cmGeneratorExpressionEvaluator.h
+++ b/Source/cmGeneratorExpressionEvaluator.h
@@ -32,6 +32,7 @@ struct cmGeneratorExpressionContext
};
struct cmGeneratorExpressionDAGChecker;
+struct cmGeneratorExpressionNode;
//----------------------------------------------------------------------------
struct cmGeneratorExpressionEvaluator
@@ -117,6 +118,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;
const char *StartContent;
diff --git a/Source/cmGeneratorExpressionParser.cxx b/Source/cmGeneratorExpressionParser.cxx
index 7a8fc51..a619cec 100644
--- a/Source/cmGeneratorExpressionParser.cxx
+++ b/Source/cmGeneratorExpressionParser.cxx
@@ -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;
diff --git a/Tests/RunCMake/GeneratorExpression/BadZero-result.txt b/Tests/RunCMake/GeneratorExpression/BadZero-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadZero-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorExpression/BadZero-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadZero-stderr.txt
new file mode 100644
index 0000000..40db4ae
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadZero-stderr.txt
@@ -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\)
diff --git a/Tests/RunCMake/GeneratorExpression/BadZero.cmake b/Tests/RunCMake/GeneratorExpression/BadZero.cmake
new file mode 100644
index 0000000..559a9fa
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/BadZero.cmake
@@ -0,0 +1,5 @@
+
+add_custom_target(check ALL COMMAND check
+ $<0>
+ $<0,>
+ VERBATIM)
diff --git a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake
index 18a47ae..992ba79 100644
--- a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake
+++ b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake
@@ -5,3 +5,4 @@ run_cmake(BadOR)
run_cmake(BadAND)
run_cmake(BadNOT)
run_cmake(BadStrEqual)
+run_cmake(BadZero)