Visitador: added treatment of whileStmts

This commit is contained in:
Carlos Galindo 2019-03-27 00:16:44 +01:00
parent 8b62733a44
commit 59a768855d
Signed by untrusted user who does not match committer: kauron
GPG key ID: 83E68706DEE119A3

View file

@ -4,6 +4,7 @@ import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.stmt.ExpressionStmt; import com.github.javaparser.ast.stmt.ExpressionStmt;
import com.github.javaparser.ast.stmt.IfStmt; import com.github.javaparser.ast.stmt.IfStmt;
import com.github.javaparser.ast.stmt.WhileStmt;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter; import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
import java.util.Collections; import java.util.Collections;
@ -64,6 +65,20 @@ public class Visitador extends VoidVisitorAdapter<CFG> {
prevNode = newPrev; 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 // Visitador de expresiones
// Cada expresión encontrada genera un nodo en el CFG // Cada expresión encontrada genera un nodo en el CFG
@Override @Override