Ignore:
File:
1 edited

Legend:

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

    r2065609 r97e3296  
    1919#include <string>                  // for string, operator==
    2020
    21 #include "Common/PassVisitor.h"    // for PassVisitor
    2221#include "Common/SemanticError.h"  // for SemanticError
    2322#include "Common/utility.h"        // for deleteAll, map_range
    24 #include "CodeGen/OperatorTable.h" // for isConstructor
    25 #include "InitTweak/InitTweak.h"   // for getPointerBase
     23#include "InitTweak/InitTweak.h"   // for isConstructor
    2624#include "Parser/LinkageSpec.h"    // for Cforall
    2725#include "SymTab/AddVisit.h"       // for acceptAndAdd
     
    4745
    4846        //=============================================================================================
    49         // Pass declarations
     47        // Visitors declaration
    5048        //=============================================================================================
    5149
     
    5957        //                                           static inline NewField_t * getter_name( MyType * this ) { return &this->newField; }
    6058        //
    61         class ConcurrentSueKeyword : public WithDeclsToAdd {
     59        class ConcurrentSueKeyword : public Visitor {
     60          protected:
     61            template< typename Visitor >
     62            friend void SymTab::acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor );
    6263          public:
    6364
     
    6768                virtual ~ConcurrentSueKeyword() {}
    6869
    69                 void postvisit( StructDecl * decl );
     70                using Visitor::visit;
     71                virtual void visit( StructDecl * decl ) override final;
    7072
    7173                void handle( StructDecl * );
     
    8385                bool needs_main;
    8486
     87                std::list< Declaration * > declsToAdd, declsToAddAfter;
    8588                StructDecl* type_decl = nullptr;
    8689        };
     
    113116
    114117                static void implement( std::list< Declaration * > & translationUnit ) {
    115                         PassVisitor< ThreadKeyword > impl;
    116                         acceptAll( translationUnit, impl );
     118                        ThreadKeyword impl;
     119                        SymTab::acceptAndAdd( translationUnit, impl );
    117120                }
    118121        };
     
    144147
    145148                static void implement( std::list< Declaration * > & translationUnit ) {
    146                         PassVisitor< CoroutineKeyword > impl;
    147                         acceptAll( translationUnit, impl );
     149                        CoroutineKeyword impl;
     150                        SymTab::acceptAndAdd( translationUnit, impl );
    148151                }
    149152        };
     
    175178
    176179                static void implement( std::list< Declaration * > & translationUnit ) {
    177                         PassVisitor< MonitorKeyword > impl;
    178                         acceptAll( translationUnit, impl );
     180                        MonitorKeyword impl;
     181                        SymTab::acceptAndAdd( translationUnit, impl );
    179182                }
    180183        };
     
    188191        // }                                                               }
    189192        //
    190         class MutexKeyword final {
     193        class MutexKeyword final : public Visitor {
    191194          public:
    192195
    193                 void postvisit( FunctionDecl * decl );
    194                 void postvisit(   StructDecl * decl );
     196                using Visitor::visit;
     197                virtual void visit( FunctionDecl * decl ) override final;
     198                virtual void visit(   StructDecl * decl ) override final;
    195199
    196200                std::list<DeclarationWithType*> findMutexArgs( FunctionDecl* );
     
    199203
    200204                static void implement( std::list< Declaration * > & translationUnit ) {
    201                         PassVisitor< MutexKeyword > impl;
     205                        MutexKeyword impl;
    202206                        acceptAll( translationUnit, impl );
    203207                }
     
    225229        // }                                                               }
    226230        //
    227         class ThreadStarter final {
     231        class ThreadStarter final : public Visitor {
    228232          public:
    229233
    230                 void postvisit( FunctionDecl * decl );
     234                using Visitor::visit;
     235                virtual void visit( FunctionDecl * decl ) override final;
    231236
    232237                void addStartStatement( FunctionDecl * decl, DeclarationWithType * param );
    233238
    234239                static void implement( std::list< Declaration * > & translationUnit ) {
    235                         PassVisitor< ThreadStarter > impl;
     240                        ThreadStarter impl;
    236241                        acceptAll( translationUnit, impl );
    237242                }
     
    258263        // Generic keyword implementation
    259264        //=============================================================================================
    260         void ConcurrentSueKeyword::postvisit(StructDecl * decl) {
     265        void ConcurrentSueKeyword::visit(StructDecl * decl) {
     266                Visitor::visit(decl);
    261267                if( decl->get_name() == type_name && decl->has_body() ) {
    262268                        assert( !type_decl );
     
    292298                        LinkageSpec::Cforall,
    293299                        nullptr,
    294                         new ReferenceType(
     300                        new PointerType(
    295301                                noQualifiers,
    296302                                new StructInstType(
     
    346352                }
    347353
    348                 declsToAddBefore.push_back( forward );
    349                 if( needs_main ) declsToAddBefore.push_back( main_decl );
    350                 declsToAddBefore.push_back( get_decl );
     354                declsToAdd.push_back( forward );
     355                if( needs_main ) declsToAdd.push_back( main_decl );
     356                declsToAdd.push_back( get_decl );
    351357
    352358                return get_decl;
     
    398404        //=============================================================================================
    399405
    400         void MutexKeyword::postvisit(FunctionDecl* decl) {
     406        void MutexKeyword::visit(FunctionDecl* decl) {
     407                Visitor::visit(decl);
    401408
    402409                std::list<DeclarationWithType*> mutexArgs = findMutexArgs( decl );
     
    416423        }
    417424
    418         void MutexKeyword::postvisit(StructDecl* decl) {
     425        void MutexKeyword::visit(StructDecl* decl) {
     426                Visitor::visit(decl);
    419427
    420428                if( decl->get_name() == "monitor_desc" ) {
     
    447455
    448456                //Makes sure it's not a copy
    449                 ReferenceType* rty = dynamic_cast< ReferenceType * >( ty );
    450                 if( ! rty ) throw SemanticError( "Mutex argument must be of reference type ", arg );
     457                PointerType* pty = dynamic_cast< PointerType * >( ty );
     458                if( ! pty ) throw SemanticError( "Mutex argument must be of pointer/reference type ", arg );
    451459
    452460                //Make sure the we are pointing directly to a type
    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 );
     461                Type* base = pty->get_base();
     462                if(  dynamic_cast< PointerType * >( base ) ) throw SemanticError( "Mutex argument have exactly one level of indirection ", arg );
    456463
    457464                //Make sure that typed isn't mutex
     
    523530        // General entry routine
    524531        //=============================================================================================
    525         void ThreadStarter::postvisit(FunctionDecl * decl) {
    526                 if( ! CodeGen::isConstructor(decl->get_name()) ) return;
     532        void ThreadStarter::visit(FunctionDecl * decl) {
     533                Visitor::visit(decl);
     534
     535                if( ! InitTweak::isConstructor(decl->get_name()) ) return;
    527536
    528537                DeclarationWithType * param = decl->get_functionType()->get_parameters().front();
    529                 auto type  = dynamic_cast< StructInstType * >( InitTweak::getPointerBase( param->get_type() ) );
     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() );
    530541                // if( type ) std::cerr << "FRED2" << std::endl;
    531542                if( type && type->get_baseStruct()->is_thread() ) {
Note: See TracChangeset for help on using the changeset viewer.