From 59a768855d675c9bc0b96f02959d05b3e004732e Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Wed, 27 Mar 2019 00:16:44 +0100 Subject: [PATCH] Visitador: added treatment of whileStmts --- src/main/java/grafos/Visitador.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/grafos/Visitador.java b/src/main/java/grafos/Visitador.java index 11dea37..4ea6b59 100755 --- a/src/main/java/grafos/Visitador.java +++ b/src/main/java/grafos/Visitador.java @@ -4,6 +4,7 @@ import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.ast.stmt.IfStmt; +import com.github.javaparser.ast.stmt.WhileStmt; import com.github.javaparser.ast.visitor.VoidVisitorAdapter; import java.util.Collections; @@ -64,6 +65,20 @@ public class Visitador extends VoidVisitorAdapter { prevNode = newPrev; } + @Override + public void visit(WhileStmt n, CFG graph) { + Node whileStart = n.getCondition(); + graph.addNode(whileStart); + graph.connect(prevNode, whileStart); + + // TODO: shortcut conditions (||, &&) + + prevNode = Collections.singletonList(whileStart); + n.getBody().accept(this, graph); + graph.connect(prevNode, whileStart); + prevNode = Collections.singletonList(whileStart); + } + // Visitador de expresiones // Cada expresión encontrada genera un nodo en el CFG @Override