Skip to content

Commit dbdc727

Browse files
committed
have unique parents, also for mock AST nodes
1 parent 5728e3e commit dbdc727

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

ql/ql/src/codeql_ql/ast/internal/AstNodes.qll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,5 @@ module AstConsistency {
248248
not (node instanceof QLDoc and node.getLocation().getFile().getExtension() = "dbscheme") // qldoc in dbschemes are not hooked up
249249
}
250250

251-
query predicate nonUniqueParent(AstNode node) {
252-
count(node.getParent()) >= 2 and
253-
not exists(AstNodes::toMock(node)) // we don't care about the mocks, they are nasty by design.
254-
}
251+
query predicate nonUniqueParent(AstNode node) { count(node.getParent()) >= 2 }
255252
}

ql/ql/src/codeql_ql/ast/internal/Builtins.qll

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,18 @@ module QlBuiltinsMocks {
140140
override string getName() { result = "T" }
141141
}
142142

143-
/** A mock TypeExpr with classname `T`. */
143+
/** A mock TypeExpr with classname `T`. Which we have 5 copies of. */
144144
class DummyTTypeExpr extends MockTypeExpr::Range {
145-
DummyTTypeExpr() { this = "Mock: QlBuiltins::T" }
145+
int n;
146+
147+
DummyTTypeExpr() {
148+
this = "Mock: QlBuiltins::T(" + n + ")" and
149+
n = [0 .. 4]
150+
}
146151

147152
override string getClassName() { result = "T" }
153+
154+
int getN() { result = n }
148155
}
149156

150157
module EdgeSig {
@@ -154,7 +161,7 @@ module QlBuiltinsMocks {
154161
override string getName() { result = "EdgeSig" }
155162

156163
override predicate hasTypeParam(int i, string type, string name) {
157-
i = 0 and name = "MyT" and type instanceof DummyTTypeExpr
164+
i = 0 and name = "MyT" and type.(DummyTTypeExpr).getN() = 0
158165
}
159166

160167
override string getMember(int i) { i = 0 and result instanceof EdgeSigPred }
@@ -183,7 +190,11 @@ module QlBuiltinsMocks {
183190

184191
override string getName() { result = name }
185192

186-
override MockTypeExpr::Range getType() { result instanceof DummyTTypeExpr }
193+
override MockTypeExpr::Range getType() {
194+
name = "a" and result.(DummyTTypeExpr).getN() = 1
195+
or
196+
name = "b" and result.(DummyTTypeExpr).getN() = 2
197+
}
187198
}
188199
}
189200

@@ -199,7 +210,7 @@ module QlBuiltinsMocks {
199210
}
200211

201212
override predicate hasTypeParam(int i, string type, string name) {
202-
i = 0 and name = "MyT" and type instanceof DummyTTypeExpr
213+
i = 0 and name = "MyT" and type.(DummyTTypeExpr).getN() = 3
203214
or
204215
none() // TODO: `EdgeSig<MyT>::edgeSig/2 edge` is not implemented.
205216
}
@@ -213,7 +224,7 @@ module QlBuiltinsMocks {
213224
override string getName() { result = "getEquivalenceClass" }
214225

215226
override MockVarDecl::Range getParameter(int i) {
216-
result.(EdgeSig::EdgeSigPredParam).getName() = "a" and // just reusing another mock node that has the right name and type.
227+
result instanceof GetEquivalenceClassPredicateAParam and
217228
i = 0
218229
}
219230

@@ -222,6 +233,16 @@ module QlBuiltinsMocks {
222233
}
223234
}
224235

236+
class GetEquivalenceClassPredicateAParam extends MockVarDecl::Range {
237+
GetEquivalenceClassPredicateAParam() {
238+
this = "Mock: QlBuiltins::EquivalenceRelation::getEquivalenceClass::a"
239+
}
240+
241+
override string getName() { result = "a" }
242+
243+
override MockTypeExpr::Range getType() { result.(DummyTTypeExpr).getN() = 4 }
244+
}
245+
225246
class EquivalenceClassClass extends MockClass::Range {
226247
EquivalenceClassClass() {
227248
this = "Mock: QlBuiltins::EquivalenceRelation::EquivalenceClass(Class)"

0 commit comments

Comments
 (0)