|
5 | 5 | */ |
6 | 6 |
|
7 | 7 | import csharp |
8 | | -private import Completion |
| 8 | +private import Completion as Comp |
| 9 | +private import Comp |
9 | 10 | private import ControlFlowGraphImpl |
10 | 11 | private import semmle.code.csharp.controlflow.ControlFlowGraph::ControlFlow as Cfg |
11 | 12 | private import semmle.code.csharp.controlflow.internal.PreSsa |
@@ -260,100 +261,77 @@ module ConditionalCompletionSplitting { |
260 | 261 |
|
261 | 262 | ConditionalCompletionSplit() { this = TConditionalCompletionSplit(completion) } |
262 | 263 |
|
| 264 | + ConditionalCompletion getCompletion() { result = completion } |
| 265 | + |
263 | 266 | override string toString() { result = completion.toString() } |
264 | 267 | } |
265 | 268 |
|
266 | | - private class ConditionalCompletionSplitKind extends SplitKind, TConditionalCompletionSplitKind { |
| 269 | + private class ConditionalCompletionSplitKind_ extends SplitKind, TConditionalCompletionSplitKind { |
267 | 270 | override int getListOrder() { result = InitializerSplitting::getNextListOrder() } |
268 | 271 |
|
269 | 272 | override predicate isEnabled(AstNode cfe) { this.appliesTo(cfe) } |
270 | 273 |
|
271 | 274 | override string toString() { result = "ConditionalCompletion" } |
272 | 275 | } |
273 | 276 |
|
274 | | - int getNextListOrder() { result = InitializerSplitting::getNextListOrder() + 1 } |
| 277 | + module ConditionalCompletionSplittingInput { |
| 278 | + private import Completion as Comp |
275 | 279 |
|
276 | | - private class ConditionalCompletionSplitImpl extends SplitImpl instanceof ConditionalCompletionSplit |
277 | | - { |
278 | | - ConditionalCompletion completion; |
| 280 | + class ConditionalCompletion = Comp::ConditionalCompletion; |
279 | 281 |
|
280 | | - ConditionalCompletionSplitImpl() { this = TConditionalCompletionSplit(completion) } |
| 282 | + class ConditionalCompletionSplitKind extends ConditionalCompletionSplitKind_, TSplitKind { } |
281 | 283 |
|
282 | | - override ConditionalCompletionSplitKind getKind() { any() } |
| 284 | + class ConditionalCompletionSplit = ConditionalCompletionSplitting::ConditionalCompletionSplit; |
283 | 285 |
|
284 | | - override predicate hasEntry(AstNode pred, AstNode succ, Completion c) { |
285 | | - succ(pred, succ, c) and |
286 | | - last(succ, _, completion) and |
| 286 | + bindingset[parent, parentCompletion] |
| 287 | + predicate condPropagateExpr( |
| 288 | + AstNode parent, ConditionalCompletion parentCompletion, AstNode child, |
| 289 | + ConditionalCompletion childCompletion |
| 290 | + ) { |
| 291 | + child = parent.(LogicalNotExpr).getOperand() and |
| 292 | + childCompletion.getDual() = parentCompletion |
| 293 | + or |
| 294 | + childCompletion = parentCompletion and |
287 | 295 | ( |
288 | | - last(succ.(LogicalNotExpr).getOperand(), pred, c) and |
289 | | - completion.(BooleanCompletion).getDual() = c |
| 296 | + child = parent.(LogicalAndExpr).getAnOperand() |
290 | 297 | or |
291 | | - last(succ.(LogicalAndExpr).getAnOperand(), pred, c) and |
292 | | - completion = c |
| 298 | + child = parent.(LogicalOrExpr).getAnOperand() |
293 | 299 | or |
294 | | - last(succ.(LogicalOrExpr).getAnOperand(), pred, c) and |
295 | | - completion = c |
| 300 | + parent = any(ConditionalExpr ce | child = [ce.getThen(), ce.getElse()]) |
296 | 301 | or |
297 | | - succ = |
298 | | - any(ConditionalExpr ce | |
299 | | - last([ce.getThen(), ce.getElse()], pred, c) and |
300 | | - completion = c |
301 | | - ) |
| 302 | + child = parent.(SwitchExpr).getACase() |
302 | 303 | or |
303 | | - succ = |
| 304 | + child = parent.(SwitchCaseExpr).getBody() |
| 305 | + or |
| 306 | + parent = |
304 | 307 | any(NullCoalescingExpr nce | |
305 | | - exists(Expr operand | |
306 | | - last(operand, pred, c) and |
307 | | - completion = c |
308 | | - | |
309 | | - if c instanceof NullnessCompletion |
310 | | - then operand = nce.getRightOperand() |
311 | | - else operand = nce.getAnOperand() |
312 | | - ) |
| 308 | + if childCompletion instanceof NullnessCompletion |
| 309 | + then child = nce.getRightOperand() |
| 310 | + else child = nce.getAnOperand() |
313 | 311 | ) |
| 312 | + ) |
| 313 | + or |
| 314 | + child = parent.(NotPatternExpr).getPattern() and |
| 315 | + childCompletion.getDual() = parentCompletion |
| 316 | + or |
| 317 | + child = parent.(IsExpr).getPattern() and |
| 318 | + parentCompletion.(BooleanCompletion).getValue() = |
| 319 | + childCompletion.(MatchingCompletion).getValue() |
| 320 | + or |
| 321 | + childCompletion = parentCompletion and |
| 322 | + ( |
| 323 | + child = parent.(AndPatternExpr).getAnOperand() |
314 | 324 | or |
315 | | - last(succ.(SwitchExpr).getACase(), pred, c) and |
316 | | - completion = c |
317 | | - or |
318 | | - last(succ.(SwitchCaseExpr).getBody(), pred, c) and |
319 | | - completion = c |
320 | | - or |
321 | | - last(succ.(NotPatternExpr).getPattern(), pred, c) and |
322 | | - completion.(MatchingCompletion).getDual() = c |
323 | | - or |
324 | | - last(succ.(IsExpr).getPattern(), pred, c) and |
325 | | - completion.(BooleanCompletion).getValue() = c.(MatchingCompletion).getValue() |
326 | | - or |
327 | | - last(succ.(AndPatternExpr).getAnOperand(), pred, c) and |
328 | | - completion = c |
329 | | - or |
330 | | - last(succ.(OrPatternExpr).getAnOperand(), pred, c) and |
331 | | - completion = c |
| 325 | + child = parent.(OrPatternExpr).getAnOperand() |
332 | 326 | or |
333 | | - last(succ.(RecursivePatternExpr).getAChildExpr(), pred, c) and |
334 | | - completion = c |
| 327 | + child = parent.(RecursivePatternExpr).getAChildExpr() |
335 | 328 | or |
336 | | - last(succ.(PropertyPatternExpr).getPattern(_), pred, c) and |
337 | | - completion = c |
| 329 | + child = parent.(PropertyPatternExpr).getPattern(_) |
338 | 330 | ) |
339 | 331 | } |
340 | | - |
341 | | - override predicate hasEntryScope(CfgScope scope, AstNode first) { none() } |
342 | | - |
343 | | - override predicate hasExit(AstNode pred, AstNode succ, Completion c) { |
344 | | - this.appliesTo(pred) and |
345 | | - succ(pred, succ, c) and |
346 | | - if c instanceof ConditionalCompletion then completion = c else any() |
347 | | - } |
348 | | - |
349 | | - override predicate hasExitScope(CfgScope scope, AstNode last, Completion c) { |
350 | | - this.appliesTo(last) and |
351 | | - scopeLast(scope, last, c) and |
352 | | - if c instanceof ConditionalCompletion then completion = c else any() |
353 | | - } |
354 | | - |
355 | | - override predicate hasSuccessor(AstNode pred, AstNode succ, Completion c) { none() } |
356 | 332 | } |
| 333 | + |
| 334 | + int getNextListOrder() { result = InitializerSplitting::getNextListOrder() + 1 } |
357 | 335 | } |
358 | 336 |
|
359 | 337 | module AssertionSplitting { |
|
0 commit comments