Skip to content

Commit 66da91f

Browse files
committed
Java, Javascript, Csharp: Restrict definitions predicates
Only expose definition-use relation itself, and getEncodedFile.
1 parent beccdce commit 66da91f

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

csharp/ql/src/definitions.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import csharp
77

88
/** An element with an associated definition. */
9-
abstract class Use extends @type_mention_parent {
9+
abstract private class Use extends @type_mention_parent {
1010
/**
1111
* Holds if this element is at the specified location.
1212
* The location spans column `startcolumn` of line `startline` to
@@ -46,7 +46,7 @@ abstract class Use extends @type_mention_parent {
4646
}
4747

4848
/** A method call/access. */
49-
class MethodUse extends Use, QualifiableExpr {
49+
private class MethodUse extends Use, QualifiableExpr {
5050
MethodUse() {
5151
this instanceof MethodCall or
5252
this instanceof MethodAccess
@@ -90,7 +90,7 @@ class MethodUse extends Use, QualifiableExpr {
9090
}
9191

9292
/** An access. */
93-
class AccessUse extends Access, Use {
93+
private class AccessUse extends Access, Use {
9494
AccessUse() {
9595
not this.getTarget().(Parameter).getCallable() instanceof Accessor and
9696
not this = any(LocalVariableDeclAndInitExpr d).getLValue() and
@@ -136,7 +136,7 @@ class AccessUse extends Access, Use {
136136
}
137137

138138
/** A type mention. */
139-
class TypeMentionUse extends Use, TypeMention {
139+
private class TypeMentionUse extends Use, TypeMention {
140140
TypeMentionUse() {
141141
// In type mentions such as `T[]`, `T?`, `T*`, and `(S, T)`, we only want
142142
// uses for the nested type mentions

java/ql/src/definitions.qll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import java
1414
* the location may be slightly inaccurate and include such whitespace,
1515
* but it should suffice for the purpose of avoiding overlapping definitions.
1616
*/
17-
class LocationOverridingMethodAccess extends MethodAccess {
17+
private class LocationOverridingMethodAccess extends MethodAccess {
1818
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
1919
exists(MemberRefExpr e | e.getReferencedCallable() = getMethod() |
2020
exists(int elRef, int ecRef | e.hasLocationInfo(path, _, _, elRef, ecRef) |
@@ -73,7 +73,7 @@ class LocationOverridingMethodAccess extends MethodAccess {
7373
* Restricts the location of a type access to exclude
7474
* the type arguments and qualifier, if any.
7575
*/
76-
class LocationOverridingTypeAccess extends TypeAccess {
76+
private class LocationOverridingTypeAccess extends TypeAccess {
7777
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
7878
exists(int slSuper, int scSuper, int elSuper, int ecSuper |
7979
super.hasLocationInfo(path, slSuper, scSuper, elSuper, ecSuper)
@@ -112,7 +112,7 @@ class LocationOverridingTypeAccess extends TypeAccess {
112112
* Restricts the location of a field access to the name of the accessed field only,
113113
* excluding its qualifier.
114114
*/
115-
class LocationOverridingFieldAccess extends FieldAccess {
115+
private class LocationOverridingFieldAccess extends FieldAccess {
116116
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
117117
super.hasLocationInfo(path, _, _, el, ec) and
118118
sl = el and
@@ -124,7 +124,7 @@ class LocationOverridingFieldAccess extends FieldAccess {
124124
* Restricts the location of a single-type-import declaration to the name of the imported type only,
125125
* excluding the `import` keyword and the package name.
126126
*/
127-
class LocationOverridingImportType extends ImportType {
127+
private class LocationOverridingImportType extends ImportType {
128128
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
129129
exists(int slSuper, int scSuper, int elSuper, int ecSuper |
130130
super.hasLocationInfo(path, slSuper, scSuper, elSuper, ecSuper)
@@ -141,7 +141,7 @@ class LocationOverridingImportType extends ImportType {
141141
* Restricts the location of a single-static-import declaration to the name of the imported member(s) only,
142142
* excluding the `import` keyword and the package name.
143143
*/
144-
class LocationOverridingImportStaticTypeMember extends ImportStaticTypeMember {
144+
private class LocationOverridingImportStaticTypeMember extends ImportStaticTypeMember {
145145
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
146146
exists(int slSuper, int scSuper, int elSuper, int ecSuper |
147147
super.hasLocationInfo(path, slSuper, scSuper, elSuper, ecSuper)
@@ -154,7 +154,7 @@ class LocationOverridingImportStaticTypeMember extends ImportStaticTypeMember {
154154
}
155155
}
156156

157-
Element definition(Element e, string kind) {
157+
private Element definition(Element e, string kind) {
158158
e.(MethodAccess).getMethod().getSourceDeclaration() = result and
159159
kind = "M" and
160160
not result instanceof InitializerMethod
@@ -173,14 +173,14 @@ Element definition(Element e, string kind) {
173173
e.(ImportStaticTypeMember).getAMemberImport() = result and kind = "I"
174174
}
175175

176-
predicate dummyVarAccess(VarAccess va) {
176+
private predicate dummyVarAccess(VarAccess va) {
177177
exists(AssignExpr ae, InitializerMethod im |
178178
ae.getDest() = va and
179179
ae.getParent() = im.getBody().getAChild()
180180
)
181181
}
182182

183-
predicate dummyTypeAccess(TypeAccess ta) {
183+
private predicate dummyTypeAccess(TypeAccess ta) {
184184
exists(FunctionalExpr e |
185185
e.getAnonymousClass().getClassInstanceExpr().getTypeName() = ta.getParent*()
186186
)

javascript/ql/src/definitions.qll

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ private import Declarations.Declarations
1515
* For example, in the expression `f(x)`, `f` has kind `"M"` while
1616
* `x` has kind `"V"`.
1717
*/
18-
string refKind(RefExpr r) {
18+
private string refKind(RefExpr r) {
1919
if exists(InvokeExpr invk | r = invk.getCallee().getUnderlyingReference())
2020
then result = "M"
2121
else result = "V"
@@ -24,7 +24,7 @@ string refKind(RefExpr r) {
2424
/**
2525
* Gets a class, function or object literal `va` may refer to.
2626
*/
27-
ASTNode lookupDef(VarAccess va) {
27+
private ASTNode lookupDef(VarAccess va) {
2828
exists(AbstractValue av | av = va.analyze().getAValue() |
2929
result = av.(AbstractClass).getClass() or
3030
result = av.(AbstractFunction).getFunction() or
@@ -36,7 +36,7 @@ ASTNode lookupDef(VarAccess va) {
3636
* Holds if `va` is of kind `kind` and `def` is the unique class,
3737
* function or object literal it refers to.
3838
*/
39-
predicate variableDefLookup(VarAccess va, ASTNode def, string kind) {
39+
private predicate variableDefLookup(VarAccess va, ASTNode def, string kind) {
4040
count(lookupDef(va)) = 1 and
4141
def = lookupDef(va) and
4242
kind = refKind(va)
@@ -50,7 +50,7 @@ predicate variableDefLookup(VarAccess va, ASTNode def, string kind) {
5050
* expression of `y` is a variable access `x` of kind `"V"` that refers to
5151
* the declaration `x = 42`.
5252
*/
53-
predicate variableDeclLookup(VarAccess va, VarDecl decl, string kind) {
53+
private predicate variableDeclLookup(VarAccess va, VarDecl decl, string kind) {
5454
// restrict to declarations in same file to avoid accidentally picking up
5555
// unrelated global definitions
5656
decl = firstRefInTopLevel(va.getVariable(), Decl(), va.getTopLevel()) and
@@ -65,7 +65,7 @@ predicate variableDeclLookup(VarAccess va, VarDecl decl, string kind) {
6565
* For example, in the statement `var a = require("./a")`, the path expression
6666
* `"./a"` imports a module `a` in the same folder.
6767
*/
68-
predicate importLookup(ASTNode path, Module target, string kind) {
68+
private predicate importLookup(ASTNode path, Module target, string kind) {
6969
kind = "I" and
7070
(
7171
exists(Import i |
@@ -83,7 +83,7 @@ predicate importLookup(ASTNode path, Module target, string kind) {
8383
/**
8484
* Gets a node that may write the property read by `prn`.
8585
*/
86-
ASTNode getAWrite(DataFlow::PropRead prn) {
86+
private ASTNode getAWrite(DataFlow::PropRead prn) {
8787
exists(DataFlow::AnalyzedNode base, DefiniteAbstractValue baseVal, string propName |
8888
base = prn.getBase() and
8989
propName = prn.getPropertyName() and
@@ -111,7 +111,7 @@ ASTNode getAWrite(DataFlow::PropRead prn) {
111111
* only such property write. Parameter `kind` is always bound to `"M"`
112112
* at the moment.
113113
*/
114-
predicate propertyLookup(Expr prop, ASTNode write, string kind) {
114+
private predicate propertyLookup(Expr prop, ASTNode write, string kind) {
115115
exists(DataFlow::PropRead prn | prop = prn.getPropertyNameExpr() |
116116
count(getAWrite(prn)) = 1 and
117117
write = getAWrite(prn) and
@@ -122,7 +122,7 @@ predicate propertyLookup(Expr prop, ASTNode write, string kind) {
122122
/**
123123
* Holds if `ref` is an identifier that refers to a type declared at `decl`.
124124
*/
125-
predicate typeLookup(ASTNode ref, ASTNode decl, string kind) {
125+
private predicate typeLookup(ASTNode ref, ASTNode decl, string kind) {
126126
exists(TypeAccess typeAccess |
127127
ref = typeAccess.getIdentifier() and
128128
decl = typeAccess.getTypeName().getADefinition() and
@@ -133,7 +133,7 @@ predicate typeLookup(ASTNode ref, ASTNode decl, string kind) {
133133
/**
134134
* Holds if `ref` is the callee name of an invocation of `decl`.
135135
*/
136-
predicate typedInvokeLookup(ASTNode ref, ASTNode decl, string kind) {
136+
private predicate typedInvokeLookup(ASTNode ref, ASTNode decl, string kind) {
137137
not variableDefLookup(ref, decl, _) and
138138
not propertyLookup(ref, decl, _) and
139139
exists(InvokeExpr invoke, Expr callee |
@@ -147,7 +147,7 @@ predicate typedInvokeLookup(ASTNode ref, ASTNode decl, string kind) {
147147
/**
148148
* Holds if `ref` is a JSDoc type annotation referring to a class defined at `decl`.
149149
*/
150-
predicate jsdocTypeLookup(JSDocNamedTypeExpr ref, ASTNode decl, string kind) {
150+
private predicate jsdocTypeLookup(JSDocNamedTypeExpr ref, ASTNode decl, string kind) {
151151
decl = ref.getClass().getAstNode() and
152152
kind = "T"
153153
}

0 commit comments

Comments
 (0)