RUNTIME: Code rearranged between Memory.* and Types.*

This commit is contained in:
Konstantin Anisimov
2016-11-17 16:08:21 +03:00
committed by vvlevchenko
parent d86b387f9c
commit dfd486a9ea
4 changed files with 39 additions and 29 deletions
-26
View File
@@ -87,32 +87,6 @@ void* AllocArrayInstance(
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
}
#endif
-3
View File
@@ -266,9 +266,6 @@ void InitMemory();
void* AllocInstance(const TypeInfo* type_info, PlacementHint hint);
void* AllocArrayInstance(
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
}
#endif
+36
View File
@@ -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
+3
View File
@@ -34,6 +34,9 @@ extern const TypeInfo* theDoubleArrayTypeInfo;
extern const TypeInfo* theBooleanArrayTypeInfo;
extern const TypeInfo* theStringTypeInfo;
KBoolean IsInstance(const ObjHeader* obj, const TypeInfo* type_info);
void CheckCast(const ObjHeader* obj, const TypeInfo* type_info);
#ifdef __cplusplus
}
#endif