Skip to content

Commit

Permalink
add - RubyTypeHintCallLinker
Browse files Browse the repository at this point in the history
  • Loading branch information
khemrajrathore committed Jul 11, 2023
1 parent c93028e commit 85d71ce
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import io.joern.rubysrc2cpg.passes.{
AstPackagePass,
ConfigFileCreationPass,
ImportResolverPass,
RubyTypeHintCallLinker,
RubyTypeRecoveryPass
}
import io.joern.rubysrc2cpg.utils.PackageTable
import io.joern.x2cpg.X2Cpg.withNewEmptyCpg
import io.joern.x2cpg.X2CpgFrontend
import io.joern.x2cpg.datastructures.Global
import io.joern.x2cpg.passes.base.AstLinkerPass
import io.joern.x2cpg.passes.callgraph.NaiveCallLinker
import io.joern.x2cpg.passes.frontend.{MetaDataPass, TypeNodePass}
import io.joern.x2cpg.utils.ExternalCommand
Expand Down Expand Up @@ -73,8 +75,14 @@ object RubySrc2Cpg {

def postProcessingPasses(cpg: Cpg, config: Option[Config] = None): List[CpgPassBase] =
List(
// TODO commented below two passes, as waiting on Dependency download PR to get merged
// new RubyTypeRecoveryPass(cpg),
new NaiveCallLinker(cpg)
// new RubyTypeHintCallLinker(cpg),
new NaiveCallLinker(cpg),

// Some of passes above create new methods, so, we
// need to run the ASTLinkerPass one more time
new AstLinkerPass(cpg)
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.joern.rubysrc2cpg.passes

import io.joern.x2cpg.passes.frontend.XTypeHintCallLinker
import io.shiftleft.codepropertygraph.Cpg
import io.shiftleft.codepropertygraph.generated.nodes.Call
import io.shiftleft.semanticcpg.language.Traversal
import io.shiftleft.semanticcpg.language._

import java.util.regex.Pattern

class RubyTypeHintCallLinker(cpg: Cpg) extends XTypeHintCallLinker(cpg) {

override def calls: Traversal[Call] = super.calls.nameNot("^(require).*")

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,4 @@ private class RecoverForRubyFile(cpg: Cpg, cu: File, builder: DiffGraphBuilder,
associateTypes(i, constructorPaths)
}

override def storeCallTypeInfo(c: Call, types: Seq[String]): Unit =
if (types.nonEmpty) {
super.storeCallTypeInfo(c, types)
// Update the methodFullName if we have only 1 type
if (c.methodFullName.equals(DynamicCallUnknownFullName) && types.size == 1)
builder.setNodeProperty(c, PropertyNames.METHOD_FULL_NAME, types.head)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import scala.collection.mutable
abstract class XTypeHintCallLinker(cpg: Cpg) extends CpgPass(cpg) {

implicit protected val resolver: NoResolve.type = NoResolve
private val fileNamePattern = Pattern.compile("^(.*(.py|.js)).*$")
private val fileNamePattern = Pattern.compile("^(.*(.py|.js|.rb)).*$")
protected val pathSep: Char = '.'

protected def calls: Traversal[Call] = cpg.call
Expand Down

0 comments on commit 85d71ce

Please sign in to comment.