@@ -995,6 +995,52 @@ private class InstanceCallable extends Callable { |
995 | 995 | Location getARelevantLocation() { result = l } |
996 | 996 | } |
997 | 997 |
|
| 998 | +/** |
| 999 | + * A callable which is either itself defined in source or which is the target |
| 1000 | + * of some call in source, and therefore ought to have dataflow nodes created. |
| 1001 | + * |
| 1002 | + * Note that for library methods these are always unbound declarations, since |
| 1003 | + * generic instantiations never have dataflow nodes constructed. |
| 1004 | + */ |
| 1005 | +private class CallableUsedInSource extends Callable { |
| 1006 | + CallableUsedInSource() { |
| 1007 | + // Should generate nodes even for abstract methods declared in source |
| 1008 | + this.fromSource() |
| 1009 | + or |
| 1010 | + // Should generate nodes even for synthetic methods derived from source |
| 1011 | + this.hasBody() |
| 1012 | + or |
| 1013 | + exists(Callable target | |
| 1014 | + exists(Call c | |
| 1015 | + // Note that getADynamicTarget does not always include getTarget. |
| 1016 | + target = c.getTarget() |
| 1017 | + or |
| 1018 | + // Note that getARuntimeTarget cannot be used here, because the |
| 1019 | + // DelegateLikeCall case depends on lambda-flow, which in turn |
| 1020 | + // uses the dataflow library; hence this would introduce recursion |
| 1021 | + // into the definition of data-flow nodes. |
| 1022 | + exists(DispatchCall dc | c = dc.getCall() | target = dc.getADynamicTarget()) |
| 1023 | + ) |
| 1024 | + or |
| 1025 | + target = any(CallableAccess ca).getTarget() |
| 1026 | + | |
| 1027 | + this = target.getUnboundDeclaration() |
| 1028 | + ) |
| 1029 | + } |
| 1030 | +} |
| 1031 | + |
| 1032 | +/** |
| 1033 | + * A field or property which is either itself defined in source or which is the target |
| 1034 | + * of some access in source, and therefore ought to have dataflow nodes created. |
| 1035 | + */ |
| 1036 | +private class FieldOrPropertyUsedInSource extends FieldOrProperty { |
| 1037 | + FieldOrPropertyUsedInSource() { |
| 1038 | + this.fromSource() |
| 1039 | + or |
| 1040 | + this.getAnAccess().fromSource() |
| 1041 | + } |
| 1042 | +} |
| 1043 | + |
998 | 1044 | /** A collection of cached types and predicates to be evaluated in the same stage. */ |
999 | 1045 | cached |
1000 | 1046 | private module Cached { |
@@ -1018,8 +1064,13 @@ private module Cached { |
1018 | 1064 | TAssignableDefinitionNode(AssignableDefinition def, ControlFlow::Node cfn) { |
1019 | 1065 | cfn = def.getExpr().getAControlFlowNode() |
1020 | 1066 | } or |
1021 | | - TExplicitParameterNode(Parameter p, DataFlowCallable c) { p = c.asCallable(_).getAParameter() } or |
1022 | | - TInstanceParameterNode(InstanceCallable c, Location l) { l = c.getARelevantLocation() } or |
| 1067 | + TExplicitParameterNode(Parameter p, DataFlowCallable c) { |
| 1068 | + p = c.asCallable(_).(CallableUsedInSource).getAParameter() |
| 1069 | + } or |
| 1070 | + TInstanceParameterNode(InstanceCallable c, Location l) { |
| 1071 | + c instanceof CallableUsedInSource and |
| 1072 | + l = c.getARelevantLocation() |
| 1073 | + } or |
1023 | 1074 | TDelegateSelfReferenceNode(Callable c) { lambdaCreationExpr(_, c) } or |
1024 | 1075 | TLocalFunctionCreationNode(ControlFlow::Nodes::ElementNode cfn, Boolean isPostUpdate) { |
1025 | 1076 | cfn.getAstNode() instanceof LocalFunctionStmt |
@@ -1055,11 +1106,13 @@ private module Cached { |
1055 | 1106 | or |
1056 | 1107 | lambdaCallExpr(_, cfn) |
1057 | 1108 | } or |
1058 | | - TFlowSummaryNode(FlowSummaryImpl::Private::SummaryNode sn) or |
| 1109 | + TFlowSummaryNode(FlowSummaryImpl::Private::SummaryNode sn) { |
| 1110 | + sn.getSummarizedCallable() instanceof CallableUsedInSource |
| 1111 | + } or |
1059 | 1112 | TParamsArgumentNode(ControlFlow::Node callCfn) { |
1060 | 1113 | callCfn = any(Call c | isParamsArg(c, _, _)).getAControlFlowNode() |
1061 | 1114 | } or |
1062 | | - TFlowInsensitiveFieldNode(FieldOrProperty f) { f.isFieldLike() } or |
| 1115 | + TFlowInsensitiveFieldNode(FieldOrPropertyUsedInSource f) { f.isFieldLike() } or |
1063 | 1116 | TFlowInsensitiveCapturedVariableNode(LocalScopeVariable v) { v.isCaptured() } or |
1064 | 1117 | TInstanceParameterAccessNode(ControlFlow::Node cfn, Boolean isPostUpdate) { |
1065 | 1118 | cfn = getAPrimaryConstructorParameterCfn(_) |
|