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 qboolean local_merging; // merge function locals into one block
unsigned progsversion; // Progs version to generate code for unsigned progsversion; // Progs version to generate code for
qboolean vector_components; // add *_[xyz] symbols for vectors qboolean vector_components; // add *_[xyz] symbols for vectors
qboolean ifstring; // expand if (str) to if (str != "")
} code_options_t; } code_options_t;
typedef struct { typedef struct {

View file

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

View file

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