Ejemplo n.º 1
0
        public void Continue()
        {
            var builder = new StatementListBuilder();

            builder
            .AddForeach(0, 136, "Outer.WorldInfo.AllControllers(Class'PlayerController', PC)")
            .AddJumpIfNot(37, 135, "PC.bIsPlayer && PC.IsLocalPlayerController()")
            .Add(79, "DCC = (DebugCameraController) PC")
            .AddJumpIfNot(95, 132, "DCC != None && DCC.OryginalControllerRef == None")
            .AddIteratorNext(128)
            .AddJump(129, 136)
            .AddJump(132, 136)
            .AddIteratorNext(135)
            .AddIteratorPop(136)
            .AddReturn(137);
            VerifyText(builder,
                       "foreach Outer.WorldInfo.AllControllers(Class'PlayerController', PC)",
                       "{",
                       "    if (PC.bIsPlayer && PC.IsLocalPlayerController())",
                       "    {",
                       "        DCC = (DebugCameraController) PC;",
                       "        if (DCC != None && DCC.OryginalControllerRef == None)",
                       "        {",
                       "            continue;",
                       "        }",
                       "        break;",
                       "    }",
                       "}");
        }
Ejemplo n.º 2
0
        public void BreakInWhile()
        {
            var builder = new StatementListBuilder();

            builder
            .AddJumpIfNot(11, 180, "CurrentMove != None")
            .AddJumpIfNot(22, 174, "CurrentMove.TimeStamp <= CurrentTimeStamp")
            .Add(70, "LastAckedAccel = CurrentMove.Acceleration")
            .AddJump(171, 177)
            .AddJump(174, 180)
            .AddJump(177, 11)
            .AddReturn(180);
            VerifyText(builder,
                       "while (CurrentMove != None)",
                       "{",
                       "    if (CurrentMove.TimeStamp <= CurrentTimeStamp)",
                       "    {",
                       "        LastAckedAccel = CurrentMove.Acceleration;",
                       "    }",
                       "    else",
                       "    {",
                       "        break;",
                       "    }",
                       "}");
        }
Ejemplo n.º 3
0
        public void IfElseReturn()
        {
            var builder = new StatementListBuilder();

            builder
            .AddJumpIfNot(0, 112, "!bGameRelevant")
            .AddJumpIfNot(87, 109, "bNoDelete")
            .Add(96, "ShutDown()")
            .AddJump(106, 112)
            .Add(109, "Destroy()")
            .AddReturn(112);

            VerifyText(builder,
                       "if (!bGameRelevant)",
                       "{",
                       "    if (bNoDelete)",
                       "    {",
                       "        ShutDown();",
                       "    }",
                       "    else",
                       "    {",
                       "        Destroy();",
                       "    }",
                       "}");
        }
Ejemplo n.º 4
0
        public void BreakInElseInForeach()
        {
            var builder = new StatementListBuilder();

            builder
            .AddForeach(320, 438, "LocalPlayerControllers(Class'PlayerController', P)")
            .AddJumpIfNot(339, 437, "P.ViewTarget != None")
            .AddJumpIfNot(359, 402, "P.Pawn == Instigator && Instigator != None")
            .AddIteratorPop(396)
            .AddReturn(397, "true")
            .AddJump(399, 437)
            .Add(402, "bResult = CheckMaxEffectDistance(P, SpawnLocation, CullDistance)")
            .AddJump(434, 438)
            .AddIteratorNext(437)
            .AddIteratorPop(438)
            .AddReturn(439, "bResult");
            VerifyText(builder,
                       "foreach LocalPlayerControllers(Class'PlayerController', P)",
                       "{",
                       "    if (P.ViewTarget != None)",
                       "    {",
                       "        if (P.Pawn == Instigator && Instigator != None)",
                       "        {",
                       "            return true;",
                       "        }",
                       "        else",
                       "        {",
                       "            bResult = CheckMaxEffectDistance(P, SpawnLocation, CullDistance);",
                       "            break;",
                       "        }",
                       "    }",
                       "}",
                       "return bResult;");
        }
