return.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef CARBON_TOOLCHAIN_CHECK_RETURN_H_
  5. #define CARBON_TOOLCHAIN_CHECK_RETURN_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/parse/tree.h"
  8. #include "toolchain/sem_ir/inst.h"
  9. namespace Carbon::Check {
  10. // Checks a `returned var` binding and returns the location of the return
  11. // value storage that the name should bind to.
  12. auto CheckReturnedVar(Context& context, Parse::NodeId returned_node,
  13. Parse::NodeId name_node, SemIR::NameId name_id,
  14. Parse::NodeId type_node, SemIR::TypeId type_id)
  15. -> SemIR::InstId;
  16. // Registers the given binding as the current `returned var` in this scope.
  17. auto RegisterReturnedVar(Context& context, SemIR::InstId bind_id) -> void;
  18. // Checks and builds SemIR for a `return;` statement.
  19. auto BuildReturnWithNoExpr(Context& context, Parse::NodeId parse_node) -> void;
  20. // Checks and builds SemIR for a `return <expression>;` statement.
  21. auto BuildReturnWithExpr(Context& context, Parse::NodeId parse_node,
  22. SemIR::InstId expr_id) -> void;
  23. // Checks and builds SemIR for a `return var;` statement.
  24. auto BuildReturnVar(Context& context, Parse::NodeId parse_node) -> void;
  25. } // namespace Carbon::Check
  26. #endif // CARBON_TOOLCHAIN_CHECK_RETURN_H_