Esempio n. 1
0
        /// <summary>
        /// Returns true if the property address is required by generated code
        /// </summary>
        private bool RequiresNativePropertyField(UProperty property)
        {
            if (!Settings.LazyFunctionParamInitDestroy && property.GetOwnerStruct().IsA <UFunction>())
            {
                // We need the property address to call InitializeValue / DestroyValue
                if (!property.HasAllPropertyFlags(EPropertyFlags.ZeroConstructor | EPropertyFlags.NoDestructor))
                {
                    return(true);
                }
                return(true);
            }

            if (property.IsFixedSizeArray)
            {
                return(true);
            }
            switch (property.PropertyType)
            {
            case EPropertyType.Enum:
            case EPropertyType.Bool:
            case EPropertyType.Array:
            case EPropertyType.Set:
            case EPropertyType.Map:
                return(true);

            default:
                UNumericProperty numericProperty = property as UNumericProperty;
                if ((numericProperty != null && numericProperty.IsEnum && numericProperty.GetIntPropertyEnum() != null))
                {
                    return(true);
                }
                break;
            }

            return(false);
        }
Esempio n. 2
0
        private string GetMarshalerFromProperty(UProperty property, List <string> namespaces, bool isFunction, bool fixedSizeArrayInnerMarshaler)
        {
            if (property.IsFixedSizeArray && !fixedSizeArrayInnerMarshaler)
            {
                if (IsOwnerClassOrStructAsClass(property))
                {
                    return(GetTypeName(property, namespaces));
                }
                else
                {
                    // Should expect either a UClass or a UScriptStruct. Fixed sized arrays aren't supported on functions in unreal.
                    System.Diagnostics.Debug.Assert(property.GetOwnerStruct().IsA <UScriptStruct>());

                    return(Names.TFixedSizeArrayMarshaler + "<" + GetTypeName(property, namespaces) + ">");
                    //// FixedSizeArrayMarshaler<int, BlittableTypeMarshaler<int>>
                    //return Names.FixedSizeArrayMarshaler + "<" + GetTypeName(property, namespaces) + ", " +
                    //    GetMarshalerFromProperty(property, namespaces, isFunction, true) + ">";
                }
            }

            UNumericProperty numericProperty = property as UNumericProperty;

            if ((numericProperty != null && numericProperty.IsEnum && numericProperty.GetIntPropertyEnum() != null) ||
                property.PropertyType == EPropertyType.Enum)
            {
                UEnum unrealEnum = null;
                if (property.PropertyType == EPropertyType.Enum)
                {
                    unrealEnum = (property as UEnumProperty).GetEnum();
                }
                else
                {
                    unrealEnum = numericProperty.GetIntPropertyEnum();
                }
                return(Names.EnumMarshaler + "<" + GetTypeName(unrealEnum, namespaces) + ">");
            }

            string blittableTypeName = GetBlittablePropertyTypeName(property, namespaces);

            if (!string.IsNullOrEmpty(blittableTypeName))
            {
                return(Names.BlittableTypeMarshaler + "<" + blittableTypeName + ">");
            }

            switch (property.PropertyType)
            {
            case EPropertyType.Bool:
                return(Names.BoolMarshaler);

            case EPropertyType.Str: return(Names.FStringMarshaler);

            case EPropertyType.Text: return(Names.FTextMarshaler);

            case EPropertyType.Struct:
            {
                UStruct unrealStruct = (property as UStructProperty).Struct;
                if (IsClassOrStructAsClass(unrealStruct))
                {
                    return(Names.StructAsClassMarshaler + "<" + GetTypeName(property, namespaces) + ">");
                }
                else
                {
                    // Normal structs use their own type name and have static FromNative/ToNative methods
                    return(GetTypeName(property, namespaces));
                }
            }

            case EPropertyType.Delegate:
            {
                string delegateTypeName = GetTypeName(property, namespaces);
                return(Names.FDelegateMarshaler + "<" + delegateTypeName + ">");
            }

            case EPropertyType.MulticastDelegate:
            {
                string delegateTypeName = GetTypeName(property, namespaces);
                return(Names.FMulticastDelegateMarshaler + "<" + delegateTypeName + ">");
            }

            case EPropertyType.Array:
            {
                string arrayMarshalerName = Names.TArrayReadWriteMarshaler;
                if (IsOwnerClassOrStructAsClass(property))
                {
                    if (property.HasAnyPropertyFlags(EPropertyFlags.BlueprintReadOnly))
                    {
                        arrayMarshalerName = Names.TArrayReadOnlyMarshaler;
                    }
                }
                else
                {
                    arrayMarshalerName = Names.TArrayCopyMarshaler;
                }
                UArrayProperty arrayProperty = property as UArrayProperty;
                return(arrayMarshalerName + "<" + GetTypeName(arrayProperty.Inner, namespaces) + ">");
            }

            case EPropertyType.Set:
            {
                string setMarshalerName = Names.TSetReadWriteMarshaler;
                if (IsOwnerClassOrStructAsClass(property))
                {
                    if (property.HasAnyPropertyFlags(EPropertyFlags.BlueprintReadOnly))
                    {
                        setMarshalerName = Names.TSetReadOnlyMarshaler;
                    }
                }
                else
                {
                    setMarshalerName = Names.TSetCopyMarshaler;
                }
                USetProperty setProperty = property as USetProperty;
                return(setMarshalerName + "<" + GetTypeName(setProperty.ElementProp, namespaces) + ">");
            }

            case EPropertyType.Map:
            {
                string mapMarshalerName = Names.TMapReadWriteMarshaler;
                if (IsOwnerClassOrStructAsClass(property))
                {
                    if (property.HasAnyPropertyFlags(EPropertyFlags.BlueprintReadOnly))
                    {
                        mapMarshalerName = Names.TMapReadOnlyMarshaler;
                    }
                }
                else
                {
                    mapMarshalerName = Names.TMapCopyMarshaler;
                }
                UMapProperty mapProperty = property as UMapProperty;
                return(mapMarshalerName + "<" + GetTypeName(mapProperty.KeyProp, namespaces) + ", " +
                       GetTypeName(mapProperty.ValueProp, namespaces) + ">");
            }

            case EPropertyType.Class:
            {
                UClass targetClass             = (property as UClassProperty).MetaClass;
                string subclassOfMarshalerName = null;
                if (targetClass.ClassFlags.HasFlag(EClassFlags.Interface))
                {
                    subclassOfMarshalerName = Names.TSubclassOfInterfaceMarshaler;
                }
                else
                {
                    subclassOfMarshalerName = Names.TSubclassOfMarshaler;
                }
                return(subclassOfMarshalerName + "<" + GetTypeName(targetClass, namespaces) + ">");
            }

            case EPropertyType.Interface: return(Names.InterfaceMarshaler + "<" + GetTypeName((property as UInterfaceProperty).InterfaceClass, namespaces) + ">");

            case EPropertyType.Object: return(Names.UObjectMarshaler + "<" + GetTypeName((property as UObjectProperty).PropertyClass, namespaces) + ">");

            case EPropertyType.WeakObject: return(Names.TWeakObjectMarshaler + "<" + GetTypeName((property as UWeakObjectProperty).PropertyClass, namespaces) + ">");

            case EPropertyType.LazyObject: return(Names.TLazyObjectMarshaler + "<" + GetTypeName((property as ULazyObjectProperty).PropertyClass, namespaces) + ">");

            case EPropertyType.SoftClass: return(Names.TSoftClassMarshaler + "<" + GetTypeName((property as USoftClassProperty).MetaClass, namespaces) + ">");

            case EPropertyType.SoftObject: return(Names.TSoftObjectMarshaler + "<" + GetTypeName((property as USoftObjectProperty).PropertyClass, namespaces) + ">");

            default: return(null);
            }
        }