Exemplo n.º 1
0
        private static void CallBaseTypeFinalizer(MethodDefinition finalizer, CppCodeWriter writer, IRuntimeMetadataAccess metadataAccess)
        {
            MethodReference method = null;
            TypeDefinition  definition;

            Unity.IL2CPP.ILPreProcessor.TypeResolver resolver;
            for (TypeReference reference2 = finalizer.DeclaringType.BaseType; reference2 != null; reference2 = resolver.Resolve(definition.BaseType))
            {
                definition = reference2.Resolve();
                resolver   = Unity.IL2CPP.ILPreProcessor.TypeResolver.For(reference2);
                foreach (MethodDefinition definition2 in definition.Methods)
                {
                    if (definition2.IsFinalizerMethod())
                    {
                        method = resolver.Resolve(definition2);
                        break;
                    }
                }
            }
            if (method != null)
            {
                List <string> argumentArray = new List <string>(2)
                {
                    Naming.ThisParameterName
                };
                if (MethodSignatureWriter.NeedsHiddenMethodInfo(method, MethodCallType.Normal, false))
                {
                    argumentArray.Add(metadataAccess.HiddenMethodInfo(method));
                }
                Unity.IL2CPP.ILPreProcessor.TypeResolver typeResolverForMethodToCall = Unity.IL2CPP.ILPreProcessor.TypeResolver.For(finalizer.DeclaringType);
                string block = MethodBodyWriter.GetMethodCallExpression(finalizer, typeResolverForMethodToCall.Resolve(method), method, typeResolverForMethodToCall, MethodCallType.Normal, metadataAccess, new VTableBuilder(), argumentArray, false, null);
                writer.WriteStatement(block);
            }
        }
Exemplo n.º 2
0
        private void WriteMainInvocation(CppCodeWriter writer, IRuntimeMetadataAccess metadataAccess)
        {
            if (this.ValidateMainMethod(writer))
            {
                writer.AddIncludeForMethodDeclarations(_entryPoint.DeclaringType);
                List <string> argumentArray = new List <string> {
                    Naming.Null
                };
                if (_entryPoint.Parameters.Count > 0)
                {
                    ArrayType parameterType = (ArrayType)_entryPoint.Parameters[0].ParameterType;
                    writer.AddIncludeForTypeDefinition(parameterType);
                    object[] args = new object[] { Naming.ForVariable(parameterType), Emit.NewSZArray(parameterType, "argc - 1", metadataAccess) };
                    writer.WriteLine("{0} args = {1};", args);
                    writer.WriteLine();
                    writer.WriteLine("for (int i = 1; i < argc; i++)");
                    using (new BlockWriter(writer, false))
                    {
                        writer.WriteLine("DECLARE_NATIVE_C_STRING_AS_STRING_VIEW_OF_IL2CPP_CHARS(argumentUtf16, argv[i]);");
                        object[] objArray2 = new object[] { Naming.ForVariable(TypeProvider.SystemString) };
                        writer.WriteLine("{0} argument = il2cpp_codegen_string_new_utf16(argumentUtf16);", objArray2);
                        writer.WriteStatement(Emit.StoreArrayElement("args", "i - 1", "argument", false));
                    }
                    writer.WriteLine();
                    argumentArray.Add("args");
                }
                if (MethodSignatureWriter.NeedsHiddenMethodInfo(_entryPoint, MethodCallType.Normal, false))
                {
                    argumentArray.Add(metadataAccess.HiddenMethodInfo(_entryPoint));
                }
                if ((_entryPoint.DeclaringType.Attributes & (TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit)) == TypeAttributes.AnsiClass)
                {
                    object[] objArray3 = new object[] { metadataAccess.TypeInfoFor(_entryPoint.DeclaringType) };
                    writer.WriteLine("IL2CPP_RUNTIME_CLASS_INIT({0});", objArray3);
                }
                Unity.IL2CPP.ILPreProcessor.TypeResolver typeResolverForMethodToCall = Unity.IL2CPP.ILPreProcessor.TypeResolver.For(_entryPoint.DeclaringType, _entryPoint);
                string block = MethodBodyWriter.GetMethodCallExpression(null, _entryPoint, _entryPoint, typeResolverForMethodToCall, MethodCallType.Normal, metadataAccess, new VTableBuilder(), argumentArray, false, null);
                switch (_entryPoint.ReturnType.MetadataType)
                {
                case MetadataType.Void:
                    writer.WriteStatement(block);
                    writer.WriteLine("return 0;");
                    break;

                case MetadataType.Int32:
                {
                    object[] objArray4 = new object[] { block };
                    writer.WriteLine("return {0};", objArray4);
                    break;
                }

                case MetadataType.UInt32:
                {
                    object[] objArray5 = new object[] { block };
                    writer.WriteLine("uint32_t exitCode = {0};", objArray5);
                    writer.WriteLine("return static_cast<int>(exitCode);");
                    break;
                }
                }
            }
        }