Add support for string literals in macros (#6408)

Adding support for macros with string literals.

Part of #6303
This commit is contained in:
Ivana Ivanovska
2025-11-21 12:33:18 +00:00
committed by GitHub
parent 00ee693833
commit 8866e39085
3 changed files with 111 additions and 15 deletions
+15
View File
@@ -2234,6 +2234,21 @@ static auto MapConstant(Context& context, SemIR::LocId loc_id,
clang::Expr* expr) -> SemIR::InstId {
CARBON_CHECK(expr, "empty expression");
if (auto* string_literal = dyn_cast<clang::StringLiteral>(expr)) {
if (!string_literal->isOrdinary() && !string_literal->isUTF8()) {
context.TODO(loc_id,
llvm::formatv("Unsupported: string literal type: {0}",
expr->getType()));
return SemIR::ErrorInst::InstId;
}
StringLiteralValueId string_id =
context.string_literal_values().Add(string_literal->getString());
auto inst_id =
MakeStringLiteral(context, Parse::StringLiteralId::None, string_id);
context.imports().push_back(inst_id);
return inst_id;
}
SemIR::TypeId type_id = MapType(context, loc_id, expr->getType()).type_id;
if (!type_id.has_value()) {
context.TODO(loc_id, llvm::formatv("Unsupported: C++ literal's type `{0}` "