diff options
| author | gingerBill <bill@gingerbill.org> | 2018-05-12 17:39:04 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-05-12 17:39:04 +0100 |
| commit | 830f4f540fdbe30b22e93540249e61c1d1521f9b (patch) | |
| tree | c48704a31f31efdbe7645d02f86430b025079a82 /src/check_expr.cpp | |
| parent | 56ff5496bc81ca2ccce00f46d9477c6d559ee5b0 (diff) | |
`typeid`
Diffstat (limited to 'src/check_expr.cpp')
| -rw-r--r-- | src/check_expr.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp index c4a1e7a43..66c26dda4 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -2873,6 +2873,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id case BuiltinProc_align_of: case BuiltinProc_offset_of: case BuiltinProc_type_info_of: + case BuiltinProc_typeid_of: // NOTE(bill): The first arg may be a Type, this will be checked case by case break; default: @@ -3426,6 +3427,34 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id break; } + case BuiltinProc_typeid_of: { + // proc typeid_of(Type) -> ^Type_Info + if (c->context.scope->is_global) { + compiler_error("'typeid_of' Cannot be declared within a #shared_global_scope due to how the internals of the compiler works"); + } + + // NOTE(bill): The type information may not be setup yet + init_preload(c); + AstNode *expr = ce->args[0]; + Operand o = {}; + check_expr_or_type(c, &o, expr); + if (o.mode == Addressing_Invalid) { + return false; + } + Type *t = o.type; + if (t == nullptr || t == t_invalid || is_type_polymorphic(operand->type)) { + error(ce->args[0], "Invalid argument for 'typeid_of'"); + return false; + } + t = default_type(t); + + add_type_info_type(c, t); + + operand->mode = Addressing_Value; + operand->type = t_typeid; + break; + } + case BuiltinProc_swizzle: { // proc swizzle(v: [N]T, ...int) -> [M]T Type *type = base_type(operand->type); |