File tree Expand file tree Collapse file tree 1 file changed +7
-22
lines changed
csharp/ql/src/Language Abuse Expand file tree Collapse file tree 1 file changed +7
-22
lines changed Original file line number Diff line number Diff line change 12
12
import csharp
13
13
import semmle.code.csharp.commons.StructuralComparison
14
14
15
- class StructuralComparisonConfig extends StructuralComparisonConfiguration {
16
- StructuralComparisonConfig ( ) { this = "MissedTernaryOpportunity" }
17
-
18
- override predicate candidate ( ControlFlowElement x , ControlFlowElement y ) {
19
- exists ( IfStmt is , AssignExpr ae1 |
20
- ae1 = is .getThen ( ) .stripSingletonBlocks ( ) .( ExprStmt ) .getExpr ( )
21
- |
22
- x = ae1 .getLValue ( ) and
23
- exists ( AssignExpr ae2 | ae2 = is .getElse ( ) .stripSingletonBlocks ( ) .( ExprStmt ) .getExpr ( ) |
24
- y = ae2 .getLValue ( )
25
- )
26
- )
27
- }
15
+ private Expr getAssignedExpr ( Stmt stmt ) {
16
+ result = stmt .stripSingletonBlocks ( ) .( ExprStmt ) .getExpr ( ) .( AssignExpr ) .getLValue ( )
17
+ }
28
18
29
- IfStmt getIfStmt ( ) {
30
- exists ( AssignExpr ae | ae = result .getThen ( ) .stripSingletonBlocks ( ) .( ExprStmt ) .getExpr ( ) |
31
- same ( ae .getLValue ( ) , _)
32
- )
33
- }
19
+ private predicate ifStmt ( IfStmt is ) {
20
+ sameGvn ( getAssignedExpr ( is .getThen ( ) ) , getAssignedExpr ( is .getElse ( ) ) )
34
21
}
35
22
36
23
from IfStmt is , string what
40
27
is .getElse ( ) .stripSingletonBlocks ( ) instanceof ReturnStmt and
41
28
what = "return"
42
29
or
43
- exists ( StructuralComparisonConfig c |
44
- is = c .getIfStmt ( ) and
45
- what = "write to the same variable"
46
- )
30
+ ifStmt ( is ) and
31
+ what = "write to the same variable"
47
32
) and
48
33
not exists ( IfStmt other | is = other .getElse ( ) )
49
34
select is ,
You can’t perform that action at this time.
0 commit comments