blob: 7c468dfeb1fc49f58e029a04102f8d7eade5d89d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#pragma once
#include <mbgl/style/expression/expression.hpp>
#include <mbgl/style/expression/parsing_context.hpp>
#include <mbgl/style/conversion.hpp>
#include <memory>
#include <map>
namespace mbgl {
namespace style {
namespace expression {
class Let : public Expression {
public:
using Bindings = std::map<std::string, std::shared_ptr<Expression>>;
Let(Bindings bindings_, std::unique_ptr<Expression> result_) :
Expression(Kind::Let, result_->getType()),
bindings(std::move(bindings_)),
result(std::move(result_))
{}
static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&);
EvaluationResult evaluate(const EvaluationContext& params) const override;
void eachChild(const std::function<void(const Expression&)>&) const override;
bool operator==(const Expression& e) const override {
if (e.getKind() == Kind::Let) {
auto rhs = static_cast<const Let*>(&e);
return *result == *(rhs->result);
}
return false;
}
std::vector<optional<Value>> possibleOutputs() const override;
Expression* getResult() const {
return result.get();
}
mbgl::Value serialize() const override;
std::string getOperator() const override { return "let"; }
private:
Bindings bindings;
std::unique_ptr<Expression> result;
};
class Var : public Expression {
public:
Var(std::string name_, const std::shared_ptr<Expression>& value_)
: Expression(Kind::Var, value_->getType()), name(std::move(name_)), value(value_) {}
static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&);
EvaluationResult evaluate(const EvaluationContext& params) const override;
void eachChild(const std::function<void(const Expression&)>&) const override;
bool operator==(const Expression& e) const override {
if (e.getKind() == Kind::Var) {
auto rhs = static_cast<const Var*>(&e);
return *value == *(rhs->value);
}
return false;
}
std::vector<optional<Value>> possibleOutputs() const override;
mbgl::Value serialize() const override;
std::string getOperator() const override { return "var"; }
const std::shared_ptr<Expression>& getBoundExpression() const { return value; }
private:
std::string name;
std::shared_ptr<Expression> value;
};
} // namespace expression
} // namespace style
} // namespace mbgl
|