From 70809fd85f890e326b1d963eb6ace7b93be46d61 Mon Sep 17 00:00:00 2001 From: Anand Thakker Date: Mon, 10 Jul 2017 10:48:10 -0400 Subject: troubleshooting 'duplicate symbol' link error --- cmake/core-files.cmake | 5 +- include/mbgl/style/expression/expression.hpp | 30 +------ include/mbgl/style/expression/type.hpp | 129 +++++++++++++++++++++++++++ include/mbgl/style/expression/value.hpp | 53 +++++++++++ include/mbgl/style/function/type.hpp | 117 ------------------------ platform/node/src/node_expression.hpp | 1 - src/mbgl/style/expression/type.cpp | 26 ++++++ src/mbgl/style/function/type.cpp | 26 ------ 8 files changed, 214 insertions(+), 173 deletions(-) create mode 100644 include/mbgl/style/expression/type.hpp create mode 100644 include/mbgl/style/expression/value.hpp delete mode 100644 include/mbgl/style/function/type.hpp create mode 100644 src/mbgl/style/expression/type.cpp delete mode 100644 src/mbgl/style/function/type.cpp diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index d3eb02ac13..01fd8dd1dc 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -392,6 +392,9 @@ set(MBGL_CORE_FILES include/mbgl/style/expression/expression.hpp include/mbgl/style/expression/parse.hpp include/mbgl/style/expression/parsing_context.hpp + include/mbgl/style/expression/type.hpp + include/mbgl/style/expression/value.hpp + src/mbgl/style/expression/type.cpp # style/function include/mbgl/style/function/camera_function.hpp @@ -404,11 +407,9 @@ set(MBGL_CORE_FILES include/mbgl/style/function/identity_stops.hpp include/mbgl/style/function/interval_stops.hpp include/mbgl/style/function/source_function.hpp - include/mbgl/style/function/type.hpp src/mbgl/style/function/categorical_stops.cpp src/mbgl/style/function/expression.cpp src/mbgl/style/function/identity_stops.cpp - src/mbgl/style/function/type.cpp # style/layers include/mbgl/style/layers/background_layer.hpp diff --git a/include/mbgl/style/expression/expression.hpp b/include/mbgl/style/expression/expression.hpp index e36db1b3c7..99aaed8a14 100644 --- a/include/mbgl/style/expression/expression.hpp +++ b/include/mbgl/style/expression/expression.hpp @@ -6,8 +6,8 @@ #include #include #include -#include -#include +#include +#include #include #include @@ -20,20 +20,6 @@ class GeometryTileFeature; namespace style { namespace expression { -struct Value; -using ValueBase = variant< - NullValue, - float, - std::string, - mbgl::Color, - mapbox::util::recursive_wrapper>, - mapbox::util::recursive_wrapper>>; -struct Value : ValueBase { - using ValueBase::ValueBase; -}; - -constexpr NullValue Null = NullValue(); - struct EvaluationError { std::string message; }; @@ -102,17 +88,7 @@ public: template static ParseResult parse(const V& value, const ParsingContext& ctx) { const Value& parsedValue = parseValue(value); - const type::Type& type = parsedValue.match( - [&](float) -> type::Type { return type::Primitive::Number; }, - [&](const std::string&) -> type::Type { return type::Primitive::String; }, - [&](const mbgl::Color&) -> type::Type { return type::Primitive::Color; }, - [&](const NullValue&) -> type::Type { return type::Primitive::Null; }, - [&](const std::unordered_map&) -> type::Type { return type::Primitive::Object; }, - [&](const std::vector& arr) -> type::Type { - // TODO - return type::Array(type::Primitive::Value, arr.size()); - } - ); + const type::Type& type = typeOf(parsedValue); return std::make_unique(ctx.key(), type, parsedValue); } diff --git a/include/mbgl/style/expression/type.hpp b/include/mbgl/style/expression/type.hpp new file mode 100644 index 0000000000..72f36e2451 --- /dev/null +++ b/include/mbgl/style/expression/type.hpp @@ -0,0 +1,129 @@ +#pragma once + +#include +#include +#include + +namespace mbgl { +namespace style { +namespace expression { +namespace type { + +class Primitive; +class Variant; +class Array; +class NArgs; +class Typename; +class Lambda; + +using ValueType = variant< + Primitive, + Typename, + mapbox::util::recursive_wrapper, + mapbox::util::recursive_wrapper, + mapbox::util::recursive_wrapper>; + +using Type = variant< + Primitive, + Typename, + Variant, + Array, + NArgs, + Lambda>; + +template +std::string toString(const T& t); + +class Primitive { +public: + std::string getName() const { return name; } + + static Primitive Null; + static Primitive Number; + static Primitive String; + static Primitive Color; + static Primitive Object; + + // It's weird for this to be on Primitive. Where should it go? + static ValueType Value; + +private: + std::string name; + Primitive(std::string name_) : name(name_) {} +}; + +class Typename { +public: + Typename(std::string name_) : name(name_) {} + std::string getName() const { return name; } +private: + std::string name; +}; + +class Array { +public: + Array(ValueType itemType_) : itemType(itemType_) {} + Array(ValueType itemType_, std::size_t N_) : itemType(itemType_), N(N_) {} + std::string getName() const { + if (N) { + return "Array<" + toString(itemType) + ", " + std::to_string(*N) + ">"; + } else if (toString(itemType) == "Value") { + return "Array"; + } else { + return "Array<" + toString(itemType) + ">"; + } + } + +private: + ValueType itemType; + optional N; +}; + +class Variant { +public: + Variant(std::vector members_) : members(members_) {} + std::string getName() const { + return "variant"; + } + + std::vector getMembers() { + return members; + } + +private: + std::vector members; +}; + +class NArgs { +public: + NArgs(std::vector types_) : types(types_) {} + std::string getName() const { + return "nargs"; + } +private: + std::vector types; +}; + +class Lambda { +public: + Lambda(ValueType result_, std::vector params_) : + result(result_), + params(params_) + {} + std::string getName() const { + return "lambda"; + } + ValueType getResult() const { return result; } +private: + ValueType result; + std::vector params; +}; + +template +std::string toString(const T& t) { return t.match([&] (const auto& t) { return t.getName(); }); } + + +} // namespace type +} // namespace expression +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/expression/value.hpp b/include/mbgl/style/expression/value.hpp new file mode 100644 index 0000000000..0cac50c6ab --- /dev/null +++ b/include/mbgl/style/expression/value.hpp @@ -0,0 +1,53 @@ +#pragma once + +#include +#include +#include + +namespace mbgl { +namespace style { +namespace expression { + +struct Value; +using ValueBase = variant< + NullValue, + float, + std::string, + mbgl::Color, + mapbox::util::recursive_wrapper>, + mapbox::util::recursive_wrapper>>; +struct Value : ValueBase { + using ValueBase::ValueBase; +}; + +constexpr NullValue Null = NullValue(); + +type::Type typeOf(const Value& value) { + return value.match( + [&](float) -> type::Type { return type::Primitive::Number; }, + [&](const std::string&) -> type::Type { return type::Primitive::String; }, + [&](const mbgl::Color&) -> type::Type { return type::Primitive::Color; }, + [&](const NullValue&) -> type::Type { return type::Primitive::Null; }, + [&](const std::unordered_map&) -> type::Type { return type::Primitive::Object; }, + [&](const std::vector& arr) -> type::Type { + optional itemType; + for (const auto& item : arr) { + const auto& t = typeOf(item); + if (!itemType) { + itemType = {t}; + } else if (type::toString(*itemType) == type::toString(t)) { + continue; + } else { + itemType = {type::Primitive::Value}; + break; + } + } + + return type::Array(type::Primitive::Value, arr.size()); + } + ); +} + +} // namespace expression +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/function/type.hpp b/include/mbgl/style/function/type.hpp deleted file mode 100644 index 19897ac77f..0000000000 --- a/include/mbgl/style/function/type.hpp +++ /dev/null @@ -1,117 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace mbgl { -namespace style { -namespace expression { -namespace type { - -class Primitive; -class Variant; -class Array; -class NArgs; -class Typename; -class Lambda; - -using ValueType = variant< - Primitive, - Typename, - mapbox::util::recursive_wrapper, - mapbox::util::recursive_wrapper, - mapbox::util::recursive_wrapper>; - -using Type = variant< - Primitive, - Typename, - Variant, - Array, - NArgs, - Lambda>; - -class Primitive { -public: - std::string getName() const { return name; } - - static Primitive Null; - static Primitive Number; - static Primitive String; - static Primitive Color; - static Primitive Object; - - // It's weird for this to be on Primitive. Where should it go? - static ValueType Value; - -private: - std::string name; - Primitive(std::string name_) : name(name_) {} -}; - -class Typename { -public: - Typename(std::string name_) : name(name_) {} - std::string getName() const { return name; } -private: - std::string name; -}; - -class Array { -public: - Array(ValueType itemType_) : itemType(itemType_) {} - Array(ValueType itemType_, std::size_t N_) : itemType(itemType_), N(N_) {} - std::string getName() const { - return "array"; - } - -private: - ValueType itemType; - optional N; -}; - -class Variant { -public: - Variant(std::vector members_) : members(members_) {} - std::string getName() const { - return "variant"; - } - - std::vector getMembers() { - return members; - } - -private: - std::vector members; -}; - -class NArgs { -public: - NArgs(std::vector types_) : types(types_) {} - std::string getName() const { - return "nargs"; - } -private: - std::vector types; -}; - -class Lambda { -public: - Lambda(ValueType result_, std::vector params_) : - result(result_), - params(params_) - {} - std::string getName() const { - return "lambda"; - } - ValueType getResult() const { return result; } -private: - ValueType result; - std::vector params; -}; - - -} // namespace type -} // namespace expression -} // namespace style -} // namespace mbgl diff --git a/platform/node/src/node_expression.hpp b/platform/node/src/node_expression.hpp index 5cfc3b553e..e977b58288 100644 --- a/platform/node/src/node_expression.hpp +++ b/platform/node/src/node_expression.hpp @@ -11,7 +11,6 @@ #include #pragma GCC diagnostic pop -using namespace mbgl::style; using namespace mbgl::style::expression; namespace node_mbgl { diff --git a/src/mbgl/style/expression/type.cpp b/src/mbgl/style/expression/type.cpp new file mode 100644 index 0000000000..2b7f78a8d8 --- /dev/null +++ b/src/mbgl/style/expression/type.cpp @@ -0,0 +1,26 @@ +#include + +namespace mbgl { +namespace style { +namespace expression { +namespace type { + +Primitive Primitive::Null = {"Null"}; +Primitive Primitive::String = {"String"}; +Primitive Primitive::Number = {"Number"}; +Primitive Primitive::Color = {"Color"}; +Primitive Primitive::Object = {"Object"}; + +// Need to add Array(Types::Value) to the member list somehow... + ValueType Primitive::Value = Variant({ + Primitive::Null, + Primitive::String, + Primitive::Number, + Primitive::Color, + Primitive::Object +}); + +} // namespace type +} // namespace expression +} // namespace style +} // namespace mbgl diff --git a/src/mbgl/style/function/type.cpp b/src/mbgl/style/function/type.cpp deleted file mode 100644 index 5e1a95433f..0000000000 --- a/src/mbgl/style/function/type.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include - -namespace mbgl { -namespace style { -namespace expression { -namespace type { - -Primitive Primitive::Null = {"Null"}; -Primitive Primitive::String = {"String"}; -Primitive Primitive::Number = {"Number"}; -Primitive Primitive::Color = {"Color"}; -Primitive Primitive::Object = {"Object"}; - -// Need to add Array(Types::Value) to the member list somehow... - ValueType Primitive::Value = Variant({ - Primitive::Null, - Primitive::String, - Primitive::Number, - Primitive::Color, - Primitive::Object -}); - -} // namespace type -} // namespace expression -} // namespace style -} // namespace mbgl -- cgit v1.2.1