ArrayMetadata.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. static void AcquireMetadataLocks();
  18. static void ReleaseMetadataLocks();
  19. // called as part of Class::Init with lock held
  20. static void SetupArrayInterfaces(Il2CppClass* klass, const il2cpp::os::FastAutoLock& lock);
  21. static void SetupArrayVTable(Il2CppClass* klass, const il2cpp::os::FastAutoLock& lock);
  22. static void Clear();
  23. /* From ECMA-335, I.8.7 Assignment compatibility:
  24. The reduced type of a type T is the following:
  25. 1. If the underlying type of T is:
  26. a. int8, or unsigned int8, then its reduced type is int8.
  27. b. int16, or unsigned int16, then its reduced type is int16.
  28. c. int32, or unsigned int32, then its reduced type is int32.
  29. d. int64, or unsigned int64, then its reduced type is int64.
  30. e. native int, or unsigned native int, then its reduced type is native int.
  31. (NOTE: In NetFW/Mono (but not CoreCLR) implementations the reduced type is int32 or int64)
  32. 2. Otherwise, the reduced type is itself.
  33. AND... enums are converted to their underlying type
  34. */
  35. static inline Il2CppClass* GetArrayVarianceReducedType(Il2CppClass* type)
  36. {
  37. if (il2cpp::vm::Type::IsArray(&type->byval_arg))
  38. {
  39. return type;
  40. }
  41. // Using castClass to handle reducing enum types - for enums castClass is the underling type
  42. switch (type->castClass->byval_arg.type)
  43. {
  44. case IL2CPP_TYPE_I1:
  45. case IL2CPP_TYPE_U1:
  46. return il2cpp_defaults.sbyte_class;
  47. case IL2CPP_TYPE_I2:
  48. case IL2CPP_TYPE_U2:
  49. return il2cpp_defaults.int16_class;
  50. case IL2CPP_TYPE_I4:
  51. case IL2CPP_TYPE_U4:
  52. return il2cpp_defaults.int32_class;
  53. case IL2CPP_TYPE_I8:
  54. case IL2CPP_TYPE_U8:
  55. return il2cpp_defaults.int64_class;
  56. case IL2CPP_TYPE_I:
  57. case IL2CPP_TYPE_U:
  58. #if IL2CPP_SIZEOF_VOID_P == 8
  59. return il2cpp_defaults.int64_class;
  60. #else
  61. return il2cpp_defaults.int32_class;
  62. #endif
  63. default:
  64. return type;
  65. }
  66. }
  67. };
  68. } /* namespace vm */
  69. } /* namespace il2cpp */