- fix missing cast for the $v <op> c -> $v optimizations
(e.g. $v - 0 -> $v, 1 * $v -> $v): instead of replacing
$v <op> c with $v use (type_of(<op>)) $v. $v without the cast
to the type produced by the operator is used now only when
type_of($v)==type_of(<op>).
E.g.: 1 * $v -> (int)$v
1 * ($v/$w) -> $v/$w ($v/$w produces always an int, so no
need for the cast)
Bug example: 1*"2"+3 was optimized to "2"+3 == "23" instead of
(int)"2"+3 == 5.
- better debugging messages
... | ... |
@@ -2792,6 +2792,37 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type) |
2792 | 2792 |
enum rval_expr_op op; |
2793 | 2793 |
struct cfg_pos pos; |
2794 | 2794 |
int right; /* debugging msg */ |
2795 |
+ |
|
2796 |
+/* helper macro: replace in-place a <ctype> type rve with v (another rve). |
|
2797 |
+ * if type_of(v)== <ctype> => rve:=*v (copy v contents into rve and free v) |
|
2798 |
+ * else if type_of(v)!=<ctype> => rve:= (ctype) v (casts v to <ctype>) |
|
2799 |
+ * Uses pos. |
|
2800 |
+ * ctype can be INT or STR |
|
2801 |
+ * WARNING: - v might be pkg_free()'d |
|
2802 |
+ * - rve members _are_ _not_ freed or destroyed |
|
2803 |
+ */ |
|
2804 |
+#define replace_rve_type_cast(e, v, ctype) \ |
|
2805 |
+ do{\ |
|
2806 |
+ if ( rve_guess_type((v)) == RV_##ctype ){\ |
|
2807 |
+ /* if type_of($v)==int we don't need to add an \ |
|
2808 |
+ int cast operator => replace with v */\ |
|
2809 |
+ pos=(e)->fpos; \ |
|
2810 |
+ *(e)=*(v); /* replace e with v (in-place) */ \ |
|
2811 |
+ (e)->fpos=pos; \ |
|
2812 |
+ pkg_free((v)); /* rve_destroy(v_rve) would free everything*/ \ |
|
2813 |
+ }else{\ |
|
2814 |
+ /* unknown type or str => (int) $v */ \ |
|
2815 |
+ (e)->op=RVE_##ctype##_OP; \ |
|
2816 |
+ (e)->left.rve=(v); \ |
|
2817 |
+ (e)->right.rve=0; \ |
|
2818 |
+ }\ |
|
2819 |
+ }while(0) |
|
2820 |
+ |
|
2821 |
+/* helper macro: replace in-place an int type rve with v (another rve).*/ |
|
2822 |
+#define replace_int_rve(e, v) replace_rve_type_cast(e, v, INT) |
|
2823 |
+/* helper macro: replace in-place a str type rve with v (another rve).*/ |
|
2824 |
+#define replace_str_rve(e, v) replace_rve_type_cast(e, v, STR) |
|
2825 |
+ |
|
2795 | 2826 |
|
2796 | 2827 |
rv=0; |
2797 | 2828 |
ret=0; |
... | ... |
@@ -2827,14 +2858,10 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type) |
2827 | 2858 |
goto error; |
2828 | 2859 |
ret=1; |
2829 | 2860 |
}else if (i==1){ |
2830 |
- /* $v * 1 -> $v |
|
2831 |
- * 1 * $v -> $v */ |
|
2861 |
+ /* $v * 1 -> (int)$v |
|
2862 |
+ * 1 * $v -> (int)$v */ |
|
2832 | 2863 |
rve_destroy(ct_rve); |
2833 |
- pos=rve->fpos; |
|
2834 |
- *rve=*v_rve; /* replace current expr. with $v */ |
|
2835 |
- rve->fpos=pos; |
|
2836 |
- pkg_free(v_rve);/* rve_destroy(v_rve) would free |
|
2837 |
- everything*/ |
|
2864 |
+ replace_int_rve(rve, v_rve); |
|
2838 | 2865 |
ret=1; |
2839 | 2866 |
} |
2840 | 2867 |
break; |
... | ... |
@@ -2852,13 +2879,9 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type) |
2852 | 2879 |
} |
2853 | 2880 |
}else if (i==1){ |
2854 | 2881 |
if (ct_rve==rve->right.rve){ |
2855 |
- /* $v / 1 -> $v */ |
|
2882 |
+ /* $v / 1 -> (int)$v */ |
|
2856 | 2883 |
rve_destroy(ct_rve); |
2857 |
- pos=rve->fpos; |
|
2858 |
- *rve=*v_rve; /* replace current expr. with $v */ |
|
2859 |
- rve->fpos=pos; |
|
2860 |
- pkg_free(v_rve);/* rve_destroy(v_rve) would free |
|
2861 |
- everything*/ |
|
2884 |
+ replace_int_rve(rve, v_rve); |
|
2862 | 2885 |
ret=1; |
2863 | 2886 |
} |
2864 | 2887 |
} |
... | ... |
@@ -2868,11 +2891,7 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type) |
2868 | 2891 |
if (ct_rve==rve->right.rve){ |
2869 | 2892 |
/* $v - 0 -> $v */ |
2870 | 2893 |
rve_destroy(ct_rve); |
2871 |
- pos=rve->fpos; |
|
2872 |
- *rve=*v_rve; /* replace current expr. with $v */ |
|
2873 |
- rve->fpos=pos; |
|
2874 |
- pkg_free(v_rve);/* rve_destroy(v_rve) would free |
|
2875 |
- everything*/ |
|
2894 |
+ replace_int_rve(rve, v_rve); |
|
2876 | 2895 |
ret=1; |
2877 | 2896 |
} |
2878 | 2897 |
/* ? 0 - $v -> -($v) ? */ |
... | ... |
@@ -2886,19 +2905,15 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type) |
2886 | 2905 |
goto error; |
2887 | 2906 |
ret=1; |
2888 | 2907 |
} |
2889 |
- /* no 0xffffff optimization for now (haven't decide on |
|
2908 |
+ /* no 0xffffff optimization for now (haven't decided on |
|
2890 | 2909 |
the number of bits ) */ |
2891 | 2910 |
break; |
2892 | 2911 |
case RVE_BOR_OP: |
2893 | 2912 |
if (i==0){ |
2894 |
- /* $v | 0 -> $v |
|
2895 |
- * 0 | $v -> $v */ |
|
2913 |
+ /* $v | 0 -> (int)$v |
|
2914 |
+ * 0 | $v -> (int)$v */ |
|
2896 | 2915 |
rve_destroy(ct_rve); |
2897 |
- pos=rve->fpos; |
|
2898 |
- *rve=*v_rve; /* replace current expr. with $v */ |
|
2899 |
- rve->fpos=pos; |
|
2900 |
- pkg_free(v_rve);/* rve_destroy(v_rve) would free |
|
2901 |
- everything*/ |
|
2916 |
+ replace_int_rve(rve, v_rve); |
|
2902 | 2917 |
ret=1; |
2903 | 2918 |
} |
2904 | 2919 |
break; |
... | ... |
@@ -2910,14 +2925,10 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type) |
2910 | 2925 |
goto error; |
2911 | 2926 |
ret=1; |
2912 | 2927 |
}else if (i==1){ |
2913 |
- /* $v && 1 -> $v |
|
2914 |
- * 1 && $v -> $v */ |
|
2928 |
+ /* $v && 1 -> (int)$v |
|
2929 |
+ * 1 && $v -> (int)$v */ |
|
2915 | 2930 |
rve_destroy(ct_rve); |
2916 |
- pos=rve->fpos; |
|
2917 |
- *rve=*v_rve; /* replace current expr. with $v */ |
|
2918 |
- rve->fpos=pos; |
|
2919 |
- pkg_free(v_rve);/* rve_destroy(v_rve) would free |
|
2920 |
- everything*/ |
|
2931 |
+ replace_int_rve(rve, v_rve); |
|
2921 | 2932 |
ret=1; |
2922 | 2933 |
} |
2923 | 2934 |
break; |
... | ... |
@@ -2929,41 +2940,25 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type) |
2929 | 2940 |
goto error; |
2930 | 2941 |
ret=1; |
2931 | 2942 |
}else if (i==0){ |
2932 |
- /* $v || 0 -> $v |
|
2933 |
- * 0 && $v -> $v */ |
|
2943 |
+ /* $v || 0 -> (int)$v |
|
2944 |
+ * 0 && $v -> (int)$v */ |
|
2934 | 2945 |
rve_destroy(ct_rve); |
2935 |
- pos=rve->fpos; |
|
2936 |
- *rve=*v_rve; /* replace current expr. with $v */ |
|
2937 |
- rve->fpos=pos; |
|
2938 |
- pkg_free(v_rve);/* rve_destroy(v_rve) would free |
|
2939 |
- everything*/ |
|
2946 |
+ replace_int_rve(rve, v_rve); |
|
2940 | 2947 |
ret=1; |
2941 | 2948 |
} |
2942 | 2949 |
break; |
2943 | 2950 |
case RVE_PLUS_OP: |
2944 | 2951 |
case RVE_IPLUS_OP: |
2945 | 2952 |
/* we must make sure that this is an int PLUS |
2946 |
- (because "foo"+0 is valid => "foo0") |
|
2947 |
- Even if overall type is RV_INT, it's still not safe |
|
2948 |
- to optimize a generic PLUS: 0 + $v is not always equivalent |
|
2949 |
- to $v (e.g. 0+"1" ==1 != "1") => optimize only if |
|
2950 |
- IPLUS (always safe since it converts to int first) or |
|
2951 |
- if generic PLUS and result is integer (rve_type) and |
|
2952 |
- expression is of the form $v+ct (and not ct+$v). |
|
2953 |
- TODO: dropping PLUS_OP all together and relying on the |
|
2954 |
- optimizer replacing safe PLUS_OP with IPLUS_OP or CONCAT_OP |
|
2955 |
- will simplify things. |
|
2953 |
+ (because "foo"+0 is valid => "foo0") => |
|
2954 |
+ check if it's an IPLUS or the result is an integer |
|
2955 |
+ (which generally means unoptimized <int> + <something>). |
|
2956 | 2956 |
*/ |
2957 |
- if ((i==0) && ((op==RVE_IPLUS_OP)|| |
|
2958 |
- (rve_type==RV_INT && ct_rve==rve->right.rve))){ |
|
2959 |
- /* $v + 0 -> $v |
|
2960 |
- * 0 + $v -> $v */ |
|
2957 |
+ if ((i==0) && ((op==RVE_IPLUS_OP) || (rve_type==RV_INT))){ |
|
2958 |
+ /* $v + 0 -> (int)$v |
|
2959 |
+ * 0 + $v -> (int)$v */ |
|
2961 | 2960 |
rve_destroy(ct_rve); |
2962 |
- pos=rve->fpos; |
|
2963 |
- *rve=*v_rve; /* replace current expr. with $v */ |
|
2964 |
- rve->fpos=pos; |
|
2965 |
- pkg_free(v_rve);/* rve_destroy(v_rve) would free |
|
2966 |
- everything*/ |
|
2961 |
+ replace_int_rve(rve, v_rve); |
|
2967 | 2962 |
ret=1; |
2968 | 2963 |
} |
2969 | 2964 |
break; |
... | ... |
@@ -2974,45 +2969,85 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type) |
2974 | 2969 |
/* debugging messages */ |
2975 | 2970 |
if (ret==1){ |
2976 | 2971 |
if (right){ |
2977 |
- if ((rve->op==RVE_RVAL_OP) && (rve->left.rval.type==RV_INT)) |
|
2978 |
- DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
2979 |
- " op%d($v, %d) -> %d\n", |
|
2980 |
- rve->fpos.s_line, rve->fpos.s_col, |
|
2981 |
- rve->fpos.e_line, rve->fpos.e_col, |
|
2982 |
- op, i, (int)rve->left.rval.v.l); |
|
2983 |
- else |
|
2972 |
+ if (rve->op==RVE_RVAL_OP){ |
|
2973 |
+ if (rve->left.rval.type==RV_INT) |
|
2974 |
+ DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
2975 |
+ " op%d($v, %d) -> %d\n", |
|
2976 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
2977 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
2978 |
+ op, i, (int)rve->left.rval.v.l); |
|
2979 |
+ else |
|
2980 |
+ DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
2981 |
+ " op%d($v, %d) -> $v (rval)\n", |
|
2982 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
2983 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
2984 |
+ op, i); |
|
2985 |
+ }else if (rve->op==RVE_INT_OP){ |
|
2986 |
+ if (rve->left.rve->op==RVE_RVAL_OP && |
|
2987 |
+ rve->left.rve->left.rval.type==RV_INT) |
|
2988 |
+ DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
2989 |
+ " op%d($v, %d) -> (int)%d\n", |
|
2990 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
2991 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
2992 |
+ op, i, (int)rve->left.rve->left.rval.v.l); |
|
2993 |
+ else |
|
2994 |
+ DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
2995 |
+ " op%d($v, %d) -> (int)$v\n", |
|
2996 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
2997 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
2998 |
+ op, i); |
|
2999 |
+ }else{ |
|
2984 | 3000 |
DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
2985 | 3001 |
" op%d($v, %d) -> $v\n", |
2986 | 3002 |
rve->fpos.s_line, rve->fpos.s_col, |
2987 | 3003 |
rve->fpos.e_line, rve->fpos.e_col, |
2988 | 3004 |
op, i); |
3005 |
+ } |
|
2989 | 3006 |
}else{ |
2990 |
- if ((rve->op==RVE_RVAL_OP) && (rve->left.rval.type==RV_INT)) |
|
2991 |
- DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
2992 |
- " op%d(%d, $v) -> %d\n", |
|
2993 |
- rve->fpos.s_line, rve->fpos.s_col, |
|
2994 |
- rve->fpos.e_line, rve->fpos.e_col, |
|
2995 |
- op, i, (int)rve->left.rval.v.l); |
|
2996 |
- else |
|
3007 |
+ if (rve->op==RVE_RVAL_OP){ |
|
3008 |
+ if (rve->left.rval.type==RV_INT) |
|
3009 |
+ DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
3010 |
+ " op%d(%d, $v) -> %d\n", |
|
3011 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3012 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3013 |
+ op, i, (int)rve->left.rval.v.l); |
|
3014 |
+ else |
|
3015 |
+ DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
3016 |
+ " op%d(%d, $v) -> $v (rval)\n", |
|
3017 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3018 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3019 |
+ op, i); |
|
3020 |
+ }else if (rve->op==RVE_INT_OP){ |
|
3021 |
+ if (rve->left.rve->op==RVE_RVAL_OP && |
|
3022 |
+ rve->left.rve->left.rval.type==RV_INT) |
|
3023 |
+ DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
3024 |
+ " op%d(%d, $v) -> (int)%d\n", |
|
3025 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3026 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3027 |
+ op, i, (int)rve->left.rve->left.rval.v.l); |
|
3028 |
+ else |
|
3029 |
+ DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
3030 |
+ " op%d(%d, $v) -> (int)$v\n", |
|
3031 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3032 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3033 |
+ op, i); |
|
3034 |
+ }else{ |
|
2997 | 3035 |
DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
2998 | 3036 |
" op%d(%d, $v) -> $v\n", |
2999 | 3037 |
rve->fpos.s_line, rve->fpos.s_col, |
3000 | 3038 |
rve->fpos.e_line, rve->fpos.e_col, |
3001 | 3039 |
op, i); |
3040 |
+ } |
|
3002 | 3041 |
} |
3003 | 3042 |
} |
3004 | 3043 |
}else if (rv->type==RV_STR){ |
3005 | 3044 |
switch(op){ |
3006 | 3045 |
case RVE_CONCAT_OP: |
3007 | 3046 |
if (rv->v.s.len==0){ |
3008 |
- /* $v . "" -> $v |
|
3009 |
- "" . $v -> $v */ |
|
3047 |
+ /* $v . "" -> (str)$v |
|
3048 |
+ "" . $v -> (str)$v */ |
|
3010 | 3049 |
rve_destroy(ct_rve); |
3011 |
- pos=rve->fpos; |
|
3012 |
- *rve=*v_rve; /* replace current expr. with $v */ |
|
3013 |
- rve->fpos=pos; |
|
3014 |
- pkg_free(v_rve);/* rve_destroy(v_rve) would free |
|
3015 |
- everything*/ |
|
3050 |
+ replace_str_rve(rve, v_rve); |
|
3016 | 3051 |
ret=1; |
3017 | 3052 |
} |
3018 | 3053 |
break; |
... | ... |
@@ -3027,18 +3062,89 @@ static int rve_opt_01(struct rval_expr* rve, enum rval_type rve_type) |
3027 | 3062 |
rve->left.rve=v_rve; |
3028 | 3063 |
rve->right.rve=0; |
3029 | 3064 |
ret=1; |
3065 |
+ DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
3066 |
+ " op%d($v, \"\") -> strempty($v)\n", |
|
3067 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3068 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3069 |
+ op); |
|
3030 | 3070 |
} |
3031 | 3071 |
break; |
3032 | 3072 |
default: |
3033 | 3073 |
break; |
3034 | 3074 |
} |
3035 | 3075 |
/* no optimization for generic RVE_PLUS_OP for now, only for RVE_CONCAT_OP |
3036 |
- (We could optimize $v + "" or ""+$v, but this ""+$v is a way |
|
3037 |
- to force convert $v to str , it might mess up type checking |
|
3038 |
- (e.g. errors w/o optimization and no errors with) and it brings |
|
3039 |
- a very small benefit anyway (it's unlikely we'll see a lot of |
|
3040 |
- "") |
|
3041 |
- */ |
|
3076 |
+ (RVE_PLUS_OP should be converted to RVE_CONCAT_OP if it's supposed |
|
3077 |
+ to work on strings. If it's not converted/optimized it means it's type |
|
3078 |
+ can be determined only at runtime => we cannot optimize */ |
|
3079 |
+ |
|
3080 |
+ /* debugging messages */ |
|
3081 |
+ if (ret==1){ |
|
3082 |
+ if (right){ |
|
3083 |
+ if (rve->op==RVE_RVAL_OP){ |
|
3084 |
+ if (rve->left.rval.type==RV_STR) |
|
3085 |
+ DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
3086 |
+ " op%d($v, <string>) -> \"%s\"\n", |
|
3087 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3088 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3089 |
+ op, rve->left.rval.v.s.s); |
|
3090 |
+ else |
|
3091 |
+ DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
3092 |
+ " op%d($v, <string>) -> $v (rval)\n", |
|
3093 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3094 |
+ rve->fpos.e_line, rve->fpos.e_col, op); |
|
3095 |
+ }else if (rve->op==RVE_STR_OP){ |
|
3096 |
+ if (rve->left.rve->op==RVE_RVAL_OP && |
|
3097 |
+ rve->left.rve->left.rval.type==RV_STR) |
|
3098 |
+ DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
3099 |
+ " op%d($v, <string>) -> (str)\"%s\"\n", |
|
3100 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3101 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3102 |
+ op, rve->left.rve->left.rval.v.s.s); |
|
3103 |
+ else |
|
3104 |
+ DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
3105 |
+ " op%d($v, <string>) -> (str)$v\n", |
|
3106 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3107 |
+ rve->fpos.e_line, rve->fpos.e_col, op); |
|
3108 |
+ }else{ |
|
3109 |
+ DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
3110 |
+ " op%d($v, <string>) -> $v\n", |
|
3111 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3112 |
+ rve->fpos.e_line, rve->fpos.e_col, op); |
|
3113 |
+ } |
|
3114 |
+ }else{ |
|
3115 |
+ if (rve->op==RVE_RVAL_OP){ |
|
3116 |
+ if (rve->left.rval.type==RV_STR) |
|
3117 |
+ DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
3118 |
+ " op%d(<string>, $v) -> \"%s\"\n", |
|
3119 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3120 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3121 |
+ op, rve->left.rval.v.s.s); |
|
3122 |
+ else |
|
3123 |
+ DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
3124 |
+ " op%d(<string>, $v) -> $v (rval)\n", |
|
3125 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3126 |
+ rve->fpos.e_line, rve->fpos.e_col, op); |
|
3127 |
+ }else if (rve->op==RVE_STR_OP){ |
|
3128 |
+ if (rve->left.rve->op==RVE_RVAL_OP && |
|
3129 |
+ rve->left.rve->left.rval.type==RV_STR) |
|
3130 |
+ DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
3131 |
+ " op%d(<string>, $v) -> (str)\"%s\"\n", |
|
3132 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3133 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3134 |
+ op, rve->left.rve->left.rval.v.s.s); |
|
3135 |
+ else |
|
3136 |
+ DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
3137 |
+ " op%d(<string>, $v) -> (str)$v\n", |
|
3138 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3139 |
+ rve->fpos.e_line, rve->fpos.e_col, op); |
|
3140 |
+ }else{ |
|
3141 |
+ DBG("FIXUP RVE: (%d,%d-%d,%d) optimized" |
|
3142 |
+ " op%d(<string>, $v) -> $v\n", |
|
3143 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3144 |
+ rve->fpos.e_line, rve->fpos.e_col, op); |
|
3145 |
+ } |
|
3146 |
+ } |
|
3147 |
+ } |
|
3042 | 3148 |
} |
3043 | 3149 |
if (rv) rval_destroy(rv); |
3044 | 3150 |
return ret; |
... | ... |
@@ -3081,11 +3187,17 @@ static int rve_optimize(struct rval_expr* rve) |
3081 | 3187 |
rv=0; |
3082 | 3188 |
trv=&rve->left.rval; |
3083 | 3189 |
if (trv->type==RV_INT) |
3084 |
- DBG("FIXUP RVE: optimized constant int rve (old op %d) to %d\n", |
|
3190 |
+ DBG("FIXUP RVE (%d,%d-%d,%d): optimized constant int rve " |
|
3191 |
+ "(old op %d) to %d\n", |
|
3192 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3193 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3085 | 3194 |
op, (int)trv->v.l); |
3086 | 3195 |
else if (trv->type==RV_STR) |
3087 |
- DBG("FIXUP RVE: optimized constant str rve (old op %d) to" |
|
3088 |
- " \"%.*s\"\n", op, trv->v.s.len, trv->v.s.s); |
|
3196 |
+ DBG("FIXUP RVE (%d,%d-%d,%d): optimized constant str rve " |
|
3197 |
+ "(old op %d) to \"%.*s\"\n", |
|
3198 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3199 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3200 |
+ op, trv->v.s.len, trv->v.s.s); |
|
3089 | 3201 |
ret=1; |
3090 | 3202 |
}else{ |
3091 | 3203 |
/* expression is not constant */ |
... | ... |
@@ -3095,9 +3207,13 @@ static int rve_optimize(struct rval_expr* rve) |
3095 | 3207 |
rve_optimize(rve->left.rve); |
3096 | 3208 |
rve_optimize(rve->right.rve); |
3097 | 3209 |
if (!rve_check_type(&type, rve, &bad_rve, &bad_type, &exp_type)){ |
3098 |
- ERR("optimization failure, type mismatch in expression (%d,%d), " |
|
3210 |
+ ERR("optimization failure while optimizing %d,%d-%d,%d:" |
|
3211 |
+ " type mismatch in expression (%d,%d-%d,%d), " |
|
3099 | 3212 |
"type %s, but expected %s\n", |
3213 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3214 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3100 | 3215 |
bad_rve->fpos.s_line, bad_rve->fpos.s_col, |
3216 |
+ bad_rve->fpos.e_line, bad_rve->fpos.e_col, |
|
3101 | 3217 |
rval_type_name(bad_type), rval_type_name(exp_type)); |
3102 | 3218 |
return 0; |
3103 | 3219 |
} |
... | ... |
@@ -3112,8 +3228,11 @@ static int rve_optimize(struct rval_expr* rve) |
3112 | 3228 |
if (rve_replace_with_ct_rv(rve->right.rve, rv)<0) |
3113 | 3229 |
goto error; |
3114 | 3230 |
rve->op=RVE_IPLUS_OP; |
3115 |
- DBG("FIXUP RVE: optimized $v - a into $v + (%d)\n", |
|
3116 |
- (int)rve->right.rve->left.rval.v.l); |
|
3231 |
+ DBG("FIXUP RVE (%d,%d-%d,%d): optimized $v - a into " |
|
3232 |
+ "$v + (%d)\n", |
|
3233 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3234 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3235 |
+ (int)rve->right.rve->left.rval.v.l); |
|
3117 | 3236 |
} |
3118 | 3237 |
rval_destroy(rv); |
3119 | 3238 |
rv=0; |
... | ... |
@@ -3124,7 +3243,7 @@ static int rve_optimize(struct rval_expr* rve) |
3124 | 3243 |
l_type=rve_guess_type(rve->left.rve); |
3125 | 3244 |
if (l_type==RV_INT){ |
3126 | 3245 |
rve->op=RVE_IPLUS_OP; |
3127 |
- DBG("FIXUP RVE (%d,%d-%d,%d): changed + into interger plus\n", |
|
3246 |
+ DBG("FIXUP RVE (%d,%d-%d,%d): changed + into integer plus\n", |
|
3128 | 3247 |
rve->fpos.s_line, rve->fpos.s_col, |
3129 | 3248 |
rve->fpos.e_line, rve->fpos.e_col); |
3130 | 3249 |
}else if (l_type==RV_STR){ |
... | ... |
@@ -3178,8 +3297,10 @@ static int rve_optimize(struct rval_expr* rve) |
3178 | 3297 |
or a combination of them */ |
3179 | 3298 |
if ((rve->op==RVE_PLUS_OP) && |
3180 | 3299 |
(rve_guess_type(tmp_rve.left.rve)!=RV_STR)){ |
3181 |
- DBG("RVE optimization failed: cannot optimize" |
|
3182 |
- " +(+($v, a), b) when typeof(a)==INT\n"); |
|
3300 |
+ DBG("RVE optimization failed (%d,%d-%d,%d): cannot " |
|
3301 |
+ "optimize +(+($v, a), b) when typeof(a)==INT\n", |
|
3302 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3303 |
+ rve->fpos.e_line, rve->fpos.e_col); |
|
3183 | 3304 |
return 0; |
3184 | 3305 |
} |
3185 | 3306 |
if ((rv=rval_expr_eval_new(0, 0, &tmp_rve))==0){ |
... | ... |
@@ -3195,12 +3316,17 @@ static int rve_optimize(struct rval_expr* rve) |
3195 | 3316 |
rve->left.rve=rve->left.rve->left.rve; |
3196 | 3317 |
trv=&rve->right.rve->left.rval; |
3197 | 3318 |
if (trv->type==RV_INT) |
3198 |
- DBG("FIXUP RVE: optimized int rve: op(op($v, a), b)" |
|
3199 |
- " with op($v, %d); op=%d\n", |
|
3319 |
+ DBG("FIXUP RVE (%d,%d-%d,%d): optimized int rve: " |
|
3320 |
+ "op(op($v, a), b) with op($v, %d); op=%d\n", |
|
3321 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3322 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3200 | 3323 |
(int)trv->v.l, rve->op); |
3201 | 3324 |
else if (trv->type==RV_STR) |
3202 |
- DBG("FIXUP RVE: optimized str rve op(op($v, a), b)" |
|
3203 |
- " with op($v, \"%.*s\"); op=%d\n", |
|
3325 |
+ DBG("FIXUP RVE (%d,%d-%d,%d): optimized str rve " |
|
3326 |
+ "op(op($v, a), b) with op($v, \"%.*s\");" |
|
3327 |
+ " op=%d\n", |
|
3328 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3329 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3204 | 3330 |
trv->v.s.len, trv->v.s.s, rve->op); |
3205 | 3331 |
ret=1; |
3206 | 3332 |
}else if (rve_is_constant(rve->left.rve->left.rve) && |
... | ... |
@@ -3228,12 +3354,17 @@ static int rve_optimize(struct rval_expr* rve) |
3228 | 3354 |
rv=0; |
3229 | 3355 |
trv=&rve->left.rve->left.rval; |
3230 | 3356 |
if (trv->type==RV_INT) |
3231 |
- DBG("FIXUP RVE: optimized int rve: op(op(a, $v), b)" |
|
3232 |
- " with op(%d, $v); op=%d\n", |
|
3357 |
+ DBG("FIXUP RVE (%d,%d-%d,%d): optimized int rve: " |
|
3358 |
+ "op(op(a, $v), b) with op(%d, $v); op=%d\n", |
|
3359 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3360 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3233 | 3361 |
(int)trv->v.l, rve->op); |
3234 | 3362 |
else if (trv->type==RV_STR) |
3235 |
- DBG("FIXUP RVE: optimized str rve op(op(a, $v), b)" |
|
3236 |
- " with op(\"%.*s\", $v); op=%d\n", |
|
3363 |
+ DBG("FIXUP RVE (%d,%d-%d,%d): optimized str rve " |
|
3364 |
+ "op(op(a, $v), b) with op(\"%.*s\", $v);" |
|
3365 |
+ " op=%d\n", |
|
3366 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3367 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3237 | 3368 |
trv->v.s.len, trv->v.s.s, rve->op); |
3238 | 3369 |
ret=1; |
3239 | 3370 |
} |
... | ... |
@@ -3269,12 +3400,17 @@ static int rve_optimize(struct rval_expr* rve) |
3269 | 3400 |
rve->right.rve=rve->right.rve->left.rve; |
3270 | 3401 |
trv=&rve->left.rve->left.rval; |
3271 | 3402 |
if (trv->type==RV_INT) |
3272 |
- DBG("FIXUP RVE: optimized int rve: op(a, op($v, b))" |
|
3273 |
- " with op(%d, $v); op=%d\n", |
|
3403 |
+ DBG("FIXUP RVE (%d,%d-%d,%d): optimized int rve: " |
|
3404 |
+ "op(a, op($v, b)) with op(%d, $v); op=%d\n", |
|
3405 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3406 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3274 | 3407 |
(int)trv->v.l, rve->op); |
3275 | 3408 |
else if (trv->type==RV_STR) |
3276 |
- DBG("FIXUP RVE: optimized str rve op(a, op($v, b))" |
|
3277 |
- " with op(\"%.*s\", $v); op=%d\n", |
|
3409 |
+ DBG("FIXUP RVE (%d,%d-%d,%d): optimized str rve " |
|
3410 |
+ "op(a, op($v, b)) with op(\"%.*s\", $v);" |
|
3411 |
+ " op=%d\n", |
|
3412 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3413 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3278 | 3414 |
trv->v.s.len, trv->v.s.s, rve->op); |
3279 | 3415 |
ret=1; |
3280 | 3416 |
}else if (rve_is_constant(rve->right.rve->left.rve)){ |
... | ... |
@@ -3288,8 +3424,11 @@ static int rve_optimize(struct rval_expr* rve) |
3288 | 3424 |
if ((rve->op==RVE_PLUS_OP) && |
3289 | 3425 |
(rve_guess_type(tmp_rve.left.rve) != |
3290 | 3426 |
rve_guess_type(tmp_rve.right.rve))){ |
3291 |
- DBG("RVE optimization failed: cannot optimize" |
|
3292 |
- " +(a, +(b, $v)) when typeof(a)!=typeof(b)\n"); |
|
3427 |
+ DBG("RVE optimization failed (%d,%d-%d,%d): cannot " |
|
3428 |
+ "optimize +(a, +(b, $v)) when " |
|
3429 |
+ "typeof(a)!=typeof(b)\n", |
|
3430 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3431 |
+ rve->fpos.e_line, rve->fpos.e_col); |
|
3293 | 3432 |
return 0; |
3294 | 3433 |
} |
3295 | 3434 |
if ((rv=rval_expr_eval_new(0, 0, &tmp_rve))==0){ |
... | ... |
@@ -3305,12 +3444,17 @@ static int rve_optimize(struct rval_expr* rve) |
3305 | 3444 |
rve->right.rve=rve->right.rve->right.rve; |
3306 | 3445 |
trv=&rve->left.rve->left.rval; |
3307 | 3446 |
if (trv->type==RV_INT) |
3308 |
- DBG("FIXUP RVE: optimized int rve: op(a, op(b, $v))" |
|
3309 |
- " with op(%d, $v); op=%d\n", |
|
3447 |
+ DBG("FIXUP RVE (%d,%d-%d,%d): optimized int rve: " |
|
3448 |
+ "op(a, op(b, $v)) with op(%d, $v); op=%d\n", |
|
3449 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3450 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3310 | 3451 |
(int)trv->v.l, rve->op); |
3311 | 3452 |
else if (trv->type==RV_STR) |
3312 |
- DBG("FIXUP RVE: optimized str rve op(a, op(b, $v))" |
|
3313 |
- " with op(\"%.*s\", $v); op=%d\n", |
|
3453 |
+ DBG("FIXUP RVE (%d,%d-%d,%d): optimized str rve " |
|
3454 |
+ "op(a, op(b, $v)) with op(\"%.*s\", $v);" |
|
3455 |
+ " op=%d\n", |
|
3456 |
+ rve->fpos.s_line, rve->fpos.s_col, |
|
3457 |
+ rve->fpos.e_line, rve->fpos.e_col, |
|
3314 | 3458 |
trv->v.s.len, trv->v.s.s, rve->op); |
3315 | 3459 |
ret=1; |
3316 | 3460 |
} |