@@ -20,14 +20,51 @@ class ShiftExpr extends BinaryBitwiseOperation {
2020  ShiftExpr ( )  {  this  instanceof  LShiftExpr  or  this  instanceof  RShiftExpr  } 
2121} 
2222
23- from  ShiftExpr  e ,  Expr  right ,  int  max_val 
23+ MacroInvocation  getAMacroInvocation ( ShiftExpr  se )  {  result .getAnExpandedElement ( )  =  se  } 
24+ 
25+ Macro  getPrimaryMacro ( ShiftExpr  se )  { 
26+   exists ( MacroInvocation  mi  | 
27+     mi  =  getAMacroInvocation ( se )  and 
28+     not  exists ( MacroInvocation  otherMi  | 
29+       otherMi  =  getAMacroInvocation ( se )  and  otherMi .getParentInvocation ( )  =  mi 
30+     )  and 
31+     result  =  mi .getMacro ( ) 
32+   ) 
33+ } 
34+ 
35+ from 
36+   ShiftExpr  e ,  Expr  right ,  int  max_val ,  float  lowerBound ,  float  upperBound ,  Type  essentialType , 
37+   string  extraMessage ,  Locatable  optionalPlaceholderLocation ,  string  optionalPlaceholderMessage 
2438where 
2539  not  isExcluded ( right ,  Contracts7Package:: rightHandOperandOfAShiftRangeQuery ( ) )  and 
2640  right  =  e .getRightOperand ( ) .getFullyConverted ( )  and 
27-   max_val  =  ( 8  *  getEssentialType ( e .getLeftOperand ( ) ) .getSize ( ) )  -  1  and 
41+   essentialType  =  getEssentialType ( e .getLeftOperand ( ) )  and 
42+   max_val  =  ( 8  *  essentialType .getSize ( ) )  -  1  and 
43+   upperBound  =  upperBound ( right )  and 
44+   lowerBound  =  lowerBound ( right )  and 
45+   ( 
46+     lowerBound  <  0  or 
47+     upperBound  >  max_val 
48+   )  and 
49+   // If this shift happens inside a macro, then report the macro as well 
50+   // for easier validation 
2851  ( 
29-     lowerBound ( right )  <  0  or 
30-     upperBound ( right )  >  max_val 
52+     if  exists ( getPrimaryMacro ( e ) ) 
53+     then 
54+       extraMessage  =  " from expansion of macro $@"  and 
55+       exists ( Macro  m  | 
56+         m  =  getPrimaryMacro ( e )  and 
57+         optionalPlaceholderLocation  =  m  and 
58+         optionalPlaceholderMessage  =  m .getName ( ) 
59+       ) 
60+     else  ( 
61+       extraMessage  =  ""  and 
62+       optionalPlaceholderLocation  =  e  and 
63+       optionalPlaceholderMessage  =  "" 
64+     ) 
3165  ) 
3266select  right , 
33-   "The right hand operand of the shift operator shall lie in the range 0 to "  +  max_val  +  "." 
67+   "The possible range of the right operand of the shift operator ("  +  lowerBound  +  ".."  +  upperBound 
68+     +  ") is outside the the valid shift range (0.."  +  max_val  + 
69+     ") for the essential type of the left operand ("  +  essentialType  +  ")"  +  extraMessage  +  "." , 
70+   optionalPlaceholderLocation ,  optionalPlaceholderMessage 
0 commit comments