Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Keywords.cc

    r3b0c8cb r2bf7ef6  
    5959
    6060                Declaration * postmutate( StructDecl * decl );
    61                 DeclarationWithType * postmutate( FunctionDecl * decl );
    6261
    6362                void handle( StructDecl * );
     
    7877                KeywordCastExpr::Target cast_target;
    7978
    80                 StructDecl   * type_decl = nullptr;
    81                 FunctionDecl * dtor_decl = nullptr;
     79                StructDecl* type_decl = nullptr;
    8280        };
    8381
     
    9997                        "__thrd",
    10098                        "get_thread",
    101                         "thread keyword requires threads to be in scope, add #include <thread.hfa>\n",
     99                        "thread keyword requires threads to be in scope, add #include <thread.hfa>",
    102100                        true,
    103101                        KeywordCastExpr::Thread
     
    131129                        "__cor",
    132130                        "get_coroutine",
    133                         "coroutine keyword requires coroutines to be in scope, add #include <coroutine.hfa>\n",
     131                        "coroutine keyword requires coroutines to be in scope, add #include <coroutine.hfa>",
    134132                        true,
    135133                        KeywordCastExpr::Coroutine
     
    163161                        "__mon",
    164162                        "get_monitor",
    165                         "monitor keyword requires monitors to be in scope, add #include <monitor.hfa>\n",
     163                        "monitor keyword requires monitors to be in scope, add #include <monitor.hfa>",
    166164                        false,
    167165                        KeywordCastExpr::Monitor
     
    286284        }
    287285
    288         DeclarationWithType * ConcurrentSueKeyword::postmutate( FunctionDecl * decl ) {
    289                 if( !type_decl ) return decl;
    290                 if( !CodeGen::isDestructor( decl->name ) ) return decl;
    291 
    292                 auto params = decl->type->parameters;
    293                 if( params.size() != 1 ) return decl;
    294 
    295                 auto type = dynamic_cast<ReferenceType*>( params.front()->get_type() );
    296                 if( !type ) return decl;
    297 
    298                 auto stype = dynamic_cast<StructInstType*>( type->base );
    299                 if( !stype ) return decl;
    300                 if( stype->baseStruct != type_decl ) return decl;
    301 
    302                 if( !dtor_decl ) dtor_decl = decl;
    303                 return decl;
    304         }
    305 
    306286        Expression * ConcurrentSueKeyword::postmutate( KeywordCastExpr * cast ) {
    307287                if ( cast_target == cast->target ) {
    308288                        // convert (thread &)t to (thread_desc &)*get_thread(t), etc.
    309289                        if( !type_decl ) SemanticError( cast, context_error );
    310                         if( !dtor_decl ) SemanticError( cast, context_error );
    311                         assert( cast->result == nullptr );
    312                         cast->set_result( new ReferenceType( noQualifiers, new StructInstType( noQualifiers, type_decl ) ) );
    313                         cast->concrete_target.field  = field_name;
    314                         cast->concrete_target.getter = getter_name;
     290                        Expression * arg = cast->arg;
     291                        cast->arg = nullptr;
     292                        delete cast;
     293                        return new CastExpr(
     294                                UntypedExpr::createDeref(
     295                                        new UntypedExpr( new NameExpr( getter_name ), { arg } )
     296                                ),
     297                                new ReferenceType(
     298                                        noQualifiers,
     299                                        new StructInstType( noQualifiers, type_decl ) )
     300                                );
    315301                }
    316302                return cast;
     
    322308
    323309                if( !type_decl ) SemanticError( decl, context_error );
    324                 if( !dtor_decl ) SemanticError( decl, context_error );
    325310
    326311                FunctionDecl * func = forwardDeclare( decl );
Note: See TracChangeset for help on using the changeset viewer.