Files
carbon-lang/toolchain/check/handle_array.cpp
T
Jon Ross-Perkins 86a7c9ff45 Rename parse_node -> node_id (#3760)
This was previously discussed at
https://discord.com/channels/655572317891461132/655578254970716160/1209975051588210729.
I'm initiating this mainly because we typically use "id" suffixes to
indicate an `IdBase` being passed around and the non-id suffix of
`parse_node` suggests at it carrying more data than it actually does.
There used to be more reason for avoiding `node_id` because
`SemIR::InstId` used to be named `NodeId`, but that's no longer
necessary. As a consequence, I'd like to rename `parse_node` to more
precisely reflect its type.

In full, this is doing:

```
parse_node_kind -> node_kind
parse_node -> node_id
ParseNodeCategory -> NodeCategory
ParseNodeKind -> NodeKind
ParseNode -> NodeId
```

This is primarily in check and sem_ir, but with some `parse_node_kind`
references in parse too.

Pluralization is consistent with name forms on both sides, so that
wasn't part of my replacements.
2024-03-09 00:21:29 +00:00

57 lines
2.0 KiB
C++

// 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
#include "toolchain/check/context.h"
#include "toolchain/check/convert.h"
#include "toolchain/parse/node_kind.h"
namespace Carbon::Check {
auto HandleArrayExprStart(Context& /*context*/,
Parse::ArrayExprStartId /*node_id*/) -> bool {
return true;
}
auto HandleArrayExprSemi(Context& context, Parse::ArrayExprSemiId node_id)
-> bool {
context.node_stack().Push(node_id);
return true;
}
auto HandleArrayExpr(Context& context, Parse::ArrayExprId node_id) -> bool {
// TODO: Handle array type with undefined bound.
if (context.node_stack()
.PopAndDiscardSoloNodeIdIf<Parse::NodeKind::ArrayExprSemi>()) {
context.node_stack().PopAndIgnore();
return context.TODO(node_id, "HandleArrayExprWithoutBounds");
}
auto bound_inst_id = context.node_stack().PopExpr();
context.node_stack()
.PopAndDiscardSoloNodeId<Parse::NodeKind::ArrayExprSemi>();
auto [element_type_node_id, element_type_inst_id] =
context.node_stack().PopExprWithNodeId();
// The array bound must be a constant.
//
// TODO: Should we support runtime-phase bounds in cases such as:
// comptime fn F(n: i32) -> type { return [i32; n]; }
auto bound_inst = context.constant_values().Get(bound_inst_id);
if (!bound_inst.is_constant()) {
CARBON_DIAGNOSTIC(InvalidArrayExpr, Error,
"Array bound is not a constant.");
context.emitter().Emit(bound_inst_id, InvalidArrayExpr);
context.node_stack().Push(node_id, SemIR::InstId::BuiltinError);
return true;
}
context.AddInstAndPush(
{node_id, SemIR::ArrayType{SemIR::TypeId::TypeType, bound_inst_id,
ExprAsType(context, element_type_node_id,
element_type_inst_id)}});
return true;
}
} // namespace Carbon::Check