From 166e8f16b53b75843d8f5978791b0815980ea921 Mon Sep 17 00:00:00 2001 From: Konstantin Chukharev Date: Mon, 3 Jun 2024 20:54:34 +0300 Subject: [PATCH] Add DTOs for ArkIR --- .../org/jacodb/panda/dynamic/ark/dto/Ark.kt | 118 ++ .../org/jacodb/panda/dynamic/ark/dto/Stmt.kt | 92 ++ .../org/jacodb/panda/dynamic/ark/dto/Type.kt | 128 ++ .../org/jacodb/panda/dynamic/ark/dto/Value.kt | 329 ++++ .../org/jacodb/panda/dynamic/ark/dto/io.kt | 37 + .../src/test/kotlin/ark/ArkFromJsonTest.kt | 31 + .../src/test/resources/basic.ts.json | 1385 +++++++++++++++++ 7 files changed, 2120 insertions(+) create mode 100644 jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Ark.kt create mode 100644 jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Stmt.kt create mode 100644 jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Type.kt create mode 100644 jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Value.kt create mode 100644 jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/io.kt create mode 100644 jacodb-panda-dynamic/src/test/kotlin/ark/ArkFromJsonTest.kt create mode 100644 jacodb-panda-dynamic/src/test/resources/basic.ts.json diff --git a/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Ark.kt b/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Ark.kt new file mode 100644 index 000000000..3e025f2f0 --- /dev/null +++ b/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Ark.kt @@ -0,0 +1,118 @@ +/* + * Copyright 2022 UnitTestBot contributors (utbot.org) + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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, + val classes: List, + val importInfos: List, + val exportInfos: List, +) + +@Serializable +data class Namespace( + val name: String, + val classes: List, +) + +@Serializable +data class Class( + val name: String, + val modifiers: List, + val typeParameters: List, + val superClassName: String?, + val implementedInterfaceNames: List, + val fields: List, + val methods: List, +) + +@Serializable +data class Field( + val name: String, + val modifiers: List, + val type: String?, + val questionToken: Boolean, + val initializer: Value?, +) + +@Serializable +data class Method( + val name: String, + val modifiers: List, + val typeParameters: List, + val parameters: List, + val returnType: String, + val body: List, +) + +@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, + 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, + 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, +) diff --git a/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Stmt.kt b/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Stmt.kt new file mode 100644 index 000000000..be9bab6ea --- /dev/null +++ b/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Stmt.kt @@ -0,0 +1,92 @@ +/* + * Copyright 2022 UnitTestBot contributors (utbot.org) + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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, +) : BranchingStmt diff --git a/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Type.kt b/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Type.kt new file mode 100644 index 000000000..96d0aeba5 --- /dev/null +++ b/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Type.kt @@ -0,0 +1,128 @@ +/* + * Copyright 2022 UnitTestBot contributors (utbot.org) + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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 + +@Serializable +@SerialName("IntersectionType") +data class TupleType( + val types: List, +) : 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 diff --git a/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Value.kt b/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Value.kt new file mode 100644 index 000000000..f7bf53fe1 --- /dev/null +++ b/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Value.kt @@ -0,0 +1,329 @@ +/* + * Copyright 2022 UnitTestBot contributors (utbot.org) + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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 Value { + val type: String +} + +@Serializable +@SerialName("UnknownValue") +data class UnknownValue( + val value: JsonElement?, +) : Value { + override val type: String + get() = "unknown" +} + +@Serializable +sealed interface Immediate : Value + +@Serializable +@SerialName("Local") +data class Local( + val name: String, + override val type: String, +) : Immediate + +@Serializable +@SerialName("Constant") +data class Constant( + val value: String, + override val type: String, +) : Immediate + +// @Serializable +// @SerialName("StringConstant") +// data class StringConstant( +// val value: String, +// ) : Constant { +// override val type: Type +// get() = StringType +// } +// +// @Serializable +// @SerialName("BooleanConstant") +// data class BooleanConstant( +// val value: Boolean, +// ) : Constant { +// override val type: Type +// get() = BooleanType +// +// companion object { +// val TRUE = BooleanConstant(true) +// val FALSE = BooleanConstant(false) +// } +// } +// +// @Serializable +// @SerialName("NumberConstant") +// data class NumberConstant( +// val value: Double, +// ) : Constant { +// override val type: Type +// get() = NumberType +// } +// +// @Serializable +// @SerialName("NullConstant") +// object NullConstant : Constant { +// override val type: Type +// get() = NullType +// +// override fun toString(): String = javaClass.simpleName +// } +// +// @Serializable +// @SerialName("UndefinedConstant") +// object UndefinedConstant : Constant { +// override val type: Type +// get() = UndefinedType +// +// override fun toString(): String = javaClass.simpleName +// } + +// @Serializable +// @SerialName("ArrayLiteral") +// data class ArrayLiteral( +// val elements: List, +// override val type: ArrayType, +// ) : Constant +// +// @Serializable +// @SerialName("ObjectLiteral") +// data class ObjectLiteral( +// val keys: List, +// val values: List, +// override val type: Type, +// ) : Constant + +@Serializable +sealed interface Expr : Value + +@Serializable +@SerialName("NewExpr") +data class NewExpr( + override val type: String, +) : Expr + +@Serializable +@SerialName("NewArrayExpr") +data class NewArrayExpr( + override val type: String, + val size: Value, +) : Expr + +@Serializable +@SerialName("TypeOfExpr") +data class TypeOfExpr( + val arg: Value, +) : Expr { + override val type: String + get() = "string" +} + +@Serializable +@SerialName("InstanceOfExpr") +data class InstanceOfExpr( + val arg: Value, + val checkType: Type, +) : Expr { + override val type: String + get() = "boolean" +} + +@Serializable +@SerialName("LengthExpr") +data class LengthExpr( + val arg: Value, +) : Expr { + override val type: String + get() = "number" +} + +@Serializable +@SerialName("CastExpr") +data class CastExpr( + val arg: Value, + override val type: String, +) : Expr + +@Serializable +@SerialName("PhiExpr") +data class PhiExpr( + val args: List, + // val argToBlock: Map, // TODO + override val type: String, +) : Expr + +@Serializable +@SerialName("ArrayLiteralExpr") +data class ArrayLiteralExpr( + val elements: List, + override val type: String, +) : Expr + +// @Serializable +// @SerialName("ObjectLiteralExpr") +// data class ObjectLiteralExpr( +// val keys: List, +// val values: List, +// override val type: Type, +// ) : Expr + +@Serializable +sealed interface UnaryExpr : Expr { + val arg: Value + + override val type: String + get() = arg.type +} + +@Serializable +@SerialName("UnaryOperation") +data class UnaryOperation( + val op: String, + override val arg: Value, +) : UnaryExpr + +@Serializable +sealed interface BinaryExpr : Expr { + val left: Value + val right: Value + + override val type: String + get() = "any" +} + +@Serializable +@SerialName("BinaryOperation") +data class BinaryOperation( + val op: String, + override val left: Value, + override val right: Value, +) : BinaryExpr { + override fun toString(): String { + return "$left $op $right" + } +} + +@Serializable +sealed interface ConditionExpr : BinaryExpr { + override val type: String + get() = "boolean" +} + +@Serializable +@SerialName("RelationOperation") +data class RelationOperation( + val relop: String, + override val left: Value, + override val right: Value, +) : ConditionExpr { + override fun toString(): String { + return "$left $relop $right" + } +} + +@Serializable +sealed interface CallExpr : Expr { + val method: String // TODO: MethodSignature + val args: List +} + +@Serializable +@SerialName("InstanceCallExpr") +data class InstanceCallExpr( + val instance: Local, + override val method: String, // TODO: MethodSignature + override val args: List, + override val type: String, +) : CallExpr + +@Serializable +@SerialName("StaticCallExpr") +data class StaticCallExpr( + override val method: String, // TODO: MethodSignature + override val args: List, + override val type: String, +) : CallExpr + +@Serializable +sealed interface Ref : Value + +@Serializable +@SerialName("This") +data class This( + override val type: String, +) : Ref { + override fun toString(): String = "this" +} + +@Serializable +@SerialName("ParameterRef") +data class ParameterRef( + val index: Int, + override val type: String, +) : Ref { + override fun toString(): String { + return "arg$index" + } +} + +@Serializable +@SerialName("ArrayAccess") +data class ArrayAccess( + val array: Value, + val index: Value, + override val type: String, +) : Ref { + override fun toString(): String { + return "$array[$index]" + } +} + +@Serializable +sealed interface FieldRef : Ref { + // TODO: FieldSignature + val fieldName: String + val isOptional: Boolean + val enclosingClass: String +} + +@Serializable +@SerialName("InstanceFieldRef") +data class InstanceFieldRef( + val instance: Local, + override val fieldName: String, + override val type: String, + override val isOptional: Boolean, + override val enclosingClass: String, +) : FieldRef + +@Serializable +@SerialName("StaticFieldRef") +data class StaticFieldRef( + override val fieldName: String, + override val type: String, + override val isOptional: Boolean, + override val enclosingClass: String, +) : FieldRef diff --git a/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/io.kt b/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/io.kt new file mode 100644 index 000000000..ce27b88a3 --- /dev/null +++ b/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/io.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2022 UnitTestBot contributors (utbot.org) + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.ExperimentalSerializationApi +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.decodeFromStream +import java.io.InputStream + +private val json = Json { + classDiscriminator = "_" + prettyPrint = true +} + +fun loadArkFromJson(jsonString: String): Ark { + return json.decodeFromString(jsonString) +} + +@OptIn(ExperimentalSerializationApi::class) +fun loadArkFromJson(stream: InputStream): Ark { + return json.decodeFromStream(stream) +} diff --git a/jacodb-panda-dynamic/src/test/kotlin/ark/ArkFromJsonTest.kt b/jacodb-panda-dynamic/src/test/kotlin/ark/ArkFromJsonTest.kt new file mode 100644 index 000000000..c03aa118e --- /dev/null +++ b/jacodb-panda-dynamic/src/test/kotlin/ark/ArkFromJsonTest.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2022 UnitTestBot contributors (utbot.org) + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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 ark + +import org.jacodb.panda.dynamic.ark.dto.loadArkFromJson +import org.junit.jupiter.api.Test + +class ArkFromJsonTest { + @Test + fun testLoadArkFromJson() { + val path = "basic.ts.json" + val stream = object {}::class.java.getResourceAsStream("/$path") + ?: error("Resource not found: $path") + val ark = loadArkFromJson(stream) + println(ark) + } +} diff --git a/jacodb-panda-dynamic/src/test/resources/basic.ts.json b/jacodb-panda-dynamic/src/test/resources/basic.ts.json new file mode 100644 index 000000000..8af7ed801 --- /dev/null +++ b/jacodb-panda-dynamic/src/test/resources/basic.ts.json @@ -0,0 +1,1385 @@ +{ + "name": "basic.ts", + "absoluteFilePath": "/home/sapphiron/dev/ark/arkanalyzer/tests/resources/save/basic.ts", + "projectDir": "/home/sapphiron/dev/ark/arkanalyzer/tests/resources/save", + "projectName": "save", + "namespaces": [], + "classes": [ + { + "name": "AnonymousClass-basic.ts-0", + "modifiers": [], + "typeParameters": [], + "superClassName": "", + "implementedInterfaceNames": [], + "fields": [ + { + "name": "content", + "modifiers": [], + "type": "Type", + "questionToken": false, + "initializer": null + } + ], + "methods": [ + { + "name": "constructor", + "modifiers": [], + "typeParameters": [], + "parameters": [ + { + "name": "value", + "type": "Type", + "optional": false + } + ], + "returnType": "unknown", + "body": [ + { + "_": "UnknownStmt", + "stmt": { + "text": "this.content = value;", + "def": null, + "uses": [], + "originPosition": 172, + "position": 172, + "cfg": null, + "originColumn": 7, + "column": 7 + } + } + ] + } + ] + }, + { + "name": "_DEFAULT_ARK_CLASS", + "modifiers": [], + "typeParameters": [], + "superClassName": "", + "implementedInterfaceNames": [], + "fields": [], + "methods": [ + { + "name": "_DEFAULT_ARK_METHOD", + "modifiers": [], + "typeParameters": [], + "parameters": [], + "returnType": "unknown", + "body": [ + { + "_": "UnknownStmt", + "stmt": { + "text": "const someClass = class {\n content: Type;\n constructor(value: Type) {\n this.content = value;\n }\n };", + "def": null, + "uses": [], + "originPosition": 169, + "position": 169, + "cfg": null, + "originColumn": 1, + "column": 1 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "const m = new someClass(\"Hello, world\");", + "def": null, + "uses": [], + "originPosition": 175, + "position": 175, + "cfg": null, + "originColumn": 1, + "column": 1 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "export let x:number = 1;", + "def": null, + "uses": [], + "originPosition": 186, + "position": 186, + "cfg": null, + "originColumn": 1, + "column": 1 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "export const soo = 123;", + "def": null, + "uses": [], + "originPosition": 187, + "position": 187, + "cfg": null, + "originColumn": 1, + "column": 1 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "forLoopTest();", + "def": null, + "uses": [], + "originPosition": 195, + "position": 195, + "cfg": null, + "originColumn": 1, + "column": 1 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "test();", + "def": null, + "uses": [], + "originPosition": 196, + "position": 196, + "cfg": null, + "originColumn": 1, + "column": 1 + } + } + ] + }, + { + "name": "forLoopTest", + "modifiers": [], + "typeParameters": [], + "parameters": [], + "returnType": "unknown", + "body": [ + { + "_": "UnknownStmt", + "stmt": { + "text": "let myPerson = new Person(10);", + "def": null, + "uses": [], + "originPosition": 18, + "position": 18, + "cfg": null, + "originColumn": 5, + "column": 5 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "let i = 0; i < 10; i++", + "def": null, + "uses": [], + "originPosition": 19, + "position": 19, + "cfg": null, + "originColumn": 5, + "column": 5 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "let newAge = myPerson.age + i;", + "def": null, + "uses": [], + "originPosition": 20, + "position": 20, + "cfg": null, + "originColumn": 9, + "column": 9 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "logger.info(newAge);", + "def": null, + "uses": [], + "originPosition": 21, + "position": 21, + "cfg": null, + "originColumn": 9, + "column": 9 + } + } + ] + }, + { + "name": "test", + "modifiers": [], + "typeParameters": [], + "parameters": [], + "returnType": "unknown", + "body": [ + { + "_": "UnknownStmt", + "stmt": { + "text": "const sampleData: number[] = [1, 2, 3, 4, 5];", + "def": null, + "uses": [], + "originPosition": 26, + "position": 26, + "cfg": null, + "originColumn": 5, + "column": 5 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "let i = 0; i < sampleData.length; i++", + "def": null, + "uses": [], + "originPosition": 28, + "position": 28, + "cfg": null, + "originColumn": 5, + "column": 5 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "if (sampleData[i] % 2 === 0)", + "def": null, + "uses": [], + "originPosition": 30, + "position": 30, + "cfg": null, + "originColumn": 9, + "column": 9 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "logger.info(`${sampleData[i]} 是偶数`);", + "def": null, + "uses": [], + "originPosition": 31, + "position": 31, + "cfg": null, + "originColumn": 13, + "column": 13 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "logger.info(`${sampleData[i]} 是奇数`);", + "def": null, + "uses": [], + "originPosition": 33, + "position": 33, + "cfg": null, + "originColumn": 13, + "column": 13 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "", + "def": null, + "uses": [], + "originPosition": 37, + "position": 37, + "cfg": null, + "originColumn": 9, + "column": 9 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "logger.info(`${sampleData[i]} 可被 3 整除`);", + "def": null, + "uses": [], + "originPosition": 39, + "position": 39, + "cfg": null, + "originColumn": 17, + "column": 17 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "break;", + "def": null, + "uses": [], + "originPosition": 40, + "position": 40, + "cfg": null, + "originColumn": 17, + "column": 17 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "logger.info(`${sampleData[i]} 除以 3 余 1`);", + "def": null, + "uses": [], + "originPosition": 42, + "position": 42, + "cfg": null, + "originColumn": 17, + "column": 17 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "break;", + "def": null, + "uses": [], + "originPosition": 43, + "position": 43, + "cfg": null, + "originColumn": 17, + "column": 17 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "logger.info(`${sampleData[i]} 除以 3 余 2`);", + "def": null, + "uses": [], + "originPosition": 45, + "position": 45, + "cfg": null, + "originColumn": 17, + "column": 17 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "break;", + "def": null, + "uses": [], + "originPosition": 46, + "position": 46, + "cfg": null, + "originColumn": 17, + "column": 17 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "logger.info(\"无法判断\");", + "def": null, + "uses": [], + "originPosition": 48, + "position": 48, + "cfg": null, + "originColumn": 17, + "column": 17 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "let count = 0;", + "def": null, + "uses": [], + "originPosition": 52, + "position": 52, + "cfg": null, + "originColumn": 9, + "column": 9 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "if (count < sampleData[i])", + "def": null, + "uses": [], + "originPosition": 53, + "position": 53, + "cfg": null, + "originColumn": 9, + "column": 9 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "logger.info(`当前计数: ${count}`);", + "def": null, + "uses": [], + "originPosition": 54, + "position": 54, + "cfg": null, + "originColumn": 13, + "column": 13 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "count++;", + "def": null, + "uses": [], + "originPosition": 55, + "position": 55, + "cfg": null, + "originColumn": 13, + "column": 13 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "let j = 0; j < 5; j++", + "def": null, + "uses": [], + "originPosition": 59, + "position": 59, + "cfg": null, + "originColumn": 9, + "column": 9 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "if (j === 2)", + "def": null, + "uses": [], + "originPosition": 60, + "position": 60, + "cfg": null, + "originColumn": 13, + "column": 13 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "continue;", + "def": null, + "uses": [], + "originPosition": 61, + "position": 61, + "cfg": null, + "originColumn": 17, + "column": 17 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "logger.info(`当前内层循环计数: ${j}`);", + "def": null, + "uses": [], + "originPosition": 63, + "position": 63, + "cfg": null, + "originColumn": 13, + "column": 13 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "let k = 0; k < 3; k++", + "def": null, + "uses": [], + "originPosition": 67, + "position": 67, + "cfg": null, + "originColumn": 9, + "column": 9 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "logger.info(`外层循环计数: ${k}`);", + "def": null, + "uses": [], + "originPosition": 68, + "position": 68, + "cfg": null, + "originColumn": 13, + "column": 13 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "logger.info('Department name: ' + k);", + "def": null, + "uses": [], + "originPosition": 69, + "position": 69, + "cfg": null, + "originColumn": 13, + "column": 13 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "if (k === 1)", + "def": null, + "uses": [], + "originPosition": 70, + "position": 70, + "cfg": null, + "originColumn": 13, + "column": 13 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "break;", + "def": null, + "uses": [], + "originPosition": 71, + "position": 71, + "cfg": null, + "originColumn": 17, + "column": 17 + } + } + ] + }, + { + "name": "classMethodTest", + "modifiers": [ + "ExportKeyword" + ], + "typeParameters": [], + "parameters": [], + "returnType": "unknown", + "body": [ + { + "_": "UnknownStmt", + "stmt": { + "text": "let notPerson = new Person(10);", + "def": null, + "uses": [], + "originPosition": 97, + "position": 97, + "cfg": null, + "originColumn": 5, + "column": 5 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "let x = new Map();", + "def": null, + "uses": [], + "originPosition": 98, + "position": 98, + "cfg": null, + "originColumn": 5, + "column": 5 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "let z = new Error();", + "def": null, + "uses": [], + "originPosition": 99, + "position": 99, + "cfg": null, + "originColumn": 5, + "column": 5 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "let y = test();", + "def": null, + "uses": [], + "originPosition": 100, + "position": 100, + "cfg": null, + "originColumn": 5, + "column": 5 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "let a = notPerson.age", + "def": null, + "uses": [], + "originPosition": 101, + "position": 101, + "cfg": null, + "originColumn": 5, + "column": 5 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "notPerson.growOld()", + "def": null, + "uses": [], + "originPosition": 102, + "position": 102, + "cfg": null, + "originColumn": 5, + "column": 5 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "Person.wooooof()", + "def": null, + "uses": [], + "originPosition": 103, + "position": 103, + "cfg": null, + "originColumn": 5, + "column": 5 + } + } + ] + }, + { + "name": "foo", + "modifiers": [ + "ExportKeyword" + ], + "typeParameters": [], + "parameters": [ + { + "name": "x", + "type": "number", + "optional": false + } + ], + "returnType": "number", + "body": [ + { + "_": "UnknownStmt", + "stmt": { + "text": "var y: number = 0;", + "def": null, + "uses": [], + "originPosition": 118, + "position": 118, + "cfg": null, + "originColumn": 5, + "column": 5 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "let k = 0; k < x; k++", + "def": null, + "uses": [], + "originPosition": 119, + "position": 119, + "cfg": null, + "originColumn": 5, + "column": 5 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "y = y + k;", + "def": null, + "uses": [], + "originPosition": 120, + "position": 120, + "cfg": null, + "originColumn": 9, + "column": 9 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "return y;", + "def": null, + "uses": [], + "originPosition": 122, + "position": 122, + "cfg": null, + "originColumn": 5, + "column": 5 + } + } + ] + }, + { + "name": "listParameters", + "modifiers": [ + "ExportKeyword" + ], + "typeParameters": [], + "parameters": [ + { + "name": "u", + "type": "number", + "optional": false + }, + { + "name": "v", + "type": "number", + "optional": false + }, + { + "name": "w", + "type": "string", + "optional": false + } + ], + "returnType": "@save/basic: AnonymousClass-basic.ts-1", + "body": [ + { + "_": "UnknownStmt", + "stmt": { + "text": "return { x: u, y: v, z: w }", + "def": null, + "uses": [], + "originPosition": 143, + "position": 143, + "cfg": null, + "originColumn": 5, + "column": 5 + } + } + ] + } + ] + }, + { + "name": "Person", + "modifiers": [], + "typeParameters": [], + "superClassName": "", + "implementedInterfaceNames": [], + "fields": [ + { + "name": "x", + "modifiers": [], + "type": "number", + "questionToken": false, + "initializer": { + "_": "Constant", + "value": "0", + "type": "number" + } + }, + { + "name": "growOld", + "modifiers": [], + "type": null, + "questionToken": false, + "initializer": { + "_": "Constant", + "value": "", + "type": "unknown" + } + } + ], + "methods": [ + { + "name": "constructor", + "modifiers": [], + "typeParameters": [], + "parameters": [ + { + "name": "age", + "type": "number", + "optional": false + } + ], + "returnType": "unknown", + "body": [] + }, + { + "name": "getAge", + "modifiers": [ + "PublicKeyword" + ], + "typeParameters": [], + "parameters": [], + "returnType": "unknown", + "body": [ + { + "_": "UnknownStmt", + "stmt": { + "text": "return this.age", + "def": null, + "uses": [], + "originPosition": 88, + "position": 88, + "cfg": null, + "originColumn": 9, + "column": 9 + } + } + ] + }, + { + "name": "wooooof", + "modifiers": [ + "StaticKeyword" + ], + "typeParameters": [], + "parameters": [], + "returnType": "unknown", + "body": [ + { + "_": "UnknownStmt", + "stmt": { + "text": "logger.info(\"not a person sound\")", + "def": null, + "uses": [], + "originPosition": 92, + "position": 92, + "cfg": null, + "originColumn": 9, + "column": 9 + } + } + ] + } + ] + }, + { + "name": "Alarm", + "modifiers": [], + "typeParameters": [], + "superClassName": "", + "implementedInterfaceNames": [], + "fields": [], + "methods": [ + { + "name": "alert", + "modifiers": [], + "typeParameters": [], + "parameters": [], + "returnType": "void", + "body": [] + } + ] + }, + { + "name": "Alarm2", + "modifiers": [], + "typeParameters": [], + "superClassName": "", + "implementedInterfaceNames": [], + "fields": [], + "methods": [ + { + "name": "alert2", + "modifiers": [], + "typeParameters": [], + "parameters": [], + "returnType": "void", + "body": [] + } + ] + }, + { + "name": "Door", + "modifiers": [], + "typeParameters": [], + "superClassName": "", + "implementedInterfaceNames": [], + "fields": [], + "methods": [] + }, + { + "name": "Adder", + "modifiers": [], + "typeParameters": [], + "superClassName": "", + "implementedInterfaceNames": [], + "fields": [ + { + "name": "add", + "modifiers": [], + "type": null, + "questionToken": false, + "initializer": { + "_": "Constant", + "value": "", + "type": "unknown" + } + } + ], + "methods": [ + { + "name": "constructor", + "modifiers": [], + "typeParameters": [], + "parameters": [ + { + "name": "a", + "type": "number", + "optional": false + } + ], + "returnType": "unknown", + "body": [] + } + ] + }, + { + "name": "ExtendedAdder", + "modifiers": [], + "typeParameters": [], + "superClassName": "Adder", + "implementedInterfaceNames": [], + "fields": [ + { + "name": "superAdd", + "modifiers": [ + "PrivateKeyword" + ], + "type": null, + "questionToken": false, + "initializer": { + "_": "UnknownValue", + "value": { + "fieldSignature": { + "declaringClassSignature": { + "declaringFileSignature": { + "projectName": "_UnkownProjectName", + "fileName": "_UnkownFileName" + }, + "declaringNamespaceSignature": null, + "className": "" + }, + "fieldName": "add", + "type": {} + }, + "base": { + "value": "", + "type": {} + } + } + } + }, + { + "name": "add", + "modifiers": [], + "type": null, + "questionToken": false, + "initializer": { + "_": "Constant", + "value": "", + "type": "unknown" + } + } + ], + "methods": [] + }, + { + "name": "AnonymousClass$listParameters$0", + "modifiers": [], + "typeParameters": [], + "superClassName": "", + "implementedInterfaceNames": [], + "fields": [], + "methods": [] + }, + { + "name": "SecurityDoor", + "modifiers": [ + "ExportKeyword" + ], + "typeParameters": [], + "superClassName": "Door", + "implementedInterfaceNames": [ + "Alarm", + "Alarm2" + ], + "fields": [ + { + "name": "x", + "modifiers": [], + "type": "number", + "questionToken": false, + "initializer": { + "_": "Constant", + "value": "0", + "type": "number" + } + }, + { + "name": "y", + "modifiers": [], + "type": "string", + "questionToken": false, + "initializer": { + "_": "Constant", + "value": "''", + "type": "string" + } + }, + { + "name": "Members", + "modifiers": [ + "PublicKeyword" + ], + "type": null, + "questionToken": false, + "initializer": { + "_": "Constant", + "value": "", + "type": "unknown" + } + } + ], + "methods": [ + { + "name": "alert", + "modifiers": [], + "typeParameters": [], + "parameters": [], + "returnType": "void", + "body": [ + { + "_": "UnknownStmt", + "stmt": { + "text": "logger.info(\"SecurityDoor alert\");", + "def": null, + "uses": [], + "originPosition": 150, + "position": 150, + "cfg": null, + "originColumn": 9, + "column": 9 + } + } + ] + }, + { + "name": "alert2", + "modifiers": [], + "typeParameters": [], + "parameters": [], + "returnType": "void", + "body": [ + { + "_": "UnknownStmt", + "stmt": { + "text": "logger.info(\"SecurityDoor alert2\");", + "def": null, + "uses": [], + "originPosition": 153, + "position": 153, + "cfg": null, + "originColumn": 9, + "column": 9 + } + } + ] + }, + { + "name": "fooo", + "modifiers": [ + "PublicKeyword" + ], + "typeParameters": [], + "parameters": [], + "returnType": "unknown", + "body": [ + { + "_": "UnknownStmt", + "stmt": { + "text": "logger.info(\"This is fooo!\");", + "def": null, + "uses": [], + "originPosition": 159, + "position": 159, + "cfg": null, + "originColumn": 9, + "column": 9 + } + } + ] + }, + { + "name": "constructor", + "modifiers": [], + "typeParameters": [], + "parameters": [ + { + "name": "x", + "type": "number", + "optional": false + }, + { + "name": "y", + "type": "string", + "optional": false + } + ], + "returnType": "unknown", + "body": [ + { + "_": "UnknownStmt", + "stmt": { + "text": "super();", + "def": null, + "uses": [], + "originPosition": 162, + "position": 162, + "cfg": null, + "originColumn": 9, + "column": 9 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "this.x = x;", + "def": null, + "uses": [], + "originPosition": 163, + "position": 163, + "cfg": null, + "originColumn": 9, + "column": 9 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "this.y = y;", + "def": null, + "uses": [], + "originPosition": 164, + "position": 164, + "cfg": null, + "originColumn": 9, + "column": 9 + } + }, + { + "_": "UnknownStmt", + "stmt": { + "text": "logger.info(\"This is a constrctor!\");", + "def": null, + "uses": [], + "originPosition": 165, + "position": 165, + "cfg": null, + "originColumn": 9, + "column": 9 + } + } + ] + } + ] + }, + { + "name": "Animal", + "modifiers": [ + "AbstractKeyword" + ], + "typeParameters": [], + "superClassName": "", + "implementedInterfaceNames": [], + "fields": [ + { + "name": "name", + "modifiers": [ + "PublicKeyword" + ], + "type": null, + "questionToken": false, + "initializer": null + } + ], + "methods": [ + { + "name": "constructor", + "modifiers": [ + "PublicKeyword" + ], + "typeParameters": [], + "parameters": [ + { + "name": "name", + "type": "string", + "optional": false + } + ], + "returnType": "unknown", + "body": [ + { + "_": "UnknownStmt", + "stmt": { + "text": "this.name = name;", + "def": null, + "uses": [], + "originPosition": 180, + "position": 180, + "cfg": null, + "originColumn": 7, + "column": 7 + } + } + ] + }, + { + "name": "sayHi", + "modifiers": [ + "PublicKeyword", + "AbstractKeyword" + ], + "typeParameters": [], + "parameters": [], + "returnType": "void", + "body": [] + } + ] + }, + { + "name": "StringValidator", + "modifiers": [ + "ExportKeyword" + ], + "typeParameters": [], + "superClassName": "", + "implementedInterfaceNames": [], + "fields": [ + { + "name": "color", + "modifiers": [], + "type": "string", + "questionToken": true, + "initializer": null + }, + { + "name": "width", + "modifiers": [], + "type": "number", + "questionToken": true, + "initializer": null + } + ], + "methods": [ + { + "name": "isAcceptable", + "modifiers": [], + "typeParameters": [], + "parameters": [ + { + "name": "s", + "type": "string", + "optional": true + } + ], + "returnType": "boolean", + "body": [] + } + ] + } + ], + "importInfos": [], + "exportInfos": [ + { + "exportClauseName": "classMethodTest", + "exportClauseType": "Method", + "isDefault": false, + "modifiers": [ + "ExportKeyword" + ], + "originTsPosition": { + "line": -1, + "col": -1 + } + }, + { + "exportClauseName": "foo", + "exportClauseType": "Method", + "isDefault": false, + "modifiers": [ + "ExportKeyword" + ], + "originTsPosition": { + "line": -1, + "col": -1 + } + }, + { + "exportClauseName": "listParameters", + "exportClauseType": "Method", + "isDefault": false, + "modifiers": [ + "ExportKeyword" + ], + "originTsPosition": { + "line": -1, + "col": -1 + } + }, + { + "exportClauseName": "SecurityDoor", + "exportClauseType": "Class", + "isDefault": false, + "modifiers": [ + "ExportKeyword" + ], + "originTsPosition": { + "line": -1, + "col": -1 + } + }, + { + "exportClauseName": "StringValidator", + "exportClauseType": "Class", + "isDefault": false, + "modifiers": [ + "ExportKeyword" + ], + "originTsPosition": { + "line": -1, + "col": -1 + } + }, + { + "exportClauseName": "ExtAdder", + "exportClauseType": "NamedExports", + "nameBeforeAs": "ExtendedAdder", + "isDefault": false, + "modifiers": [], + "originTsPosition": { + "line": 193, + "col": 1 + } + }, + { + "exportClauseName": "ExtendedAdder", + "exportClauseType": "NamedExports", + "isDefault": false, + "modifiers": [], + "originTsPosition": { + "line": 193, + "col": 1 + } + } + ] +}