Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/Concurrency/Keywords.cc

    r97e3296 r2065609  
    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
    23 #include "InitTweak/InitTweak.h"   // for isConstructor
     24#include "CodeGen/OperatorTable.h" // for isConstructor
     25#include "InitTweak/InitTweak.h"   // for getPointerBase
    2426#include "Parser/LinkageSpec.h"    // for Cforall
    2527#include "SymTab/AddVisit.h"       // for acceptAndAdd
     
    4547
    4648        //=============================================================================================
    47         // Visitors declaration
     49        // Pass declarations
    4850        //=============================================================================================
    4951
     
    5759        //                                           static inline NewField_t * getter_name( MyType * this ) { return &this->newField; }
    5860        //
    59         class ConcurrentSueKeyword : public Visitor {
    60           protected:
    61             template< typename Visitor >
    62             friend void SymTab::acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor );
     61        class ConcurrentSueKeyword : public WithDeclsToAdd {
    6362          public:
    6463
     
    6867                virtual ~ConcurrentSueKeyword() {}
    6968
    70                 using Visitor::visit;
    71                 virtual void visit( StructDecl * decl ) override final;
     69                void postvisit( StructDecl * decl );
    7270
    7371                void handle( StructDecl * );
     
    8583                bool needs_main;
    8684
    87                 std::list< Declaration * > declsToAdd, declsToAddAfter;
    8885                StructDecl* type_decl = nullptr;
    8986        };
     
    116113
    117114                static void implement( std::list< Declaration * > & translationUnit ) {
    118                         ThreadKeyword impl;
    119                         SymTab::acceptAndAdd( translationUnit, impl );
     115                        PassVisitor< ThreadKeyword > impl;
     116                        acceptAll( translationUnit, impl );
    120117                }
    121118        };
     
    147144
    148145                static void implement( std::list< Declaration * > & translationUnit ) {
    149                         CoroutineKeyword impl;
    150                         SymTab::acceptAndAdd( translationUnit, impl );
     146                        PassVisitor< CoroutineKeyword > impl;
     147                        acceptAll( translationUnit, impl );
    151148                }
    152149        };
     
    178175
    179176                static void implement( std::list< Declaration * > & translationUnit ) {
    180                         MonitorKeyword impl;
    181                         SymTab::acceptAndAdd( translationUnit, impl );
     177                        PassVisitor< MonitorKeyword > impl;
     178                        acceptAll( translationUnit, impl );
    182179                }
    183180        };
     
    191188        // }                                                               }
    192189        //
    193         class MutexKeyword final : public Visitor {
     190        class MutexKeyword final {
    194191          public:
    195192
    196                 using Visitor::visit;
    197                 virtual void visit( FunctionDecl * decl ) override final;
    198                 virtual void visit(   StructDecl * decl ) override final;
     193                void postvisit( FunctionDecl * decl );
     194                void postvisit(   StructDecl * decl );
    199195
    200196                std::list<DeclarationWithType*> findMutexArgs( FunctionDecl* );
     
    203199
    204200                static void implement( std::list< Declaration * > & translationUnit ) {
    205                         MutexKeyword impl;
     201                        PassVisitor< MutexKeyword > impl;
    206202                        acceptAll( translationUnit, impl );
    207203                }
     
    229225        // }                                                               }
    230226        //
    231         class ThreadStarter final : public Visitor {
     227        class ThreadStarter final {
    232228          public:
    233229
    234                 using Visitor::visit;
    235                 virtual void visit( FunctionDecl * decl ) override final;
     230                void postvisit( FunctionDecl * decl );
    236231
    237232                void addStartStatement( FunctionDecl * decl, DeclarationWithType * param );
    238233
    239234                static void implement( std::list< Declaration * > & translationUnit ) {
    240                         ThreadStarter impl;
     235                        PassVisitor< ThreadStarter > impl;
    241236                        acceptAll( translationUnit, impl );
    242237                }
     
    263258        // Generic keyword implementation
    264259        //=============================================================================================
    265         void ConcurrentSueKeyword::visit(StructDecl * decl) {
    266                 Visitor::visit(decl);
     260        void ConcurrentSueKeyword::postvisit(StructDecl * decl) {
    267261                if( decl->get_name() == type_name && decl->has_body() ) {
    268262                        assert( !type_decl );
     
    298292                        LinkageSpec::Cforall,
    299293                        nullptr,
    300                         new PointerType(
     294                        new ReferenceType(
    301295                                noQualifiers,
    302296                                new StructInstType(
     
    352346                }
    353347
    354                 declsToAdd.push_back( forward );
    355                 if( needs_main ) declsToAdd.push_back( main_decl );
    356                 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 );
    357351
    358352                return get_decl;
     
    404398        //=============================================================================================
    405399
    406         void MutexKeyword::visit(FunctionDecl* decl) {
    407                 Visitor::visit(decl);
     400        void MutexKeyword::postvisit(FunctionDecl* decl) {
    408401
    409402                std::list<DeclarationWithType*> mutexArgs = findMutexArgs( decl );
     
    423416        }
    424417
    425         void MutexKeyword::visit(StructDecl* decl) {
    426                 Visitor::visit(decl);
     418        void MutexKeyword::postvisit(StructDecl* decl) {
    427419
    428420                if( decl->get_name() == "monitor_desc" ) {
     
    455447
    456448                //Makes sure it's not a copy
    457                 PointerType* pty = dynamic_cast< PointerType * >( ty );
    458                 if( ! pty ) throw SemanticError( "Mutex argument must be of pointer/reference type ", arg );
     449                ReferenceType* rty = dynamic_cast< ReferenceType * >( ty );
     450                if( ! rty ) throw SemanticError( "Mutex argument must be of reference type ", arg );
    459451
    460452                //Make sure the we are pointing directly to a type
    461                 Type* base = pty->get_base();
    462                 if(  dynamic_cast< PointerType * >( base ) ) throw SemanticError( "Mutex argument have exactly one level of indirection ", arg );
     453                Type* base = rty->get_base();
     454                if( dynamic_cast< ReferenceType * >( base ) ) throw SemanticError( "Mutex argument have exactly one level of indirection ", arg );
     455                if( dynamic_cast< PointerType * >( base ) ) throw SemanticError( "Mutex argument have exactly one level of indirection ", arg );
    463456
    464457                //Make sure that typed isn't mutex
     
    530523        // General entry routine
    531524        //=============================================================================================
    532         void ThreadStarter::visit(FunctionDecl * decl) {
    533                 Visitor::visit(decl);
    534 
    535                 if( ! InitTweak::isConstructor(decl->get_name()) ) return;
     525        void ThreadStarter::postvisit(FunctionDecl * decl) {
     526                if( ! CodeGen::isConstructor(decl->get_name()) ) return;
    536527
    537528                DeclarationWithType * param = decl->get_functionType()->get_parameters().front();
    538                 auto ptr = dynamic_cast< PointerType * >( param->get_type() );
    539                 // if( ptr ) std::cerr << "FRED1" << std::endl;
    540                 auto type  = dynamic_cast< StructInstType * >( ptr->get_base() );
     529                auto type  = dynamic_cast< StructInstType * >( InitTweak::getPointerBase( param->get_type() ) );
    541530                // if( type ) std::cerr << "FRED2" << std::endl;
    542531                if( type && type->get_baseStruct()->is_thread() ) {
Note: See TracChangeset for help on using the changeset viewer.