|
| 1 | +private import codeql.swift.elements.expr.BinaryExpr |
| 2 | +private import codeql.swift.elements.expr.Expr |
| 3 | +private import codeql.swift.elements.expr.PrefixUnaryExpr |
| 4 | + |
| 5 | +/** |
| 6 | + * A bitwise operation, such as: |
| 7 | + * ``` |
| 8 | + * a & b |
| 9 | + * ``` |
| 10 | + */ |
| 11 | +class BitwiseOperation extends Expr { |
| 12 | + BitwiseOperation() { |
| 13 | + this instanceof BinaryBitwiseOperation or |
| 14 | + this instanceof UnaryBitwiseOperation |
| 15 | + } |
| 16 | + |
| 17 | + /** |
| 18 | + * Gets an operand of this bitwise operation. |
| 19 | + */ |
| 20 | + Expr getAnOperand() { |
| 21 | + result = |
| 22 | + [this.(BinaryBitwiseOperation).getAnOperand(), this.(UnaryBitwiseOperation).getOperand()] |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +/** |
| 27 | + * A binary bitwise operation, such as: |
| 28 | + * ``` |
| 29 | + * a & b |
| 30 | + * ``` |
| 31 | + */ |
| 32 | +class BinaryBitwiseOperation extends BinaryExpr { |
| 33 | + BinaryBitwiseOperation() { |
| 34 | + this instanceof AndBitwiseExpr or |
| 35 | + this instanceof OrBitwiseExpr or |
| 36 | + this instanceof XorBitwiseExpr or |
| 37 | + this instanceof ShiftLeftBitwiseExpr or |
| 38 | + this instanceof ShiftRightBitwiseExpr |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +/** |
| 43 | + * A bitwise AND expression. |
| 44 | + * ``` |
| 45 | + * a & b |
| 46 | + * ``` |
| 47 | + */ |
| 48 | +class AndBitwiseExpr extends BinaryExpr { |
| 49 | + AndBitwiseExpr() { this.getStaticTarget().getName() = "&(_:_:)" } |
| 50 | +} |
| 51 | + |
| 52 | +/** |
| 53 | + * A bitwise OR expression. |
| 54 | + * ``` |
| 55 | + * a | b |
| 56 | + * ``` |
| 57 | + */ |
| 58 | +class OrBitwiseExpr extends BinaryExpr { |
| 59 | + OrBitwiseExpr() { this.getStaticTarget().getName() = "|(_:_:)" } |
| 60 | +} |
| 61 | + |
| 62 | +/** |
| 63 | + * A bitwise XOR expression. |
| 64 | + * ``` |
| 65 | + * a ^ b |
| 66 | + * ``` |
| 67 | + */ |
| 68 | +class XorBitwiseExpr extends BinaryExpr { |
| 69 | + XorBitwiseExpr() { this.getStaticTarget().getName() = "^(_:_:)" } |
| 70 | +} |
| 71 | + |
| 72 | +/** |
| 73 | + * A bitwise shift left expression. |
| 74 | + * ``` |
| 75 | + * a << b |
| 76 | + * ``` |
| 77 | + */ |
| 78 | +class ShiftLeftBitwiseExpr extends BinaryExpr { |
| 79 | + ShiftLeftBitwiseExpr() { this.getStaticTarget().getName() = "<<(_:_:)" } |
| 80 | +} |
| 81 | + |
| 82 | +/** |
| 83 | + * A bitwise shift right expression. |
| 84 | + * ``` |
| 85 | + * a >> b |
| 86 | + * ``` |
| 87 | + */ |
| 88 | +class ShiftRightBitwiseExpr extends BinaryExpr { |
| 89 | + ShiftRightBitwiseExpr() { this.getStaticTarget().getName() = ">>(_:_:)" } |
| 90 | +} |
| 91 | + |
| 92 | +/** |
| 93 | + * A unary bitwise operation, such as: |
| 94 | + * ``` |
| 95 | + * ~a |
| 96 | + * ``` |
| 97 | + */ |
| 98 | +class UnaryBitwiseOperation extends PrefixUnaryExpr instanceof NotBitwiseExpr { } |
| 99 | + |
| 100 | +/** |
| 101 | + * A bitwise NOT expression. |
| 102 | + * ``` |
| 103 | + * ~a |
| 104 | + * ``` |
| 105 | + */ |
| 106 | +class NotBitwiseExpr extends PrefixUnaryExpr { |
| 107 | + NotBitwiseExpr() { this.getStaticTarget().getName() = "~(_:)" } |
| 108 | +} |
0 commit comments