Ejemplo n.º 5
0
        public void While()
        {
            var builder = new StatementListBuilder();

            builder
            .AddJumpIfNot(0, 182, "Len(Text) > 0")
            .Add(13, "Character = Asc(Left(Text, 1))")
            .Add(29, "Text = Mid(Text, 1)")
            .AddJumpIfNot(44, 179, "Character >= 32 && Character < 256 && Character != Asc(\"~\") && Character != Asc(\"`\")")
            .Add(107, "SetInputText(Left(TypedStr, TypedStrPos) $ Chr(Character) $ Right(TypedStr, Len(TypedStr) - TypedStrPos))")
            .Add(161, "SetCursorPos(TypedStrPos + 1)")
            .AddJump(179, 0)
            .AddReturn(182);

            VerifyText(builder,
                       "while (Len(Text) > 0)",
                       "{",
                       "    Character = Asc(Left(Text, 1));",
                       "    Text = Mid(Text, 1);",
                       "    if (Character >= 32 && Character < 256 && Character != Asc(\"~\") && Character != Asc(\"`\"))",
                       "    {",
                       "        SetInputText(Left(TypedStr, TypedStrPos) $ Chr(Character) $ Right(TypedStr, Len(TypedStr) - TypedStrPos));",
                       "        SetCursorPos(TypedStrPos + 1);",
                       "    }",
                       "}");
        }
Ejemplo n.º 6
0
        private static string PrintText(StatementListBuilder builder)
        {
            builder.List.CreateControlStatements();
            builder.List.RemoveRedundantReturns();
            var result = new TextBuilder();

            builder.List.Print(result, null, false);
            return(result.ToString());
        }
Ejemplo n.º 7
0
        private static void VerifyText(StatementListBuilder builder, params string[] lines)
        {
            string text     = PrintText(builder);
            var    expected = new StringBuilder();

            foreach (var line in lines)
            {
                expected.Append("    ").Append(line).Append("\r\n");
            }
            Assert.AreEqual(expected.ToString(), text);
        }
Ejemplo n.º 8
0
        public void BreakInIfInForeach()
        {
            var builder = new StatementListBuilder();

            builder
            .AddForeach(0, 99, "Outer.WorldInfo.AllControllers(Class'Controller', P)")
            .AddJumpIfNot(37, 98, "P.bIsPlayer && P.PlayerReplicationInfo.GetPlayerAlias() ~= S")
            .AddJump(95, 99)
            .AddIteratorNext(98)
            .AddIteratorPop(99)
            .AddReturn(100);
            VerifyText(builder,
                       "foreach Outer.WorldInfo.AllControllers(Class'Controller', P)",
                       "{",
                       "    if (P.bIsPlayer && P.PlayerReplicationInfo.GetPlayerAlias() ~= S)",
                       "    {",
                       "        break;",
                       "    }",
                       "}");
        }
Ejemplo n.º 9
0
        public void IfInForeach()
        {
            var builder = new StatementListBuilder();

            builder
            .AddForeach(175, 238, "Outer.DynamicActors(Class'Actor', A)")
            .AddJumpIfNot(200, 237, "ClassIsChildOf(A.Class, aClass)")
            .Add(225, "A.Destroy()")
            .AddIteratorNext(237)
            .AddIteratorPop(238)
            .AddReturn(239);
            VerifyText(builder,
                       "foreach Outer.DynamicActors(Class'Actor', A)",
                       "{",
                       "    if (ClassIsChildOf(A.Class, aClass))",
                       "    {",
                       "        A.Destroy();",
                       "    }",
                       "}");
        }
