# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("//bazel/cc_rules:defs.bzl", "cc_library")
load("//testing/fuzzing:rules.bzl", "cc_fuzz_test")

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

filegroup(
    name = "testdata",
    srcs = glob(["testdata/**/*.carbon"]),
)

cc_library(
    name = "context",
    srcs = [
        "action.cpp",
        "call.cpp",
        "class.cpp",
        "context.cpp",
        "control_flow.cpp",
        "convert.cpp",
        "decl_name_stack.cpp",
        "deduce.cpp",
        "deferred_definition_worklist.cpp",
        "eval.cpp",
        "eval_inst.cpp",
        "facet_type.cpp",
        "function.cpp",
        "generic.cpp",
        "global_init.cpp",
        "impl.cpp",
        "impl_lookup.cpp",
        "impl_validation.cpp",
        "import.cpp",
        "import_cpp.cpp",
        "import_ref.cpp",
        "inst.cpp",
        "inst_block_stack.cpp",
        "interface.cpp",
        "literal.cpp",
        "member_access.cpp",
        "merge.cpp",
        "modifiers.cpp",
        "name_component.cpp",
        "name_lookup.cpp",
        "name_ref.cpp",
        "operator.cpp",
        "pattern.cpp",
        "pattern_match.cpp",
        "pointer_dereference.cpp",
        "return.cpp",
        "subst.cpp",
        "thunk.cpp",
        "type.cpp",
        "type_completion.cpp",
        "type_structure.cpp",
    ],
    hdrs = [
        "action.h",
        "call.h",
        "class.h",
        "context.h",
        "control_flow.h",
        "convert.h",
        "decl_introducer_state.h",
        "decl_name_stack.h",
        "deduce.h",
        "deferred_definition_worklist.h",
        "diagnostic_helpers.h",
        "eval.h",
        "eval_inst.h",
        "facet_type.h",
        "function.h",
        "generic.h",
        "global_init.h",
        "impl.h",
        "impl_lookup.h",
        "impl_validation.h",
        "import.h",
        "import_cpp.h",
        "import_ref.h",
        "inst.h",
        "inst_block_stack.h",
        "interface.h",
        "keyword_modifier_set.h",
        "literal.h",
        "member_access.h",
        "merge.h",
        "modifiers.h",
        "name_component.h",
        "name_lookup.h",
        "name_ref.h",
        "operator.h",
        "param_and_arg_refs_stack.h",
        "pattern.h",
        "pattern_match.h",
        "pending_block.h",
        "pointer_dereference.h",
        "region_stack.h",
        "return.h",
        "subst.h",
        "thunk.h",
        "type.h",
        "type_completion.h",
        "type_structure.h",
    ],
    deps = [
        ":node_stack",
        "//common:array_stack",
        "//common:check",
        "//common:concepts",
        "//common:emplace_by_calling",
        "//common:find",
        "//common:growing_range",
        "//common:map",
        "//common:ostream",
        "//common:raw_string_ostream",
        "//common:set",
        "//common:vlog",
        "//toolchain/base:canonical_value_store",
        "//toolchain/base:index_base",
        "//toolchain/base:kind_switch",
        "//toolchain/base:value_store",
        "//toolchain/check:generic_region_stack",
        "//toolchain/check:scope_stack",
        "//toolchain/diagnostics:diagnostic_emitter",
        "//toolchain/diagnostics:format_providers",
        "//toolchain/lex:token_kind",
        "//toolchain/lex:tokenized_buffer",
        "//toolchain/parse:node_kind",
        "//toolchain/parse:tree",
        "//toolchain/sem_ir:clang_decl",
        "//toolchain/sem_ir:expr_info",
        "//toolchain/sem_ir:file",
        "//toolchain/sem_ir:formatter",
        "//toolchain/sem_ir:typed_insts",
        "@llvm-project//clang:ast",
        "@llvm-project//clang:basic",
        "@llvm-project//clang:frontend",
        "@llvm-project//clang:lex",
        "@llvm-project//clang:sema",
        "@llvm-project//clang:tooling",
        "@llvm-project//llvm:Support",
    ],
)

cc_library(
    name = "dump",
    srcs = ["dump.cpp"],
    deps = [
        ":context",
        "//common:check",
        "//common:ostream",
        "//common:raw_string_ostream",
        "//toolchain/lex:dump",
        "//toolchain/lex:tokenized_buffer",
        "//toolchain/parse:dump",
        "//toolchain/parse:tree",
        "//toolchain/sem_ir:dump",
        "//toolchain/sem_ir:file",
    ],
    # Always link dump methods.
    alwayslink = 1,
)

