mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
C++ Interop: Add Core.CppCompat.Long32 as a distinct type for Cpp.long when long is 32 bits (#6364)
For now, only support implicit conversions from and to `i32`. See #6275 for rationale. Part of #5263.
This commit is contained in:
@@ -1112,6 +1112,11 @@ static auto MapBuiltinIntegerType(Context& context, SemIR::LocId loc_id,
|
||||
return ExprAsType(context, Parse::NodeId::None,
|
||||
MakeCharTypeLiteral(context, Parse::NodeId::None));
|
||||
}
|
||||
if (ast_context.hasSameType(qual_type, ast_context.LongTy) && width == 32) {
|
||||
return ExprAsType(context, Parse::NodeId::None,
|
||||
LookupNameInCore(context, Parse::NodeId::None,
|
||||
{"CppCompat", "Long32"}));
|
||||
}
|
||||
return TypeExpr::None;
|
||||
}
|
||||
|
||||
|
||||
@@ -104,6 +104,8 @@ static auto LookupCppType(
|
||||
// type is not supported.
|
||||
static auto TryMapClassType(Context& context, SemIR::ClassType class_type)
|
||||
-> clang::QualType {
|
||||
clang::ASTContext& ast_context = context.ast_context();
|
||||
|
||||
// If the class was imported from C++, return the original C++ type.
|
||||
auto clang_decl_id =
|
||||
context.name_scopes()
|
||||
@@ -112,7 +114,7 @@ static auto TryMapClassType(Context& context, SemIR::ClassType class_type)
|
||||
if (clang_decl_id.has_value()) {
|
||||
clang::Decl* clang_decl = context.clang_decls().Get(clang_decl_id).key.decl;
|
||||
auto* tag_type_decl = clang::cast<clang::TagDecl>(clang_decl);
|
||||
return context.ast_context().getCanonicalTagType(tag_type_decl);
|
||||
return ast_context.getCanonicalTagType(tag_type_decl);
|
||||
}
|
||||
|
||||
// If the class represents a Carbon type literal, map it to the corresponding
|
||||
@@ -135,22 +137,28 @@ static auto TryMapClassType(Context& context, SemIR::ClassType class_type)
|
||||
CARBON_FATAL("Unexpected invalid numeric type literal");
|
||||
}
|
||||
case SemIR::NumericTypeLiteralInfo::Float: {
|
||||
return context.ast_context().getRealTypeForBitwidth(
|
||||
return ast_context.getRealTypeForBitwidth(
|
||||
bit_width, clang::FloatModeKind::NoFloat);
|
||||
}
|
||||
case SemIR::NumericTypeLiteralInfo::Int: {
|
||||
return context.ast_context().getIntTypeForBitwidth(bit_width, true);
|
||||
return ast_context.getIntTypeForBitwidth(bit_width, true);
|
||||
}
|
||||
case SemIR::NumericTypeLiteralInfo::UInt: {
|
||||
return context.ast_context().getIntTypeForBitwidth(bit_width, false);
|
||||
return ast_context.getIntTypeForBitwidth(bit_width, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
case SemIR::TypeLiteralInfo::Char: {
|
||||
return context.ast_context().CharTy;
|
||||
return ast_context.CharTy;
|
||||
}
|
||||
case SemIR::TypeLiteralInfo::CppLong32: {
|
||||
if (ast_context.getIntWidth(ast_context.LongTy) == 32) {
|
||||
return ast_context.LongTy;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SemIR::TypeLiteralInfo::CppNullptrT: {
|
||||
return context.ast_context().NullPtrTy;
|
||||
return ast_context.NullPtrTy;
|
||||
}
|
||||
case SemIR::TypeLiteralInfo::Str: {
|
||||
return LookupCppType(context, {"std", "string_view"});
|
||||
|
||||
Reference in New Issue
Block a user