1 #include <mbgl/style/expression/is_constant.hpp>
2 #include <mbgl/style/expression/collator_expression.hpp>
3 
4 
5 namespace mbgl {
6 namespace style {
7 namespace expression {
8 
9 constexpr static const char filter[] = "filter-";
10 
isFeatureConstant(const Expression & expression)11 bool isFeatureConstant(const Expression& expression) {
12     if (expression.getKind() == Kind::CompoundExpression) {
13         auto e = static_cast<const CompoundExpressionBase*>(&expression);
14         const std::string name = e->getName();
15         optional<std::size_t> parameterCount = e->getParameterCount();
16         if (name == "get" && parameterCount && *parameterCount == 1) {
17             return false;
18         } else if (name == "has" && parameterCount && *parameterCount == 1) {
19             return false;
20         } else if (std::equal(std::begin(filter), std::end(filter) - 1, name.begin())) {
21             // Legacy filters begin with "filter-" and are never constant.
22             return false;
23         } else if (
24             name == "properties" ||
25             name == "geometry-type" ||
26             name == "id"
27         ) {
28             return false;
29         }
30     }
31 
32     if (expression.getKind() == Kind::CollatorExpression) {
33         // Although the results of a Collator expression with fixed arguments
34         // generally shouldn't change between executions, we can't serialize them
35         // as constant expressions because results change based on environment.
36         return false;
37     }
38 
39     bool featureConstant = true;
40     expression.eachChild([&](const Expression& e) {
41         if (featureConstant && !isFeatureConstant(e)) {
42             featureConstant = false;
43         }
44     });
45     return featureConstant;
46 }
47 
isZoomConstant(const Expression & e)48 bool isZoomConstant(const Expression& e) {
49     return isGlobalPropertyConstant(e, std::array<std::string, 1>{{"zoom"}});
50 }
51 
52 
53 } // namespace expression
54 } // namespace style
55 } // namespace mbgl
56