Mercurial > hg > qcc
changeset 490:082f4509bce5
First bit of dynamic arrays. Doesn't work yet, but gives a specific error
message.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 02 Oct 2007 21:47:58 -0500 |
parents | a606eb4464e6 |
children | 41841f0acc48 |
files | tcc.c tcc.h |
diffstat | 2 files changed, 16 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/tcc.c Tue Oct 02 21:29:02 2007 -0500 +++ b/tcc.c Tue Oct 02 21:47:58 2007 -0500 @@ -6131,12 +6131,22 @@ } else if (tok == '[') { /* array definition */ next(); - if (tok == TOK_RESTRICT1) next(); /* Work around bug in glibc regex.h */ + if (tok == TOK_RESTRICT1) next(); n = -1; if (tok != ']') { - n = expr_const(); - if (n < 0) - error("invalid array size"); + char *message = "invalid array size"; + expr_const1(); + /* Conventional constant array? */ + if ((vtop->r & (VT_VALMASK |VT_LVAL | VT_SYM)) == VT_CONST) { + n = vtop->c.i; + vpop(); + + if (n < 0) error(message); + } else if (!local_stack) error(message); + else { + gen_assign_cast(&int_type); + error("dynamic arrays not implemented yet"); + } } skip(']'); /* parse next post type */
--- a/tcc.h Tue Oct 02 21:29:02 2007 -0500 +++ b/tcc.h Tue Oct 02 21:47:58 2007 -0500 @@ -158,7 +158,7 @@ float f; int i; unsigned int ui; - unsigned int ul; /* address (should be unsigned long on 64 bit cpu) */ + unsigned long ul; /* address (should be unsigned long on 64 bit cpu) */ long long ll; unsigned long long ull; struct CString *cstr; @@ -719,6 +719,7 @@ static int parse_btype(CType *type, AttributeDef *ad); static void type_decl(CType *type, AttributeDef *ad, int *v, int td); static int is_compatible_types(CType *type1, CType *type2); +static void expr_const1(void); int ieee_finite(double d); void error(const char *fmt, ...);