Parameter.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "il2cpp-config.h"
  2. #include "il2cpp-runtime-metadata.h"
  3. #include "il2cpp-class-internals.h"
  4. #include "il2cpp-object-internals.h"
  5. #include "Parameter.h"
  6. #include "vm-utils/BlobReader.h"
  7. #include "vm/Class.h"
  8. #include "vm/Object.h"
  9. #include "vm/Method.h"
  10. #include "hybridclr/metadata/MetadataUtil.h"
  11. namespace il2cpp
  12. {
  13. namespace vm
  14. {
  15. Il2CppObject* Parameter::GetDefaultParameterValueObject(const MethodInfo* method, int32_t parameterPosition, bool* isExplicitySetNullDefaultValue)
  16. {
  17. const Il2CppType* typeOfDefaultValue;
  18. const char* data = Method::GetParameterDefaultValue(method, parameterPosition, &typeOfDefaultValue, isExplicitySetNullDefaultValue);
  19. if (data == NULL)
  20. return NULL;
  21. Il2CppClass* parameterType = Class::FromIl2CppType(method->parameters[parameterPosition]);
  22. bool useInterpFormat = hybridclr::metadata::IsInterpreterType(method->klass);
  23. if (il2cpp::vm::Class::IsValuetype(parameterType))
  24. {
  25. if (il2cpp::vm::Class::IsNullable(parameterType))
  26. {
  27. parameterType = il2cpp::vm::Class::GetNullableArgument(parameterType);
  28. typeOfDefaultValue = &parameterType->byval_arg;
  29. }
  30. Class::SetupFields(parameterType);
  31. IL2CPP_ASSERT(parameterType->size_inited);
  32. void* value = alloca(parameterType->instance_size - sizeof(Il2CppObject));
  33. utils::BlobReader::GetConstantValueFromBlob(method->klass->image, typeOfDefaultValue->type, data, value);
  34. return Object::Box(parameterType, value);
  35. }
  36. Il2CppObject* value = NULL;
  37. utils::BlobReader::GetConstantValueFromBlob(method->klass->image, typeOfDefaultValue->type, data, &value);
  38. return value;
  39. }
  40. }
  41. }