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 EtsScene #261

Merged
merged 42 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a620c94
Move example
Lipen Aug 8, 2024
5cce043
Update structure guide
Lipen Aug 8, 2024
afe9cdd
Cleanup gradle task
Lipen Aug 8, 2024
18098bf
Remove default ArkAnalyzer directory
Lipen Aug 8, 2024
58bf240
Use absolute
Lipen Aug 8, 2024
3a1414a
Cleanup gradle task
Lipen Aug 8, 2024
c36a4ef
Remove JSON dumps, move source
Lipen Aug 8, 2024
942672b
Add some messages
Lipen Aug 8, 2024
ff5e390
Fix path
Lipen Aug 8, 2024
cb71bc2
Reorganize
Lipen Aug 8, 2024
4de3412
Fix generated path
Lipen Aug 8, 2024
b767697
Fix source name
Lipen Aug 8, 2024
4c0a45f
Add fancy Path.resolveSibling extension
Lipen Aug 8, 2024
5d0be84
Simplify DOT generation
Lipen Aug 8, 2024
6850181
Update structure
Lipen Aug 8, 2024
a054327
Generate test resources in GHA
Lipen Aug 8, 2024
ceb85b6
Add EtsScene
Lipen Aug 13, 2024
fbd5832
Refactor signatures
Lipen Aug 14, 2024
41da8ce
Merge branch 'lipen/resources'
Lipen Aug 14, 2024
ec48da2
Cleanup
Lipen Aug 14, 2024
caacd15
Fix test
Lipen Aug 14, 2024
e63d952
Fix 'declaringClass' serialized field
Lipen Aug 14, 2024
3843215
Make declaringFile for ClassDto optional
Lipen Aug 14, 2024
32bc70d
Fix test
Lipen Aug 14, 2024
e0a5e19
Fix toString
Lipen Aug 14, 2024
95bc14f
Resolve callees by signature
Lipen Aug 14, 2024
5925b43
Remove "auto-convert-with-dot" loader
Lipen Aug 16, 2024
22231cc
Move .gitignore out of resources
Lipen Aug 16, 2024
4e5c7eb
Ignore generated folder
Lipen Aug 16, 2024
3e2de48
Fix import
Lipen Aug 16, 2024
458d3cd
Add test with EtsScene
Lipen Aug 16, 2024
7981613
Replace 'name' with 'signature'
Lipen Aug 16, 2024
081b8e1
Update ArkAnalyzer neo branch
Lipen Aug 16, 2024
dd0542e
Comment
Lipen Aug 16, 2024
258f764
Comment
Lipen Aug 16, 2024
836c756
Comment
Lipen Aug 16, 2024
9946091
Fix ClassSignatureDto.toString
Lipen Aug 16, 2024
3b48655
Fix NamespaceSignatureDto.toString
Lipen Aug 16, 2024
d89337b
Remove check in DTO
Lipen Aug 16, 2024
9288f88
Fix MethodSignatureDto.toString
Lipen Aug 16, 2024
3c27a63
Remove custom 'equals' for data classes
Lipen Aug 16, 2024
569ef06
Merge branch 'origin/neo'
Lipen Aug 16, 2024
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 .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
DEST_DIR="arkanalyzer"
MAX_RETRIES=10
RETRY_DELAY=3 # Delay between retries in seconds
BRANCH="neo/2024-08-07"
BRANCH="neo/2024-08-16"

for ((i=1; i<=MAX_RETRIES; i++)); do
git clone --depth=1 --branch $BRANCH $REPO_URL $DEST_DIR && break
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
build/
idea-community
*.db
/generated/
4 changes: 4 additions & 0 deletions jacodb-ets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/src/test/resources/samples/etsir
/src/test/resources/projects

*.abc
68 changes: 49 additions & 19 deletions jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Convert.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,14 @@
import org.jacodb.ets.model.EtsFieldSignature
import org.jacodb.ets.model.EtsFieldSubSignature
import org.jacodb.ets.model.EtsFile
import org.jacodb.ets.model.EtsFileSignature
import org.jacodb.ets.model.EtsMethod
import org.jacodb.ets.model.EtsMethodImpl
import org.jacodb.ets.model.EtsMethodParameter
import org.jacodb.ets.model.EtsMethodSignature
import org.jacodb.ets.model.EtsMethodSubSignature
import org.jacodb.ets.model.EtsNamespace
import org.jacodb.ets.model.EtsNamespaceSignature