Ejemplo n.º 10
0
        public void Switch()
        {
            var builder = new StatementListBuilder();

            builder
            .AddSwitch(0, "Physics")
            .AddCase(7, "0")
            .AddReturn(12, "\"None\"")
            .AddJump(19, 232)
            .AddDefaultCase(229)
            .AddReturn(232, "\"Unknown\"");

            VerifyText(builder,
                       "switch (Physics)",
                       "{",
                       "    case 0:",
                       "        return \"None\";",
                       "}",
                       "return \"Unknown\";");
        }
Ejemplo n.º 11
0
        public void ForEachSimple()
        {
            var builder = new StatementListBuilder();

            builder
            .AddForeach(0, 52, "Outer.DynamicActors(Class'Actor', A)")
            .Add(25, "I++")
            .Add(32, "LogInternal(I @ A))")
            .AddIteratorNext(51)
            .AddIteratorPop(52)
            .Add(53, "LogInternal(\"Num dynamic actors: \" $ I)")
            .AddReturn(87);
            VerifyText(builder,
                       "foreach Outer.DynamicActors(Class'Actor', A)",
                       "{",
                       "    I++;",
                       "    LogInternal(I @ A));",
                       "}",
                       "LogInternal(\"Num dynamic actors: \" $ I);");
        }
Ejemplo n.º 12
0
        public void ReturnInElse()
        {
            var builder = new StatementListBuilder();

            builder
            .Add(0, "P = Pawn(TheActor)")
            .AddJumpIfNot(16, 36, "P != None")
            .AddReturn(27, "P")
            .AddJump(33, 81)
            .Add(36, "C = Controller(TheActor)")
            .AddReturn(52, "C != None ? C.Pawn : None");
            VerifyText(builder,
                       "P = Pawn(TheActor);",
                       "if (P != None)",
                       "{",
                       "    return P;",
                       "}",
                       "else",
                       "{",
                       "    C = Controller(TheActor);",
                       "    return C != None ? C.Pawn : None;",
                       "}");
        }
Ejemplo n.º 13
0
        public void SwitchNoBreak()
        {
            var builder = new StatementListBuilder();

            builder
            .AddSwitch(0, "SplitscreenType")
            .AddCase(7, "0")
            .AddCase(12, "2")
            .AddReturn(17, "true")
            .AddDefaultCase(72)
            .AddReturn(75, "false")
            .AddErrorReturn(77, "// invalid");

            VerifyText(builder,
                       "switch (SplitscreenType)",
                       "{",
                       "    case 0:",
                       "    case 2:",
                       "        return true;",
                       "    default:",
                       "        return false;",
                       "}");
        }
Ejemplo n.º 14
0
        public void ReturnInForeach()
        {
            var builder = new StatementListBuilder();

            builder
            .AddForeach(0, 106, "Outer.AllActors(Class'Actor', A)")
            .AddJumpIfNot(25, 105, "A.Name == actorName")
            .Add(49, "Outer.SetViewTarget(A)")
            .AddIteratorPop(102)
            .AddReturn(103)
            .AddIteratorNext(105)
            .AddIteratorPop(106)
            .AddReturn(107);
            VerifyText(builder,
                       "foreach Outer.AllActors(Class'Actor', A)",
                       "{",
                       "    if (A.Name == actorName)",
                       "    {",
                       "        Outer.SetViewTarget(A);",
                       "        return;",
                       "    }",
                       "}");
        }
