From 8f39ebbe5a7628e8d4597d39f9253c23fead53a6 Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Sun, 1 Oct 2017 20:01:00 +0100 Subject: Procedure literals for default values in structs --- src/check_expr.cpp | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'src/check_expr.cpp') diff --git a/src/check_expr.cpp b/src/check_expr.cpp index c5dc436b2..dd172634b 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -1035,7 +1035,12 @@ Array check_struct_fields(Checker *c, AstNode *node, Array if (is_operand_nil(o)) { default_is_nil = true; } else if (o.mode != Addressing_Constant) { - error(default_value, "Default parameter must be a constant"); + if (default_value->kind == AstNode_ProcLit) { + value = exact_value_procedure(default_value); + // error(default_value, "A procedure literal as a default param is not yet supported"); + } else { + error(default_value, "Default parameter must be a constant"); + } } else { value = o.value; } @@ -1329,10 +1334,10 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node, Arraypolymorphic_params != nullptr) { ast_node(field_list, FieldList, st->polymorphic_params); @@ -1481,12 +1486,12 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node, ArrayStruct.scope = c->context.scope; - struct_type->Struct.is_packed = st->is_packed; - struct_type->Struct.is_ordered = st->is_ordered; - struct_type->Struct.polymorphic_params = polymorphic_params; - struct_type->Struct.is_polymorphic = is_polymorphic; - struct_type->Struct.is_poly_specialized = is_poly_specialized; + struct_type->Struct.scope = c->context.scope; + struct_type->Struct.is_packed = st->is_packed; + struct_type->Struct.is_ordered = st->is_ordered; + struct_type->Struct.polymorphic_params = polymorphic_params; + struct_type->Struct.is_polymorphic = is_polymorphic; + struct_type->Struct.is_poly_specialized = is_poly_specialized; Array fields = {}; @@ -1497,6 +1502,16 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node, ArrayStruct.fields = fields; struct_type->Struct.fields_in_src_order = fields; + for_array(i, fields) { + Entity *f = fields[i]; + if (f->kind == Entity_Variable) { + if (f->Variable.default_value.kind == ExactValue_Procedure) { + struct_type->Struct.has_proc_default_values = true; + break; + } + } + } + if (!struct_type->Struct.is_raw_union) { type_set_offsets(c->allocator, struct_type); -- cgit v1.2.3