Changeset 9a705dc8 for src/Concurrency


Ignore:
Timestamp:
Apr 19, 2018, 5:18:46 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
da9d79b
Parents:
60ba456
Message:

Implement concurrency keyword casts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Keywords.cc

    r60ba456 r9a705dc8  
    5353          public:
    5454
    55                 ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main ) :
    56                   type_name( type_name ), field_name( field_name ), getter_name( getter_name ), context_error( context_error ), needs_main( needs_main ) {}
     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 ) :
     56                  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
    5858                virtual ~ConcurrentSueKeyword() {}
    5959
    60                 void postvisit( StructDecl * decl );
     60                Declaration * postmutate( StructDecl * decl );
    6161
    6262                void handle( StructDecl * );
     
    6666
    6767                virtual bool is_target( StructDecl * decl ) = 0;
     68
     69                Expression * postmutate( KeywordCastExpr * cast );
    6870
    6971          private:
     
    7375                const std::string context_error;
    7476                bool needs_main;
     77                KeywordCastExpr::Target cast_target;
    7578
    7679                StructDecl* type_decl = nullptr;
     
    9598                        "get_thread",
    9699                        "thread keyword requires threads to be in scope, add #include <thread>",
    97                         true
     100                        true,
     101                        KeywordCastExpr::Thread
    98102                )
    99103                {}
     
    105109                static void implement( std::list< Declaration * > & translationUnit ) {
    106110                        PassVisitor< ThreadKeyword > impl;
    107                         acceptAll( translationUnit, impl );
     111                        mutateAll( translationUnit, impl );
    108112                }
    109113        };
     
    126130                        "get_coroutine",
    127131                        "coroutine keyword requires coroutines to be in scope, add #include <coroutine>",
    128                         true
     132                        true,
     133                        KeywordCastExpr::Coroutine
    129134                )
    130135                {}
     
    136141                static void implement( std::list< Declaration * > & translationUnit ) {
    137142                        PassVisitor< CoroutineKeyword > impl;
    138                         acceptAll( translationUnit, impl );
     143                        mutateAll( translationUnit, impl );
    139144                }
    140145        };
     
    157162                        "get_monitor",
    158163                        "monitor keyword requires monitors to be in scope, add #include <monitor>",
    159                         false
     164                        false,
     165                        KeywordCastExpr::Monitor
    160166                )
    161167                {}
     
    167173                static void implement( std::list< Declaration * > & translationUnit ) {
    168174                        PassVisitor< MonitorKeyword > impl;
    169                         acceptAll( translationUnit, impl );
     175                        mutateAll( translationUnit, impl );
    170176                }
    171177        };
     
    267273        }
    268274
    269         void ConcurrentSueKeyword::postvisit(StructDecl * decl) {
     275        Declaration * ConcurrentSueKeyword::postmutate(StructDecl * decl) {
    270276                if( decl->name == type_name && decl->body ) {
    271277                        assert( !type_decl );
     
    275281                        handle( decl );
    276282                }
    277         }
     283                return decl;
     284        }
     285
     286        Expression * ConcurrentSueKeyword::postmutate( KeywordCastExpr * cast ) {
     287                if ( cast_target == cast->target ) {
     288                        // convert (thread &)t to (thread_desc &)*get_thread(t), etc.
     289                        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                                );
     301                }
     302                return cast;
     303        }
     304
    278305
    279306        void ConcurrentSueKeyword::handle( StructDecl * decl ) {
Note: See TracChangeset for help on using the changeset viewer.