class EtsMethodBuilder(
signature: EtsMethodSignature,
Expand Down Expand Up @@ -187,8 +190,13 @@

is AssignStmtDto -> {
val lhv = convertToEtsEntity(stmt.left) as EtsValue // safe cast
check(lhv is EtsLocal || lhv is EtsFieldRef || lhv is EtsArrayAccess) {
"LHV of AssignStmt should be EtsLocal, EtsFieldRef, or EtsArrayAccess, but got $lhv"

Check warning on line 194 in jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Convert.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Convert.kt#L194

Added line #L194 was not covered by tests
}
val rhv = convertToEtsEntity(stmt.right).let {
if (it is EtsCastExpr || it is EtsNewExpr) {
if (lhv is EtsLocal) {
it
} else if (it is EtsCastExpr || it is EtsNewExpr) {
it
} else {
ensureOneAddress(it)
Expand Down Expand Up @@ -516,7 +524,7 @@
val cfg = CfgDto(blocks = listOf(zeroBlock))
val body = BodyDto(locals = emptyList(), cfg = cfg)
val signature = MethodSignatureDto(
enclosingClass = classSignatureDto,
declaringClass = classSignatureDto,
name = "constructor",
parameters = emptyList(),
returnType = ClassTypeDto(classSignatureDto),
Expand All @@ -529,16 +537,12 @@
)
}

val signature = EtsClassSignature(
name = classDto.signature.name,
namespace = null, // TODO
file = null, // TODO
)
val signature = convertToEtsClassSignature(classDto.signature)
val superClassSignature = classDto.superClassName?.takeIf { it != "" }?.let { name ->
EtsClassSignature(
name = name,
namespace = null, // TODO
file = null, // TODO
namespace = null, // TODO
)
}

Expand Down Expand Up @@ -658,17 +662,32 @@
}
}

fun convertToEtsFileSignature(file: FileSignatureDto): EtsFileSignature {
return EtsFileSignature(
projectName = file.projectName,
fileName = file.fileName,
)
}

fun convertToEtsNamespaceSignature(namespace: NamespaceSignatureDto): EtsNamespaceSignature {
return EtsNamespaceSignature(
name = namespace.name,

Check warning on line 674 in jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Convert.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Convert.kt#L673-L674

Added lines #L673 - L674 were not covered by tests
file = namespace.declaringFile?.let { convertToEtsFileSignature(it) },
namespace = namespace.declaringNamespace?.let { convertToEtsNamespaceSignature(it) },
)
}

fun convertToEtsClassSignature(clazz: ClassSignatureDto): EtsClassSignature {
return EtsClassSignature(
name = clazz.name,
namespace = null, // TODO
file = null, // TODO
file = clazz.declaringFile?.let { convertToEtsFileSignature(it) },
namespace = clazz.declaringNamespace?.let { convertToEtsNamespaceSignature(it) },
)
}

fun convertToEtsFieldSignature(field: FieldSignatureDto): EtsFieldSignature {
return EtsFieldSignature(
enclosingClass = convertToEtsClassSignature(field.enclosingClass),
enclosingClass = convertToEtsClassSignature(field.declaringClass),
sub = EtsFieldSubSignature(
name = field.name,
type = convertToEtsType(field.type),
Expand All @@ -678,7 +697,7 @@

fun convertToEtsMethodSignature(method: MethodSignatureDto): EtsMethodSignature {
return EtsMethodSignature(
enclosingClass = convertToEtsClassSignature(method.enclosingClass),
enclosingClass = convertToEtsClassSignature(method.declaringClass),
sub = EtsMethodSubSignature(
name = method.name,
parameters = method.parameters.mapIndexed { index, param ->
Expand Down Expand Up @@ -715,7 +734,7 @@
fun convertToEtsField(field: FieldDto): EtsField {
return EtsFieldImpl(
signature = EtsFieldSignature(
enclosingClass = convertToEtsClassSignature(field.signature.enclosingClass),
enclosingClass = convertToEtsClassSignature(field.signature.declaringClass),
sub = EtsFieldSubSignature(
name = field.signature.name,
type = convertToEtsType(field.signature.type),
Expand All @@ -730,13 +749,24 @@
)
}

fun convertToEtsNamespace(namespace: NamespaceDto): EtsNamespace {
val signature = convertToEtsNamespaceSignature(namespace.signature)
val classes = namespace.classes.map { convertToEtsClass(it) }
val namespaces = namespace.namespaces.map { convertToEtsNamespace(it) }
return EtsNamespace(
signature = signature,
classes = classes,
namespaces = namespaces,

Check warning on line 759 in jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Convert.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Convert.kt#L753-L759

Added lines #L753 - L759 were not covered by tests
)
}

fun convertToEtsFile(file: EtsFileDto): EtsFile {
val classesFromNamespaces = file.namespaces.flatMap { it.classes }
val allClasses = file.classes + classesFromNamespaces
val convertedClasses = allClasses.map { convertToEtsClass(it) }
val signature = convertToEtsFileSignature(file.signature)
val classes = file.classes.map { convertToEtsClass(it) }
val namespaces = file.namespaces.map { convertToEtsNamespace(it) }
return EtsFile(
name = file.name,
path = file.absoluteFilePath,
classes = convertedClasses,
signature = signature,
classes = classes,
namespaces = namespaces,
)
}
2 changes: 1 addition & 1 deletion jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Graph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ data class CfgDto(
data class BasicBlockDto(
val id: Int,
val successors: List<Int>,
val predecessors: List<Int>,
val predecessors: List<Int>? = null,
val stmts: List<StmtDto>,
)
9 changes: 3 additions & 6 deletions jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Model.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@

@Serializable
data class EtsFileDto(
val name: String,
val absoluteFilePath: String? = null,
val projectDir: String? = null,
val projectName: String? = null,
val signature: FileSignatureDto,
val namespaces: List<NamespaceDto>,
val classes: List<ClassDto>,
val importInfos: List<ImportInfoDto>,
Expand All @@ -49,9 +46,9 @@

@Serializable
data class NamespaceDto(
val name: String,
val namespaces: List<NamespaceDto> = emptyList(),
val signature: NamespaceSignatureDto,

Check warning on line 49 in jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Model.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Model.kt#L49

Added line #L49 was not covered by tests
val classes: List<ClassDto> = emptyList(),
val namespaces: List<NamespaceDto> = emptyList(),

Check warning on line 51 in jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Model.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Model.kt#L51

Added line #L51 was not covered by tests
)

@Serializable
Expand Down
44 changes: 40 additions & 4 deletions jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Signatures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,53 @@

import kotlinx.serialization.Serializable

@Serializable
data class FileSignatureDto(
val projectName: String,
val fileName: String,
) {
override fun toString(): String {
return "@$projectName/$fileName"
}
}

@Serializable
data class NamespaceSignatureDto(
val name: String,
val declaringFile: FileSignatureDto? = null,
val declaringNamespace: NamespaceSignatureDto? = null,

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

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Signatures.kt#L33-L35

Added lines #L33 - L35 were not covered by tests
) {
override fun toString(): String {
return if (declaringNamespace != null) {
"$declaringNamespace::$name"

Check warning on line 39 in jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Signatures.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Signatures.kt#L39

Added line #L39 was not covered by tests
} else if (declaringFile != null) {
"$name in $declaringFile"

Check warning on line 41 in jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Signatures.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Signatures.kt#L41

Added line #L41 was not covered by tests
} else {
name

Check warning on line 43 in jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Signatures.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Signatures.kt#L43

Added line #L43 was not covered by tests
}
}
}

@Serializable
data class ClassSignatureDto(
val name: String,
val declaringFile: FileSignatureDto? = null,
val declaringNamespace: NamespaceSignatureDto? = null,
) {
override fun toString(): String {
return name
return if (declaringNamespace != null) {
"$declaringNamespace::$name"

Check warning on line 56 in jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Signatures.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Signatures.kt#L56

Added line #L56 was not covered by tests
} else if (declaringFile != null) {
"$name in $declaringFile"
} else {
name

Check warning on line 60 in jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Signatures.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Signatures.kt#L60

Added line #L60 was not covered by tests
}
}
}

@Serializable
data class FieldSignatureDto(
val enclosingClass: ClassSignatureDto,
val declaringClass: ClassSignatureDto,
val name: String,
val type: TypeDto,
) {
Expand All @@ -40,13 +75,14 @@

@Serializable
data class MethodSignatureDto(
val enclosingClass: ClassSignatureDto,
val declaringClass: ClassSignatureDto,
val name: String,
val parameters: List<MethodParameterDto>,
val returnType: TypeDto,
) {
override fun toString(): String {
return "$name(${parameters.joinToString { it.toString() }}): $returnType"
val params = parameters.joinToString()
return "$name($params): $returnType"
}
}

Expand Down
2 changes: 1 addition & 1 deletion jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Values.kt
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,6 @@
override val field: FieldSignatureDto,
) : FieldRefDto {
override fun toString(): String {
return "${field.enclosingClass.name}.${field.name}"
return "${field.declaringClass.name}.${field.name}"

Check warning on line 432 in jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Values.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Values.kt#L432

Added line #L432 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ package org.jacodb.ets.graph

import org.jacodb.api.common.analysis.ApplicationGraph
import org.jacodb.ets.base.EtsStmt
import org.jacodb.ets.model.EtsFile
import org.jacodb.ets.model.EtsMethod
import org.jacodb.ets.model.EtsScene
import org.jacodb.ets.utils.callExpr

interface EtsApplicationGraph : ApplicationGraph<EtsMethod, EtsStmt> {
val cp: EtsFile
val cp: EtsScene
}

class EtsApplicationGraphImpl(
override val cp: EtsFile,
override val cp: EtsScene,
) : EtsApplicationGraph {

override fun predecessors(node: EtsStmt): Sequence<EtsStmt> {
Expand All @@ -45,9 +45,10 @@ class EtsApplicationGraphImpl(
override fun callees(node: EtsStmt): Sequence<EtsMethod> {
val expr = node.callExpr ?: return emptySequence()
val callee = expr.method
return cp.classes.asSequence()
return cp.classes
.asSequence()
.flatMap { it.methods }
.filter { it.name == callee.name }
.filter { it.signature == callee }
}

override fun callers(method: EtsMethod): Sequence<EtsStmt> {
Expand Down
20 changes: 9 additions & 11 deletions jacodb-ets/src/main/kotlin/org/jacodb/ets/model/EtsFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@

package org.jacodb.ets.model

import org.jacodb.api.common.CommonProject

class EtsFile(
val name: String,
val path: String? = null,
val signature: EtsFileSignature,
val classes: List<EtsClass>,
) : CommonProject {

fun getMethodBySignature(signature: EtsMethodSignature): EtsMethod? {
return classes.asSequence().flatMap { it.methods }.firstOrNull { it.signature == signature }
}
val namespaces: List<EtsNamespace>,
) {
val name: String
get() = signature.fileName
val projectName: String
get() = signature.projectName

Check warning on line 27 in jacodb-ets/src/main/kotlin/org/jacodb/ets/model/EtsFile.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/model/EtsFile.kt#L27

Added line #L27 was not covered by tests

fun getClassBySignature(signature: EtsClassSignature): EtsClass? {
return classes.firstOrNull { it.signature == signature }
override fun toString(): String {
return name
}
}
23 changes: 23 additions & 0 deletions jacodb-ets/src/main/kotlin/org/jacodb/ets/model/EtsNamespace.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2022 UnitTestBot contributors (utbot.org)
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jacodb.ets.model

class EtsNamespace(
val signature: EtsNamespaceSignature,
val classes: List<EtsClass>,
val namespaces: List<EtsNamespace>,

Check warning on line 22 in jacodb-ets/src/main/kotlin/org/jacodb/ets/model/EtsNamespace.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/model/EtsNamespace.kt#L19-L22

Added lines #L19 - L22 were not covered by tests
)
26 changes: 26 additions & 0 deletions jacodb-ets/src/main/kotlin/org/jacodb/ets/model/EtsScene.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2022 UnitTestBot contributors (utbot.org)
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jacodb.ets.model

import org.jacodb.api.common.CommonProject

class EtsScene (
Lipen marked this conversation as resolved.
Show resolved Hide resolved
val files: List<EtsFile>,
): CommonProject {
val classes: List<EtsClass>
get() = files.flatMap { it.classes }
}
Loading
Loading