mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 21:10:11 +01:00
Destroy local variables and temporaries at each `}`, and when branching with `break` and `continue`. In `for` statements, destroy loop variables along with anything created within the loop at the end of each loop iteration, and destroy the cursor and range object when the loop terminates. Assisted-by: Gemini via Antigravity --------- Co-authored-by: Geoff Romer <gromer@google.com>
28 lines
899 B
C++
28 lines
899 B
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/control_flow.h"
|
|
#include "toolchain/check/handle.h"
|
|
#include "toolchain/check/unused.h"
|
|
|
|
namespace Carbon::Check {
|
|
|
|
auto HandleParseNode(Context& context, Parse::CodeBlockStartId node_id)
|
|
-> bool {
|
|
context.node_stack().Push(node_id);
|
|
context.scope_stack().PushForSameRegion(ScopeStack::CleanupScopeKind::Owned);
|
|
return true;
|
|
}
|
|
|
|
auto HandleParseNode(Context& context, Parse::CodeBlockId /*node_id*/) -> bool {
|
|
AddAndDiscardCleanups(context);
|
|
context.scope_stack().Pop(/*check_unused=*/true);
|
|
context.node_stack()
|
|
.PopAndDiscardSoloNodeId<Parse::NodeKind::CodeBlockStart>();
|
|
return true;
|
|
}
|
|
|
|
} // namespace Carbon::Check
|