Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions latte/src/main/java/typechecking/LatteTypeChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,12 @@ public void visitCtIf(CtIf ifElement) {
visitCtVariableRead((CtVariableRead<?>)condition);
} else if (condition instanceof CtFieldRead){
visitCtFieldRead((CtFieldRead<?>)condition);
} else if (condition instanceof CtInvocation) {
CtInvocation<?> invocation = (CtInvocation<?>) condition;
if (!invocation.getType().getQualifiedName().equals("boolean")) {
logError("Method invoked in if condition must return boolean", condition);
}
visitCtInvocation(invocation);
} else {
logError("Cannot evaluate the condition of the if statement: " + condition.toString(), condition);
}
Expand All @@ -532,11 +538,21 @@ public void visitCtIf(CtIf ifElement) {
PermissionEnvironment thenPermEnv = permEnv.cloneLast();
exitScopes();

enterScopes();
super.visitCtBlock(ifElement.getElseStatement());
SymbolicEnvironment elseSymbEnv = symbEnv.cloneLast();
PermissionEnvironment elsePermEnv = permEnv.cloneLast();
exitScopes();
SymbolicEnvironment elseSymbEnv;
PermissionEnvironment elsePermEnv;

if (ifElement.getElseStatement() != null) {
//Else statement
enterScopes();
super.visitCtBlock(ifElement.getElseStatement());
elseSymbEnv = symbEnv.cloneLast();
elsePermEnv = permEnv.cloneLast();
exitScopes();
} else {
//No Else statement
elseSymbEnv = symbEnv.cloneLast();
elsePermEnv = permEnv.cloneLast();
}

joining(thenSymbEnv, thenPermEnv, elseSymbEnv, elsePermEnv);
}
Expand Down
42 changes: 42 additions & 0 deletions latte/src/test/examples/MyNodeAllKindsIfs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package latte;

import specification.Free;
import specification.Unique;

/*
* This file is part of the Latte test suite.
*/
class MyNode {

@Unique Object value;
@Unique Node next;

/**
* Constructor for the Node class using @Free value and next nodes
* @param value
* @param next
*/
public MyNode (@Free Object value, @Free Node next) {
this.value = value;
this.next = next;
}

public void test(@Free Object v1, @Free Object v2, boolean c1, boolean c2){
if (c1) {
this.value = v1;
} else if (c2) {
this.value = v2;
} else {
this.value = v1;
}

if (c2) {
this.value = v1;
} else {
this.value = v2;
}
if (c1 && c2) {
this.value = v2;
}
}
}
29 changes: 29 additions & 0 deletions latte/src/test/examples/MyNodeIfNoElse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package latte;

import specification.Free;
import specification.Unique;

/*
* This file is part of the Latte test suite.
*/
class MyNode {

@Unique Object value;
@Unique Node next;

/**
* Constructor for the Node class using @Free value and next nodes
* @param value
* @param next
*/
public MyNode (@Free Object value, @Free Node next) {
this.value = value;
this.next = next;
}

public void test(@Free Object v1, boolean c1){
if (c1) {
this.value = v1;
}
}
}
35 changes: 35 additions & 0 deletions latte/src/test/examples/MyNodeInvocationIf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package latte;

import specification.Free;
import specification.Unique;

/*
* This file is part of the Latte test suite.
*/
class MyNode {

@Unique Object value;
@Unique Node next;

/**
* Constructor for the Node class using @Free value and next nodes
* @param value
* @param next
*/
public MyNode (@Free Object value, @Free Node next) {
this.value = value;
this.next = next;
}

public void test(@Free Object v1, boolean c1){
if (boolRead(c1)) {
this.value = v1;
} else {
this.value = null;
}
}

private boolean boolRead(boolean b){
return b;
}
}
5 changes: 4 additions & 1 deletion latte/src/test/java/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ private static Stream<Arguments> provideCorrectTestCases() {
Arguments.of("src/test/examples/searching_state_space/TimerTaskCannotReschedule.java"),
Arguments.of("src/test/examples/searching_state_space/ResultSetNoNext.java"),
Arguments.of("src/test/examples/searching_state_space/ResultSetForwardOnly.java"),
Arguments.of("src/test/examples/stack_overflow/MediaRecord.java")
Arguments.of("src/test/examples/stack_overflow/MediaRecord.java"),
Arguments.of("src/test/examples/MyNodeAllKindsIfs.java"),
Arguments.of("src/test/examples/MyNodeIfNoElse.java"),
Arguments.of("src/test/examples/MyNodeInvocationIf.java")
);
}

Expand Down
Loading