diff options
| author | gingerBill <bill@gingerbill.org> | 2018-09-02 15:56:36 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-09-02 15:56:36 +0100 |
| commit | 220485a2d2cd180e7ff2a15bab66c867c06b05d7 (patch) | |
| tree | 4b3df1aae33e7b2af9375b1f8e11d8c2b2b88a15 /src/check_type.cpp | |
| parent | eb274cf31600814b2f808c80d43376b0e9e959f1 (diff) | |
`typeid` as keyword (ready to implement polymorphic name parameters)
Diffstat (limited to 'src/check_type.cpp')
| -rw-r--r-- | src/check_type.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
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) { |