Exemplo n.º 1
0
        public Class(string name, VariableType parent, VariableType outer, UnrealFlags.EClassFlags flags,
                     List <VariableType> interfaces           = null,
                     List <VariableType> types                = null,
                     List <VariableDeclaration> vars          = null,
                     List <Function> funcs                    = null,
                     List <State> states                      = null,
                     DefaultPropertiesBlock defaultProperties = null,
                     SourcePosition start                     = null, SourcePosition end = null)
            : base(name, start, end, EPropertyType.Object)
        {
            Parent               = parent;
            OuterClass           = outer;
            Flags                = flags;
            Interfaces           = interfaces ?? new List <VariableType>();
            VariableDeclarations = vars ?? new List <VariableDeclaration>();
            TypeDeclarations     = types ?? new List <VariableType>();
            Functions            = funcs ?? new List <Function>();
            States               = states ?? new List <State>();
            DefaultProperties    = defaultProperties ?? new DefaultPropertiesBlock();
            Type = ASTNodeType.Class;

            foreach (ASTNode node in ChildNodes)
            {
                node.Outer = this;
            }
        }
Exemplo n.º 2
0
        public bool VisitNode(Class node)
        {
            // class classname extends parentclass [within outerclass] [specifiers] ;
            Write($"{CLASS} {node.Name}");

            if (node.Parent != null && !node.Parent.Name.Equals("Object", StringComparison.OrdinalIgnoreCase))
            {
                Append($" {EXTENDS} {node.Parent.Name}");
            }
            if (node.OuterClass != null && !node.OuterClass.Name.Equals("Object", StringComparison.OrdinalIgnoreCase))
            {
                Append($" {WITHIN} {node.OuterClass.Name}");
            }

            NestingLevel++;

            if (node.Interfaces.Any())
            {
                Write($"implements({string.Join(", ", node.Interfaces.Select(i => i.Name))})");
            }

            UnrealFlags.EClassFlags flags = node.Flags;
            if (flags.Has(UnrealFlags.EClassFlags.Native))
            {
                Write("native");
            }
            if (flags.Has(UnrealFlags.EClassFlags.NativeOnly))
            {
                Write("nativeonly");
            }
            if (flags.Has(UnrealFlags.EClassFlags.NoExport))
            {
                Write("noexport");
            }
            if (flags.Has(UnrealFlags.EClassFlags.EditInlineNew))
            {
                Write("editinlinenew");
            }
            if (flags.Has(UnrealFlags.EClassFlags.Placeable))
            {
                Write("placeable");
            }
            if (flags.Has(UnrealFlags.EClassFlags.HideDropDown))
            {
                Write("hidedropdown");
            }
            if (flags.Has(UnrealFlags.EClassFlags.NativeReplication))
            {
                Write("nativereplication");
            }
            if (flags.Has(UnrealFlags.EClassFlags.PerObjectConfig))
            {
                Write("perobjectconfig");
            }
            if (flags.Has(UnrealFlags.EClassFlags.Localized))
            {
                Write("localized");
            }
            if (flags.Has(UnrealFlags.EClassFlags.Abstract))
            {
                Write("abstract");
            }
            if (flags.Has(UnrealFlags.EClassFlags.Deprecated))
            {
                Write("deprecated");
            }
            if (flags.Has(UnrealFlags.EClassFlags.Transient))
            {
                Write("transient");
            }
            if (flags.Has(UnrealFlags.EClassFlags.Config))
            {
                Write($"config({node.ConfigName})");
            }
            if (flags.Has(UnrealFlags.EClassFlags.SafeReplace))
            {
                Write("safereplace");
            }
            if (flags.Has(UnrealFlags.EClassFlags.Hidden))
            {
                Write("hidden");
            }
            if (flags.Has(UnrealFlags.EClassFlags.CollapseCategories))
            {
                Write("collapsecategories");
            }

            NestingLevel--;
            Append(";");

            // print the rest of the class, according to the standard "anatomy of an unrealscript" article.
            if (node.TypeDeclarations.Count > 0)
            {
                Write("");
                Write("// Types");
                foreach (VariableType type in node.TypeDeclarations)
                {
                    type.AcceptVisitor(this);
                }
            }

            if (node.VariableDeclarations.Count > 0)
            {
                Write("");
                Write("// Variables");
                foreach (VariableDeclaration decl in node.VariableDeclarations)
                {
                    decl.AcceptVisitor(this);
                }
            }

            if (node.Functions.Count > 0)
            {
                Write("");
                Write("// Functions");
                foreach (Function func in node.Functions)
                {
                    func.AcceptVisitor(this);
                }
            }

            if (node.States.Count > 0)
            {
                Write("");
                Write("// States");
                foreach (State state in node.States)
                {
                    state.AcceptVisitor(this);
                }
            }

            Write("");
            node.DefaultProperties?.AcceptVisitor(this);

            return(true);
        }