Beispiel #1
0
        public override Object Visit(WhileStatement node, Object obj)
        {
            Object aux  = null;
            SSAMap map1 = this.map.Clone();

            if ((aux = node.Condition.Accept(this, false)) is SingleIdentifierExpression)
            {
                node.Condition = (SingleIdentifierExpression)aux;
            }
            SSAMap map2 = this.map.Clone();

            this.map.SetScope();
            node.Statements.Accept(this, obj);
            this.addLocalVariable(this.map.ResetScope(), node.Statements);
            // map3 = this.map

            List <MoveStatement> mvSt = map1.GetMoveStatements(this.map, node.Location.FileName, node.Location.Line);

            if (mvSt.Count != 0)
            {
                node.InitWhile = mvSt;
            }

            List <ThetaStatement> thSt = map1.GetThetaStatements(map2, ref this.map, node.Location.FileName, node.Condition.Location.Line);

            if (thSt.Count != 0)
            {
                node.BeforeCondition = thSt;
            }

            mvSt = map1.GetMoveStatements(map2, this.map, node.Location.FileName, node.Condition.Location.Line);
            if (mvSt.Count != 0)
            {
                node.AfterCondition = mvSt;
            }

            SSAInfo info = new SSAInfo(null, null, map1, this.map);

            node.Condition.Accept(new VisitorSSA2(), info);

            info = new SSAInfo(this.map, null, map1, this.map);
            node.Statements.Accept(new VisitorSSA2(), info);

            return(null);
        }
Beispiel #2
0
        public override Object Visit(SwitchStatement node, Object obj)
        {
            Object        aux             = null;
            List <SSAMap> mapsSwitch      = new List <SSAMap>();
            int           indexDefaultMap = -1;

            if ((aux = node.Condition.Accept(this, false)) is SingleIdentifierExpression)
            {
                node.Condition = (SingleIdentifierExpression)aux;
            }
            SSAMap map0 = this.map.Clone();

            IList <SingleIdentifierExpression> previousCaseReferences = this.referencesUsedInCaseBody;

            for (int i = 0; i < node.SwitchBlockCount; i++)
            {
                // * Updates the current if statatement body being analyzed
                IList <SingleIdentifierExpression> caseReferences = new List <SingleIdentifierExpression>();
                node.ReferencesUsedCases[node.GetSwitchSectionElement(i).SwitchBlock] = caseReferences;
                IList <SingleIdentifierExpression> previousReferencesUsedInCaseBody = this.referencesUsedInCaseBody;
                this.referencesUsedInCaseBody = caseReferences;

                this.map.SetScope();
                node.GetSwitchSectionElement(i).Accept(this, false);
                if (node.GetSwitchSectionElement(i).IsDefaultCase())
                {
                    indexDefaultMap = i;
                }
                this.addLocalVariable(this.map.ResetScope(), node.GetSwitchSectionElement(i).SwitchBlock);
                mapsSwitch.Add(this.map.Clone());
            }
            this.referencesUsedInCaseBody = previousCaseReferences;

            // lastMap => this.map

            List <MoveStatement> mvSt;

            if (indexDefaultMap == -1)
            {
                mvSt = map0.GetMoveStatements(this.map, node.Location.FileName, node.Location.Line);
            }
            else
            {
                mvSt = map0.GetMoveStatementsForSwitch(mapsSwitch, node.Location.FileName, node.Location.Line);
            }
            if (mvSt.Count != 0)
            {
                node.AfterCondition = mvSt;
            }


            for (int i = 0; i < node.SwitchBlockCount; i++)
            {
                SSAInfo info;
                if (i > 0)
                {
                    info = new SSAInfo(mapsSwitch[i], this.map, mapsSwitch[i - 1], map0);
                }
                else
                {
                    info = new SSAInfo(mapsSwitch[i], this.map, null, null);
                }
                node.GetSwitchSectionElement(i).Accept(new VisitorSSA2(), info);
            }

            List <ThetaStatement> thSt;

            if (indexDefaultMap != -1)
            {
                thSt = map0.GetThetaStatements(mapsSwitch, ref this.map, true, node.Location.FileName, node.GetSwitchSectionElement(node.SwitchBlockCount - 1).SwitchBlock.Location.Line);
            }
            else
            {
                thSt = map0.GetThetaStatements(mapsSwitch, ref this.map, false, node.Location.FileName, node.GetSwitchSectionElement(node.SwitchBlockCount - 1).SwitchBlock.Location.Line);
            }

            if (thSt.Count != 0)
            {
                node.ThetaStatements = thSt;
            }

            return(null);
        }
Beispiel #3
0
        public override Object Visit(IfElseStatement node, Object obj)
        {
            Object aux = null;

            if ((aux = node.Condition.Accept(this, false)) is SingleIdentifierExpression)
            {
                node.Condition = (SingleIdentifierExpression)aux;
            }
            SSAMap map1 = this.map.Clone();

            this.map.SetScope();

            // * Updates the current if statatement body being analyzed
            IList <SingleIdentifierExpression> previousReferencesUsedInIfElseBody = this.referencesUsedInIfElseBody;

            this.referencesUsedInIfElseBody = node.ReferencesUsedInTrueBranch;
            node.TrueBranch.Accept(this, obj);

            this.addLocalVariable(this.map.ResetScope(), node.TrueBranch);
            SSAMap map2 = this.map.Clone();

            this.map.SetScope();
            this.referencesUsedInIfElseBody = node.ReferencesUsedInFalseBranch;
            node.FalseBranch.Accept(this, obj);
            // * Updates the previous if statatement being analyzed
            this.referencesUsedInIfElseBody = previousReferencesUsedInIfElseBody;

            this.addLocalVariable(this.map.ResetScope(), node.FalseBranch);
            // map3 = this.map

            List <MoveStatement> mvSt = map1.GetMoveStatementsForIf(map2, this.map, node.Location.FileName, node.Condition.Location.Line);

            if (mvSt.Count != 0)
            {
                node.AfterCondition = mvSt;
            }

            SSAInfo info = new SSAInfo(map2, this.map, null, null);

            node.TrueBranch.Accept(new VisitorSSA2(), info);

            info = new SSAInfo(this.map, this.map, map2, map1);
            node.FalseBranch.Accept(new VisitorSSA2(), info);

            List <ThetaStatement> thSt;

            if (node.HaveElseBlock())
            {
                thSt = map2.GetThetaStatements(ref this.map, map1, node.Location.FileName, node.FalseBranch.Location.Line);
            }
            else
            {
                thSt = map1.GetThetaStatements(ref this.map, node.Location.FileName, node.FalseBranch.Location.Line);
            }

            if (thSt.Count != 0)
            {
                node.ThetaStatements = thSt;
            }

            return(null);
        }