* SOFTWARE.
*/
#include <string.h>
+#include <math.h>
+
#include "ast.h"
#include "parser.h"
#define isfloat(X) (((ast_expression*)(X))->vtype == TYPE_FLOAT && fold_possible(X))
#define isvector(X) (((ast_expression*)(X))->vtype == TYPE_VECTOR && fold_possible(X))
-#define isstring(S) (((ast_expression*)(X))->vtype == TYPE_STRING && fold_possible(X))
+#define isstring(X) (((ast_expression*)(X))->vtype == TYPE_STRING && fold_possible(X))
#define isfloats(X,Y) (isfloat (X) && isfloat(Y))
#define isvectors(X,Y) (isvector(X) && isvector(Y))
#define isstrings(X,Y) (isstring(X) && isstring(Y))
static GMQCC_INLINE qcfloat_t vec3_mulvv(vec3_t a, vec3_t b) {
return (a.x * b.x + a.y * b.y + a.z * b.z);
}
-#endif
+
static GMQCC_INLINE vec3_t vec3_mulvf(vec3_t a, qcfloat_t b) {
vec3_t out;
out.z = a.z * b;
return out;
}
+#endif
static GMQCC_INLINE bool vec3_cmp(vec3_t a, vec3_t b) {
return a.x == b.x &&
static GMQCC_INLINE vec3_t fold_immvalue_vector(ast_value *expr) {
return expr->constval.vvec;
}
-#if 0
static GMQCC_INLINE const char *fold_immvalue_string(ast_value *expr) {
return expr->constval.vstring;
}
-#endif
fold_t *fold_init(parser_t *parser) {
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))
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('*'):
- if (isfloat(a))
- return isvector(b) ? fold_constgen_vector(fold, vec3_mulvf(fold_immvalue_vector(b), fold_immvalue_float(a)))
- : fold_constgen_float (fold, fold_immvalue_float(a) * fold_immvalue_float(b));
- return NULL;
- case opid1('/'):
- return isfloats(a,b) ? fold_constgen_float (fold, fold_immvalue_float(a) / fold_immvalue_float(b))
- : isvector(a)&&isfloat(b) ? fold_constgen_vector(fold, vec3_mulvf(fold_immvalue_vector(a), 1.0f / 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 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 NULL;
- case opid2('&','&'): return NULL;
- case opid2('?',':'): return NULL;
- case opid2('*','*'): return NULL;
- case opid3('<','=','>'): return 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('~','P'):
return isfloat(a) ? fold_constgen_float (fold, ~(qcint_t)fold_immvalue_float(a))
: NULL;
- break;
+
+ case opid1('*'):
+ /* TODO: seperate function for this case */
+ return NULL;
+ case opid1('/'):
+ /* TODO: seperate function for this case */
+ return NULL;
+ case opid2('|','|'):
+ /* TODO: seperate function for this case */
+ return NULL;
+ case opid2('&','&'):
+ /* TODO: seperate function for this case */
+ return NULL;
+ case opid2('?',':'):
+ /* TODO: seperate function for this case */
+ return NULL;
+ case opid3('<','=','>'):
+ /* TODO: seperate function for this case */
+ return NULL;
}
return NULL;
}