- case opid2('-', 'P'):
- return isfloat (a) ? fold_constgen_float (fold, fold_immvalue_float(a))
- : isvector(a) ? fold_constgen_vector(fold, vec3_neg(fold_immvalue_vector(a)))
- : NULL;
- case opid2('!', 'P'):
- return isfloat (a) ? fold_constgen_float (fold, !fold_immvalue_float(a))
- : isvector(a) ? fold_constgen_vector(fold, vec3_not(fold_immvalue_vector(a)))
- : isstring(a) ? fold_constgen_float (fold, !fold_immvalue_string(a) || OPTS_FLAG(TRUE_EMPTY_STRINGS) ? 0 : !*fold_immvalue_string(a))
- : NULL;
- case opid1('+'):
- return isfloats(a,b) ? fold_constgen_float (fold, fold_immvalue_float(a) + fold_immvalue_float(b))
- : isvectors(a,b) ? fold_constgen_vector(fold, vec3_add(fold_immvalue_vector(a), fold_immvalue_vector(b)))
- : NULL;
- case opid1('-'):
- return isfloats(a,b) ? fold_constgen_float (fold, fold_immvalue_float(a) - fold_immvalue_float(b))
- : isvectors(a,b) ? fold_constgen_vector(fold, vec3_sub(fold_immvalue_vector(a), fold_immvalue_vector(b)))
- : NULL;
- case opid1('%'):
- return isfloats(a,b) ? fold_constgen_float (fold, (qcfloat_t)(((qcint_t)fold_immvalue_float(a)) % ((qcint_t)fold_immvalue_float(b))))
- : NULL;
- case opid1('|'):
- return isfloats(a,b) ? fold_constgen_float (fold, (qcfloat_t)(((qcint_t)fold_immvalue_float(a)) | ((qcint_t)fold_immvalue_float(b))))
- : NULL;
- case opid1('&'):
- return isfloats(a,b) ? fold_constgen_float (fold, (qcfloat_t)(((qcint_t)fold_immvalue_float(a)) & ((qcint_t)fold_immvalue_float(b))))
- : NULL;
- case opid1('^'):
- return isfloats(a,b) ? fold_constgen_float (fold, (qcfloat_t)(((qcint_t)fold_immvalue_float(a)) ^ ((qcint_t)fold_immvalue_float(b))))
- : isvectors(a,b) ? fold_constgen_vector(fold, vec3_xor (fold_immvalue_vector(a), fold_immvalue_vector(b)))
- : isvector(a)&&isfloat(b) ? fold_constgen_vector(fold, vec3_xorvf(fold_immvalue_vector(a), fold_immvalue_float (b)))
- : NULL;
- case opid2('<','<'):
- return isfloats(a,b) ? fold_constgen_float (fold, (qcfloat_t)(((qcuint_t)(fold_immvalue_float(a)) << ((qcuint_t)fold_immvalue_float(b)))))
- : NULL;
- case opid2('>','>'):
- return isfloats(a,b) ? fold_constgen_float (fold, (qcfloat_t)(((qcuint_t)(fold_immvalue_float(a)) >> ((qcuint_t)fold_immvalue_float(b)))))
- : NULL;
- case opid2('*','*'):
- return isfloats(a,b) ? fold_constgen_float (fold, (qcfloat_t)powf(fold_immvalue_float(a), fold_immvalue_float(b)))
- : NULL;
- case opid2('!','='):
- return isfloats(a,b) ? fold_constgen_float (fold, fold_immvalue_float(a) != fold_immvalue_float(b))
- : NULL;
- case opid2('=','='):
- return isfloats(a,b) ? fold_constgen_float (fold, fold_immvalue_float(a) == fold_immvalue_float(b))
- : NULL;
- case opid2('~','P'):
- return isfloat(a) ? fold_constgen_float (fold, ~(qcint_t)fold_immvalue_float(a))
- : NULL;
-
- case opid1('*'): return fold_op_mul (fold, a, b);
- case opid1('/'): return fold_op_div (fold, a, b);
- case opid2('|','|'): return fold_op_andor(fold, a, b, true);
- case opid2('&','&'): return fold_op_andor(fold, a, b, false);
- case opid3('<','=','>'): return fold_op_lteqgt(fold, a, b);
- case opid2('?',':'):
- /* TODO: seperate function for this case */
- return NULL;
+ fold_op_case(2, ('-', 'P'), neg, (fold, a));
+ fold_op_case(2, ('!', 'P'), not, (fold, a));
+ fold_op_case(1, ('+'), add, (fold, a, b));
+ fold_op_case(1, ('-'), sub, (fold, a, b));
+ fold_op_case(1, ('*'), mul, (fold, a, b));
+ fold_op_case(1, ('/'), div, (fold, a, b));
+ fold_op_case(1, ('%'), mod, (fold, a, b));
+ fold_op_case(1, ('|'), bor, (fold, a, b));
+ fold_op_case(1, ('&'), band, (fold, a, b));
+ fold_op_case(1, ('^'), xor, (fold, a, b));
+ fold_op_case(2, ('<', '<'), lshift, (fold, a, b));
+ fold_op_case(2, ('>', '>'), rshift, (fold, a, b));
+ fold_op_case(2, ('|', '|'), andor, (fold, a, b, true));
+ fold_op_case(2, ('&', '&'), andor, (fold, a, b, false));
+ fold_op_case(2, ('?', ':'), tern, (fold, a, b, c));
+ fold_op_case(2, ('*', '*'), exp, (fold, a, b));
+ fold_op_case(3, ('<','=','>'), lteqgt, (fold, a, b));
+ fold_op_case(2, ('!', '='), cmp, (fold, a, b, true));
+ fold_op_case(2, ('=', '='), cmp, (fold, a, b, false));
+ fold_op_case(2, ('~', 'P'), bnot, (fold, a));