Skip to content

Commit 31bbf09

Browse files
committed
Convert Entity/Expr/Stmt/Cfg to Proto
1 parent 243e0d7 commit 31bbf09

File tree

7 files changed

+629
-4
lines changed

7 files changed

+629
-4
lines changed

jacodb-ets/src/main/kotlin/org/jacodb/ets/proto/ConvertToProto.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import org.jacodb.ets.model.EtsModifiers
3131
import org.jacodb.ets.model.EtsNamespace
3232
import org.jacodb.ets.model.EtsNamespaceSignature
3333
import org.jacodb.ets.model.EtsScene
34+
import model.Block as ProtoBlock
3435
import model.BlockCfg as ProtoBlockCfg
3536
import model.Class as ProtoClass
3637
import model.ClassSignature as ProtoClassSignature
@@ -148,4 +149,15 @@ fun EtsModifiers.toProto(): Int {
148149
return mask
149150
}
150151

151-
fun EtsBlockCfg.toProto(): ProtoBlockCfg = TODO()
152+
fun EtsBlockCfg.toProto(): ProtoBlockCfg {
153+
return ProtoBlockCfg(
154+
blocks = blocks.map { block ->
155+
ProtoBlock(
156+
id = block.id,
157+
statements = block.statements.map { stmt -> stmt.toProto() },
158+
successors = successors.getValue(block.id),
159+
// Note: predecessors are omitted
160+
)
161+
},
162+
)
163+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2022 UnitTestBot contributors (utbot.org)
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.jacodb.ets.proto
18+
19+
import org.jacodb.ets.model.EtsEntity
20+
import org.jacodb.ets.model.EtsExpr
21+
import org.jacodb.ets.model.EtsRawEntity
22+
import org.jacodb.ets.model.EtsValue
23+
import model.RawValue as ProtoRawValue
24+
import model.Value as ProtoValue
25+
26+
fun EtsEntity.toProto(): ProtoValue = accept(EtsEntityToProto)
27+
28+
internal object EtsEntityToProto :
29+
EtsEntity.Visitor<ProtoValue>,
30+
EtsValue.Visitor.Default<ProtoValue>,
31+
EtsExpr.Visitor.Default<ProtoValue> {
32+
33+
override fun visit(value: EtsRawEntity): ProtoValue {
34+
val rawValue = ProtoRawValue(
35+
kind = value.kind,
36+
type = value.type.toProto(),
37+
)
38+
return ProtoValue(raw_value = rawValue)
39+
}
40+
41+
override fun defaultVisit(value: EtsValue): ProtoValue = value.toProto()
42+
override fun defaultVisit(expr: EtsExpr): ProtoValue = expr.toProto()
43+
}

0 commit comments

Comments
 (0)