private void BuildPath(List <IStatementList> paths, IStatementList path, Statement lastElement) { Statement element = path.GetSize() > 0 ? path.GetLast() : lastElement; if (path.GetSize() == 0 || element != lastElement) { IStatementList nexting = GetNext(element); if (nexting.GetSize() > 0) { if (nexting.GetLast() != nexting.GetFirst()) { IStatementList newPath = path.Copy(); newPath.AddStatement(nexting.GetLast()); BuildPath(paths, newPath, element); } path.AddStatement(nexting.GetFirst()); BuildPath(paths, path, element); } else { paths.Add(path); } } else { paths.Add(path); } }
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; } } } } }
public Assign(Variable left, Token operation, Factor right, int programLine) : base(programLine) { Left = left; Operation = operation; Right = right; AffectedBy = ImplementationFactory.CreateStatementList(); Affecting = ImplementationFactory.CreateStatementList(); }
public List <IStatementList> GetPathsFrom(Statement statement) { List <IStatementList> paths = new List <IStatementList>(); IStatementList newPath = ImplementationFactory.CreateStatementList(); BuildPath(paths, newPath, statement); return(paths); }
protected override IEntityList ProcessRightSide(IProgramKnowledgeBase pkb, IEntity arg) { Statement statement = arg as Statement; Statement parent = pkb.ParentTable.GetParent(statement); IStatementList result = ImplementationFactory.CreateStatementList(); result.AddStatement(parent); return(result); }
protected override IEntityList ProcessRightSide(IProgramKnowledgeBase pkb, IEntity arg) { Statement statement = arg as Statement; Statement followed = pkb.FollowsTable.GetFollowedBy(statement); IStatementList result = ImplementationFactory.CreateStatementList(); result.AddStatement(followed); return(result); }
public Variable(Token token) { Name = token.Value.ToString(); Attribute = new Attribute("varName", Name); ModifiedByProcedures = ImplementationFactory.CreateProcedureList(); ModifiedByStatements = ImplementationFactory.CreateStatementList(); UsedByProcedures = ImplementationFactory.CreateProcedureList(); UsedByStatements = ImplementationFactory.CreateStatementList(); }
public Variable(string name) { Name = name; Attribute = new Attribute("varName", Name); ModifiedByProcedures = ImplementationFactory.CreateProcedureList(); ModifiedByStatements = ImplementationFactory.CreateStatementList(); UsedByProcedures = ImplementationFactory.CreateProcedureList(); UsedByStatements = ImplementationFactory.CreateStatementList(); }
public IStatementList GetNextT(Statement statement) { IStatementList nexting = GetNext(statement); for (int i = 0; i < nexting.GetSize(); i++) { nexting.Sum(GetNext(nexting[i])); } return(nexting); }
public IStatementList GetNextedByT(Statement statement) { IStatementList nexted = GetNextedBy(statement); for (int i = 0; i < nexted.GetSize(); i++) { nexted.Sum(GetNextedBy(nexted[i])); } return(nexted); }
public Procedure(string name, IStatementList body) { Name = name; Body = body; Attribute = new Attribute("procName", Name); Modifying = ImplementationFactory.CreateVariableList(); Using = ImplementationFactory.CreateVariableList(); CalledBy = ImplementationFactory.CreateProcedureList(); Calling = ImplementationFactory.CreateProcedureList(); }
public IStatementList GetParentedByT(Statement statement) { IStatementList parented = GetParentedBy(statement); for (int i = 0; i < parented.GetSize(); i++) { parented.Sum(GetParentedBy(parented[i])); } return(parented); }
public Statement(int programLine) { ProgramLine = programLine; Attribute = new Attribute("progLine", ProgramLine.ToString()); Modifying = ImplementationFactory.CreateVariableList(); Using = ImplementationFactory.CreateVariableList(); NextedBy = ImplementationFactory.CreateStatementList(); Nexting = ImplementationFactory.CreateStatementList(); Children = ImplementationFactory.CreateStatementList(); }
private While WhileStatement() { int programLine = ++statementCounter; Eat(TokenType.WHILE); Variable var = Var(); IStatementList body = StmtLst(); return(new While(var, body, programLine)); }
public IStatementList GetAffectedByT(Assign assignment) { IStatementList affected = GetAffectedBy(assignment); for (int i = 0; i < affected.GetSize(); i++) { Assign affectedAssignment = affected[i] as Assign; affected.Sum(GetAffectedBy(affectedAssignment)); } return(affected); }
public IStatementList GetAffectsT(Assign assignment) { IStatementList affecting = GetAffects(assignment); for (int i = 0; i < affecting.GetSize(); i++) { Assign affectingAssignment = affecting[i] as Assign; affecting.Sum(GetAffects(affectingAssignment)); } return(affecting); }
public IStatementList GetFollowedByT(Statement statement) { IStatementList followed = ImplementationFactory.CreateStatementList(); Statement followedStatement = GetFollowedBy(statement); followed.AddStatement(followedStatement); for (int i = 0; i < followed.GetSize(); i++) { followed.AddStatement(GetFollowedBy(followed[i])); } return(followed); }
public IStatementList GetFollowsT(Statement statement) { IStatementList following = ImplementationFactory.CreateStatementList(); Statement followingStatement = GetFollows(statement); following.AddStatement(followingStatement); for (int i = 0; i < following.GetSize(); i++) { following.AddStatement(GetFollows(following[i])); } return(following); }
public IStatementList GetParentT(Statement statement) { IStatementList parents = ImplementationFactory.CreateStatementList(); Statement parentStatement = GetParent(statement); parents.AddStatement(parentStatement); for (int i = 0; i < parents.GetSize(); i++) { parents.AddEntity(GetParent(parents[i])); } return(parents); }
private IStatementList Statements() { Statement statement = SingleStatement(); IStatementList statements = ImplementationFactory.CreateStatementList(); statements.AddStatement(statement); while (currentToken.Type != TokenType.RBRACE) { statements.AddStatement(SingleStatement()); } return(statements); }
private IStatementList StmtLst() { Eat(TokenType.LBRACE); IStatementList statements = Statements(); Eat(TokenType.RBRACE); IStatementList root = ImplementationFactory.CreateStatementList(); foreach (Statement statement in statements) { root.AddStatement(statement); } return(root); }
private If IfStatement() { int programLine = ++statementCounter; Eat(TokenType.IF); Variable var = Var(); Eat(TokenType.THEN); IStatementList body = StmtLst(); IStatementList elseBody = null; if (currentToken.Type == TokenType.ELSE) { Eat(TokenType.ELSE); elseBody = StmtLst(); } return(new If(var, body, elseBody, programLine)); }
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); } } }
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); } } }
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); } } }
public bool IsAffectsT(Assign assignment1, Assign assignment2) { IStatementList affectingAssignments = GetAffectsT(assignment2); return(affectingAssignments.Contains(assignment1)); }
public If(Variable condition, IStatementList ifBody, IStatementList elseBody, int programLine) : base(programLine) { Condition = condition; IfBody = ifBody; ElseBody = elseBody; }
public bool IsFollowsT(Statement firstStatement, Statement secondStatement) { IStatementList statementList = GetFollowedByT(secondStatement); return(statementList.Contains(firstStatement)); }
public While(Variable condition, IStatementList body, int programLine) : base(programLine) { Condition = condition; Body = body; }
public While(int programLine) : base(programLine) { Body = ImplementationFactory.CreateStatementList(); }