ArrayMetadata.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #pragma once
  2. #include <stdint.h>
  3. #include "os/Mutex.h"
  4. #include "il2cpp-class-internals.h"
  5. #include "vm/Type.h"
  6. namespace il2cpp
  7. {
  8. namespace metadata
  9. {
  10. class ArrayMetadata
  11. {
  12. public:
  13. static Il2CppClass* GetBoundedArrayClass(Il2CppClass* elementClass, uint32_t rank, bool bounded);
  14. typedef void(*ArrayTypeWalkCallback)(Il2CppClass* type, void* context);
  15. static void WalkSZArrays(ArrayTypeWalkCallback callback, void* context);
  16. static void WalkArrays(ArrayTypeWalkCallback callback, void* context);
  17. // called as part of Class::Init with lock held
  18. static void SetupArrayInterfaces(Il2CppClass* klass, const il2cpp::os::FastAutoLock& lock);
  19. static void SetupArrayVTable(Il2CppClass* klass, const il2cpp::os::FastAutoLock& lock);
  20. static void Clear();
  21. /* From ECMA-335, I.8.7 Assignment compatibility:
  22. The reduced type of a type T is the following:
  23. 1. If the underlying type of T is:
  24. a. int8, or unsigned int8, then its reduced type is int8.
  25. b. int16, or unsigned int16, then its reduced type is int16.
  26. c. int32, or unsigned int32, then its reduced type is int32.
  27. d. int64, or unsigned int64, then its reduced type is int64.
  28. e. native int, or unsigned native int, then its reduced type is native int.
  29. (NOTE: In NetFW/Mono (but not CoreCLR) implementations the reduced type is int32 or int64)
  30. 2. Otherwise, the reduced type is itself.
  31. AND... enums are converted to their underlying type
  32. */
  33. static inline Il2CppClass* GetArrayVarianceReducedType(Il2CppClass* type)
  34. {
  35. if (il2cpp::vm::Type::IsArray(&type->byval_arg))
  36. {
  37. return type;
  38. }
  39. // Using castClass to handle reducing enum types - for enums castClass is the underling type
  40. switch (type->castClass->byval_arg.type)
  41. {
  42. case IL2CPP_TYPE_I1:
  43. case IL2CPP_TYPE_U1:
  44. return il2cpp_defaults.sbyte_class;
  45. case IL2CPP_TYPE_I2:
  46. case IL2CPP_TYPE_U2:
  47. return il2cpp_defaults.int16_class;
  48. case IL2CPP_TYPE_I4:
  49. case IL2CPP_TYPE_U4:
  50. return il2cpp_defaults.int32_class;
  51. case IL2CPP_TYPE_I8:
  52. case IL2CPP_TYPE_U8:
  53. return il2cpp_defaults.int64_class;
  54. case IL2CPP_TYPE_I:
  55. case IL2CPP_TYPE_U:
  56. #if IL2CPP_SIZEOF_VOID_P == 8
  57. return il2cpp_defaults.int64_class;
  58. #else
  59. return il2cpp_defaults.int32_class;
  60. #endif
  61. default:
  62. return type;
  63. }
  64. }
  65. };
  66. } /* namespace vm */
  67. } /* namespace il2cpp */