Visitador: added support and test for foreachStmts

This commit is contained in:
Carlos Galindo 2019-03-27 12:11:08 +01:00
parent 5a1d4b8e8d
commit a5ba8831b2
Signed by untrusted user who does not match committer: kauron
GPG Key ID: 83E68706DEE119A3
2 changed files with 20 additions and 0 deletions

View File

@ -137,6 +137,17 @@ public class Visitador extends VoidVisitorAdapter<CFG> {
prevNode = Collections.emptyList();
}
@Override
public void visit(ForeachStmt n, CFG graph) {
ForeachStmt copy = new ForeachStmt(n.getTokenRange().get(), n.getVariable(), n.getIterable(), new EmptyStmt());
graph.addNode(copy);
graph.connect(prevNode, copy);
prevNode = Collections.singletonList(copy);
n.getBody().accept(this, graph);
graph.connect(prevNode, copy);
prevNode = Collections.singletonList(copy);
}
// Visitador de expresiones
// Cada expresión encontrada genera un nodo en el CFG
@Override

View File

@ -0,0 +1,9 @@
public class BasicForeach {
public static void main(String[] args){
int[] numbers =
{1,2,3,4,5,6,7,8,9,10};
for (int item : numbers) {
System.out.println("Count is: " + item);
}
}
}