Ejemplo n.º 15
0
        //------------------------------------------------------------
        // FUNCBREC.BindCollectionInitializer
        //
        /// <summary></summary>
        /// <param name="newNode"></param>
        /// <param name="typeSym"></param>
        /// <param name="locVarSym"></param>
        /// <param name="objectExpr"></param>
        /// <param name="builder"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal EXPR BindCollectionInitializer(
            NEWNODE newNode,
            BASENODE elementsNode,
            TYPESYM typeSym,
            LOCVARSYM locVarSym,
            EXPR leftExpr,
            EXPR rightExpr,
            StatementListBuilder builder)
        {
            DebugUtil.Assert(newNode != null && typeSym != null && builder != null);
            DebugUtil.Assert(locVarSym != null || leftExpr != null || rightExpr != null);

            string addMethName = Compiler.NameManager.GetPredefinedName(PREDEFNAME.ADD);

            //--------------------------------------------------------
            // typeSym should implement IEnumerable.
            //--------------------------------------------------------
            AGGTYPESYM enumerableSym = HasIEnumerable(typeSym);

            if (enumerableSym == null)
            {
                Compiler.Error(
                    newNode.TypeNode,
                    CSCERRID.ERR_CollectInitRequiresIEnumerable,
                    new ErrArg(typeSym));
                return(rightExpr);
            }

            TYPESYM   paramTypeSym = null;
            TypeArray typeArgs     = enumerableSym.TypeArguments;

            if (typeArgs != null && typeArgs.Count > 0)
            {
                DebugUtil.Assert(typeArgs.Count == 1);
                paramTypeSym = typeArgs[0];
            }
            else
            {
                paramTypeSym
                    = Compiler.GetReqPredefAgg(PREDEFTYPE.OBJECT, true).GetThisType();
                if (typeArgs == null)
                {
                    typeArgs = new TypeArray();
                }
                typeArgs.Add(paramTypeSym);
                typeArgs = Compiler.MainSymbolManager.AllocParams(typeArgs);
            }

            BindFlagsEnum bindFlags   = BindFlagsEnum.RValueRequired;
            string        localFormat = "<{0}><{1}>__local";

            //--------------------------------------------------------
            // Bind the local variable.
            //--------------------------------------------------------
            if (leftExpr == null)
            {
                if (locVarSym == null)
                {
                    string locName
                        = String.Format(localFormat, typeSym.Name, (this.localCount)++);

                    locVarSym = Compiler.LocalSymbolManager.CreateLocalSym(
                        SYMKIND.LOCVARSYM,
                        locName,
                        this.currentScopeSym) as LOCVARSYM;
                    locVarSym.TypeSym             = typeSym;
                    locVarSym.LocSlotInfo.HasInit = true;
                    locVarSym.DeclTreeNode        = newNode;

                    StoreInCache(newNode, locName, locVarSym, null, true);
                }

                leftExpr = BindToLocal(
                    newNode,
                    locVarSym,
                    bindFlags | BindFlagsEnum.MemberSet);
            }

            //--------------------------------------------------------
            // If objectExpr is not null, assign it to the local variable.
            //--------------------------------------------------------
            if (rightExpr != null)
            {
                EXPR assignLocExpr = BindAssignment(
                    newNode,
                    leftExpr,
                    rightExpr,
                    false);

                builder.Add(SetNodeStmt(newNode, MakeStmt(newNode, assignLocExpr, 0)));
            }

            //--------------------------------------------------------
            // Get "Add" method.
            //--------------------------------------------------------
            MemberLookup mem = new MemberLookup();

            if (!mem.Lookup(
                    Compiler,
                    typeSym,
                    leftExpr,
                    this.parentDeclSym,
                    addMethName,
                    0,
                    MemLookFlagsEnum.UserCallable))
            {
                Compiler.Error(
                    newNode.TypeNode,
                    CSCERRID.ERR_NoSuchMember,
                    new ErrArg(typeSym),
                    new ErrArg("Add"));
                return(NewError(newNode, null));
            }
            if (mem.FirstSym == null || !mem.FirstSym.IsMETHSYM)
            {
                return(NewError(newNode, null));
            }

            TypeArray typeGroup = mem.GetAllTypes();

            EXPRMEMGRP grpExpr = NewExpr(
                newNode,
                EXPRKIND.MEMGRP,
                Compiler.MainSymbolManager.MethodGroupTypeSym) as EXPRMEMGRP;

            grpExpr.Name                = addMethName;
            grpExpr.SymKind             = SYMKIND.METHSYM;
            grpExpr.TypeArguments       = BSYMMGR.EmptyTypeArray;
            grpExpr.ParentTypeSym       = typeSym;
            grpExpr.MethPropSym         = null;
            grpExpr.ObjectExpr          = leftExpr;
            grpExpr.ContainingTypeArray = typeGroup;
            grpExpr.Flags              |= EXPRFLAG.USERCALLABLE;

            //--------------------------------------------------------
            // Add each value.
            //--------------------------------------------------------
            DebugUtil.Assert(newNode.InitialNode != null);
#if false
            BASENODE node = null;
            switch (newNode.InitialNode.Kind)
            {
            case NODEKIND.DECLSTMT:
                node = (newNode.InitialNode as DECLSTMTNODE).VariablesNode;
                break;

            case NODEKIND.UNOP:
                node = (newNode.InitialNode as UNOPNODE).Operand;
                break;

            default:
                DebugUtil.Assert(false);
                break;
            }
#endif
            BASENODE node = elementsNode;
            while (node != null)
            {
                BASENODE elementNode;
                if (node.Kind == NODEKIND.LIST)
                {
                    elementNode = node.AsLIST.Operand1;
                    node        = node.AsLIST.Operand2;
                }
                else
                {
                    elementNode = node;
                    node        = null;
                }

                //----------------------------------------------------
                // Bind the elements
                //----------------------------------------------------
                EXPR elementExpr = BindExpr(
                    elementNode,
                    BindFlagsEnum.RValueRequired);

                //----------------------------------------------------
                // Add the elements
                //----------------------------------------------------
                EXPR addExpr = BindGrpToArgs(newNode, bindFlags, grpExpr, elementExpr);

                if (addExpr != null)
                {
                    builder.Add(SetNodeStmt(newNode, MakeStmt(newNode, addExpr, 0)));
                }
            }

            return(leftExpr);
        }
