Skip to content

Commit 440547c

Browse files
authored
Merge branch 'main' into post-release-prep/codeql-cli-2.10.2
2 parents 8fb85a9 + e23a45d commit 440547c

File tree

2 files changed

+39
-27
lines changed

2 files changed

+39
-27
lines changed

ruby/ql/lib/codeql/ruby/printAst.qll

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
private import AST
1010
private import codeql.ruby.Regexp as RE
1111
private import codeql.ruby.ast.internal.Synthesis
12+
private import ast.internal.AST
1213

1314
/**
1415
* The query can extend this class to control which nodes are printed.
@@ -35,6 +36,8 @@ private predicate shouldPrintAstEdge(AstNode parent, string edgeName, AstNode ch
3536
any(PrintAstConfiguration config).shouldPrintAstEdge(parent, edgeName, child)
3637
}
3738

39+
private int nonSynthIndex() { result = min([-1, any(int i | exists(getSynthChild(_, i)))]) - 1 }
40+
3841
newtype TPrintNode =
3942
TPrintRegularAstNode(AstNode n) { shouldPrintNode(n) } or
4043
TPrintRegExpNode(RE::RegExpTerm term) {
@@ -112,13 +115,22 @@ class PrintRegularAstNode extends PrintAstNode, TPrintRegularAstNode {
112115
)
113116
}
114117

118+
private int getSynthAstNodeIndex() {
119+
not astNode.isSynthesized() and result = nonSynthIndex()
120+
or
121+
astNode = getSynthChild(astNode.getParent(), result)
122+
}
123+
115124
override int getOrder() {
116125
this =
117126
rank[result](PrintRegularAstNode p, Location l, File f |
118127
l = p.getLocation() and
119128
f = l.getFile()
120129
|
121-
p order by f.getBaseName(), f.getAbsolutePath(), l.getStartLine(), l.getStartColumn()
130+
p
131+
order by
132+
f.getBaseName(), f.getAbsolutePath(), l.getStartLine(), l.getStartColumn(),
133+
l.getEndLine(), l.getEndColumn(), p.getSynthAstNodeIndex()
122134
)
123135
}
124136

ruby/ql/test/library-tests/ast/AstDesugar.expected

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,23 @@ calls/calls.rb:
8686
# 316| getStmt: [SetterMethodCall] call to foo=
8787
# 316| getReceiver: [SelfVariableAccess] self
8888
# 316| getArgument: [AssignExpr] ... = ...
89+
# 316| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
8990
# 316| getAnOperand/getRightOperand: [MethodCall] call to []
90-
# 316| getArgument: [IntegerLiteral] 0
9191
# 316| getReceiver: [LocalVariableAccess] __synth__0
92-
# 316| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
92+
# 316| getArgument: [IntegerLiteral] 0
9393
# 316| getStmt: [LocalVariableAccess] __synth__0__1
9494
# 316| getStmt: [AssignExpr] ... = ...
9595
# 316| getAnOperand/getLeftOperand: [MethodCall] call to bar
9696
# 316| getDesugared: [StmtSequence] ...
9797
# 316| getStmt: [SetterMethodCall] call to bar=
9898
# 316| getReceiver: [SelfVariableAccess] self
9999
# 316| getArgument: [AssignExpr] ... = ...
100+
# 316| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
100101
# 316| getAnOperand/getRightOperand: [MethodCall] call to []
102+
# 316| getReceiver: [LocalVariableAccess] __synth__0
101103
# 316| getArgument: [RangeLiteral] _ .. _
102104
# 316| getBegin: [IntegerLiteral] 1
103105
# 316| getEnd: [IntegerLiteral] -2
104-
# 316| getReceiver: [LocalVariableAccess] __synth__0
105-
# 316| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
106106
# 316| getStmt: [LocalVariableAccess] __synth__0__1
107107
# 316| getStmt: [AssignExpr] ... = ...
108108
# 316| getAnOperand/getLeftOperand: [ElementReference] ...[...]
@@ -111,13 +111,14 @@ calls/calls.rb:
111111
# 316| getReceiver: [MethodCall] call to foo
112112
# 316| getReceiver: [SelfVariableAccess] self
113113
# 316| getArgument: [AssignExpr] ... = ...
114+
# 316| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
114115
# 316| getAnOperand/getRightOperand: [MethodCall] call to []
115-
# 316| getArgument: [IntegerLiteral] -1
116116
# 316| getReceiver: [LocalVariableAccess] __synth__0
117-
# 316| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
117+
# 316| getArgument: [IntegerLiteral] -1
118118
# 316| getArgument: [IntegerLiteral] 4
119119
# 316| getStmt: [LocalVariableAccess] __synth__0__1
120120
# 316| getStmt: [AssignExpr] ... = ...
121+
# 316| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0
121122
# 316| getAnOperand/getRightOperand: [SplatExpr] * ...
122123
# 316| getAnOperand/getOperand/getReceiver: [ArrayLiteral] [...]
123124
# 316| getDesugared: [MethodCall] call to []
@@ -126,38 +127,37 @@ calls/calls.rb:
126127
# 316| getArgument: [IntegerLiteral] 2
127128
# 316| getArgument: [IntegerLiteral] 3
128129
# 316| getArgument: [IntegerLiteral] 4
129-
# 316| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0
130130
# 317| [AssignExpr] ... = ...
131131
# 317| getDesugared: [StmtSequence] ...
132132
# 317| getStmt: [AssignExpr] ... = ...
133133
# 317| getAnOperand/getLeftOperand: [LocalVariableAccess] a
134134
# 317| getAnOperand/getRightOperand: [MethodCall] call to []
135-
# 317| getArgument: [IntegerLiteral] 0
136135
# 317| getReceiver: [LocalVariableAccess] __synth__0
136+
# 317| getArgument: [IntegerLiteral] 0
137137
# 317| getStmt: [AssignExpr] ... = ...
138138
# 317| getAnOperand/getLeftOperand: [ElementReference] ...[...]
139139
# 317| getDesugared: [StmtSequence] ...
140140
# 317| getStmt: [SetterMethodCall] call to []=
141141
# 317| getReceiver: [MethodCall] call to foo
142142
# 317| getReceiver: [SelfVariableAccess] self
143143
# 317| getArgument: [AssignExpr] ... = ...
144+
# 317| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
144145
# 317| getAnOperand/getRightOperand: [MethodCall] call to []
146+
# 317| getReceiver: [LocalVariableAccess] __synth__0
145147
# 317| getArgument: [RangeLiteral] _ .. _
146148
# 317| getBegin: [IntegerLiteral] 1
147149
# 317| getEnd: [IntegerLiteral] -1
148-
# 317| getReceiver: [LocalVariableAccess] __synth__0
149-
# 317| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
150150
# 317| getArgument: [IntegerLiteral] 5
151151
# 317| getStmt: [LocalVariableAccess] __synth__0__1
152152
# 317| getStmt: [AssignExpr] ... = ...
153+
# 317| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0
153154
# 317| getAnOperand/getRightOperand: [SplatExpr] * ...
154155
# 317| getAnOperand/getOperand/getReceiver: [ArrayLiteral] [...]
155156
# 317| getDesugared: [MethodCall] call to []
156157
# 317| getReceiver: [ConstantReadAccess] Array
157158
# 317| getArgument: [IntegerLiteral] 1
158159
# 317| getArgument: [IntegerLiteral] 2
159160
# 317| getArgument: [IntegerLiteral] 3
160-
# 317| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0
161161
# 318| [AssignAddExpr] ... += ...
162162
# 318| getDesugared: [StmtSequence] ...
163163
# 318| getStmt: [AssignExpr] ... = ...
@@ -167,11 +167,11 @@ calls/calls.rb:
167167
# 318| getReceiver: [LocalVariableAccess] __synth__0
168168
# 318| getArgument: [LocalVariableAccess] __synth__1
169169
# 318| getStmt: [AssignExpr] ... = ...
170+
# 318| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__1
170171
# 318| getAnOperand/getRightOperand: [AddExpr] ... + ...
171172
# 318| getAnOperand/getLeftOperand/getReceiver: [MethodCall] call to count
172173
# 318| getReceiver: [LocalVariableAccess] __synth__0
173174
# 318| getAnOperand/getArgument/getRightOperand: [IntegerLiteral] 1
174-
# 318| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__1
175175
# 318| getStmt: [LocalVariableAccess] __synth__1
176176
# 319| [AssignAddExpr] ... += ...
177177
# 319| getDesugared: [StmtSequence] ...
@@ -187,12 +187,12 @@ calls/calls.rb:
187187
# 319| getAnOperand/getRightOperand: [IntegerLiteral] 0
188188
# 319| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__1
189189
# 319| getStmt: [AssignExpr] ... = ...
190+
# 319| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__2
190191
# 319| getAnOperand/getRightOperand: [AddExpr] ... + ...
191192
# 319| getAnOperand/getLeftOperand/getReceiver: [MethodCall] call to []
192193
# 319| getReceiver: [LocalVariableAccess] __synth__0
193194
# 319| getArgument: [LocalVariableAccess] __synth__1
194195
# 319| getAnOperand/getArgument/getRightOperand: [IntegerLiteral] 1
195-
# 319| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__2
196196
# 319| getStmt: [LocalVariableAccess] __synth__2
197197
# 320| [AssignMulExpr] ... *= ...
198198
# 320| getDesugared: [StmtSequence] ...
@@ -223,14 +223,14 @@ calls/calls.rb:
223223
# 320| getAnOperand/getArgument/getRightOperand: [IntegerLiteral] 1
224224
# 320| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__3
225225
# 320| getStmt: [AssignExpr] ... = ...
226+
# 320| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__4
226227
# 320| getAnOperand/getRightOperand: [MulExpr] ... * ...
227228
# 320| getAnOperand/getLeftOperand/getReceiver: [MethodCall] call to []
228229
# 320| getReceiver: [LocalVariableAccess] __synth__0
229230
# 320| getArgument: [LocalVariableAccess] __synth__1
230231
# 320| getArgument: [LocalVariableAccess] __synth__2
231232
# 320| getArgument: [LocalVariableAccess] __synth__3
232233
# 320| getAnOperand/getArgument/getRightOperand: [IntegerLiteral] 2
233-
# 320| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__4
234234
# 320| getStmt: [LocalVariableAccess] __synth__4
235235
# 340| [ForExpr] for ... in ...
236236
# 340| getDesugared: [MethodCall] call to each
@@ -240,24 +240,24 @@ calls/calls.rb:
240240
# 340| getStmt: [AssignExpr] ... = ...
241241
# 340| getDesugared: [StmtSequence] ...
242242
# 340| getStmt: [AssignExpr] ... = ...
243+
# 340| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
243244
# 340| getAnOperand/getRightOperand: [SplatExpr] * ...
244245
# 340| getAnOperand/getOperand/getReceiver: [LocalVariableAccess] __synth__0__1
245-
# 340| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
246246
# 340| getStmt: [AssignExpr] ... = ...
247247
# 340| getAnOperand/getLeftOperand: [LocalVariableAccess] x
248248
# 340| getAnOperand/getRightOperand: [MethodCall] call to []
249-
# 340| getArgument: [IntegerLiteral] 0
250249
# 340| getReceiver: [LocalVariableAccess] __synth__0__1
250+
# 340| getArgument: [IntegerLiteral] 0
251251
# 340| getStmt: [AssignExpr] ... = ...
252252
# 340| getAnOperand/getLeftOperand: [LocalVariableAccess] y
253253
# 340| getAnOperand/getRightOperand: [MethodCall] call to []
254-
# 340| getArgument: [IntegerLiteral] 1
255254
# 340| getReceiver: [LocalVariableAccess] __synth__0__1
255+
# 340| getArgument: [IntegerLiteral] 1
256256
# 340| getStmt: [AssignExpr] ... = ...
257257
# 340| getAnOperand/getLeftOperand: [LocalVariableAccess] z
258258
# 340| getAnOperand/getRightOperand: [MethodCall] call to []
259-
# 340| getArgument: [IntegerLiteral] 2
260259
# 340| getReceiver: [LocalVariableAccess] __synth__0__1
260+
# 340| getArgument: [IntegerLiteral] 2
261261
# 340| getAnOperand/getLeftOperand: [DestructuredLhsExpr] (..., ...)
262262
# 341| getStmt: [MethodCall] call to foo
263263
# 341| getReceiver: [SelfVariableAccess] self
@@ -286,9 +286,9 @@ calls/calls.rb:
286286
# 362| getReceiver: [SelfVariableAccess] self
287287
# 362| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
288288
# 362| getStmt: [IfExpr] if ...
289+
# 362| getBranch/getThen: [NilLiteral] nil
289290
# 362| getBranch/getElse: [MethodCall] call to empty?
290291
# 362| getReceiver: [LocalVariableAccess] __synth__0__1
291-
# 362| getBranch/getThen: [NilLiteral] nil
292292
# 362| getCondition: [MethodCall] call to ==
293293
# 362| getArgument: [LocalVariableAccess] __synth__0__1
294294
# 362| getReceiver: [NilLiteral] nil
@@ -299,6 +299,7 @@ calls/calls.rb:
299299
# 364| getReceiver: [SelfVariableAccess] self
300300
# 364| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
301301
# 364| getStmt: [IfExpr] if ...
302+
# 364| getBranch/getThen: [NilLiteral] nil
302303
# 364| getBranch/getElse: [MethodCall] call to bar
303304
# 364| getReceiver: [LocalVariableAccess] __synth__0__1
304305
# 364| getArgument: [IntegerLiteral] 1
@@ -307,7 +308,6 @@ calls/calls.rb:
307308
# 364| getParameter: [SimpleParameter] x
308309
# 364| getDefiningAccess: [LocalVariableAccess] x
309310
# 364| getStmt: [LocalVariableAccess] x
310-
# 364| getBranch/getThen: [NilLiteral] nil
311311
# 364| getCondition: [MethodCall] call to ==
312312
# 364| getArgument: [LocalVariableAccess] __synth__0__1
313313
# 364| getReceiver: [NilLiteral] nil
@@ -608,19 +608,19 @@ control/loops.rb:
608608
# 22| getStmt: [AssignExpr] ... = ...
609609
# 22| getDesugared: [StmtSequence] ...
610610
# 22| getStmt: [AssignExpr] ... = ...
611+
# 22| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
611612
# 22| getAnOperand/getRightOperand: [SplatExpr] * ...
612613
# 22| getAnOperand/getOperand/getReceiver: [LocalVariableAccess] __synth__0__1
613-
# 22| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
614614
# 22| getStmt: [AssignExpr] ... = ...
615615
# 22| getAnOperand/getLeftOperand: [LocalVariableAccess] key
616616
# 22| getAnOperand/getRightOperand: [MethodCall] call to []
617-
# 22| getArgument: [IntegerLiteral] 0
618617
# 22| getReceiver: [LocalVariableAccess] __synth__0__1
618+
# 22| getArgument: [IntegerLiteral] 0
619619
# 22| getStmt: [AssignExpr] ... = ...
620620
# 22| getAnOperand/getLeftOperand: [LocalVariableAccess] value
621621
# 22| getAnOperand/getRightOperand: [MethodCall] call to []
622-
# 22| getArgument: [IntegerLiteral] 1
623622
# 22| getReceiver: [LocalVariableAccess] __synth__0__1
623+
# 22| getArgument: [IntegerLiteral] 1
624624
# 22| getAnOperand/getLeftOperand: [DestructuredLhsExpr] (..., ...)
625625
# 23| getStmt: [AssignAddExpr] ... += ...
626626
# 23| getDesugared: [AssignExpr] ... = ...
@@ -653,19 +653,19 @@ control/loops.rb:
653653
# 28| getStmt: [AssignExpr] ... = ...
654654
# 28| getDesugared: [StmtSequence] ...
655655
# 28| getStmt: [AssignExpr] ... = ...
656+
# 28| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
656657
# 28| getAnOperand/getRightOperand: [SplatExpr] * ...
657658
# 28| getAnOperand/getOperand/getReceiver: [LocalVariableAccess] __synth__0__1
658-
# 28| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
659659
# 28| getStmt: [AssignExpr] ... = ...
660660
# 28| getAnOperand/getLeftOperand: [LocalVariableAccess] key
661661
# 28| getAnOperand/getRightOperand: [MethodCall] call to []
662-
# 28| getArgument: [IntegerLiteral] 0
663662
# 28| getReceiver: [LocalVariableAccess] __synth__0__1
663+
# 28| getArgument: [IntegerLiteral] 0
664664
# 28| getStmt: [AssignExpr] ... = ...
665665
# 28| getAnOperand/getLeftOperand: [LocalVariableAccess] value
666666
# 28| getAnOperand/getRightOperand: [MethodCall] call to []
667-
# 28| getArgument: [IntegerLiteral] 1
668667
# 28| getReceiver: [LocalVariableAccess] __synth__0__1
668+
# 28| getArgument: [IntegerLiteral] 1
669669
# 28| getAnOperand/getLeftOperand: [DestructuredLhsExpr] (..., ...)
670670
# 29| getStmt: [AssignAddExpr] ... += ...
671671
# 29| getDesugared: [AssignExpr] ... = ...

0 commit comments

Comments
 (0)