Skip to content

Commit

Permalink
Clean up ResolveIOStreams
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltoli committed Oct 24, 2023
1 parent 08fbf2b commit ccc09ac
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions kernel/src/main/java/org/kframework/compile/ResolveIOStreams.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,8 @@
/**
* Created by daejunpark on 9/6/15.
*/
public class ResolveIOStreams {

private final Definition definition;

private final KExceptionManager kem;

public ResolveIOStreams(Definition definition, KExceptionManager kem) {
this.definition = definition;
this.kem = kem;
}
public record ResolveIOStreams(Definition definition,
KExceptionManager kem) {

/**
* Update modules that declare stream cells in configuration,
Expand Down Expand Up @@ -83,7 +75,7 @@ public Module resolve(Module m) {
sentences.addAll(getStreamModuleSentences(p));
}
}
return Module(m.name(), (Set<Import>)m.imports().
return Module(m.name(), (Set<Import>) m.imports().
$bar(Set(Import(definition.getModule("K-IO").get(), true))).
$bar(Set(Import(definition.getModule("K-REFLECTION").get(), true))),
immutable(sentences), m.att());
Expand All @@ -94,8 +86,7 @@ public Module resolve(Module m) {
private java.util.Set<Production> getStreamProductions(Set<Sentence> sentences) {
java.util.Set<Production> productions = new HashSet<>();
for (Sentence s : mutable(sentences)) {
if (s instanceof Production) {
Production p = (Production) s;
if (s instanceof Production p) {
if (p.att().getOption(Att.STREAM()).isDefined()) {
checkStreamName(p.att().get(Att.STREAM()));
productions.add(p);
Expand Down Expand Up @@ -165,8 +156,7 @@ private KList getContentsOfInitRule(Production streamProduction) {

java.util.List<Sentence> initRules =
stream(getStreamModule(streamName).localSentences())
.filter(s -> isInitRule(initLabel, cellLabel, s))
.collect(Collectors.toList());
.filter(s -> isInitRule(initLabel, cellLabel, s)).toList();
assert initRules.size() == 1;
Sentence initRule = initRules.get(0);

Expand All @@ -187,8 +177,7 @@ private java.util.Set<Sentence> getStreamModuleSentences(Production streamProduc

java.util.Set<Sentence> sentences = new HashSet<>();
for (Sentence s : mutable(getStreamModule(streamName).localSentences())) {
if (s instanceof Rule) {
Rule rule = (Rule) s;
if (s instanceof Rule rule) {
if (rule.att().contains(Att.STREAM())) {
// Update cell names
K body = new TransformK() {
Expand All @@ -212,8 +201,7 @@ private KLabel apply(KLabel klabel) {
} else if (rule.att().contains(Att.PROJECTION())) {
sentences.add(rule);
}
} else if (s instanceof Production) {
Production production = (Production) s;
} else if (s instanceof Production production) {
if (production.sort().toString().equals("Stream") || production.att().contains(Att.PROJECTION())) {
sentences.add(production);
}
Expand Down Expand Up @@ -257,8 +245,7 @@ private java.util.Set<Sentence> getStdinStreamUnblockingRules(Production streamP
// find rules with currently supported matching patterns
java.util.Set<Tuple2<Rule, String>> rules = new HashSet<>();
for (Sentence s : sentences) {
if (s instanceof Rule) {
Rule rule = (Rule) s;
if (s instanceof Rule rule) {
java.util.List<String> sorts = isSupportingRulePatternAndGetSortNameOfCast(streamProduction, rule);
assert sorts.size() <= 1;
if (sorts.size() == 1) {
Expand Down Expand Up @@ -392,8 +379,7 @@ private K getUnblockRuleBody(Production streamProduction, String sort) {
KLabel userCellLabel = streamProduction.klabel().get(); // <in>

java.util.List<Sentence> unblockRules = stream(getStreamModule(streamName).localSentences())
.filter(s -> s instanceof Rule && s.att().getOptional(Att.LABEL()).map(lbl -> lbl.equals("STDIN-STREAM.stdinUnblock")).orElse(false))
.collect(Collectors.toList());
.filter(s -> s instanceof Rule && s.att().getOptional(Att.LABEL()).map(lbl -> lbl.equals("STDIN-STREAM.stdinUnblock")).orElse(false)).toList();
assert unblockRules.size() == 1;
Rule unblockRule = (Rule) unblockRules.get(0);

Expand All @@ -402,8 +388,7 @@ private K getUnblockRuleBody(Production streamProduction, String sort) {
public K apply(KApply k) {
if (k.klabel().name().equals("#SemanticCastToString") && k.klist().size() == 1) {
K i = k.klist().items().get(0);
if (i instanceof KVariable) {
KVariable x = (KVariable) i;
if (i instanceof KVariable x) {
switch (x.name()) {
case "?Sort":
return KToken("\"" + sort + "\"", Sorts.String());
Expand Down

0 comments on commit ccc09ac

Please sign in to comment.