Support for constant propagation #1831
-
Hi folks, I really appreciate your work. However, the documentation of this repo says it supports constant propagation, but I cannot find the concrete code implementation or the corresponding test cases. Can you give me further instructions? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You need to include the import de.fraunhofer.aisec.cpg.graph.*
val node = /* ... */
val value = node.evaluate() This is equivalent to You can find some more test cases here: https://github.com/Fraunhofer-AISEC/cpg/blob/main/cpg-analysis/src/test/kotlin/de/fraunhofer/aisec/cpg/analysis/ValueEvaluatorTest.kt |
Beta Was this translation helpful? Give feedback.
You need to include the
cpg-analysis
module. You can then use theValueEvaluator
class to evaluate simple constants such as strings and numbers in most languages. You can also override the default behaviour if you specify your own implementation ofnotDefined
. There is also a shortcut you can use:evaluate()
, so if you have a node that you suspect will contain a constant you can doThis is equivalent to
ValueEvaluator().evaluate(node)
You can find some more test cases here: https://github.com/Fraunhofer-AISEC/cpg/blob/main/cpg-analysis/src/test/kotlin/de/fraunhofer/aisec/cpg/analysis/ValueEvaluatorTes…