예제 #1
0
        private void ExtractAffects()
        {
            IStatementList assignStatements = Statements.Copy().FilterByType(typeof(Assign)) as IStatementList;

            foreach (Statement assignStatement in assignStatements)
            {
                Assign   assignment = assignStatement as Assign;
                Variable variable   = ModifiesTable.GetModifiedBy(assignment).GetVariableByIndex(0);

                List <IStatementList> paths = NextTable.GetPathsFrom(assignStatement);
                foreach (IStatementList path in paths)
                {
                    foreach (Statement nextStatement in path)
                    {
                        if (nextStatement is Assign && UsesTable.IsUses(nextStatement, variable))
                        {
                            AffectsTable.SetAffects(assignment, nextStatement as Assign);
                        }
                        if (nextStatement != assignStatement && (nextStatement is Assign || nextStatement is Call) && ModifiesTable.IsModifies(nextStatement, variable))
                        {
                            break;
                        }
                    }
                }
            }
        }
예제 #2
0
        private void ExtractAssign(Assign assign)
        {
            ExtractVariable(assign.Left);
            ExtractFactor(assign.Right, assign);

            Variable retrievedVariable = Variables.GetVariableByName(assign.Left.Name);

            ModifiesTable.SetModifies(assign, retrievedVariable);
        }
예제 #3
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);
                }
            }
        }
예제 #4
0
        private void ExtractProcedureCalls(Procedure procedure)
        {
            IProcedureList callingProcedures = CallsTable.GetCalling(procedure);

            foreach (Procedure callingProcedure in callingProcedures)
            {
                List <Call> procedureCalls = calls[callingProcedure].Where(x => x.Procedure == procedure).ToList();
                foreach (Call call in procedureCalls)
                {
                    IStatementList callParents = ParentTable.GetParentT(call);

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

                    foreach (Variable variable in modifiedVariables)
                    {
                        ModifiesTable.SetModifies(call, variable);
                        ModifiesTable.SetModifies(callingProcedure, variable);
                        foreach (Statement parent in callParents)
                        {
                            ModifiesTable.SetModifies(parent, variable);
                        }
                    }
                    foreach (Variable variable in usedVariables)
                    {
                        UsesTable.SetUses(call, variable);
                        UsesTable.SetUses(callingProcedure, variable);
                        foreach (Statement parent in callParents)
                        {
                            UsesTable.SetUses(parent, variable);
                        }
                    }
                    ExtractProcedureCalls(callingProcedure);
                }
            }
        }
예제 #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);
                }
            }
        }