diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-03-15 15:05:39 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-03-15 15:05:39 -0400 |
commit | c24d807e24b4ea7dafe5872db618163fc683cdca (patch) | |
tree | 7bd5a6e5c4d5bcecd505de4d9e0b15aca884b2f5 | |
parent | e093297dd5846e963868b62afe55f589d72384c0 (diff) |
removed where
-rw-r--r-- | copy.c | 4 | ||||
-rw-r--r-- | parse.c | 16 | ||||
-rw-r--r-- | tests/printf.toc (renamed from tests/where.toc) | 9 | ||||
-rw-r--r-- | tests/printf_expected | 3 | ||||
-rwxr-xr-x | tests/test.sh | 4 | ||||
-rw-r--r-- | tests/where_expected | 1 | ||||
-rw-r--r-- | types.c | 27 | ||||
-rw-r--r-- | types.h | 4 |
8 files changed, 16 insertions, 52 deletions
@@ -226,10 +226,6 @@ static void copy_fn_expr(Copier *c, FnExpr *fout, FnExpr *fin, U8 flags) { copy_decl(c, fout->ret_decls + i, fin->ret_decls + i); } copy_type(c, &fout->ret_type, &fin->ret_type); - - if (fin->condition) { - fout->condition = copy_expr_(c, fin->condition); - } } c->block = prev; if (copy_body) { @@ -396,10 +396,6 @@ static Token *expr_find_end(Parser *p, ExprEndFlags flags) { if (all_levels_0 && (flags & EXPR_CAN_END_WITH_EQ)) return token; break; - case KW_WHERE: - if (all_levels_0 && (flags & EXPR_CAN_END_WITH_WHERE)) - return token; - break; case KW_COLON: if ((flags & EXPR_CAN_END_WITH_COLON) && all_levels_0) return token; @@ -807,7 +803,7 @@ static bool parser_is_definitely_type(Parser *p, Token **end) { --paren_level; if (paren_level == 0) { ++t->token; - if (token_is_kw(t->token, KW_LBRACE) || token_is_kw(t->token, KW_WHERE)) goto end; /* void fn expr */ + if (token_is_kw(t->token, KW_LBRACE)) goto end; /* void fn expr */ if (is_decl(t)) /* has return declaration */ goto end; @@ -959,7 +955,6 @@ static Status parse_fn_expr(Parser *p, FnExpr *f) { f->instance_id = 0; f->ret_decls = NULL; f->instances = NULL; - f->condition = NULL; /* only called when token is fn */ assert(token_is_kw(t->token, KW_FN)); ++t->token; @@ -990,7 +985,7 @@ static Status parse_fn_expr(Parser *p, FnExpr *f) { success = false; goto ret; } - if (token_is_kw(t->token, KW_LBRACE) || token_is_kw(t->token, KW_WHERE)) { + if (token_is_kw(t->token, KW_LBRACE)) { /* void function */ f->ret_type.kind = TYPE_VOID; f->ret_type.flags = 0; @@ -1017,13 +1012,6 @@ static Status parse_fn_expr(Parser *p, FnExpr *f) { goto ret; } } - if (token_is_kw(t->token, KW_WHERE)) { - ++t->token; - f->condition = parser_new_expr(p); - if (!parse_expr(p, f->condition, expr_find_end(p, EXPR_CAN_END_WITH_LBRACE))) { - return false; - } - } p->block = prev_block; /* be nice to parse_block */ if (!parse_block(p, &f->body, PARSE_BLOCK_DONT_CREATE_IDENTS)) success = false; diff --git a/tests/where.toc b/tests/printf.toc index 4223656..e030af4 100644 --- a/tests/where.toc +++ b/tests/printf.toc @@ -1,5 +1,7 @@ printf ::= #foreign("printf","libc.so.6") fn(#C &"const char", #C ..) #C int; + +// NOTE: this doesn't work (e.g. "%%%") tprintf_valid ::= fn(fmt :: []char, nargs: int) bool { if fmt[fmt.len-1] != '\0' { return false; @@ -20,11 +22,16 @@ tprintf_valid ::= fn(fmt :: []char, nargs: int) bool { }; -tprintf ::= fn(fmt :: []char, args: ..) where tprintf_valid(fmt, args.len) { +tprintf ::= fn(fmt :: []char, args: ..) { + #if !tprintf_valid(fmt, args.len) { + #error "Invalid printf format"; + } f := fmt; printf(&f[0], args); }; main ::= fn() { tprintf("%d %d%%\n\0", 3, 4); + tprintf("%d %d %d%%\n\0", 3, 4, 5); + tprintf("Hello!\n\0"); }; diff --git a/tests/printf_expected b/tests/printf_expected new file mode 100644 index 0000000..a5e51ec --- /dev/null +++ b/tests/printf_expected @@ -0,0 +1,3 @@ +3 4% +3 4 5% +Hello! diff --git a/tests/test.sh b/tests/test.sh index 31ccb6b..d30de7c 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -8,7 +8,7 @@ foreign params nms varargs -where +printf misc' STARTPWD=$(pwd) @@ -22,7 +22,7 @@ compile_c() { if [ "$CC" = "gcc -O0 -g" ]; then EXTRA_FLAGS="-Wno-builtin-declaration-mismatch" elif [ "$CC" = "clang -O3 -s" ]; then - EXTRA_FLAGS="-Wno-builtin-requires-header" + EXTRA_FLAGS="-Wno-builtin-requires-header -Wno-format-security" elif [ "$CC" = "tcc" ]; then EXTRA_FLAGS="-w" fi diff --git a/tests/where_expected b/tests/where_expected deleted file mode 100644 index 622c000..0000000 --- a/tests/where_expected +++ /dev/null @@ -1 +0,0 @@ -3 4% @@ -2361,33 +2361,6 @@ static Status types_expr(Typer *tr, Expression *e) { } } - if (fn_copy->condition) { - typer_block_enter(tr, &fn_copy->body); - /* check where condition */ - if (!types_expr(tr, fn_copy->condition)) { - typer_block_exit(tr); - return false; - } - typer_block_exit(tr); - - Type *condition_type = &fn_copy->condition->type; - if (!type_is_builtin(condition_type, BUILTIN_BOOL)) { - char *s = type_to_str(condition_type); - err_print(fn_copy->condition->where, "where conditions must be of type bool, but this is of type %s.", s); - free(s); - return false; - } - Value val; - if (!eval_expr(tr->evalr, fn_copy->condition, &val)) { - return false; - } - if (!val.boolv) { - err_print(fn_copy->condition->where, "Function where condition not satisfied. You are probably calling this function incorrectly."); - info_print(e->where, "Offending call is here."); - return false; - } - } - ret_type = f->type.fn.types; param_types = ret_type + 1; } @@ -321,7 +321,6 @@ typedef enum { KW_FALSE, KW_NMS, KW_TYPEOF, - KW_WHERE, KW_COUNT } Keyword; @@ -336,7 +335,7 @@ static const char *const keywords[KW_COUNT] = "int", "i8", "i16", "i32", "i64", "u8", "u16", "u32", "u64", "float", "f32", "f64", "Type", "Namespace", - "char", "bool", "true", "false", "nms", "typeof", "where"}; + "char", "bool", "true", "false", "nms", "typeof"}; typedef enum { NUM_LITERAL_INT, @@ -694,7 +693,6 @@ typedef struct FnExpr { U64 instance_id; Type ret_type; Block body; - struct Expression *condition; /* fn(...) ... where ... */ }; struct { Type type; /* type of this function */ |