mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add an EnumMaskBase type (#6053)
This is a bit of an experiment to see if there's a reasonable way to write a shared enum type, rather than writing per-case wrappers for things like `HasTypeQualifiers` or the printing. I think it's a bit borderline complexity right now, but I'm not sure I can reduce it much further. This changes from things like `Internal::EnumClassName##RawEnum` to `Internal::EnumClassName##Data::RawEnum` so that the enum entries can have back references to bit shifts without needing to know the containing type name. Because I'm trying to reduce duplication between mask and non-mask enums, I did this to non-mask enums too. This was motivated by #6035 adding another enum mask (which will grow more entries, and is intended to switch if this is accepted), but I'm not using that PR as a base here because I didn't want the merge dependency.
This commit is contained in:
@@ -138,19 +138,19 @@ auto GetConstType(Context& context, SemIR::TypeInstId inner_type_id)
|
||||
|
||||
auto GetQualifiedType(Context& context, SemIR::TypeId type_id,
|
||||
SemIR::TypeQualifiers quals) -> SemIR::TypeId {
|
||||
if (HasTypeQualifier(quals, SemIR::TypeQualifiers::Const)) {
|
||||
if (quals.HasAnyOf(SemIR::TypeQualifiers::Const)) {
|
||||
type_id = GetConstType(context, context.types().GetInstId(type_id));
|
||||
quals &= ~SemIR::TypeQualifiers::Const;
|
||||
quals.Remove(SemIR::TypeQualifiers::Const);
|
||||
}
|
||||
if (HasTypeQualifier(quals, SemIR::TypeQualifiers::MaybeUnformed)) {
|
||||
if (quals.HasAnyOf(SemIR::TypeQualifiers::MaybeUnformed)) {
|
||||
type_id = GetTypeImpl<SemIR::MaybeUnformedType>(
|
||||
context, context.types().GetInstId(type_id));
|
||||
quals &= ~SemIR::TypeQualifiers::MaybeUnformed;
|
||||
quals.Remove(SemIR::TypeQualifiers::MaybeUnformed);
|
||||
}
|
||||
if (HasTypeQualifier(quals, SemIR::TypeQualifiers::Partial)) {
|
||||
if (quals.HasAnyOf(SemIR::TypeQualifiers::Partial)) {
|
||||
type_id = GetTypeImpl<SemIR::PartialType>(
|
||||
context, context.types().GetInstId(type_id));
|
||||
quals &= ~SemIR::TypeQualifiers::Partial;
|
||||
quals.Remove(SemIR::TypeQualifiers::Partial);
|
||||
}
|
||||
CARBON_CHECK(quals == SemIR::TypeQualifiers::None);
|
||||
return type_id;
|
||||
|
||||
Reference in New Issue
Block a user