Visitador: added support and test for foreachStmts
This commit is contained in:
parent
5a1d4b8e8d
commit
a5ba8831b2
2 changed files with 20 additions and 0 deletions
|
@ -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
|
||||
|
|
9
src/test/res/mytest/BasicForeach.java
Normal file
9
src/test/res/mytest/BasicForeach.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue