diff options
-rw-r--r-- | main.c | 7 | ||||
-rw-r--r-- | parse.c | 28 |
2 files changed, 22 insertions, 13 deletions
@@ -8,11 +8,11 @@ /* TODO: -test for v := v (where v is a varargs param) -varargs only exist in decls. not a type of its own +indices in varargs for loops don't allow default varargs don't allow semiconst varargs -don't allow struct varargs +don't allow struct varargs (yet) +make sure varargs[i] isn't an lvalue make sure you can't have a variadic function pointer make sure varargs works with inference #foreign variadic fns @@ -25,6 +25,7 @@ continue switch enums typeof + - make sure you can't do typeof(something_that_is_varargs) unions --- switch to / add as an alternative: libffi @@ -156,7 +156,7 @@ static int kw_to_builtin_type(Keyword kw) { case KW_CHAR: return BUILTIN_CHAR; case KW_TYPE: return BUILTIN_TYPE; case KW_NAMESPACE: return BUILTIN_NMS; - case KW_DOTDOT: return BUILTIN_VARARGS; + /* don't allow .. => varargs because it's not a normal type */ default: return -1; } return -1; @@ -2278,15 +2278,23 @@ static Status parse_decl(Parser *p, Declaration *d, DeclEndKind ends_with, U16 f bool annotates_type = !token_is_kw(t->token, KW_EQ) && !token_is_kw(t->token, KW_COMMA); if (annotates_type) { d->flags |= DECL_ANNOTATES_TYPE; - Type type; - Location type_where; - if (!parse_type(p, &type, &type_where)) { - goto ret_false; - } - d->type = type; - if (type.kind == TYPE_TUPLE && arr_len(d->type.tuple) != arr_len(d->idents)) { - err_print(type_where, "Expected to have %lu things declared in declaration, but got %lu.", (unsigned long)arr_len(d->type.tuple), (unsigned long)arr_len(d->idents)); - goto ret_false; + if (token_is_kw(t->token, KW_DOTDOT)) { + d->type.kind = TYPE_BUILTIN; + d->type.flags = 0; + d->type.was_expr = NULL; + d->type.builtin = BUILTIN_VARARGS; + ++t->token; + } else { + Type type; + Location type_where; + if (!parse_type(p, &type, &type_where)) { + goto ret_false; + } + d->type = type; + if (type.kind == TYPE_TUPLE && arr_len(d->type.tuple) != arr_len(d->idents)) { + err_print(type_where, "Expected to have %lu things declared in declaration, but got %lu.", (unsigned long)arr_len(d->type.tuple), (unsigned long)arr_len(d->idents)); + goto ret_false; + } } } } |