public static string Apply(TypeReference leftType, TypeReference rightType)
 {
     if (leftType.FullName == rightType.FullName)
     {
         return(string.Empty);
     }
     return("(" + Naming.ForVariable(leftType) + ")");
 }
        private static string FormatParameterName(TypeReference parameterType, string parameterName, ParameterFormat format)
        {
            string str = string.Empty;

            if ((((format == ParameterFormat.WithTypeAndName) || (format == ParameterFormat.WithTypeAndNameNoThis)) || ((format == ParameterFormat.WithType) || (format == ParameterFormat.WithTypeNoThis))) || ((format == ParameterFormat.WithTypeAndNameThisObject) || (format == ParameterFormat.WithTypeThisObject)))
            {
                str = str + Naming.ForVariable(parameterType);
            }
            if (((format == ParameterFormat.WithTypeAndName) || (format == ParameterFormat.WithTypeAndNameNoThis)) || (format == ParameterFormat.WithTypeAndNameThisObject))
            {
                str = str + " ";
            }
            if ((((format != ParameterFormat.WithTypeAndName) && (format != ParameterFormat.WithTypeAndNameNoThis)) && ((format != ParameterFormat.WithName) && (format != ParameterFormat.WithTypeAndNameThisObject))) && (((format != ParameterFormat.WithNameNoThis) && (format != ParameterFormat.WithNameCastThis)) && (format != ParameterFormat.WithNameUnboxThis)))
            {
                return(str);
            }
            return(str + parameterName);
        }
Example #3
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;
                }
                }
            }
        }
Example #4
0
 public static string Cast(TypeReference type, string value) =>
 $"({Naming.ForVariable(type)}){value}";
 private static string FormatParameterName(TypeReference parameterType, string parameterName) =>
 ((string.Empty + Naming.ForVariable(parameterType)) + " " + parameterName);