From a5ba8831b2688b9bf7142e48bc7ee28ac485a06d Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Wed, 27 Mar 2019 12:11:08 +0100 Subject: [PATCH] Visitador: added support and test for foreachStmts --- src/main/java/grafos/Visitador.java | 11 +++++++++++ src/test/res/mytest/BasicForeach.java | 9 +++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/test/res/mytest/BasicForeach.java diff --git a/src/main/java/grafos/Visitador.java b/src/main/java/grafos/Visitador.java index 45763d5..7a926cc 100755 --- a/src/main/java/grafos/Visitador.java +++ b/src/main/java/grafos/Visitador.java @@ -137,6 +137,17 @@ public class Visitador extends VoidVisitorAdapter { 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 diff --git a/src/test/res/mytest/BasicForeach.java b/src/test/res/mytest/BasicForeach.java new file mode 100644 index 0000000..08dd728 --- /dev/null +++ b/src/test/res/mytest/BasicForeach.java @@ -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); + } + } +} \ No newline at end of file