Skip to content

Commit

Permalink
Add DTOs for ArkIR
Browse files Browse the repository at this point in the history
  • Loading branch information
Lipen committed Jun 3, 2024
1 parent 2c5328e commit 166e8f1
Show file tree
Hide file tree
Showing 7 changed files with 2,120 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* 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.panda.dynamic.ark.dto

import kotlinx.serialization.Serializable

@Serializable
data class Ark(
val name: String,
val absoluteFilePath: String,
val projectDir: String,
val projectName: String,
val namespaces: List<Namespace>,
val classes: List<Class>,
val importInfos: List<ImportInfo>,
val exportInfos: List<ExportInfo>,
)

@Serializable
data class Namespace(
val name: String,
val classes: List<Class>,
)

@Serializable
data class Class(
val name: String,
val modifiers: List<String>,
val typeParameters: List<String>,
val superClassName: String?,
val implementedInterfaceNames: List<String>,
val fields: List<Field>,
val methods: List<Method>,
)

@Serializable
data class Field(
val name: String,
val modifiers: List<String>,
val type: String?,
val questionToken: Boolean,
val initializer: Value?,
)

@Serializable
data class Method(
val name: String,
val modifiers: List<String>,
val typeParameters: List<String>,
val parameters: List<Parameter>,
val returnType: String,
val body: List<Stmt>,
)

@Serializable
data class Parameter(
val name: String,
val optional: Boolean,
val type: String,
)

@Serializable
data class ImportInfo(
val importClauseName: String,
val importType: String,
val importFrom: String,
val nameBeforeAs: String?,
val clauseType: String,
val modifiers: List<String>,
val importFromSignature: FileSignature,
val importProjectType: String,
val originTsPosition: LineColPosition,
)

@Serializable
data class ExportInfo(
val exportClauseName: String,
val exportClauseType: String,
val exportFrom: String? = null,
val nameBeforeAs: String? = null,
val declaringSignature: String? = null,
val isDefault: Boolean,
val importInfo: ImportInfo? = null,
val modifiers: List<String>,
val originTsPosition: LineColPosition,
)

// @Serializable
// data class Decorator(
// val kind: String,
// val type: String?,
// )

@Serializable
data class FileSignature(
val projectName: String,
val fileName: String,
)

@Serializable
data class LineColPosition(
val line: Int,
val col: Int,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* 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.panda.dynamic.ark.dto

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonElement

@Serializable
sealed interface Stmt

@Serializable
@SerialName("UnknownStmt")
data class UnknownStmt(
val stmt: JsonElement,
) : Stmt

@Serializable
@SerialName("NopStmt")
object NopStmt : Stmt {
override fun toString(): String = javaClass.simpleName
}

@Serializable
@SerialName("AssignStmt")
data class AssignStmt(
val left: Local,
val right: Value,
) : Stmt

@Serializable
@SerialName("CallStmt")
data class CallStmt(
val expr: CallExpr,
) : Stmt

@Serializable
@SerialName("DeleteStmt")
data class DeleteStmt(
val arg: FieldRef,
) : Stmt

@Serializable
sealed interface TerminatingStmt : Stmt

@Serializable
@SerialName("ReturnStmt")
data class ReturnStmt(
val arg: Value?,
) : TerminatingStmt

@Serializable
@SerialName("ThrowStmt")
data class ThrowStmt(
val arg: Value,
) : TerminatingStmt

@Serializable
sealed interface BranchingStmt : Stmt

@Serializable
@SerialName("GotoStmt")
object GotoStmt : BranchingStmt {
override fun toString(): String = javaClass.simpleName
}

@Serializable
@SerialName("IfStmt")
data class IfStmt(
val condition: ConditionExpr,
) : BranchingStmt

@Serializable
@SerialName("SwitchStmt")
data class SwitchStmt(
val arg: Value,
val cases: List<Value>,
) : BranchingStmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* 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.panda.dynamic.ark.dto

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
sealed interface Type

@Serializable
@SerialName("AnyType")
object AnyType : Type {
override fun toString(): String = javaClass.simpleName
}

@Serializable
@SerialName("UnknownType")
object UnknownType : Type {
override fun toString(): String = javaClass.simpleName
}

@Serializable
@SerialName("UnionType")
data class UnionType(
val types: List<Type>,
) : Type

@Serializable
@SerialName("IntersectionType")
data class TupleType(
val types: List<Type>,
) : Type

// TODO: EnumType

@Serializable
sealed interface PrimitiveType : Type

@Serializable
@SerialName("BooleanType")
object BooleanType : PrimitiveType {
override fun toString(): String = javaClass.simpleName
}

@Serializable
@SerialName("NumberType")
object NumberType : PrimitiveType {
override fun toString(): String = javaClass.simpleName
}

@Serializable
@SerialName("StringType")
object StringType : PrimitiveType {
override fun toString(): String = javaClass.simpleName
}

@Serializable
@SerialName("NullType")
object NullType : PrimitiveType {
override fun toString(): String = javaClass.simpleName
}

@Serializable
@SerialName("UndefinedType")
object UndefinedType : PrimitiveType {
override fun toString(): String = javaClass.simpleName
}

@Serializable
@SerialName("VoidType")
object VoidType : PrimitiveType {
override fun toString(): String = javaClass.simpleName
}

@Serializable
@SerialName("NeverType")
object NeverType : PrimitiveType {
override fun toString(): String = javaClass.simpleName
}

@Serializable
@SerialName("LiteralType")
data class LiteralType(
val literal: String,
) : PrimitiveType

@Serializable
sealed interface RefType : Type

@Serializable
@SerialName("ClassType")
data class ClassType(
val className: String,
) : RefType

@Serializable
@SerialName("ArrayType")
data class ArrayType(
val elementType: Type,
val dimensions: Int,
) : RefType

@Serializable
@SerialName("ArrayObjectType")
data class ArrayObjectType(
val elementType: Type,
) : RefType

@Serializable
@SerialName("UnclearRefType")
data class UnclearRefType(
val typeName: String,
) : RefType
Loading

0 comments on commit 166e8f1

Please sign in to comment.