diff options
| author | gingerBill <bill@gingerbill.org> | 2018-02-24 19:03:29 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-02-24 19:03:29 +0000 |
| commit | 35ba5771a5dbe5fec3fea8804fb46fe843478830 (patch) | |
| tree | d46c33864d8a2b14a2bba7c860ce2cf875f2bc39 /src/check_expr.cpp | |
| parent | b2461f7192684f979301be9f174237e740ec28c6 (diff) | |
Replace `compile_assert` with `#assert`
Diffstat (limited to 'src/check_expr.cpp')
| -rw-r--r-- | src/check_expr.cpp | 89 |
1 files changed, 47 insertions, 42 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 147c6c6a6..526932229 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -2813,27 +2813,48 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id case BuiltinProc_DIRECTIVE: { ast_node(bd, BasicDirective, ce->proc); String name = bd->name; - GB_ASSERT(name == "location"); - if (ce->args.count > 1) { - error(ce->args[0], "'#location' expects either 0 or 1 arguments, got %td", ce->args.count); - } - if (ce->args.count > 0) { - AstNode *arg = ce->args[0]; - Entity *e = nullptr; - Operand o = {}; - if (arg->kind == AstNode_Ident) { - e = check_ident(c, &o, arg, nullptr, nullptr, true); - } else if (arg->kind == AstNode_SelectorExpr) { - e = check_selector(c, &o, arg, nullptr); + if (name == "location") { + if (ce->args.count > 1) { + error(ce->args[0], "'#location' expects either 0 or 1 arguments, got %td", ce->args.count); } - if (e == nullptr) { - error(ce->args[0], "'#location' expected a valid entity name"); + if (ce->args.count > 0) { + AstNode *arg = ce->args[0]; + Entity *e = nullptr; + Operand o = {}; + if (arg->kind == AstNode_Ident) { + e = check_ident(c, &o, arg, nullptr, nullptr, true); + } else if (arg->kind == AstNode_SelectorExpr) { + e = check_selector(c, &o, arg, nullptr); + } + if (e == nullptr) { + error(ce->args[0], "'#location' expected a valid entity name"); + } } - } + operand->type = t_source_code_location; + operand->mode = Addressing_Value; + } else if (name == "assert") { + if (ce->args.count != 1) { + error(call, "'#assert' expects at 1 argument, got %td", ce->args.count); + return false; + } + if (!is_type_boolean(operand->type) && operand->mode != Addressing_Constant) { + gbString str = expr_to_string(ce->args[0]); + error(call, "'%s' is not a constant boolean", str); + gb_string_free(str); + return false; + } + if (!operand->value.value_bool) { + gbString arg = expr_to_string(ce->args[0]); + error(call, "Compile time assertion: %s", arg); + gb_string_free(arg); + } - operand->type = t_source_code_location; - operand->mode = Addressing_Value; + operand->type = t_untyped_bool; + operand->mode = Addressing_Constant; + } else { + GB_PANIC("Unhandled #%.*s", LIT(name)); + } break; } @@ -3321,25 +3342,6 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id break; } - case BuiltinProc_compile_assert: - // proc compile_assert(cond: bool) -> bool - - if (!is_type_boolean(operand->type) && operand->mode != Addressing_Constant) { - gbString str = expr_to_string(ce->args[0]); - error(call, "'%s' is not a constant boolean", str); - gb_string_free(str); - return false; - } - if (!operand->value.value_bool) { - gbString str = expr_to_string(ce->args[0]); - error(call, "Compile time assertion: '%s'", str); - gb_string_free(str); - } - - operand->mode = Addressing_Constant; - operand->type = t_untyped_bool; - break; - case BuiltinProc_swizzle: { // proc swizzle(v: [N]T, ...int) -> [M]T Type *type = base_type(operand->type); @@ -4805,12 +4807,15 @@ ExprKind check_call_expr(Checker *c, Operand *operand, AstNode *call) { ce->proc->kind == AstNode_BasicDirective) { ast_node(bd, BasicDirective, ce->proc); String name = bd->name; - GB_ASSERT(name == "location"); - operand->mode = Addressing_Builtin; - operand->builtin_id = BuiltinProc_DIRECTIVE; - operand->expr = ce->proc; - operand->type = t_invalid; - add_type_and_value(&c->info, ce->proc, operand->mode, operand->type, operand->value); + if (name == "location" || name == "assert") { + operand->mode = Addressing_Builtin; + operand->builtin_id = BuiltinProc_DIRECTIVE; + operand->expr = ce->proc; + operand->type = t_invalid; + add_type_and_value(&c->info, ce->proc, operand->mode, operand->type, operand->value); + } else { + GB_PANIC("Unhandled #%.*s", LIT(name)); + } } else { check_expr_or_type(c, operand, ce->proc); } |