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

Add Raw Stmt/Value/Type #291

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object Versions {
const val kotlinx_collections_immutable = "0.3.5"
const val kotlinx_coroutines = "1.6.4"
const val kotlin_metadata = kotlin
const val kotlinx_serialization = "1.4.1"
const val kotlinx_serialization = "1.8.0"
const val licenser = "0.6.1"
const val mockk = "1.13.3"
const val sarif4k = "0.5.0"
Expand Down
21 changes: 21 additions & 0 deletions jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
EtsValue.Visitor<R>,
EtsExpr.Visitor<R> {

fun visit(value: EtsRawEntity): R {
if (this is Default) {
return defaultVisit(value)

Check warning on line 33 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#L33

Added line #L33 was not covered by tests
}
error("Cannot handle ${value::class.java.simpleName}: $value")

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
}

interface Default<out R> : Visitor<R>,
EtsValue.Visitor.Default<R>,
EtsExpr.Visitor.Default<R> {
Expand All @@ -41,3 +48,17 @@

fun <R> accept(visitor: Visitor<R>): R
}

data class EtsRawEntity(
val kind: String,
val extra: Map<String, Any> = emptyMap(),
override val type: EtsType,
) : EtsEntity {

Check warning on line 56 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#L52-L56

Added lines #L52 - L56 were not covered by tests
override fun toString(): String {
return "$kind $extra: $type"

Check warning on line 58 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#L58

Added line #L58 was not covered by tests
}

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

Check warning on line 62 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#L62

Added line #L62 was not covered by tests
}
}
82 changes: 41 additions & 41 deletions jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsRef.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,47 +45,47 @@ data class EtsParameterRef(
}
}

data class EtsCaughtExceptionRef(
override val type: EtsType,
) : EtsValue {
override fun toString(): String {
return "catch($type)"
}

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

data class EtsGlobalRef(
val name: String,
val ref: EtsValue?, // TODO: check whether it could be EtsEntity at best
) : EtsValue {
override val type: EtsType
get() = ref?.type ?: EtsUnknownType

override fun toString(): String {
return "global $name"
}

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

data class EtsClosureFieldRef(
val base: EtsLocal,
val fieldName: String,
override val type: EtsType,
) : EtsValue {
override fun toString(): String {
return "$base.$fieldName"
}

override fun <R> accept(visitor: EtsValue.Visitor<R>): R {
return visitor.visit(this)
}
}
// data class EtsCaughtExceptionRef(
// override val type: EtsType,
// ) : EtsValue {
// override fun toString(): String {
// return "catch($type)"
// }
//
// override fun <R> accept(visitor: EtsValue.Visitor<R>): R {
// return visitor.visit(this)
// }
// }
//
// data class EtsGlobalRef(
// val name: String,
// val ref: EtsValue?, // TODO: check whether it could be EtsEntity at best
// ) : EtsValue {
// override val type: EtsType
// get() = ref?.type ?: EtsUnknownType
//
// override fun toString(): String {
// return "global $name"
// }
//
// override fun <R> accept(visitor: EtsValue.Visitor<R>): R {
// return visitor.visit(this)
// }
// }
//
// data class EtsClosureFieldRef(
// val base: EtsLocal,
// val fieldName: String,
// override val type: EtsType,
// ) : EtsValue {
// override fun toString(): String {
// return "$base.$fieldName"
// }
//
// override fun <R> accept(visitor: EtsValue.Visitor<R>): R {
// return visitor.visit(this)
// }
// }

data class EtsArrayAccess(
val array: EtsValue,
Expand Down
36 changes: 21 additions & 15 deletions jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsStmt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@
fun visit(stmt: EtsGotoStmt): R
fun visit(stmt: EtsIfStmt): R
fun visit(stmt: EtsSwitchStmt): R
fun visit(stmt: EtsRawStmt): R

fun visit(stmt: EtsRawStmt): R {
if (this is Default) {
return defaultVisit(stmt)

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

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsStmt.kt#L48

Added line #L48 was not covered by tests
}
error("Cannot handle ${stmt::class.java.simpleName}: $stmt")

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

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsStmt.kt#L50

Added line #L50 was not covered by tests
}

interface Default<out R> : Visitor<R> {
override fun visit(stmt: EtsNopStmt): R = defaultVisit(stmt)
Expand All @@ -62,6 +68,20 @@
fun <R> accept(visitor: Visitor<R>): R
}

data class EtsRawStmt(
override val location: EtsInstLocation,
val kind: String,
val extra: Map<String, Any> = emptyMap(),
) : EtsStmt {

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

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsStmt.kt#L71-L75

Added lines #L71 - L75 were not covered by tests
override fun toString(): String {
return "$kind $extra"

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

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsStmt.kt#L77

Added line #L77 was not covered by tests
}

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

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

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsStmt.kt#L81

Added line #L81 was not covered by tests
}
}

data class EtsNopStmt(
override val location: EtsInstLocation,
) : EtsStmt {
Expand Down Expand Up @@ -169,17 +189,3 @@
return visitor.visit(this)
}
}

data class EtsRawStmt(
override val location: EtsInstLocation,
val type: String,
val text: String,
) : EtsStmt {
override fun toString(): String {
return text
}

override fun <R> accept(visitor: EtsStmt.Visitor<R>): R {
return visitor.visit(this)
}
}
91 changes: 24 additions & 67 deletions jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.jacodb.ets.model.EtsClassSignature
import org.jacodb.ets.model.EtsLocalSignature
import org.jacodb.ets.model.EtsMethodSignature
import org.jacodb.ets.model.EtsNamespaceSignature

interface EtsType : CommonType, CommonTypeName {
override val typeName: String
Expand All @@ -45,13 +44,16 @@
fun visit(type: EtsClassType): R
fun visit(type: EtsFunctionType): R
fun visit(type: EtsArrayType): R
fun visit(type: EtsArrayObjectType): R
fun visit(type: EtsUnclearRefType): R
fun visit(type: EtsGenericType): R
fun visit(type: EtsAliasType): R
fun visit(type: EtsAnnotationNamespaceType): R
fun visit(type: EtsAnnotationTypeQueryType): R
fun visit(type: EtsLexicalEnvType): R

fun visit(type: EtsRawType): R {
if (this is Default) {
return defaultVisit(type)

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

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsType.kt#L53

Added line #L53 was not covered by tests
}
error("Cannot handle ${type::class.java.simpleName}: $type")

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

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsType.kt#L55

Added line #L55 was not covered by tests
}

interface Default<R> : Visitor<R> {
override fun visit(type: EtsAnyType): R = defaultVisit(type)
Expand All @@ -69,13 +71,10 @@
override fun visit(type: EtsClassType): R = defaultVisit(type)
override fun visit(type: EtsFunctionType): R = defaultVisit(type)
override fun visit(type: EtsArrayType): R = defaultVisit(type)
override fun visit(type: EtsArrayObjectType): R = defaultVisit(type)
override fun visit(type: EtsUnclearRefType): R = defaultVisit(type)
override fun visit(type: EtsGenericType): R = defaultVisit(type)
override fun visit(type: EtsAliasType): R = defaultVisit(type)
override fun visit(type: EtsAnnotationNamespaceType): R = defaultVisit(type)
override fun visit(type: EtsAnnotationTypeQueryType): R = defaultVisit(type)
override fun visit(type: EtsLexicalEnvType): R = defaultVisit(type)
override fun visit(type: EtsRawType): R = defaultVisit(type)

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

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsType.kt#L77

Added line #L77 was not covered by tests

fun defaultVisit(type: EtsType): R
}
Expand All @@ -84,6 +83,22 @@
fun <R> accept(visitor: Visitor<R>): R
}

data class EtsRawType(
val kind: String,
val extra: Map<String, Any> = emptyMap(),
) : EtsType {

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

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsType.kt#L86-L89

Added lines #L86 - L89 were not covered by tests
override val typeName: String
get() = kind

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

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsType.kt#L91

Added line #L91 was not covered by tests

override fun toString(): String {
return "$kind $extra"

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

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsType.kt#L94

Added line #L94 was not covered by tests
}

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

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

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsType.kt#L98

Added line #L98 was not covered by tests
}
}

