|
| 1 | +private import codeql.swift.elements.expr.Expr |
| 2 | +private import codeql.swift.elements.expr.BinaryExpr |
| 3 | +private import codeql.swift.elements.expr.PrefixUnaryExpr |
| 4 | +private import codeql.swift.elements.expr.DotSyntaxCallExpr |
| 5 | +private import codeql.swift.elements.expr.DeclRefExpr |
| 6 | +private import codeql.swift.elements.decl.ConcreteFuncDecl |
| 7 | + |
| 8 | +private predicate unaryHasName(PrefixUnaryExpr e, string name) { |
| 9 | + e.getFunction() |
| 10 | + .(DotSyntaxCallExpr) |
| 11 | + .getFunction() |
| 12 | + .(DeclRefExpr) |
| 13 | + .getDecl() |
| 14 | + .(ConcreteFuncDecl) |
| 15 | + .getName() = name |
| 16 | +} |
| 17 | + |
| 18 | +private predicate binaryHasName(BinaryExpr e, string name) { |
| 19 | + e.getFunction() |
| 20 | + .(DotSyntaxCallExpr) |
| 21 | + .getFunction() |
| 22 | + .(DeclRefExpr) |
| 23 | + .getDecl() |
| 24 | + .(ConcreteFuncDecl) |
| 25 | + .getName() = name |
| 26 | +} |
| 27 | + |
| 28 | +class LogicalAndExpr extends BinaryExpr { |
| 29 | + LogicalAndExpr() { binaryHasName(this, "&&") } |
| 30 | +} |
| 31 | + |
| 32 | +class LogicalOrExpr extends BinaryExpr { |
| 33 | + LogicalOrExpr() { binaryHasName(this, "||") } |
| 34 | +} |
| 35 | + |
| 36 | +class BinaryLogicalOperation extends BinaryExpr { |
| 37 | + BinaryLogicalOperation() { |
| 38 | + this instanceof LogicalAndExpr or |
| 39 | + this instanceof LogicalOrExpr |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +class NotExpr extends PrefixUnaryExpr { |
| 44 | + NotExpr() { unaryHasName(this, "!") } |
| 45 | +} |
| 46 | + |
| 47 | +class UnaryLogicalOperation extends PrefixUnaryExpr { |
| 48 | + UnaryLogicalOperation() { this instanceof NotExpr } |
| 49 | +} |
| 50 | + |
| 51 | +class LogicalOperation extends Expr { |
| 52 | + LogicalOperation() { |
| 53 | + this instanceof BinaryLogicalOperation or |
| 54 | + this instanceof UnaryLogicalOperation |
| 55 | + } |
| 56 | + |
| 57 | + Expr getAnOperand() { |
| 58 | + result = this.(BinaryLogicalOperation).getAnOperand() |
| 59 | + or |
| 60 | + result = this.(UnaryLogicalOperation).getOperand() |
| 61 | + } |
| 62 | +} |
0 commit comments