return.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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,
  20. Parse::ReturnStatementId parse_node) -> void;
  21. // Checks and builds SemIR for a `return <expression>;` statement.
  22. auto BuildReturnWithExpr(Context& context, Parse::ReturnStatementId parse_node,
  23. SemIR::InstId expr_id) -> void;
  24. // Checks and builds SemIR for a `return var;` statement.
  25. auto BuildReturnVar(Context& context, Parse::ReturnStatementId parse_node)
  26. -> void;
  27. } // namespace Carbon::Check
  28. #endif // CARBON_TOOLCHAIN_CHECK_RETURN_H_