Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rubysrc2cpg] Enhancing TypeDecl implementation #3358

Merged

Conversation

khemrajrathore
Copy link
Contributor

The PR contains the following

  • For encountered TypeDecl create corresponding TypeRef assignments similar to how we do for python, so that types for the class instance usage within the same files is resolved
  • For instance methods create a this parameter as the parameter with index 0, which help in tracking and linking dataflow for instance variables
  • For method parameters refactored the current code to be short and precise along with adding corresponding index and order values
  • Fixed 2 existing ignored test cases
    cc - @fabsx00 @DavidBakerEffendi

@@ -36,6 +86,10 @@ trait AstCreatorHelper { this: AstCreator =>
usedVariableNames.put(variableName, counter)
currentVariableName
}

protected def addReceiverEdge(dstNode: nodes.NewNode, srcNode: nodes.NewNode): Unit = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this exists in the Ast() class already

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove this code as anyways we are not using this function anywhere in ruby

case _: SimpleMethodNamePartContext if !classStack.top.endsWith(":program") =>
val thisParameterNode = createMethodParameterIn(
"this",
typeFullName = callNode.methodFullName,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this call node refer to the :program method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the call node refers to methodDefinition. We use the information from the callNode and discard it

Basically here for any methodDefinition encountered we are categorizing the whether they are class method or instance method

@DavidBakerEffendi DavidBakerEffendi changed the title RubySrc2Cpg : Enhancing TypeDecl implementation [rubysrc2cpg] Enhancing TypeDecl implementation Aug 1, 2023
@DavidBakerEffendi DavidBakerEffendi added enhancement New feature or request ruby Relates to rubysrc2cpg labels Aug 1, 2023
@khemrajrathore
Copy link
Contributor Author

@DavidBakerEffendi Have made the requested changes

@DavidBakerEffendi DavidBakerEffendi merged commit fb681a0 into joernio:master Aug 2, 2023
5 checks passed
@pandurangpatil pandurangpatil deleted the khemraj/fixingClassInstanceCalls branch November 28, 2023 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ruby Relates to rubysrc2cpg
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants