diff options
-rw-r--r-- | include/mbgl/style/expression/assertion.hpp | 5 | ||||
-rw-r--r-- | include/mbgl/style/expression/interpolate.hpp | 11 | ||||
-rw-r--r-- | include/mbgl/style/expression/step.hpp | 11 | ||||
-rw-r--r-- | src/mbgl/style/expression/assertion.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/style/expression/coercion.cpp | 1 | ||||
-rw-r--r-- | src/mbgl/style/expression/equals.cpp | 16 | ||||
-rw-r--r-- | src/mbgl/style/expression/interpolate.cpp | 11 | ||||
-rw-r--r-- | src/mbgl/style/expression/step.cpp | 10 | ||||
-rw-r--r-- | test/style/conversion/stringify.test.cpp | 2 |
9 files changed, 47 insertions, 28 deletions
diff --git a/include/mbgl/style/expression/assertion.hpp b/include/mbgl/style/expression/assertion.hpp index d1e919b10f..90da16b068 100644 --- a/include/mbgl/style/expression/assertion.hpp +++ b/include/mbgl/style/expression/assertion.hpp @@ -13,10 +13,7 @@ namespace expression { class Assertion : public Expression { public: - Assertion(type::Type type_, std::vector<std::unique_ptr<Expression>> inputs_) : - Expression(type_), - inputs(std::move(inputs_)) - {} + Assertion(type::Type type_, std::vector<std::unique_ptr<Expression>> inputs_); static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); diff --git a/include/mbgl/style/expression/interpolate.hpp b/include/mbgl/style/expression/interpolate.hpp index 0e7682007f..0aca6909a3 100644 --- a/include/mbgl/style/expression/interpolate.hpp +++ b/include/mbgl/style/expression/interpolate.hpp @@ -19,14 +19,9 @@ ParseResult parseInterpolate(const mbgl::style::conversion::Convertible& value, class Interpolate : public Expression { public: Interpolate(const type::Type& type_, - Interpolator interpolator_, - std::unique_ptr<Expression> input_, - std::map<double, std::unique_ptr<Expression>> stops_ - ) : Expression(type_), - interpolator(std::move(interpolator_)), - input(std::move(input_)), - stops(std::move(stops_)) - {} + Interpolator interpolator_, + std::unique_ptr<Expression> input_, + std::map<double, std::unique_ptr<Expression>> stops_); const std::unique_ptr<Expression>& getInput() const { return input; } const Interpolator& getInterpolator() const { return interpolator; } diff --git a/include/mbgl/style/expression/step.hpp b/include/mbgl/style/expression/step.hpp index 2f9524a53c..24e29b1a4e 100644 --- a/include/mbgl/style/expression/step.hpp +++ b/include/mbgl/style/expression/step.hpp @@ -1,4 +1,3 @@ - #pragma once #include <mbgl/style/expression/expression.hpp> @@ -10,7 +9,6 @@ #include <memory> #include <map> - namespace mbgl { namespace style { namespace expression { @@ -18,12 +16,8 @@ namespace expression { class Step : public Expression { public: Step(const type::Type& type_, - std::unique_ptr<Expression> input_, - std::map<double, std::unique_ptr<Expression>> stops_ - ) : Expression(type_), - input(std::move(input_)), - stops(std::move(stops_)) - {} + std::unique_ptr<Expression> input_, + std::map<double, std::unique_ptr<Expression>> stops_); EvaluationResult evaluate(const EvaluationContext& params) const override; void eachChild(const std::function<void(const Expression&)>& visit) const override; @@ -40,6 +34,7 @@ public: mbgl::Value serialize() const override; std::string getOperator() const override { return "step"; } + private: const std::unique_ptr<Expression> input; const std::map<double, std::unique_ptr<Expression>> stops; diff --git a/src/mbgl/style/expression/assertion.cpp b/src/mbgl/style/expression/assertion.cpp index d6f3f1b584..eefc9e24f8 100644 --- a/src/mbgl/style/expression/assertion.cpp +++ b/src/mbgl/style/expression/assertion.cpp @@ -6,6 +6,14 @@ namespace style { namespace expression { using namespace mbgl::style::conversion; + +Assertion::Assertion(type::Type type_, std::vector<std::unique_ptr<Expression>> inputs_) : + Expression(type_), + inputs(std::move(inputs_)) +{ + assert(!inputs.empty()); +} + ParseResult Assertion::parse(const Convertible& value, ParsingContext& ctx) { static std::unordered_map<std::string, type::Type> types { {"string", type::String}, diff --git a/src/mbgl/style/expression/coercion.cpp b/src/mbgl/style/expression/coercion.cpp index 0166d144e0..11172a3668 100644 --- a/src/mbgl/style/expression/coercion.cpp +++ b/src/mbgl/style/expression/coercion.cpp @@ -71,6 +71,7 @@ Coercion::Coercion(type::Type type_, std::vector<std::unique_ptr<Expression>> in Expression(std::move(type_)), inputs(std::move(inputs_)) { + assert(!inputs.empty()); type::Type t = getType(); if (t.is<type::NumberType>()) { coerceSingleValue = toNumber; diff --git a/src/mbgl/style/expression/equals.cpp b/src/mbgl/style/expression/equals.cpp index 6d963cc1d8..f2f59e31ef 100644 --- a/src/mbgl/style/expression/equals.cpp +++ b/src/mbgl/style/expression/equals.cpp @@ -4,11 +4,20 @@ namespace mbgl { namespace style { namespace expression { +static bool isComparableType(const type::Type& type) { + return type == type::String || + type == type::Number || + type == type::Boolean || + type == type::Null; +} + Equals::Equals(std::unique_ptr<Expression> lhs_, std::unique_ptr<Expression> rhs_, bool negate_) : Expression(type::Boolean), lhs(std::move(lhs_)), rhs(std::move(rhs_)), negate(negate_) { + assert(isComparableType(lhs->getType()) || isComparableType(rhs->getType())); + assert(lhs->getType() == rhs->getType() || lhs->getType() == type::Value || rhs->getType() == type::Value); } EvaluationResult Equals::evaluate(const EvaluationContext& params) const { @@ -41,13 +50,6 @@ std::vector<optional<Value>> Equals::possibleOutputs() const { return {{ true }, { false }}; } -static bool isComparableType(const type::Type& type) { - return type == type::String || - type == type::Number || - type == type::Boolean || - type == type::Null; -} - using namespace mbgl::style::conversion; ParseResult Equals::parse(const Convertible& value, ParsingContext& ctx) { std::size_t length = arrayLength(value); diff --git a/src/mbgl/style/expression/interpolate.cpp b/src/mbgl/style/expression/interpolate.cpp index c3a1f0dc95..a9bb3bf05e 100644 --- a/src/mbgl/style/expression/interpolate.cpp +++ b/src/mbgl/style/expression/interpolate.cpp @@ -260,6 +260,17 @@ ParseResult createInterpolate(type::Type type, ); } +Interpolate::Interpolate(const type::Type& type_, + Interpolator interpolator_, + std::unique_ptr<Expression> input_, + std::map<double, std::unique_ptr<Expression>> stops_) + : Expression(type_), + interpolator(std::move(interpolator_)), + input(std::move(input_)), + stops(std::move(stops_)) { + assert(input->getType() == type::Number); +} + std::vector<optional<Value>> Interpolate::possibleOutputs() const { std::vector<optional<Value>> result; for (const auto& stop : stops) { diff --git a/src/mbgl/style/expression/step.cpp b/src/mbgl/style/expression/step.cpp index ddaf9417cb..f42a2721a9 100644 --- a/src/mbgl/style/expression/step.cpp +++ b/src/mbgl/style/expression/step.cpp @@ -8,6 +8,16 @@ namespace mbgl { namespace style { namespace expression { +Step::Step(const type::Type& type_, + std::unique_ptr<Expression> input_, + std::map<double, std::unique_ptr<Expression>> stops_) + : Expression(type_), + input(std::move(input_)), + stops(std::move(stops_)) +{ + assert(input->getType() == type::Number); +} + EvaluationResult Step::evaluate(const EvaluationContext& params) const { const EvaluationResult evaluatedInput = input->evaluate(params); if (!evaluatedInput) { diff --git a/test/style/conversion/stringify.test.cpp b/test/style/conversion/stringify.test.cpp index 567c022036..bc73b0cedb 100644 --- a/test/style/conversion/stringify.test.cpp +++ b/test/style/conversion/stringify.test.cpp @@ -79,7 +79,7 @@ TEST(Stringify, Value) { TEST(Stringify, Filter) { using namespace mbgl::style::expression::dsl; ASSERT_EQ(stringify(Filter()), "null"); - ASSERT_EQ(stringify(Filter(eq(literal("a"), literal(1.0)))), "[\"==\",\"a\",1.0]"); + ASSERT_EQ(stringify(Filter(eq(literal("a"), literal("b")))), "[\"==\",\"a\",\"b\"]"); } TEST(Stringify, CameraFunction) { |