diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2018-06-29 14:32:39 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2018-06-29 15:38:11 -0700 |
commit | 647959a85327660a8d0b35da0b8a247820a36c15 (patch) | |
tree | 75e3b323b96d6bd36b7a351cb04b6f3a565399e4 /src/mbgl | |
parent | 25ac89e018a27fc689f742429c78ba492682b0a0 (diff) | |
download | qtlocation-mapboxgl-647959a85327660a8d0b35da0b8a247820a36c15.tar.gz |
[core] Add assertions to expression constructors
Diffstat (limited to 'src/mbgl')
-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 |
5 files changed, 39 insertions, 7 deletions
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) { |