Browse code

script engine: keep file pos. info when optimizing

- try to keep a reasonable value for an optimized rv. expression
script file position
- fix file position in debugging messages

Andrei Pelinescu-Onciul authored on 18/12/2008 12:33:57
Showing 1 changed files
... ...
@@ -2007,6 +2007,7 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type)
2007 2007
 	int i;
2008 2008
 	int ret;
2009 2009
 	enum rval_expr_op op;
2010
+	struct cfg_pos pos;
2010 2011
 	int right; /* debugging msg */
2011 2012
 	
2012 2013
 	rv=0;
... ...
@@ -2046,7 +2047,9 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type)
2046 2046
 					/* $v *  1 -> $v
2047 2047
 					 *  1 * $v -> $v */
2048 2048
 					rve_destroy(ct_rve);
2049
+					pos=rve->fpos;
2049 2050
 					*rve=*v_rve; /* replace current expr. with $v */
2051
+					rve->fpos=pos;
2050 2052
 					pkg_free(v_rve);/* rve_destroy(v_rve) would free
2051 2053
 									   everything*/
2052 2054
 					ret=1;
... ...
@@ -2068,7 +2071,9 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type)
2068 2068
 					if (ct_rve==rve->right.rve){
2069 2069
 						/* $v / 1 -> $v */
2070 2070
 						rve_destroy(ct_rve);
2071
+						pos=rve->fpos;
2071 2072
 						*rve=*v_rve; /* replace current expr. with $v */
2073
+						rve->fpos=pos;
2072 2074
 						pkg_free(v_rve);/* rve_destroy(v_rve) would free
2073 2075
 										   everything*/
2074 2076
 						ret=1;
... ...
@@ -2080,7 +2085,9 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type)
2080 2080
 					if (ct_rve==rve->right.rve){
2081 2081
 						/* $v - 0 -> $v */
2082 2082
 						rve_destroy(ct_rve);
2083
+						pos=rve->fpos;
2083 2084
 						*rve=*v_rve; /* replace current expr. with $v */
2085
+						rve->fpos=pos;
2084 2086
 						pkg_free(v_rve);/* rve_destroy(v_rve) would free
2085 2087
 										   everything*/
2086 2088
 						ret=1;
... ...
@@ -2104,7 +2111,9 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type)
2104 2104
 					/* $v |  0 -> $v
2105 2105
 					 *  0 | $v -> $v */
2106 2106
 					rve_destroy(ct_rve);
2107
+					pos=rve->fpos;
2107 2108
 					*rve=*v_rve; /* replace current expr. with $v */
2109
+					rve->fpos=pos;
2108 2110
 					pkg_free(v_rve);/* rve_destroy(v_rve) would free
2109 2111
 									   everything*/
2110 2112
 					ret=1;
... ...
@@ -2121,7 +2130,9 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type)
2121 2121
 					/* $v &&  1 -> $v
2122 2122
 					 *  1 && $v -> $v */
2123 2123
 					rve_destroy(ct_rve);
2124
+					pos=rve->fpos;
2124 2125
 					*rve=*v_rve; /* replace current expr. with $v */
2126
+					rve->fpos=pos;
2125 2127
 					pkg_free(v_rve);/* rve_destroy(v_rve) would free
2126 2128
 									   everything*/
2127 2129
 					ret=1;
... ...
@@ -2138,7 +2149,9 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type)
2138 2138
 					/* $v ||  0 -> $v
2139 2139
 					 *  0 && $v -> $v */
2140 2140
 					rve_destroy(ct_rve);
2141
+					pos=rve->fpos;
2141 2142
 					*rve=*v_rve; /* replace current expr. with $v */
2143
+					rve->fpos=pos;
2142 2144
 					pkg_free(v_rve);/* rve_destroy(v_rve) would free
2143 2145
 									   everything*/
2144 2146
 					ret=1;
... ...
@@ -2151,7 +2164,9 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type)
2151 2151
 					/* $v +  0 -> $v
2152 2152
 					 *  0 + $v -> $v */
2153 2153
 					rve_destroy(ct_rve);
2154
+					pos=rve->fpos;
2154 2155
 					*rve=*v_rve; /* replace current expr. with $v */
2156
+					rve->fpos=pos;
2155 2157
 					pkg_free(v_rve);/* rve_destroy(v_rve) would free
2156 2158
 									   everything*/
2157 2159
 					ret=1;
... ...
@@ -2168,26 +2183,26 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type)
2168 2168
 					DBG("FIXUP RVE: (%d,%d-%d,%d) optimized"
2169 2169
 							" op%d($v, %d) -> %d\n", 
2170 2170
 							rve->fpos.s_line, rve->fpos.s_col,
2171
-							rve->fpos.e_line, rve->fpos.s_col,
2171
+							rve->fpos.e_line, rve->fpos.e_col,
2172 2172
 							op, i, (int)rve->left.rval.v.l);
2173 2173
 				else
2174 2174
 					DBG("FIXUP RVE: (%d,%d-%d,%d) optimized"
2175 2175
 							" op%d($v, %d) -> $v\n",
2176 2176
 							rve->fpos.s_line, rve->fpos.s_col,
2177
-							rve->fpos.e_line, rve->fpos.s_col,
2177
+							rve->fpos.e_line, rve->fpos.e_col,
2178 2178
 							op, i);
2179 2179
 			}else{
2180 2180
 				if ((rve->op==RVE_RVAL_OP) && (rve->left.rval.type==RV_INT))
2181 2181
 					DBG("FIXUP RVE: (%d,%d-%d,%d) optimized"
2182 2182
 							" op%d(%d, $v) -> %d\n", 
2183 2183
 							rve->fpos.s_line, rve->fpos.s_col,
2184
-							rve->fpos.e_line, rve->fpos.s_col,
2184
+							rve->fpos.e_line, rve->fpos.e_col,
2185 2185
 							op, i, (int)rve->left.rval.v.l);
2186 2186
 				else
2187 2187
 					DBG("FIXUP RVE: (%d,%d-%d,%d) optimized"
2188 2188
 							" op%d(%d, $v) -> $v\n",
2189 2189
 							rve->fpos.s_line, rve->fpos.s_col,
2190
-							rve->fpos.e_line, rve->fpos.s_col,
2190
+							rve->fpos.e_line, rve->fpos.e_col,
2191 2191
 							op, i);
2192 2192
 			}
2193 2193
 		}