@@ -44,22 +44,18 @@ signature module ModelGeneratorInputSig<LocationSig Location, InputSig<Location>
4444 * Gets the type of this node.
4545 */
4646 Type getType ( ) ;
47+ }
4748
48- /**
49- * Gets the enclosing callable of this node.
50- */
51- Callable getEnclosingCallable ( ) ;
49+ /** Gets the enclosing callable of `node`. */
50+ Callable getEnclosingCallable ( NodeExtended node ) ;
5251
53- /**
54- * Gets the enclosing callable of this node, when considered as an expression.
55- */
56- Callable getAsExprEnclosingCallable ( ) ;
52+ /**
53+ * Gets the enclosing callable of ` node` , when considered as an expression.
54+ */
55+ Callable getAsExprEnclosingCallable ( NodeExtended node ) ;
5756
58- /**
59- * Gets the parameter corresponding to this node, if any.
60- */
61- Parameter asParameter ( ) ;
62- }
57+ /** Gets the parameter corresponding to this node, if any. */
58+ Parameter asParameter ( NodeExtended n ) ;
6359
6460 /**
6561 * A class of callables that are potentially relevant for generating summary or
@@ -226,6 +222,14 @@ signature module ModelGeneratorInputSig<LocationSig Location, InputSig<Location>
226222 */
227223 default Lang:: ParameterPosition getReturnKindParamPosition ( Lang:: ReturnKind node ) { none ( ) }
228224
225+ /**
226+ * Gets the string that represents the return value corresponding to the
227+ * return kind `kind`.
228+ *
229+ * For most languages this will be the string "ReturnValue".
230+ */
231+ default string getReturnValueString ( Lang:: ReturnKind kind ) { result = "ReturnValue" }
232+
229233 /**
230234 * Holds if it is irrelevant to generate models for `api` based on data flow analysis.
231235 *
@@ -321,9 +325,11 @@ module MakeModelGenerator<
321325
322326 private module PrintReturnNodeExt< printCallableParamSig / 2 printCallableParam> {
323327 string getOutput ( ReturnNodeExt node ) {
324- node .getKind ( ) instanceof DataFlow:: ValueReturnKind and
325- not exists ( node .getPosition ( ) ) and
326- result = "ReturnValue"
328+ exists ( DataFlow:: ValueReturnKind valueReturnKind |
329+ valueReturnKind = node .getKind ( ) and
330+ not exists ( node .getPosition ( ) ) and
331+ result = getReturnValueString ( valueReturnKind .getKind ( ) )
332+ )
327333 or
328334 exists ( DataFlow:: ParameterPosition pos |
329335 pos = node .getPosition ( ) and
@@ -390,7 +396,7 @@ module MakeModelGenerator<
390396 * Gets the MaD string representation of the parameter node `p`.
391397 */
392398 string parameterNodeAsInput ( DataFlow:: ParameterNode p ) {
393- result = parameterAccess ( p . ( NodeExtended ) . asParameter ( ) )
399+ result = parameterAccess ( asParameter ( p ) )
394400 or
395401 result = qualifierString ( ) and p instanceof InstanceParameterNode
396402 }
@@ -465,7 +471,7 @@ module MakeModelGenerator<
465471 predicate isSource ( DataFlow:: Node source , FlowState state ) {
466472 source instanceof DataFlow:: ParameterNode and
467473 exists ( Callable c |
468- c = source . ( NodeExtended ) . getEnclosingCallable ( ) and
474+ c = getEnclosingCallable ( source ) and
469475 c instanceof DataFlowSummaryTargetApi and
470476 not isUninterestingForHeuristicDataFlowModels ( c )
471477 ) and
@@ -475,7 +481,7 @@ module MakeModelGenerator<
475481 predicate isSink ( DataFlow:: Node sink , FlowState state ) {
476482 sink instanceof ReturnNodeExt and
477483 not isOwnInstanceAccessNode ( sink ) and
478- not exists ( captureQualifierFlow ( sink . ( NodeExtended ) . getAsExprEnclosingCallable ( ) ) ) and
484+ not exists ( captureQualifierFlow ( getAsExprEnclosingCallable ( sink ) ) ) and
479485 ( state instanceof TaintRead or state instanceof TaintStore )
480486 }
481487
@@ -519,8 +525,8 @@ module MakeModelGenerator<
519525 DataFlowSummaryTargetApi api , DataFlow:: ParameterNode p , ReturnNodeExt returnNodeExt
520526 ) {
521527 exists ( string input , string output |
522- p . ( NodeExtended ) . getEnclosingCallable ( ) = api and
523- returnNodeExt . getEnclosingCallable ( ) = api and
528+ getEnclosingCallable ( p ) = api and
529+ getEnclosingCallable ( returnNodeExt ) = api and
524530 input = parameterNodeAsInput ( p ) and
525531 output = getOutput ( returnNodeExt ) and
526532 input != output and
@@ -570,11 +576,12 @@ module MakeModelGenerator<
570576 private module PropagateContentFlowConfig implements ContentDataFlow:: ConfigSig {
571577 predicate isSource ( DataFlow:: Node source ) {
572578 source instanceof DataFlow:: ParameterNode and
573- source . ( NodeExtended ) . getEnclosingCallable ( ) instanceof DataFlowSummaryTargetApi
579+ getEnclosingCallable ( source ) instanceof DataFlowSummaryTargetApi
574580 }
575581
576582 predicate isSink ( DataFlow:: Node sink ) {
577- sink .( ReturnNodeExt ) .getEnclosingCallable ( ) instanceof DataFlowSummaryTargetApi
583+ sink instanceof ReturnNodeExt and
584+ getEnclosingCallable ( sink ) instanceof DataFlowSummaryTargetApi
578585 }
579586
580587 predicate isAdditionalFlowStep = isAdditionalContentFlowStep / 2 ;
@@ -613,7 +620,7 @@ module MakeModelGenerator<
613620 * when used in content flow.
614621 */
615622 private string parameterNodeAsContentInput ( DataFlow:: ParameterNode p ) {
616- result = parameterContentAccess ( p . ( NodeExtended ) . asParameter ( ) )
623+ result = parameterContentAccess ( asParameter ( p ) )
617624 or
618625 result = qualifierString ( ) and p instanceof InstanceParameterNode
619626 }
@@ -667,8 +674,8 @@ module MakeModelGenerator<
667674 PropagateContentFlow:: AccessPath stores , boolean preservesValue
668675 ) {
669676 PropagateContentFlow:: flow ( p , reads , returnNodeExt , stores , preservesValue ) and
670- returnNodeExt . getEnclosingCallable ( ) = api and
671- p . ( NodeExtended ) . getEnclosingCallable ( ) = api
677+ getEnclosingCallable ( returnNodeExt ) = api and
678+ getEnclosingCallable ( p ) = api
672679 }
673680
674681 /**
@@ -687,7 +694,7 @@ module MakeModelGenerator<
687694 private DataFlow:: ParameterNode parameter ;
688695
689696 ContentDataFlowSummaryTargetApi ( ) {
690- count ( string input , string output |
697+ strictcount ( string input , string output |
691698 exists (
692699 PropagateContentFlow:: AccessPath reads , ReturnNodeExt returnNodeExt ,
693700 PropagateContentFlow:: AccessPath stores
@@ -712,8 +719,8 @@ module MakeModelGenerator<
712719 PropagateContentFlow:: AccessPath stores , boolean preservesValue
713720 ) {
714721 PropagateContentFlow:: flow ( p , reads , returnNodeExt , stores , preservesValue ) and
715- returnNodeExt . getEnclosingCallable ( ) = api and
716- p . ( NodeExtended ) . getEnclosingCallable ( ) = api and
722+ getEnclosingCallable ( returnNodeExt ) = api and
723+ getEnclosingCallable ( p ) = api and
717724 p = api .getARelevantParameterNode ( )
718725 }
719726
@@ -985,7 +992,8 @@ module MakeModelGenerator<
985992 }
986993
987994 predicate isSink ( DataFlow:: Node sink ) {
988- sink .( ReturnNodeExt ) .getEnclosingCallable ( ) instanceof DataFlowSourceTargetApi
995+ sink instanceof ReturnNodeExt and
996+ getEnclosingCallable ( sink ) instanceof DataFlowSourceTargetApi
989997 }
990998
991999 DataFlow:: FlowFeature getAFeature ( ) { result instanceof DataFlow:: FeatureHasSinkCallContext }
@@ -1008,8 +1016,8 @@ module MakeModelGenerator<
10081016 exists ( NodeExtended source , ReturnNodeExt sink , string kind |
10091017 PropagateFromSource:: flow ( source , sink ) and
10101018 sourceNode ( source , kind ) and
1011- api = sink . getEnclosingCallable ( ) and
1012- not irrelevantSourceSinkApi ( source . getEnclosingCallable ( ) , api ) and
1019+ api = getEnclosingCallable ( sink ) and
1020+ not irrelevantSourceSinkApi ( getEnclosingCallable ( source ) , api ) and
10131021 result = ModelPrinting:: asSourceModel ( api , getOutput ( sink ) , kind )
10141022 )
10151023 }
@@ -1024,7 +1032,7 @@ module MakeModelGenerator<
10241032 module PropagateToSinkConfig implements DataFlow:: ConfigSig {
10251033 predicate isSource ( DataFlow:: Node source ) {
10261034 apiSource ( source ) and
1027- source . ( NodeExtended ) . getEnclosingCallable ( ) instanceof DataFlowSinkTargetApi
1035+ getEnclosingCallable ( source ) instanceof DataFlowSinkTargetApi
10281036 }
10291037
10301038 predicate isSink ( DataFlow:: Node sink ) {
@@ -1053,7 +1061,7 @@ module MakeModelGenerator<
10531061 exists ( NodeExtended src , NodeExtended sink , string kind |
10541062 PropagateToSink:: flow ( src , sink ) and
10551063 sinkNode ( sink , kind ) and
1056- api = src . getEnclosingCallable ( ) and
1064+ api = getEnclosingCallable ( src ) and
10571065 result = ModelPrinting:: asSinkModel ( api , asInputArgument ( src ) , kind )
10581066 )
10591067 }
0 commit comments