#define isvector(X) (((ast_expression*)(X))->vtype == TYPE_VECTOR)
#define isstring(X) (((ast_expression*)(X))->vtype == TYPE_STRING)
#define isfloats(X,Y) (isfloat (X) && isfloat (Y))
-#define isvectors(X,Y) (isvector (X) && isvector(Y))
/*
* Implementation of basic vector math for vec3_t, for trivial constant
static GMQCC_INLINE vec3_t vec3_xor(vec3_t a, vec3_t b) {
vec3_t out;
- out.x = (qcfloat_t)((qcint_t)a.x ^ (qcint_t)b.x);
- out.y = (qcfloat_t)((qcint_t)a.y ^ (qcint_t)b.y);
- out.z = (qcfloat_t)((qcint_t)a.z ^ (qcint_t)b.z);
+ out.x = (qcfloat_t)(((qcint_t)a.x) ^ ((qcint_t)b.x));
+ out.y = (qcfloat_t)(((qcint_t)a.y) ^ ((qcint_t)b.y));
+ out.z = (qcfloat_t)(((qcint_t)a.z) ^ ((qcint_t)b.z));
return out;
}
static GMQCC_INLINE vec3_t vec3_xorvf(vec3_t a, qcfloat_t b) {
vec3_t out;
- out.x = (qcfloat_t)((qcint_t)a.x ^ (qcint_t)b);
- out.y = (qcfloat_t)((qcint_t)a.y ^ (qcint_t)b);
- out.z = (qcfloat_t)((qcint_t)a.z ^ (qcint_t)b);
+ out.x = (qcfloat_t)(((qcint_t)a.x) ^ ((qcint_t)b));
+ out.y = (qcfloat_t)(((qcint_t)a.y) ^ ((qcint_t)b));
+ out.z = (qcfloat_t)(((qcint_t)a.z) ^ ((qcint_t)b));
return out;
}
}
static GMQCC_INLINE bool fold_can_1(const ast_value *val) {
- return (ast_istype((ast_expression*)val, ast_value) && val->hasvalue && val->cvq == CV_CONST && ((ast_expression*)val)->vtype != TYPE_FUNCTION);
+ return (ast_istype(((ast_expression*)(val)), ast_value) && val->hasvalue && (val->cvq == CV_CONST) &&
+ ((ast_expression*)(val))->vtype != TYPE_FUNCTION);
}
static GMQCC_INLINE bool fold_can_2(const ast_value *v1, const ast_value *v2) {
case TYPE_VECTOR:
if (OPTS_FLAG(CORRECT_LOGIC))
return vec3_pbool(v->constval.vvec);
- return !!v->constval.vvec.x;
+ return !!(v->constval.vvec.x);
case TYPE_STRING:
if (!v->constval.vstring)
return false;
out = (ast_expression*)ast_member_new(fold_ctx(fold), (ast_expression*)sel, set[0]-'x', NULL);
out->node.keep = false;
((ast_member*)out)->rvalue = true;
- if (!x != -1)
+ if (x != -1)
return (ast_expression*)ast_binary_new(fold_ctx(fold), INSTR_MUL_F, fold_constgen_float(fold, x), out);
}
return NULL;
static GMQCC_INLINE ast_expression *fold_op_mul(fold_t *fold, ast_value *a, ast_value *b) {
if (isfloat(a)) {
- if (isfloat(b) && fold_can_2(a, b))
- return fold_constgen_vector(fold, vec3_mulvf(fold_immvalue_vector(b), fold_immvalue_float(a)));
- else if (fold_can_2(a, b))
- return fold_constgen_float(fold, fold_immvalue_float(a) * fold_immvalue_float(b));
+ if (isvector(b)) {
+ if (fold_can_2(a, b))
+ return fold_constgen_vector(fold, vec3_mulvf(fold_immvalue_vector(b), fold_immvalue_float(a)));
+ } else {
+ if (fold_can_2(a, b))
+ return fold_constgen_float(fold, fold_immvalue_float(a) * fold_immvalue_float(b));
+ }
} else if (isvector(a)) {
- if (isfloat(b) && fold_can_2(a, b)) {
- return fold_constgen_vector(fold, vec3_mulvf(fold_immvalue_vector(a), fold_immvalue_float(b)));
+ if (isfloat(b)) {
+ if (fold_can_2(a, b))
+ return fold_constgen_vector(fold, vec3_mulvf(fold_immvalue_vector(a), fold_immvalue_float(b)));
} else {
if (fold_can_2(a, b)) {
return fold_constgen_float(fold, vec3_mulvv(fold_immvalue_vector(a), fold_immvalue_vector(b)));
} else if (isvector(a)) {
if (fold_can_2(a, b))
return fold_constgen_vector(fold, vec3_mulvf(fold_immvalue_vector(a), 1.0f / fold_immvalue_float(b)));
- else if (fold_can_1(b))
- return fold_constgen_float (fold, 1.0f / fold_immvalue_float(b));
+ else {
+ return (ast_expression*)ast_binary_new(
+ fold_ctx(fold),
+ INSTR_MUL_VF,
+ (ast_expression*)a,
+ (fold_can_1(b))
+ ? (ast_expression*)fold_constgen_float(fold, 1.0f / fold_immvalue_float(b))
+ : (ast_expression*)ast_binary_new(
+ fold_ctx(fold),
+ INSTR_DIV_F,
+ (ast_expression*)fold->imm_float[1],
+ (ast_expression*)b
+ )
+ );
+ }
}
return NULL;
}
fold,
((or) ? (fold_immediate_true(fold, a) || fold_immediate_true(fold, b))
: (fold_immediate_true(fold, a) && fold_immediate_true(fold, b)))
- ? 1.0f
- : 0.0f
+ ? 1
+ : 0
);
}
}
}
switch(info->id) {
- case opid2('-', 'P'): return fold_op_neg (fold, a);
- case opid2('!', 'P'): return fold_op_not (fold, a);
+ case opid2('-','P'): return fold_op_neg (fold, a);
+ case opid2('!','P'): return fold_op_not (fold, a);
case opid1('+'): return fold_op_add (fold, a, b);
case opid1('-'): return fold_op_sub (fold, a, b);
case opid1('*'): return fold_op_mul (fold, a, b);
case opid2('=','='): return fold_op_cmp (fold, a, b, false);
case opid2('~','P'): return fold_op_bnot (fold, a);
}
+ compile_error(fold_ctx(fold), "internal error: attempted to constant for unsupported operator");
return NULL;
}