From b3d8f5dab7f33dba4f327ab7ef4bd7ea90d6b651 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 4 Oct 2012 00:34:03 +0200 Subject: [PATCH] GenEx: Parse comma after colon tokens specially Otherwise the comma is treated as plain text by ParseContent. $ should be valid and true. $ should be valid and false. $ should be non-valid as it is 3 parameters. $ should be non-valid as it is 3 parameters. Additionally, this allows reporting the correct error for other expressions. For example $ should be invalid because it has an empty target and empty property. It shouldn't attempt to read the property ',' on the 'implicit this' target. --- Source/cmGeneratorExpressionParser.cxx | 8 +++- Tests/GeneratorExpression/CMakeLists.txt | 2 + Tests/GeneratorExpression/check.cmake | 2 + .../GeneratorExpression/BadNOT-stderr.txt | 2 +- .../BadStrEqual-result.txt | 1 + .../BadStrEqual-stderr.txt | 38 +++++++++++++++++++ .../GeneratorExpression/BadStrEqual.cmake | 6 +++ .../GeneratorExpression/RunCMakeTest.cmake | 1 + 8 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 Tests/RunCMake/GeneratorExpression/BadStrEqual-result.txt create mode 100644 Tests/RunCMake/GeneratorExpression/BadStrEqual-stderr.txt create mode 100644 Tests/RunCMake/GeneratorExpression/BadStrEqual.cmake diff --git a/Source/cmGeneratorExpressionParser.cxx b/Source/cmGeneratorExpressionParser.cxx index 344e9f832..d95e1cc2e 100644 --- a/Source/cmGeneratorExpressionParser.cxx +++ b/Source/cmGeneratorExpressionParser.cxx @@ -118,10 +118,16 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression( colonToken = this->it; parameters.resize(parameters.size() + 1); ++this->it; + while (this->it->TokenType == cmGeneratorExpressionToken::CommaSeparator) + { + commaTokens.push_back(this->it); + parameters.resize(parameters.size() + 1); + ++this->it; + } while(this->it->TokenType != cmGeneratorExpressionToken::EndExpression) { this->ParseContent(*(parameters.end() - 1)); - if (this->it->TokenType == cmGeneratorExpressionToken::CommaSeparator) + while (this->it->TokenType == cmGeneratorExpressionToken::CommaSeparator) { commaTokens.push_back(this->it); parameters.resize(parameters.size() + 1); diff --git a/Tests/GeneratorExpression/CMakeLists.txt b/Tests/GeneratorExpression/CMakeLists.txt index 79a8abbf3..64941074b 100644 --- a/Tests/GeneratorExpression/CMakeLists.txt +++ b/Tests/GeneratorExpression/CMakeLists.txt @@ -37,6 +37,8 @@ add_custom_target(check ALL -Dtest_strequal_angle_r=$,$> -Dtest_strequal_comma=$,$> -Dtest_strequal_angle_r_comma=$,$> + -Dtest_strequal_both_empty=$ + -Dtest_strequal_one_empty=$ -Dtest_angle_r=$ -Dtest_comma=$ -P ${CMAKE_CURRENT_SOURCE_DIR}/check.cmake diff --git a/Tests/GeneratorExpression/check.cmake b/Tests/GeneratorExpression/check.cmake index 6fb87a282..71924703f 100644 --- a/Tests/GeneratorExpression/check.cmake +++ b/Tests/GeneratorExpression/check.cmake @@ -38,5 +38,7 @@ check(test_strequal_no_yes "0") check(test_strequal_angle_r "1") check(test_strequal_comma "1") check(test_strequal_angle_r_comma "0") +check(test_strequal_both_empty "1") +check(test_strequal_one_empty "0") check(test_angle_r ">") check(test_comma ",") diff --git a/Tests/RunCMake/GeneratorExpression/BadNOT-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadNOT-stderr.txt index 32169c537..e5e628c30 100644 --- a/Tests/RunCMake/GeneratorExpression/BadNOT-stderr.txt +++ b/Tests/RunCMake/GeneratorExpression/BadNOT-stderr.txt @@ -20,7 +20,7 @@ CMake Error at BadNOT.cmake:1 \(add_custom_target\): \$ - \$ parameter must resolve to exactly one '0' or '1' value. + \$ expression requires exactly one parameter. Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) + diff --git a/Tests/RunCMake/GeneratorExpression/BadStrEqual-result.txt b/Tests/RunCMake/GeneratorExpression/BadStrEqual-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/BadStrEqual-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/BadStrEqual-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadStrEqual-stderr.txt new file mode 100644 index 000000000..dd0d931be --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/BadStrEqual-stderr.txt @@ -0,0 +1,38 @@ +CMake Error at BadStrEqual.cmake:1 \(add_custom_target\): + Error evaluating generator expression: + + \$ + + \$ expression requires 2 comma separated parameters, but got 0 + instead. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) ++CMake Error at BadStrEqual.cmake:1 \(add_custom_target\): + Error evaluating generator expression: + + \$ + + \$ expression requires 2 comma separated parameters, but got 1 + instead. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) ++ +CMake Error at BadStrEqual.cmake:1 \(add_custom_target\): + Error evaluating generator expression: + + \$ + + \$ expression requires 2 comma separated parameters, but got 3 + instead. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) ++ +CMake Error at BadStrEqual.cmake:1 \(add_custom_target\): + Error evaluating generator expression: + + \$ + + \$ expression requires 2 comma separated parameters, but got 3 + instead. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/GeneratorExpression/BadStrEqual.cmake b/Tests/RunCMake/GeneratorExpression/BadStrEqual.cmake new file mode 100644 index 000000000..56eb45853 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/BadStrEqual.cmake @@ -0,0 +1,6 @@ +add_custom_target(check ALL COMMAND check + $ + $ + $ + $ + VERBATIM) diff --git a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake index ed18f25bb..18a47ae00 100644 --- a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake +++ b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake @@ -4,3 +4,4 @@ run_cmake(BadCONFIG) run_cmake(BadOR) run_cmake(BadAND) run_cmake(BadNOT) +run_cmake(BadStrEqual)