Skip to content

Commit c8a7354

Browse files
michaelnebelhvitved
authored andcommitted
C#: Refactor to align implementation between languages.
1 parent 0d61a2c commit c8a7354

File tree

11 files changed

+28
-26
lines changed

11 files changed

+28
-26
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/ExternalFlow.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,9 @@ Element interpretElement(
515515
/**
516516
* Holds if `c` has a `generated` summary.
517517
*/
518-
predicate hasSummary(Callable c, boolean generated) { summaryElement(c, _, _, _, generated) }
518+
predicate hasSummary(Callable c, boolean generated) {
519+
exists(DataFlowCallable dc | dc.asCallable() = c and summaryElement(dc, _, _, _, generated))
520+
}
519521

520522
cached
521523
private module Cached {

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowDispatch.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ private module DispatchImpl {
144144
* call is a delegate call, or if the qualifier accesses a parameter of
145145
* the enclosing callable `c` (including the implicit `this` parameter).
146146
*/
147-
predicate mayBenefitFromCallContext(NonDelegateDataFlowCall call, Callable c) {
148-
c = call.getEnclosingCallable().asCallable() and
147+
predicate mayBenefitFromCallContext(NonDelegateDataFlowCall call, DataFlowCallable c) {
148+
c = call.getEnclosingCallable() and
149149
call.getDispatchCall().mayBenefitFromCallContext()
150150
}
151151

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ private module Cached {
698698
*/
699699
pragma[nomagic]
700700
private predicate mayBenefitFromCallContextExt(DataFlowCall call, DataFlowCallable callable) {
701-
mayBenefitFromCallContext(call, callable.asCallable())
701+
mayBenefitFromCallContext(call, callable)
702702
or
703703
callEnclosingCallable(call, callable) and
704704
exists(viableCallableLambda(call, TDataFlowCallSome(_)))

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private import semmle.code.csharp.frameworks.system.Collections
1919
private import semmle.code.csharp.frameworks.system.threading.Tasks
2020

2121
/** Gets the callable in which this node occurs. */
22-
DataFlowCallable nodeGetEnclosingCallable(Node n) { result = n.getEnclosingCallable() }
22+
DataFlowCallable nodeGetEnclosingCallable(Node n) { result.asCallable() = n.getEnclosingCallable() }
2323

2424
/** Holds if `p` is a `ParameterNode` of `c` with position `pos`. */
2525
predicate isParameterNode(ParameterNodeImpl p, DataFlowCallable c, ParameterPosition pos) {
@@ -960,7 +960,7 @@ private module ParameterNodes {
960960

961961
override predicate isParameterOf(DataFlowCallable c, ParameterPosition pos) {
962962
pos.isImplicitCapturedParameterPosition(def.getSourceVariable().getAssignable()) and
963-
c = this.getEnclosingCallable()
963+
c.asCallable() = this.getEnclosingCallable()
964964
}
965965
}
966966
}
@@ -1384,7 +1384,7 @@ private module OutNodes {
13841384
additionalCalls = false and call = csharpCall(_, cfn)
13851385
or
13861386
additionalCalls = true and
1387-
call = TTransitiveCapturedCall(cfn, n.getEnclosingCallable().asCallable())
1387+
call = TTransitiveCapturedCall(cfn, n.getEnclosingCallable())
13881388
)
13891389
}
13901390

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPublic.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class Node extends TNode {
4040
final DotNet::Type getType() { result = this.(NodeImpl).getTypeImpl() }
4141

4242
/** Gets the enclosing callable of this node. */
43-
final DataFlowCallable getEnclosingCallable() {
44-
result = this.(NodeImpl).getEnclosingCallableImpl()
43+
final Callable getEnclosingCallable() {
44+
result = this.(NodeImpl).getEnclosingCallableImpl().asCallable()
4545
}
4646

4747
/** Gets the control flow node corresponding to this node, if any. */

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DelegateDataFlow.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ deprecated private predicate flowIntoDelegateCall(DelegateLikeCall call, Callabl
269269

270270
pragma[noinline]
271271
private predicate flowOutOfNonDelegateCall(NonDelegateCall call, NormalReturnNode ret) {
272-
call.getARuntimeTarget() = ret.getEnclosingCallable().asCallable()
272+
call.getARuntimeTarget() = ret.getEnclosingCallable()
273273
}
274274

275275
pragma[noinline]
@@ -278,7 +278,7 @@ deprecated private predicate flowOutOfDelegateCall(
278278
) {
279279
exists(DelegateLikeFlowSource dfs, DelegateLikeCallExpr dce, Callable c |
280280
flowsFrom(dce, dfs, _, lastCall) and
281-
ret.getEnclosingCallable().asCallable() = c and
281+
ret.getEnclosingCallable() = c and
282282
c = dfs.getCallable() and
283283
dc = dce.getCall()
284284
)

csharp/ql/lib/semmle/code/csharp/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -910,13 +910,13 @@ module Private {
910910
}
911911

912912
private class SummarizedCallableExternal extends SummarizedCallable {
913-
SummarizedCallableExternal() { summaryElement(this.asCallable(), _, _, _, _) }
913+
SummarizedCallableExternal() { summaryElement(this, _, _, _, _) }
914914

915915
private predicate relevantSummaryElement(AccessPath inSpec, AccessPath outSpec, string kind) {
916-
summaryElement(this.asCallable(), inSpec, outSpec, kind, false)
916+
summaryElement(this, inSpec, outSpec, kind, false)
917917
or
918-
summaryElement(this.asCallable(), inSpec, outSpec, kind, true) and
919-
not summaryElement(this.asCallable(), _, _, _, false)
918+
summaryElement(this, inSpec, outSpec, kind, true) and
919+
not summaryElement(this, _, _, _, false)
920920
}
921921

922922
override predicate propagatesFlow(
@@ -933,7 +933,7 @@ module Private {
933933
)
934934
}
935935

936-
override predicate isAutoGenerated() { summaryElement(this.asCallable(), _, _, _, true) }
936+
override predicate isAutoGenerated() { summaryElement(this, _, _, _, true) }
937937
}
938938

939939
/** Holds if component `c` of specification `spec` cannot be parsed. */

csharp/ql/lib/semmle/code/csharp/dataflow/internal/FlowSummaryImplSpecific.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ DataFlowType getCallbackReturnType(DataFlowType t, ReturnKind rk) {
9090
* stating whether the summary is autogenerated.
9191
*/
9292
predicate summaryElement(
93-
DotNet::Callable c, string input, string output, string kind, boolean generated
93+
DataFlowCallable c, string input, string output, string kind, boolean generated
9494
) {
9595
exists(
9696
string namespace, string type, boolean subtypes, string name, string signature, string ext
9797
|
9898
summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, generated) and
99-
c = interpretElement(namespace, type, subtypes, name, signature, ext)
99+
c.asCallable() = interpretElement(namespace, type, subtypes, name, signature, ext)
100100
)
101101
}
102102

csharp/ql/src/API Abuse/NoDisposeCallOnLocalIDisposable.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ predicate mayNotBeDisposed(LocalScopeDisposableCreation disposable) {
9999
not exists(DataFlow::Node sink | conf.hasFlow(DataFlow::exprNode(disposable), sink) |
100100
sink instanceof ReturnNode
101101
implies
102-
sink.getEnclosingCallable().asCallable() = disposable.getEnclosingCallable()
102+
sink.getEnclosingCallable() = disposable.getEnclosingCallable()
103103
)
104104
)
105105
}

csharp/ql/src/utils/model-generator/internal/CaptureModels.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private class ThroughFlowConfig extends TaintTracking::Configuration {
131131

132132
override predicate isSource(DataFlow::Node source, DataFlow::FlowState state) {
133133
source instanceof DataFlow::ParameterNode and
134-
source.getEnclosingCallable().asCallable() instanceof TargetApi and
134+
source.getEnclosingCallable() instanceof TargetApi and
135135
state.(TaintRead).getStep() = 0
136136
}
137137

@@ -181,7 +181,7 @@ string captureThroughFlow(TargetApi api) {
181181
DataFlowImplCommon::ReturnNodeExt returnNodeExt, string input, string output
182182
|
183183
config.hasFlow(p, returnNodeExt) and
184-
returnNodeExt.getEnclosingCallable().asCallable() = api and
184+
returnNodeExt.getEnclosingCallable() = api and
185185
input = parameterNodeAsInput(p) and
186186
output = returnNodeAsOutput(returnNodeExt) and
187187
input != output and
@@ -204,7 +204,7 @@ private class FromSourceConfiguration extends TaintTracking::Configuration {
204204
override predicate isSink(DataFlow::Node sink) {
205205
exists(TargetApi c |
206206
sink instanceof DataFlowImplCommon::ReturnNodeExt and
207-
sink.getEnclosingCallable().asCallable() = c
207+
sink.getEnclosingCallable() = c
208208
)
209209
}
210210

@@ -224,7 +224,7 @@ string captureSource(TargetApi api) {
224224
exists(DataFlow::Node source, DataFlow::Node sink, FromSourceConfiguration config, string kind |
225225
config.hasFlow(source, sink) and
226226
ExternalFlow::sourceNode(source, kind) and
227-
api = sink.getEnclosingCallable().asCallable() and
227+
api = sink.getEnclosingCallable() and
228228
result = asSourceModel(api, returnNodeAsOutput(sink), kind)
229229
)
230230
}
@@ -253,7 +253,7 @@ string captureSink(TargetApi api) {
253253
exists(DataFlow::Node src, DataFlow::Node sink, PropagateToSinkConfiguration config, string kind |
254254
config.hasFlow(src, sink) and
255255
ExternalFlow::sinkNode(sink, kind) and
256-
api = src.getEnclosingCallable().asCallable() and
256+
api = src.getEnclosingCallable() and
257257
isRelevantSinkKind(kind) and
258258
result = asSinkModel(api, asInputArgument(src), kind)
259259
)

0 commit comments

Comments
 (0)