Array.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #include <stdint.h>
  3. #include "il2cpp-config.h"
  4. #include "gc/GarbageCollector.h"
  5. struct Il2CppArray;
  6. struct Il2CppObject;
  7. struct Il2CppString;
  8. struct Il2CppClass;
  9. namespace il2cpp
  10. {
  11. namespace vm
  12. {
  13. class LIBIL2CPP_CODEGEN_API Array
  14. {
  15. public:
  16. static Il2CppArray* Clone(Il2CppArray* arr);
  17. static int32_t GetElementSize(const Il2CppClass *klass);
  18. static uint32_t GetLength(Il2CppArray* array);
  19. static uint32_t GetByteLength(Il2CppArray* array);
  20. static Il2CppArray* New(Il2CppClass *elementTypeInfo, il2cpp_array_size_t length);
  21. static Il2CppArray* NewSpecific(Il2CppClass *arrayTypeInfo, il2cpp_array_size_t length);
  22. static Il2CppArray* NewFull(Il2CppClass *array_class, il2cpp_array_size_t *lengths, il2cpp_array_size_t *lower_bounds);
  23. public:
  24. // internal
  25. static Il2CppArray* NewCached(Il2CppClass *elementTypeInfo, il2cpp_array_size_t length)
  26. {
  27. return New(elementTypeInfo, length);
  28. }
  29. static char* GetFirstElementAddress(Il2CppArray *array);
  30. };
  31. } /* namespace vm */
  32. } /* namespace il2cpp */
  33. extern "C"
  34. {
  35. IL2CPP_EXPORT int il2cpp_array_element_size(const Il2CppClass *ac);
  36. }
  37. #define il2cpp_array_setwithsize(array, elementSize, index, value) \
  38. do { \
  39. void*__p = (void*) il2cpp_array_addr_with_size ((array), elementSize, (index)); \
  40. memcpy(__p, &(value), elementSize); \
  41. } while (0)
  42. #define il2cpp_array_setrefwithsize(array, elementSize, index, value) \
  43. do { \
  44. void* __p = (void*) il2cpp_array_addr_with_size ((array), elementSize, (index)); \
  45. memcpy(__p, value, elementSize); \
  46. il2cpp::gc::GarbageCollector::SetWriteBarrier((void**)__p, elementSize); \
  47. } while (0)
  48. #define il2cpp_array_addr(array, type, index) ((type*)(void*) il2cpp_array_addr_with_size (array, sizeof (type), index))
  49. #define il2cpp_array_get(array, type, index) ( *(type*)il2cpp_array_addr ((array), type, (index)) )
  50. #define il2cpp_array_set(array, type, index, value) \
  51. do { \
  52. type *__p = (type *) il2cpp_array_addr ((array), type, (index)); \
  53. *__p = (value); \
  54. } while (0)
  55. #define il2cpp_array_setref(array, index, value) \
  56. do { \
  57. void* *__p = (void* *) il2cpp_array_addr ((array), void*, (index)); \
  58. *__p = (value); \
  59. il2cpp::gc::GarbageCollector::SetWriteBarrier(__p); \
  60. } while (0)