Skip to content

Commit 993ce4b

Browse files
owen-mcCopilot
andcommitted
Model optional overlay annotations
Preserve the anonymous question-mark suffix in annotation arguments so overlay[caller?] and overlay[local?] use their dedicated AST classes. Add regression coverage for optional and non-optional overlay annotations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d8e7e2e commit 993ce4b

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,13 +2530,25 @@ private class AnnotationArg extends TAnnotationArg, AstNode {
25302530

25312531
AnnotationArg() { this = TAnnotationArg(arg) }
25322532

2533+
private predicate isOptional() {
2534+
arg.getLocation().getEndLine() != arg.getChild().getLocation().getEndLine()
2535+
or
2536+
arg.getLocation().getEndColumn() != arg.getChild().getLocation().getEndColumn()
2537+
}
2538+
25332539
/** Gets the name of this argument. */
25342540
string getValue() {
2535-
result =
2536-
[
2537-
arg.getChild().(QL::SimpleId).getValue(), arg.getChild().(QL::Result).getValue(),
2538-
arg.getChild().(QL::This).getValue()
2539-
]
2541+
exists(string value |
2542+
value =
2543+
[
2544+
arg.getChild().(QL::SimpleId).getValue(), arg.getChild().(QL::Result).getValue(),
2545+
arg.getChild().(QL::This).getValue()
2546+
]
2547+
|
2548+
result = value and not this.isOptional()
2549+
or
2550+
result = value + "?" and this.isOptional()
2551+
)
25402552
}
25412553

25422554
override string toString() { result = this.getValue() }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| Test.qll:1:1:1:15 | overlay[local?] | overlay[local?] |
2+
| Test.qll:9:1:9:15 | overlay[caller] | overlay[caller] |
3+
| Test.qll:16:1:16:16 | overlay[caller?] | overlay[caller?] |
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import ql
2+
3+
from Annotation a
4+
where
5+
a instanceof OverlayCaller or
6+
a instanceof OverlayCallerQ or
7+
a instanceof OverlayLocal or
8+
a instanceof OverlayLocalQ
9+
select a, a.toString()

0 commit comments

Comments
 (0)