@@ -6,6 +6,7 @@ module Private {
66 private import csharp as CS
77 private import ConstantUtils as CU
88 private import semmle.code.csharp.controlflow.Guards as G
9+ private import Sign
910 import Impl
1011
1112 class Guard = G:: Guard ;
@@ -42,7 +43,73 @@ module Private {
4243
4344 class DivExpr = CS:: DivExpr ;
4445
45- class BinaryOperation = CS:: BinaryOperation ;
46+ /** Class to represent unary operation. */
47+ class UnaryOperation extends Expr {
48+ UnaryOperation ( ) {
49+ this instanceof CS:: PreIncrExpr or
50+ this instanceof CS:: PreDecrExpr or
51+ this instanceof CS:: UnaryMinusExpr or
52+ this instanceof CS:: ComplementExpr
53+ }
54+
55+ /** Returns the operand of this expression. */
56+ Expr getOperand ( ) {
57+ result = this .( CS:: PreIncrExpr ) .getOperand ( ) or
58+ result = this .( CS:: PreDecrExpr ) .getOperand ( ) or
59+ result = this .( CS:: UnaryMinusExpr ) .getOperand ( ) or
60+ result = this .( CS:: ComplementExpr ) .getOperand ( )
61+ }
62+
63+ /** Returns the operation representing this expression. */
64+ TUnarySignOperation getOp ( ) {
65+ this instanceof CS:: PreIncrExpr and result = TIncOp ( )
66+ or
67+ this instanceof CS:: PreDecrExpr and result = TDecOp ( )
68+ or
69+ this instanceof CS:: UnaryMinusExpr and result = TNegOp ( )
70+ or
71+ this instanceof CS:: ComplementExpr and result = TBitNotOp ( )
72+ }
73+ }
74+
75+ /** Class to represent binary operation. */
76+ class BinaryOperation extends CS:: BinaryOperation {
77+ BinaryOperation ( ) {
78+ this instanceof CS:: AddExpr or
79+ this instanceof CS:: SubExpr or
80+ this instanceof CS:: MulExpr or
81+ this instanceof CS:: DivExpr or
82+ this instanceof CS:: RemExpr or
83+ this instanceof CS:: BitwiseAndExpr or
84+ this instanceof CS:: BitwiseOrExpr or
85+ this instanceof CS:: BitwiseXorExpr or
86+ this instanceof CS:: LShiftExpr or
87+ this instanceof CS:: RShiftExpr
88+ }
89+
90+ /** Returns the operation representing this expression. */
91+ TBinarySignOperation getOp ( ) {
92+ this instanceof CS:: AddExpr and result = TAddOp ( )
93+ or
94+ this instanceof CS:: SubExpr and result = TSubOp ( )
95+ or
96+ this instanceof CS:: MulExpr and result = TMulOp ( )
97+ or
98+ this instanceof CS:: DivExpr and result = TDivOp ( )
99+ or
100+ this instanceof CS:: RemExpr and result = TRemOp ( )
101+ or
102+ this instanceof CS:: BitwiseAndExpr and result = TBitAndOp ( )
103+ or
104+ this instanceof CS:: BitwiseOrExpr and result = TBitOrOp ( )
105+ or
106+ this instanceof CS:: BitwiseXorExpr and result = TBitXorOp ( )
107+ or
108+ this instanceof CS:: LShiftExpr and result = TLShiftOp ( )
109+ or
110+ this instanceof CS:: RShiftExpr and result = TRShiftOp ( )
111+ }
112+ }
46113
47114 predicate ssaRead = SU:: ssaRead / 2 ;
48115}
@@ -203,7 +270,7 @@ private module Impl {
203270 }
204271
205272 /** Returns a sub expression of `e` for expression types where the sign depends on the child. */
206- Expr getASubExpr ( Expr e ) {
273+ Expr getASubExprWithSameSign ( Expr e ) {
207274 result = e .( AssignExpr ) .getRValue ( ) or
208275 result = e .( AssignOperation ) .getExpandedAssignment ( ) or
209276 result = e .( UnaryPlusExpr ) .getOperand ( ) or
@@ -218,74 +285,6 @@ private module Impl {
218285 result = e .( CastExpr ) .getExpr ( )
219286 }
220287
221- /** Class to represent unary expressions. */
222- class UnaryExpr extends Expr {
223- UnaryExpr ( ) {
224- this instanceof PreIncrExpr or
225- this instanceof PreDecrExpr or
226- this instanceof UnaryMinusExpr or
227- this instanceof ComplementExpr
228- }
229-
230- /** Returns the operand of this expression. */
231- Expr getOperand ( ) {
232- result = this .( PreIncrExpr ) .getOperand ( ) or
233- result = this .( PreDecrExpr ) .getOperand ( ) or
234- result = this .( UnaryMinusExpr ) .getOperand ( ) or
235- result = this .( ComplementExpr ) .getOperand ( )
236- }
237-
238- /** Returns the operation representing this expression. */
239- TUnarySignOperation getOp ( ) {
240- this instanceof PreIncrExpr and result = TIncOp ( )
241- or
242- this instanceof PreDecrExpr and result = TDecOp ( )
243- or
244- this instanceof UnaryMinusExpr and result = TNegOp ( )
245- or
246- this instanceof ComplementExpr and result = TBitNotOp ( )
247- }
248- }
249-
250- /** Class to represent binary expressions. */
251- class BinaryExpr extends Expr {
252- BinaryExpr ( ) {
253- this instanceof AddExpr or
254- this instanceof SubExpr or
255- this instanceof MulExpr or
256- this instanceof DivExpr or
257- this instanceof RemExpr or
258- this instanceof BitwiseAndExpr or
259- this instanceof BitwiseOrExpr or
260- this instanceof BitwiseXorExpr or
261- this instanceof LShiftExpr or
262- this instanceof RShiftExpr
263- }
264-
265- /** Returns the operation representing this expression. */
266- TBinarySignOperation getOp ( ) {
267- this instanceof AddExpr and result = TAddOp ( )
268- or
269- this instanceof SubExpr and result = TSubOp ( )
270- or
271- this instanceof MulExpr and result = TMulOp ( )
272- or
273- this instanceof DivExpr and result = TDivOp ( )
274- or
275- this instanceof RemExpr and result = TRemOp ( )
276- or
277- this instanceof BitwiseAndExpr and result = TBitAndOp ( )
278- or
279- this instanceof BitwiseOrExpr and result = TBitOrOp ( )
280- or
281- this instanceof BitwiseXorExpr and result = TBitXorOp ( )
282- or
283- this instanceof LShiftExpr and result = TLShiftOp ( )
284- or
285- this instanceof RShiftExpr and result = TRShiftOp ( )
286- }
287- }
288-
289288 Expr getARead ( Ssa:: Definition v ) { result = v .getARead ( ) }
290289
291290 Field getField ( FieldAccess fa ) { result = fa .getTarget ( ) }
0 commit comments