@@ -122,21 +122,34 @@ class NormalCall extends DataFlowCall, TNormalCall {
122122 override Location getLocation ( ) { result = c .getLocation ( ) }
123123}
124124
125- /** A call for which we want to compute call targets. */
126- private class RelevantCall extends CfgNodes:: CallCfgNode { }
125+ private predicate localFlowStep ( Node nodeFrom , Node nodeTo , StepSummary summary ) {
126+ localFlowStepTypeTracker ( nodeFrom , nodeTo ) and
127+ summary .toString ( ) = "level"
128+ }
127129
128130private module TrackInstanceInput implements CallGraphConstruction:: InputSig {
129- newtype State = additional MkState ( Type m , Boolean exact )
131+ private predicate start0 ( Node start , string typename , boolean exact ) {
132+ start .( ObjectCreationNode ) .getObjectCreationNode ( ) .getConstructedTypeName ( ) = typename and
133+ exact = true
134+ or
135+ start .asExpr ( ) .( CfgNodes:: ExprNodes:: TypeNameCfgNode ) .getTypeName ( ) = typename and
136+ exact = true
137+ }
138+
139+ newtype State = additional MkState ( string typename , Boolean exact ) { start0 ( _, typename , exact ) }
130140
131141 predicate start ( Node start , State state ) {
132- exists ( Type tp , boolean exact | state = MkState ( tp , exact ) |
133- start .asExpr ( ) .( CfgNodes:: ExprNodes:: ConstructorCallCfgNode ) .getConstructedType ( ) = tp
142+ exists ( string typename , boolean exact |
143+ state = MkState ( typename , exact ) and
144+ start0 ( start , typename , exact )
134145 )
135146 }
136147
137148 pragma [ nomagic]
138149 predicate stepNoCall ( Node nodeFrom , Node nodeTo , StepSummary summary ) {
139150 smallStepNoCall ( nodeFrom , nodeTo , summary )
151+ or
152+ localFlowStep ( nodeFrom , nodeTo , summary )
140153 }
141154
142155 predicate stepCall ( Node nodeFrom , Node nodeTo , StepSummary summary ) {
@@ -155,16 +168,22 @@ private predicate qualifiedCall(CfgNodes::CallCfgNode call, Node receiver, strin
155168 call .getName ( ) = method
156169}
157170
158- Node trackInstance ( Type t , boolean exact ) {
171+ Node trackInstance ( string typename , boolean exact ) {
159172 result =
160- CallGraphConstruction:: Make< TrackInstanceInput > :: track ( TrackInstanceInput:: MkState ( t , exact ) )
173+ CallGraphConstruction:: Make< TrackInstanceInput > :: track ( TrackInstanceInput:: MkState ( typename ,
174+ exact ) )
161175}
162176
163177private CfgScope getTargetInstance ( CfgNodes:: CallCfgNode call ) {
164- exists ( Node receiver , string method , Type t |
178+ // TODO: Also match argument/parameter types
179+ exists ( Node receiver , string method , string typename , Type t |
165180 qualifiedCall ( call , receiver , method ) and
166- receiver = trackInstance ( t , _) and
167- result = t .getMemberFunction ( method ) .getBody ( )
181+ receiver = trackInstance ( typename , _) and
182+ t .getName ( ) = typename
183+ |
184+ if method = "new"
185+ then result = t .getAConstructor ( ) .getBody ( )
186+ else result = t .getMethod ( method ) .getBody ( )
168187 )
169188}
170189
0 commit comments