forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathCfgNodes.qll
More file actions
1566 lines (1080 loc) · 48.1 KB
/
CfgNodes.qll
File metadata and controls
1566 lines (1080 loc) · 48.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** Provides classes representing nodes in a control flow graph. */
private import powershell
private import BasicBlocks
private import ControlFlowGraph
private import internal.ControlFlowGraphImpl as CfgImpl
/** An entry node for a given scope. */
class EntryNode extends CfgNode, CfgImpl::EntryNode {
override string getAPrimaryQlClass() { result = "EntryNode" }
final override EntryBasicBlock getBasicBlock() { result = super.getBasicBlock() }
}
/** An exit node for a given scope, annotated with the type of exit. */
class AnnotatedExitNode extends CfgNode, CfgImpl::AnnotatedExitNode {
override string getAPrimaryQlClass() { result = "AnnotatedExitNode" }
final override AnnotatedExitBasicBlock getBasicBlock() { result = super.getBasicBlock() }
}
/** An exit node for a given scope. */
class ExitNode extends CfgNode, CfgImpl::ExitNode {
override string getAPrimaryQlClass() { result = "ExitNode" }
}
/**
* A node for an AST node.
*
* Each AST node maps to zero or more `AstCfgNode`s: zero when the node is unreachable
* (dead) code or not important for control flow, and multiple when there are different
* splits for the AST node.
*/
class AstCfgNode extends CfgNode, CfgImpl::AstCfgNode {
/** Gets the name of the primary QL class for this node. */
override string getAPrimaryQlClass() { result = "AstCfgNode" }
}
/** A control-flow node that wraps an AST expression. */
class ExprCfgNode extends AstCfgNode {
override string getAPrimaryQlClass() { result = "ExprCfgNode" }
Expr e;
ExprCfgNode() { e = this.getAstNode() }
/** Gets the underlying expression. */
Expr getExpr() { result = e }
final ConstantValue getValue() { result = e.getValue() }
}
/** A control-flow node that wraps an AST statement. */
class StmtCfgNode extends AstCfgNode {
override string getAPrimaryQlClass() { result = "StmtCfgNode" }
Stmt s;
StmtCfgNode() { s = this.getAstNode() }
/** Gets the underlying expression. */
Stmt getStmt() { result = s }
}
/**
* A class for mapping parent-child AST nodes to parent-child CFG nodes.
*/
abstract private class ChildMapping extends Ast {
/**
* Holds if `child` is a (possibly nested) child of this expression
* for which we would like to find a matching CFG child.
*/
abstract predicate relevantChild(Ast child);
/**
* Holds if `child` appears before its parent in the control-flow graph.
* This always holds for expressions, and _almost_ never for statements.
*/
abstract predicate precedesParent(Ast child);
pragma[nomagic]
final predicate reachesBasicBlock(Ast child, CfgNode cfn, BasicBlock bb) {
this.relevantChild(child) and
cfn.getAstNode() = this and
bb.getANode() = cfn
or
exists(BasicBlock mid |
this.reachesBasicBlock(child, cfn, mid) and
not mid.getANode().getAstNode() = child
|
if this.precedesParent(child) then bb = mid.getAPredecessor() else bb = mid.getASuccessor()
)
}
/**
* Holds if there is a control-flow path from `cfn` to `cfnChild`, where `cfn`
* is a control-flow node for this expression, and `cfnChild` is a control-flow
* node for `child`.
*
* The path never escapes the syntactic scope of this expression.
*/
cached
predicate hasCfgChild(Ast child, CfgNode cfn, CfgNode cfnChild) {
this.reachesBasicBlock(child, cfn, cfnChild.getBasicBlock()) and
cfnChild.getAstNode() = child
}
}
/**
* A class for mapping parent-child AST nodes to parent-child CFG nodes.
*/
abstract private class ExprChildMapping extends Expr, ChildMapping {
final override predicate precedesParent(Ast child) { this.relevantChild(child) }
}
/**
* A class for mapping parent-child AST nodes to parent-child CFG nodes.
*/
abstract private class NonExprChildMapping extends ChildMapping {
NonExprChildMapping() { not this instanceof Expr }
override predicate precedesParent(Ast child) { none() } // this is not final because it is overriden by ForEachStmt
}
private class AttributeBaseChildMapping extends NonExprChildMapping, AttributeBase {
override predicate relevantChild(Ast child) { none() }
}
class AttributeBaseCfgNode extends AstCfgNode {
AttributeBaseCfgNode() { attr = this.getAstNode() }
override string getAPrimaryQlClass() { result = "AttributeBaseCfgNode" }
AttributeBaseChildMapping attr;
}
private class AttributeChildMapping extends AttributeBaseChildMapping, Attribute {
override predicate relevantChild(Ast child) {
this.relevantChild(child)
or
child = this.getANamedArgument()
or
child = this.getAPositionalArgument()
}
}
private class NamedAttributeArgumentChildMapping extends NonExprChildMapping, NamedAttributeArgument
{
override predicate relevantChild(Ast child) { child = this.getValue() }
}
class NamedAttributeArgumentCfgNode extends AstCfgNode {
NamedAttributeArgumentCfgNode() { attr = this.getAstNode() }
override string getAPrimaryQlClass() { result = "NamedAttributeArgumentCfgNode" }
NamedAttributeArgumentChildMapping attr;
NamedAttributeArgument getAttr() { result = attr }
ExprCfgNode getValue() { attr.hasCfgChild(attr.getValue(), this, result) }
string getName() { result = attr.getName() }
}
class AttributeCfgNode extends AttributeBaseCfgNode {
override string getAPrimaryQlClass() { result = "AttributeCfgNode" }
override AttributeChildMapping attr;
NamedAttributeArgumentCfgNode getNamedArgument(int i) {
attr.hasCfgChild(attr.getNamedArgument(i), this, result)
}
ExprCfgNode getPositionalArgument(int i) {
attr.hasCfgChild(attr.getPositionalArgument(i), this, result)
}
string getLowerCaseName() { result = attr.getLowerCaseName() }
bindingset[result]
string getAName() { result = attr.getAName() }
}
private class ScriptBlockChildMapping extends NonExprChildMapping, ScriptBlock {
override predicate relevantChild(Ast child) {
child = this.getProcessBlock()
or
child = this.getBeginBlock()
or
child = this.getEndBlock()
or
child = this.getDynamicBlock()
or
child = this.getAnAttribute()
or
child = this.getAParameter()
}
}
private class ParameterChildMapping extends NonExprChildMapping, Parameter {
override predicate relevantChild(Ast child) {
child = this.getAnAttribute() or child = this.getDefaultValue()
}
}
class ParameterCfgNode extends AstCfgNode {
ParameterCfgNode() { param = this.getAstNode() }
override string getAPrimaryQlClass() { result = "ParameterCfgNode" }
ParameterChildMapping param;
Parameter getParameter() { result = param }
ExprCfgNode getDefaultValue() { param.hasCfgChild(param.getDefaultValue(), this, result) }
AttributeCfgNode getAttribute(int i) { param.hasCfgChild(param.getAttribute(i), this, result) }
AttributeCfgNode getAnAttribute() { result = this.getAttribute(_) }
}
class ScriptBlockCfgNode extends AstCfgNode {
ScriptBlockCfgNode() { block = this.getAstNode() }
override string getAPrimaryQlClass() { result = "ScriptBlockCfgNode" }
ScriptBlockChildMapping block;
ScriptBlock getBlock() { result = block }
ProcessBlockCfgNode getProcessBlock() { block.hasCfgChild(block.getProcessBlock(), this, result) }
NamedBlockCfgNode getBeginBlock() { block.hasCfgChild(block.getBeginBlock(), this, result) }
NamedBlockCfgNode getEndBlock() { block.hasCfgChild(block.getEndBlock(), this, result) }
NamedBlockCfgNode getDynamicBlock() { block.hasCfgChild(block.getDynamicBlock(), this, result) }
AttributeCfgNode getAttribute(int i) { block.hasCfgChild(block.getAttribute(i), this, result) }
AttributeCfgNode getAnAttribute() { result = this.getAttribute(_) }
ParameterCfgNode getParameter(int i) { block.hasCfgChild(block.getParameter(i), this, result) }
ParameterCfgNode getAParameter() { result = this.getParameter(_) }
}
private class NamedBlockChildMapping extends NonExprChildMapping, NamedBlock {
override predicate relevantChild(Ast child) {
child = this.getAStmt() or child = this.getATrapStmt()
}
}
class NamedBlockCfgNode extends AstCfgNode {
NamedBlockCfgNode() { block = this.getAstNode() }
override string getAPrimaryQlClass() { result = "NamedBlockCfgNode" }
NamedBlockChildMapping block;
NamedBlock getBlock() { result = block }
StmtCfgNode getStmt(int i) { block.hasCfgChild(block.getStmt(i), this, result) }
StmtCfgNode getAStmt() { result = this.getStmt(_) }
StmtNodes::TrapStmtCfgNode getTrapStmt(int i) {
block.hasCfgChild(block.getTrapStmt(i), this, result)
}
StmtNodes::TrapStmtCfgNode getATrapStmt() { result = this.getTrapStmt(_) }
}
private class ProcessBlockChildMapping extends NamedBlockChildMapping, ProcessBlock {
override predicate relevantChild(Ast child) {
super.relevantChild(child)
or
child = super.getPipelineParameterAccess()
or
child = super.getAPipelineByPropertyNameParameterAccess()
}
}
class ProcessBlockCfgNode extends NamedBlockCfgNode {
override string getAPrimaryQlClass() { result = "ProcessBlockCfgNode" }
override ProcessBlockChildMapping block;
override ProcessBlock getBlock() { result = block }
ScriptBlockCfgNode getScriptBlock() { result.getProcessBlock() = this }
PipelineParameter getPipelineParameter() {
result.getScriptBlock() = this.getScriptBlock().getAstNode()
}
ExprNodes::VarReadAccessCfgNode getPipelineParameterAccess() {
block.hasCfgChild(block.getPipelineParameterAccess(), this, result)
}
PipelineIteratorVariable getPipelineIteratorVariable() {
result.getProcessBlock().getScriptBlock() = this.getScriptBlock().getAstNode()
}
PipelineByPropertyNameIteratorVariable getPipelineBypropertyNameIteratorVariable(string name) {
result.getPropertyName() = name and
result.getProcessBlock().getScriptBlock() = this.getScriptBlock().getAstNode()
}
PipelineByPropertyNameIteratorVariable getAPipelineBypropertyNameIteratorVariable() {
result = this.getPipelineBypropertyNameIteratorVariable(_)
}
ExprNodes::VarReadAccessCfgNode getPipelineByPropertyNameParameterAccess(string name) {
block.hasCfgChild(block.getPipelineByPropertyNameParameterAccess(name), this, result)
}
ExprNodes::VarReadAccessCfgNode getAPipelineByPropertyNameParameterAccess() {
result = this.getPipelineByPropertyNameParameterAccess(_)
}
}
private class CatchClauseChildMapping extends NonExprChildMapping, CatchClause {
override predicate relevantChild(Ast child) {
child = this.getBody() or child = this.getACatchType()
}
}
class CatchClauseCfgNode extends AstCfgNode {
override string getAPrimaryQlClass() { result = "CatchClauseCfgNode" }
CatchClauseChildMapping s;
CatchClause getCatchClause() { result = s }
StmtCfgNode getBody() { s.hasCfgChild(s.getBody(), this, result) }
TypeConstraint getCatchType(int i) { result = s.getCatchType(i) }
TypeConstraint getACatchType() { result = this.getCatchType(_) }
}
module ExprNodes {
private class ArrayExprChildMapping extends ExprChildMapping, ArrayExpr {
override predicate relevantChild(Ast child) {
child = this.getAnExpr()
or
child = this.getStmtBlock()
}
}
class ArrayExprCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "ArrayExprCfgNode" }
override ArrayExprChildMapping e;
override ArrayExpr getExpr() { result = e }
ExprCfgNode getExpr(int i) { e.hasCfgChild(e.getExpr(i), this, result) }
ExprCfgNode getAnExpr() { result = this.getExpr(_) }
StmtCfgNode getStmtBlock() { e.hasCfgChild(e.getStmtBlock(), this, result) }
}
private class ArrayLiteralChildMapping extends ExprChildMapping, ArrayLiteral {
override predicate relevantChild(Ast child) { child = this.getAnExpr() }
}
class ArrayLiteralCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "ArrayLiteralCfgNode" }
override ArrayLiteralChildMapping e;
override ArrayLiteral getExpr() { result = e }
ExprCfgNode getExpr(int i) { e.hasCfgChild(e.getExpr(i), this, result) }
ExprCfgNode getAnExpr() { result = this.getExpr(_) }
}
private class ParenExprChildMapping extends ExprChildMapping, ParenExpr {
override predicate relevantChild(Ast child) { child = this.getExpr() }
}
class ParenExprCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "ParenExprCfgNode" }
override ParenExprChildMapping e;
override ParenExpr getExpr() { result = e }
ExprCfgNode getSubExpr() { e.hasCfgChild(e.getExpr(), this, result) }
}
private class BinaryExprChildMapping extends ExprChildMapping, BinaryExpr {
override predicate relevantChild(Ast child) {
child = this.getLeft()
or
child = this.getRight()
}
}
class BinaryExprCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "BinaryExprCfgNode" }
override BinaryExprChildMapping e;
override BinaryExpr getExpr() { result = e }
ExprCfgNode getLeft() { e.hasCfgChild(e.getLeft(), this, result) }
ExprCfgNode getRight() { e.hasCfgChild(e.getRight(), this, result) }
}
private class UnaryExprChildMapping extends ExprChildMapping, UnaryExpr {
override predicate relevantChild(Ast child) { child = this.getOperand() }
}
class UnaryExprCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "UnaryExprCfgNode" }
override UnaryExprChildMapping e;
override UnaryExpr getExpr() { result = e }
ExprCfgNode getOperand() { e.hasCfgChild(e.getOperand(), this, result) }
}
private class ConstExprChildMapping extends ExprChildMapping, ConstExpr {
override predicate relevantChild(Ast child) { none() }
}
class ConstExprCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "ConstExprCfgNode" }
override ConstExprChildMapping e;
override ConstExpr getExpr() { result = e }
}
private class ConvertExprChildMapping extends ExprChildMapping, ConvertExpr {
override predicate relevantChild(Ast child) { child = this.getExpr() }
}
class ConvertExprCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "ConvertExprCfgNode" }
override ConvertExprChildMapping e;
override ConvertExpr getExpr() { result = e }
ExprCfgNode getSubExpr() { e.hasCfgChild(e.getExpr(), this, result) }
}
private class IndexExprChildMapping extends ExprChildMapping, IndexExpr {
override predicate relevantChild(Ast child) {
child = this.getBase()
or
child = this.getIndex()
}
}
class IndexExprCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "IndexExprCfgNode" }
override IndexExprChildMapping e;
override IndexExpr getExpr() { result = e }
ExprCfgNode getBase() { e.hasCfgChild(e.getBase(), this, result) }
ExprCfgNode getIndex() { e.hasCfgChild(e.getIndex(), this, result) }
}
private class IndexExprWriteAccessChildMapping extends IndexExprChildMapping, IndexExprWriteAccess
{
override predicate relevantChild(Ast child) {
super.relevantChild(child) or
this.isExplicitWrite(child)
}
}
class IndexExprWriteAccessCfgNode extends IndexExprCfgNode {
override IndexExprWriteAccessChildMapping e;
override string getAPrimaryQlClass() { result = "IndexExprWriteAccessCfgNode" }
override IndexExprWriteAccess getExpr() { result = e }
final StmtNodes::AssignStmtCfgNode getAssignStmt() { this.isExplicitWrite(result) }
predicate isExplicitWrite(AstCfgNode assignmentCfg) {
exists(Ast assignment |
// this.isExplicitWrite(assignment) and
e.isExplicitWrite(assignment) and
e.hasCfgChild(assignment, this, assignmentCfg)
)
}
predicate isImplicitWrite() { e.isImplicitWrite() }
}
private class IndexExprReadAccessChildMapping extends IndexExprChildMapping, IndexExprReadAccess {
override predicate relevantChild(Ast child) { super.relevantChild(child) }
}
class IndexExprReadAccessCfgNode extends IndexExprCfgNode {
override IndexExprReadAccessChildMapping e;
override string getAPrimaryQlClass() { result = "IndexExprAccessCfgNode" }
override IndexExprReadAccess getExpr() { result = e }
}
private class CallExprChildMapping extends ExprChildMapping, CallExpr {
override predicate relevantChild(Ast child) {
child = this.getQualifier()
or
child = this.getAnArgument()
or
child = this.getCallee()
}
}
class CallExprCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "CallExprCfgNode" }
override CallExprChildMapping e;
override CallExpr getExpr() { result = e }
ExprCfgNode getQualifier() { e.hasCfgChild(e.getQualifier(), this, result) }
ExprCfgNode getArgument(int i) { e.hasCfgChild(e.getArgument(i), this, result) }
ExprCfgNode getAnArgument() { result = this.getArgument(_) }
/** Gets the name that is used to select the callee. */
string getLowerCaseName() { result = e.getLowerCaseName() }
predicate hasLowerCaseName(string name) { this.getLowerCaseName() = name }
bindingset[name]
pragma[inline_late]
final predicate matchesName(string name) { this.getLowerCaseName() = name.toLowerCase() }
bindingset[result]
pragma[inline_late]
final string getAName() { result.toLowerCase() = this.getLowerCaseName() }
/** Gets the i'th positional argument to this call. */
ExprCfgNode getPositionalArgument(int i) {
e.hasCfgChild(e.getPositionalArgument(i), this, result)
}
/** Holds if an argument with name `name` is provided to this call. */
final predicate hasNamedArgument(string name) { exists(this.getNamedArgument(name)) }
/** Gets the argument to this call with the name `name`. */
ExprCfgNode getNamedArgument(string name) {
e.hasCfgChild(e.getNamedArgument(name), this, result)
}
ExprCfgNode getCallee() { e.hasCfgChild(e.getCallee(), this, result) }
ExprCfgNode getPipelineArgument() {
exists(ExprNodes::PipelineCfgNode pipeline, int i |
pipeline.getComponent(i + 1) = this and
result = pipeline.getComponent(i)
)
}
predicate isStatic() { this.getExpr().isStatic() }
}
private class ObjectCreationChildMapping extends CallExprChildMapping instanceof ObjectCreation {
override predicate relevantChild(Ast child) { child = super.getConstructedTypeExpr() }
}
class ObjectCreationCfgNode extends CallExprCfgNode {
// TODO: Also calls to Activator.CreateInstance
override string getAPrimaryQlClass() { result = "CallExprCfgNode" }
override ObjectCreationChildMapping e;
override ObjectCreation getExpr() { result = e }
string getLowerCaseConstructedTypeName() {
result = this.getExpr().getLowerCaseConstructedTypeName()
}
bindingset[result]
pragma[inline_late]
string getAConstructedTypeName() {
result.toLowerCase() = this.getLowerCaseConstructedTypeName()
}
ExprCfgNode getConstructedTypeExpr() {
e.hasCfgChild(this.getExpr().getConstructedTypeExpr(), this, result)
}
}
private class CallOperatorChildMapping extends CallExprChildMapping instanceof CallOperator {
override predicate relevantChild(Ast child) { super.relevantChild(child) }
}
class CallOperatorCfgNode extends CallExprCfgNode {
override string getAPrimaryQlClass() { result = "CallOperatorCfgNode" }
override CallOperatorChildMapping e;
override CallOperator getExpr() { result = e }
ExprCfgNode getCommand() { result = this.getCallee() }
}
private class DotSourcingOperatorChildMapping extends CallExprChildMapping instanceof DotSourcingOperator
{
override predicate relevantChild(Ast child) { super.relevantChild(child) }
}
class DotSourcingOperatorCfgNode extends CallExprCfgNode {
override string getAPrimaryQlClass() { result = "DotSourcingOperatorCfgNode" }
override DotSourcingOperatorChildMapping e;
override DotSourcingOperator getExpr() { result = e }
ExprCfgNode getCommand() { result = this.getCallee() }
}
private class ToStringCallChildmapping extends CallExprChildMapping instanceof ToStringCall {
override predicate relevantChild(Ast child) { super.relevantChild(child) }
}
class ToStringCallCfgNode extends CallExprCfgNode {
override string getAPrimaryQlClass() { result = "ToStringCallCfgNode" }
override ToStringCallChildmapping e;
override ToStringCall getExpr() { result = e }
}
private class MemberExprChildMapping extends ExprChildMapping, MemberExpr {
override predicate relevantChild(Ast child) {
child = this.getQualifier()
or
child = this.getMemberExpr()
}
}
class MemberExprCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "MemberExprCfgNode" }
override MemberExprChildMapping e;
override MemberExpr getExpr() { result = e }
ExprCfgNode getQualifier() { e.hasCfgChild(e.getQualifier(), this, result) }
ExprCfgNode getMemberExpr() { e.hasCfgChild(e.getMemberExpr(), this, result) }
string getLowerCaseMemberName() { result = e.getLowerCaseMemberName() }
bindingset[name]
pragma[inline_late]
predicate memberNameMatches(string name) { this.getLowerCaseMemberName() = name.toLowerCase() }
predicate isStatic() { e.isStatic() }
}
private class MemberExprWriteAccessChildMapping extends MemberExprChildMapping,
MemberExprWriteAccess
{
override predicate relevantChild(Ast child) {
super.relevantChild(child) or
this.isExplicitWrite(child)
}
}
class MemberExprWriteAccessCfgNode extends MemberExprCfgNode {
override MemberExprWriteAccessChildMapping e;
override string getAPrimaryQlClass() { result = "MemberExprWriteAccessCfgNode" }
override MemberExprWriteAccess getExpr() { result = e }
final StmtNodes::AssignStmtCfgNode getAssignStmt() { this.isExplicitWrite(result) }
predicate isExplicitWrite(AstCfgNode assignmentCfg) {
exists(Ast assignment |
// this.isExplicitWrite(assignment) and
e.isExplicitWrite(assignment) and
e.hasCfgChild(assignment, this, assignmentCfg)
)
}
predicate isImplicitWrite() { e.isImplicitWrite() }
}
private class MemberExprReadAccessChildMapping extends MemberExprChildMapping,
MemberExprReadAccess
{
override predicate relevantChild(Ast child) { super.relevantChild(child) }
}
class MemberExprReadAccessCfgNode extends MemberExprCfgNode {
override MemberExprReadAccessChildMapping e;
override string getAPrimaryQlClass() { result = "MemberExprReadAccessCfgNode" }
override MemberExprReadAccess getExpr() { result = e }
}
private class TypeNameExprChildMapping extends ExprChildMapping, TypeNameExpr {
override predicate relevantChild(Ast child) { none() }
}
class TypeNameExprCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "TypeExprCfgNode" }
override TypeNameExprChildMapping e;
override TypeNameExpr getExpr() { result = e }
bindingset[result]
pragma[inline_late]
string getAName() { result = e.getAName() }
string getLowerCaseName() { result = e.getLowerCaseName() }
string getNamespace() { result = e.getNamespace() }
string getPossiblyQualifiedName() { result = e.getPossiblyQualifiedName() }
predicate isQualified() { e.isQualified() }
predicate hasQualifiedName(string namespace, string typename) {
e.hasQualifiedName(namespace, typename)
}
}
private class QualifiedTypeNameExprChildMapping extends TypeNameExprChildMapping,
QualifiedTypeNameExpr
{
override predicate relevantChild(Ast child) { super.relevantChild(child) }
}
class QualifiedTypeNameExprCfgNode extends TypeNameExprCfgNode {
override QualifiedTypeNameExprChildMapping e;
override TypeNameExpr getExpr() { result = e }
override string getAPrimaryQlClass() { result = "QualifiedTypeNameExprCfgNode" }
}
private class ErrorExprChildMapping extends ExprChildMapping, ErrorExpr {
override predicate relevantChild(Ast child) { none() }
}
class ErrorExprCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "ErrorExprCfgNode" }
override ErrorExprChildMapping e;
override ErrorExpr getExpr() { result = e }
}
private class ScriptBlockExprChildMapping extends ExprChildMapping, ScriptBlockExpr {
override predicate relevantChild(Ast child) { child = this.getBody() }
}
class ScriptBlockExprCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "ScriptBlockExprCfgNode" }
override ScriptBlockExprChildMapping e;
override ScriptBlockExpr getExpr() { result = e }
ScriptBlockCfgNode getBody() { e.hasCfgChild(e.getBody(), this, result) }
}
private class StringLiteralExprChildMapping extends ExprChildMapping, StringConstExpr {
override predicate relevantChild(Ast child) { none() }
}
class StringLiteralExprCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "StringLiteralExprCfgNode" }
override StringLiteralExprChildMapping e;
override StringConstExpr getExpr() { result = e }
string getValueString() { result = e.getValueString() }
}
private class ExpandableStringExprChildMapping extends ExprChildMapping, ExpandableStringExpr {
override predicate relevantChild(Ast child) { child = this.getAnExpr() }
}
class ExpandableStringExprCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "ExpandableStringExprCfgNode" }
override ExpandableStringExprChildMapping e;
override ExpandableStringExpr getExpr() { result = e }
ExprCfgNode getExpr(int i) { e.hasCfgChild(e.getExpr(i), this, result) }
ExprCfgNode getAnExpr() { result = this.getExpr(_) }
}
class VarAccessCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "VarAccessExprCfgNode" }
override VarAccess e;
override VarAccess getExpr() { result = e }
Variable getVariable() { result = e.getVariable() }
}
private class VarWriteAccessChildMapping extends ExprChildMapping, VarWriteAccess {
override predicate relevantChild(Ast child) { this.isExplicitWrite(child) }
}
class VarWriteAccessCfgNode extends VarAccessCfgNode {
override VarWriteAccessChildMapping e;
override string getAPrimaryQlClass() { result = "VarWriteAccessCfgNode" }
override VarWriteAccess getExpr() { result = e }
final StmtNodes::AssignStmtCfgNode getAssignStmt() { this.isExplicitWrite(result) }
predicate isExplicitWrite(AstCfgNode assignmentCfg) {
exists(Ast assignment |
e.isExplicitWrite(assignment) and
e.hasCfgChild(assignment, this, assignmentCfg)
)
}
predicate isImplicitWrite() { e.isImplicitWrite() }
}
class VarReadAccessCfgNode extends VarAccessCfgNode {
override VarReadAccess e;
override string getAPrimaryQlClass() { result = "VarReadAccessCfgNode" }
override VarReadAccess getExpr() { result = e }
}
private class HashTableExprChildMapping extends ExprChildMapping, HashTableExpr {
override predicate relevantChild(Ast child) {
child = this.getAKey()
or
child = this.getAValue()
}
}
class HashTableExprCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "HashTableExprCfgNode" }
override HashTableExprChildMapping e;
override HashTableExpr getExpr() { result = e }
ExprCfgNode getKey(int i) { e.hasCfgChild(e.getKey(i), this, result) }
ExprCfgNode getAnKey() { result = this.getKey(_) }
ExprCfgNode getValue(int i) { e.hasCfgChild(e.getValue(i), this, result) }
ExprCfgNode getValueFromKey(ExprCfgNode key) {
exists(int i |
this.getKey(i) = key and
result = this.getValue(i)
)
}
ExprCfgNode getAValue() { result = this.getValue(_) }
}
private class PipelineChildMapping extends ExprChildMapping, Pipeline {
override predicate relevantChild(Ast child) { child = this.getAComponent() }
}
class PipelineCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "PipelineCfgNode" }
override PipelineChildMapping e;
override Pipeline getExpr() { result = e }
ExprCfgNode getComponent(int i) { e.hasCfgChild(e.getComponent(i), this, result) }
ExprCfgNode getAComponent() { result = this.getComponent(_) }
ExprCfgNode getLastComponent() { e.hasCfgChild(e.getLastComponent(), this, result) }
}
private class PipelineChainChildMapping extends ExprChildMapping, PipelineChain {
override predicate relevantChild(Ast child) {
child = this.getLeft() or child = this.getRight()
}
}
class PipelineChainCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "PipelineChainCfgNode" }
override PipelineChainChildMapping e;
override PipelineChain getExpr() { result = e }
ExprCfgNode getLeft() { e.hasCfgChild(e.getLeft(), this, result) }
ExprCfgNode getRight() { e.hasCfgChild(e.getRight(), this, result) }
}
private class ConditionalExprChildMapping extends ExprChildMapping, ConditionalExpr {
override predicate relevantChild(Ast child) {
child = this.getCondition()
or
child = this.getIfTrue()
or
child = this.getIfFalse()
}
}
class ConditionalExprCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "ConditionalExprCfgNode" }
override ConditionalExprChildMapping e;
override ConditionalExpr getExpr() { result = e }
ExprCfgNode getCondition() { e.hasCfgChild(e.getCondition(), this, result) }
ExprCfgNode getIfTrue() { e.hasCfgChild(e.getIfTrue(), this, result) }
ExprCfgNode getIfFalse() { e.hasCfgChild(e.getIfFalse(), this, result) }
ExprCfgNode getBranch(boolean b) {
b = true and
result = this.getIfTrue()
or
b = false and
result = this.getIfFalse()
}
ExprCfgNode getABranch() { result = this.getBranch(_) }
}
private class ExpandableSubExprChildMapping extends ExprChildMapping, ExpandableSubExpr {
override predicate relevantChild(Ast child) { child = this.getExpr() }
}
class ExpandableSubExprCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "ExpandableSubExprCfgNode" }
override ExpandableSubExprChildMapping e;
override ExpandableSubExpr getExpr() { result = e }
ExprCfgNode getSubExpr() { e.hasCfgChild(e.getExpr(), this, result) }
}
private class UsingExprChildMapping extends ExprChildMapping, UsingExpr {
override predicate relevantChild(Ast child) { child = this.getExpr() }
}
class UsingExprCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "UsingExprCfgNode" }
override UsingExprChildMapping e;
override UsingExpr getExpr() { result = e }
ExprCfgNode getSubExpr() { e.hasCfgChild(e.getExpr(), this, result) }
}
private class AttributedExprChildMapping extends ExprChildMapping, AttributedExpr {
override predicate relevantChild(Ast child) {
child = this.getExpr() or
child = this.getAttribute()
}
}
class AttributedExprCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "TAttributedExprCfgNode" }
override AttributedExprChildMapping e;
override AttributedExpr getExpr() { result = e }
ExprCfgNode getSubExpr() { e.hasCfgChild(e.getExpr(), this, result) }