@@ -239,55 +239,38 @@ module ControlFlow {
239239 /** Holds if this node has more than one successor. */
240240 predicate isBranch ( ) { strictcount ( this .getASuccessor ( ) ) > 1 }
241241
242- /** Gets the enclosing callable of this control flow node, if any . */
242+ /** Gets the enclosing callable of this control flow node. */
243243 Callable getEnclosingCallable ( ) { none ( ) }
244-
245- /** Gets the enclosing entry element of this control flow node. */
246- ControlFlowEntryElement getEnclosingElement ( ) { none ( ) }
247244 }
248245
249246 /** Provides different types of control flow nodes. */
250247 module Nodes {
251- private import semmle.code.csharp.Enclosing:: Internal
252-
253- /** An entry node, for example a callable or a field initializer. */
248+ /** A node for a callable entry point. */
254249 class EntryNode extends Node , TEntryNode {
255- private ControlFlowEntryElement e ;
256-
257- EntryNode ( ) { this = TEntryNode ( e ) }
258-
259- /** Gets the callable that this entry applies to, if any. */
260- Callable getCallable ( ) { result = e }
250+ /** Gets the callable that this entry applies to. */
251+ Callable getCallable ( ) { this = TEntryNode ( result ) }
261252
262253 override BasicBlocks:: EntryBlock getBasicBlock ( ) { result = Node .super .getBasicBlock ( ) }
263254
264255 override Callable getEnclosingCallable ( ) { result = this .getCallable ( ) }
265256
266- override ControlFlowEntryElement getEnclosingElement ( ) { result = e }
257+ override Location getLocation ( ) { result = getCallable ( ) . getLocation ( ) }
267258
268- override Location getLocation ( ) { result = this .getEnclosingElement ( ) .getLocation ( ) }
269-
270- override string toString ( ) { result = "enter " + this .getEnclosingElement ( ) .toString ( ) }
259+ override string toString ( ) { result = "enter " + getCallable ( ) .toString ( ) }
271260 }
272261
273- /** An exit node, for example a callable or a field initializer . */
262+ /** A node for a callable exit point . */
274263 class ExitNode extends Node , TExitNode {
275- private ControlFlowEntryElement e ;
276-
277- ExitNode ( ) { this = TExitNode ( e ) }
278-
279- /** Gets the callable that this exit applies to, if any. */
280- Callable getCallable ( ) { result = e }
264+ /** Gets the callable that this exit applies to. */
265+ Callable getCallable ( ) { this = TExitNode ( result ) }
281266
282267 override BasicBlocks:: ExitBlock getBasicBlock ( ) { result = Node .super .getBasicBlock ( ) }
283268
284269 override Callable getEnclosingCallable ( ) { result = this .getCallable ( ) }
285270
286- override ControlFlowEntryElement getEnclosingElement ( ) { result = e }
271+ override Location getLocation ( ) { result = getCallable ( ) . getLocation ( ) }
287272
288- override Location getLocation ( ) { result = this .getEnclosingElement ( ) .getLocation ( ) }
289-
290- override string toString ( ) { result = "exit " + this .getEnclosingElement ( ) .toString ( ) }
273+ override string toString ( ) { result = "exit " + getCallable ( ) .toString ( ) }
291274 }
292275
293276 /**
@@ -306,10 +289,6 @@ module ControlFlow {
306289
307290 override Callable getEnclosingCallable ( ) { result = cfe .getEnclosingCallable ( ) }
308291
309- override ControlFlowEntryElement getEnclosingElement ( ) {
310- exprEnclosingEntryElement ( cfe , result )
311- }
312-
313292 override ControlFlowElement getElement ( ) { result = cfe }
314293
315294 override string toString ( ) {
@@ -1845,32 +1824,27 @@ module ControlFlow {
18451824 }
18461825
18471826 /**
1848- * Gets the control flow element that is first executed when entering `e`.
1827+ * Gets the control flow element that is first executed when entering
1828+ * callable `c`.
18491829 */
1850- ControlFlowElement succEntry ( ControlFlowEntryElement e ) {
1851- e = any ( Callable c |
1830+ ControlFlowElement succEntry ( @top_level_exprorstmt_parent p ) {
1831+ p = any ( Callable c |
18521832 if exists ( c .( Constructor ) .getInitializer ( ) )
18531833 then result = first ( c .( Constructor ) .getInitializer ( ) )
18541834 else result = first ( c .getBody ( ) )
18551835 )
18561836 or
1857- expr_parent_top_level_adjusted ( any ( Expr e0 | result = first ( e0 ) ) , _, e ) and
1858- not e instanceof Callable
1837+ expr_parent_top_level_adjusted ( any ( Expr e | result = first ( e ) ) , _, p ) and
1838+ not p instanceof Callable
18591839 }
18601840
18611841 /**
1862- * Gets the element that is exited when `cfe` finishes with completion `c`,
1842+ * Gets the callable that is exited when `cfe` finishes with completion `c`,
18631843 * if any.
18641844 */
1865- ControlFlowEntryElement succExit ( ControlFlowElement cfe , Completion c ) {
1866- cfe = last ( result .( Callable ) . getBody ( ) , c ) and
1845+ Callable succExit ( ControlFlowElement cfe , Completion c ) {
1846+ cfe = last ( result .getBody ( ) , c ) and
18671847 not c instanceof GotoCompletion
1868- or
1869- exists ( Expr e |
1870- expr_parent_top_level_adjusted ( e , _, result ) and
1871- cfe = last ( e , c ) and
1872- not result instanceof Callable
1873- )
18741848 }
18751849 }
18761850 import Successor
@@ -1885,13 +1859,13 @@ module ControlFlow {
18851859 */
18861860 cached
18871861 newtype TNode =
1888- TEntryNode ( ControlFlowEntryElement e ) {
1862+ TEntryNode ( Callable c ) {
18891863 Stages:: ControlFlowStage:: forceCachingInSameStage ( ) and
1890- succEntrySplits ( e , _, _, _)
1864+ succEntrySplits ( c , _, _, _)
18911865 } or
1892- TExitNode ( ControlFlowEntryElement e ) {
1866+ TExitNode ( Callable c ) {
18931867 exists ( Reachability:: SameSplitsBlock b | b .isReachable ( _) |
1894- succExitSplits ( b .getAnElement ( ) , _, e , _)
1868+ succExitSplits ( b .getAnElement ( ) , _, c , _)
18951869 )
18961870 } or
18971871 TElementNode ( ControlFlowElement cfe , Splits splits ) {
@@ -1901,20 +1875,18 @@ module ControlFlow {
19011875 /** Gets a successor node of a given flow type, if any. */
19021876 cached
19031877 Node getASuccessorByType ( Node pred , SuccessorType t ) {
1904- // Entry node -> body
1905- exists ( ControlFlowElement succElement , Splits succSplits , ControlFlowEntryElement e |
1906- result = TElementNode ( succElement , succSplits ) and
1907- pred = TEntryNode ( e ) and
1908- succEntrySplits ( e , succElement , succSplits , t )
1878+ // Callable entry node -> callable body
1879+ exists ( ControlFlowElement succElement , Splits succSplits |
1880+ result = TElementNode ( succElement , succSplits )
1881+ |
1882+ succEntrySplits ( pred . ( Nodes :: EntryNode ) . getCallable ( ) , succElement , succSplits , t )
19091883 )
19101884 or
19111885 exists ( ControlFlowElement predElement , Splits predSplits |
19121886 pred = TElementNode ( predElement , predSplits )
19131887 |
1914- // Element node -> exit node
1915- exists ( ControlFlowEntryElement e | result = TExitNode ( e ) |
1916- succExitSplits ( predElement , predSplits , e , t )
1917- )
1888+ // Element node -> callable exit
1889+ succExitSplits ( predElement , predSplits , result .( Nodes:: ExitNode ) .getCallable ( ) , t )
19181890 or
19191891 // Element node -> element node
19201892 exists ( ControlFlowElement succElement , Splits succSplits , Completion c |
0 commit comments