mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add a typed node return to AddNode (#5123)
Building on #5120, make a variant of `AddNode` that returns typed nodes, and replace `UnsafeMake` uses with it. This switches to templating in import parsing so that we can get type validation. With this change, `UnsafeMake` ends up used in three places: `Tree::As`, `Tree::TryAs`, and `Context::AddNode`. That should mean that all typed nodes are verified.
This commit is contained in:
@@ -447,27 +447,23 @@ static auto ParsingInDeferredDefinitionScope(Context& context) -> bool {
|
||||
|
||||
auto Context::AddFunctionDefinitionStart(Lex::TokenIndex token, bool has_error)
|
||||
-> void {
|
||||
auto start_id = AddNode<NodeKind::FunctionDefinitionStart>(token, has_error);
|
||||
if (ParsingInDeferredDefinitionScope(*this)) {
|
||||
deferred_definition_stack_.push_back(tree_->deferred_definitions_.Add(
|
||||
{.start_id = FunctionDefinitionStartId::UnsafeMake(
|
||||
NodeId(tree_->node_impls_.size()))}));
|
||||
deferred_definition_stack_.push_back(
|
||||
tree_->deferred_definitions_.Add({.start_id = start_id}));
|
||||
}
|
||||
|
||||
AddNode(NodeKind::FunctionDefinitionStart, token, has_error);
|
||||
}
|
||||
|
||||
auto Context::AddFunctionDefinition(Lex::TokenIndex token, bool has_error)
|
||||
-> void {
|
||||
auto definition_id = AddNode<NodeKind::FunctionDefinition>(token, has_error);
|
||||
if (ParsingInDeferredDefinitionScope(*this)) {
|
||||
auto definition_index = deferred_definition_stack_.pop_back_val();
|
||||
auto& definition = tree_->deferred_definitions_.Get(definition_index);
|
||||
definition.definition_id =
|
||||
FunctionDefinitionId::UnsafeMake(NodeId(tree_->node_impls_.size()));
|
||||
definition.definition_id = definition_id;
|
||||
definition.next_definition_index =
|
||||
DeferredDefinitionIndex(tree_->deferred_definitions().size());
|
||||
}
|
||||
|
||||
AddNode(NodeKind::FunctionDefinition, token, has_error);
|
||||
}
|
||||
|
||||
auto Context::PrintForStackDump(llvm::raw_ostream& output) const -> void {
|
||||
|
||||
Reference in New Issue
Block a user