Exemplo n.º 1
0
        // Builder parameter string
        public void PrepareSendFunctionParametersCPP(string strPrefix, Parameter[] parameter)
        {
            TypeUsage from = TypeUsage.CPPForSharp;
            TypeUsage to   = ParameterMode;

            if (parameter == null)
            {
                return;
            }

            foreach (Parameter param in parameter)
            {
                string paramElementTypeName = SystemTypeInfo.ElementTypeNameFor(from, param);
                string paramTypeNameOnly    = SystemTypeInfo.TypeNameOnlyFor(from, param);
                string paramTypeFrom        = SystemTypeInfo.TypeNameFor(from, param);
                string paramTypeTo          = SystemTypeInfo.TypeNameFor(to, param);
                var    typeInfo             = SystemTypeInfo.GetParameterInfo(param);
                //Type scharpType = SystemTypeInfo.ToCSharpType(param.Type);
                bool paramTypeEquality = paramTypeFrom == paramTypeTo;

                //bool bIsStruct = IsStruct(param.Type);

                // Disable native conversion
                if (param.IsArray) // string type
                {
                    if (IsStrType(param))
                    {
                        string varName = string.Format("{0}{1}", strPrefix, InParamName(param.Name));
                        MatchIndent(); OutStream.WriteLine("auto& {0}Array_ = *NativeToObject<SF::ArrayObject<const char*>>({0});", varName);
                    }
                }
            }
        }
Exemplo n.º 2
0
        // Builder parameter string
        public string ParamInListString(TypeUsage from, string strPrefix, Parameter[] parameter)
        {
            TypeUsage     to        = ParameterMode;
            StringBuilder strParams = new StringBuilder(512);
            string        strComma  = ",";

            if (parameter == null)
            {
                return(strParams.ToString());
            }

            foreach (Parameter param in parameter)
            {
                strParams.Append(strComma);

                string paramElementTypeName = SystemTypeInfo.ElementTypeNameFor(from, param);
                string paramTypeNameOnly    = SystemTypeInfo.TypeNameOnlyFor(from, param);
                string paramTypeFrom        = SystemTypeInfo.TypeNameFor(from, param);
                string paramTypeTo          = SystemTypeInfo.TypeNameFor(to, param);
                var    typeInfo             = SystemTypeInfo.GetParameterInfo(param);
                //Type scharpType = SystemTypeInfo.ToCSharpType(param.Type);
                bool paramTypeEquality = paramTypeFrom == paramTypeTo;

                if (IsStrType(param)) // string type
                {
                    strParams.AppendFormat("{0}{1}", strPrefix, InParamName(param.Name));
                }
                else if (param.IsArray) // array
                {
                    if (from == TypeUsage.CPPForSharp)
                    {
                        strParams.AppendFormat("SF::ArrayView<const {2}>({0}_sizeOf{1}, {0}_sizeOf{1}, const_cast<{3}>({0}{1}))", strPrefix, InParamName(param.Name), paramElementTypeName, paramTypeNameOnly);
                    }
                    else
                    {
                        if (from == TypeUsage.CSharp)
                        {
                            strParams.AppendFormat("(ushort){0}{1}.Length, ", strPrefix, InParamName(param.Name));
                        }

                        if (from == TypeUsage.CSharp && typeInfo.IsEnum)
                        {
                            strParams.AppendFormat("GameTypes.ToIntArray({0}{1})", strPrefix, InParamName(param.Name));
                        }
                        else
                        {
                            strParams.AppendFormat("{0}{1}", strPrefix, InParamName(param.Name));
                        }
                    }
                }
                else // generic type
                {
                    if (typeInfo.IsCSharpStruct)
                    {
                        if (ParameterMode == TypeUsage.CSharp || ParameterMode == TypeUsage.CSharpNative)
                        {
                            strParams.AppendFormat("ref {0}{1}", strPrefix, InParamName(param.Name));
                        }
                        else
                        {
                            strParams.AppendFormat("{0}{1}", strPrefix, InParamName(param.Name));
                        }
                    }
                    else
                    {
                        if (paramTypeEquality)
                        {
                            strParams.AppendFormat(" {0}{1}", strPrefix, InParamName(param.Name));
                        }
                        else
                        {
                            strParams.AppendFormat("({2}) {0}{1}", strPrefix, InParamName(param.Name), paramTypeTo);
                        }
                    }
                }
            }

            return(strParams.ToString());
        }
