mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 14:01:05 +01:00
Add support for string literals in macros (#6408)
Adding support for macros with string literals. Part of #6303
This commit is contained in:
@@ -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}` "
|
||||
|
||||
Reference in New Issue
Block a user