Skip to content

Commit 81108ef

Browse files
committed
Merge remote-tracking branch 'origin/feature/configuration-concretization' into feature/imp-end-to-end
Conflicts: kernel/src/main/java/org/kframework/kore/convertors/KILtoKORE.java Former-commit-id: 3ddbbb7553fb81bc4d71a8a7429ec4eb6f1d283a [formerly 6440e3241c392f6f521997cb470faaa2f89d0921] Former-commit-id: 00c259158da1f5c8b0847cdc783f010111550e0b
2 parents 6853841 + e8e6cd9 commit 81108ef

17 files changed

Lines changed: 979 additions & 118 deletions

File tree

k-distribution/src/test/java/org/kframework/kore/Kompile.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
import org.apache.commons.io.FileUtils;
55
import org.kframework.Collections;
66
import org.kframework.compile.ConfigurationInfoFromModule;
7+
import org.kframework.compile.LabelInfoFromModule;
78
import org.kframework.compile.StrictToHeatingCooling;
89
import org.kframework.definition.Bubble;
910
import org.kframework.definition.Definition;
1011
import org.kframework.definition.Module;
1112
import org.kframework.definition.Sentence;
1213
import org.kframework.kil.Sources;
1314
import org.kframework.kore.K;
15+
import org.kframework.kore.compile.ConcretizationInfo;
1416
import org.kframework.kore.compile.ConcretizeConfiguration;
17+
import org.kframework.compile.LabelInfo;
1518
import org.kframework.parser.TreeNodesToKORE;
1619
import org.kframework.parser.concrete2kore.ParseInModule;
1720
import org.kframework.parser.concrete2kore.ParserUtils;
@@ -127,7 +130,9 @@ public static Tuple2<Module, Function<String, K>> getStuff(File definitionFile,
127130
Lists.newArrayList(BUILTIN_DIRECTORY))));
128131

129132
ConfigurationInfoFromModule configInfo = new ConfigurationInfoFromModule(afterHeatingCooling);
130-
ConcretizeConfiguration concretizeConfiguration = new ConcretizeConfiguration(configInfo);
133+
LabelInfo labelInfo = new LabelInfoFromModule(configInfo);
134+
ConcretizationInfo concretizationInfo = new ConcretizationInfo(configInfo, labelInfo);
135+
ConcretizeConfiguration concretizeConfiguration = new ConcretizeConfiguration(concretizationInfo);
131136
Module concretized = concretizeConfiguration.concretize(afterHeatingCooling);
132137

133138

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) 2015 K Team. All Rights Reserved.
2+
package org.kframework.kore.compile;
3+
4+
import org.kframework.compile.ConfigurationInfo;
5+
import org.kframework.compile.LabelInfo;
6+
import org.kframework.kore.K;
7+
import org.kframework.kore.KLabel;
8+
import org.kframework.kore.Sort;
9+
10+
import java.util.List;
11+
12+
/**
13+
* Created by brandon on 3/31/15.
14+
*/
15+
public class ConcretizationInfo {
16+
private final ConfigurationInfo cfg;
17+
private final LabelInfo labels;
18+
19+
public ConcretizationInfo(ConfigurationInfo cfg, LabelInfo labels) {
20+
this.cfg = cfg;
21+
this.labels = labels;
22+
}
23+
24+
25+
public ConfigurationInfo.Multiplicity getMultiplicity(KLabel label) {
26+
return cfg.getMultiplicity(labels.getCodomain(label));
27+
}
28+
public ConfigurationInfo.Multiplicity getMultiplicity(Sort sort) {
29+
return cfg.getMultiplicity(sort);
30+
}
31+
32+
public int getLevel(KLabel label) {
33+
return cfg.getLevel(labels.getCodomain(label));
34+
}
35+
36+
public KLabel getParent(KLabel klabel) {
37+
return cfg.getCellLabel(cfg.getParent(labels.getCodomain(klabel)));
38+
}
39+
40+
public Sort getCellSort(KLabel cellLabel) {
41+
Sort s = labels.getCodomain(cellLabel);
42+
return cfg.isCell(s) ? s : null;
43+
}
44+
45+
public boolean isCell(KLabel klabel) {
46+
return cfg.isCell(labels.getCodomain(klabel));
47+
}
48+
public boolean isLeafCell(KLabel klabel) {
49+
return cfg.isLeafCell(labels.getCodomain(klabel));
50+
}
51+
public boolean isParentCell(KLabel klabel) {
52+
return cfg.isParentCell(labels.getCodomain(klabel));
53+
}
54+
55+
public Sort leafCellType(KLabel label) {
56+
return cfg.leafCellType(labels.getCodomain(label));
57+
}
58+
public List<Sort> getChildren(KLabel label) {
59+
return cfg.getChildren(labels.getCodomain(label));
60+
}
61+
62+
public K getDefaultCell(Sort sort) {
63+
return cfg.getDefaultCell(sort);
64+
}
65+
}