Exemplo n.º 3
0
        // Builder parameter string
        public string CallCreateNativeParameterString(TypeUsage from, string strPrefix, Parameter[] parameter)
        {
            TypeUsage     to        = ParameterMode;
            StringBuilder strParams = new StringBuilder(512);
            string        strComma  = ",";

            if (parameter == null)
            {
                return(strParams.ToString());
            }

            foreach (Parameter param in parameter)
            {
                strParams.Append(strComma);

                string paramElementTypeName = SystemTypeInfo.ElementTypeNameFor(from, param);
                string paramTypeNameOnly    = SystemTypeInfo.TypeNameOnlyFor(from, param);
                string paramTypeFrom        = SystemTypeInfo.TypeNameFor(from, param);
                string paramTypeTo          = SystemTypeInfo.TypeNameFor(to, param);
                bool   paramTypeEquality    = paramTypeFrom == paramTypeTo;
                var    typeInfo             = SystemTypeInfo.GetParameterInfo(param);

                bool bIsStruct = typeInfo.IsCSharpStruct;

                if (param.IsArray)        // array
                {
                    if (IsStrType(param)) // string type
                    {
                        strParams.AppendFormat("{0}{1}Array_", strPrefix, InParamName(param.Name));
                    }
                    else
                    {
                        strParams.AppendFormat("SF::ArrayView<{2}>({0}_sizeOf{1}, {0}_sizeOf{1}, const_cast<{3}>({0}{1}))", strPrefix, InParamName(param.Name), paramElementTypeName, paramTypeNameOnly);
                    }
                }
                else if (IsStrType(param)) // string type
                {
                    strParams.AppendFormat("{0}{1}", strPrefix, InParamName(param.Name));
                }
                else if (IsVariableSizeType(param))
                {
                    strParams.AppendFormat("SF::ArrayView<uint8_t>({0}_sizeOf{1}, {0}_sizeOf{1}, {0}{1})", strPrefix, InParamName(param.Name), paramElementTypeName, paramTypeNameOnly);
                }
                else // generic type
                {
                    if (bIsStruct)
                    {
                        strParams.AppendFormat("{0}{1}", strPrefix, InParamName(param.Name));
                    }
                    else
                    {
                        if (paramTypeEquality)
                        {
                            strParams.AppendFormat(" {0}{1}", strPrefix, InParamName(param.Name));
                        }
                        else
                        {
                            strParams.AppendFormat("({2}) {0}{1}", strPrefix, InParamName(param.Name), paramTypeTo);
                        }
                    }
                }
            }

            return(strParams.ToString());
        }
Exemplo n.º 4
0
        public string CallNativeParameterString(Parameter[] parameter)
        {
            TypeUsage     from      = TypeUsage.CSharp;
            TypeUsage     to        = ParameterMode;
            StringBuilder strParams = new StringBuilder(512);
            string        strComma  = ",";
            string        strPrefix = "";

            if (parameter == null)
            {
                return(strParams.ToString());
            }

            foreach (Parameter param in parameter)
            {
                strParams.Append(strComma);

                string paramElementTypeName = SystemTypeInfo.ElementTypeNameFor(from, param);
                string paramTypeNameOnly    = SystemTypeInfo.TypeNameOnlyFor(from, param);
                string paramTypeFrom        = SystemTypeInfo.TypeNameFor(from, param);
                string paramTypeTo          = SystemTypeInfo.TypeNameFor(to, param);
                var    typeInfo             = SystemTypeInfo.GetParameterInfo(param);
                //Type csharpType = SystemTypeInfo.ToCSharpType(param.Type);
                bool paramTypeEquality = paramTypeFrom == paramTypeTo;

                bool IsArray   = param.IsArray | typeInfo.IsCSharpArray;
                bool bIsStruct = typeInfo.IsCSharpStruct;

                if (IsArray)              // array
                {
                    if (IsStrType(param)) // string type
                    {
                        strParams.AppendFormat("{0}{1}Array.NativeHandle", strPrefix, InParamName(param.Name));
                    }
                    else
                    {
                        strParams.AppendFormat("(ushort){0}{1}.Length, ", strPrefix, InParamName(param.Name));

                        if (typeInfo.IsEnum)
                        {
                            strParams.AppendFormat("GameTypes.ToIntArray({0}{1})", strPrefix, InParamName(param.Name));
                        }
                        else
                        {
                            strParams.AppendFormat("{0}{1}", strPrefix, InParamName(param.Name));
                        }
                    }
                }
                else if (IsStrType(param)) // string type
                {
                    strParams.AppendFormat("System.Text.Encoding.UTF8.GetBytes({0}{1} + \"\\0\")", strPrefix, InParamName(param.Name));
                }
                else if (IsVariableSizeType(param))
                {
                    strParams.AppendFormat("(ushort){0}{1}_.Length, ", strPrefix, InParamName(param.Name));
                    strParams.AppendFormat("{0}{1}_PinnedPtr_.Ptr", strPrefix, InParamName(param.Name));
                }
                else // generic type
                {
                    if (bIsStruct)
                    {
                        if (ParameterMode == TypeUsage.CSharp || ParameterMode == TypeUsage.CSharpNative)
                        {
                            strParams.AppendFormat("ref {0}{1}", strPrefix, InParamName(param.Name));
                        }
                        else
                        {
                            strParams.AppendFormat("{0}{1}", strPrefix, InParamName(param.Name));
                        }
                    }
                    else
                    {
                        if (paramTypeEquality)
                        {
                            strParams.AppendFormat(" {0}{1}", strPrefix, InParamName(param.Name));
                        }
                        else
                        {
                            strParams.AppendFormat("({2}) {0}{1}", strPrefix, InParamName(param.Name), paramTypeTo);
                        }
                    }
                }
            }

            return(strParams.ToString());
        }