mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 07:11:41 +00:00
Implement comma expressions
Doesn't quite work (attempt to suppress warning for return a = 3, 5; failed).
This commit is contained in:
parent
689d1ad3ec
commit
7fce68649a
3 changed files with 76 additions and 4 deletions
|
@ -180,7 +180,7 @@ int yylex (void);
|
|||
%type <symbol> methoddef
|
||||
%type <expr> opt_initializer var_initializer local_def
|
||||
|
||||
%type <expr> opt_init opt_expr fexpr expr element_list element
|
||||
%type <expr> opt_init opt_expr cexpr fexpr expr element_list element
|
||||
%type <expr> optional_state_expr texpr vector_expr
|
||||
%type <expr> statement statements compound_statement
|
||||
%type <expr> else label break_label continue_label
|
||||
|
@ -1175,7 +1175,7 @@ statement
|
|||
break_label = $2;
|
||||
continue_label = $3;
|
||||
}
|
||||
| fexpr ';'
|
||||
| cexpr ';'
|
||||
{
|
||||
$$ = $1;
|
||||
}
|
||||
|
@ -1227,7 +1227,7 @@ switch_block
|
|||
;
|
||||
|
||||
opt_init
|
||||
: fexpr
|
||||
: cexpr
|
||||
| type init_var_decl_list { $$ = $2; }
|
||||
| /* empty */
|
||||
{
|
||||
|
@ -1260,7 +1260,7 @@ init_var_decl
|
|||
;
|
||||
|
||||
opt_expr
|
||||
: fexpr
|
||||
: cexpr
|
||||
| /* empty */
|
||||
{
|
||||
$$ = 0;
|
||||
|
@ -1346,6 +1346,18 @@ texpr
|
|||
: fexpr { $$ = convert_bool ($1, 1); }
|
||||
;
|
||||
|
||||
cexpr
|
||||
: arg_list
|
||||
{
|
||||
if ($1->next) {
|
||||
expr_t *res = $1;
|
||||
$1 = build_block_expr ($1->next);
|
||||
$1->e.block.result = res;
|
||||
}
|
||||
$$ = $1;
|
||||
}
|
||||
;
|
||||
|
||||
opt_arg_list
|
||||
: /* emtpy */ { $$ = 0; }
|
||||
| arg_list { $$ = $1; }
|
||||
|
|
|
@ -31,6 +31,7 @@ fail_bins=
|
|||
test_progs_dat=\
|
||||
chewed-alias.dat \
|
||||
chewed-return.dat \
|
||||
comma-expr.dat \
|
||||
deadbool.dat \
|
||||
fordecl.dat \
|
||||
func-expr.dat \
|
||||
|
@ -89,6 +90,15 @@ chewed-return.run: Makefile build-run
|
|||
include ./$(DEPDIR)/chewed-return.Qo # am--include-marker
|
||||
r_depfiles_remade += ./$(DEPDIR)/chewed-return.Qo
|
||||
|
||||
comma_expr_dat_SOURCES=comma-expr.r
|
||||
comma_expr_obj=$(comma_expr_dat_SOURCES:.r=.qfo)
|
||||
comma-expr.dat$(EXEEXT): $(comma_expr_obj) $(QFCC_DEP)
|
||||
$(QFCC) $(QCFLAGS) -o $@ $(comma_expr_obj)
|
||||
comma-expr.run: Makefile build-run
|
||||
$(srcdir)/build-run $@
|
||||
include ./$(DEPDIR)/comma-expr.Qo # am--include-marker
|
||||
r_depfiles_remade += ./$(DEPDIR)/comma-expr.Qo
|
||||
|
||||
deadbool_dat_SOURCES=deadbool.r
|
||||
deadbool_obj=$(deadbool_dat_SOURCES:.r=.qfo)
|
||||
deadbool.dat$(EXEEXT): $(deadbool_obj) $(QFCC_DEP)
|
||||
|
|
50
tools/qfcc/test/comma-expr.r
Normal file
50
tools/qfcc/test/comma-expr.r
Normal file
|
@ -0,0 +1,50 @@
|
|||
void printf (string fmt, ...) = #0;
|
||||
|
||||
int a = 0;
|
||||
int b = 0;
|
||||
|
||||
int
|
||||
return_comma()
|
||||
{
|
||||
return a = 3, 5;
|
||||
}
|
||||
|
||||
int
|
||||
test_for_comma ()
|
||||
{
|
||||
int fail = 1;
|
||||
int count = 5;
|
||||
int i = -1;
|
||||
float j = -1;
|
||||
|
||||
for (i = 3, j = 5; count-- > 0; ) {
|
||||
i += 2;
|
||||
j += 3;
|
||||
}
|
||||
if (i == 13 && j == 20) {
|
||||
fail = 0;
|
||||
}
|
||||
|
||||
return fail;
|
||||
}
|
||||
|
||||
int
|
||||
test_comma ()
|
||||
{
|
||||
int fail = 1;
|
||||
if (return_comma() == 5) {
|
||||
if (a == 3) {
|
||||
fail = 0;
|
||||
}
|
||||
}
|
||||
return fail;
|
||||
}
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
int fail = 0;
|
||||
fail |= test_comma ();
|
||||
fail |= test_for_comma ();
|
||||
return fail;
|
||||
}
|
Loading…
Reference in a new issue