Exemplo n.º 1
0
        private void ExtractIfNext(If check, Statement next)
        {
            Statement last1 = check.IfBody.GetLast();

            if (last1 is If)
            {
                ExtractIfNext(last1 as If, next);
            }
            else
            {
                NextTable.SetNext(last1, next);
            }

            if (check.ElseBody != null)
            {
                Statement last2 = check.ElseBody.GetLast();
                if (last2 is If)
                {
                    ExtractIfNext(last2 as If, next);
                }
                else
                {
                    NextTable.SetNext(last2, next);
                }
            }
        }
Exemplo n.º 2
0
        private void ExtractIf(If check, Procedure procedureContext)
        {
            ExtractVariable(check.Condition);
            Variable retrievedVariable = Variables.GetVariableByName(check.Condition.Name);

            UsesTable.SetUses(check, retrievedVariable);
            ExtractBody(check, check.IfBody, procedureContext);
            NextTable.SetNext(check, check.IfBody.GetFirst());
            if (check.ElseBody != null)
            {
                ExtractBody(check, check.ElseBody, procedureContext);
                NextTable.SetNext(check, check.ElseBody.GetFirst());
            }
        }
Exemplo n.º 3
0
        private void ExtractWhile(While loop, Procedure procedureContext)
        {
            ExtractVariable(loop.Condition);
            Variable retrievedVariable = Variables.GetVariableByName(loop.Condition.Name);

            UsesTable.SetUses(loop, retrievedVariable);
            ExtractBody(loop, loop.Body, procedureContext);

            NextTable.SetNext(loop, loop.Body.GetFirst());
            if (loop.Body.GetLast() is If)
            {
                ExtractIfNext(loop.Body.GetLast() as If, loop);
            }
            else
            {
                NextTable.SetNext(loop.Body.GetLast(), loop);
            }
        }
Exemplo n.º 4
0
        private void ExtractProcedure(Procedure procedure)
        {
            IStatementList children = procedure.Body;

            for (int i = 0; i < children.GetSize(); i++)
            {
                Statement child = children[i];
                ExtractStatement(child, procedure);
                if (i > 0)
                {
                    Statement previousChild = children[i - 1];
                    FollowsTable.SetFollows(previousChild, child);

                    if (!(previousChild is If))
                    {
                        NextTable.SetNext(previousChild, child);
                    }
                    else
                    {
                        ExtractIfNext(previousChild as If, child);
                    }
                }

                IVariableList modifiedVariables = ModifiesTable.GetModifiedBy(child);
                IVariableList usedVariables     = UsesTable.GetUsedBy(child);

                foreach (Variable variable in modifiedVariables)
                {
                    ModifiesTable.SetModifies(procedure, variable);
                }
                foreach (Variable variable in usedVariables)
                {
                    UsesTable.SetUses(procedure, variable);
                }
            }
        }
Exemplo n.º 5
0
        private void ExtractBody(Container container, IStatementList body, Procedure procedureContext)
        {
            for (int i = 0; i < body.GetSize(); i++)
            {
                Statement child = body[i];
                ExtractStatement(child, procedureContext);

                ParentTable.SetParent(container, child);
                if (i > 0)
                {
                    Statement previousChild = body[i - 1];
                    FollowsTable.SetFollows(previousChild, child);

                    if (!(previousChild is If))
                    {
                        NextTable.SetNext(previousChild, child);
                    }
                    else
                    {
                        ExtractIfNext(previousChild as If, child);
                    }
                }

                IVariableList modifiedVariables = ModifiesTable.GetModifiedBy(child);
                IVariableList usedVariables     = UsesTable.GetUsedBy(child);

                foreach (Variable variable in modifiedVariables)
                {
                    ModifiesTable.SetModifies(container, variable);
                }
                foreach (Variable variable in usedVariables)
                {
                    UsesTable.SetUses(container, variable);
                }
            }
        }