protected Method.Parameter AllocateLocalVariable <TVariable>(string variableName)
        {
            var parameter = new Method.Parameter(typeof(TVariable), variableName);

            Variables.Add(parameter);
            return(parameter);
        }
Пример #2
0
        /// <summary>
        /// Generates the methods of a class.
        /// </summary>
        /// <param name="classObj">The class object.</param>
        /// <returns>Return The methods of the class.</returns>
        private async Task <List <Method> > GenerateMethods(GenericTypes.UEClass classObj)
        {
            var methods = new List <Method>();

            //some classes (AnimBlueprintGenerated...) have multiple members with the same name, so filter them out
            var uniqueMethods = new List <string>();

            // prop can be UEObject, UEField, UEProperty
            for (var prop = (await classObj.GetChildren()).Cast <GenericTypes.UEField>(); prop.IsValid(); prop = await prop.GetNext())
            {
                if (!await prop.IsA <GenericTypes.UEFunction>())
                {
                    continue;
                }

                var function = prop.Cast <GenericTypes.UEFunction>();

                var m = new Method
                {
                    Index    = function.GetIndex(),
                    FullName = await function.GetFullName(),
                    Name     = Generator.GetSafeKeywordsName(NameValidator.MakeValidName(await function.GetName()))
                };

                if (uniqueMethods.Contains(m.FullName))
                {
                    continue;
                }

                uniqueMethods.Add(m.FullName);

                m.IsNative    = (await function.GetFunctionFlags()).HasFlag(UEFunctionFlags.Native);
                m.IsStatic    = (await function.GetFunctionFlags()).HasFlag(UEFunctionFlags.Static);
                m.FlagsString = FunctionFlags.StringifyFlags(await function.GetFunctionFlags());

                var parameters = new List <KeyValuePair <GenericTypes.UEProperty, Method.Parameter> >();
                var unique     = new Dictionary <string, int>();
                for (var param = (await function.GetChildren()).Cast <GenericTypes.UEProperty>(); param.IsValid(); param = (await param.GetNext()).Cast <GenericTypes.UEProperty>())
                {
                    if (await param.GetElementSize() == 0)
                    {
                        continue;
                    }

                    var info = await param.GetInfo();

                    if (info.Type == GenericTypes.UEProperty.PropertyType.Unknown)
                    {
                        continue;
                    }

                    var p = new Method.Parameter(UnrealVersion.Unreal4);

                    if (!p.MakeType(await param.GetPropertyFlags(), out p.ParamType))
                    {
                        //child isn't a parameter
                        continue;
                    }

                    p.PassByReference = false;
                    p.Name            = NameValidator.MakeValidName(await param.GetName());

                    if (!unique.ContainsKey(p.Name))
                    {
                        unique[p.Name] = 1;
                    }
                    else
                    {
                        unique[p.Name]++;
                        p.Name += unique[p.Name];
                    }

                    p.FlagsString = PropertyFlags.StringifyFlags(await param.GetPropertyFlags());
                    p.CppType     = info.CppType;

                    if (await param.IsA <GenericTypes.UEBoolProperty>())
                    {
                        p.CppType = Generator.GetOverrideType("bool");
                    }

                    if (p.ParamType == Method.Parameter.Type.Default)
                    {
                        if (await param.GetArrayDim() > 1)
                        {
                            p.CppType += "*";
                        }
                        else if (info.CanBeReference)
                        {
                            p.PassByReference = true;
                        }
                    }

                    p.Name = Generator.GetSafeKeywordsName(p.Name);
                    parameters.Add(new KeyValuePair <GenericTypes.UEProperty, Method.Parameter>(param, p));
                }

                parameters.Sort((lhs, rhs) => ComparePropertyLess(lhs.Key, rhs.Key).Result ? 0 : 1);

                foreach (var param in parameters)
                {
                    m.Parameters.Add(param.Value);
                }

                methods.Add(m);
            }

            return(methods);
        }