mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
[cexpr] Add support for the bool type
It's currently rather limited, but enough to make use of it in vkgen and vkparse.
This commit is contained in:
parent
f5e7d5fbbc
commit
0a50fb1bf1
2 changed files with 53 additions and 0 deletions
|
@ -140,6 +140,8 @@ void cexpr_init_symtab (exprtab_t *symtab, exprctx_t *ctx);
|
|||
|
||||
char *cexpr_yyget_text (void *scanner);
|
||||
|
||||
extern exprenum_t cexpr_bool_enum;
|
||||
extern exprtype_t cexpr_bool;
|
||||
extern exprtype_t cexpr_int;
|
||||
extern exprtype_t cexpr_uint;
|
||||
extern exprtype_t cexpr_size_t;
|
||||
|
|
|
@ -66,6 +66,57 @@ pre##_##opname (const exprval_t *a, exprval_t *b, exprctx_t *ctx) \
|
|||
(*(type *) b->value) = op (*(type *) a->value); \
|
||||
}
|
||||
|
||||
BINOP(bool, and, bool, &)
|
||||
BINOP(bool, or, bool, |)
|
||||
BINOP(bool, xor, bool, ^)
|
||||
|
||||
UNOP(bool, not, bool, !)
|
||||
|
||||
static const char *
|
||||
bool_get_string (const exprval_t *val, va_ctx_t *va_ctx)
|
||||
{
|
||||
return val->value ? "true" : "false";
|
||||
}
|
||||
|
||||
binop_t bool_binops[] = {
|
||||
{ '&', &cexpr_bool, &cexpr_bool, bool_and },
|
||||
{ '|', &cexpr_bool, &cexpr_bool, bool_or },
|
||||
{ '^', &cexpr_bool, &cexpr_bool, bool_xor },
|
||||
{ '=', &cexpr_plitem, &cexpr_bool, cexpr_cast_plitem },
|
||||
{}
|
||||
};
|
||||
|
||||
unop_t bool_unops[] = {
|
||||
{ '!', &cexpr_bool, bool_not },
|
||||
{}
|
||||
};
|
||||
|
||||
exprtype_t cexpr_bool = {
|
||||
.name = "bool",
|
||||
.size = sizeof (bool),
|
||||
.binops = bool_binops,
|
||||
.unops = bool_unops,
|
||||
.data = &cexpr_bool_enum,
|
||||
.get_string = bool_get_string,
|
||||
};
|
||||
|
||||
static int bool_values[] = {
|
||||
false,
|
||||
true,
|
||||
};
|
||||
static exprsym_t bool_symbols[] = {
|
||||
{"false", &cexpr_bool, bool_values + 0},
|
||||
{"true", &cexpr_bool, bool_values + 1},
|
||||
{}
|
||||
};
|
||||
static exprtab_t bool_symtab = {
|
||||
bool_symbols,
|
||||
};
|
||||
exprenum_t cexpr_bool_enum = {
|
||||
&cexpr_bool,
|
||||
&bool_symtab,
|
||||
};
|
||||
|
||||
BINOP(int, shl, int, <<)
|
||||
BINOP(int, shr, int, >>)
|
||||
BINOP(int, add, int, +)
|
||||
|
|
Loading…
Reference in a new issue