mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-26 11:31:17 +00:00
For parameters (and in the future, arguments too; generally comma-separated lists) track two node blocks: 1. param_ir: The complete IR. 2. param_refs: Nodes within the IR that are the "root" parameter. param_refs should allow quick counting of the # of parameters, and more efficient comparison of call args with function parameters. param_ir should be necessary to generate the actual signature. In order to construct this, this refactors the node_block_stack into its own class, which is reused in params_stack. These carry references to the underlying SmallVector for lazy modification in order to avoid a dependency cycle with SemanticsIR (also see notes on empty node blocks below). When finalized, the block pair is pushed onto finished_params_stack. That's because node_stack only has space for one thing, and this is two things -- so I'm essentially choosing a trade-off of adding another stack in order to avoid consuming more space in the expectation that most parse nodes have 0 or 1 things to return, and 2 will be very rare. As factored, this currently consolidates most empty node blocks into a single canonical empty node block. This is because I think empty blocks, i.e. `()`, will be very common. In order to achieve this, SemanticsNodeBlockStack does lazy creation. An alternative approach would have been to use 1 node block per parameter. We decided against this in order to reduce the number of vectors being created.
107 lines
2.8 KiB
Python
107 lines
2.8 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
|
|
|
|
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 = ["//toolchain/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 = ["//toolchain/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/parser:parse_tree",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "semantics_node_block_stack",
|
|
srcs = ["semantics_node_block_stack.cpp"],
|
|
hdrs = ["semantics_node_block_stack.h"],
|
|
deps = [
|
|
":semantics_node",
|
|
"//common:check",
|
|
"//common:ostream",
|
|
"//common:vlog",
|
|
"@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_parse_tree_handler.cpp",
|
|
],
|
|
hdrs = [
|
|
"semantics_ir.h",
|
|
"semantics_parse_tree_handler.h",
|
|
],
|
|
deps = [
|
|
":semantics_builtin_kind",
|
|
":semantics_node",
|
|
":semantics_node_block_stack",
|
|
":semantics_node_stack",
|
|
"//common:check",
|
|
"//common:ostream",
|
|
"//common:vlog",
|
|
"//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 = [
|
|
":semantics_ir",
|
|
"//common:gtest_main",
|
|
"//toolchain/common:yaml_test_helpers",
|
|
"//toolchain/diagnostics:diagnostic_emitter",
|
|
"//toolchain/lexer:tokenized_buffer",
|
|
"@com_google_googletest//:gtest",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|