Refactor TryEvaluateMacroToConstant to simplify and dedup code (#6820)

For integral and float types, `TryEvaluateMacroToConstant` now calls
`MapAPValueToConstant` to directly convert from an APValue, rather than
converting the `APValue` to an expression and importing it with
`MapConstant`.

`MapConstant` is still used, but only for string literals and nullptrs.
Since it's only used by `TryEvaluateMacroToConstant`, moved it to
`macros.cpp` and removed the code for other types of expressions.
This commit is contained in:
Nicholas Bishop
2026-03-02 21:00:07 +00:00
committed by GitHub
parent 6359e3f550
commit 069c6f4447
5 changed files with 142 additions and 245 deletions
-1
View File
@@ -9,7 +9,6 @@
namespace Carbon::Check {
// TODO: dedup with code in `MapConstant` and `TryEvaluateMacroToConstant`.
auto MapAPValueToConstant(Context& context, SemIR::LocId loc_id,
const clang::APValue& ap_value, clang::QualType type)
-> SemIR::ConstantId {