cc_library(
    name = "check",
    srcs = [
        "check.cpp",
        "check_unit.cpp",
        "check_unit.h",
        "handle.h",
        "node_id_traversal.cpp",
        "node_id_traversal.h",
    ] +
    # Glob handler files to avoid missing any.
    glob([
        "handle_*.cpp",
    ]),
    hdrs = ["check.h"],
    deps = [
        ":context",
        ":diagnostic_emitter",
        ":dump",
        ":scope_stack",
        "//common:check",
        "//common:error",
        "//common:find",
        "//common:growing_range",
        "//common:map",
        "//common:ostream",
        "//common:pretty_stack_trace_function",
        "//common:vlog",
        "//toolchain/base:fixed_size_value_store",
        "//toolchain/base:kind_switch",
        "//toolchain/base:shared_value_stores",
        "//toolchain/base:timings",
        "//toolchain/diagnostics:diagnostic_emitter",
        "//toolchain/diagnostics:format_providers",
        "//toolchain/lex:token_index",
        "//toolchain/lex:token_kind",
        "//toolchain/lex:tokenized_buffer",
        "//toolchain/parse:node_kind",
        "//toolchain/parse:tree",
        "//toolchain/sem_ir:absolute_node_id",
        "//toolchain/sem_ir:entry_point",
        "//toolchain/sem_ir:expr_info",
        "//toolchain/sem_ir:file",
        "//toolchain/sem_ir:formatter",
        "//toolchain/sem_ir:typed_insts",
        "@llvm-project//clang:frontend",
        "@llvm-project//llvm:Support",
    ],
)

cc_fuzz_test(
    name = "check_fuzzer",
    size = "small",
    srcs = ["check_fuzzer.cpp"],
    corpus = glob(["fuzzer_corpus/*"]),
    deps = [
        "//common:exe_path",
        "//testing/fuzzing:libfuzzer_header",
        "//toolchain/driver",
        "@llvm-project//llvm:Support",
    ],
)

cc_library(
    name = "generic_region_stack",
    srcs = ["generic_region_stack.cpp"],
    hdrs = ["generic_region_stack.h"],
    deps = [
        "//common:array_stack",
        "//common:check",
        "//common:map",
        "//common:ostream",
        "//common:vlog",
        "//toolchain/sem_ir:file",
        "//toolchain/sem_ir:typed_insts",
        "@llvm-project//llvm:Support",
    ],
)

cc_library(
    name = "node_stack",
    srcs = ["node_stack.cpp"],
    hdrs = ["node_stack.h"],
    deps = [
        "//common:check",
        "//common:ostream",
        "//common:vlog",
        "//toolchain/parse:node_kind",
        "//toolchain/parse:tree",
        "//toolchain/sem_ir:typed_insts",
        "@llvm-project//llvm:Support",
    ],
)

cc_library(
    name = "scope_stack",
    srcs = ["scope_stack.cpp"],
    hdrs = [
        "full_pattern_stack.h",
        "lexical_lookup.h",
        "scope_index.h",
        "scope_stack.h",
    ],
    deps = [
        "//common:array_stack",
        "//common:check",
        "//common:move_only",
        "//common:ostream",
        "//common:set",
        "//common:vlog",
        "//toolchain/base:canonical_value_store",
        "//toolchain/base:index_base",
        "//toolchain/base:shared_value_stores",
        "//toolchain/base:value_ids",
        "//toolchain/base:value_store",
        "//toolchain/sem_ir:file",
        "//toolchain/sem_ir:typed_insts",
        "@llvm-project//llvm:Support",
    ],
)

cc_library(
    name = "diagnostic_emitter",
    srcs = ["diagnostic_emitter.cpp"],
    hdrs = ["diagnostic_emitter.h"],
    deps = [
        ":context",
        "//common:raw_string_ostream",
        "//toolchain/diagnostics:diagnostic_emitter",
        "//toolchain/lex:token_index",
        "//toolchain/parse:tree",
        "//toolchain/sem_ir:absolute_node_id",
        "//toolchain/sem_ir:diagnostic_loc_converter",
        "//toolchain/sem_ir:file",
        "//toolchain/sem_ir:stringify",
        "//toolchain/sem_ir:typed_insts",
        "@llvm-project//llvm:Support",
    ],
)