object EtsAnyType : EtsType {
override val typeName: String
get() = "any"
Expand Down Expand Up @@ -278,19 +293,6 @@
}
}

data class EtsArrayObjectType(
val elementType: EtsType,
) : EtsRefType {
override val typeName: String
get() = "Array<${elementType.typeName}>"

override fun toString(): String = typeName

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

data class EtsUnclearRefType(
val name: String,
val typeParameters: List<EtsType> = emptyList(),
Expand Down Expand Up @@ -343,48 +345,3 @@
return visitor.visit(this)
}
}

data class EtsAnnotationNamespaceType(
val originType: String,
val namespaceSignature: EtsNamespaceSignature,
) : EtsType {
override val typeName: String
get() = originType

override fun toString(): String {
return originType
}

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

data class EtsAnnotationTypeQueryType(
val originType: String,
) : EtsType {
override val typeName: String
get() = originType

override fun toString(): String {
return originType
}

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

data class EtsLexicalEnvType(
val nestedMethod: EtsMethodSignature,
val closures: List<EtsLocal>,
) : EtsType {
override val typeName: String
get() = closures.joinToString(prefix = "[", postfix = "]")

override fun toString(): String = typeName

override fun <R> accept(visitor: EtsType.Visitor<R>): R {
return visitor.visit(this)
}
}
6 changes: 0 additions & 6 deletions jacodb-ets/src/main/kotlin/org/jacodb/ets/base/EtsValue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ interface EtsValue : EtsEntity, CommonValue {
// Ref
fun visit(value: EtsThis): R
fun visit(value: EtsParameterRef): R
fun visit(value: EtsCaughtExceptionRef): R
fun visit(value: EtsGlobalRef): R
fun visit(value: EtsClosureFieldRef): R
fun visit(value: EtsArrayAccess): R
fun visit(value: EtsInstanceFieldRef): R
fun visit(value: EtsStaticFieldRef): R
Expand All @@ -50,9 +47,6 @@ interface EtsValue : EtsEntity, CommonValue {

override fun visit(value: EtsThis): R = defaultVisit(value)
override fun visit(value: EtsParameterRef): R = defaultVisit(value)
override fun visit(value: EtsCaughtExceptionRef): R = defaultVisit(value)
override fun visit(value: EtsGlobalRef): R = defaultVisit(value)
override fun visit(value: EtsClosureFieldRef): R = defaultVisit(value)
override fun visit(value: EtsArrayAccess): R = defaultVisit(value)
override fun visit(value: EtsInstanceFieldRef): R = defaultVisit(value)
override fun visit(value: EtsStaticFieldRef): R = defaultVisit(value)
Expand Down
Loading
Loading