Skip to content

Commit c2174bc

Browse files
author
dwightguth
authored
a few helper methods for the scala kore code (#413)
1 parent 3e04cbd commit c2174bc

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

kore/src/main/scala/org/kframework/parser/kore/Default.scala

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,17 @@ object implementation {
6666

6767
case class StringLiteral(str: String) extends i.StringLiteral
6868

69-
case class SortVariable(name: String) extends i.SortVariable
69+
case class SortVariable(name: String) extends i.SortVariable {
70+
override def toString = name
71+
}
7072

71-
case class CompoundSort(ctr: String, params: Seq[i.Sort]) extends i.CompoundSort
73+
case class CompoundSort(ctr: String, params: Seq[i.Sort]) extends i.CompoundSort {
74+
override def toString = ctr + "{" + params.map(_.toString).mkString(", ") + "}"
75+
}
7276

73-
case class SymbolOrAlias(ctr: String, params: Seq[i.Sort]) extends i.SymbolOrAlias
77+
case class SymbolOrAlias(ctr: String, params: Seq[i.Sort]) extends i.SymbolOrAlias {
78+
override def toString = ctr + "{" + params.map(_.toString).mkString(", ") + "}"
79+
}
7480

7581
case class Symbol(ctr: String, params: Seq[i.Sort]) extends i.Symbol
7682

@@ -125,13 +131,13 @@ object implementation {
125131

126132
// def Next(s: i.Sort, _1: i.Pattern): i.Pattern = d.Next(s, _1)
127133

128-
def Rewrites(s: i.Sort, _1: i.Pattern, _2: i.Pattern): i.Pattern = d.Rewrites(s, _1, _2)
134+
def Rewrites(s: i.Sort, _1: i.Pattern, _2: i.Pattern): i.Rewrites = d.Rewrites(s, _1, _2)
129135

130136
def Ceil(s: i.Sort, rs: i.Sort, p: Pattern): i.Pattern = d.Ceil(s, rs, p)
131137

132138
def Floor(s: i.Sort, rs: i.Sort, p: Pattern): i.Pattern = d.Floor(s, rs, p)
133139

134-
def Equals(s: i.Sort, rs: i.Sort, _1: i.Pattern, _2: i.Pattern): i.Pattern = d.Equals(s, rs, _1, _2)
140+
def Equals(s: i.Sort, rs: i.Sort, _1: i.Pattern, _2: i.Pattern): i.Equals = d.Equals(s, rs, _1, _2)
135141

136142
def Mem(s: i.Sort, rs: i.Sort, p: i.Pattern, q: i.Pattern): i.Pattern = d.Mem(s, rs, p, q)
137143

kore/src/main/scala/org/kframework/parser/kore/Interface.scala

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,7 @@ object SortDeclaration {
4747
= Some(arg.params, arg.sort, arg.att)
4848
}
4949

50-
trait HookSortDeclaration extends Declaration {
51-
def params: Seq[SortVariable]
52-
53-
def sort: Sort
54-
55-
def att: Attributes
50+
trait HookSortDeclaration extends SortDeclaration {
5651
}
5752

5853
object HookSortDeclaration {
@@ -75,14 +70,7 @@ object SymbolDeclaration {
7570
= Some(arg.symbol, arg.argSorts, arg.returnSort, arg.att)
7671
}
7772

78-
trait HookSymbolDeclaration extends Declaration {
79-
def symbol: Symbol
80-
81-
def argSorts: Seq[Sort]
82-
83-
def returnSort: Sort
84-
85-
def att: Attributes
73+
trait HookSymbolDeclaration extends SymbolDeclaration {
8674
}
8775

8876
object HookSymbolDeclaration {
@@ -287,33 +275,52 @@ object Floor {
287275
// def unapply(arg: Next): Option[(Sort, Pattern)] = Some(arg.s, arg._1)
288276
// }
289277

278+
trait GeneralizedRewrite {
279+
def sort: Sort
280+
def getLeftHandSide: Seq[Pattern]
281+
def getRightHandSide: Pattern
282+
}
283+
290284
/**
291285
* \rewrites(P, Q) is defined as a predicate pattern floor(P implies Q)
292286
* Therefore a rewrites-to pattern is parametric on two sorts.
293287
* One is the sort of patterns P and Q;
294288
* The other is the sort of the context.
295289
*/
296-
trait Rewrites extends Pattern {
290+
trait Rewrites extends Pattern with GeneralizedRewrite {
297291
def s: Sort // the sort of the two patterns P and Q
298292

293+
def sort = s
294+
299295
def _1: Pattern
300296

301297
def _2: Pattern
298+
299+
def getLeftHandSide = Seq(_1)
300+
def getRightHandSide = _2
302301
}
303302

304303
object Rewrites {
305304
def unapply(arg: Rewrites): Option[(Sort, Pattern, Pattern)] =
306305
Some(arg.s, arg._1, arg._2)
307306
}
308307

309-
trait Equals extends Pattern {
308+
trait Equals extends Pattern with GeneralizedRewrite {
310309
def s: Sort // the sort of the two patterns that are being compared
311310

312311
def rs: Sort // the sort of the context where the equality pattern is being placed
313312

313+
def sort = rs
314+
314315
def _1: Pattern
315316

316317
def _2: Pattern
318+
319+
def getLeftHandSide = _1 match {
320+
case Application(_, ps) => ps
321+
}
322+
323+
def getRightHandSide = _2
317324
}
318325

319326
object Equals {

0 commit comments

Comments
 (0)