function.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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`, applying the specified set of substitutions to the
  26. // previous function. Prints a suitable diagnostic and returns false if not.
  27. auto CheckFunctionTypeMatches(Context& context,
  28. const SemIR::Function& new_function,
  29. const SemIR::Function& prev_function,
  30. Substitutions substitutions, bool check_syntax)
  31. -> 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.
  35. auto CheckFunctionReturnType(Context& context, SemIRLoc loc,
  36. SemIR::Function& function,
  37. SemIR::SpecificId specific_id)
  38. -> SemIR::Function::ReturnSlot;
  39. } // namespace Carbon::Check
  40. #endif // CARBON_TOOLCHAIN_CHECK_FUNCTION_H_