Array.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include <stdint.h>
  3. #include "il2cpp-config.h"
  4. struct Il2CppArray;
  5. struct Il2CppObject;
  6. struct Il2CppString;
  7. struct Il2CppClass;
  8. namespace il2cpp
  9. {
  10. namespace vm
  11. {
  12. class LIBIL2CPP_CODEGEN_API Array
  13. {
  14. public:
  15. static Il2CppArray* Clone(Il2CppArray* arr);
  16. static int32_t GetElementSize(const Il2CppClass *klass);
  17. static uint32_t GetLength(Il2CppArray* array);
  18. static uint32_t GetByteLength(Il2CppArray* array);
  19. static Il2CppArray* New(Il2CppClass *elementTypeInfo, il2cpp_array_size_t length);
  20. static Il2CppArray* NewSpecific(Il2CppClass *arrayTypeInfo, il2cpp_array_size_t length);
  21. static Il2CppArray* NewFull(Il2CppClass *array_class, il2cpp_array_size_t *lengths, il2cpp_array_size_t *lower_bounds);
  22. public:
  23. // internal
  24. static Il2CppArray* NewCached(Il2CppClass *elementTypeInfo, il2cpp_array_size_t length)
  25. {
  26. return New(elementTypeInfo, length);
  27. }
  28. static char* GetFirstElementAddress(Il2CppArray *array);
  29. };
  30. } /* namespace vm */
  31. } /* namespace il2cpp */
  32. LIBIL2CPP_CODEGEN_API char* il2cpp_array_addr_with_size(Il2CppArray *array, int32_t size, uintptr_t idx);
  33. extern "C"
  34. {
  35. IL2CPP_EXPORT int il2cpp_array_element_size(const Il2CppClass *ac);
  36. }
  37. #define load_array_elema(arr, idx, size) ((((uint8_t*)(arr)) + kIl2CppSizeOfArray) + ((size) * (idx)))
  38. #define il2cpp_array_setwithsize(array, elementSize, index, value) \
  39. do { \
  40. void*__p = (void*) il2cpp_array_addr_with_size ((array), elementSize, (index)); \
  41. memcpy(__p, &(value), elementSize); \
  42. } while (0)
  43. #define il2cpp_array_setrefwithsize(array, elementSize, index, value) \
  44. do { \
  45. void*__p = (void*) il2cpp_array_addr_with_size ((array), elementSize, (index)); \
  46. memcpy(__p, value, 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_wbarrier_set_field((Il2CppObject *)(array), __p, (value));\
  60. } while (0)