return.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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/node_ids.h"
  8. namespace Carbon::Check {
  9. // Gets the function that a `return` statement in the current context would
  10. // return from.
  11. auto GetCurrentFunctionForReturn(Context& context) -> SemIR::Function&;
  12. // Gets the return slot of the function that lexically encloses the current
  13. // location.
  14. auto GetCurrentReturnSlot(Context& context) -> SemIR::InstId;
  15. // Checks a `returned var` binding and registers it as the current `returned
  16. // var` in this scope.
  17. auto RegisterReturnedVar(Context& context, Parse::NodeId returned_node,
  18. Parse::NodeId type_node, SemIR::TypeId type_id,
  19. SemIR::InstId bind_id) -> void;
  20. // Checks and builds SemIR for a `return;` statement.
  21. auto BuildReturnWithNoExpr(Context& context, Parse::ReturnStatementId node_id)
  22. -> void;
  23. // Checks and builds SemIR for a `return <expression>;` statement.
  24. auto BuildReturnWithExpr(Context& context, Parse::ReturnStatementId node_id,
  25. SemIR::InstId expr_id) -> void;
  26. // Checks and builds SemIR for a `return var;` statement.
  27. auto BuildReturnVar(Context& context, Parse::ReturnStatementId node_id) -> void;
  28. } // namespace Carbon::Check
  29. #endif // CARBON_TOOLCHAIN_CHECK_RETURN_H_