kernel/src/main/java/org/kframework/kore/compile/ConcretizeConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
public class ConcretizeConfiguration {
2424

25-
private final ConfigurationInfo cfg;
26-
public ConcretizeConfiguration(ConfigurationInfo cfg) {
25+
private final ConcretizationInfo cfg;
26+
public ConcretizeConfiguration(ConcretizationInfo cfg) {
2727
this.cfg = cfg;
2828
}
2929

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2015 K Team. All Rights Reserved.
2+
package org.kframework.kore.compile;
3+
4+
import com.google.common.collect.Maps;
5+
import org.kframework.kore.KLabel;
6+
import org.kframework.kore.Sort;
7+
8+
import static org.kframework.kore.KORE.*;
9+
10+
import java.util.Map;
11+
12+
public class SortInfo {
13+
private final Map<Sort, KLabel> closeOperators = Maps.newHashMap();
14+
15+
protected void addOp(String sort, String label) {
16+
closeOperators.put(Sort(sort), KLabel(label));
17+
}
18+
19+
public SortInfo() {
20+
}
21+
22+
public KLabel getCloseOperator(Sort s) {
23+
return closeOperators.get(s);
24+
}
25+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (c) 2015 K Team. All Rights Reserved.
2+
package org.kframework.kore.compile;
3+
4+
import org.kframework.kore.*;
5+
6+
import java.util.ArrayList;
7+
8+
import static org.kframework.kore.KORE.*;
9+
10+
/**
11+
* Created by brandon on 3/30/15.
12+
*/
13+
public class TransformKORE extends AbstractKORETransformer<K> {
14+
15+
@Override
16+
public K apply(KApply k) {
17+
ArrayList<K> newItems = new ArrayList<>(k.klist().items());
18+
boolean change = false;
19+
for (int i = 0; i < newItems.size(); ++i) {
20+
K in = newItems.get(i);
21+
K out = apply(in);
22+
newItems.set(i, out);
23+
change = change || (in != out);
24+
}
25+
if (change) {
26+
return KApply(k.klabel(), KList(newItems), k.att());
27+
} else {
28+
return k;
29+
}
30+
}
31+
32+
@Override
33+
public K apply(KRewrite k) {
34+
K l = apply(k.left());
35+
K r = apply(k.right());
36+
if (l != k.left() || r != k.right()) {
37+
return KRewrite(l, r, k.att());
38+
} else {
39+
return k;
40+
}
41+
}
42+
43+
@Override
44+
public K apply(KToken k) {
45+
return k;
46+
}
47+
48+
@Override
49+
public K apply(KVariable k) {
50+
return k;
51+
}
52+
53+
@Override
54+
public K apply(KSequence k) {
55+
ArrayList<K> newItems = new ArrayList<>(k.items());
56+
boolean change = false;
57+
for (int i = 0; i < newItems.size(); ++i) {
58+
K in = newItems.get(0);
59+
K out = apply(newItems.get(0));
60+
newItems.set(i, out);
61+
change = change || (in != out);
62+
}
63+
if (change) {
64+
return KSequence(newItems, k.att());
65+
} else {
66+
return k;
67+
}
68+
}
69+
70+
@Override
71+
public K apply(InjectedKLabel k) {
72+
return k;
73+
}
74+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) 2015 K Team. All Rights Reserved.
2+
package org.kframework.kore.compile;
3+
4+
import org.kframework.kore.*;
5+
6+
/**
7+
* Created by brandon on 3/30/15.
8+
*/
9+
public class VisitKORE extends AbstractKORETransformer<Void> {
10+
11+
@Override
12+
public Void apply(KApply k) {
13+
k.klist().items().stream().forEach(this::apply);
14+
return null;
15+
}
16+
17+
@Override
18+
public Void apply(KRewrite k) {
19+
apply(k.left());
20+
apply(k.right());
21+
return null;
22+
}
23+
24+
@Override
25+
public Void apply(KToken k) {
26+
return null;
27+
}
28+
29+
@Override
30+
public Void apply(KVariable k) {
31+
return null;
32+
}
33+
34+
@Override
35+
public Void apply(KSequence k) {
36+
k.items().stream().forEach(this::apply);
37+
return null;
38+
}
39+
40+
@Override
41+
public Void apply(InjectedKLabel k) {
42+
return null;
43+
}
44+
}

kernel/src/main/java/org/kframework/kore/convertors/KILtoKORE.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,7 @@
4040
import org.kframework.attributes.Att;
4141
import org.kframework.definition.*;
4242

43-
import org.kframework.kore.AbstractKORETransformer;
44-
import org.kframework.kore.K;
45-
import org.kframework.kore.KApply;
46-
import org.kframework.kore.KCollection;
47-
import org.kframework.kore.KRewrite;
48-
import org.kframework.kore.KSequence;
49-
import org.kframework.kore.KToken;
50-
import org.kframework.kore.KVariable;
51-
import org.kframework.kore.Sort;
43+
import org.kframework.kore.*;
5244
import org.kframework.parser.generator.SDFHelper;
5345
import org.kframework.utils.errorsystem.KExceptionManager;
5446
import scala.Enumeration.Value;
@@ -201,6 +193,11 @@ public Set<Tuple2<K, Sort>> apply(KToken k) {
201193
return Sets.newHashSet();
202194
}
203195

196+
@Override
197+
public Set<Tuple2<K, Sort>> apply(InjectedKLabel k) {
198+
return Sets.newHashSet();
199+
}
200+
204201
@Override
205202
public Set<Tuple2<K, Sort>> apply(KVariable k) {
206203
return (Set<Tuple2<K, Sort>>) k.att().<String>getOptional("sort")

0 commit comments

Comments
 (0)