Imported Debian patch 0.13.1-3
[pkg-lisaac.git] / src / external / arithmetic / expr_shift_r.li
blobd40614cb434f23d7bac3f327be51a6b23cfa636f
1 ///////////////////////////////////////////////////////////////////////////////
2 //                             Lisaac Compiler                               //
3 //                                                                           //
4 //                   LSIIT - ULP - CNRS - INRIA - FRANCE                     //
5 //                                                                           //
6 //   This program is free software: you can redistribute it and/or modify    //
7 //   it under the terms of the GNU General Public License as published by    //
8 //   the Free Software Foundation, either version 3 of the License, or       //
9 //   (at your option) any later version.                                     //
10 //                                                                           //
11 //   This program is distributed in the hope that it will be useful,         //
12 //   but WITHOUT ANY WARRANTY; without even the implied warranty of          //
13 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
14 //   GNU General Public License for more details.                            //
15 //                                                                           //
16 //   You should have received a copy of the GNU General Public License       //
17 //   along with this program.  If not, see <http://www.gnu.org/licenses/>.   //
18 //                                                                           //
19 //                     http://isaacproject.u-strasbg.fr/                     //
20 ///////////////////////////////////////////////////////////////////////////////
21 Section Header
22   
23   + name        := EXPR_SHIFT_R;
25   - copyright   := "2003-2007 Benoit Sonntag";
27   
28   - author      := "Sonntag Benoit (bsonntag@loria.fr)";
29   - comment     := "Add Binary Expression.";
30   
31 Section Inherit
32   
33   + parent_expr_binary:Expanded EXPR_BINARY;
34   
35 Section Private  
36   
37   + symbol:STRING_CONSTANT := ">>";
38   
39   //
40   // Execute.
41   //
42   
43   - exec_conservator_right right_cst:INTEGER_CST :EXPR <- 
44   //-- E >>  0 -> E  
45   ( + result:EXPR;
46     
47     (right_cst.value = 0).if {
48       result := left;
49       right_cst.remove;
50     };
51     result
52   );
53   
54   - exec left_cst:INTEGER_CST and right_cst:INTEGER_CST :EXPR <- 
55   //-- C1 >> C2  -> C3
56   //-- C1 >> -C2 -> Error.
57   (
58     (right_cst.value < 0).if {
59       warning_error (position,"Right shift count is negative.");
60       left_cst.set_value 0;
61     } else {
62       left_cst.set_value (left_cst.value >> right_cst.value); 
63     };
64     right_cst.remove;
65     left_cst
66   );
67   
68   - exec:EXPR <-
69   //-- E(unsigned) >> E(unsigned) -> 0
70   ( + result:EXPR;
71     /*
72     (left == right) && {left.is_unsigned_type}.if {
73       result := INTEGER_CST.create position value 0 type static_type;
74       left .remove;
75       right.remove;
76     };
77     */
78     result
79   );
80   
81   - exec_left  left_cst:INTEGER_CST :EXPR <- 
82   //-- 0 >> E            -> 0
83   //-- -1(signed) >> E   -> -1(signed)
84   ( + result:EXPR;
85     
86     (left_cst.value = 0).if {
87       result := left_cst;
88       right.remove;
89     }.elseif {left_cst.value = -1} then {
90       result := left_cst;
91       right.remove;
92     };
93     result
94   );
95   
96   - exec_right right_cst:INTEGER_CST :EXPR <- 
97   //-- E >> -C2 -> Error.
98   ( + result:EXPR;
99     
100     (right_cst.value < 0).if {
101       warning_error (position,"Right shift count is negative.");
102       right_cst.set_value 0;
103       right_cst.cast_type static_type;
104       result := right_cst;
105       left.remove;
106     };
107     result
108   );
109   
110   
111   
112