summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2018-07-20 15:40:47 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2018-07-24 10:06:18 +0300
commitcb714d57c5c5ad181aaf5e1690221da8d965682b (patch)
tree21fa8cc6caf1e66de40f9715fa98426e86cfd964 /src
parent1683da3225d0cbed3bb6238fd292fa288f6a32d6 (diff)
downloadqtlocation-mapboxgl-cb714d57c5c5ad181aaf5e1690221da8d965682b.tar.gz
[core] Replace expressions RTTI with enums + static cast
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/style/expression/assertion.cpp5
-rw-r--r--src/mbgl/style/expression/boolean_operator.cpp6
-rw-r--r--src/mbgl/style/expression/case.cpp3
-rw-r--r--src/mbgl/style/expression/coalesce.cpp3
-rw-r--r--src/mbgl/style/expression/coercion.cpp5
-rw-r--r--src/mbgl/style/expression/collator_expression.cpp5
-rw-r--r--src/mbgl/style/expression/equals.cpp5
-rw-r--r--src/mbgl/style/expression/find_zoom_curve.cpp39
-rw-r--r--src/mbgl/style/expression/interpolate.cpp2
-rw-r--r--src/mbgl/style/expression/is_constant.cpp5
-rw-r--r--src/mbgl/style/expression/length.cpp5
-rw-r--r--src/mbgl/style/expression/match.cpp3
-rw-r--r--src/mbgl/style/expression/parsing_context.cpp16
-rw-r--r--src/mbgl/style/expression/step.cpp5
14 files changed, 70 insertions, 37 deletions
diff --git a/src/mbgl/style/expression/assertion.cpp b/src/mbgl/style/expression/assertion.cpp
index eefc9e24f8..2434d7a2f8 100644
--- a/src/mbgl/style/expression/assertion.cpp
+++ b/src/mbgl/style/expression/assertion.cpp
@@ -8,7 +8,7 @@ namespace expression {
using namespace mbgl::style::conversion;
Assertion::Assertion(type::Type type_, std::vector<std::unique_ptr<Expression>> inputs_) :
- Expression(type_),
+ Expression(Kind::Assertion, type_),
inputs(std::move(inputs_))
{
assert(!inputs.empty());
@@ -72,7 +72,8 @@ void Assertion::eachChild(const std::function<void(const Expression&)>& visit) c
};
bool Assertion::operator==(const Expression& e) const {
- if (auto rhs = dynamic_cast<const Assertion*>(&e)) {
+ if (e.getKind() == Kind::Assertion) {
+ auto rhs = static_cast<const Assertion*>(&e);
return getType() == rhs->getType() && Expression::childrenEqual(inputs, rhs->inputs);
}
return false;
diff --git a/src/mbgl/style/expression/boolean_operator.cpp b/src/mbgl/style/expression/boolean_operator.cpp
index 8d277450ba..68e96129aa 100644
--- a/src/mbgl/style/expression/boolean_operator.cpp
+++ b/src/mbgl/style/expression/boolean_operator.cpp
@@ -20,7 +20,8 @@ void Any::eachChild(const std::function<void(const Expression&)>& visit) const {
}
bool Any::operator==(const Expression& e) const {
- if (auto rhs = dynamic_cast<const Any*>(&e)) {
+ if (e.getKind() == Kind::Any) {
+ auto rhs = static_cast<const Any*>(&e);
return Expression::childrenEqual(inputs, rhs->inputs);
}
return false;
@@ -47,7 +48,8 @@ void All::eachChild(const std::function<void(const Expression&)>& visit) const {
}
bool All::operator==(const Expression& e) const {
- if (auto rhs = dynamic_cast<const All*>(&e)) {
+ if (e.getKind() == Kind::All) {
+ auto rhs = static_cast<const All*>(&e);
return Expression::childrenEqual(inputs, rhs->inputs);
}
return false;
diff --git a/src/mbgl/style/expression/case.cpp b/src/mbgl/style/expression/case.cpp
index 295e694189..e885c0ce6b 100644
--- a/src/mbgl/style/expression/case.cpp
+++ b/src/mbgl/style/expression/case.cpp
@@ -28,7 +28,8 @@ void Case::eachChild(const std::function<void(const Expression&)>& visit) const
}
bool Case::operator==(const Expression& e) const {
- if (auto rhs = dynamic_cast<const Case*>(&e)) {
+ if (e.getKind() == Kind::Case) {
+ auto rhs = static_cast<const Case*>(&e);
return *otherwise == *(rhs->otherwise) && Expression::childrenEqual(branches, rhs->branches);
}
return false;
diff --git a/src/mbgl/style/expression/coalesce.cpp b/src/mbgl/style/expression/coalesce.cpp
index 872a9abbef..0090f16009 100644
--- a/src/mbgl/style/expression/coalesce.cpp
+++ b/src/mbgl/style/expression/coalesce.cpp
@@ -21,7 +21,8 @@ void Coalesce::eachChild(const std::function<void(const Expression&)>& visit) co
}
bool Coalesce::operator==(const Expression& e) const {
- if (auto rhs = dynamic_cast<const Coalesce*>(&e)) {
+ if (e.getKind() == Kind::Coalesce) {
+ auto rhs = static_cast<const Coalesce*>(&e);
return Expression::childrenEqual(args, rhs->args);
}
return false;
diff --git a/src/mbgl/style/expression/coercion.cpp b/src/mbgl/style/expression/coercion.cpp
index 11172a3668..f5a4d70f66 100644
--- a/src/mbgl/style/expression/coercion.cpp
+++ b/src/mbgl/style/expression/coercion.cpp
@@ -68,7 +68,7 @@ EvaluationResult toColor(const Value& colorValue) {
}
Coercion::Coercion(type::Type type_, std::vector<std::unique_ptr<Expression>> inputs_) :
- Expression(std::move(type_)),
+ Expression(Kind::Coercion, std::move(type_)),
inputs(std::move(inputs_))
{
assert(!inputs.empty());
@@ -138,7 +138,8 @@ void Coercion::eachChild(const std::function<void(const Expression&)>& visit) co
};
bool Coercion::operator==(const Expression& e) const {
- if (auto rhs = dynamic_cast<const Coercion*>(&e)) {
+ if (e.getKind() == Kind::Coercion) {
+ auto rhs = static_cast<const Coercion*>(&e);
return getType() == rhs->getType() && Expression::childrenEqual(inputs, rhs->inputs);
}
return false;
diff --git a/src/mbgl/style/expression/collator_expression.cpp b/src/mbgl/style/expression/collator_expression.cpp
index f5e4e3fdff..b27eedbc76 100644
--- a/src/mbgl/style/expression/collator_expression.cpp
+++ b/src/mbgl/style/expression/collator_expression.cpp
@@ -10,7 +10,7 @@ namespace expression {
CollatorExpression::CollatorExpression(std::unique_ptr<Expression> caseSensitive_,
std::unique_ptr<Expression> diacriticSensitive_,
optional<std::unique_ptr<Expression>> locale_)
- : Expression(type::Collator)
+ : Expression(Kind::CollatorExpression, type::Collator)
, caseSensitive(std::move(caseSensitive_))
, diacriticSensitive(std::move(diacriticSensitive_))
, locale(std::move(locale_))
@@ -73,7 +73,8 @@ void CollatorExpression::eachChild(const std::function<void(const Expression&)>&
}
bool CollatorExpression::operator==(const Expression& e) const {
- if (auto rhs = dynamic_cast<const CollatorExpression*>(&e)) {
+ if (e.getKind() == Kind::CollatorExpression) {
+ auto rhs = static_cast<const CollatorExpression*>(&e);
if ((locale && (!rhs->locale || **locale != **(rhs->locale))) ||
(!locale && rhs->locale)) {
return false;
diff --git a/src/mbgl/style/expression/equals.cpp b/src/mbgl/style/expression/equals.cpp
index 245899f975..73e2baf71b 100644
--- a/src/mbgl/style/expression/equals.cpp
+++ b/src/mbgl/style/expression/equals.cpp
@@ -13,7 +13,7 @@ static bool isComparableType(const type::Type& type) {
}
Equals::Equals(std::unique_ptr<Expression> lhs_, std::unique_ptr<Expression> rhs_, optional<std::unique_ptr<Expression>> collator_, bool negate_)
- : Expression(type::Boolean),
+ : Expression(Kind::Equals, type::Boolean),
lhs(std::move(lhs_)),
rhs(std::move(rhs_)),
collator(std::move(collator_)),
@@ -53,7 +53,8 @@ void Equals::eachChild(const std::function<void(const Expression&)>& visit) cons
}
bool Equals::operator==(const Expression& e) const {
- if (auto eq = dynamic_cast<const Equals*>(&e)) {
+ if (e.getKind() == Kind::Equals) {
+ auto eq = static_cast<const Equals*>(&e);
return eq->negate == negate && *eq->lhs == *lhs && *eq->rhs == *rhs;
}
return false;
diff --git a/src/mbgl/style/expression/find_zoom_curve.cpp b/src/mbgl/style/expression/find_zoom_curve.cpp
index 1e0a936605..a27f8560ef 100644
--- a/src/mbgl/style/expression/find_zoom_curve.cpp
+++ b/src/mbgl/style/expression/find_zoom_curve.cpp
@@ -14,9 +14,14 @@ namespace expression {
optional<variant<const Interpolate*, const Step*, ParsingError>> findZoomCurve(const expression::Expression* e) {
optional<variant<const Interpolate*, const Step*, ParsingError>> result;
- if (auto let = dynamic_cast<const Let*>(e)) {
+ switch (e->getKind()) {
+ case Kind::Let: {
+ auto let = static_cast<const Let*>(e);
result = findZoomCurve(let->getResult());
- } else if (auto coalesce = dynamic_cast<const Coalesce*>(e)) {
+ break;
+ }
+ case Kind::Coalesce: {
+ auto coalesce = static_cast<const Coalesce*>(e);
std::size_t length = coalesce->getLength();
for (std::size_t i = 0; i < length; i++) {
result = findZoomCurve(coalesce->getChild(i));
@@ -24,16 +29,30 @@ optional<variant<const Interpolate*, const Step*, ParsingError>> findZoomCurve(c
break;
}
}
- } else if (auto curve = dynamic_cast<const Interpolate*>(e)) {
- auto z = dynamic_cast<CompoundExpressionBase*>(curve->getInput().get());
- if (z && z->getName() == "zoom") {
- result = {curve};
+ break;
+ }
+ case Kind::Interpolate: {
+ auto curve = static_cast<const Interpolate*>(e);
+ if (curve->getInput()->getKind() == Kind::CompoundExpression) {
+ auto z = static_cast<CompoundExpressionBase*>(curve->getInput().get());
+ if (z && z->getName() == "zoom") {
+ result = {curve};
+ }
}
- } else if (auto step = dynamic_cast<const Step*>(e)) {
- auto z = dynamic_cast<CompoundExpressionBase*>(step->getInput().get());
- if (z && z->getName() == "zoom") {
- result = {step};
+ break;
+ }
+ case Kind::Step: {
+ auto step = static_cast<const Step*>(e);
+ if (step->getInput()->getKind() == Kind::CompoundExpression) {
+ auto z = static_cast<CompoundExpressionBase*>(step->getInput().get());
+ if (z && z->getName() == "zoom") {
+ result = {step};
+ }
}
+ break;
+ }
+ default:
+ break;
}
if (result && result->is<ParsingError>()) {
diff --git a/src/mbgl/style/expression/interpolate.cpp b/src/mbgl/style/expression/interpolate.cpp
index a9bb3bf05e..852042382c 100644
--- a/src/mbgl/style/expression/interpolate.cpp
+++ b/src/mbgl/style/expression/interpolate.cpp
@@ -264,7 +264,7 @@ Interpolate::Interpolate(const type::Type& type_,
Interpolator interpolator_,
std::unique_ptr<Expression> input_,
std::map<double, std::unique_ptr<Expression>> stops_)
- : Expression(type_),
+ : Expression(Kind::Interpolate, type_),
interpolator(std::move(interpolator_)),
input(std::move(input_)),
stops(std::move(stops_)) {
diff --git a/src/mbgl/style/expression/is_constant.cpp b/src/mbgl/style/expression/is_constant.cpp
index b877ed550a..3b1f1aba8c 100644
--- a/src/mbgl/style/expression/is_constant.cpp
+++ b/src/mbgl/style/expression/is_constant.cpp
@@ -9,7 +9,8 @@ namespace expression {
constexpr static const char filter[] = "filter-";
bool isFeatureConstant(const Expression& expression) {
- if (auto e = dynamic_cast<const CompoundExpressionBase*>(&expression)) {
+ if (expression.getKind() == Kind::CompoundExpression) {
+ auto e = static_cast<const CompoundExpressionBase*>(&expression);
const std::string name = e->getName();
optional<std::size_t> parameterCount = e->getParameterCount();
if (name == "get" && parameterCount && *parameterCount == 1) {
@@ -28,7 +29,7 @@ bool isFeatureConstant(const Expression& expression) {
}
}
- if (dynamic_cast<const CollatorExpression*>(&expression)) {
+ if (expression.getKind() == Kind::CollatorExpression) {
// Although the results of a Collator expression with fixed arguments
// generally shouldn't change between executions, we can't serialize them
// as constant expressions because results change based on environment.
diff --git a/src/mbgl/style/expression/length.cpp b/src/mbgl/style/expression/length.cpp
index 258353ae4e..ad7a15675a 100644
--- a/src/mbgl/style/expression/length.cpp
+++ b/src/mbgl/style/expression/length.cpp
@@ -6,7 +6,7 @@ namespace style {
namespace expression {
Length::Length(std::unique_ptr<Expression> input_)
- : Expression(type::Number),
+ : Expression(Kind::Length, type::Number),
input(std::move(input_)) {
}
@@ -30,7 +30,8 @@ void Length::eachChild(const std::function<void(const Expression&)>& visit) cons
}
bool Length::operator==(const Expression& e) const {
- if (auto eq = dynamic_cast<const Length*>(&e)) {
+ if (e.getKind() == Kind::Length) {
+ auto eq = static_cast<const Length*>(&e);
return *eq->input == *input;
}
return false;
diff --git a/src/mbgl/style/expression/match.cpp b/src/mbgl/style/expression/match.cpp
index 59123c9812..340f1dab4d 100644
--- a/src/mbgl/style/expression/match.cpp
+++ b/src/mbgl/style/expression/match.cpp
@@ -18,7 +18,8 @@ void Match<T>::eachChild(const std::function<void(const Expression&)>& visit) co
template <typename T>
bool Match<T>::operator==(const Expression& e) const {
- if (auto rhs = dynamic_cast<const Match*>(&e)) {
+ if (e.getKind() == Kind::Match) {
+ auto rhs = static_cast<const Match*>(&e);
return (*input == *(rhs->input) &&
*otherwise == *(rhs->otherwise) &&
Expression::childrenEqual(branches, rhs->branches));
diff --git a/src/mbgl/style/expression/parsing_context.cpp b/src/mbgl/style/expression/parsing_context.cpp
index fe3102f158..a4c04b03b1 100644
--- a/src/mbgl/style/expression/parsing_context.cpp
+++ b/src/mbgl/style/expression/parsing_context.cpp
@@ -32,19 +32,21 @@ namespace style {
namespace expression {
bool isConstant(const Expression& expression) {
- if (auto varExpression = dynamic_cast<const Var*>(&expression)) {
+ if (expression.getKind() == Kind::Var) {
+ auto varExpression = static_cast<const Var*>(&expression);
return isConstant(*varExpression->getBoundExpression());
}
- if (auto compound = dynamic_cast<const CompoundExpressionBase*>(&expression)) {
+ if (expression.getKind() == Kind::CompoundExpression) {
+ auto compound = static_cast<const CompoundExpressionBase*>(&expression);
if (compound->getName() == "error") {
return false;
}
}
- bool isTypeAnnotation = dynamic_cast<const Coercion*>(&expression) ||
- dynamic_cast<const Assertion*>(&expression) ||
- dynamic_cast<const ArrayAssertion*>(&expression);
+ bool isTypeAnnotation = expression.getKind() == Kind::Coercion ||
+ expression.getKind() == Kind::Assertion ||
+ expression.getKind() == Kind::ArrayAssertion;
bool childrenConstant = true;
expression.eachChild([&](const Expression& child) {
@@ -58,7 +60,7 @@ bool isConstant(const Expression& expression) {
if (isTypeAnnotation) {
childrenConstant = childrenConstant && isConstant(child);
} else {
- childrenConstant = childrenConstant && dynamic_cast<const Literal*>(&child);
+ childrenConstant = childrenConstant && child.getKind() == Kind::Literal;
}
});
if (!childrenConstant) {
@@ -186,7 +188,7 @@ ParseResult ParsingContext::parse(const Convertible& value, TypeAnnotationOption
// If an expression's arguments are all constant, we can evaluate
// it immediately and replace it with a literal value in the
// parsed result.
- if (!dynamic_cast<Literal *>(parsed->get()) && isConstant(**parsed)) {
+ if ((*parsed)->getKind() != Kind::Literal && isConstant(**parsed)) {
EvaluationContext params(nullptr);
EvaluationResult evaluated((*parsed)->evaluate(params));
if (!evaluated) {
diff --git a/src/mbgl/style/expression/step.cpp b/src/mbgl/style/expression/step.cpp
index f42a2721a9..ee6055091e 100644
--- a/src/mbgl/style/expression/step.cpp
+++ b/src/mbgl/style/expression/step.cpp
@@ -11,7 +11,7 @@ namespace expression {
Step::Step(const type::Type& type_,
std::unique_ptr<Expression> input_,
std::map<double, std::unique_ptr<Expression>> stops_)
- : Expression(type_),
+ : Expression(Kind::Step, type_),
input(std::move(input_)),
stops(std::move(stops_))
{
@@ -57,7 +57,8 @@ void Step::eachStop(const std::function<void(double, const Expression&)>& visit)
}
bool Step::operator==(const Expression& e) const {
- if (auto rhs = dynamic_cast<const Step*>(&e)) {
+ if (e.getKind() == Kind::Step) {
+ auto rhs = static_cast<const Step*>(&e);
return *input == *(rhs->input) && Expression::childrenEqual(stops, rhs->stops);
}
return false;