From 220485a2d2cd180e7ff2a15bab66c867c06b05d7 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 2 Sep 2018 15:56:36 +0100 Subject: `typeid` as keyword (ready to implement polymorphic name parameters) --- src/check_type.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/check_type.cpp') diff --git a/src/check_type.cpp b/src/check_type.cpp index b5c1d7120..2eff33922 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -1190,6 +1190,7 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is if (specialization == t_invalid){ specialization = nullptr; } + // warning(type_expr, "'type' parameters are deprecated, please use a polymorphic identifier with a type of 'typeid'. For example, '$T: typeid'"); if (operands != nullptr) { detemine_type_from_operand = true; @@ -1263,10 +1264,30 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is for_array(j, p->names) { Ast *name = p->names[j]; + + bool is_poly_name = false; + + switch (name->kind) { + case Ast_Ident: + break; + case Ast_PolyType: + GB_ASSERT(name->PolyType.specialization == nullptr); + is_poly_name = true; + name = name->PolyType.type; + break; + } if (!ast_node_expect(name, Ast_Ident)) { continue; } + if (is_poly_name) { + if (type != nullptr && is_type_typeid(type)) { + is_type_param = true; + } else { + error(name, "Polymorphic names are not yet supported for non-typeid parameters"); + } + } + Entity *param = nullptr; if (is_type_param) { if (operands != nullptr) { @@ -2022,6 +2043,14 @@ bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, Type *named_t return check_type_internal(ctx, dt->type, type, named_type); case_end; + case_ast_node(tt, TypeidType, e); + e->tav.mode = Addressing_Type; + e->tav.type = t_typeid; + *type = t_typeid; + set_base_type(named_type, *type); + return true; + case_end; + case_ast_node(pt, PolyType, e); Ast *ident = pt->type; if (ident->kind != Ast_Ident) { -- cgit v1.2.3