-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from ftsrg/xsts-localvars
Improved XSTS local variables
- Loading branch information
Showing
15 changed files
with
183 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/BasicDynamicScope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package hu.bme.mit.theta.common.dsl; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
public class BasicDynamicScope implements DynamicScope { | ||
private final Optional<DynamicScope> enclosingScope; | ||
private final SymbolTable symbolTable; | ||
|
||
public BasicDynamicScope(final DynamicScope enclosingScope) { | ||
this.enclosingScope = Optional.ofNullable(enclosingScope); | ||
symbolTable = new SymbolTable(); | ||
} | ||
|
||
//// | ||
|
||
@Override | ||
public void declare(final Symbol symbol) { | ||
symbolTable.add(symbol); | ||
} | ||
|
||
@Override | ||
public void declareAll(final Collection<? extends Symbol> symbols) { | ||
symbolTable.addAll(symbols); | ||
} | ||
|
||
//// | ||
|
||
@Override | ||
public Optional<DynamicScope> enclosingScope() { | ||
return enclosingScope; | ||
} | ||
|
||
@Override | ||
public Optional<? extends Symbol> resolve(final String name) { | ||
checkNotNull(name); | ||
final Optional<Symbol> symbol = symbolTable.get(name); | ||
if (symbol.isPresent() || !enclosingScope.isPresent()) { | ||
return symbol; | ||
} else { | ||
return enclosingScope.get().resolve(name); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/DynamicScope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package hu.bme.mit.theta.common.dsl; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
|
||
public interface DynamicScope extends Scope{ | ||
|
||
void declare(final Symbol symbol); | ||
|
||
void declareAll(final Collection<? extends Symbol> symbols); | ||
|
||
Optional<? extends DynamicScope> enclosingScope(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
subprojects/xsts/xsts-analysis/src/test/resources/model/localvars2.xsts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var a: integer = 0 | ||
|
||
trans { | ||
a:=0; | ||
local var a:integer=1; | ||
a:=1; | ||
} | ||
|
||
init{} | ||
|
||
env{} |
3 changes: 3 additions & 0 deletions
3
subprojects/xsts/xsts-analysis/src/test/resources/property/localvars2.prop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
prop{ | ||
a==0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.