@@ -22,14 +22,10 @@ private module Cached {
2222 }
2323
2424 cached
25- newtype TSplitKind =
26- TInitializerSplitKind ( ) or
27- TConditionalCompletionSplitKind ( )
25+ newtype TSplitKind = TConditionalCompletionSplitKind ( )
2826
2927 cached
30- newtype TSplit =
31- TInitializerSplit ( Constructor c ) { InitializerSplitting:: constructorInitializes ( c , _) } or
32- TConditionalCompletionSplit ( ConditionalCompletion c )
28+ newtype TSplit = TConditionalCompletionSplit ( ConditionalCompletion c )
3329}
3430
3531import Cached
@@ -44,8 +40,6 @@ class Split extends TSplit {
4440}
4541
4642module InitializerSplitting {
47- private import semmle.code.csharp.ExprOrStmtParent
48-
4943 /**
5044 * A non-static member with an initializer, for example a field `int Field = 0`.
5145 */
@@ -60,40 +54,28 @@ module InitializerSplitting {
6054
6155 /** Gets the initializer expression. */
6256 AssignExpr getInitializer ( ) { expr_parent_top_level ( result , _, this ) }
63-
64- /**
65- * Gets a control flow element that is a syntactic descendant of the
66- * initializer expression.
67- */
68- AstNode getAnInitializerDescendant ( ) {
69- result = this .getInitializer ( )
70- or
71- result = this .getAnInitializerDescendant ( ) .getAChild ( )
72- }
7357 }
7458
7559 /**
76- * Holds if `c ` is a non-static constructor that performs the initialization
60+ * Holds if `obinit ` is an object initializer method that performs the initialization
7761 * of a member via assignment `init`.
7862 */
79- predicate constructorInitializes ( InstanceConstructor c , AssignExpr init ) {
63+ predicate obinitInitializes ( ObjectInitMethod obinit , AssignExpr init ) {
8064 exists ( InitializedInstanceMember m |
81- c .isUnboundDeclaration ( ) and
82- c .getDeclaringType ( ) .getAMember ( ) = m and
83- not c .getInitializer ( ) .isThis ( ) and
65+ obinit .getDeclaringType ( ) .getAMember ( ) = m and
8466 init = m .getInitializer ( )
8567 )
8668 }
8769
8870 /**
89- * Gets the `i`th member initializer expression for non-static constructor `c `
71+ * Gets the `i`th member initializer expression for object initializer method `obinit `
9072 * in compilation `comp`.
9173 */
92- AssignExpr constructorInitializeOrder ( Constructor c , CompilationExt comp , int i ) {
93- constructorInitializes ( c , result ) and
74+ AssignExpr initializedInstanceMemberOrder ( ObjectInitMethod obinit , CompilationExt comp , int i ) {
75+ obinitInitializes ( obinit , result ) and
9476 result =
9577 rank [ i + 1 ] ( AssignExpr ae0 , Location l |
96- constructorInitializes ( c , ae0 ) and
78+ obinitInitializes ( obinit , ae0 ) and
9779 l = ae0 .getLocation ( ) and
9880 getCompilation ( l .getFile ( ) ) = comp
9981 |
@@ -105,122 +87,12 @@ module InitializerSplitting {
10587 * Gets the last member initializer expression for non-static constructor `c`
10688 * in compilation `comp`.
10789 */
108- AssignExpr lastConstructorInitializer ( Constructor c , CompilationExt comp ) {
90+ AssignExpr lastInitializer ( ObjectInitMethod obinit , CompilationExt comp ) {
10991 exists ( int i |
110- result = constructorInitializeOrder ( c , comp , i ) and
111- not exists ( constructorInitializeOrder ( c , comp , i + 1 ) )
92+ result = initializedInstanceMemberOrder ( obinit , comp , i ) and
93+ not exists ( initializedInstanceMemberOrder ( obinit , comp , i + 1 ) )
11294 )
11395 }
114-
115- /**
116- * A split for non-static member initializers belonging to a given non-static
117- * constructor. For example, in
118- *
119- * ```csharp
120- * class C
121- * {
122- * int Field1 = 0;
123- * int Field2 = Field1 + 1;
124- * int Field3;
125- *
126- * public C()
127- * {
128- * Field3 = 2;
129- * }
130- *
131- * public C(int i)
132- * {
133- * Field3 = 3;
134- * }
135- * }
136- * ```
137- *
138- * the initializer expressions `Field1 = 0` and `Field2 = Field1 + 1` are split
139- * on the two constructors. This is in order to generate CFGs for the two
140- * constructors that mimic
141- *
142- * ```csharp
143- * public C()
144- * {
145- * Field1 = 0;
146- * Field2 = Field1 + 1;
147- * Field3 = 2;
148- * }
149- * ```
150- *
151- * and
152- *
153- * ```csharp
154- * public C()
155- * {
156- * Field1 = 0;
157- * Field2 = Field1 + 1;
158- * Field3 = 3;
159- * }
160- * ```
161- *
162- * respectively.
163- */
164- private class InitializerSplit extends Split , TInitializerSplit {
165- private Constructor c ;
166-
167- InitializerSplit ( ) { this = TInitializerSplit ( c ) }
168-
169- /** Gets the constructor. */
170- Constructor getConstructor ( ) { result = c }
171-
172- override string toString ( ) { result = "" }
173- }
174-
175- private class InitializerSplitKind extends SplitKind , TInitializerSplitKind {
176- override int getListOrder ( ) { result = 0 }
177-
178- override predicate isEnabled ( AstNode cfe ) { this .appliesTo ( cfe ) }
179-
180- override string toString ( ) { result = "Initializer" }
181- }
182-
183- int getNextListOrder ( ) { result = 1 }
184-
185- private class InitializerSplitImpl extends SplitImpl instanceof InitializerSplit {
186- override InitializerSplitKind getKind ( ) { any ( ) }
187-
188- override predicate hasEntry ( AstNode pred , AstNode succ , Completion c ) {
189- exists ( ConstructorInitializer ci |
190- last ( ci , pred , c ) and
191- succ ( pred , succ , c ) and
192- succ = any ( InitializedInstanceMember m ) .getAnInitializerDescendant ( ) and
193- super .getConstructor ( ) = ci .getConstructor ( )
194- )
195- }
196-
197- override predicate hasEntryScope ( CfgScope scope , AstNode first ) {
198- scopeFirst ( scope , first ) and
199- scope = super .getConstructor ( ) and
200- first = any ( InitializedInstanceMember m ) .getAnInitializerDescendant ( )
201- }
202-
203- override predicate hasExit ( AstNode pred , AstNode succ , Completion c ) {
204- this .appliesTo ( pred ) and
205- succ ( pred , succ , c ) and
206- not succ = any ( InitializedInstanceMember m ) .getAnInitializerDescendant ( ) and
207- succ .( ControlFlowElement ) .getEnclosingCallable ( ) = super .getConstructor ( )
208- }
209-
210- override predicate hasExitScope ( CfgScope scope , AstNode last , Completion c ) {
211- this .appliesTo ( last ) and
212- scopeLast ( scope , last , c ) and
213- scope = super .getConstructor ( )
214- }
215-
216- override predicate hasSuccessor ( AstNode pred , AstNode succ , Completion c ) {
217- this .appliesSucc ( pred , succ , c ) and
218- succ =
219- any ( InitializedInstanceMember m |
220- constructorInitializes ( super .getConstructor ( ) , m .getInitializer ( ) )
221- ) .getAnInitializerDescendant ( )
222- }
223- }
22496}
22597
22698module ConditionalCompletionSplitting {
@@ -249,7 +121,7 @@ module ConditionalCompletionSplitting {
249121 }
250122
251123 private class ConditionalCompletionSplitKind_ extends SplitKind , TConditionalCompletionSplitKind {
252- override int getListOrder ( ) { result = InitializerSplitting :: getNextListOrder ( ) }
124+ override int getListOrder ( ) { result = 0 }
253125
254126 override predicate isEnabled ( AstNode cfe ) { this .appliesTo ( cfe ) }
255127
@@ -312,6 +184,4 @@ module ConditionalCompletionSplitting {
312184 )
313185 }
314186 }
315-
316- int getNextListOrder ( ) { result = InitializerSplitting:: getNextListOrder ( ) + 1 }
317187}
0 commit comments