~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-08-19 06:03:00 UTC
  • mfrom: (100.1.22 misc)
  • Revision ID: eda-qa@disemia.com-20170819060300-209dwd5884343mi0
merging miscelaneous changes, mainly platform improvements

Show diffs side-by-side

added added

removed removed

Lines of Context:
475
475
        shared_ptr<statement> result;
476
476
        switch( s->statement_form() )
477
477
        {
478
 
                #define STM(type) \
479
 
                        case sf_##type: \
480
 
                                result = proc_##type( std::static_pointer_cast<type>(s), ctx ); \
 
478
                #define STATEMENT_FORM(type) \
 
479
                        case sf_##type##_statement: \
 
480
                                result = proc_##type##_statement( std::static_pointer_cast<type##_statement>(s), ctx ); \
481
481
                                break;
482
 
                STM(assign_statement)
483
 
                STM(defer_statement)
484
 
                STM(do_statement)
485
 
                STM(expression_statement)
486
 
                STM(fail_statement)
487
 
                STM(for_statement)
488
 
                STM(import_statement)
489
 
                STM(init_statement)
490
 
                STM(loop_flow_statement)
491
 
                STM(return_statement)
492
 
                STM(typedef_statement)
493
 
                STM(var_statement)
 
482
                STATEMENT_FORMS
494
483
                #undef STM
495
 
 
496
 
                //not expected in input (generated by typer)
497
 
                case sf_noop_statement:
498
 
                        result = s;
499
 
                        break;
500
484
        }
501
485
        STMT_CHECK( *s, result );
502
486
        
529
513
                        return ds; //incomplete
530
514
        }
531
515
        
532
 
        return proc_error_statement( ds, ctx );
 
516
        ds->local_complete = true;
 
517
        return ds;
533
518
}
534
519
 
535
520
bool typer::proc_error_block( shared_ptr<statement> st, error_block & block, context ctx ) {
539
524
                        
540
525
                auto decl = declaration::create();
541
526
                decl->form = declaration::f_single;
542
 
                decl->symbol = "current_error_info";
 
527
                decl->symbol = "current_fail";
543
528
                
544
 
                auto shared_error = extr_type(ctx.types().get_error_info());
 
529
                auto shared_error = extr_type(ctx.types().get_fail_info());
545
530
                shared_error.set_ref_shared();
546
531
                decl->type = shared_error;
547
532
                
552
537
        return proc_statement_block( block.on_error );
553
538
}
554
539
 
555
 
shared_ptr<statement> typer::proc_error_statement( shared_ptr<error_statement> ds, context ctx ) {
556
 
        //STMT_CHECK( *ds, !ctx.sc->is_declarative() );
557
 
        if( ds->error.on_error ) {
558
 
                STMT_CHECK( *ds, !(ds->get_flow() & (flow_return | flow_loop_break | flow_loop_next)), 
 
540
shared_ptr<statement> typer::proc_error_statement( shared_ptr<error_statement> es, context ctx ) {
 
541
        es->inner = proc_statement( es->inner, ctx );
 
542
        
 
543
        if( !proc_error_block( es, es->error, ctx ) ) {
 
544
                return es;
 
545
        }
 
546
        
 
547
        if( es->inner->is_resolved() ) {
 
548
                STMT_CHECK( *es, !(es->inner->get_flow() & (flow_return | flow_loop_break | flow_loop_next)), 
559
549
                        "terminator-handled" );
560
 
                
561
 
                if( !proc_error_block( ds, ds->error, ctx ) )
562
 
                        return ds; //incomplete
 
550
                if( !es->inner->is_skippable() && !es->safe_skip ) {
 
551
                        STMT_CHECK(*es, es->error.on_error->is_terminator(), "on-fail-must-terminate" );
 
552
                }
 
553
        
 
554
                es->local_complete = true;
563
555
        }
564
 
        
565
 
        ds->local_complete = true;
566
 
        return ds;
 
556
        return es;
567
557
}
568
558
 
569
559
shared_ptr<statement> typer::proc_defer_statement( shared_ptr<defer_statement> ds, context ctx ) {
846
836
        if( !es->ignore ) {
847
837
                STMT_CHECK( *es, vl && vl->sub.size() == 0, "cannot-ignore-value" );
848
838
        }
849
 
        return proc_error_statement( es, ctx );
 
839
        
 
840
        es->local_complete = true;
 
841
        return es;
 
842
}
 
843
 
 
844
shared_ptr<statement> typer::proc_noop_statement( shared_ptr<noop_statement> ns, context /*ctx*/ ) {
 
845
        ns->local_complete = true;
 
846
        return ns;
850
847
}
851
848
 
852
849
struct typer_serial_resolver : public serial_resolver {
888
885
 
889
886
        auto in_file_name = mloader->resolve_import( is->mod_name );
890
887
        std::ifstream in_file( in_file_name, std::ios::binary );
 
888
        STATE_CHECK( !!in_file, "cannot-open-file", error::tag_error_symbol(in_file_name) );
891
889
 
892
890
        serial_in sin( in_file, get_serial_resolver() );
893
891