Skip to content

Commit 115cef2

Browse files
committed
C#: Move asPartialModel into DataFlowPrivate (to enable re-use).
1 parent 7a9a9d8 commit 115cef2

File tree

3 files changed

+48
-41
lines changed

3 files changed

+48
-41
lines changed

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,3 +2031,47 @@ abstract class SyntheticField extends string {
20312031
* Holds if the the content `c` is a container.
20322032
*/
20332033
predicate containerContent(DataFlow::Content c) { c instanceof DataFlow::ElementContent }
2034+
2035+
/**
2036+
* Module containing predicates related to generating models as data.
2037+
*/
2038+
module Csv {
2039+
private string parameterQualifiedTypeNamesToString(DataFlowCallable c) {
2040+
result =
2041+
concat(Parameter p, int i |
2042+
p = c.getParameter(i)
2043+
|
2044+
p.getType().getQualifiedName(), "," order by i
2045+
)
2046+
}
2047+
2048+
/** Holds if the summary should apply for all overrides of this. */
2049+
private predicate isBaseCallableOrPrototype(DataFlowCallable c) {
2050+
c.getDeclaringType() instanceof Interface
2051+
or
2052+
exists(Modifiable m | m = [c.(Modifiable), c.(Accessor).getDeclaration()] |
2053+
m.isAbstract()
2054+
or
2055+
c.getDeclaringType().(Modifiable).isAbstract() and m.(Virtualizable).isVirtual()
2056+
)
2057+
}
2058+
2059+
/** Gets a string representing whether the summary should apply for all overrides of this. */
2060+
private string getCallableOverride(DataFlowCallable c) {
2061+
if isBaseCallableOrPrototype(c) then result = "true" else result = "false"
2062+
}
2063+
2064+
/** Computes the first 6 columns for CSV rows. */
2065+
string asPartialModel(DataFlowCallable c) {
2066+
exists(string namespace, string type |
2067+
c.getDeclaringType().hasQualifiedName(namespace, type) and
2068+
result =
2069+
namespace + ";" //
2070+
+ type + ";" //
2071+
+ getCallableOverride(c) + ";" //
2072+
+ c.getName() + ";" //
2073+
+ "(" + parameterQualifiedTypeNamesToString(c) + ")" //
2074+
+ /* ext + */ ";" //
2075+
)
2076+
}
2077+
}

csharp/ql/src/utils/model-generator/ModelGeneratorUtilsSpecific.qll

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,20 @@ private import semmle.code.csharp.dataflow.internal.DataFlowDispatch
77
private predicate isRelevantForModels(Callable api) { not api instanceof MainMethod }
88

99
/**
10-
* A class of Callables that are relevant for generating summary, source and sinks models for.
10+
* A class of DataFlowCallables that are relevant generating summary, source and sinks models for.
1111
*
1212
* In the Standard library and 3rd party libraries it the Callables that can be called
1313
* from outside the library itself.
1414
*/
15-
class TargetApi extends Callable {
15+
class TargetApi extends DataFlowCallable {
1616
TargetApi() {
1717
[this.(Modifiable), this.(Accessor).getDeclaration()].isEffectivelyPublic() and
1818
this.fromSource() and
1919
isRelevantForModels(this)
2020
}
2121
}
2222

23-
private string parameterQualifiedTypeNamesToString(TargetApi api) {
24-
result =
25-
concat(Parameter p, int i |
26-
p = api.getParameter(i)
27-
|
28-
p.getType().getQualifiedName(), "," order by i
29-
)
30-
}
31-
32-
/** Holds if the summary should apply for all overrides of this. */
33-
private predicate isBaseCallableOrPrototype(TargetApi api) {
34-
api.getDeclaringType() instanceof Interface
35-
or
36-
exists(Modifiable m | m = [api.(Modifiable), api.(Accessor).getDeclaration()] |
37-
m.isAbstract()
38-
or
39-
api.getDeclaringType().(Modifiable).isAbstract() and m.(Virtualizable).isVirtual()
40-
)
41-
}
42-
43-
/** Gets a string representing whether the summary should apply for all overrides of this. */
44-
private string getCallableOverride(TargetApi api) {
45-
if isBaseCallableOrPrototype(api) then result = "true" else result = "false"
46-
}
47-
48-
/** Computes the first 6 columns for CSV rows. */
49-
string asPartialModel(TargetApi api) {
50-
exists(string namespace, string type |
51-
api.getDeclaringType().hasQualifiedName(namespace, type) and
52-
result =
53-
namespace + ";" //
54-
+ type + ";" //
55-
+ getCallableOverride(api) + ";" //
56-
+ api.getName() + ";" //
57-
+ "(" + parameterQualifiedTypeNamesToString(api) + ")" //
58-
+ /* ext + */ ";" //
59-
)
60-
}
23+
predicate asPartialModel = Csv::asPartialModel/1;
6124

6225
/**
6326
* Holds for type `t` for fields that are relevant as an intermediate

java/ql/src/utils/model-generator/ModelGeneratorUtilsSpecific.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ private import semmle.code.java.dataflow.ExternalFlow
55
private import semmle.code.java.dataflow.internal.ContainerFlow
66
private import semmle.code.java.dataflow.internal.DataFlowImplCommon
77

8-
Method superImpl(Method m) {
8+
private Method superImpl(Method m) {
99
result = m.getAnOverride() and
1010
not exists(result.getAnOverride()) and
1111
not m instanceof ToStringMethod

0 commit comments

Comments
 (0)