constant.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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_CPP_CONSTANT_H_
  5. #define CARBON_TOOLCHAIN_CHECK_CPP_CONSTANT_H_
  6. #include <optional>
  7. #include "clang/AST/APValue.h"
  8. #include "toolchain/check/context.h"
  9. #include "toolchain/sem_ir/ids.h"
  10. namespace Carbon::Check {
  11. // Converts an `APValue` to a Carbon `ConstantId`.
  12. auto MapAPValueToConstant(Context& context, SemIR::LocId loc_id,
  13. const clang::APValue& ap_value, clang::QualType type,
  14. bool is_lvalue) -> SemIR::ConstantId;
  15. // Converts a Carbon constant instruction to an `APValue`.
  16. auto MapConstantToAPValue(Context& context, SemIR::InstId const_inst_id,
  17. clang::QualType param_type)
  18. -> std::optional<clang::APValue>;
  19. // Attempt to evaluate a C++ constexpr variable as a Carbon constant.
  20. auto EvalCppVarDecl(Context& context, SemIR::LocId loc_id,
  21. const clang::VarDecl* var_decl, SemIR::TypeId type_id)
  22. -> SemIR::ConstantId;
  23. // Attempt to evaluate a call to a C++ constexpr/consteval function as a
  24. // Carbon constant.
  25. auto EvalCppCall(Context& context, SemIR::LocId loc_id,
  26. SemIR::ClangDeclId clang_decl_id, SemIR::InstBlockId args_id)
  27. -> SemIR::ConstantId;
  28. // If the callee is a C++ thunk, modify `call` to directly call the
  29. // callee of the C++ thunk. Otherwise, does nothing and leaves `call`
  30. // unmodified.
  31. auto MaybeModifyCppThunkCallForConstEval(Context& context, SemIR::Call* call)
  32. -> void;
  33. } // namespace Carbon::Check
  34. #endif // CARBON_TOOLCHAIN_CHECK_CPP_CONSTANT_H_