From b16893f903b3f81803d59cdfa3253a3fb09cfd3e Mon Sep 17 00:00:00 2001 From: Anand Thakker Date: Wed, 21 Feb 2018 21:39:33 -0500 Subject: [PATCH] Correctly parse constant expressions in dds style properties (#11282) * Correctly parse constant expressions in dds style properties Closes #10849 * Clarify --- .../conversion/data_driven_property_value.hpp | 21 ++++++++++++++++--- include/mbgl/style/expression/literal.hpp | 4 ++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/mbgl/style/conversion/data_driven_property_value.hpp b/include/mbgl/style/conversion/data_driven_property_value.hpp index 8880d28fb..5f4395f35 100644 --- a/include/mbgl/style/conversion/data_driven_property_value.hpp +++ b/include/mbgl/style/conversion/data_driven_property_value.hpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include @@ -32,12 +34,25 @@ struct Converter> { return {}; } - if (isFeatureConstant(**expression)) { + bool featureConstant = isFeatureConstant(**expression); + bool zoomConstant = isZoomConstant(**expression); + + if (featureConstant && !zoomConstant) { return DataDrivenPropertyValue(CameraFunction(std::move(*expression))); - } else if (isZoomConstant(**expression)) { + } else if (!featureConstant && zoomConstant) { return DataDrivenPropertyValue(SourceFunction(std::move(*expression))); - } else { + } else if (!featureConstant && !zoomConstant) { return DataDrivenPropertyValue(CompositeFunction(std::move(*expression))); + } else { + // If an expression is neither zoom- nor feature-dependent, it + // should have been reduced to a Literal when it was parsed. + auto literal = dynamic_cast(expression->get()); + assert(literal); + optional constant = fromExpressionValue(literal->getValue()); + if (!constant) { + return {}; + } + return DataDrivenPropertyValue(*constant); } } else if (!isObject(value)) { optional constant = convert(value, error); diff --git a/include/mbgl/style/expression/literal.hpp b/include/mbgl/style/expression/literal.hpp index 82983d78a..a5c5fa109 100644 --- a/include/mbgl/style/expression/literal.hpp +++ b/include/mbgl/style/expression/literal.hpp @@ -32,6 +32,10 @@ public: std::vector> possibleOutputs() const override { return {{ value }}; } + + Value getValue() const { + return value; + } private: Value value;