Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Port Collator expressions to core/iOS/Android/Qt #11869

Merged
merged 8 commits into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ xcuserdata
test/fixtures/api/assets.zip
test/fixtures/storage/assets.zip
/.circle-week
/vendor/.cache

# Generated list files from code generation
/scripts/generate-cmake-files.list
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ endif(WITH_COVERAGE)
set(CMAKE_CONFIGURATION_TYPES Debug Release RelWithDebugInfo Sanitize)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -ftemplate-depth=1024 -fPIC -fvisibility=hidden -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wno-variadic-macros -Wno-unknown-pragmas")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -fvisibility=hidden -Wall -Wextra -Wshadow -Wno-variadic-macros -Wno-unknown-pragmas")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -fPIC -fvisibility=hidden -Wall -Wextra -Wshadow -Wno-variadic-macros -Wno-unknown-pragmas")

if (WITH_ERROR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
Expand Down
5 changes: 5 additions & 0 deletions cmake/core-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ set(MBGL_CORE_FILES
include/mbgl/style/expression/check_subtype.hpp
include/mbgl/style/expression/coalesce.hpp
include/mbgl/style/expression/coercion.hpp
include/mbgl/style/expression/collator.hpp
include/mbgl/style/expression/collator_expression.hpp
include/mbgl/style/expression/compound_expression.hpp
include/mbgl/style/expression/dsl.hpp
include/mbgl/style/expression/equals.hpp
Expand All @@ -473,6 +475,7 @@ set(MBGL_CORE_FILES
src/mbgl/style/expression/check_subtype.cpp
src/mbgl/style/expression/coalesce.cpp
src/mbgl/style/expression/coercion.cpp
src/mbgl/style/expression/collator_expression.cpp
src/mbgl/style/expression/compound_expression.cpp
src/mbgl/style/expression/dsl.cpp
src/mbgl/style/expression/equals.cpp
Expand Down Expand Up @@ -614,6 +617,8 @@ set(MBGL_CORE_FILES
src/mbgl/text/glyph_pbf.cpp
src/mbgl/text/glyph_pbf.hpp
src/mbgl/text/glyph_range.hpp
src/mbgl/text/language_tag.cpp
src/mbgl/text/language_tag.hpp
src/mbgl/text/local_glyph_rasterizer.hpp
src/mbgl/text/placement.cpp
src/mbgl/text/placement.hpp
Expand Down
Empty file added cmake/empty.cpp
Empty file.
19 changes: 19 additions & 0 deletions cmake/mbgl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,25 @@ function(create_source_groups target)
endforeach()
endfunction()

# Creates a library target for a vendored dependency
function(add_vendor_target NAME TYPE)
add_library(${NAME} ${TYPE} cmake/empty.cpp)
set(INCLUDE_TYPE "INTERFACE")
set(SOURCE_TYPE "INTERFACE")
if (TYPE STREQUAL "STATIC" OR TYPE STREQUAL "SHARED")
set(INCLUDE_TYPE "PUBLIC")
set(SOURCE_TYPE "PRIVATE")
set_target_properties(${NAME} PROPERTIES SOURCES "")
endif()
set_target_properties(${NAME} PROPERTIES INTERFACE_SOURCES "")
file(STRINGS vendor/${NAME}/files.txt FILES)
foreach(FILE IN LISTS FILES)
target_sources(${NAME} ${SOURCE_TYPE} "${CMAKE_SOURCE_DIR}/vendor/${NAME}/${FILE}")
endforeach()
target_include_directories(${NAME} ${INCLUDE_TYPE} vendor/${NAME}/include)
create_source_groups(${NAME})
endfunction()

# This little macro lets you set any XCode specific property
macro(set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE)
set_property(TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE})
Expand Down
5 changes: 5 additions & 0 deletions cmake/nunicode.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_vendor_target(nunicode STATIC)

target_compile_definitions(nunicode
PRIVATE "-DNU_BUILD_STATIC"
)
1 change: 1 addition & 0 deletions cmake/test-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ set(MBGL_TEST_FILES
test/text/cross_tile_symbol_index.test.cpp
test/text/glyph_manager.test.cpp
test/text/glyph_pbf.test.cpp
test/text/language_tag.test.cpp
test/text/local_glyph_rasterizer.test.cpp
test/text/quads.test.cpp

Expand Down
29 changes: 29 additions & 0 deletions include/mbgl/style/expression/collator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <mbgl/util/feature.hpp>
#include <mbgl/util/optional.hpp>

#include <string>
#include <memory>

namespace mbgl {
namespace style {
namespace expression {

class Collator {
public:
Collator(bool caseSensitive, bool diacriticSensitive, optional<std::string> locale = {});

bool operator==(const Collator& other) const;

int compare(const std::string& lhs, const std::string& rhs) const;

std::string resolvedLocale() const;
private:
class Impl;
std::shared_ptr<Impl> impl;
};

} // namespace expression
} // namespace style
} // namespace mbgl
44 changes: 44 additions & 0 deletions include/mbgl/style/expression/collator_expression.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include <mbgl/style/expression/expression.hpp>
#include <mbgl/style/expression/parsing_context.hpp>
#include <mbgl/style/conversion.hpp>

#include <memory>

namespace mbgl {
namespace style {
namespace expression {

class CollatorExpression : public Expression {
public:
CollatorExpression(std::unique_ptr<Expression> caseSensitive,
std::unique_ptr<Expression> diacriticSensitive,
optional<std::unique_ptr<Expression>> locale);

EvaluationResult evaluate(const EvaluationContext&) const override;
static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&);

void eachChild(const std::function<void(const Expression&)>&) const override;

bool operator==(const Expression& e) const override;

std::vector<optional<Value>> possibleOutputs() const override {
// Technically the set of possible outputs is the combinatoric set of Collators produced
// by all possibleOutputs of locale/caseSensitive/diacriticSensitive
// But for the primary use of Collators in comparison operators, we ignore the Collator's
// possibleOutputs anyway, so we can get away with leaving this undefined for now.
return { nullopt };
}

mbgl::Value serialize() const override;
std::string getOperator() const override { return "collator"; }
private:
std::unique_ptr<Expression> caseSensitive;
std::unique_ptr<Expression> diacriticSensitive;
optional<std::unique_ptr<Expression>> locale;
};

} // namespace expression
} // namespace style
} // namespace mbgl
4 changes: 3 additions & 1 deletion include/mbgl/style/expression/equals.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <mbgl/style/expression/collator_expression.hpp>
#include <mbgl/style/expression/expression.hpp>
#include <mbgl/style/expression/parsing_context.hpp>
#include <mbgl/style/conversion.hpp>
Expand All @@ -12,7 +13,7 @@ namespace expression {

class Equals : public Expression {
public:
Equals(std::unique_ptr<Expression> lhs, std::unique_ptr<Expression> rhs, bool negate);
Equals(std::unique_ptr<Expression> lhs, std::unique_ptr<Expression> rhs, optional<std::unique_ptr<Expression>> collator, bool negate);

static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&);

Expand All @@ -25,6 +26,7 @@ class Equals : public Expression {
private:
std::unique_ptr<Expression> lhs;
std::unique_ptr<Expression> rhs;
optional<std::unique_ptr<Expression>> collator;
bool negate;
};

Expand Down
8 changes: 8 additions & 0 deletions include/mbgl/style/expression/type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ struct ValueType {
std::string getName() const { return "value"; }
bool operator==(const ValueType&) const { return true; }
};

struct CollatorType {
constexpr CollatorType() {}; // NOLINT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why the NOLINT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a complaint about not using the default constructor (which actually wouldn't compile on all platforms). I never figured out why -- I wonder if it has some magic relation to being ordered last in the variant declaration? I'll try switching that with ErrorType and see what happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, still get the error without the // NOLINT:

/src/build/linux-x86_64/Debug/../../../include/mbgl/style/expression/type.hpp:65:15: warning: use '= default' to define a trivial default constructor [modernize-use-equals-default]
    constexpr CollatorType() {};
              ^
                             = default;

std::string getName() const { return "collator"; }
bool operator==(const CollatorType&) const { return true; }
};

constexpr NullType Null;
constexpr NumberType Number;
Expand All @@ -68,6 +74,7 @@ constexpr BooleanType Boolean;
constexpr ColorType Color;
constexpr ValueType Value;
constexpr ObjectType Object;
constexpr CollatorType Collator;
constexpr ErrorType Error;

struct Array;
Expand All @@ -81,6 +88,7 @@ using Type = variant<
ObjectType,
ValueType,
mapbox::util::recursive_wrapper<Array>,
CollatorType,
ErrorType>;

struct Array {
Expand Down
2 changes: 2 additions & 0 deletions include/mbgl/style/expression/value.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <mbgl/style/expression/collator.hpp>
#include <mbgl/style/expression/type.hpp>
#include <mbgl/style/position.hpp>
#include <mbgl/style/types.hpp>
Expand All @@ -23,6 +24,7 @@ using ValueBase = variant<
double,
std::string,
Color,
Collator,
mapbox::util::recursive_wrapper<std::vector<Value>>,
mapbox::util::recursive_wrapper<std::unordered_map<std::string, Value>>>;
struct Value : ValueBase {
Expand Down
10 changes: 7 additions & 3 deletions platform/android/config.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_definitions(-DMBGL_USE_GLES2=1)
include(cmake/test-files.cmake)
include(cmake/nunicode.cmake)

# Build thin archives.
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> cruT <TARGET> <LINK_FLAGS> <OBJECTS>")
Expand All @@ -21,7 +22,6 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -Wl,--ve
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -Wl,--version-script=${CMAKE_SOURCE_DIR}/platform/android/version-script")

mason_use(jni.hpp VERSION 3.0.0 HEADER_ONLY)
mason_use(nunicode VERSION 1.7.1)
mason_use(sqlite VERSION 3.14.2)
mason_use(gtest VERSION 1.8.0)
mason_use(icu VERSION 58.1-min-size)
Expand All @@ -37,13 +37,17 @@ macro(mbgl_platform_core)
PRIVATE platform/android/src/timer.cpp

# Misc
PRIVATE platform/android/src/text/local_glyph_rasterizer_jni.hpp
PRIVATE platform/android/src/text/collator.cpp
PRIVATE platform/android/src/text/collator_jni.hpp
PRIVATE platform/android/src/text/local_glyph_rasterizer.cpp
PRIVATE platform/android/src/text/local_glyph_rasterizer_jni.hpp
PRIVATE platform/android/src/logging_android.cpp
PRIVATE platform/android/src/thread.cpp
PRIVATE platform/default/string_stdlib.cpp
PRIVATE platform/default/bidi.cpp
PRIVATE platform/default/thread_local.cpp
PRIVATE platform/default/unaccent.cpp
PRIVATE platform/default/unaccent.hpp
PRIVATE platform/default/utf.cpp

# Image handling
Expand Down Expand Up @@ -81,13 +85,13 @@ macro(mbgl_platform_core)
PRIVATE platform/android
)

target_add_mason_package(mbgl-core PUBLIC nunicode)
target_add_mason_package(mbgl-core PUBLIC geojson)
target_add_mason_package(mbgl-core PUBLIC jni.hpp)
target_add_mason_package(mbgl-core PUBLIC rapidjson)
target_add_mason_package(mbgl-core PRIVATE icu)

target_link_libraries(mbgl-core
PRIVATE nunicode
PUBLIC -llog
PUBLIC -landroid
PUBLIC -ljnigraphics
Expand Down
3 changes: 3 additions & 0 deletions platform/android/src/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "style/light.hpp"
#include "snapshotter/map_snapshotter.hpp"
#include "snapshotter/map_snapshot.hpp"
#include "text/collator_jni.hpp"
#include "text/local_glyph_rasterizer_jni.hpp"
#include "java/lang.hpp"

Expand Down Expand Up @@ -188,6 +189,8 @@ void registerNatives(JavaVM *vm) {

// text
LocalGlyphRasterizer::registerNative(env);
Locale::registerNative(env);
Collator::registerNative(env);
}

} // namespace android
Expand Down
Loading