Skip to content

Resolve 6-method-call-nodes

Carlos Galindo requested to merge 6-method-call-nodes into develop

Created by: jacosro

Implemented

  • Added type field to node (NodeType enum)
  • Added TypeNodeFactory, with an only and static fromType method, creates a GraphNode providing a NodeType
  • Now, a node can be added to a graph providing a factory by which that node will be created in the method addNode
  • Added new arcs, such as CallArc, ParameterInOutArc and ReturnArc
  • MethodCallReplacerVisitor: Visitor that looks for method call nodes and adds call, in, out and return node to the graph. Also, adds arcs to link them to the corresponding nodes
  • SDG is created correctly ONLY for variables or constants as arguments. It won't work with method calls, field access expressions, etc. as arguments

Behaviour

  • Modified CFG to include in and out parameters of a method (this is necessary to build data dependency of these variables INSIDE a method)
  • Modified PDG: Nodes that contain method calls are considered that they make use and defines the variables that are arguments to those method calls (in other case, we'd have to recalculate data dependency after the new out nodes are added, a costly task)

After the (partial) SDG is built from PDGs, the MethodCallReplacerVisitor visits all the graph and looks for MethodCallExpr. When one is found, what it does is the following:

  1. Find the MethodDeclaration which the method call makes reference (This is done with JavaParser's SymbolSolver). If none is found, do nothing
  2. Iterate over the method declaration's parameters: 2.1. Build in nodes. For each one do: 2.1.1. Create a new in node with the form: int <parameterName>_in = <variable> 2.1.2. Add a control dependency arc from call node to the newly created in node 2.1.3. In the original method call node, look for the data dependency arc that indicates the data dependency of the variable and point that arc to the newly created in node 2.2. Build out nodes: For each one do: 2.2.1. Create a new out node with the form: <variable> = <parameterName>_out 2.2.2. Add a control dependency arc from call node to the newly created out node 2.2.3. In the original method call node, look for the data dependency arc that indicates the data dependency of the variable and change the source of the arc, making the newly created out node the source of the variable data dependencies
  3. Build return node 3.1. Add a new node to the graph with an EmptyStmt 3.2. Add a control dependency arc from the call node to the newly created return node 3.3. Add a return arc from all method's ReturnStmt nodes to the newly created return node

What is left

  • More exhaustive validation
  • Parse arguments that are not variable (NameExpr) or constants, and mostly, the special cases:
    • MethodCallExpr, a nested method call (method call as argument)
    • ConditionalExpr, a ternary expression (condition ? thenExpr : elseExpr) as argument, where thenExpr and elseExpr are expressions that must be parsed too
  • Add global variables (class fields): distinguish between static and instance fields, add to in nodes of a method declaration, etc.

Merge request reports