Ejemplo n.º 1
0
        private void AppendSetter(CSharpTextBuilder builder, string propertyName, UField setter, List <string> namespaces)
        {
            builder.AppendLine("set");
            builder.OpenBrace();

            UFunction function = setter as UFunction;

            if (function != null)
            {
                AppendFunctionBody(builder, function, false, true, false, namespaces);
            }
            else
            {
                if (Settings.CheckObjectDestroyed)
                {
                    builder.AppendLine(Names.UObject_CheckDestroyed + "();");
                }
                if (Settings.GenerateIsValidSafeguards)
                {
                    builder.AppendLine("if (!" + propertyName + Settings.VarNames.IsValid + ")");
                    builder.OpenBrace();
                    builder.AppendLine(Names.NativeReflection_LogInvalidPropertyAccessed + "(\"" + setter.GetPathName() + "\");");
                    builder.AppendLine("return;");
                    builder.CloseBrace();
                }

                AppendPropertyToNative(builder, setter as UProperty, propertyName, Names.UObject_Address, "this", "value", false, namespaces);
            }

            builder.CloseBrace();
        }
Ejemplo n.º 2
0
        private string GetModuleNamespace(UField field, out UnrealModuleType moduleAssetType, bool allowFoldersAsNamespace = true)
        {
            moduleAssetType = UnrealModuleType.Unknown;
            UPackage package = field.GetOutermost();

            if (package != null)
            {
                CachedNamespace cachedNamespace;
                if (namespaceCache.TryGetValue(package, out cachedNamespace))
                {
                    moduleAssetType = cachedNamespace.ModuleAssetType;
                    return(cachedNamespace.Namespace);
                }

                UnrealModuleType moduleType = UnrealModuleType.Unknown;
                moduleAssetType = UnrealModuleType.Unknown;

                string packageFilename = package.FileName.ToString();
                if (string.IsNullOrEmpty(packageFilename.ToString()) || packageFilename == FName.None.ToString())
                {
                    packageFilename = field.GetPathName();
                }

                string moduleName = FPackageName.GetShortName(package.GetName());
                if (packageFilename.StartsWith("/Script"))
                {
                    if (!modulesByName.TryGetValue(new FName(moduleName), out moduleType))
                    {
                        moduleType = UnrealModuleType.Unknown;
                        FMessage.Log(ELogVerbosity.Error, string.Format("Failed to find module for module '{0}'", moduleName));
                    }
                }
                else if (packageFilename.StartsWith("/Game/"))
                {
                    moduleType      = UnrealModuleType.Game;
                    moduleAssetType = UnrealModuleType.Game;
                    moduleName      = FPaths.GetBaseFilename(FPaths.ProjectFilePath);// {Module} same as {Game}
                }
                else if (packageFilename.StartsWith("/Engine/"))
                {
                    moduleType      = UnrealModuleType.Game;
                    moduleAssetType = UnrealModuleType.Engine;
                    moduleName      = Settings.Namespaces.Default;
                }
                else
                {
                    string rootName = null;
                    if (packageFilename.Length > 1 && packageFilename[0] == '/')
                    {
                        int slashIndex = packageFilename.IndexOf('/', 1);
                        if (slashIndex >= 0)
                        {
                            rootName   = packageFilename.Substring(1, slashIndex - 1);
                            moduleName = rootName;// Update ModuleName for {Module}

                            if (!modulesByName.TryGetValue(new FName(rootName), out moduleAssetType))
                            {
                                moduleAssetType = UnrealModuleType.Unknown;
                            }
                        }
                    }

                    if (moduleAssetType == UnrealModuleType.Unknown)
                    {
                        FMessage.Log(ELogVerbosity.Error, string.Format("Unknown module asset type root:'{0}' path:'{1}' name:'{2}' path2:'{3}'",
                                                                        rootName, packageFilename, field.GetName(), field.GetPathName()));
                    }
                    moduleType = UnrealModuleType.Game;
                }

                if (moduleType != UnrealModuleType.Unknown)
                {
                    string namespaceName = GetModuleNamespace(moduleType, moduleName, moduleAssetType, allowFoldersAsNamespace, packageFilename);
                    namespaceCache[package] = new CachedNamespace(namespaceName, moduleName, moduleType, moduleAssetType);
                    return(namespaceName);
                }
                else
                {
                    FMessage.Log(ELogVerbosity.Error, string.Format("Unknown module type {0} {1}", packageFilename, moduleName));
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
            private void ResolveNameConflicts()
            {
                List <NameConflictInfo> baseConflictInfos = new List <NameConflictInfo>();

                UStruct parentStruct = Struct.GetSuperStruct();

                if (parentStruct != null)
                {
                    StructInfo parentInfo = codeGenerator.GetStructInfo(parentStruct);
                    if (parentInfo != null && parentInfo.conflictInfo != null)
                    {
                        baseConflictInfos.Add(parentInfo.conflictInfo);
                    }
                }

                if (Class != null)
                {
                    foreach (FImplementedInterface implementedInterface in Class.Interfaces)
                    {
                        UClass interfaceClass = implementedInterface.InterfaceClass;
                        if (interfaceClass != null)
                        {
                            StructInfo interfaceInfo = codeGenerator.GetStructInfo(interfaceClass);
                            if (interfaceInfo != null && interfaceInfo.conflictInfo != null)
                            {
                                baseConflictInfos.Add(interfaceInfo.conflictInfo);
                            }
                        }
                    }
                }

                conflictInfo = new NameConflictInfo(this);

                foreach (KeyValuePair <UProperty, string> property in exportableProperties)
                {
                    conflictInfo.AddMember(property.Key, codeGenerator.GetMemberName(property.Key, false, property.Value));
                }

                foreach (UFunction function in exportableFunctions)
                {
                    // Functions are a special case. They can be redefined in the hierarchy but for name resolving
                    // we want them to have the same name throughout. Therefore only resolve the base-most function
                    // name (even if redefined later in the hierarchy). Then when we do a name conflict lookup find that
                    // base-most function and use that name for all of the functions in the hierarchy with that name.
                    // - This is lookup is done in ResolveNameConflict().
                    if (codeGenerator.GetOriginalFunctionOwner(function) == Class)
                    {
                        conflictInfo.AddMember(function, codeGenerator.GetFunctionName(function, false));
                    }
                }

                foreach (NameConflictInfo baseConflictInfo in baseConflictInfos)
                {
                    foreach (KeyValuePair <string, NameConflictFieldInfo> baseMembersByName in baseConflictInfo.MembersByName)
                    {
                        NameConflictFieldInfo baseMembers;
                        if (!conflictInfo.BaseMembersByName.TryGetValue(baseMembersByName.Key, out baseMembers))
                        {
                            conflictInfo.BaseMembersByName.Add(baseMembersByName.Key,
                                                               baseMembers = new NameConflictFieldInfo(baseMembersByName.Key));
                        }

                        foreach (KeyValuePair <UField, CollapsedMember> baseMember in baseMembersByName.Value.Fields)
                        {
                            baseMembers.AddField(baseMember.Key, baseMember.Value);
                        }
                    }

                    foreach (KeyValuePair <string, NameConflictFieldInfo> baseBaseMembersByName in baseConflictInfo.BaseMembersByName)
                    {
                        NameConflictFieldInfo baseBaseMembers;
                        if (!conflictInfo.BaseMembersByName.TryGetValue(baseBaseMembersByName.Key, out baseBaseMembers))
                        {
                            conflictInfo.BaseMembersByName.Add(baseBaseMembersByName.Key,
                                                               baseBaseMembers = new NameConflictFieldInfo(baseBaseMembersByName.Key));
                        }

                        foreach (KeyValuePair <UField, CollapsedMember> baseBaseMember in baseBaseMembersByName.Value.Fields)
                        {
                            baseBaseMembers.AddField(baseBaseMember.Key, baseBaseMember.Value);
                        }
                    }
                }

                var tempMembersByName = new Dictionary <string, NameConflictFieldInfo>(conflictInfo.MembersByName);

                foreach (KeyValuePair <string, NameConflictFieldInfo> membersByName in tempMembersByName)
                {
                    // What about overridden functions? where do they appear?
                    if (membersByName.Value.HasConflict() || conflictInfo.BaseMembersByName.ContainsKey(membersByName.Key))
                    {
                        foreach (KeyValuePair <UField, CollapsedMember> field in membersByName.Value.Fields)
                        {
                            if (field.Value == null)
                            {
                                string hashedName = membersByName.Key + "_" + field.Key.GetPathName().GetHashCode().ToString("X8");
                                NameConflictResolved(field.Key, hashedName);
                            }
                        }

                        foreach (KeyValuePair <CollapsedMember, List <UField> > collapsedMember in membersByName.Value.FieldsByCollapsedMember)
                        {
                            UField field = null;
                            if (collapsedMember.Key.Getter != null)
                            {
                                field = collapsedMember.Key.Getter;
                            }
                            else if (collapsedMember.Key.Setter != null)
                            {
                                field = collapsedMember.Key.Setter;
                            }
                            else if (collapsedMember.Key.BackingProperty != null)
                            {
                                field = collapsedMember.Key.BackingProperty;
                            }

                            string hashedName = membersByName.Key + "_" + field.GetPathName().GetHashCode().ToString("X8");
                            if (collapsedMember.Key.Getter != null)
                            {
                                NameConflictResolved(collapsedMember.Key.Getter, hashedName);
                            }
                            if (collapsedMember.Key.Setter != null)
                            {
                                NameConflictResolved(collapsedMember.Key.Setter, hashedName);
                            }
                            if (collapsedMember.Key.BackingProperty != null)
                            {
                                NameConflictResolved(collapsedMember.Key.BackingProperty, hashedName);
                            }
                        }

                        // All fields with this name should have been renamed. Remove the old name.
                        conflictInfo.MembersByName.Remove(membersByName.Key);
                    }
                }
            }
Ejemplo n.º 4
0
        private void AppendAttribute(CSharpTextBuilder builder, UField field, UnrealModuleInfo module, bool isCollapsedMember)
        {
            UnrealModuleType moduleType;
            UnrealModuleType moduleAssetType;
            string           moduleName = GetModuleName(field, out moduleType, out moduleAssetType);

            if (string.IsNullOrEmpty(moduleName))
            {
                moduleName = module.Name;
            }

            List <string> attributes = new List <string>();

            // TODO: Combine all of this into EPropertyType (add some TypeCode into UField?)
            bool          isInterface  = false;
            UEnum         unrealEnum   = field as UEnum;
            UClass        unrealClass  = field as UClass;
            UScriptStruct unrealStruct = field as UScriptStruct;

            UFunction unrealFunction = field as UFunction;

            if (unrealFunction != null)
            {
                if (unrealFunction.HasAnyFunctionFlags(EFunctionFlags.Delegate))
                {
                    attributes.Add("UDelegate");
                }
                else
                {
                    string additionalFunctionInfo = string.Empty;

                    // TODO: Only get the script name for virtual functions / interface functions as we currently only need
                    //       this for finding the base function for hooking things up to the native base types.
                    string scriptFunctionName;
                    if (unrealFunction.GetScriptName(out scriptFunctionName))
                    {
                        additionalFunctionInfo += ", OriginalName=\"" + unrealFunction.GetName() + "\"";
                    }

                    if (isCollapsedMember)
                    {
                        // The Flags here might not contain too useful information if there is both a get/set function.
                        // Maybe include a second flags var?
                        attributes.Add("UFunctionAsProp(Flags=0x" + ((uint)unrealFunction.FunctionFlags).ToString("X8") + additionalFunctionInfo + ")");
                    }
                    else
                    {
                        attributes.Add("UFunction(Flags=0x" + ((uint)unrealFunction.FunctionFlags).ToString("X8") + additionalFunctionInfo + ")");
                    }
                }
            }

            UProperty unrealProperty = field as UProperty;

            if (unrealProperty != null)
            {
                attributes.Add("UProperty(Flags=(PropFlags)0x" + ((ulong)unrealProperty.PropertyFlags).ToString("X16") + ")");
            }

            if (unrealStruct != null)
            {
                attributes.Add("UStruct(Flags=0x" + ((uint)unrealStruct.StructFlags).ToString("X8") + ")");
            }
            else if (unrealClass != null)
            {
                // Abstract isn't really required but might help with code browsing to know what is abstract
                // and what isn't. Therefore put it at the start of the attributes list.
                if (unrealClass.HasAnyClassFlags(EClassFlags.Abstract))
                {
                    attributes.Add("Abstract");
                }

                isInterface = unrealClass.IsChildOf <UInterface>();
                if (isInterface)
                {
                    attributes.Add("UInterface(Flags=0x" + ((uint)unrealClass.ClassFlags).ToString("X8") + ")");
                }
                else
                {
                    attributes.Add("UClass(Flags=(ClassFlags)0x" + ((uint)unrealClass.ClassFlags).ToString("X8") + ")");
                }
            }

            if (unrealEnum != null)
            {
                attributes.Add("UEnum");
            }

            if (unrealEnum != null || unrealClass != null || unrealStruct != null)
            {
                bool blueprintType = false;
                bool blueprintable = false;
                if (unrealEnum != null)
                {
                    blueprintType = field.GetBoolMetaData(MDClass.BlueprintType);
                }
                else
                {
                    GetBlueprintability(field as UStruct, out blueprintType, out blueprintable);
                }
                if (blueprintType)
                {
                    attributes.Add(UMeta.GetKey(MDClass.BlueprintType));
                }
                if (unrealClass != null && blueprintable)
                {
                    attributes.Add(UMeta.GetKey(MDClass.Blueprintable));
                }

                attributes.Add("UMetaPath(\"" + field.GetPathName() + "\"" +
                               (isInterface ? ", InterfaceImpl=typeof(" + GetTypeName(unrealClass, null) + "Impl" + ")" : string.Empty) + ")");
            }
            else
            {
                attributes.Add("UMetaPath(\"" + field.GetPathName() + "\")");
            }

            if (attributes.Count > 0)
            {
                builder.AppendLine("[" + string.Join(", ", attributes) + "]");
            }
        }
Ejemplo n.º 5
0
        private void AppendAttribute(CSharpTextBuilder builder, UField field, UnrealModuleInfo module, bool isCollapsedMember)
        {
            UnrealModuleType moduleType;
            UnrealModuleType moduleAssetType;
            string           moduleName = GetModuleName(field, out moduleType, out moduleAssetType);

            if (string.IsNullOrEmpty(moduleName))
            {
                moduleName = module.Name;
            }

            List <string> attributes = new List <string>();

            // TODO: Combine all of this into EPropertyType (add some TypeCode into UField?)
            bool          isInterface  = false;
            UEnum         unrealEnum   = field as UEnum;
            UClass        unrealClass  = field as UClass;
            UScriptStruct unrealStruct = field as UScriptStruct;

            UFunction unrealFunction = field as UFunction;

            if (unrealFunction != null)
            {
                if (unrealFunction.HasAnyFunctionFlags(EFunctionFlags.Delegate))
                {
                    attributes.Add("UDelegate");
                }
                else
                {
                    if (isCollapsedMember)
                    {
                        // The Flags here might not contain too useful information if there is both a get/set function.
                        // Maybe include a second flags var?
                        attributes.Add("UFunctionAsProp(Flags=0x" + ((uint)unrealFunction.FunctionFlags).ToString("X8") + ")");
                    }
                    else
                    {
                        attributes.Add("UFunction(Flags=0x" + ((uint)unrealFunction.FunctionFlags).ToString("X8") + ")");
                    }
                }
            }

            UProperty unrealProperty = field as UProperty;

            if (unrealProperty != null)
            {
                attributes.Add("UProperty(Flags=(PropFlags)0x" + ((ulong)unrealProperty.PropertyFlags).ToString("X16") + ")");
            }

            if (unrealStruct != null)
            {
                attributes.Add("UStruct(Flags=0x" + ((uint)unrealStruct.StructFlags).ToString("X8") + ")");
            }
            else if (unrealClass != null)
            {
                // Abstract isn't really required but might help with code browsing to know what is abstract
                // and what isn't. Therefore put it at the start of the attributes list.
                if (unrealClass.HasAnyClassFlags(EClassFlags.Abstract))
                {
                    attributes.Add("Abstract");
                }

                isInterface = unrealClass.IsChildOf <UInterface>();
                if (isInterface)
                {
                    attributes.Add("UInterface(Flags=0x" + ((uint)unrealClass.ClassFlags).ToString("X8") + ")");
                }
                else
                {
                    // Should we skip "inherit" config name?
                    string configNameStr = string.Empty;
                    if (unrealClass.ClassConfigName != FName.None &&
                        !unrealClass.ClassConfigName.ToString().Equals("inherit", StringComparison.InvariantCultureIgnoreCase))
                    {
                        configNameStr = ", Config=\"" + unrealClass.ClassConfigName + "\"";
                    }

                    attributes.Add("UClass(Flags=(ClassFlags)0x" + ((uint)unrealClass.ClassFlags).ToString("X8") +
                                   configNameStr + ")");
                }
            }

            if (unrealEnum != null)
            {
                attributes.Add("UEnum");
            }

            if (unrealEnum != null || unrealClass != null || unrealStruct != null)
            {
                bool blueprintType = false;
                bool blueprintable = false;
                if (unrealEnum != null)
                {
                    blueprintType = field.GetBoolMetaData(MDClass.BlueprintType);
                }
                else
                {
                    GetBlueprintability(field as UStruct, out blueprintType, out blueprintable);
                }
                if (blueprintType)
                {
                    attributes.Add(UMeta.GetKey(MDClass.BlueprintType));
                }
                if (unrealClass != null && blueprintable)
                {
                    attributes.Add(UMeta.GetKey(MDClass.Blueprintable));
                }

                if (isInterface)
                {
                }

                attributes.Add("UMetaPath(\"" + field.GetPathName() + "\", \"" + moduleName +
                               "\", UnrealModuleType." + GetUnrealModuleTypeString(moduleType, moduleAssetType) +
                               (isInterface ? ", InterfaceImpl=typeof(" + GetTypeName(unrealClass, null) + "Impl" + ")" : string.Empty) + ")");
            }
            else
            {
                attributes.Add("UMetaPath(\"" + field.GetPathName() + "\")");
            }

            if (attributes.Count > 0)
            {
                builder.AppendLine("[" + string.Join(", ", attributes) + "]");
            }
        }