diff --git a/runtime/vm/class_id.h b/runtime/vm/class_id.h index 4c973f44720..84219447225 100644 --- a/runtime/vm/class_id.h +++ b/runtime/vm/class_id.h @@ -352,21 +352,29 @@ inline bool IsFfiNativeTypeTypeClassId(intptr_t index) { } inline bool IsFfiTypeClassId(intptr_t index) { - // Make sure this is updated when new Ffi types are added. - COMPILE_ASSERT(kFfiNativeFunctionCid == kFfiPointerCid + 1 && - kFfiInt8Cid == kFfiPointerCid + 2 && - kFfiInt16Cid == kFfiPointerCid + 3 && - kFfiInt32Cid == kFfiPointerCid + 4 && - kFfiInt64Cid == kFfiPointerCid + 5 && - kFfiUint8Cid == kFfiPointerCid + 6 && - kFfiUint16Cid == kFfiPointerCid + 7 && - kFfiUint32Cid == kFfiPointerCid + 8 && - kFfiUint64Cid == kFfiPointerCid + 9 && - kFfiIntPtrCid == kFfiPointerCid + 10 && - kFfiFloatCid == kFfiPointerCid + 11 && - kFfiDoubleCid == kFfiPointerCid + 12 && - kFfiVoidCid == kFfiPointerCid + 13); - return (index >= kFfiPointerCid && index <= kFfiVoidCid); + switch (index) { + case kFfiPointerCid: + case kFfiNativeFunctionCid: +#define CASE_FFI_CID(name) case kFfi##name##Cid: + CLASS_LIST_FFI_TYPE_MARKER(CASE_FFI_CID) +#undef CASE_FFI_CID + return true; + default: + return false; + } + UNREACHABLE(); +} + +inline bool IsFfiPredefinedClassId(classid_t class_id) { + switch (class_id) { +#define CASE_FFI_CID(name) case kFfi##name##Cid: + CLASS_LIST_FFI(CASE_FFI_CID) +#undef CASE_FFI_CID + return true; + default: + return false; + } + UNREACHABLE(); } inline bool IsFfiTypeIntClassId(intptr_t index) { diff --git a/runtime/vm/compiler/ffi/native_type.cc b/runtime/vm/compiler/ffi/native_type.cc index 05eb8526e22..1ffb1a2e4ef 100644 --- a/runtime/vm/compiler/ffi/native_type.cc +++ b/runtime/vm/compiler/ffi/native_type.cc @@ -337,20 +337,8 @@ static PrimitiveType TypeRepresentation(classid_t class_id) { } } -static bool IsPredefinedFfiCid(classid_t class_id) { - switch (class_id) { -#define CASE_FFI_CID_TRUE(name) \ - case kFfi##name##Cid: \ - return true; - CLASS_LIST_FFI(CASE_FFI_CID_TRUE) - default: - return false; - } - UNREACHABLE(); -} - NativeType& NativeType::FromTypedDataClassId(Zone* zone, classid_t class_id) { - ASSERT(IsPredefinedFfiCid(class_id)); + ASSERT(IsFfiPredefinedClassId(class_id)); const auto fundamental_rep = TypeRepresentation(class_id); return *new (zone) NativePrimitiveType(fundamental_rep); } @@ -358,7 +346,7 @@ NativeType& NativeType::FromTypedDataClassId(Zone* zone, classid_t class_id) { #if !defined(FFI_UNIT_TESTS) NativeType& NativeType::FromAbstractType(Zone* zone, const AbstractType& type) { const classid_t class_id = type.type_class_id(); - if (IsPredefinedFfiCid(class_id)) { + if (IsFfiPredefinedClassId(class_id)) { return NativeType::FromTypedDataClassId(zone, class_id); }