# Copyright 2010-2021, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
#     * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#     * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

load(
    "//:build_defs.bzl",
    "mozc_cc_binary",
    "mozc_cc_library",
    "mozc_cc_test",
)

package(default_visibility = ["//visibility:private"])

mozc_cc_library(
    name = "query",
    hdrs = ["query.h"],
    visibility = [
        "//:__subpackages__",
        "//engine:__pkg__",
        "//prediction:__pkg__",
    ],
)

mozc_cc_library(
    name = "composer",
    srcs = ["composer.cc"],
    hdrs = ["composer.h"],
    visibility = [
        "//:__subpackages__",
        "//engine:__pkg__",
        "//request:__pkg__",
        "//session:__pkg__",
    ],
    deps = [
        ":composition",
        ":composition_input",
        ":key_event_util",
        ":mode_switching_handler",
        ":table",
        ":transliterators",
        "//base:clock",
        "//base:japanese_util",
        "//base:util",
        "//base:vlog",
        "//base/container:flat_multimap",
        "//base/strings:assign",
        "//base/strings:unicode",
        "//config:character_form_manager",
        "//config:config_handler",
        "//protocol:commands_cc_proto",
        "//protocol:config_cc_proto",
        "//transliteration",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/base:no_destructor",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:span",
    ],
)

mozc_cc_test(
    name = "composer_test",
    size = "small",
    srcs = ["composer_test.cc"],
    deps = [
        ":composer",
        ":key_parser",
        ":table",
        "//base:clock_mock",
        "//base:util",
        "//config:character_form_manager",
        "//config:config_handler",
        "//protocol:commands_cc_proto",
        "//protocol:config_cc_proto",
        "//testing:gunit_main",
        "//testing:test_peer",
        "//transliteration",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:span",
    ],
)

mozc_cc_library(
    name = "table",
    srcs = ["table.cc"],
    hdrs = ["table.h"],
    visibility = [
        "//:__subpackages__",
        "//converter:__pkg__",
        "//engine:__pkg__",
        "//prediction:__pkg__",
        "//rewriter:__pkg__",
        "//session:__pkg__",
    ],
    deps = [
        ":special_key",
        "//base:config_file_stream",
        "//base:hash",
        "//base:util",
        "//base/container:trie",
        "//protocol:commands_cc_proto",
        "//protocol:config_cc_proto",
        "@com_google_absl//absl/base:no_destructor",
        "@com_google_absl//absl/base:nullability",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/hash",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/strings",
    ],
)

mozc_cc_binary(
    name = "composer_main",
    srcs = ["composer_main.cc"],
    deps = [
        ":composer",
        ":table",
        "//base:init_mozc",
        "//protocol:commands_cc_proto",
        "//protocol:config_cc_proto",
        "//transliteration",
        "@com_google_absl//absl/flags:flag",
    ],
)

mozc_cc_test(
    name = "table_test",
    size = "small",
    srcs = ["table_test.cc"],
    deps = [
        ":special_key",
        ":table",
        "//config:config_handler",
        "//data_manager/testing:mock_data_manager",
        "//protocol:commands_cc_proto",
        "//protocol:config_cc_proto",
        "//testing:gunit_main",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/strings",
    ],
)

mozc_cc_library(
    name = "key_event_util",
    srcs = ["key_event_util.cc"],
    hdrs = ["key_event_util.h"],
    visibility = [
        "//client:__pkg__",
        "//session:__pkg__",
        "//win32/base:__pkg__",
    ],
    deps = [
        "//protocol:commands_cc_proto",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
    ],
)

mozc_cc_test(
    name = "key_event_util_test",
    size = "small",
    srcs = ["key_event_util_test.cc"],
    deps = [
        ":key_event_util",
        ":key_parser",
        "//protocol:commands_cc_proto",
        "//testing:gunit_main",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/strings:string_view",
    ],
)

