mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:00:13 +01:00
This involves a number of supporting changes: * The `parse_node;` member of instruction types may now have any type derived from `Parse::NodeId` and is no longer required to have that exact type. * `Parse::Node::Invalid` is now a singleton object of a separate type that is convertible to `Parse::NodeId` and its descendants. This replaces the `Invalid` member of its descendants, and avoids having to write long `NodeIdOneOf<...>` types when initializing variables to invalid. * `IndexBase` now allows `==` and `!=` comparisons between its derived classes and types that are convertible to those types. * A number of functions in the check stage have been changed to preserve more type information instead of using `Parse::NodeId`. * `NodeIdForKind<K>` (also known as `KId`) now has a `Kind` member so it may be used to declare `NodeIdOneOf<T, U>` types without #including `parse/typed_nodes.h`. * `NodeIdForKind<K>` (also known as `KId`) may be implicitly converted to `NodeIdOneOf<T, U>` if `T::Kind == K` or `U::Kind == K` (executing a TODO). Many of the `parse_node` members were not converted since they would have required more extensive changes. They have been marked with "TODO" comments. --------- Co-authored-by: Richard Smith <richard@metafoo.co.uk>
39 lines
1.5 KiB
C++
39 lines
1.5 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
|
|
|
|
#ifndef CARBON_TOOLCHAIN_CHECK_RETURN_H_
|
|
#define CARBON_TOOLCHAIN_CHECK_RETURN_H_
|
|
|
|
#include "toolchain/check/context.h"
|
|
#include "toolchain/parse/tree.h"
|
|
#include "toolchain/sem_ir/inst.h"
|
|
|
|
namespace Carbon::Check {
|
|
|
|
// Checks a `returned var` binding and returns the location of the return
|
|
// value storage that the name should bind to.
|
|
auto CheckReturnedVar(Context& context, Parse::NodeId returned_node,
|
|
Parse::NodeId name_node, SemIR::NameId name_id,
|
|
Parse::NodeId type_node, SemIR::TypeId type_id)
|
|
-> SemIR::InstId;
|
|
|
|
// Registers the given binding as the current `returned var` in this scope.
|
|
auto RegisterReturnedVar(Context& context, SemIR::InstId bind_id) -> void;
|
|
|
|
// Checks and builds SemIR for a `return;` statement.
|
|
auto BuildReturnWithNoExpr(Context& context,
|
|
Parse::ReturnStatementId parse_node) -> void;
|
|
|
|
// Checks and builds SemIR for a `return <expression>;` statement.
|
|
auto BuildReturnWithExpr(Context& context, Parse::ReturnStatementId parse_node,
|
|
SemIR::InstId expr_id) -> void;
|
|
|
|
// Checks and builds SemIR for a `return var;` statement.
|
|
auto BuildReturnVar(Context& context, Parse::ReturnStatementId parse_node)
|
|
-> void;
|
|
|
|
} // namespace Carbon::Check
|
|
|
|
#endif // CARBON_TOOLCHAIN_CHECK_RETURN_H_
|