Implement the basics of fteqcc's -Fifstring.

It's -Cifstring in qfcc, but otherwise the intent is the same. More testing
and investigation into what fteqcc does is required.
This commit is contained in:
Bill Currie 2012-12-20 10:05:17 +09:00
parent 8d34d33055
commit 6fa63f6c54
3 changed files with 11 additions and 1 deletions

View file

@ -44,6 +44,7 @@ typedef struct {
qboolean local_merging; // merge function locals into one block
unsigned progsversion; // Progs version to generate code for
qboolean vector_components; // add *_[xyz] symbols for vectors
qboolean ifstring; // expand if (str) to if (str != "")
} code_options_t;
typedef struct {

View file

@ -1082,6 +1082,8 @@ test_expr (expr_t *e)
}
return error (e, "void has no value");
case ev_string:
if (!options.code.ifstring)
return new_alias_expr (type_default, e);
new = new_string_expr (0);
break;
case ev_uinteger:
@ -1211,7 +1213,8 @@ convert_bool (expr_t *e, int block)
return b;
}
if (e->type == ex_uexpr && e->e.expr.op == '!') {
if (e->type == ex_uexpr && e->e.expr.op == '!'
&& get_type (e->e.expr.e1) != &type_string) {
e = convert_bool (e->e.expr.e1, 0);
if (e->type == ex_error)
return e;

View file

@ -470,6 +470,8 @@ DecodeArgs (int argc, char **argv)
options.code.optimize = flag;
} else if (!(strcasecmp (temp, "short-circuit"))) {
options.code.short_circuit = flag;
} else if (!(strcasecmp (temp, "ifstring"))) {
options.code.ifstring = flag;
} else if (!(strcasecmp (temp, "single-cpp"))) {
options.single_cpp = flag;
} else if (!(strcasecmp (temp, "vector-calls"))) {
@ -645,6 +647,8 @@ DecodeArgs (int argc, char **argv)
options.advanced = false;
if (!options.code.progsversion)
options.code.progsversion = PROG_ID_VERSION;
if (options.code.ifstring == (qboolean) -1)
options.code.ifstring = false;
if (options.code.short_circuit == (qboolean) -1)
options.code.short_circuit = false;
if (options.code.local_merging == (qboolean) -1)
@ -658,6 +662,8 @@ DecodeArgs (int argc, char **argv)
options.advanced = true;
add_cpp_def ("-D__RUAMOKO__=1");
add_cpp_def ("-D__RAUMOKO__=1");
if (options.code.ifstring == (qboolean) -1)
options.code.ifstring = false;
if (options.code.short_circuit == (qboolean) -1)
options.code.short_circuit = true;
if (options.code.local_merging == (qboolean) -1)