return.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 parameter corresponding to `function`'s `returned var`.
  13. // Returns None if the `returned var` doesn't correspond to a return parameter
  14. // (e.g. because it doesn't have an in-place init representation).
  15. auto GetReturnedVarParam(Context& context, const SemIR::Function& function)
  16. -> SemIR::InstId;
  17. // Checks a `returned var` binding and registers it as the current `returned
  18. // var` in this scope.
  19. auto RegisterReturnedVar(Context& context, Parse::NodeId returned_node,
  20. Parse::NodeId type_node, SemIR::TypeId type_id,
  21. SemIR::InstId bind_id, SemIR::NameId name_id) -> void;
  22. // Checks and builds SemIR for a `return;` statement.
  23. auto BuildReturnWithNoExpr(Context& context, SemIR::LocId loc_id) -> void;
  24. // Checks and builds SemIR for a `return <expression>;` statement.
  25. auto BuildReturnWithExpr(Context& context, SemIR::LocId loc_id,
  26. SemIR::InstId expr_id) -> void;
  27. // Checks and builds SemIR for a `return var;` statement.
  28. auto BuildReturnVar(Context& context, Parse::ReturnStatementId node_id) -> void;
  29. } // namespace Carbon::Check
  30. #endif // CARBON_TOOLCHAIN_CHECK_RETURN_H_