Resolve 6-method-call-nodes
Created by: jacosro
Implemented
- Added
type
field to node (NodeType
enum) - Added
TypeNodeFactory
, with an only and staticfromType
method, creates aGraphNode
providing aNodeType
- 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
andReturnArc
-
MethodCallReplacerVisitor
: Visitor that looks for method call nodes and addscall
,in
,out
andreturn
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
andout
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:
- Find the
MethodDeclaration
which the method call makes reference (This is done with JavaParser'sSymbolSolver
). If none is found, do nothing - Iterate over the method declaration's parameters:
2.1. Build
in
nodes. For each one do: 2.1.1. Create a newin
node with the form:int <parameterName>_in = <variable>
2.1.2. Add a control dependency arc fromcall
node to the newly createdin
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 createdin
node 2.2. Buildout
nodes: For each one do: 2.2.1. Create a newout
node with the form:<variable> = <parameterName>_out
2.2.2. Add a control dependency arc fromcall
node to the newly createdout
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 createdout
node the source of the variable data dependencies - Build
return
node 3.1. Add a new node to the graph with anEmptyStmt
3.2. Add a control dependency arc from thecall
node to the newly createdreturn
node 3.3. Add a return arc from all method'sReturnStmt
nodes to the newly createdreturn
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, wherethenExpr
andelseExpr
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.