Object.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include <stdint.h>
  3. #include "il2cpp-config.h"
  4. #include "Class.h"
  5. #include "ClassInlines.h"
  6. struct Il2CppString;
  7. struct Il2CppObject;
  8. struct Il2CppClass;
  9. struct MethodInfo;
  10. namespace il2cpp
  11. {
  12. namespace vm
  13. {
  14. class LIBIL2CPP_CODEGEN_API Object
  15. {
  16. public:
  17. static Il2CppObject* Box(Il2CppClass *klass, void* data);
  18. static Il2CppClass* GetClass(Il2CppObject* obj);
  19. static int32_t GetHash(Il2CppObject* obj);
  20. static uint32_t GetSize(Il2CppObject* obj);
  21. static const MethodInfo* GetVirtualMethod(Il2CppObject *obj, const MethodInfo *virtualMethod);
  22. static Il2CppObject * IsInst(Il2CppObject *obj, Il2CppClass *klass);
  23. static Il2CppObject* New(Il2CppClass *klass);
  24. static void* Unbox(Il2CppObject* obj);
  25. static void UnboxNullable(Il2CppObject* obj, Il2CppClass* nullableArgumentClass, void* storage);
  26. static void UnboxNullableWithWriteBarrier(Il2CppObject* obj, Il2CppClass* nullableArgumentClass, void* storage);
  27. static Il2CppObject * Clone(Il2CppObject *obj);
  28. static Il2CppObject* NewPinned(Il2CppClass *klass);
  29. static void NullableInit(uint8_t* buf, Il2CppObject* value, Il2CppClass* klass);
  30. static bool NullableHasValue(Il2CppClass* klass, void* data)
  31. {
  32. IL2CPP_ASSERT(Class::IsNullable(klass));
  33. IL2CPP_ASSERT(metadata::Il2CppTypeEqualityComparer::AreEqual(ClassInlines::InitFromCodegen(klass)->fields[0].type, &il2cpp_defaults.boolean_class->byval_arg));
  34. // The hasValue field is the first field in the Nullable managed struct,
  35. // so read the first byte to get its value;
  36. uint8_t* hasValueByte = static_cast<uint8_t*>(data);
  37. return *hasValueByte != 0;
  38. }
  39. private:
  40. static Il2CppObject * NewAllocSpecific(Il2CppClass *klass);
  41. static Il2CppObject* NewPtrFree(Il2CppClass *klass);
  42. static Il2CppObject* Allocate(size_t size, Il2CppClass *typeInfo);
  43. static Il2CppObject* AllocatePtrFree(size_t size, Il2CppClass *typeInfo);
  44. static Il2CppObject* AllocateSpec(size_t size, Il2CppClass *typeInfo);
  45. // Yo! Don't call this function! See the comments in the implementation if you do.
  46. static uint32_t UnboxNullableGCUnsafe(Il2CppObject* obj, Il2CppClass* nullableArgumentClass, void* storage);
  47. friend class Array;
  48. friend class RCW;
  49. friend class String;
  50. };
  51. } /* namespace vm */
  52. } /* namespace il2cpp */