-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bug in or patterns when used outside of a rewrite (#340)
* fix bug in or patterns when used outside of a rewrite * expand macros prior to GuardOrPatterns * support anonymous variables in or patterns
- Loading branch information
1 parent
1a38233
commit 3e98406
Showing
14 changed files
with
140 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test(foo) |
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 @@ | ||
<k> | ||
2 ~> test ( foo ) | ||
</k> |
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 @@ | ||
test(bar) |
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 @@ | ||
<k> | ||
2 ~> test ( bar ) | ||
</k> |
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 @@ | ||
test(test2(baz,baz)) |
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 @@ | ||
<k> | ||
1 | ||
</k> |
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 @@ | ||
test(test(test2(baz,baz))) |
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 @@ | ||
<k> | ||
1 | ||
</k> |
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 was deleted.
Oops, something went wrong.
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 @@ | ||
../or-llvm/test.k |
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
103 changes: 103 additions & 0 deletions
103
kernel/src/main/java/org/kframework/compile/GuardOrPatterns.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,103 @@ | ||
// Copyright (c) 2019 K Team. All Rights Reserved. | ||
package org.kframework.compile; | ||
|
||
import org.kframework.builtin.KLabels; | ||
import org.kframework.definition.Context; | ||
import org.kframework.definition.Production; | ||
import org.kframework.definition.Rule; | ||
import org.kframework.definition.Sentence; | ||
import org.kframework.kore.*; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import static org.kframework.kore.KORE.*; | ||
|
||
public class GuardOrPatterns { | ||
|
||
private Set<KVariable> vars = new HashSet<>(); | ||
|
||
void resetVars() { | ||
vars.clear(); | ||
} | ||
|
||
private Rule resolve(Rule rule) { | ||
resetVars(); | ||
gatherVars(rule.body()); | ||
gatherVars(rule.requires()); | ||
gatherVars(rule.ensures()); | ||
return new Rule( | ||
transform(rule.body()), | ||
transform(rule.requires()), | ||
transform(rule.ensures()), | ||
rule.att()); | ||
} | ||
|
||
private Context resolve(Context context) { | ||
resetVars(); | ||
gatherVars(context.body()); | ||
gatherVars(context.requires()); | ||
return new Context( | ||
transform(context.body()), | ||
transform(context.requires()), | ||
context.att()); | ||
} | ||
|
||
public K resolveK(K k) { | ||
resetVars();; | ||
gatherVars(k); | ||
return transform(k); | ||
} | ||
|
||
public synchronized Sentence resolve(Sentence s) { | ||
if (s instanceof Rule) { | ||
return resolve((Rule) s); | ||
} else if (s instanceof Context) { | ||
return resolve((Context) s); | ||
} else { | ||
return s; | ||
} | ||
} | ||
|
||
void gatherVars(K term) { | ||
new VisitK() { | ||
@Override | ||
public void apply(KVariable v) { | ||
vars.add(v); | ||
super.apply(v); | ||
} | ||
}.apply(term); | ||
} | ||
|
||
K transform(K term) { | ||
return new TransformK() { | ||
@Override | ||
public K apply(KApply k) { | ||
if (k.klabel().equals(KLabels.ML_OR)) { | ||
return KAs(k, newDotVariable()); | ||
} | ||
return super.apply(k); | ||
} | ||
|
||
@Override | ||
public K apply(KAs k) { | ||
return k; | ||
} | ||
|
||
@Override | ||
public K apply(KRewrite k) { | ||
return KRewrite(k.left(), apply(k.right()), k.att()); | ||
} | ||
}.apply(term); | ||
} | ||
|
||
private int counter = 0; | ||
KVariable newDotVariable() { | ||
KVariable newLabel; | ||
do { | ||
newLabel = KVariable("_" + (counter++), Att().add("anonymous")); | ||
} while (vars.contains(newLabel)); | ||
vars.add(newLabel); | ||
return newLabel; | ||
} | ||
} |
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