File tree Expand file tree Collapse file tree 7 files changed +34
-9
lines changed
common/src/main/kotlin/spp/jetbrains/artifact/model
insight/src/main/kotlin/spp/jetbrains/insight Expand file tree Collapse file tree 7 files changed +34
-9
lines changed Original file line number Diff line number Diff line change 1717package spp.jetbrains.artifact.model
1818
1919import com.intellij.psi.PsiElement
20+ import spp.jetbrains.SourceKey
2021
2122/* *
2223 * Represents if/elif/else control structures.
2324 */
2425abstract class IfArtifact (psiElement : PsiElement ) : ControlStructureArtifact(psiElement) {
2526
27+ companion object {
28+ private val CONDITION_EVALUATION = SourceKey <Boolean >(" CONDITION_EVALUATION" )
29+ }
30+
2631 abstract val condition: ArtifactElement ?
2732 abstract val thenBranch: ArtifactElement ?
2833 abstract val elseBranch: ArtifactElement ?
@@ -58,5 +63,27 @@ abstract class IfArtifact(psiElement: PsiElement) : ControlStructureArtifact(psi
5863 }
5964 }
6065
66+ fun setConditionEvaluation (value : Boolean ) {
67+ data[CONDITION_EVALUATION ] = value
68+ }
69+
70+ fun getConditionEvaluation (): Boolean? {
71+ return getData(CONDITION_EVALUATION )
72+ }
73+
74+ override fun toString (): String {
75+ return buildString {
76+ append(" IfArtifact(conditionEvaluation=" )
77+ append(getConditionEvaluation())
78+ append(" , condition=" )
79+ append(condition)
80+ append(" , thenBranch=" )
81+ append(thenBranch)
82+ append(" , elseBranch=" )
83+ append(elseBranch)
84+ append(" )" )
85+ }
86+ }
87+
6188 abstract override fun clone (): IfArtifact
6289}
Original file line number Diff line number Diff line change @@ -34,7 +34,6 @@ object InsightKeys {
3434 val PATH_EXECUTION_PROBABILITY = SourceKey <InsightValue <Double >>(InsightType .PATH_EXECUTION_PROBABILITY .name)
3535 val PATH_DURATION = SourceKey <InsightValue <Double >>(InsightType .PATH_DURATION .name)
3636 val RECURSIVE_CALL = SourceKey <InsightValue <Boolean >>(InsightType .RECURSIVE_CALL .name)
37- val CONDITION_EVALUATION = SourceKey <Boolean >(" CONDITION_EVALUATION" )
3837
3938 val ALL_INSIGHTS : List <SourceKey <out InsightValue <out Any >>> = listOf (
4039 FUNCTION_DURATION ,
Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ class ProceduralAnalyzer {
118118
119119 if (artifactElement is IfArtifact ) {
120120 val bool = boolIterator.next()
121- artifactElement.data[ InsightKeys . CONDITION_EVALUATION ] = bool
121+ artifactElement.setConditionEvaluation( bool)
122122
123123 if (bool) {
124124 val childArtifacts = processArtifacts[index + 1 ] as List <Any >
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ class RandomConditionalPass : ArtifactPass {
6363 else -> 0.0
6464 }.let { if (it > 1.0 ) 1.0 else if (it < 0.0 ) 0.0 else it }
6565
66- val conditionEvaluation = ifArtifact.getData( InsightKeys . CONDITION_EVALUATION )!!
66+ val conditionEvaluation = ifArtifact.getConditionEvaluation( )!!
6767 if (conditionEvaluation) {
6868 ifArtifact.data[InsightKeys .CONTROL_STRUCTURE_PROBABILITY ] =
6969 InsightValue (InsightType .CONTROL_STRUCTURE_PROBABILITY , probability)
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ class StaticDfaMultiPathPass : ProceduralMultiPathPass {
6969 if (it is IfArtifact ) {
7070 if (it.condition?.psiElement == expression) {
7171 val probability = if (value == ConstantValue .TRUE ) 1.0 else 0.0
72- val conditionEvaluation = it.getData( InsightKeys . CONDITION_EVALUATION )!!
72+ val conditionEvaluation = it.getConditionEvaluation( )!!
7373 if (conditionEvaluation) {
7474 it.data[InsightKeys .CONTROL_STRUCTURE_PROBABILITY ] =
7575 InsightValue (InsightType .CONTROL_STRUCTURE_PROBABILITY , probability)
@@ -90,7 +90,7 @@ class StaticDfaMultiPathPass : ProceduralMultiPathPass {
9090 if (it is IfArtifact ) {
9191 if (it.condition?.psiElement == expression) {
9292 val probability = if (value == ConstantValue .TRUE ) 1.0 else 0.0
93- val conditionEvaluation = it.getData( InsightKeys . CONDITION_EVALUATION )!!
93+ val conditionEvaluation = it.getConditionEvaluation( )!!
9494 if (conditionEvaluation) {
9595 it.data[InsightKeys .CONTROL_STRUCTURE_PROBABILITY ] =
9696 InsightValue (InsightType .CONTROL_STRUCTURE_PROBABILITY , probability)
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ class PathProbabilityPass : ProceduralPathPass {
3939 InsightValue .of(PATH_EXECUTION_PROBABILITY , 1.0 )
4040
4141 if (it is IfArtifact ) {
42- analyze(it, it.getData( InsightKeys . CONDITION_EVALUATION )!! , 1.0 )
42+ analyze(it, it.getConditionEvaluation( )!! , 1.0 )
4343 }
4444 }
4545 }
@@ -51,7 +51,7 @@ class PathProbabilityPass : ProceduralPathPass {
5151 InsightValue .of(PATH_EXECUTION_PROBABILITY , probability)
5252
5353 if (it is IfArtifact ) {
54- analyze(it, it.getData( InsightKeys . CONDITION_EVALUATION )!! , probability)
54+ analyze(it, it.getConditionEvaluation( )!! , probability)
5555 }
5656 }
5757 }
Original file line number Diff line number Diff line change @@ -20,7 +20,6 @@ import spp.jetbrains.artifact.model.ArtifactElement
2020import spp.jetbrains.artifact.model.CallArtifact
2121import spp.jetbrains.artifact.model.FunctionArtifact
2222import spp.jetbrains.artifact.model.IfArtifact
23- import spp.jetbrains.insight.InsightKeys
2423import spp.protocol.insight.InsightValue
2524
2625/* *
@@ -46,7 +45,7 @@ data class ProceduralPath(
4645 val conditionals = descendants.filterIsInstance<IfArtifact >()
4746 val conditions = mutableListOf<Pair <Boolean , IfArtifact >>()
4847 for (i in conditionals.indices) {
49- conditions.add(Pair (conditionals[i].getData( InsightKeys . CONDITION_EVALUATION )!! , conditionals[i]))
48+ conditions.add(Pair (conditionals[i].getConditionEvaluation( )!! , conditionals[i]))
5049 }
5150 return conditions
5251 }
You can’t perform that action at this time.
0 commit comments