Ignore:
Timestamp:
Feb 25, 2020, 1:17:33 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
7dc2e015
Parents:
9fb8f01 (diff), dd9e1ca (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

resolve conflict

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Keywords.cc

    r9fb8f01 r3d5701e  
    1111// Last Modified By :
    1212// Last Modified On :
    13 // Update Count     : 5
     13// Update Count     : 10
    1414//
    1515
     
    2424#include "CodeGen/OperatorTable.h" // for isConstructor
    2525#include "InitTweak/InitTweak.h"   // for getPointerBase
    26 #include "Parser/LinkageSpec.h"    // for Cforall
     26#include "SynTree/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, KeywordCastExpr::Target cast_target ) :
     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 ) :
    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 );
    6162
    6263                void handle( StructDecl * );
     
    7576                const std::string context_error;
    7677                bool needs_main;
    77                 KeywordCastExpr::Target cast_target;
    78 
    79                 StructDecl* type_decl = nullptr;
     78                AggregateDecl::Aggregate cast_target;
     79
     80                StructDecl   * type_decl = nullptr;
     81                FunctionDecl * dtor_decl = nullptr;
    8082        };
    8183
     
    8688        //      int data;                                  int data;
    8789        //      a_struct_t more_data;                      a_struct_t more_data;
    88         //                                =>             thread_desc __thrd_d;
     90        //                                =>             $thread __thrd_d;
    8991        // };                                        };
    90         //                                           static inline thread_desc * get_thread( MyThread * this ) { return &this->__thrd_d; }
     92        //                                           static inline $thread * get_thread( MyThread * this ) { return &this->__thrd_d; }
    9193        //
    9294        class ThreadKeyword final : public ConcurrentSueKeyword {
     
    9496
    9597                ThreadKeyword() : ConcurrentSueKeyword(
    96                         "thread_desc",
     98                        "$thread",
    9799                        "__thrd",
    98100                        "get_thread",
    99                         "thread keyword requires threads to be in scope, add #include <thread.hfa>",
     101                        "thread keyword requires threads to be in scope, add #include <thread.hfa>\n",
    100102                        true,
    101                         KeywordCastExpr::Thread
     103                        AggregateDecl::Thread
    102104                )
    103105                {}
     
    118120        //      int data;                                  int data;
    119121        //      a_struct_t more_data;                      a_struct_t more_data;
    120         //                                =>             coroutine_desc __cor_d;
     122        //                                =>             $coroutine __cor_d;
    121123        // };                                        };
    122         //                                           static inline coroutine_desc * get_coroutine( MyCoroutine * this ) { return &this->__cor_d; }
     124        //                                           static inline $coroutine * get_coroutine( MyCoroutine * this ) { return &this->__cor_d; }
    123125        //
    124126        class CoroutineKeyword final : public ConcurrentSueKeyword {
     
    126128
    127129                CoroutineKeyword() : ConcurrentSueKeyword(
    128                         "coroutine_desc",
     130                        "$coroutine",
    129131                        "__cor",
    130132                        "get_coroutine",
    131                         "coroutine keyword requires coroutines to be in scope, add #include <coroutine.hfa>",
     133                        "coroutine keyword requires coroutines to be in scope, add #include <coroutine.hfa>\n",
    132134                        true,
    133                         KeywordCastExpr::Coroutine
     135                        AggregateDecl::Coroutine
    134136                )
    135137                {}
     
    150152        //      int data;                                  int data;
    151153        //      a_struct_t more_data;                      a_struct_t more_data;
    152         //                                =>             monitor_desc __mon_d;
     154        //                                =>             $monitor __mon_d;
    153155        // };                                        };
    154         //                                           static inline monitor_desc * get_coroutine( MyMonitor * this ) { return &this->__cor_d; }
     156        //                                           static inline $monitor * get_coroutine( MyMonitor * this ) { return &this->__cor_d; }
    155157        //
    156158        class MonitorKeyword final : public ConcurrentSueKeyword {
     
    158160
    159161                MonitorKeyword() : ConcurrentSueKeyword(
    160                         "monitor_desc",
     162                        "$monitor",
    161163                        "__mon",
    162164                        "get_monitor",
    163                         "monitor keyword requires monitors to be in scope, add #include <monitor.hfa>",
     165                        "monitor keyword requires monitors to be in scope, add #include <monitor.hfa>\n",
    164166                        false,
    165                         KeywordCastExpr::Monitor
     167                        AggregateDecl::Monitor
    166168                )
    167169                {}
     
    180182        //Handles mutex routines definitions :
    181183        // void foo( A * mutex a, B * mutex b,  int i ) {                  void foo( A * a, B * b,  int i ) {
    182         //                                                                       monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) };
     184        //                                                                       $monitor * __monitors[] = { get_monitor(a), get_monitor(b) };
    183185        //                                                                       monitor_guard_t __guard = { __monitors, 2 };
    184186        //    /*Some code*/                                       =>           /*Some code*/
     
    219221        //Handles mutex routines definitions :
    220222        // void foo( A * mutex a, B * mutex b,  int i ) {                  void foo( A * a, B * b,  int i ) {
    221         //                                                                       monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) };
     223        //                                                                       $monitor * __monitors[] = { get_monitor(a), get_monitor(b) };
    222224        //                                                                       monitor_guard_t __guard = { __monitors, 2 };
    223225        //    /*Some code*/                                       =>           /*Some code*/
     
    284286        }
    285287
     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
    286306        Expression * ConcurrentSueKeyword::postmutate( KeywordCastExpr * cast ) {
    287307                if ( cast_target == cast->target ) {
    288                         // convert (thread &)t to (thread_desc &)*get_thread(t), etc.
     308                        // convert (thread &)t to ($thread &)*get_thread(t), etc.
    289309                        if( !type_decl ) SemanticError( cast, context_error );
    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                                 );
     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;
    301315                }
    302316                return cast;
     
    308322
    309323                if( !type_decl ) SemanticError( decl, context_error );
     324                if( !dtor_decl ) SemanticError( decl, context_error );
    310325
    311326                FunctionDecl * func = forwardDeclare( decl );
     
    362377                        get_type,
    363378                        nullptr,
    364                         noAttributes,
     379                        { new Attribute("const") },
    365380                        Type::Inline
    366381                );
     
    501516        void MutexKeyword::postvisit(StructDecl* decl) {
    502517
    503                 if( decl->name == "monitor_desc" && decl->body ) {
     518                if( decl->name == "$monitor" && decl->body ) {
    504519                        assert( !monitor_decl );
    505520                        monitor_decl = decl;
     
    597612                );
    598613
    599                 //monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) };
     614                //$monitor * __monitors[] = { get_monitor(a), get_monitor(b) };
    600615                body->push_front( new DeclStmt( monitors) );
    601616        }
     
    658673                );
    659674
    660                 //monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) };
     675                //$monitor * __monitors[] = { get_monitor(a), get_monitor(b) };
    661676                body->push_front( new DeclStmt( monitors) );
    662677        }
     
    666681        //=============================================================================================
    667682        void ThreadStarter::previsit( StructDecl * decl ) {
    668                 if( decl->name == "thread_desc" && decl->body ) {
     683                if( decl->name == "$thread" && decl->body ) {
    669684                        assert( !thread_decl );
    670685                        thread_decl = decl;
     
    701716                                new UntypedExpr(
    702717                                        new NameExpr( "__thrd_start" ),
    703                                         { new VariableExpr( param ) }
     718                                        { new VariableExpr( param ), new NameExpr("main") }
    704719                                )
    705720                        )
Note: See TracChangeset for help on using the changeset viewer.