mozc_cc_library(
    name = "key_parser",
    srcs = ["key_parser.cc"],
    hdrs = ["key_parser.h"],
    visibility = [
        "//client:__pkg__",
        "//gui/config_dialog:__pkg__",
        "//session:__pkg__",
        "//unix/emacs:__pkg__",
    ],
    deps = [
        "//base:util",
        "//base/container:flat_map",
        "//base/container:flat_multimap",
        "//protocol:commands_cc_proto",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

mozc_cc_test(
    name = "key_parser_test",
    size = "small",
    srcs = ["key_parser_test.cc"],
    deps = [
        ":key_event_util",
        ":key_parser",
        "//protocol:commands_cc_proto",
        "//testing:gunit_main",
        "@com_google_absl//absl/strings:string_view",
    ],
)

mozc_cc_library(
    name = "char_chunk",
    srcs = [
        "char_chunk.cc",
    ],
    hdrs = ["char_chunk.h"],
    deps = [
        ":composition_input",
        ":special_key",
        ":table",
        ":transliterators",
        "//base:thread",
        "//base:util",
        "//base/strings:assign",
        "//base/strings:unicode",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

mozc_cc_library(
    name = "transliterators",
    srcs = [
        "transliterators.cc",
    ],
    hdrs = ["transliterators.h"],
    deps = [
        "//base:japanese_util",
        "//base:singleton",
        "//base:util",
        "//base:vlog",
        "//base/strings:assign",
        "//config:character_form_manager",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/strings",
    ],
)

mozc_cc_test(
    name = "transliterators_test",
    size = "small",
    srcs = [
        "transliterators_test.cc",
    ],
    deps = [
        ":transliterators",
        "//testing:gunit_main",
    ],
)

mozc_cc_test(
    name = "char_chunk_test",
    size = "small",
    srcs = [
        "char_chunk_test.cc",
    ],
    deps = [
        ":char_chunk",
        ":composition_input",
        ":table",
        ":transliterators",
        "//testing:gunit_main",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

mozc_cc_library(
    name = "composition_input",
    srcs = ["composition_input.cc"],
    hdrs = ["composition_input.h"],
    deps = [
        ":key_parser",
        ":table",
        "//base:util",
        "//base/protobuf:repeated_ptr_field",
        "//base/strings:assign",
        "//protocol:commands_cc_proto",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/strings",
    ],
)

mozc_cc_test(
    name = "composition_input_test",
    size = "small",
    srcs = [
        "composition_input_test.cc",
    ],
    deps = [
        ":composition_input",
        ":table",
        "//base/protobuf:repeated_ptr_field",
        "//protocol:commands_cc_proto",
        "//testing:gunit_main",
    ],
)

mozc_cc_library(
    name = "composition",
    srcs = [
        "composition.cc",
    ],
    hdrs = ["composition.h"],
    deps = [
        ":char_chunk",
        ":composition_input",
        ":table",
        ":transliterators",
        "//base:util",
        "//base:vlog",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

mozc_cc_test(
    name = "composition_test",
    size = "small",
    srcs = [
        "composition_test.cc",
    ],
    deps = [
        ":char_chunk",
        ":composition",
        ":composition_input",
        ":table",
        ":transliterators",
        "//testing:gunit_main",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:string_view",
    ],
)

mozc_cc_binary(
    name = "composition_main",
    srcs = ["composition_main.cc"],
    deps = [
        ":composition",
        ":table",
        "//base:init_mozc",
        "@com_google_absl//absl/flags:flag",
    ],
)

mozc_cc_library(
    name = "mode_switching_handler",
    srcs = ["mode_switching_handler.cc"],
    hdrs = ["mode_switching_handler.h"],
    deps = [
        "//base:singleton",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/strings",
    ],
)

mozc_cc_test(
    name = "mode_switching_handler_test",
    size = "small",
    srcs = ["mode_switching_handler_test.cc"],
    deps = [
        ":mode_switching_handler",
        "//testing:gunit_main",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

mozc_cc_library(
    name = "special_key",
    srcs = ["special_key.cc"],
    hdrs = ["special_key.h"],
    deps = [
        "//base:util",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/functional:any_invocable",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/strings",
    ],
)

mozc_cc_test(
    name = "special_key_test",
    srcs = ["special_key_test.cc"],
    deps = [
        ":special_key",
        ":table",
        "//testing:gunit_main",
    ],
)
