mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 14:41:06 +01:00
This started with cleaning up the remaining Name/expression type punning in the node stack, and grew. I'm factoring out a class because we've previously expressed the desire to factor logic out of SemanticsContext where possible, and this seemed like a reasonable cut. NameExpression as the first node as a QualifiedExpression allows the qualifier handling to consider Name in one less spot, an incremental simplification. However, the additional complexity caused by this makes me split ApplyNameQualifier/ApplyExpressionQualifier in order to avoid repeat checks of the parse node's kind. The logic is still largely shared, thus a couple helper functions. I think this is all fairly well structured in the isolated class. I can see that we may want to avoid passing SemanticsContext as an argument in the future if it elides a step of lookup.
138 lines
3.6 KiB
Python
138 lines
3.6 KiB
Python
# 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/sh_run:rules.bzl", "glob_sh_run")
|
|
load("//testing/file_test:rules.bzl", "file_test")
|
|
|
|
package(default_visibility = ["//visibility:public"])
|
|
|
|
cc_library(
|
|
name = "semantics_builtin_kind",
|
|
srcs = ["semantics_builtin_kind.cpp"],
|
|
hdrs = ["semantics_builtin_kind.h"],
|
|
textual_hdrs = ["semantics_builtin_kind.def"],
|
|
deps = ["//common:enum_base"],
|
|
)
|
|
|
|
cc_library(
|
|
name = "semantics_node_kind",
|
|
srcs = ["semantics_node_kind.cpp"],
|
|
hdrs = ["semantics_node_kind.h"],
|
|
textual_hdrs = ["semantics_node_kind.def"],
|
|
deps = ["//common:enum_base"],
|
|
)
|
|
|
|
cc_library(
|
|
name = "semantics_node",
|
|
srcs = ["semantics_node.cpp"],
|
|
hdrs = ["semantics_node.h"],
|
|
deps = [
|
|
":semantics_builtin_kind",
|
|
":semantics_node_kind",
|
|
"//common:check",
|
|
"//common:ostream",
|
|
"//toolchain/common:index_base",
|
|
"//toolchain/parser:parse_tree",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "semantics_node_stack",
|
|
srcs = ["semantics_node_stack.cpp"],
|
|
hdrs = ["semantics_node_stack.h"],
|
|
deps = [
|
|
":semantics_node",
|
|
"//common:check",
|
|
"//common:ostream",
|
|
"//common:vlog",
|
|
"//toolchain/parser:parse_node_kind",
|
|
"//toolchain/parser:parse_tree",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "semantics_ir",
|
|
srcs = [
|
|
"semantics_ir.cpp",
|
|
"semantics_context.cpp",
|
|
"semantics_node_block_stack.cpp",
|
|
"semantics_declaration_name_stack.cpp",
|
|
] +
|
|
# Glob handler files to avoid missing anyway.
|
|
glob([
|
|
"semantics_handle*.cpp",
|
|
]),
|
|
hdrs = [
|
|
"semantics_context.h",
|
|
"semantics_declaration_name_stack.h",
|
|
"semantics_ir.h",
|
|
"semantics_node_block_stack.h",
|
|
],
|
|
deps = [
|
|
":semantics_builtin_kind",
|
|
":semantics_node",
|
|
":semantics_node_stack",
|
|
"//common:check",
|
|
"//common:ostream",
|
|
"//common:vlog",
|
|
"//toolchain/common:pretty_stack_trace_function",
|
|
"//toolchain/diagnostics:diagnostic_kind",
|
|
"//toolchain/lexer:numeric_literal",
|
|
"//toolchain/lexer:token_kind",
|
|
"//toolchain/lexer:tokenized_buffer",
|
|
"//toolchain/parser:parse_node_kind",
|
|
"//toolchain/parser:parse_tree",
|
|
"//toolchain/parser:parse_tree_node_location_translator",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_test(
|
|
name = "semantics_ir_test",
|
|
size = "small",
|
|
srcs = ["semantics_ir_test.cpp"],
|
|
deps = [
|
|
"//testing/util:gtest_main",
|
|
"//testing/util:test_raw_ostream",
|
|
"//toolchain/common:yaml_test_helpers",
|
|
"//toolchain/driver",
|
|
"@com_google_googletest//:gtest",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
file_test(
|
|
name = "semantics_file_test",
|
|
srcs = ["semantics_file_test.cpp"],
|
|
tests = glob(["testdata/**/*.carbon"]),
|
|
deps = [
|
|
"//toolchain/driver:driver_file_test_base",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
glob_sh_run(
|
|
args = [
|
|
"$(location //toolchain/driver:carbon)",
|
|
"dump",
|
|
"semantics-ir",
|
|
],
|
|
data = ["//toolchain/driver:carbon"],
|
|
file_exts = ["carbon"],
|
|
)
|
|
|
|
glob_sh_run(
|
|
args = [
|
|
"$(location //toolchain/driver:carbon)",
|
|
"-v",
|
|
"dump",
|
|
"semantics-ir",
|
|
],
|
|
data = ["//toolchain/driver:carbon"],
|
|
file_exts = ["carbon"],
|
|
run_ext = "verbose",
|
|
)
|