Changeset 2065609


Ignore:
Timestamp:
Aug 28, 2017, 2:59:30 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:
26238c1
Parents:
212c421e
Message:

Added new node to PassVisitor?.
Converted Keywords to PassVisitor?.
Fix crash in build waitfor.

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.h

    r212c421e r2065609  
    7575        virtual void visit( CatchStmt *catchStmt ) override final;
    7676        virtual void visit( FinallyStmt *finallyStmt ) override final;
     77        virtual void visit( WaitForStmt *waitforStmt ) override final;
    7778        virtual void visit( NullStmt *nullStmt ) override final;
    7879        virtual void visit( DeclStmt *declStmt ) override final;
     
    159160        virtual Statement* mutate( ReturnStmt *returnStmt ) override final;
    160161        virtual Statement* mutate( ThrowStmt *throwStmt ) override final;
    161         virtual Statement* mutate( TryStmt *returnStmt ) override final;
     162        virtual Statement* mutate( TryStmt *tryStmt ) override final;
    162163        virtual Statement* mutate( CatchStmt *catchStmt ) override final;
    163         virtual Statement* mutate( FinallyStmt *catchStmt ) override final;
     164        virtual Statement* mutate( FinallyStmt *finallyStmt ) override final;
     165        virtual Statement* mutate( WaitForStmt *waitforStmt ) override final;
    164166        virtual NullStmt* mutate( NullStmt *nullStmt ) override final;
    165167        virtual Statement* mutate( DeclStmt *declStmt ) override final;
  • src/Common/PassVisitor.impl.h

    r212c421e r2065609  
    541541}
    542542
     543//--------------------------------------------------------------------------
     544// FinallyStmt
    543545template< typename pass_type >
    544546void PassVisitor< pass_type >::visit( FinallyStmt * node ) {
     
    547549
    548550template< typename pass_type >
     551Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) {
     552        MUTATE_BODY( Statement, node );
     553}
     554
     555//--------------------------------------------------------------------------
     556// WaitForStmt
     557template< typename pass_type >
     558void PassVisitor< pass_type >::visit( WaitForStmt * node ) {
     559        VISIT_BODY( node );
     560}
     561
     562template< typename pass_type >
     563Statement * PassVisitor< pass_type >::mutate( WaitForStmt * node ) {
     564        MUTATE_BODY( Statement, node );
     565}
     566
     567//--------------------------------------------------------------------------
     568// NullStmt
     569template< typename pass_type >
    549570void PassVisitor< pass_type >::visit( NullStmt * node ) {
    550571        VISIT_BODY( node );
     
    552573
    553574template< typename pass_type >
     575NullStmt * PassVisitor< pass_type >::mutate( NullStmt * node ) {
     576        MUTATE_BODY( NullStmt, node );
     577}
     578
     579//--------------------------------------------------------------------------
     580// DeclStmt
     581template< typename pass_type >
    554582void PassVisitor< pass_type >::visit( DeclStmt * node ) {
    555583        VISIT_BODY( node );
     
    557585
    558586template< typename pass_type >
     587Statement * PassVisitor< pass_type >::mutate( DeclStmt * node ) {
     588        MUTATE_BODY( Statement, node );
     589}
     590
     591//--------------------------------------------------------------------------
     592// ImplicitCtorDtorStmt
     593template< typename pass_type >
    559594void PassVisitor< pass_type >::visit( ImplicitCtorDtorStmt * node ) {
    560595        VISIT_BODY( node );
     
    562597
    563598template< typename pass_type >
     599Statement * PassVisitor< pass_type >::mutate( ImplicitCtorDtorStmt * node ) {
     600        MUTATE_BODY( Statement, node );
     601}
     602
     603//--------------------------------------------------------------------------
     604// ApplicationExpr
     605template< typename pass_type >
    564606void PassVisitor< pass_type >::visit( ApplicationExpr * node ) {
    565607        VISIT_BODY( node );
     608}
     609
     610template< typename pass_type >
     611Expression * PassVisitor< pass_type >::mutate( ApplicationExpr * node ) {
     612        MUTATE_BODY( Expression, node );
    566613}
    567614
     
    944991
    945992template< typename pass_type >
    946 Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) {
    947         MUTATE_BODY( Statement, node );
    948 }
    949 
    950 template< typename pass_type >
    951 NullStmt * PassVisitor< pass_type >::mutate( NullStmt * node ) {
    952         MUTATE_BODY( NullStmt, node );
    953 }
    954 
    955 template< typename pass_type >
    956 Statement * PassVisitor< pass_type >::mutate( DeclStmt * node ) {
    957         MUTATE_BODY( Statement, node );
    958 }
    959 
    960 template< typename pass_type >
    961 Statement * PassVisitor< pass_type >::mutate( ImplicitCtorDtorStmt * node ) {
    962         MUTATE_BODY( Statement, node );
    963 }
    964 
    965 template< typename pass_type >
    966 Expression * PassVisitor< pass_type >::mutate( ApplicationExpr * node ) {
    967         MUTATE_BODY( Expression, node );
    968 }
    969 
    970 template< typename pass_type >
    971993Expression * PassVisitor< pass_type >::mutate( NameExpr * node ) {
    972994        MUTATE_BODY( Expression, node );
  • src/Concurrency/Keywords.cc

    r212c421e 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
     
    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* );
     
    204199
    205200                static void implement( std::list< Declaration * > & translationUnit ) {
    206                         MutexKeyword impl;
     201                        PassVisitor< MutexKeyword > impl;
    207202                        acceptAll( translationUnit, impl );
    208203                }
     
    230225        // }                                                               }
    231226        //
    232         class ThreadStarter final : public Visitor {
     227        class ThreadStarter final {
    233228          public:
    234229
    235                 using Visitor::visit;
    236                 virtual void visit( FunctionDecl * decl ) override final;
     230                void postvisit( FunctionDecl * decl );
    237231
    238232                void addStartStatement( FunctionDecl * decl, DeclarationWithType * param );
    239233
    240234                static void implement( std::list< Declaration * > & translationUnit ) {
    241                         ThreadStarter impl;
     235                        PassVisitor< ThreadStarter > impl;
    242236                        acceptAll( translationUnit, impl );
    243237                }
     
    264258        // Generic keyword implementation
    265259        //=============================================================================================
    266         void ConcurrentSueKeyword::visit(StructDecl * decl) {
    267                 Visitor::visit(decl);
     260        void ConcurrentSueKeyword::postvisit(StructDecl * decl) {
    268261                if( decl->get_name() == type_name && decl->has_body() ) {
    269262                        assert( !type_decl );
     
    353346                }
    354347
    355                 declsToAdd.push_back( forward );
    356                 if( needs_main ) declsToAdd.push_back( main_decl );
    357                 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 );
    358351
    359352                return get_decl;
     
    405398        //=============================================================================================
    406399
    407         void MutexKeyword::visit(FunctionDecl* decl) {
    408                 Visitor::visit(decl);
     400        void MutexKeyword::postvisit(FunctionDecl* decl) {
    409401
    410402                std::list<DeclarationWithType*> mutexArgs = findMutexArgs( decl );
     
    424416        }
    425417
    426         void MutexKeyword::visit(StructDecl* decl) {
    427                 Visitor::visit(decl);
     418        void MutexKeyword::postvisit(StructDecl* decl) {
    428419
    429420                if( decl->get_name() == "monitor_desc" ) {
     
    532523        // General entry routine
    533524        //=============================================================================================
    534         void ThreadStarter::visit(FunctionDecl * decl) {
    535                 Visitor::visit(decl);
    536 
     525        void ThreadStarter::postvisit(FunctionDecl * decl) {
    537526                if( ! CodeGen::isConstructor(decl->get_name()) ) return;
    538527
  • src/Parser/StatementNode.cc

    r212c421e r2065609  
    212212        WaitForStmt::Target target;
    213213        target.function = maybeBuild<Expression>( targetExpr );
    214         buildMoveList< Expression >( targetExpr, target.arguments );
     214
     215        ExpressionNode * next = dynamic_cast<ExpressionNode *>( targetExpr->get_next() );
     216        targetExpr->set_next( nullptr );
     217        buildMoveList< Expression >( next, target.arguments );
     218
    215219        delete targetExpr;
    216220
     
    226230WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when, WaitForStmt * node ) {
    227231        WaitForStmt::Target target;
    228 
    229232        target.function = maybeBuild<Expression>( targetExpr );
    230         buildMoveList< Expression >( targetExpr, target.arguments );
     233
     234        ExpressionNode * next = dynamic_cast<ExpressionNode *>( targetExpr->get_next() );
     235        targetExpr->set_next( nullptr );
     236        buildMoveList< Expression >( next, target.arguments );
     237
    231238        delete targetExpr;
    232239
Note: See TracChangeset for help on using the changeset viewer.