Ignore:
Timestamp:
Aug 29, 2017, 2:54:49 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
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, resolv-new, with_gc
Children:
235b41f
Parents:
28e58fd (diff), 6454949 (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 branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Keywords.cc

    r28e58fd r800d275  
    1919#include <string>                  // for string, operator==
    2020
     21#include "Common/PassVisitor.h"    // for PassVisitor
    2122#include "Common/SemanticError.h"  // for SemanticError
    2223#include "Common/utility.h"        // for deleteAll, map_range
     
    4647
    4748        //=============================================================================================
    48         // Visitors declaration
     49        // Pass declarations
    4950        //=============================================================================================
    5051
     
    5859        //                                           static inline NewField_t * getter_name( MyType * this ) { return &this->newField; }
    5960        //
    60         class ConcurrentSueKeyword : public Visitor {
    61           protected:
    62             template< typename Visitor >
    63             friend void SymTab::acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor );
     61        class ConcurrentSueKeyword : public WithDeclsToAdd {
    6462          public:
    6563
     
    6967                virtual ~ConcurrentSueKeyword() {}
    7068
    71                 using Visitor::visit;
    72                 virtual void visit( StructDecl * decl ) override final;
     69                void postvisit( StructDecl * decl );
    7370
    7471                void handle( StructDecl * );
     
    8683                bool needs_main;
    8784
    88                 std::list< Declaration * > declsToAdd, declsToAddAfter;
    8985                StructDecl* type_decl = nullptr;
    9086        };
     
    117113
    118114                static void implement( std::list< Declaration * > & translationUnit ) {
    119                         ThreadKeyword impl;
    120                         SymTab::acceptAndAdd( translationUnit, impl );
     115                        PassVisitor< ThreadKeyword > impl;
     116                        acceptAll( translationUnit, impl );
    121117                }
    122118        };
     
    148144
    149145                static void implement( std::list< Declaration * > & translationUnit ) {
    150                         CoroutineKeyword impl;
    151                         SymTab::acceptAndAdd( translationUnit, impl );
     146                        PassVisitor< CoroutineKeyword > impl;
     147                        acceptAll( translationUnit, impl );
    152148                }
    153149        };
     
    179175
    180176                static void implement( std::list< Declaration * > & translationUnit ) {
    181                         MonitorKeyword impl;
    182                         SymTab::acceptAndAdd( translationUnit, impl );
     177                        PassVisitor< MonitorKeyword > impl;
     178                        acceptAll( translationUnit, impl );
    183179                }
    184180        };
     
    192188        // }                                                               }
    193189        //
    194         class MutexKeyword final : public Visitor {
     190        class MutexKeyword final {
    195191          public:
    196192
    197                 using Visitor::visit;
    198                 virtual void visit( FunctionDecl * decl ) override final;
    199                 virtual void visit(   StructDecl * decl ) override final;
     193                void postvisit( FunctionDecl * decl );
     194                void postvisit(   StructDecl * decl );
    200195
    201196                std::list<DeclarationWithType*> findMutexArgs( FunctionDecl* );
    202197                void validate( DeclarationWithType * );
    203                 void addStatments( CompoundStmt *, const std::list<DeclarationWithType * > &);
     198                void addStatments( FunctionDecl* func, CompoundStmt *, const std::list<DeclarationWithType * > &);
    204199
    205200                static void implement( std::list< Declaration * > & translationUnit ) {
    206                         MutexKeyword impl;
     201                        PassVisitor< MutexKeyword > impl;
    207202                        acceptAll( translationUnit, impl );
    208203                }
     
    211206                StructDecl* monitor_decl = nullptr;
    212207                StructDecl* guard_decl = nullptr;
     208
     209                static std::unique_ptr< Type > generic_func;
    213210        };
     211
     212        std::unique_ptr< Type > MutexKeyword::generic_func = std::unique_ptr< Type >(
     213                new FunctionType(
     214                        noQualifiers,
     215                        true
     216                )
     217        );
    214218
    215219        //-----------------------------------------------------------------------------
     
    221225        // }                                                               }
    222226        //
    223         class ThreadStarter final : public Visitor {
     227        class ThreadStarter final {
    224228          public:
    225229
    226                 using Visitor::visit;
    227                 virtual void visit( FunctionDecl * decl ) override final;
     230                void postvisit( FunctionDecl * decl );
    228231
    229232                void addStartStatement( FunctionDecl * decl, DeclarationWithType * param );
    230233
    231234                static void implement( std::list< Declaration * > & translationUnit ) {
    232                         ThreadStarter impl;
     235                        PassVisitor< ThreadStarter > impl;
    233236                        acceptAll( translationUnit, impl );
    234237                }
     
    255258        // Generic keyword implementation
    256259        //=============================================================================================
    257         void ConcurrentSueKeyword::visit(StructDecl * decl) {
    258                 Visitor::visit(decl);
     260        void ConcurrentSueKeyword::postvisit(StructDecl * decl) {
    259261                if( decl->get_name() == type_name && decl->has_body() ) {
    260262                        assert( !type_decl );
     
    344346                }
    345347
    346                 declsToAdd.push_back( forward );
    347                 if( needs_main ) declsToAdd.push_back( main_decl );
    348                 declsToAdd.push_back( get_decl );
     348                declsToAddBefore.push_back( forward );
     349                if( needs_main ) declsToAddBefore.push_back( main_decl );
     350                declsToAddBefore.push_back( get_decl );
    349351
    350352                return get_decl;
     
    395397        // Mutex keyword implementation
    396398        //=============================================================================================
    397         void MutexKeyword::visit(FunctionDecl* decl) {
    398                 Visitor::visit(decl);
     399
     400        void MutexKeyword::postvisit(FunctionDecl* decl) {
    399401
    400402                std::list<DeclarationWithType*> mutexArgs = findMutexArgs( decl );
     
    411413                if( !guard_decl ) throw SemanticError( "mutex keyword requires monitors to be in scope, add #include <monitor>", decl );
    412414
    413                 addStatments( body, mutexArgs );
    414         }
    415 
    416         void MutexKeyword::visit(StructDecl* decl) {
    417                 Visitor::visit(decl);
     415                addStatments( decl, body, mutexArgs );
     416        }
     417
     418        void MutexKeyword::postvisit(StructDecl* decl) {
    418419
    419420                if( decl->get_name() == "monitor_desc" ) {
     
    458459        }
    459460
    460         void MutexKeyword::addStatments( CompoundStmt * body, const std::list<DeclarationWithType * > & args ) {
     461        void MutexKeyword::addStatments( FunctionDecl* func, CompoundStmt * body, const std::list<DeclarationWithType * > & args ) {
    461462                ObjectDecl * monitors = new ObjectDecl(
    462463                        "__monitors",
     
    489490                );
    490491
     492                assert(generic_func);
     493
    491494                //in reverse order :
    492                 // monitor_guard_t __guard = { __monitors, # };
     495                // monitor_guard_t __guard = { __monitors, #, func };
    493496                body->push_front(
    494497                        new DeclStmt( noLabels, new ObjectDecl(
     
    504507                                        {
    505508                                                new SingleInit( new VariableExpr( monitors ) ),
    506                                                 new SingleInit( new ConstantExpr( Constant::from_ulong( args.size() ) ) )
     509                                                new SingleInit( new ConstantExpr( Constant::from_ulong( args.size() ) ) ),
     510                                                new SingleInit( new CastExpr( new VariableExpr( func ), generic_func->clone() ) )
    507511                                        },
    508512                                        noDesignators,
     
    519523        // General entry routine
    520524        //=============================================================================================
    521         void ThreadStarter::visit(FunctionDecl * decl) {
    522                 Visitor::visit(decl);
    523 
     525        void ThreadStarter::postvisit(FunctionDecl * decl) {
    524526                if( ! CodeGen::isConstructor(decl->get_name()) ) return;
    525527
Note: See TracChangeset for help on using the changeset viewer.