function.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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_FUNCTION_H_
  5. #define CARBON_TOOLCHAIN_CHECK_FUNCTION_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/check/decl_name_stack.h"
  8. #include "toolchain/check/subst.h"
  9. #include "toolchain/sem_ir/function.h"
  10. #include "toolchain/sem_ir/ids.h"
  11. namespace Carbon::Check {
  12. // State saved for a function definition that has been suspended after
  13. // processing its declaration and before processing its body. This is used for
  14. // inline method handling.
  15. struct SuspendedFunction {
  16. // The function that was declared.
  17. SemIR::FunctionId function_id;
  18. // The instruction ID of the FunctionDecl instruction.
  19. SemIR::InstId decl_id;
  20. // The declaration name information of the function. This includes the scope
  21. // information, such as parameter names.
  22. DeclNameStack::SuspendedName saved_name_state;
  23. };
  24. // Checks that `new_function` has the same parameter types and return type as
  25. // `prev_function`, or if `prev_function_id` is specified, a specific version of
  26. // `prev_function`. Prints a suitable diagnostic and returns false if not.
  27. auto CheckFunctionTypeMatches(
  28. Context& context, const SemIR::Function& new_function,
  29. const SemIR::Function& prev_function,
  30. SemIR::SpecificId prev_specific_id = SemIR::SpecificId::Invalid,
  31. bool check_syntax = true) -> bool;
  32. // Checks that the return type of the specified function is complete, issuing an
  33. // error if not. This computes the return slot usage for the function if
  34. // necessary, and returns information about how the function returns its return
  35. // value.
  36. auto CheckFunctionReturnType(Context& context, SemIR::LocId loc_id,
  37. SemIR::Function& function,
  38. SemIR::SpecificId specific_id)
  39. -> SemIR::ReturnTypeInfo;
  40. } // namespace Carbon::Check
  41. #endif // CARBON_TOOLCHAIN_CHECK_FUNCTION_H_