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 2047
 					/* $v *  1 -> $v
2047 2048
 					 *  1 * $v -> $v */
2048 2049
 					rve_destroy(ct_rve);
2050
+					pos=rve->fpos;
2049 2051
 					*rve=*v_rve; /* replace current expr. with $v */
2052
+					rve->fpos=pos;
2050 2053
 					pkg_free(v_rve);/* rve_destroy(v_rve) would free
2051 2054
 									   everything*/
2052 2055
 					ret=1;
... ...
@@ -2068,7 +2071,9 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type)
2068 2071
 					if (ct_rve==rve->right.rve){
2069 2072
 						/* $v / 1 -> $v */
2070 2073
 						rve_destroy(ct_rve);
2074
+						pos=rve->fpos;
2071 2075
 						*rve=*v_rve; /* replace current expr. with $v */
2076
+						rve->fpos=pos;
2072 2077
 						pkg_free(v_rve);/* rve_destroy(v_rve) would free
2073 2078
 										   everything*/
2074 2079
 						ret=1;
... ...
@@ -2080,7 +2085,9 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type)
2080 2085
 					if (ct_rve==rve->right.rve){
2081 2086
 						/* $v - 0 -> $v */
2082 2087
 						rve_destroy(ct_rve);
2088
+						pos=rve->fpos;
2083 2089
 						*rve=*v_rve; /* replace current expr. with $v */
2090
+						rve->fpos=pos;
2084 2091
 						pkg_free(v_rve);/* rve_destroy(v_rve) would free
2085 2092
 										   everything*/
2086 2093
 						ret=1;
... ...
@@ -2104,7 +2111,9 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type)
2104 2111
 					/* $v |  0 -> $v
2105 2112
 					 *  0 | $v -> $v */
2106 2113
 					rve_destroy(ct_rve);
2114
+					pos=rve->fpos;
2107 2115
 					*rve=*v_rve; /* replace current expr. with $v */
2116
+					rve->fpos=pos;
2108 2117
 					pkg_free(v_rve);/* rve_destroy(v_rve) would free
2109 2118
 									   everything*/
2110 2119
 					ret=1;
... ...
@@ -2121,7 +2130,9 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type)
2121 2130
 					/* $v &&  1 -> $v
2122 2131
 					 *  1 && $v -> $v */
2123 2132
 					rve_destroy(ct_rve);
2133
+					pos=rve->fpos;
2124 2134
 					*rve=*v_rve; /* replace current expr. with $v */
2135
+					rve->fpos=pos;
2125 2136
 					pkg_free(v_rve);/* rve_destroy(v_rve) would free
2126 2137
 									   everything*/
2127 2138
 					ret=1;
... ...
@@ -2138,7 +2149,9 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type)
2138 2149
 					/* $v ||  0 -> $v
2139 2150
 					 *  0 && $v -> $v */
2140 2151
 					rve_destroy(ct_rve);
2152
+					pos=rve->fpos;
2141 2153
 					*rve=*v_rve; /* replace current expr. with $v */
2154
+					rve->fpos=pos;
2142 2155
 					pkg_free(v_rve);/* rve_destroy(v_rve) would free
2143 2156
 									   everything*/
2144 2157
 					ret=1;
... ...
@@ -2151,7 +2164,9 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type)
2151 2164
 					/* $v +  0 -> $v
2152 2165
 					 *  0 + $v -> $v */
2153 2166
 					rve_destroy(ct_rve);
2167
+					pos=rve->fpos;
2154 2168
 					*rve=*v_rve; /* replace current expr. with $v */
2169
+					rve->fpos=pos;
2155 2170
 					pkg_free(v_rve);/* rve_destroy(v_rve) would free
2156 2171
 									   everything*/
2157 2172
 					ret=1;
... ...
@@ -2168,26 +2183,26 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type)
2168 2183
 					DBG("FIXUP RVE: (%d,%d-%d,%d) optimized"
2169 2184
 							" op%d($v, %d) -> %d\n", 
2170 2185
 							rve->fpos.s_line, rve->fpos.s_col,
2171
-							rve->fpos.e_line, rve->fpos.s_col,
2186
+							rve->fpos.e_line, rve->fpos.e_col,
2172 2187
 							op, i, (int)rve->left.rval.v.l);
2173 2188
 				else
2174 2189
 					DBG("FIXUP RVE: (%d,%d-%d,%d) optimized"
2175 2190
 							" op%d($v, %d) -> $v\n",
2176 2191
 							rve->fpos.s_line, rve->fpos.s_col,
2177
-							rve->fpos.e_line, rve->fpos.s_col,
2192
+							rve->fpos.e_line, rve->fpos.e_col,
2178 2193
 							op, i);
2179 2194
 			}else{
2180 2195
 				if ((rve->op==RVE_RVAL_OP) && (rve->left.rval.type==RV_INT))
2181 2196
 					DBG("FIXUP RVE: (%d,%d-%d,%d) optimized"
2182 2197
 							" op%d(%d, $v) -> %d\n", 
2183 2198
 							rve->fpos.s_line, rve->fpos.s_col,
2184
-							rve->fpos.e_line, rve->fpos.s_col,
2199
+							rve->fpos.e_line, rve->fpos.e_col,
2185 2200
 							op, i, (int)rve->left.rval.v.l);
2186 2201
 				else
2187 2202
 					DBG("FIXUP RVE: (%d,%d-%d,%d) optimized"
2188 2203
 							" op%d(%d, $v) -> $v\n",
2189 2204
 							rve->fpos.s_line, rve->fpos.s_col,
2190
-							rve->fpos.e_line, rve->fpos.s_col,
2205
+							rve->fpos.e_line, rve->fpos.e_col,
2191 2206
 							op, i);
2192 2207
 			}
2193 2208
 		}