Skip to content

Commit d7f1491

Browse files
committed
fix non-attached annotations for newtype branches
1 parent 418d632 commit d7f1491

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

ql/ql/src/codeql_ql/ast/Ast.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,8 @@ class NewTypeBranch extends TNewTypeBranch, Predicate, TypeDeclaration {
983983

984984
override NewTypeBranchType getReturnType() { result.getDeclaration() = this }
985985

986+
override Annotation getAnAnnotation() { toQL(this).getAFieldOrChild() = toQL(result) }
987+
986988
override Type getParameterType(int i) { result = this.getField(i).getType() }
987989

988990
override int getArity() { result = count(this.getField(_)) }
@@ -2397,6 +2399,8 @@ private class AnnotationArg extends TAnnotationArg, AstNode {
23972399
}
23982400

23992401
override string toString() { result = this.getValue() }
2402+
2403+
override string getAPrimaryQlClass() { result = "AnnotationArg" }
24002404
}
24012405

24022406
private class NoInlineArg extends AnnotationArg {

ql/ql/test/printAst/Foo.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ predicate calls(Foo f) {
2525
or
2626
true = false
2727
}
28+
29+
newtype TPathNode =
30+
pragma[assume_small_delta]
31+
TPathNodeMid()

ql/ql/test/printAst/printAst.expected

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
nodes
22
| Foo.qll:1:1:1:17 | Import | semmle.label | [Import] Import |
33
| Foo.qll:1:1:1:17 | Import | semmle.order | 1 |
4-
| Foo.qll:1:1:27:2 | TopLevel | semmle.label | [TopLevel] TopLevel |
5-
| Foo.qll:1:1:27:2 | TopLevel | semmle.order | 1 |
4+
| Foo.qll:1:1:31:17 | TopLevel | semmle.label | [TopLevel] TopLevel |
5+
| Foo.qll:1:1:31:17 | TopLevel | semmle.order | 1 |
66
| Foo.qll:1:8:1:17 | javascript | semmle.label | [ModuleExpr] javascript |
77
| Foo.qll:1:8:1:17 | javascript | semmle.order | 3 |
88
| Foo.qll:3:7:3:9 | Class Foo | semmle.label | [Class] Class Foo |
@@ -153,6 +153,14 @@ nodes
153153
| Foo.qll:26:3:26:14 | ComparisonFormula | semmle.order | 75 |
154154
| Foo.qll:26:10:26:14 | Boolean | semmle.label | [Boolean] Boolean |
155155
| Foo.qll:26:10:26:14 | Boolean | semmle.order | 77 |
156+
| Foo.qll:29:9:29:17 | NewType TPathNode | semmle.label | [NewType] NewType TPathNode |
157+
| Foo.qll:29:9:29:17 | NewType TPathNode | semmle.order | 78 |
158+
| Foo.qll:30:3:30:28 | annotation | semmle.label | [Annotation] annotation |
159+
| Foo.qll:30:3:30:28 | annotation | semmle.order | 79 |
160+
| Foo.qll:30:10:30:27 | assume_small_delta | semmle.label | [AnnotationArg] assume_small_delta |
161+
| Foo.qll:30:10:30:27 | assume_small_delta | semmle.order | 80 |
162+
| Foo.qll:31:3:31:14 | NewTypeBranch TPathNodeMid | semmle.label | [NewTypeBranch] NewTypeBranch TPathNodeMid |
163+
| Foo.qll:31:3:31:14 | NewTypeBranch TPathNodeMid | semmle.order | 81 |
156164
| file://:0:0:0:0 | abs | semmle.label | [BuiltinPredicate] abs |
157165
| file://:0:0:0:0 | abs | semmle.label | [BuiltinPredicate] abs |
158166
| file://:0:0:0:0 | acos | semmle.label | [BuiltinPredicate] acos |
@@ -235,22 +243,24 @@ nodes
235243
| file://:0:0:0:0 | trim | semmle.label | [BuiltinPredicate] trim |
236244
| file://:0:0:0:0 | ulp | semmle.label | [BuiltinPredicate] ulp |
237245
| printAst.ql:1:1:1:28 | Import | semmle.label | [Import] Import |
238-
| printAst.ql:1:1:1:28 | Import | semmle.order | 78 |
246+
| printAst.ql:1:1:1:28 | Import | semmle.order | 82 |
239247
| printAst.ql:1:1:1:29 | TopLevel | semmle.label | [TopLevel] TopLevel |
240-
| printAst.ql:1:1:1:29 | TopLevel | semmle.order | 78 |
248+
| printAst.ql:1:1:1:29 | TopLevel | semmle.order | 82 |
241249
| printAst.ql:1:18:1:28 | printAstAst | semmle.label | [ModuleExpr] printAstAst |
242-
| printAst.ql:1:18:1:28 | printAstAst | semmle.order | 80 |
250+
| printAst.ql:1:18:1:28 | printAstAst | semmle.order | 84 |
243251
edges
244252
| Foo.qll:1:1:1:17 | Import | Foo.qll:1:8:1:17 | javascript | semmle.label | getModuleExpr() |
245253
| Foo.qll:1:1:1:17 | Import | Foo.qll:1:8:1:17 | javascript | semmle.order | 3 |
246-
| Foo.qll:1:1:27:2 | TopLevel | Foo.qll:1:1:1:17 | Import | semmle.label | getAnImport() |
247-
| Foo.qll:1:1:27:2 | TopLevel | Foo.qll:1:1:1:17 | Import | semmle.order | 1 |
248-
| Foo.qll:1:1:27:2 | TopLevel | Foo.qll:3:7:3:9 | Class Foo | semmle.label | getAClass() |
249-
| Foo.qll:1:1:27:2 | TopLevel | Foo.qll:3:7:3:9 | Class Foo | semmle.order | 4 |
250-
| Foo.qll:1:1:27:2 | TopLevel | Foo.qll:9:17:9:19 | ClasslessPredicate foo | semmle.label | getAPredicate() |
251-
| Foo.qll:1:1:27:2 | TopLevel | Foo.qll:9:17:9:19 | ClasslessPredicate foo | semmle.order | 16 |
252-
| Foo.qll:1:1:27:2 | TopLevel | Foo.qll:13:11:13:15 | ClasslessPredicate calls | semmle.label | getAPredicate() |
253-
| Foo.qll:1:1:27:2 | TopLevel | Foo.qll:13:11:13:15 | ClasslessPredicate calls | semmle.order | 32 |
254+
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:1:1:1:17 | Import | semmle.label | getAnImport() |
255+
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:1:1:1:17 | Import | semmle.order | 1 |
256+
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:3:7:3:9 | Class Foo | semmle.label | getAClass() |
257+
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:3:7:3:9 | Class Foo | semmle.order | 4 |
258+
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:9:17:9:19 | ClasslessPredicate foo | semmle.label | getAPredicate() |
259+
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:9:17:9:19 | ClasslessPredicate foo | semmle.order | 16 |
260+
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:13:11:13:15 | ClasslessPredicate calls | semmle.label | getAPredicate() |
261+
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:13:11:13:15 | ClasslessPredicate calls | semmle.order | 32 |
262+
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:29:9:29:17 | NewType TPathNode | semmle.label | getANewType() |
263+
| Foo.qll:1:1:31:17 | TopLevel | Foo.qll:29:9:29:17 | NewType TPathNode | semmle.order | 78 |
254264
| Foo.qll:3:7:3:9 | Class Foo | Foo.qll:3:19:3:22 | TypeExpr | semmle.label | getASuperType() |
255265
| Foo.qll:3:7:3:9 | Class Foo | Foo.qll:3:19:3:22 | TypeExpr | semmle.order | 5 |
256266
| Foo.qll:3:7:3:9 | Class Foo | Foo.qll:4:3:4:17 | CharPred Foo | semmle.label | getCharPred() |
@@ -393,9 +403,15 @@ edges
393403
| Foo.qll:26:3:26:14 | ComparisonFormula | Foo.qll:26:3:26:6 | Boolean | semmle.order | 75 |
394404
| Foo.qll:26:3:26:14 | ComparisonFormula | Foo.qll:26:10:26:14 | Boolean | semmle.label | getRightOperand() |
395405
| Foo.qll:26:3:26:14 | ComparisonFormula | Foo.qll:26:10:26:14 | Boolean | semmle.order | 77 |
406+
| Foo.qll:29:9:29:17 | NewType TPathNode | Foo.qll:31:3:31:14 | NewTypeBranch TPathNodeMid | semmle.label | getABranch() |
407+
| Foo.qll:29:9:29:17 | NewType TPathNode | Foo.qll:31:3:31:14 | NewTypeBranch TPathNodeMid | semmle.order | 81 |
408+
| Foo.qll:30:3:30:28 | annotation | Foo.qll:30:10:30:27 | assume_small_delta | semmle.label | getArgs(_) |
409+
| Foo.qll:30:3:30:28 | annotation | Foo.qll:30:10:30:27 | assume_small_delta | semmle.order | 80 |
410+
| Foo.qll:31:3:31:14 | NewTypeBranch TPathNodeMid | Foo.qll:30:3:30:28 | annotation | semmle.label | getAnAnnotation() |
411+
| Foo.qll:31:3:31:14 | NewTypeBranch TPathNodeMid | Foo.qll:30:3:30:28 | annotation | semmle.order | 79 |
396412
| printAst.ql:1:1:1:28 | Import | printAst.ql:1:18:1:28 | printAstAst | semmle.label | getModuleExpr() |
397-
| printAst.ql:1:1:1:28 | Import | printAst.ql:1:18:1:28 | printAstAst | semmle.order | 80 |
413+
| printAst.ql:1:1:1:28 | Import | printAst.ql:1:18:1:28 | printAstAst | semmle.order | 84 |
398414
| printAst.ql:1:1:1:29 | TopLevel | printAst.ql:1:1:1:28 | Import | semmle.label | getAnImport() |
399-
| printAst.ql:1:1:1:29 | TopLevel | printAst.ql:1:1:1:28 | Import | semmle.order | 78 |
415+
| printAst.ql:1:1:1:29 | TopLevel | printAst.ql:1:1:1:28 | Import | semmle.order | 82 |
400416
graphProperties
401417
| semmle.graphKind | tree |

0 commit comments

Comments
 (0)