~eda-qa/leaflang/cpp

« back to all changes in this revision

Viewing changes to src/lang/typer.cpp

  • Committer: edA-qa mort-ora-y
  • Date: 2017-06-03 05:03:54 UTC
  • mfrom: (98.1.18 typefixes)
  • Revision ID: eda-qa@disemia.com-20170603050354-6hfg5huvq56zjs66
merging typefixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
136
136
                complete_type();
137
137
                
138
138
                if( flags & tef_convert_inferred ) {
139
 
                        auto it = type_identifier(ctx).infer( shared_ptr<type_spec>(), result->type, false );
 
139
                        auto it = type_identifier::infer( ctx, shared_ptr<type_spec>(), result->type, false );
140
140
                        STMT_CHECK( *expr, it.okay(), it.explain_error() );
141
141
                        auto cost = type_converter(ctx).convert( it.result, result->type );
142
142
                        result = ctx.applicator().apply( cost, result );
237
237
                        bhow = &type_converter::convert_to_lvalue;
238
238
                        break;
239
239
        }
 
240
        STMT_CHECK( *as, as->right->type.extr().allow_copy(), "no-copy-allowed" );
 
241
        STMT_CHECK( *as, as->left->type.extr().allow_copy(), "no-copy-allowed" );
240
242
        //DEBUG( "ASSIGN", dump::get(as->left->type), dump::get(as->right->type) );
241
243
        as->right = ctx.convert_expression( bhow, as->left, as->right );
242
244
        as->local_complete = true;
263
265
        }
264
266
        
265
267
        //an init_block needs to be evaluated in a different context
266
 
        auto value_ctx = init_block ?
267
 
                context( ctx.get_owner(), init_block->symbols, ctx.sc )
268
 
                : ctx;
 
268
        auto value_ctx = ctx.sc->has_init_block() ? ctx.derive( ctx.sc->get_init_block()->symbols ) : ctx;
269
269
        
270
270
        if( vs->value ) {
271
271
                vs->value = value_ctx.proc_expression( vs->value );
282
282
                        STMT_CHECK( *vs, !vs->init_refer_value );
283
283
                
284
284
                        //literals constrain their type rather than infer it
285
 
                        auto it = ctx.identifier().constrain( vs->decl->spec_type, vs->value->type );
 
285
                        auto it = type_identifier::constrain( ctx, vs->decl->spec_type, vs->value->type );
286
286
                        STMT_CHECK( *vs, it.okay(), it.explain_error() );
287
287
                        vs->decl->type = type_ref(it.result);
288
288
                        
289
289
                        parametric = vs->decl->type.contains_parametric();
290
290
                } else {
291
 
                        auto it = ctx.identifier().infer( vs->decl->spec_type, vs->value->type, vs->init_refer_value );
 
291
                        auto it = type_identifier::infer( ctx, vs->decl->spec_type, vs->value->type, vs->init_refer_value );
292
292
                        if( it.unknown_identifier() ) {
293
293
                                STMT_CHECK( *vs, !no_incomplete, it.explain_error() );
294
294
                                return vs;
306
306
                        vs->value->type.is_complete(), dump::get(*vs->value) );
307
307
                vs->value->bound_decl = vs->decl;
308
308
        } else {
309
 
                auto rt = ctx.identifier().determine( vs->decl->spec_type );
 
309
                auto rt = type_identifier::determine( ctx, vs->decl->spec_type );
310
310
                if( rt.unknown_identifier() ) {
311
311
                        STMT_CHECK( *vs, !no_incomplete, rt.explain_error() );
312
312
                        return vs;
427
427
        //this avoids class construction since optionals are empty by default
428
428
        if( type.extr().is_optional() ) { 
429
429
                //nop
430
 
        } else if( type.extr().is<intr_type_class>() && !is->value && !is->code ) {
 
430
        } else if( type.extr().is<intr_type_classlike>() && !is->value && !is->code ) {
431
431
                auto fc = expression_typer::create_default_ctor_call( *is, ctx, is->sref->type );
432
432
                if( !fc ) {
433
433
                        return is;
448
448
        }
449
449
        
450
450
        if( is->value ) {
 
451
                STMT_CHECK( *is, type.extr().allow_copy(), "no-copy-allowed" );
451
452
                is->value = ctx.proc_expression( is->value );
452
453
                RETURN_IF_UNRESOLVED( *is->value, is );
453
454
        } 
631
632
                        STMT_CHECK( *ts, ts->spec_type->extrinsic_free() );
632
633
                        STMT_CHECK( *ts, ts->spec_type->get<pt_fun_class>( intr_type::f_invalid ) == intr_type::f_tuple );
633
634
 
634
 
                        auto nt = ctx.identifier().determine( ts->spec_type, type_identifier::df_allow_param );
 
635
                        auto nt = type_identifier::determine( ctx, ts->spec_type, type_identifier::df_allow_param );
635
636
                        if( nt.okay() ) {
636
637
                                STMT_CHECK( *ts, !nt.result.extr().intr->is_whole() );
637
638
                                auto nt_tuple = nt.result.extr().if_cast<intr_type_tuple>();
654
655
                ts->type = extr_type(ts->proc_tuple);
655
656
        
656
657
        } else if( ts->what == typedef_statement::w_alias ) {
657
 
                auto err = ctx.identifier().expand( *ts->spec_type );
 
658
                auto err = type_identifier::expand( ctx, *ts->spec_type );
658
659
                if( err.unknown_identifier() ) {
659
660
                        STMT_CHECK( *ts, !no_incomplete, err.explain_error() );
660
661
                        //aliases cannot be partially constructure, they only exist in the scope once fully definable
661
662
                        return ts;
662
663
                }
663
664
                ctx.sc->add_type_alias( ts->name, ts->spec_type );
664
 
        } else if( ts->what == typedef_statement::w_class ) {
 
665
        } else if( ts->what == typedef_statement::w_class || ts->what == typedef_statement::w_service ) {
665
666
                class_typer::process( ts, ctx );
666
667
        }
667
668
        
697
698
                
698
699
                rs->value = ctx.convert_expression( use_return_type, rs->value );
699
700
                rs->local_complete = true;
 
701
                
 
702
                STMT_CHECK( *rs, use_return_type.extr().allow_copy(), "no-copy-allowed" );
700
703
        } else {
701
704
                expr_funcdefn::pend_return pr;
702
705
                pr.rs = rs;