function.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_id` has the same parameter types and return type as
  25. // `prev_function_id`, applying the specified set of substitutions to the
  26. // previous function. Prints a suitable diagnostic and returns false if not.
  27. // Note that this doesn't include the syntactic check that's performed for
  28. // redeclarations.
  29. auto CheckFunctionTypeMatches(Context& context,
  30. SemIR::FunctionId new_function_id,
  31. SemIR::FunctionId prev_function_id,
  32. Substitutions substitutions) -> bool;
  33. // Tries to merge new_function into prev_function_id. Since new_function won't
  34. // have a definition even if one is upcoming, set is_definition to indicate the
  35. // planned result.
  36. //
  37. // If merging is successful, returns true and may update the previous function.
  38. // Otherwise, returns false. Prints a diagnostic when appropriate.
  39. auto MergeFunctionRedecl(Context& context, SemIRLoc new_loc,
  40. SemIR::Function& new_function, bool new_is_import,
  41. bool new_is_definition,
  42. SemIR::FunctionId prev_function_id,
  43. SemIR::ImportIRId prev_import_ir_id) -> bool;
  44. // Checks that the return type of the specified function is complete, issuing an
  45. // error if not. This computes the return slot usage for the function if
  46. // necessary.
  47. auto CheckFunctionReturnType(Context& context, SemIRLoc loc,
  48. SemIR::Function& function) -> void;
  49. } // namespace Carbon::Check
  50. #endif // CARBON_TOOLCHAIN_CHECK_FUNCTION_H_