RUNTIME: Code rearranged between Memory.* and Types.*
This commit is contained in:
committed by
vvlevchenko
parent
d86b387f9c
commit
dfd486a9ea
@@ -87,32 +87,6 @@ void* AllocArrayInstance(
|
|||||||
return ArrayContainer(type_info, elements).GetPlace();
|
return ArrayContainer(type_info, elements).GetPlace();
|
||||||
}
|
}
|
||||||
|
|
||||||
int IsInstance(const ObjHeader* obj, const TypeInfo* type_info) {
|
|
||||||
// We assume null check is handled by caller.
|
|
||||||
RuntimeAssert(obj != nullptr, "must not be null");
|
|
||||||
const TypeInfo* obj_type_info = obj->type_info();
|
|
||||||
// If it is an interface - check in list of implemented interfaces.
|
|
||||||
if (type_info->fieldsCount_ < 0) {
|
|
||||||
for (int i = 0; i < obj_type_info->implementedInterfacesCount_; ++i) {
|
|
||||||
if (obj_type_info->implementedInterfaces_[i] == type_info) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
while (obj_type_info != nullptr && obj_type_info != type_info) {
|
|
||||||
obj_type_info = obj_type_info->superType_;
|
|
||||||
}
|
|
||||||
return obj_type_info != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckInstance(const ObjHeader* obj, const TypeInfo* type_info) {
|
|
||||||
if (IsInstance(obj, type_info)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ThrowClassCastException();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -266,9 +266,6 @@ void InitMemory();
|
|||||||
void* AllocInstance(const TypeInfo* type_info, PlacementHint hint);
|
void* AllocInstance(const TypeInfo* type_info, PlacementHint hint);
|
||||||
void* AllocArrayInstance(
|
void* AllocArrayInstance(
|
||||||
const TypeInfo* type_info, PlacementHint hint, uint32_t elements);
|
const TypeInfo* type_info, PlacementHint hint, uint32_t elements);
|
||||||
int IsInstance(const ObjHeader* obj, const TypeInfo* type_info);
|
|
||||||
void CheckInstance(const ObjHeader* obj, const TypeInfo* type_info);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#include "Types.h"
|
||||||
|
#include "Exceptions.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
KBoolean IsInstance(const ObjHeader* obj, const TypeInfo* type_info) {
|
||||||
|
// We assume null check is handled by caller.
|
||||||
|
RuntimeAssert(obj != nullptr, "must not be null");
|
||||||
|
const TypeInfo* obj_type_info = obj->type_info();
|
||||||
|
// If it is an interface - check in list of implemented interfaces.
|
||||||
|
if (type_info->fieldsCount_ < 0) {
|
||||||
|
for (int i = 0; i < obj_type_info->implementedInterfacesCount_; ++i) {
|
||||||
|
if (obj_type_info->implementedInterfaces_[i] == type_info) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
while (obj_type_info != nullptr && obj_type_info != type_info) {
|
||||||
|
obj_type_info = obj_type_info->superType_;
|
||||||
|
}
|
||||||
|
return obj_type_info != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckInstance(const ObjHeader* obj, const TypeInfo* type_info) {
|
||||||
|
if (IsInstance(obj, type_info)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ThrowClassCastException();
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -34,6 +34,9 @@ extern const TypeInfo* theDoubleArrayTypeInfo;
|
|||||||
extern const TypeInfo* theBooleanArrayTypeInfo;
|
extern const TypeInfo* theBooleanArrayTypeInfo;
|
||||||
extern const TypeInfo* theStringTypeInfo;
|
extern const TypeInfo* theStringTypeInfo;
|
||||||
|
|
||||||
|
KBoolean IsInstance(const ObjHeader* obj, const TypeInfo* type_info);
|
||||||
|
void CheckCast(const ObjHeader* obj, const TypeInfo* type_info);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user