function.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  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/subst.h"
  8. #include "toolchain/sem_ir/function.h"
  9. namespace Carbon::Check {
  10. // Checks that `new_function_id` has the same parameter types and return type as
  11. // `prev_function_id`, applying the specified set of substitutions to the
  12. // previous function. Prints a suitable diagnostic and returns false if not.
  13. // Note that this doesn't include the syntactic check that's performed for
  14. // redeclarations.
  15. auto CheckFunctionTypeMatches(Context& context,
  16. SemIR::FunctionId new_function_id,
  17. SemIR::FunctionId prev_function_id,
  18. Substitutions substitutions) -> bool;
  19. // Tries to merge new_function into prev_function_id. Since new_function won't
  20. // have a definition even if one is upcoming, set is_definition to indicate the
  21. // planned result.
  22. //
  23. // If merging is successful, updates the FunctionId on new_function and returns
  24. // true. Otherwise, returns false. Prints a diagnostic when appropriate.
  25. auto MergeFunctionRedecl(Context& context, Parse::NodeId node_id,
  26. SemIR::Function& new_function,
  27. SemIR::FunctionId prev_function_id, bool is_definition)
  28. -> bool;
  29. } // namespace Carbon::Check
  30. #endif // CARBON_TOOLCHAIN_CHECK_FUNCTION_H_