summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnder Conselvan de Oliveira <ander.deoliveira@mapbox.com>2019-04-02 11:59:13 +0300
committerAnder Conselvan de Oliveira <ander.deoliveira@mapbox.com>2019-05-21 12:14:22 +0300
commit33cfd080c2ce0f2ed0c9ee3102cedc4baedf0d8c (patch)
tree61524ba15c720b2957454f9841856d4618330329 /src
parent11055f9a8887eec8c69b14cd1417c29abce43d89 (diff)
downloadqtlocation-mapboxgl-33cfd080c2ce0f2ed0c9ee3102cedc4baedf0d8c.tar.gz
[core] Fix most identity function with default legacy expression tests
Add handling of default value to the conversion of legacy identity functions. The color and enum tests still don't pass though.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/style/conversion/function.cpp17
-rw-r--r--src/mbgl/style/expression/dsl.cpp50
2 files changed, 47 insertions, 20 deletions
diff --git a/src/mbgl/style/conversion/function.cpp b/src/mbgl/style/conversion/function.cpp
index fdf52c36db..179ad0e437 100644
--- a/src/mbgl/style/conversion/function.cpp
+++ b/src/mbgl/style/conversion/function.cpp
@@ -660,6 +660,11 @@ optional<std::unique_ptr<Expression>> convertFunctionToExpression(type::Type typ
}
}
+ optional<std::unique_ptr<Expression>> defaultExpr;
+ if (objectMember(value, "default")) {
+ defaultExpr = convertLiteral(type, *objectMember(value, "default"), err);
+ }
+
if (!objectMember(value, "property")) {
// Camera function.
switch (functionType) {
@@ -688,22 +693,22 @@ optional<std::unique_ptr<Expression>> convertFunctionToExpression(type::Type typ
if (functionType == FunctionType::Identity) {
return type.match(
[&] (const type::StringType&) -> optional<std::unique_ptr<Expression>> {
- return string(get(literal(*property)));
+ return string(get(literal(*property)), std::move(defaultExpr));
},
[&] (const type::NumberType&) -> optional<std::unique_ptr<Expression>> {
- return number(get(literal(*property)));
+ return number(get(literal(*property)), std::move(defaultExpr));
},
[&] (const type::BooleanType&) -> optional<std::unique_ptr<Expression>> {
- return boolean(get(literal(*property)));
+ return boolean(get(literal(*property)), std::move(defaultExpr));
},
[&] (const type::ColorType&) -> optional<std::unique_ptr<Expression>> {
- return toColor(get(literal(*property)));
+ return toColor(get(literal(*property)), std::move(defaultExpr));
},
[&] (const type::Array& array) -> optional<std::unique_ptr<Expression>> {
- return assertion(array, get(literal(*property)));
+ return assertion(array, get(literal(*property)), std::move(defaultExpr));
},
[&] (const type::FormattedType&) -> optional<std::unique_ptr<Expression>> {
- return format(get(literal(*property)));
+ return toFormatted(get(literal(*property)), std::move(defaultExpr));
},
[&] (const auto&) -> optional<std::unique_ptr<Expression>> {
assert(false); // No properties use this type.
diff --git a/src/mbgl/style/expression/dsl.cpp b/src/mbgl/style/expression/dsl.cpp
index b4fd8fa551..d1d8dea799 100644
--- a/src/mbgl/style/expression/dsl.cpp
+++ b/src/mbgl/style/expression/dsl.cpp
@@ -54,32 +54,54 @@ std::unique_ptr<Expression> literal(std::initializer_list<const char *> value) {
return literal(values);
}
-std::unique_ptr<Expression> assertion(type::Type type, std::unique_ptr<Expression> value) {
- return std::make_unique<Assertion>(type, vec(std::move(value)));
+std::unique_ptr<Expression> assertion(type::Type type,
+ std::unique_ptr<Expression> value,
+ optional<std::unique_ptr<Expression>> def) {
+ std::vector<std::unique_ptr<Expression>> v = vec(std::move(value));
+ if (def) {
+ v.push_back(std::move(*def));
+ }
+ return std::make_unique<Assertion>(type, std::move(v));
+}
+
+std::unique_ptr<Expression> number(std::unique_ptr<Expression> value,
+ optional<std::unique_ptr<Expression>> def) {
+ return assertion(type::Number, std::move(value), std::move(def));
}
-std::unique_ptr<Expression> number(std::unique_ptr<Expression> value) {
- return assertion(type::Number, std::move(value));
+std::unique_ptr<Expression> string(std::unique_ptr<Expression> value,
+ optional<std::unique_ptr<Expression>> def) {
+ return assertion(type::String, std::move(value), std::move(def));
}
-std::unique_ptr<Expression> string(std::unique_ptr<Expression> value) {
- return assertion(type::String, std::move(value));
+std::unique_ptr<Expression> boolean(std::unique_ptr<Expression> value,
+ optional<std::unique_ptr<Expression>> def) {
+ return assertion(type::Boolean, std::move(value), std::move(def));
}
-std::unique_ptr<Expression> boolean(std::unique_ptr<Expression> value) {
- return assertion(type::Boolean, std::move(value));
+std::unique_ptr<Expression> coercion(type::Type type,
+ std::unique_ptr<Expression> value,
+ optional<std::unique_ptr<Expression>> def) {
+ std::vector<std::unique_ptr<Expression>> v = vec(std::move(value));
+ if (def) {
+ v.push_back(std::move(*def));
+ }
+ return std::make_unique<Coercion>(type, std::move(v));
}
-std::unique_ptr<Expression> toColor(std::unique_ptr<Expression> value) {
- return std::make_unique<Coercion>(type::Color, vec(std::move(value)));
+std::unique_ptr<Expression> toColor(std::unique_ptr<Expression> value,
+ optional<std::unique_ptr<Expression>> def) {
+ return coercion(type::Color, std::move(value), std::move(def));
}
-std::unique_ptr<Expression> toString(std::unique_ptr<Expression> value) {
- return std::make_unique<Coercion>(type::String, vec(std::move(value)));
+std::unique_ptr<Expression> toString(std::unique_ptr<Expression> value,
+ optional<std::unique_ptr<Expression>> def) {
+ return coercion(type::String, std::move(value), std::move(def));
}
-std::unique_ptr<Expression> toFormatted(std::unique_ptr<Expression> value) {
- return std::make_unique<Coercion>(type::Formatted, vec(std::move(value)));
+std::unique_ptr<Expression> toFormatted(std::unique_ptr<Expression> value,
+ optional<std::unique_ptr<Expression>> def) {
+ return coercion(type::Formatted, std::move(value), std::move(def));
}
std::unique_ptr<Expression> get(const char* value) {