Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Ets values, operations, visitors #249

Merged
merged 3 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 8 additions & 36 deletions jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsConstant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,7 @@

package org.jacodb.ets.base

interface EtsConstant : EtsImmediate {
interface Visitor<out R> {
fun visit(value: EtsStringConstant): R
fun visit(value: EtsBooleanConstant): R
fun visit(value: EtsNumberConstant): R
fun visit(value: EtsNullConstant): R
fun visit(value: EtsUndefinedConstant): R
fun visit(value: EtsArrayLiteral): R
fun visit(value: EtsObjectLiteral): R

interface Default<out R> : Visitor<R> {
override fun visit(value: EtsStringConstant): R = defaultVisit(value)
override fun visit(value: EtsBooleanConstant): R = defaultVisit(value)
override fun visit(value: EtsNumberConstant): R = defaultVisit(value)
override fun visit(value: EtsNullConstant): R = defaultVisit(value)
override fun visit(value: EtsUndefinedConstant): R = defaultVisit(value)
override fun visit(value: EtsArrayLiteral): R = defaultVisit(value)
override fun visit(value: EtsObjectLiteral): R = defaultVisit(value)

fun defaultVisit(value: EtsConstant): R
}
}

override fun <R> accept(visitor: EtsImmediate.Visitor<R>): R {
return accept(visitor as Visitor<R>)
}

fun <R> accept(visitor: Visitor<R>): R
}
interface EtsConstant : EtsImmediate

data class EtsStringConstant(
val value: String,
Expand All @@ -56,7 +28,7 @@ data class EtsStringConstant(
return "\"$value\""
}

override fun <R> accept(visitor: EtsConstant.Visitor<R>): R {
override fun <R> accept(visitor: EtsValue.Visitor<R>): R {
return visitor.visit(this)
}
}
Expand All @@ -71,7 +43,7 @@ data class EtsBooleanConstant(
return if (value) "true" else "false"
}

override fun <R> accept(visitor: EtsConstant.Visitor<R>): R {
override fun <R> accept(visitor: EtsValue.Visitor<R>): R {
return visitor.visit(this)
}

Expand All @@ -91,7 +63,7 @@ data class EtsNumberConstant(
return value.toString()
}

override fun <R> accept(visitor: EtsConstant.Visitor<R>): R {
override fun <R> accept(visitor: EtsValue.Visitor<R>): R {
return visitor.visit(this)
}
}
Expand All @@ -102,7 +74,7 @@ object EtsNullConstant : EtsConstant {

override fun toString(): String = "null"

override fun <R> accept(visitor: EtsConstant.Visitor<R>): R {
override fun <R> accept(visitor: EtsValue.Visitor<R>): R {
return visitor.visit(this)
}
}
Expand All @@ -113,7 +85,7 @@ object EtsUndefinedConstant : EtsConstant {

override fun toString(): String = "undefined"

override fun <R> accept(visitor: EtsConstant.Visitor<R>): R {
override fun <R> accept(visitor: EtsValue.Visitor<R>): R {
return visitor.visit(this)
}
}
Expand All @@ -135,7 +107,7 @@ data class EtsArrayLiteral(
return elements.joinToString(prefix = "[", postfix = "]")
}

override fun <R> accept(visitor: EtsConstant.Visitor<R>): R {
override fun <R> accept(visitor: EtsValue.Visitor<R>): R {
return visitor.visit(this)
}
}
Expand All @@ -151,7 +123,7 @@ data class EtsObjectLiteral(
}
}

override fun <R> accept(visitor: EtsConstant.Visitor<R>): R {
override fun <R> accept(visitor: EtsValue.Visitor<R>): R {
return visitor.visit(this)
}
}
13 changes: 5 additions & 8 deletions jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,15 @@
get() = type.typeName

interface Visitor<out R> :
EtsImmediate.Visitor<R>,
EtsExpr.Visitor<R>,
EtsRef.Visitor<R> {
EtsValue.Visitor<R>,
EtsExpr.Visitor<R> {

interface Default<out R> : Visitor<R>,
EtsImmediate.Visitor.Default<R>,
EtsExpr.Visitor.Default<R>,
EtsRef.Visitor.Default<R> {
EtsValue.Visitor.Default<R>,
EtsExpr.Visitor.Default<R> {

override fun defaultVisit(value: EtsImmediate): R = defaultVisit(value as EtsEntity)
override fun defaultVisit(value: EtsValue): R = defaultVisit(value as EtsEntity)

Check warning on line 35 in jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsEntity.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsEntity.kt#L35

Added line #L35 was not covered by tests
override fun defaultVisit(expr: EtsExpr): R = defaultVisit(expr as EtsEntity)
override fun defaultVisit(ref: EtsRef): R = defaultVisit(ref as EtsEntity)

fun defaultVisit(value: EtsEntity): R
}
Expand Down
Loading
Loading