Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Keywords.cc

    rac2b598 r2bf7ef6  
    1111// Last Modified By :
    1212// Last Modified On :
    13 // Update Count     : 10
     13// Update Count     : 5
    1414//
    1515
     
    2424#include "CodeGen/OperatorTable.h" // for isConstructor
    2525#include "InitTweak/InitTweak.h"   // for getPointerBase
    26 #include "SynTree/LinkageSpec.h"   // for Cforall
     26#include "Parser/LinkageSpec.h"    // for Cforall
    2727#include "SynTree/Constant.h"      // for Constant
    2828#include "SynTree/Declaration.h"   // for StructDecl, FunctionDecl, ObjectDecl
     
    5353          public:
    5454
    55                 ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main, AggregateDecl::Aggregate cast_target ) :
     55                ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main, KeywordCastExpr::Target cast_target ) :
    5656                  type_name( type_name ), field_name( field_name ), getter_name( getter_name ), context_error( context_error ), needs_main( needs_main ), cast_target( cast_target ) {}
    5757
     
    5959
    6060                Declaration * postmutate( StructDecl * decl );
    61                 DeclarationWithType * postmutate( FunctionDecl * decl );
    6261
    6362                void handle( StructDecl * );
     
    7675                const std::string context_error;
    7776                bool needs_main;
    78                 AggregateDecl::Aggregate cast_target;
    79 
    80                 StructDecl   * type_decl = nullptr;
    81                 FunctionDecl * dtor_decl = nullptr;
     77                KeywordCastExpr::Target cast_target;
     78
     79                StructDecl* type_decl = nullptr;
    8280        };
    8381
     
    8886        //      int data;                                  int data;
    8987        //      a_struct_t more_data;                      a_struct_t more_data;
    90         //                                =>             $thread __thrd_d;
     88        //                                =>             thread_desc __thrd_d;
    9189        // };                                        };
    92         //                                           static inline $thread * get_thread( MyThread * this ) { return &this->__thrd_d; }
     90        //                                           static inline thread_desc * get_thread( MyThread * this ) { return &this->__thrd_d; }
    9391        //
    9492        class ThreadKeyword final : public ConcurrentSueKeyword {
     
    9694
    9795                ThreadKeyword() : ConcurrentSueKeyword(
    98                         "$thread",
     96                        "thread_desc",
    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,
    103                         AggregateDecl::Thread
     101                        KeywordCastExpr::Thread
    104102                )
    105103                {}
     
    120118        //      int data;                                  int data;
    121119        //      a_struct_t more_data;                      a_struct_t more_data;
    122         //                                =>             $coroutine __cor_d;
     120        //                                =>             coroutine_desc __cor_d;
    123121        // };                                        };
    124         //                                           static inline $coroutine * get_coroutine( MyCoroutine * this ) { return &this->__cor_d; }
     122        //                                           static inline coroutine_desc * get_coroutine( MyCoroutine * this ) { return &this->__cor_d; }
    125123        //
    126124        class CoroutineKeyword final : public ConcurrentSueKeyword {
     
    128126
    129127                CoroutineKeyword() : ConcurrentSueKeyword(
    130                         "$coroutine",
     128                        "coroutine_desc",
    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,
    135                         AggregateDecl::Coroutine
     133                        KeywordCastExpr::Coroutine
    136134                )
    137135                {}
     
    152150        //      int data;                                  int data;
    153151        //      a_struct_t more_data;                      a_struct_t more_data;
    154         //                                =>             $monitor __mon_d;
     152        //                                =>             monitor_desc __mon_d;
    155153        // };                                        };
    156         //                                           static inline $monitor * get_coroutine( MyMonitor * this ) { return &this->__cor_d; }
     154        //                                           static inline monitor_desc * get_coroutine( MyMonitor * this ) { return &this->__cor_d; }
    157155        //
    158156        class MonitorKeyword final : public ConcurrentSueKeyword {
     
    160158
    161159                MonitorKeyword() : ConcurrentSueKeyword(
    162                         "$monitor",
     160                        "monitor_desc",
    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,
    167                         AggregateDecl::Monitor
     165                        KeywordCastExpr::Monitor
    168166                )
    169167                {}
     
    182180        //Handles mutex routines definitions :
    183181        // void foo( A * mutex a, B * mutex b,  int i ) {                  void foo( A * a, B * b,  int i ) {
    184         //                                                                       $monitor * __monitors[] = { get_monitor(a), get_monitor(b) };
     182        //                                                                       monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) };
    185183        //                                                                       monitor_guard_t __guard = { __monitors, 2 };
    186184        //    /*Some code*/                                       =>           /*Some code*/
     
    221219        //Handles mutex routines definitions :
    222220        // void foo( A * mutex a, B * mutex b,  int i ) {                  void foo( A * a, B * b,  int i ) {
    223         //                                                                       $monitor * __monitors[] = { get_monitor(a), get_monitor(b) };
     221        //                                                                       monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) };
    224222        //                                                                       monitor_guard_t __guard = { __monitors, 2 };
    225223        //    /*Some code*/                                       =>           /*Some code*/
     
    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 ) {
    308                         // convert (thread &)t to ($thread &)*get_thread(t), etc.
     288                        // 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 );
     
    377362                        get_type,
    378363                        nullptr,
    379                         { new Attribute("const") },
     364                        noAttributes,
    380365                        Type::Inline
    381366                );
     
    516501        void MutexKeyword::postvisit(StructDecl* decl) {
    517502
    518                 if( decl->name == "$monitor" && decl->body ) {
     503                if( decl->name == "monitor_desc" && decl->body ) {
    519504                        assert( !monitor_decl );
    520505                        monitor_decl = decl;
     
    612597                );
    613598
    614                 //$monitor * __monitors[] = { get_monitor(a), get_monitor(b) };
     599                //monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) };
    615600                body->push_front( new DeclStmt( monitors) );
    616601        }
     
    673658                );
    674659
    675                 //$monitor * __monitors[] = { get_monitor(a), get_monitor(b) };
     660                //monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) };
    676661                body->push_front( new DeclStmt( monitors) );
    677662        }
     
    681666        //=============================================================================================
    682667        void ThreadStarter::previsit( StructDecl * decl ) {
    683                 if( decl->name == "$thread" && decl->body ) {
     668                if( decl->name == "thread_desc" && decl->body ) {
    684669                        assert( !thread_decl );
    685670                        thread_decl = decl;
     
    716701                                new UntypedExpr(
    717702                                        new NameExpr( "__thrd_start" ),
    718                                         { new VariableExpr( param ), new NameExpr("main") }
     703                                        { new VariableExpr( param ) }
    719704                                )
    720705                        )
Note: See TracChangeset for help on using the changeset viewer.