Changeset 1cdfa82 for src/Concurrency


Ignore:
Timestamp:
Apr 25, 2018, 4:55:53 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
42107b4
Parents:
2efe4b8 (diff), 9d5fb67 (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:

Merge remote-tracking branch 'origin/master' into with_gc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Keywords.cc

    r2efe4b8 r1cdfa82  
    5454          public:
    5555
    56                 ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main ) :
    57                   type_name( type_name ), field_name( field_name ), getter_name( getter_name ), context_error( context_error ), needs_main( needs_main ) {}
     56                ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main, KeywordCastExpr::Target cast_target ) :
     57                  type_name( type_name ), field_name( field_name ), getter_name( getter_name ), context_error( context_error ), needs_main( needs_main ), cast_target( cast_target ) {}
    5858
    5959                virtual ~ConcurrentSueKeyword() {}
    6060
    61                 void postvisit( StructDecl * decl );
     61                Declaration * postmutate( StructDecl * decl );
    6262
    6363                void handle( StructDecl * );
     
    6767
    6868                virtual bool is_target( StructDecl * decl ) = 0;
     69
     70                Expression * postmutate( KeywordCastExpr * cast );
    6971
    7072          private:
     
    7476                const std::string context_error;
    7577                bool needs_main;
     78                KeywordCastExpr::Target cast_target;
    7679
    7780                StructDecl* type_decl = nullptr;
     
    9699                        "get_thread",
    97100                        "thread keyword requires threads to be in scope, add #include <thread>",
    98                         true
     101                        true,
     102                        KeywordCastExpr::Thread
    99103                )
    100104                {}
     
    106110                static void implement( std::list< Declaration * > & translationUnit ) {
    107111                        PassVisitor< ThreadKeyword > impl;
    108                         acceptAll( translationUnit, impl );
     112                        mutateAll( translationUnit, impl );
    109113                }
    110114        };
     
    127131                        "get_coroutine",
    128132                        "coroutine keyword requires coroutines to be in scope, add #include <coroutine>",
    129                         true
     133                        true,
     134                        KeywordCastExpr::Coroutine
    130135                )
    131136                {}
     
    137142                static void implement( std::list< Declaration * > & translationUnit ) {
    138143                        PassVisitor< CoroutineKeyword > impl;
    139                         acceptAll( translationUnit, impl );
     144                        mutateAll( translationUnit, impl );
    140145                }
    141146        };
     
    158163                        "get_monitor",
    159164                        "monitor keyword requires monitors to be in scope, add #include <monitor>",
    160                         false
     165                        false,
     166                        KeywordCastExpr::Monitor
    161167                )
    162168                {}
     
    168174                static void implement( std::list< Declaration * > & translationUnit ) {
    169175                        PassVisitor< MonitorKeyword > impl;
    170                         acceptAll( translationUnit, impl );
     176                        mutateAll( translationUnit, impl );
    171177                }
    172178        };
     
    263269        }
    264270
    265         void ConcurrentSueKeyword::postvisit(StructDecl * decl) {
     271        Declaration * ConcurrentSueKeyword::postmutate(StructDecl * decl) {
    266272                if( decl->name == type_name && decl->body ) {
    267273                        assert( !type_decl );
     
    271277                        handle( decl );
    272278                }
    273         }
     279                return decl;
     280        }
     281
     282        Expression * ConcurrentSueKeyword::postmutate( KeywordCastExpr * cast ) {
     283                if ( cast_target == cast->target ) {
     284                        // convert (thread &)t to (thread_desc &)*get_thread(t), etc.
     285                        if( !type_decl ) SemanticError( cast, context_error );
     286                        Expression * arg = cast->arg;
     287                        cast->arg = nullptr;
     288                        delete cast;
     289                        return new CastExpr(
     290                                UntypedExpr::createDeref(
     291                                        new UntypedExpr( new NameExpr( getter_name ), { arg } )
     292                                ),
     293                                new ReferenceType(
     294                                        noQualifiers,
     295                                        new StructInstType( noQualifiers, type_decl ) )
     296                                );
     297                }
     298                return cast;
     299        }
     300
    274301
    275302        void ConcurrentSueKeyword::handle( StructDecl * decl ) {
Note: See TracChangeset for help on using the changeset viewer.