Skip to content

Commit

Permalink
ReachingDefs now optional (#205)
Browse files Browse the repository at this point in the history
* Separating dataflow pre-calcs

* Updated docs

* Added default to scala tests
  • Loading branch information
DavidBakerEffendi authored Sep 6, 2021
1 parent e26976e commit b37bfe8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Upgrade ShiftLeft dependencies to 1.3.236
- Removed `Binding` vertices
- Can now handle new type arguments API of domain classes
- `Extractor::project` now takes an optional boolean to disable reaching defs calculation
- `Extractor::projectReachingDefs` now calculates reaching defs separately

## [0.5.12] - 2021-07-30

Expand Down
25 changes: 20 additions & 5 deletions plume/src/main/kotlin/io/github/plume/oss/Extractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,11 @@ class Extractor(val driver: IDriver) {
/**
* Projects all loaded classes to the graph database. This expects that all application files part of the artifact
* are loaded.
*
* @param includeReachingDefs if true, will include calculating REACHING_DEF chains. If false, will keep method CPGs
* in memory storage.
*/
fun project(): Extractor {
fun project(includeReachingDefs: Boolean = true): Extractor {
/*
Load and compile files then feed them into Soot
*/
Expand Down Expand Up @@ -335,13 +338,25 @@ class Extractor(val driver: IDriver) {
PlumeTimer.measure(ExtractorTimeKey.BASE_CPG_BUILDING) { buildMethods(methodsToBuild, sootUnitGraphs) }
// Clear all Soot resources and storage
this.clear()
/*
Method body level analysis - only done on new/updated methods
*/
if (includeReachingDefs) {
/*
Method body level analysis - only done on new/updated methods
*/
logger.info("Running data flow passes")
PlumeTimer.measure(ExtractorTimeKey.DATA_FLOW_PASS) { DataFlowPass(driver).runPass() }
PlumeStorage.methodCpgs.clear()
}
return this
}

/**
* Runs reaching defs analysis - necessary for data-flow analysis queries i.e. reachableBy(). Will not make changes
* if [project] ran in default mode i.e. project(includeReachingDefs = true).
*/
fun projectReachingDefs() {
logger.info("Running data flow passes")
PlumeTimer.measure(ExtractorTimeKey.DATA_FLOW_PASS) { DataFlowPass(driver).runPass() }
PlumeStorage.methodCpgs.clear()
return this
}

private fun earlyStopCleanUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class BasicExtractorTest {
@Test
fun validSourceFileTest() {
extractor.load(validSourceFile)
extractor.project()
extractor.project(false)
extractor.projectReachingDefs()
g = driver.getWholeGraph()
val ns = g.nodes().asSequence().toList()
assertNotNull(ns.filterIsInstance<NamespaceBlock>().find { it.name() == "extractor_tests" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PlumeFrontend extends LanguageFrontend {
Using(DriverFactory.invoke(GraphDatabase.OVERFLOWDB).asInstanceOf[OverflowDbDriver]) { driver =>
driver.storageLocation(cpgFile.getAbsolutePath)
val extractor = new Extractor(driver)
extractor.load(sourceCodeFile).project()
extractor.load(sourceCodeFile).project(true)
LocalCache.INSTANCE.clear()
}
val odbConfig = overflowdb.Config.withDefaults().withStorageLocation(cpgFile.getAbsolutePath)
Expand Down

0 comments on commit b37bfe8

Please sign in to comment.