Split Semantics into Check and SemIR namespaces (#3138)

Splits IR files into SemIR, and logic files into Check. These will be
split into separate directories as part of a later move; the namespaces
are being done first in order to vet the switch, and hopefully make
conflicts a little easier to manage due to the substantial renames.

A lot of this is just automated removal of Semantics prefixes from
names, adding namespace references where needed. A few special-cases
are:

- SemanticsIR -> SemIR::File
- A few things were discussed, like Unit, CompileUnit, or CompiledUnit.
Unit was too vague for chandlerc, and I thought CompileUnit might lead
to incorrect inferences (CompilationUnit would be more precise, but
typically written as SemIR::CompilationUnit which is pretty long). File
seemed to be a short name that we could agree on.
- SemanticsIRFormatter -> SemIR::Formatter
- FormatSemanticsIR -> SemIR::FormatFile
- SemanticsFileTest -> CheckFileTest
- It remains in the Testing namespace, where just "FileTest" might be
too broad a name.
- SemanticsDeclarationNameStack::Context ->
Check::DeclarationNameStack::NameContext
  - This avoids a Check::Context name shadowing.

Changes check_internal.h to include ostream.h to improve finding of
Print/operator<< (otherwise it didn't compile).

This is part of #3070
This commit is contained in:
Jon Ross-Perkins
2023-08-23 22:51:23 +00:00
committed by GitHub
parent b2db2ca7cf
commit 67da700dd5
53 changed files with 1337 additions and 1466 deletions
@@ -5,15 +5,14 @@
#include "toolchain/semantics/semantics_context.h"
#include "toolchain/semantics/semantics_node.h"
namespace Carbon {
namespace Carbon::Check {
auto SemanticsHandleIfConditionStart(SemanticsContext& /*context*/,
ParseTree::Node /*parse_node*/) -> bool {
auto HandleIfConditionStart(Context& /*context*/,
ParseTree::Node /*parse_node*/) -> bool {
return true;
}
auto SemanticsHandleIfCondition(SemanticsContext& context,
ParseTree::Node parse_node) -> bool {
auto HandleIfCondition(Context& context, ParseTree::Node parse_node) -> bool {
// Convert the condition to `bool`.
auto cond_value_id = context.node_stack().PopExpression();
cond_value_id = context.ImplicitAsBool(parse_node, cond_value_id);
@@ -35,8 +34,8 @@ auto SemanticsHandleIfCondition(SemanticsContext& context,
return true;
}
auto SemanticsHandleIfStatementElse(SemanticsContext& context,
ParseTree::Node parse_node) -> bool {
auto HandleIfStatementElse(Context& context, ParseTree::Node parse_node)
-> bool {
context.node_stack().PopAndDiscardSoloParseNode<ParseNodeKind::IfCondition>();
// Switch to emitting the else block.
@@ -46,8 +45,7 @@ auto SemanticsHandleIfStatementElse(SemanticsContext& context,
return true;
}
auto SemanticsHandleIfStatement(SemanticsContext& context,
ParseTree::Node parse_node) -> bool {
auto HandleIfStatement(Context& context, ParseTree::Node parse_node) -> bool {
// Either the then or else block, depending on whether there's an `else` node
// on the top of the node stack.
auto sub_block_id = context.node_block_stack().PopForAdd();
@@ -60,14 +58,14 @@ auto SemanticsHandleIfStatement(SemanticsContext& context,
.PopAndDiscardSoloParseNode<ParseNodeKind::IfCondition>();
context.AddNodeToBlock(
sub_block_id,
SemanticsNode::Branch::Make(parse_node,
context.node_block_stack().PeekForAdd()));
SemIR::Node::Branch::Make(parse_node,
context.node_block_stack().PeekForAdd()));
break;
}
case ParseNodeKind::IfStatementElse: {
// Branch from the then and else blocks to a new resumption block.
SemanticsNodeBlockId then_block_id =
SemIR::NodeBlockId then_block_id =
context.node_stack().Pop<ParseNodeKind::IfStatementElse>();
context.AddConvergenceBlockAndPush(parse_node,
{then_block_id, sub_block_id});
@@ -83,4 +81,4 @@ auto SemanticsHandleIfStatement(SemanticsContext& context,
return true;
}
} // namespace Carbon
} // namespace Carbon::Check