Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiDreyer committed May 9, 2024
1 parent 8792a3e commit 14be3e5
Showing 1 changed file with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.joern.rubysrc2cpg.astcreation

import io.joern.rubysrc2cpg.astcreation.RubyIntermediateAst.*
import io.joern.rubysrc2cpg.datastructures.{BlockScope, NamespaceScope, RubyProgramSummary, RubyScope}
import io.joern.rubysrc2cpg.datastructures.{BlockScope, NamespaceScope, RubyProgramSummary, RubyScope, RubyStubbedType}
import io.joern.rubysrc2cpg.parser.{RubyNodeCreator, RubyParser}
import io.joern.rubysrc2cpg.passes.Defines
import io.joern.x2cpg.utils.NodeBuilders.newModifierNode
Expand Down Expand Up @@ -44,7 +44,7 @@ class AstCreator(
.map(_.stripPrefix(java.io.File.separator))
.getOrElse(fileName)

private val internalLineAndColNum: Option[Integer] = Option(1)
private def internalLineAndColNum: Option[Integer] = Option(1)

/** The relative file name, in a unix path delimited format.
*/
Expand Down Expand Up @@ -110,14 +110,14 @@ class AstCreator(
private def methodRefNodesForInternalMethods(): List[Ast] = {
val typeNameForMethods = scope.surroundingTypeFullName
.map { x =>
x.split("[:]{2}").dropRight(1).mkString("")
x.stripSuffix(s":${Defines.Program}")
}
.getOrElse(Defines.Undefined)

programSummary.namespaceToType
.filter(_._1 == typeNameForMethods)
.flatMap(_._2)
.filter(x => x.name.contains(":program"))
.filter(!_.isInstanceOf[RubyStubbedType])
.flatMap(_.methods)
.map { method =>
val methodRefNode = NewMethodRef()
Expand All @@ -140,25 +140,30 @@ class AstCreator(
}

private def typeRefNodesForInternalDecls(): List[Ast] = {
programSummary.namespaceToType
.filter(_._1.contains(scope.surroundingTypeFullName.getOrElse(Defines.Undefined)))
.flatMap(_._2)
.map { x =>
val typeRefName = x.name.split("[.]").takeRight(1).head
val typeRefNode = NewTypeRef()
.code(s"class ${x.name} (...)")
.typeFullName(x.name)

val typeRefIdent = NewIdentifier()
.code(typeRefName)
.name(typeRefName)
.typeFullName(x.name)
.lineNumber(internalLineAndColNum)
.columnNumber(internalLineAndColNum)

astForAssignment(typeRefIdent, typeRefNode, internalLineAndColNum, internalLineAndColNum)
scope.surroundingTypeFullName
.map { surroundingTypeFullName =>
programSummary.namespaceToType
.filter(_._1.contains(surroundingTypeFullName))
.flatMap(_._2)
.map { x =>
val typeRefName = x.name.split("[.]").takeRight(1).head
val typeRefNode = NewTypeRef()
.code(s"class ${x.name} (...)")
.typeFullName(x.name)

val typeRefIdent = NewIdentifier()
.code(typeRefName)
.name(typeRefName)
.typeFullName(x.name)
.lineNumber(internalLineAndColNum)
.columnNumber(internalLineAndColNum)

astForAssignment(typeRefIdent, typeRefNode, internalLineAndColNum, internalLineAndColNum)
}
.toList
}
.toList
.getOrElse(List.empty)

}
}

Expand Down

0 comments on commit 14be3e5

Please sign in to comment.