@@ -16,6 +16,42 @@ private import semmle.code.csharp.dispatch.Dispatch
16
16
private import semmle.code.csharp.frameworks.EntityFramework
17
17
private import semmle.code.csharp.frameworks.NHibernate
18
18
19
+ abstract class NodeImpl extends Node {
20
+ /** Do not call: use `getEnclosingCallable()` instead. */
21
+ abstract DataFlowCallable getEnclosingCallableImpl ( ) ;
22
+
23
+ /** Do not call: use `getType()` instead. */
24
+ abstract DotNet:: Type getTypeImpl ( ) ;
25
+
26
+ /** Do not call: use `getControlFlowNode()` instead. */
27
+ abstract ControlFlow:: Node getControlFlowNodeImpl ( ) ;
28
+
29
+ /** Do not call: use `getLocation()` instead. */
30
+ abstract Location getLocationImpl ( ) ;
31
+
32
+ /** Do not call: use `toString()` instead. */
33
+ abstract string toStringImpl ( ) ;
34
+ }
35
+
36
+ private class ExprNodeImpl extends ExprNode , NodeImpl {
37
+ override DataFlowCallable getEnclosingCallableImpl ( ) {
38
+ result = this .getExpr ( ) .getEnclosingCallable ( )
39
+ }
40
+
41
+ override DotNet:: Type getTypeImpl ( ) { result = this .getExpr ( ) .getType ( ) }
42
+
43
+ override ControlFlow:: Nodes:: ElementNode getControlFlowNodeImpl ( ) { this = TExprNode ( result ) }
44
+
45
+ override Location getLocationImpl ( ) { result = this .getExpr ( ) .getLocation ( ) }
46
+
47
+ override string toStringImpl ( ) {
48
+ result = this .getControlFlowNode ( ) .toString ( )
49
+ or
50
+ this = TCilExprNode ( _) and
51
+ result = "CIL expression"
52
+ }
53
+ }
54
+
19
55
/** Calculation of the relative order in which `this` references are read. */
20
56
private module ThisFlow {
21
57
private class BasicBlock = ControlFlow:: BasicBlock ;
@@ -553,27 +589,31 @@ private module Cached {
553
589
import Cached
554
590
555
591
/** An SSA definition, viewed as a node in a data flow graph. */
556
- class SsaDefinitionNode extends Node , TSsaDefinitionNode {
592
+ class SsaDefinitionNode extends NodeImpl , TSsaDefinitionNode {
557
593
Ssa:: Definition def ;
558
594
559
595
SsaDefinitionNode ( ) { this = TSsaDefinitionNode ( def ) }
560
596
561
597
/** Gets the underlying SSA definition. */
562
598
Ssa:: Definition getDefinition ( ) { result = def }
563
599
564
- override Callable getEnclosingCallable ( ) { result = def .getEnclosingCallable ( ) }
600
+ override Callable getEnclosingCallableImpl ( ) { result = def .getEnclosingCallable ( ) }
565
601
566
- override Type getType ( ) { result = def .getSourceVariable ( ) .getType ( ) }
602
+ override Type getTypeImpl ( ) { result = def .getSourceVariable ( ) .getType ( ) }
567
603
568
- override Location getLocation ( ) { result = def .getLocation ( ) }
604
+ override ControlFlow :: Node getControlFlowNodeImpl ( ) { result = def .getControlFlowNode ( ) }
569
605
570
- override string toString ( ) {
606
+ override Location getLocationImpl ( ) { result = def .getLocation ( ) }
607
+
608
+ override string toStringImpl ( ) {
571
609
not explicitParameterNode ( this , _) and
572
610
result = def .toString ( )
573
611
}
574
612
}
575
613
576
614
private module ParameterNodes {
615
+ abstract private class ParameterNodeImpl extends ParameterNode , NodeImpl { }
616
+
577
617
/**
578
618
* Holds if definition node `node` is an entry definition for parameter `p`.
579
619
*/
@@ -585,7 +625,7 @@ private module ParameterNodes {
585
625
* The value of an explicit parameter at function entry, viewed as a node in a data
586
626
* flow graph.
587
627
*/
588
- class ExplicitParameterNode extends ParameterNode {
628
+ class ExplicitParameterNode extends ParameterNodeImpl {
589
629
private DotNet:: Parameter parameter ;
590
630
591
631
ExplicitParameterNode ( ) {
@@ -597,17 +637,19 @@ private module ParameterNodes {
597
637
598
638
override predicate isParameterOf ( DataFlowCallable c , int i ) { c .getParameter ( i ) = parameter }
599
639
600
- override DotNet:: Callable getEnclosingCallable ( ) { result = parameter .getCallable ( ) }
640
+ override DotNet:: Callable getEnclosingCallableImpl ( ) { result = parameter .getCallable ( ) }
641
+
642
+ override DotNet:: Type getTypeImpl ( ) { result = parameter .getType ( ) }
601
643
602
- override DotNet :: Type getType ( ) { result = parameter . getType ( ) }
644
+ override ControlFlow :: Node getControlFlowNodeImpl ( ) { none ( ) }
603
645
604
- override Location getLocation ( ) { result = parameter .getLocation ( ) }
646
+ override Location getLocationImpl ( ) { result = parameter .getLocation ( ) }
605
647
606
- override string toString ( ) { result = parameter .toString ( ) }
648
+ override string toStringImpl ( ) { result = parameter .toString ( ) }
607
649
}
608
650
609
651
/** An implicit instance (`this`) parameter. */
610
- class InstanceParameterNode extends ParameterNode , TInstanceParameterNode {
652
+ class InstanceParameterNode extends ParameterNodeImpl , TInstanceParameterNode {
611
653
private Callable callable ;
612
654
613
655
InstanceParameterNode ( ) { this = TInstanceParameterNode ( callable ) }
@@ -617,13 +659,15 @@ private module ParameterNodes {
617
659
618
660
override predicate isParameterOf ( DataFlowCallable c , int pos ) { callable = c and pos = - 1 }
619
661
620
- override Callable getEnclosingCallable ( ) { result = callable }
662
+ override Callable getEnclosingCallableImpl ( ) { result = callable }
621
663
622
- override Type getType ( ) { result = callable .getDeclaringType ( ) }
664
+ override Type getTypeImpl ( ) { result = callable .getDeclaringType ( ) }
623
665
624
- override Location getLocation ( ) { result = callable . getLocation ( ) }
666
+ override ControlFlow :: Node getControlFlowNodeImpl ( ) { none ( ) }
625
667
626
- override string toString ( ) { result = "this" }
668
+ override Location getLocationImpl ( ) { result = callable .getLocation ( ) }
669
+
670
+ override string toStringImpl ( ) { result = "this" }
627
671
}
628
672
629
673
module ImplicitCapturedParameterNodeImpl {
@@ -776,7 +820,7 @@ private module ArgumentNodes {
776
820
* } }
777
821
* ```
778
822
*/
779
- class ImplicitCapturedArgumentNode extends ArgumentNode , TImplicitCapturedArgumentNode {
823
+ class ImplicitCapturedArgumentNode extends ArgumentNode , NodeImpl , TImplicitCapturedArgumentNode {
780
824
private LocalScopeVariable v ;
781
825
private ControlFlow:: Nodes:: ElementNode cfn ;
782
826
@@ -814,20 +858,22 @@ private module ArgumentNodes {
814
858
)
815
859
}
816
860
817
- override Callable getEnclosingCallable ( ) { result = cfn .getEnclosingCallable ( ) }
861
+ override Callable getEnclosingCallableImpl ( ) { result = cfn .getEnclosingCallable ( ) }
862
+
863
+ override Type getTypeImpl ( ) { result = v .getType ( ) }
818
864
819
- override Type getType ( ) { result = v . getType ( ) }
865
+ override ControlFlow :: Node getControlFlowNodeImpl ( ) { none ( ) }
820
866
821
- override Location getLocation ( ) { result = cfn .getLocation ( ) }
867
+ override Location getLocationImpl ( ) { result = cfn .getLocation ( ) }
822
868
823
- override string toString ( ) { result = "[implicit argument] " + v }
869
+ override string toStringImpl ( ) { result = "[implicit argument] " + v }
824
870
}
825
871
826
872
/**
827
873
* A node that corresponds to the value of an object creation (`new C()`) before
828
874
* the constructor has run.
829
875
*/
830
- class MallocNode extends ArgumentNode , TMallocNode {
876
+ class MallocNode extends ArgumentNode , NodeImpl , TMallocNode {
831
877
private ControlFlow:: Nodes:: ElementNode cfn ;
832
878
833
879
MallocNode ( ) { this = TMallocNode ( cfn ) }
@@ -837,15 +883,15 @@ private module ArgumentNodes {
837
883
pos = - 1
838
884
}
839
885
840
- override ControlFlow:: Node getControlFlowNode ( ) { result = cfn }
886
+ override ControlFlow:: Node getControlFlowNodeImpl ( ) { result = cfn }
841
887
842
- override Callable getEnclosingCallable ( ) { result = cfn .getEnclosingCallable ( ) }
888
+ override Callable getEnclosingCallableImpl ( ) { result = cfn .getEnclosingCallable ( ) }
843
889
844
- override Type getType ( ) { result = cfn .getElement ( ) .( Expr ) .getType ( ) }
890
+ override Type getTypeImpl ( ) { result = cfn .getElement ( ) .( Expr ) .getType ( ) }
845
891
846
- override Location getLocation ( ) { result = cfn .getLocation ( ) }
892
+ override Location getLocationImpl ( ) { result = cfn .getLocation ( ) }
847
893
848
- override string toString ( ) { result = "malloc" }
894
+ override string toStringImpl ( ) { result = "malloc" }
849
895
}
850
896
851
897
/**
@@ -858,7 +904,7 @@ private module ArgumentNodes {
858
904
*
859
905
* `x` is an implicit argument of the implicit call to `Foo`.
860
906
*/
861
- class ImplicitDelegateArgumentNode extends ArgumentNode , TImplicitDelegateArgumentNode {
907
+ class ImplicitDelegateArgumentNode extends ArgumentNode , NodeImpl , TImplicitDelegateArgumentNode {
862
908
private ControlFlow:: Node cfn ;
863
909
private int delegateIndex ;
864
910
private int parameterIndex ;
@@ -874,15 +920,17 @@ private module ArgumentNodes {
874
920
pos = parameterIndex
875
921
}
876
922
877
- override Callable getEnclosingCallable ( ) { result = cfn .getEnclosingCallable ( ) }
923
+ override Callable getEnclosingCallableImpl ( ) { result = cfn .getEnclosingCallable ( ) }
878
924
879
- override Type getType ( ) {
925
+ override Type getTypeImpl ( ) {
880
926
result = this .getDelegateCall ( ) .getDelegateParameterType ( parameterIndex )
881
927
}
882
928
883
- override Location getLocation ( ) { result = cfn .getLocation ( ) }
929
+ override ControlFlow:: Node getControlFlowNodeImpl ( ) { none ( ) }
930
+
931
+ override Location getLocationImpl ( ) { result = cfn .getLocation ( ) }
884
932
885
- override string toString ( ) { result = "[implicit argument " + parameterIndex + "] " + cfn }
933
+ override string toStringImpl ( ) { result = "[implicit argument " + parameterIndex + "] " + cfn }
886
934
}
887
935
}
888
936
@@ -939,7 +987,7 @@ private module ReturnNodes {
939
987
* `yield return`s as stores into collections, i.e., there is flow from `e`
940
988
* to `yield return e [e]`.
941
989
*/
942
- class YieldReturnNode extends ReturnNode , PostUpdateNode , TYieldReturnNode {
990
+ class YieldReturnNode extends ReturnNode , NodeImpl , TYieldReturnNode {
943
991
private ControlFlow:: Nodes:: ElementNode cfn ;
944
992
private YieldReturnStmt yrs ;
945
993
@@ -949,15 +997,15 @@ private module ReturnNodes {
949
997
950
998
override YieldReturnKind getKind ( ) { any ( ) }
951
999
952
- override ExprNode getPreUpdateNode ( ) { result . getControlFlowNode ( ) = cfn }
1000
+ override Callable getEnclosingCallableImpl ( ) { result = yrs . getEnclosingCallable ( ) }
953
1001
954
- override Callable getEnclosingCallable ( ) { result = yrs .getEnclosingCallable ( ) }
1002
+ override Type getTypeImpl ( ) { result = yrs .getEnclosingCallable ( ) . getReturnType ( ) }
955
1003
956
- override Type getType ( ) { result = yrs . getEnclosingCallable ( ) . getReturnType ( ) }
1004
+ override ControlFlow :: Node getControlFlowNodeImpl ( ) { result = cfn }
957
1005
958
- override Location getLocation ( ) { result = yrs .getLocation ( ) }
1006
+ override Location getLocationImpl ( ) { result = yrs .getLocation ( ) }
959
1007
960
- override string toString ( ) { result = yrs .toString ( ) }
1008
+ override string toStringImpl ( ) { result = yrs .toString ( ) }
961
1009
}
962
1010
963
1011
/**
@@ -1112,7 +1160,7 @@ private module OutNodes {
1112
1160
* in a call to a library method. For example, the output from the implicit
1113
1161
* call to `M` in `new Lazy<int>(M)`.
1114
1162
*/
1115
- class ImplicitDelegateOutNode extends OutNode , TImplicitDelegateOutNode {
1163
+ class ImplicitDelegateOutNode extends OutNode , NodeImpl , TImplicitDelegateOutNode {
1116
1164
private ControlFlow:: Nodes:: ElementNode cfn ;
1117
1165
private ControlFlow:: Nodes:: ElementNode call ;
1118
1166
@@ -1128,7 +1176,7 @@ private module OutNodes {
1128
1176
call .getElement ( ) .( Call ) .getArgument ( i ) = cfn .getElement ( )
1129
1177
}
1130
1178
1131
- override ControlFlow:: Nodes:: ElementNode getControlFlowNode ( ) { result = cfn }
1179
+ override ControlFlow:: Nodes:: ElementNode getControlFlowNodeImpl ( ) { result = cfn }
1132
1180
1133
1181
override ImplicitDelegateDataFlowCall getCall ( ReturnKind kind ) {
1134
1182
result .getNode ( ) = this and
@@ -1141,17 +1189,17 @@ private module OutNodes {
1141
1189
)
1142
1190
}
1143
1191
1144
- override Callable getEnclosingCallable ( ) { result = cfn .getEnclosingCallable ( ) }
1192
+ override Callable getEnclosingCallableImpl ( ) { result = cfn .getEnclosingCallable ( ) }
1145
1193
1146
- override Type getType ( ) {
1194
+ override Type getTypeImpl ( ) {
1147
1195
exists ( ImplicitDelegateDataFlowCall c | c .getNode ( ) = this |
1148
1196
result = c .getDelegateReturnType ( )
1149
1197
)
1150
1198
}
1151
1199
1152
- override Location getLocation ( ) { result = cfn .getLocation ( ) }
1200
+ override Location getLocationImpl ( ) { result = cfn .getLocation ( ) }
1153
1201
1154
- override string toString ( ) { result = "[output] " + cfn }
1202
+ override string toStringImpl ( ) { result = "[output] " + cfn }
1155
1203
}
1156
1204
}
1157
1205
@@ -1320,7 +1368,7 @@ module LibraryFlow {
1320
1368
}
1321
1369
1322
1370
/** A data-flow node used to model flow through library code. */
1323
- class LibraryCodeNode extends Node , TLibraryCodeNode {
1371
+ class LibraryCodeNode extends NodeImpl , TLibraryCodeNode {
1324
1372
private ControlFlow:: Node callCfn ;
1325
1373
private CallableFlowSource source ;
1326
1374
private AccessPath sourceAp ;
@@ -1413,7 +1461,7 @@ class LibraryCodeNode extends Node, TLibraryCodeNode {
1413
1461
)
1414
1462
}
1415
1463
1416
- override Callable getEnclosingCallable ( ) { result = callCfn .getEnclosingCallable ( ) }
1464
+ override Callable getEnclosingCallableImpl ( ) { result = callCfn .getEnclosingCallable ( ) }
1417
1465
1418
1466
override DataFlowType getTypeBound ( ) {
1419
1467
preservesValue = true and
@@ -1426,9 +1474,13 @@ class LibraryCodeNode extends Node, TLibraryCodeNode {
1426
1474
result = this .getSuccessor ( _) .getTypeBound ( )
1427
1475
}
1428
1476
1429
- override Location getLocation ( ) { result = callCfn . getLocation ( ) }
1477
+ override DotNet :: Type getTypeImpl ( ) { none ( ) }
1430
1478
1431
- override string toString ( ) { result = "[library code] " + callCfn }
1479
+ override ControlFlow:: Node getControlFlowNodeImpl ( ) { result = callCfn }
1480
+
1481
+ override Location getLocationImpl ( ) { result = callCfn .getLocation ( ) }
1482
+
1483
+ override string toStringImpl ( ) { result = "[library code] " + callCfn }
1432
1484
}
1433
1485
1434
1486
/** A field or a property. */
@@ -1600,20 +1652,22 @@ private module PostUpdateNodes {
1600
1652
override MallocNode getPreUpdateNode ( ) { this = TExprNode ( result .getControlFlowNode ( ) ) }
1601
1653
}
1602
1654
1603
- class ExprPostUpdateNode extends PostUpdateNode , TExprPostUpdateNode {
1655
+ class ExprPostUpdateNode extends PostUpdateNode , NodeImpl , TExprPostUpdateNode {
1604
1656
private ControlFlow:: Nodes:: ElementNode cfn ;
1605
1657
1606
1658
ExprPostUpdateNode ( ) { this = TExprPostUpdateNode ( cfn ) }
1607
1659
1608
1660
override ExprNode getPreUpdateNode ( ) { cfn = result .getControlFlowNode ( ) }
1609
1661
1610
- override Callable getEnclosingCallable ( ) { result = cfn .getEnclosingCallable ( ) }
1662
+ override Callable getEnclosingCallableImpl ( ) { result = cfn .getEnclosingCallable ( ) }
1663
+
1664
+ override Type getTypeImpl ( ) { result = cfn .getElement ( ) .( Expr ) .getType ( ) }
1611
1665
1612
- override Type getType ( ) { result = cfn . getElement ( ) . ( Expr ) . getType ( ) }
1666
+ override ControlFlow :: Node getControlFlowNodeImpl ( ) { none ( ) }
1613
1667
1614
- override Location getLocation ( ) { result = cfn .getLocation ( ) }
1668
+ override Location getLocationImpl ( ) { result = cfn .getLocation ( ) }
1615
1669
1616
- override string toString ( ) { result = "[post] " + cfn .toString ( ) }
1670
+ override string toStringImpl ( ) { result = "[post] " + cfn .toString ( ) }
1617
1671
}
1618
1672
}
1619
1673
0 commit comments