private void WriteMarshalToNativeForNonSealedType(CppCodeWriter writer, ManagedMarshalValue sourceVariable, string destinationVariable) { object[] args = new object[] { sourceVariable.Load() }; writer.WriteLine("if (({0})->klass->is_import_or_windows_runtime)", args); using (new BlockWriter(writer, false)) { if (this._isClass) { object[] objArray2 = new object[] { destinationVariable, sourceVariable.Load(), DefaultMarshalInfoWriter.Naming.ForComTypeInterfaceFieldGetter(this._defaultInterface) }; writer.WriteLine("{0} = ({1})->{2}();", objArray2); object[] objArray3 = new object[] { destinationVariable }; writer.WriteLine("{0}->AddRef();", objArray3); } else { object[] objArray4 = new object[] { DefaultMarshalInfoWriter.Naming.ForInteropHResultVariable(), DefaultMarshalInfoWriter.Naming.ForVariable(DefaultMarshalInfoWriter.TypeProvider.Il2CppComObjectTypeReference), sourceVariable.Load(), DefaultMarshalInfoWriter.Naming.ForIl2CppComObjectIdentityField(), this._interfaceTypeName, destinationVariable }; writer.WriteLine("il2cpp_hresult_t {0} = (({1}){2})->{3}->QueryInterface({4}::IID, reinterpret_cast<void**>(&{5}));", objArray4); writer.WriteStatement(Emit.Call("il2cpp_codegen_com_raise_exception_if_failed", DefaultMarshalInfoWriter.Naming.ForInteropHResultVariable())); } } writer.WriteLine("else"); using (new BlockWriter(writer, false)) { object[] objArray5 = new object[] { destinationVariable, this._interfaceTypeName, sourceVariable.Load() }; writer.WriteLine("{0} = il2cpp_codegen_com_get_or_create_ccw<{1}>({2});", objArray5); } }
private void WriteThrowNotSupportedException(CppCodeWriter writer) { string exception = DefaultMarshalInfoWriter.Naming.ForField(this._faultyField) + "Exception"; object[] args = new object[] { exception, this.GetMarshalingException() }; writer.WriteLine("Il2CppCodeGenException* {0} = {1};", args); writer.WriteStatement(Emit.RaiseManagedException(exception)); }
public override void WriteMarshaledTypeForwardDeclaration(CppCodeWriter writer) { if (!Extensions.IsSystemObject(base._typeRef)) { writer.AddForwardDeclaration(string.Format("struct {0}", this._interfaceTypeName)); } }
public sealed override string WriteMarshalVariableToNative(CppCodeWriter writer, ManagedMarshalValue sourceVariable, string managedVariableName, IRuntimeMetadataAccess metadataAccess) { string variableName = string.Format("_{0}_marshaled", sourceVariable.GetNiceName()); this.WriteNativeVariableDeclarationOfType(writer, variableName); this.WriteMarshalVariableToNative(writer, sourceVariable, variableName, managedVariableName, metadataAccess); return variableName; }
protected override void WriteMarshalToNativeMethodDefinition(CppCodeWriter writer) { writer.WriteLine(base._marshalToNativeFunctionDeclaration); writer.BeginBlock(); this.WriteThrowNotSupportedException(writer); writer.EndBlock(false); }
protected virtual void OnBeforeHResultCheck(CppCodeWriter writer) { if (this.UseQueryInterfaceToObtainInterfacePointer) { writer.WriteStatement(InteropMethodBodyWriter.Naming.ForInteropInterfaceVariable(this._interfaceType) + "->Release()"); } }
public override string WriteMarshalVariableToNative(CppCodeWriter writer, ManagedMarshalValue sourceVariable, string managedVariableName, IRuntimeMetadataAccess metadataAccess) { if (DefaultMarshalInfoWriter.Naming.ForVariable(base._typeRef) != this._marshaledTypes[0].DecoratedName) { return string.Format("reinterpret_cast<{0}>({1})", this._marshaledTypes[0].DecoratedName, sourceVariable.Load()); } return sourceVariable.Load(); }
public override string WriteMarshalVariableFromNative(CppCodeWriter writer, string variableName, IList<MarshaledParameter> methodParameters, bool returnValue, bool forNativeWrapperOfManagedMethod, IRuntimeMetadataAccess metadataAccess) { string marshaledVariableName = variableName.Replace("*", ""); string unmarshaledVariableName = string.Format("_{0}_unmarshaled", DefaultMarshalInfoWriter.CleanVariableName(variableName)); this.WriteDeclareAndAllocateObject(writer, unmarshaledVariableName, marshaledVariableName, metadataAccess); this.WriteMarshalVariableFromNative(writer, variableName, new ManagedMarshalValue(unmarshaledVariableName), methodParameters, returnValue, forNativeWrapperOfManagedMethod, metadataAccess); return unmarshaledVariableName; }
public override void WriteMarshalVariableToNative(CppCodeWriter writer, ManagedMarshalValue sourceVariable, string destinationVariable, string managedVariableName, IRuntimeMetadataAccess metadataAccess) { if (!this.CanMarshalTypeToNative()) { throw new InvalidOperationException("Cannot marshal HandleRef by reference to native code."); } if (<>f__am$cache0 == null) {
public override string WriteMarshalVariableFromNative(CppCodeWriter writer, string variableName, IList<MarshaledParameter> methodParameters, bool returnValue, bool forNativeWrapperOfManagedMethod, IRuntimeMetadataAccess metadataAccess) { string str = DefaultMarshalInfoWriter.Naming.ForVariable(base._typeRef); if (str != this._marshaledTypes[0].DecoratedName) { return string.Format("reinterpret_cast<{0}>({1})", str, variableName); } return variableName; }
public OptimizationWriter(CppCodeWriter writer, string methodFullName) { this._platformsWithOptimizationsDisabled = OptimizationDatabase.GetPlatformsWithDisabledOptimizations(methodFullName); if (this._platformsWithOptimizationsDisabled != null) { this._writer = writer; object[] args = new object[1]; if (<>f__am$cache0 == null) {
protected override void WriteMethodPrologue(CppCodeWriter writer, IRuntimeMetadataAccess metadataAccess) { string decoratedName = base._marshaledReturnType.DecoratedName; object[] args = new object[] { decoratedName, InteropMethodBodyWriter.Naming.ForPInvokeFunctionPointerTypedef(), base.FormatParametersForTypedef() }; writer.WriteLine("typedef {0} (STDCALL *{1})({2});", args); object[] objArray2 = new object[] { InteropMethodBodyWriter.Naming.ForPInvokeFunctionPointerTypedef(), InteropMethodBodyWriter.Naming.ForPInvokeFunctionPointerVariable(), InteropMethodBodyWriter.Naming.ThisParameterName }; writer.WriteLine("{0} {1} = reinterpret_cast<{0}>(((Il2CppDelegate*){2})->method->methodPointer);", objArray2); writer.WriteLine(); }
protected override void WriteReturnStatementEpilogue(CppCodeWriter writer, string unmarshaledReturnValueVariableName) { if (this.GetMethodReturnType().ReturnType.MetadataType != MetadataType.Void) { object[] args = new object[] { InteropMethodBodyWriter.Naming.ForComInterfaceReturnParameterName(), unmarshaledReturnValueVariableName }; writer.WriteLine("*{0} = {1};", args); } writer.WriteLine("return IL2CPP_S_OK;"); }
protected sealed override void WriteReturnStatement(CppCodeWriter writer, string unmarshaledReturnValueVariableName, IRuntimeMetadataAccess metadataAccess) { MarshaledType[] marshaledTypes = base.MarshalInfoWriterFor(this.GetMethodReturnType()).MarshaledTypes; for (int i = 0; i < (marshaledTypes.Length - 1); i++) { object[] args = new object[] { InteropMethodBodyWriter.Naming.ForComInterfaceReturnParameterName(), unmarshaledReturnValueVariableName, marshaledTypes[i].VariableName }; writer.WriteLine("*{0}{2} = {1}{2};", args); } this.WriteReturnStatementEpilogue(writer, unmarshaledReturnValueVariableName); }
private bool ValidateMainMethod(CppCodeWriter writer) { if (_entryPoint == null) { string str = string.Format("Entry point not found in assembly '{0}'.", _executable.FullName); object[] arguments = new object[] { str }; writer.WriteStatement(Emit.RaiseManagedException("il2cpp_codegen_get_missing_method_exception(\"{0}\")", arguments)); return false; } if (_entryPoint.HasThis) { string str2 = "Entry point must be static."; object[] objArray2 = new object[] { str2 }; writer.WriteStatement(Emit.RaiseManagedException("il2cpp_codegen_get_missing_method_exception(\"{0}\")", objArray2)); return false; } TypeReference returnType = _entryPoint.ReturnType; if (((returnType.MetadataType != MetadataType.Void) && (returnType.MetadataType != MetadataType.Int32)) && (returnType.MetadataType != MetadataType.UInt32)) { string str3 = "Entry point must have a return type of void, integer, or unsigned integer."; object[] objArray3 = new object[] { str3 }; writer.WriteStatement(Emit.RaiseManagedException("il2cpp_codegen_get_missing_method_exception(\"{0}\")", objArray3)); return false; } Collection<ParameterDefinition> parameters = _entryPoint.Parameters; bool flag2 = (parameters.Count < 2) && !_entryPoint.HasGenericParameters; if (flag2 && (parameters.Count == 1)) { ParameterDefinition definition = parameters[0]; ArrayType parameterType = definition.ParameterType as ArrayType; if ((parameterType == null) || !parameterType.IsVector) { flag2 = false; } else if (parameterType.ElementType.MetadataType != MetadataType.String) { flag2 = false; } } if (!flag2) { string str4 = string.Format("Entry point method for type '{0}' has invalid signature.", _entryPoint.DeclaringType.FullName); object[] objArray4 = new object[] { str4 }; writer.WriteStatement(Emit.RaiseManagedException("il2cpp_codegen_get_missing_method_exception(\"{0}\")", objArray4)); return false; } if (_entryPoint.DeclaringType.HasGenericParameters) { string str5 = string.Format("Entry point method is defined on a generic type '{0}'.", _entryPoint.DeclaringType.FullName); object[] objArray5 = new object[] { str5 }; writer.WriteStatement(Emit.RaiseManagedException("il2cpp_codegen_get_missing_method_exception(\"{0}\")", objArray5)); return false; } return true; }
protected override void WriteMethodPrologue(CppCodeWriter writer, IRuntimeMetadataAccess metadataAccess) { string str = InteropMethodBodyWriter.Naming.ForWindowsRuntimeDelegateComCallableWrapperInterface(base._interfaceType); string str2 = InteropMethodBodyWriter.Naming.ForInteropInterfaceVariable(base._interfaceType); object[] args = new object[] { str, str2, InteropMethodBodyWriter.Naming.Null }; writer.WriteLine("{0}* {1} = {2};", args); object[] objArray2 = new object[] { InteropMethodBodyWriter.Naming.ForInteropHResultVariable(), InteropMethodBodyWriter.Naming.ThisParameterName, InteropMethodBodyWriter.Naming.ForIl2CppComObjectIdentityField(), str, str2 }; writer.WriteLine("il2cpp_hresult_t {0} = {1}->{2}->QueryInterface({3}::IID, reinterpret_cast<void**>(&{4}));", objArray2); writer.WriteStatement(Emit.Call("il2cpp_codegen_com_raise_exception_if_failed", InteropMethodBodyWriter.Naming.ForInteropHResultVariable())); writer.WriteLine(); }
protected override void WriteInteropCallStatement(CppCodeWriter writer, string[] localVariableNames, IRuntimeMetadataAccess metadataAccess) { MethodReturnType methodReturnType = this.GetMethodReturnType(); if (methodReturnType.ReturnType.MetadataType != MetadataType.Void) { base.MarshalInfoWriterFor(methodReturnType).WriteNativeVariableDeclarationOfType(writer, InteropMethodBodyWriter.Naming.ForInteropReturnValue()); } writer.WriteStatement(this.GetMethodCallExpression(localVariableNames)); this.OnBeforeHResultCheck(writer); writer.WriteLine(); writer.WriteStatement(Emit.Call("il2cpp_codegen_com_raise_exception_if_failed", InteropMethodBodyWriter.Naming.ForInteropHResultVariable())); }
internal static void WriteRegistrationIncludes(CppCodeWriter writer) { writer.AddInclude("il2cpp-config.h"); writer.AddInclude("class-internals.h"); writer.AddInclude("codegen/il2cpp-codegen.h"); writer.AddStdInclude("cstring"); writer.AddStdInclude("string.h"); writer.AddStdInclude("stdio.h"); writer.AddStdInclude("cmath"); writer.AddStdInclude("limits"); writer.AddStdInclude("assert.h"); writer.WriteLine(); }
private void ActivateThroughCustomActivationFactory(CppCodeWriter writer, string staticFieldsAccess, string parameters) { string str = InteropMethodBodyWriter.Naming.ForMethod(this.factoryMethod); string str2 = InteropMethodBodyWriter.Naming.ForComTypeInterfaceFieldName(Extensions.ExtractDefaultInterface(this.constructedObjectType.Resolve())); WriteDeclareActivationFactory(writer, this.factoryMethod.DeclaringType, staticFieldsAccess); writer.WriteLine(string.Format("il2cpp_hresult_t hr = activationFactory->{0}({1}&{2}->{3});", new object[] { str, parameters, this.thisParameter, str2 })); writer.WriteLine("il2cpp_codegen_com_raise_exception_if_failed(hr);"); writer.WriteLine(); writer.WriteLine(string.Format("hr = {0}->{1}->QueryInterface(Il2CppIUnknown::IID, reinterpret_cast<void**>(&{2}->{3}));", new object[] { this.thisParameter, str2, this.thisParameter, this.identityField })); writer.WriteLine("il2cpp_codegen_com_raise_exception_if_failed(hr);"); writer.WriteLine(); writer.WriteLine(string.Format("il2cpp_codegen_com_register_rcw({0});", this.thisParameter)); }
public sealed override void WriteMarshalCleanupVariable(CppCodeWriter writer, string variableName, IRuntimeMetadataAccess metadataAccess, string managedVariableName) { if (!this._isSealed) { object[] args = new object[] { variableName, DefaultMarshalInfoWriter.Naming.Null }; writer.WriteLine("if ({0} != {1})", args); using (new BlockWriter(writer, false)) { object[] objArray2 = new object[] { variableName }; writer.WriteLine("({0})->Release();", objArray2); object[] objArray3 = new object[] { variableName, DefaultMarshalInfoWriter.Naming.Null }; writer.WriteLine("{0} = {1};", objArray3); } } }
protected override void WriteMethodPrologue(CppCodeWriter writer, IRuntimeMetadataAccess metadataAccess) { string str = InteropMethodBodyWriter.Naming.ForTypeNameOnly(this._interfaceType); string str2 = InteropMethodBodyWriter.Naming.ForInteropInterfaceVariable(this._interfaceType); if (this.UseQueryInterfaceToObtainInterfacePointer) { object[] args = new object[] { str, str2, InteropMethodBodyWriter.Naming.Null }; writer.WriteLine("{0}* {1} = {2};", args); object[] objArray2 = new object[] { InteropMethodBodyWriter.Naming.ForInteropHResultVariable(), InteropMethodBodyWriter.Naming.ForVariable(InteropMethodBodyWriter.TypeProvider.Il2CppComObjectTypeReference), InteropMethodBodyWriter.Naming.ThisParameterName, InteropMethodBodyWriter.Naming.ForIl2CppComObjectIdentityField(), str, str2 }; writer.WriteLine("il2cpp_hresult_t {0} = static_cast<{1}>({2})->{3}->QueryInterface({4}::IID, reinterpret_cast<void**>(&{5}));", objArray2); writer.WriteStatement(Emit.Call("il2cpp_codegen_com_raise_exception_if_failed", InteropMethodBodyWriter.Naming.ForInteropHResultVariable())); } else { string str3 = !this._actualMethod.HasThis ? string.Format("(({0}*){1}->static_fields)", InteropMethodBodyWriter.Naming.ForStaticFieldsStruct(this._actualMethod.DeclaringType), metadataAccess.TypeInfoFor(this._actualMethod.DeclaringType)) : string.Format("{0}", InteropMethodBodyWriter.Naming.ThisParameterName); object[] objArray3 = new object[] { InteropMethodBodyWriter.Naming.ForTypeNameOnly(this._interfaceType), InteropMethodBodyWriter.Naming.ForInteropInterfaceVariable(this._interfaceType), str3, InteropMethodBodyWriter.Naming.ForComTypeInterfaceFieldGetter(this._interfaceType) }; writer.WriteLine("{0}* {1} = {2}->{3}();", objArray3); } writer.WriteLine(); }
protected override void WriteInteropCallStatement(CppCodeWriter writer, string[] localVariableNames, IRuntimeMetadataAccess metadataAccess) { MethodReturnType methodReturnType = this.GetMethodReturnType(); if (methodReturnType.ReturnType.MetadataType != MetadataType.Void) { object[] args = new object[] { InteropMethodBodyWriter.Naming.ForVariable(base._typeResolver.Resolve(methodReturnType.ReturnType)), InteropMethodBodyWriter.Naming.ForInteropReturnValue() }; writer.WriteLine("{0} {1};", args); } writer.WriteLine("try"); using (new BlockWriter(writer, false)) { if (Extensions.IsValueType(base._managedMethod.DeclaringType)) { object[] objArray2 = new object[] { InteropMethodBodyWriter.Naming.ForTypeNameOnly(base._managedMethod.DeclaringType), InteropMethodBodyWriter.Naming.ThisParameterName, metadataAccess.TypeInfoFor(base._managedMethod.DeclaringType) }; writer.WriteLine("{0}* {1} = ({0}*)UnBox(GetManagedObjectInline(), {2});", objArray2); } else { object[] objArray3 = new object[] { InteropMethodBodyWriter.Naming.ForVariable(base._managedMethod.DeclaringType), InteropMethodBodyWriter.Naming.ThisParameterName }; writer.WriteLine("{0} {1} = ({0})GetManagedObjectInline();", objArray3); } string block = base.GetMethodCallExpression(metadataAccess, InteropMethodBodyWriter.Naming.ThisParameterName, localVariableNames); if (methodReturnType.ReturnType.MetadataType != MetadataType.Void) { object[] objArray4 = new object[] { InteropMethodBodyWriter.Naming.ForInteropReturnValue(), block }; writer.WriteLine("{0} = {1};", objArray4); } else { writer.WriteStatement(block); } } writer.WriteLine("catch (const Il2CppExceptionWrapper& ex)"); using (new BlockWriter(writer, false)) { writer.WriteLine("return ex.ex->hresult;"); } }
private void ActivateThroughCompositionFactory(CppCodeWriter writer, string staticFieldsAccess, string parameters, IRuntimeMetadataAccess metadataAccess) { string str = metadataAccess.TypeInfoFor(this.constructedObjectType); string str2 = InteropMethodBodyWriter.Naming.ForMethod(this.factoryMethod); TypeReference interfaceType = Extensions.ExtractDefaultInterface(this.constructedObjectType.Resolve()); string str3 = InteropMethodBodyWriter.Naming.ForComTypeInterfaceFieldName(interfaceType); writer.WriteLine(string.Format("Il2CppIInspectable* outerInstance = {0};", InteropMethodBodyWriter.Naming.Null)); writer.WriteLine(string.Format("Il2CppIInspectable** innerInstance = {0};", InteropMethodBodyWriter.Naming.Null)); writer.WriteLine(string.Format("bool isComposedConstruction = {0}->klass != {1};", this.thisParameter, str)); WriteDeclareActivationFactory(writer, this.factoryMethod.DeclaringType, staticFieldsAccess); writer.WriteLine(); writer.WriteLine("if (isComposedConstruction)"); using (new BlockWriter(writer, false)) { writer.WriteLine(string.Format("outerInstance = il2cpp_codegen_com_get_or_create_ccw<Il2CppIInspectable>({0});", this.thisParameter)); writer.WriteLine(string.Format("innerInstance = reinterpret_cast<Il2CppIInspectable**>(&{0}->{1});", this.thisParameter, this.identityField)); } writer.WriteLine(); writer.WriteLine(string.Format("il2cpp_hresult_t hr = activationFactory->{0}({1}outerInstance, innerInstance, &{2}->{3});", new object[] { str2, parameters, this.thisParameter, str3 })); writer.WriteLine("il2cpp_codegen_com_raise_exception_if_failed(hr);"); writer.WriteLine(); writer.WriteLine("if (isComposedConstruction)"); using (new BlockWriter(writer, false)) { writer.WriteLine("outerInstance->Release();"); writer.WriteLine(string.Format("{0}->{1}->Release();", this.thisParameter, str3)); } writer.WriteLine("else"); using (new BlockWriter(writer, false)) { writer.WriteLine(string.Format("hr = {0}->{1}->QueryInterface(Il2CppIUnknown::IID, reinterpret_cast<void**>(&{2}->{3}));", new object[] { this.thisParameter, str3, this.thisParameter, this.identityField })); writer.WriteLine("il2cpp_codegen_com_raise_exception_if_failed(hr);"); writer.WriteLine(); writer.WriteLine(string.Format("il2cpp_codegen_com_register_rcw({0});", this.thisParameter)); } }
protected override void WriteMethodEpilogue(CppCodeWriter writer, IRuntimeMetadataAccess metadataAccess) { }
public abstract void WriteMarshalCleanupParameter(CppCodeWriter writer, string valueName, MarshaledParameter parameter, IRuntimeMetadataAccess metadataAccess);
public override void WriteMarshalCleanupVariable(CppCodeWriter writer, string variableName, IRuntimeMetadataAccess metadataAccess, string managedVariableName = null) { }
public Il2CppGenericMethodWriter(CppCodeWriter writer) : base(writer) { }
public abstract void WriteMarshalCleanupReturnValue(CppCodeWriter writer, MethodReturnType methodReturnType, IRuntimeMetadataAccess metadataAccess);
public void WriteDebugBreak(CppCodeWriter writer) { }
public void WriteDebugMetadataIncludes(CppCodeWriter writer) { }
protected MetadataWriter(CppCodeWriter writer) { this._writer = writer; this._debuggerSupport = DebuggerSupportFactory.GetDebuggerSupport(); }
public void WriteDebugTypeInfosDefinitionFor(CppCodeWriter writer, TypeReference typeReference) { }
public Il2CppGenericInstWriter(CppCodeWriter writer) : base(writer) { }
public override void WriteMarshalCleanupEmptyParameter(CppCodeWriter writer, string valueName, MarshaledParameter parameter, IRuntimeMetadataAccess metadataAccess) {
protected abstract void WriteReturnStatementEpilogue(CppCodeWriter writer, string unmarshaleedReturnValueVariableName);
public GenericClassWriter(CppCodeWriter writer) : base(writer) { }
public abstract string WriteMarshalReturnValue(CppCodeWriter writer, MethodReturnType methodReturnType, IList <MarshaledParameter> parameters, IRuntimeMetadataAccess metadataAccess);
public void WriteCallStackInformation(CppCodeWriter writer, MethodReference methodReference, IEnumerable<KeyValuePair<string, TypeReference>> locals, IRuntimeMetadataAccess metadataAccess) { }
public abstract void WriteMarshalOutputParameter(CppCodeWriter writer, string valueName, MarshaledParameter parameter, IList <MarshaledParameter> parameters, IRuntimeMetadataAccess metadataAccess);
public void WriteDebugIncludes(CppCodeWriter writer) { }
public abstract string WriteMarshalInputParameter(CppCodeWriter writer, MarshaledParameter parameter, IList <MarshaledParameter> parameters, IRuntimeMetadataAccess metadataAccess);
public void WriteDebugMethodInfoDefinitionFor(CppCodeWriter writer, MethodReference methodReference) { }
public override void WriteMarshalOutParameterFromNative(CppCodeWriter writer, string variableName, ManagedMarshalValue destinationVariable, IList <MarshaledParameter> methodParameters, bool returnValue, bool forNativeWrapperOfManagedMethod, IRuntimeMetadataAccess metadataAccess) {
public void WriteSequencePoint(CppCodeWriter writer, Instruction instruction, bool injected) { }
protected override void WriteMethodPrologue(CppCodeWriter writer, IRuntimeMetadataAccess metadataAccess) { writer.WriteLine("il2cpp_native_wrapper_vm_thread_attacher _vmThreadHelper;"); writer.WriteLine(); }