Ejemplo n.º 16
0
        //------------------------------------------------------------
        // FUNCBREC.BindObjectInitializer
        //
        /// <summary></summary>
        /// <param name="newNode"></param>
        /// <param name="typeSym"></param>
        /// <param name="locVarSym"></param>
        /// <param name="objectExpr"></param>
        /// <param name="builder"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal EXPR BindObjectInitializer(
            NEWNODE newNode,
            TYPESYM typeSym,
            LOCVARSYM locVarSym,
            EXPR objectExpr,
            StatementListBuilder builder)
        {
            DebugUtil.Assert(newNode != null && typeSym != null && builder != null);
            DebugUtil.Assert(
                (locVarSym != null && objectExpr == null) ||
                (locVarSym == null && objectExpr != null));

            BindFlagsEnum bindFlags   = BindFlagsEnum.RValueRequired;
            string        localFormat = "<{0}><{1}>__local";

            //--------------------------------------------------------
            // Bind the local variable.
            //--------------------------------------------------------
            if (locVarSym == null)
            {
                string typeName = typeSym.IsAGGTYPESYM ?
                                  (typeSym as AGGTYPESYM).GetAggregate().Name :
                                  typeSym.Name;
                string locName = String.Format(localFormat, typeName, (this.localCount)++);

                locVarSym = Compiler.LocalSymbolManager.CreateLocalSym(
                    SYMKIND.LOCVARSYM,
                    locName,
                    this.currentScopeSym) as LOCVARSYM;
                locVarSym.TypeSym             = typeSym;
                locVarSym.LocSlotInfo.HasInit = true;
                locVarSym.DeclTreeNode        = newNode;

                StoreInCache(newNode, locName, locVarSym, null, true);
            }

            EXPR locVarExpr = BindToLocal(
                newNode,
                locVarSym,
                bindFlags | BindFlagsEnum.MemberSet);

            //--------------------------------------------------------
            // If objectExpr is not null, assign it to the local variable.
            //--------------------------------------------------------
            if (objectExpr != null)
            {
                EXPR assignLocExpr = BindAssignment(
                    newNode,
                    locVarExpr,
                    objectExpr,
                    false);

                builder.Add(SetNodeStmt(newNode, MakeStmt(newNode, assignLocExpr, 0)));
            }

            //--------------------------------------------------------
            // Assign each value.
            //--------------------------------------------------------
            DECLSTMTNODE decNode = newNode.InitialNode as DECLSTMTNODE;

            DebugUtil.Assert(decNode != null);
            BASENODE node = decNode.VariablesNode;

            while (node != null)
            {
                VARDECLNODE varDecl;
                if (node.Kind == NODEKIND.LIST)
                {
                    varDecl = node.AsLIST.Operand1 as VARDECLNODE;
                    node    = node.AsLIST.Operand2;
                }
                else
                {
                    varDecl = node as VARDECLNODE;
                    node    = null;
                }

                BINOPNODE assignNode = varDecl.ArgumentsNode as BINOPNODE;
                if (assignNode == null ||
                    assignNode.Operator != OPERATOR.ASSIGN ||
                    assignNode.Operand1 == null ||
                    assignNode.Operand1.Kind != NODEKIND.NAME ||
                    assignNode.Operand2 == null)
                {
                    continue;
                }

                //----------------------------------------------------
                // LHS
                //----------------------------------------------------
                NAMENODE nameNode = assignNode.Operand1 as NAMENODE;
                DebugUtil.Assert(nameNode != null);

                bindFlags = BindFlagsEnum.MemberSet;
                MemberLookup mem = new MemberLookup();

                EXPR leftExpr = null;
                if (mem.Lookup(
                        Compiler,
                        typeSym,
                        locVarExpr,
                        this.parentDeclSym,
                        nameNode.Name,
                        0,
                        MemLookFlagsEnum.UserCallable))
                {
                    SymWithType swt = mem.FirstSymWithType;
                    DebugUtil.Assert(swt != null && swt.IsNotNull);

                    switch (swt.Sym.Kind)
                    {
                    case SYMKIND.MEMBVARSYM:
                        leftExpr = BindToField(
                            assignNode,
                            locVarExpr,
                            FieldWithType.Convert(swt),
                            bindFlags);
                        break;

                    case SYMKIND.PROPSYM:
                        leftExpr = BindToProperty(
                            assignNode,
                            locVarExpr,
                            PropWithType.Convert(swt),
                            bindFlags,
                            null,
                            null);
                        break;

                    default:
                        leftExpr = NewError(nameNode, null);
                        break;
                    }
                }
                else
                {
                    mem.ReportErrors(nameNode);
                    leftExpr = NewError(nameNode, null);
                }

                //----------------------------------------------------
                // Collection initializer
                //----------------------------------------------------
                if (assignNode.Operand2.Kind == NODEKIND.ARRAYINIT)
                {
                    if (!leftExpr.TypeSym.IsARRAYSYM)
                    {
                        BindCollectionInitializer(
                            newNode,
                            (assignNode.Operand2 as UNOPNODE).Operand,
                            leftExpr.TypeSym, //typeSym,
                            null,             //locVarSym,
                            leftExpr,
                            null,
                            builder);
                        continue;
                    }
                }

                //----------------------------------------------------
                // RHS
                //----------------------------------------------------
                EXPR rightExpr = BindExpr(
                    assignNode.Operand2,
                    BindFlagsEnum.RValueRequired);

                //----------------------------------------------------
                // Assign
                //----------------------------------------------------
                EXPR assignExpr = BindAssignment(
                    assignNode,
                    leftExpr,
                    rightExpr,
                    false);

                builder.Add(SetNodeStmt(decNode, MakeStmt(decNode, assignExpr, 0)));
            }

            return(locVarExpr);
        }