Skip to content

Commit

Permalink
complex while-loop instrumentation works (now also for complex cond-c…
Browse files Browse the repository at this point in the history
…hains, such as i < 2*3+myMethod(4))

issue #58 : #58

Some minor aspects of the model have been changed (e.g. supports move of one invocation to another scope, objvar rename)
  • Loading branch information
miho committed Aug 6, 2015
1 parent 3021199 commit f8a8f5d
Show file tree
Hide file tree
Showing 9 changed files with 358 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public IType getType() {

@Override
public String toString() {
return "[Argument: argType=" + getArgType() + ", type=" + getType() + "]";
String valueString = ", val='"+getConstant().orElse("?").toString()+"'";
return "[Argument: argType=" + getArgType() + ", type=" + getType() + valueString + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public static boolean booleanOperator(Operator operator) {
|| operator == Operator.NOT_EQUALS
|| operator == Operator.LESS_EQUALS
|| operator == Operator.GREATER_EQUALS
|| operator == Operator.GREATER
|| operator == Operator.LESS
|| operator == Operator.GREATER_EQUALS
|| operator == Operator.OR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
package eu.mihosoft.vrl.lang.model;

import java.util.List;
import java.util.Optional;

/**
*
Expand All @@ -77,6 +78,7 @@ public interface ControlFlow {
public List<Invocation> getInvocations();

public boolean isUsedAsInput(Invocation invocation);
public Optional<Invocation> returnInvTargetIfPresent(Invocation invocation);

public BinaryOperatorInvocation invokeOperator(String id, IArgument leftArg, IArgument rightArg, Operator operator);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
import eu.mihosoft.vrl.workflow.WorkflowUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import javafx.beans.Observable;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
Expand All @@ -81,20 +83,25 @@ public ControlFlowImpl(Scope parent) {
}

private void initListeners() {
invocations.addListener((ListChangeListener.Change<? extends Invocation> c) -> {
// while(c.next()) {
// if (c.wasAdded()) {
// //
// }
// ... TODO
//
// }

invocations.addListener((Observable observable) -> {
if (!currentlyUpdatingInvocations) {
updateConnections();
// update invocation parent;
for (Invocation invocation : invocations) {
((InvocationImpl) invocation).setParent(getParent());
}
}

});
// invocations.addListener((ListChangeListener.Change<? extends Invocation> c) -> {
// while (c.next()) {
// if (c.wasAdded()) {
// c.getAddedSubList().stream().forEach((inv) -> {
// System.out.println("inv-add: " + inv);
// ((InvocationImpl) inv).setParent(getParent());
// });
// }
// }
// });

flow.getConnections(WorkflowUtil.CONTROL_FLOW).getConnections().addListener(
new ListChangeListener<Connection>() {
Expand Down Expand Up @@ -124,7 +131,6 @@ private void updateConnections() {
flow.getConnections(WorkflowUtil.CONTROL_FLOW).getConnections().clear();
Invocation prevInvocation = null;
for (Invocation invocation : invocations) {

if (prevInvocation != null) {
flow.connect(prevInvocation.getNode(), invocation.getNode(),
WorkflowUtil.CONTROL_FLOW);
Expand Down Expand Up @@ -254,14 +260,20 @@ public Invocation callMethod(String id, String varName,
@Override
public boolean isUsedAsInput(Invocation invocation) {

return returnInvTargetIfPresent(invocation).isPresent();
}

@Override
public Optional<Invocation> returnInvTargetIfPresent(Invocation invocation) {

for (Invocation inv : invocations) {

if (inv instanceof ScopeInvocation) {
ScopeInvocation sInv = (ScopeInvocation) inv;
if (sInv.getScope() instanceof WhileDeclaration) {
WhileDeclaration whileD = (WhileDeclaration) sInv.getScope();
if (invocation == whileD.getCheck()) {
return true;
return Optional.of(inv);
}
}
}
Expand All @@ -270,13 +282,13 @@ public boolean isUsedAsInput(Invocation invocation) {

if (arg.getArgType() == ArgumentType.INVOCATION) {
if (arg.getInvocation().get().equals(invocation)) {
return true;
return Optional.of(inv);
}
}
}
}

return false;
return Optional.empty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class InvocationImpl implements Invocation {
private final boolean constructor;
private boolean Void;
// private String code;
private final Scope parent;
private Scope parent;
private boolean Static;
private ICodeRange location;
private IType returnType;
Expand Down Expand Up @@ -105,11 +105,11 @@ public InvocationImpl(
// } else {
// returnValue = parent.createVariable(this);
// }
init(varName);
init(varName, parent);

}

private void init(String varName) {
private void init(String varName, Scope oldParent) {

if (varName != null && !varName.isEmpty()) {
Variable var = null;
Expand All @@ -134,7 +134,10 @@ private void init(String varName) {
if (isScope()) {
// nothing (see ScopeInvocationImpl)
} else {
if (node == null) {
if (node == null || parent != oldParent) {
if (node != null) {
oldParent.getFlow().remove(node);
}
node = parent.getFlow().newNode();
} else {
List<Connector> delList = new ArrayList<>();
Expand Down Expand Up @@ -419,7 +422,15 @@ public void setTextRenderingEnabled(boolean textRenderingEnabled) {
@Override
public void setVariableName(String variableName) {
this.varName = variableName;
init(varName);
init(varName, parent);
}

void setParent(Scope parent) {
Scope oldParent = this.parent;
this.parent = parent;
if (parent != oldParent) {
init(varName, oldParent);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
*/
@FunctionalInterface
public interface CodeTransform<T extends CodeEntity> {
public T transform(T ce);
public T transform(T ce, String indent);
}
Loading

0 comments on commit f8a8f5d

Please sign in to comment.