Changes in / [5da9d6a:3d560060]


Ignore:
Location:
src
Files:
4 added
33 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/FixNames.cc

    r5da9d6a r3d560060  
    1919#include <string>                  // for string, operator!=, operator==
    2020
    21 #include "Common/PassVisitor.h"
    2221#include "Common/SemanticError.h"  // for SemanticError
    2322#include "FixMain.h"               // for FixMain
     
    3332
    3433namespace CodeGen {
    35         class FixNames : public WithGuards {
     34        class FixNames : public Visitor {
    3635          public:
    37                 void postvisit( ObjectDecl *objectDecl );
    38                 void postvisit( FunctionDecl *functionDecl );
     36                virtual void visit( ObjectDecl *objectDecl );
     37                virtual void visit( FunctionDecl *functionDecl );
    3938
    40                 void previsit( CompoundStmt *compoundStmt );
     39                virtual void visit( CompoundStmt *compoundStmt );
    4140          private:
    4241                int scopeLevel = 1;
     
    9493        }
    9594
    96         void fixNames( std::list< Declaration* > & translationUnit ) {
    97                 PassVisitor<FixNames> fixer;
     95        void fixNames( std::list< Declaration* > translationUnit ) {
     96                FixNames fixer;
    9897                acceptAll( translationUnit, fixer );
    9998        }
    10099
    101         void FixNames::fixDWT( DeclarationWithType * dwt ) {
     100        void FixNames::fixDWT( DeclarationWithType *dwt ) {
    102101                if ( dwt->get_name() != "" ) {
    103102                        if ( LinkageSpec::isMangled( dwt->get_linkage() ) ) {
     
    108107        }
    109108
    110         void FixNames::postvisit( ObjectDecl * objectDecl ) {
     109        void FixNames::visit( ObjectDecl *objectDecl ) {
     110                Visitor::visit( objectDecl );
    111111                fixDWT( objectDecl );
    112112        }
    113113
    114         void FixNames::postvisit( FunctionDecl * functionDecl ) {
     114        void FixNames::visit( FunctionDecl *functionDecl ) {
     115                Visitor::visit( functionDecl );
    115116                fixDWT( functionDecl );
    116117
     
    120121                                throw SemanticError("Main expected to have 0, 2 or 3 arguments\n", functionDecl);
    121122                        }
    122                         functionDecl->get_statements()->get_kids().push_back( new ReturnStmt( new ConstantExpr( Constant::from_int( 0 ) ) ) );
     123                        functionDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new ConstantExpr( Constant::from_int( 0 ) ) ) );
    123124                        CodeGen::FixMain::registerMain( functionDecl );
    124125                }
    125126        }
    126127
    127         void FixNames::previsit( CompoundStmt * ) {
     128        void FixNames::visit( CompoundStmt *compoundStmt ) {
    128129                scopeLevel++;
    129                 GuardAction( [this](){ scopeLevel--; } );
     130                Visitor::visit( compoundStmt );
     131                scopeLevel--;
    130132        }
    131133} // namespace CodeGen
  • src/CodeGen/FixNames.h

    r5da9d6a r3d560060  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // FixNames.h --
     7// FixNames.h -- 
    88//
    99// Author           : Richard C. Bilson
     
    2222namespace CodeGen {
    2323        /// mangles object and function names
    24         void fixNames( std::list< Declaration* > & translationUnit );
     24        void fixNames( std::list< Declaration* > translationUnit );
    2525} // namespace CodeGen
    2626
  • src/Common/PassVisitor.impl.h

    r5da9d6a r3d560060  
    5555                it,
    5656                [](Declaration * decl) -> auto {
    57                         return new DeclStmt( decl );
     57                        return new DeclStmt( noLabels, decl );
    5858                }
    5959        );
     
    251251            || ( empty( beforeDecls ) && empty( afterDecls )) );
    252252
    253         CompoundStmt *compound = new CompoundStmt();
     253        CompoundStmt *compound = new CompoundStmt( noLabels );
    254254        if( !empty(beforeDecls) ) { splice( std::back_inserter( compound->get_kids() ), beforeDecls ); }
    255255        if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); }
     
    400400        {
    401401                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    402                 // implicit add __func__ identifier as specified in the C manual 6.4.2.2
    403                 static ObjectDecl func(
    404                         "__func__", noStorageClasses, LinkageSpec::C, nullptr,
    405                         new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),
    406                         nullptr
    407                 );
    408                 indexerAddId( &func );
    409402                maybeAccept_impl( node->type, *this );
    410403                maybeAccept_impl( node->statements, *this );
     
    425418        {
    426419                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    427                 // implicit add __func__ identifier as specified in the C manual 6.4.2.2
    428                 static ObjectDecl func(
    429                         "__func__", noStorageClasses, LinkageSpec::C, nullptr,
    430                         new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),
    431                         nullptr
    432                 );
    433                 indexerAddId( &func );
    434420                maybeMutate_impl( node->type, *this );
    435421                maybeMutate_impl( node->statements, *this );
  • src/Concurrency/Keywords.cc

    r5da9d6a r3d560060  
    3838
    3939namespace Concurrency {
     40
     41        namespace {
     42                const std::list<Label> noLabels;
     43                const std::list< Attribute * > noAttributes;
     44                Type::StorageClasses noStorage;
     45                Type::Qualifiers noQualifiers;
     46        }
     47
    4048        //=============================================================================================
    4149        // Pass declarations
     
    288296                ObjectDecl * this_decl = new ObjectDecl(
    289297                        "this",
    290                         noStorageClasses,
     298                        noStorage,
    291299                        LinkageSpec::Cforall,
    292300                        nullptr,
     
    305313                        new ObjectDecl(
    306314                                "ret",
    307                                 noStorageClasses,
     315                                noStorage,
    308316                                LinkageSpec::Cforall,
    309317                                nullptr,
     
    338346                        main_decl = new FunctionDecl(
    339347                                "main",
    340                                 noStorageClasses,
     348                                noStorage,
    341349                                LinkageSpec::Cforall,
    342350                                main_type,
     
    355363                ObjectDecl * field = new ObjectDecl(
    356364                        field_name,
    357                         noStorageClasses,
     365                        noStorage,
    358366                        LinkageSpec::Cforall,
    359367                        nullptr,
     
    371379
    372380        void ConcurrentSueKeyword::addRoutines( ObjectDecl * field, FunctionDecl * func ) {
    373                 CompoundStmt * statement = new CompoundStmt();
     381                CompoundStmt * statement = new CompoundStmt( noLabels );
    374382                statement->push_back(
    375383                        new ReturnStmt(
     384                                noLabels,
    376385                                new AddressExpr(
    377386                                        new MemberExpr(
     
    479488                ObjectDecl * monitors = new ObjectDecl(
    480489                        "__monitor",
    481                         noStorageClasses,
     490                        noStorage,
    482491                        LinkageSpec::Cforall,
    483492                        nullptr,
     
    500509                // monitor_guard_t __guard = { __monitors, #, func };
    501510                body->push_front(
    502                         new DeclStmt( new ObjectDecl(
     511                        new DeclStmt( noLabels, new ObjectDecl(
    503512                                "__guard",
    504                                 noStorageClasses,
     513                                noStorage,
    505514                                LinkageSpec::Cforall,
    506515                                nullptr,
     
    521530
    522531                //monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) };
    523                 body->push_front( new DeclStmt( monitors) );
     532                body->push_front( new DeclStmt( noLabels, monitors) );
    524533        }
    525534
     
    527536                ObjectDecl * monitors = new ObjectDecl(
    528537                        "__monitors",
    529                         noStorageClasses,
     538                        noStorage,
    530539                        LinkageSpec::Cforall,
    531540                        nullptr,
     
    560569                // monitor_guard_t __guard = { __monitors, #, func };
    561570                body->push_front(
    562                         new DeclStmt( new ObjectDecl(
     571                        new DeclStmt( noLabels, new ObjectDecl(
    563572                                "__guard",
    564                                 noStorageClasses,
     573                                noStorage,
    565574                                LinkageSpec::Cforall,
    566575                                nullptr,
     
    582591
    583592                //monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) };
    584                 body->push_front( new DeclStmt( monitors) );
     593                body->push_front( new DeclStmt( noLabels, monitors) );
    585594        }
    586595
     
    622631                stmt->push_back(
    623632                        new ExprStmt(
     633                                noLabels,
    624634                                new UntypedExpr(
    625635                                        new NameExpr( "__thrd_start" ),
  • src/Concurrency/Waitfor.cc

    r5da9d6a r3d560060  
    100100
    101101namespace Concurrency {
     102
     103        namespace {
     104                const std::list<Label> noLabels;
     105                const std::list< Attribute * > noAttributes;
     106                Type::StorageClasses noStorage;
     107                Type::Qualifiers noQualifiers;
     108        }
     109
    102110        //=============================================================================================
    103111        // Pass declarations
     
    195203                        ResolvExpr::findVoidExpression( expr, indexer );
    196204
    197                         return new ExprStmt( expr );
     205                        return new ExprStmt( noLabels, expr );
    198206                }
    199207
     
    251259                if( !decl_monitor || !decl_acceptable || !decl_mask ) throw SemanticError( "waitfor keyword requires monitors to be in scope, add #include <monitor>", waitfor );
    252260
    253                 CompoundStmt * stmt = new CompoundStmt();
     261                CompoundStmt * stmt = new CompoundStmt( noLabels );
    254262
    255263                ObjectDecl * acceptables = declare( waitfor->clauses.size(), stmt );
     
    273281                );
    274282
    275                 CompoundStmt * compound = new CompoundStmt();
     283                CompoundStmt * compound = new CompoundStmt( noLabels );
    276284                stmt->push_back( new IfStmt(
     285                        noLabels,
    277286                        safeCond( new VariableExpr( flag ) ),
    278287                        compound,
     
    304313                );
    305314
    306                 stmt->push_back( new DeclStmt( acceptables) );
     315                stmt->push_back( new DeclStmt( noLabels, acceptables) );
    307316
    308317                Expression * set = new UntypedExpr(
     
    317326                ResolvExpr::findVoidExpression( set, indexer );
    318327
    319                 stmt->push_back( new ExprStmt( set ) );
     328                stmt->push_back( new ExprStmt( noLabels, set ) );
    320329
    321330                return acceptables;
     
    332341                );
    333342
    334                 stmt->push_back( new DeclStmt( flag) );
     343                stmt->push_back( new DeclStmt( noLabels, flag) );
    335344
    336345                return flag;
     
    348357                ResolvExpr::findVoidExpression( expr, indexer );
    349358
    350                 return new ExprStmt( expr );
     359                return new ExprStmt( noLabels, expr );
    351360        }
    352361
     
    390399                );
    391400
    392                 stmt->push_back( new DeclStmt( mon) );
     401                stmt->push_back( new DeclStmt( noLabels, mon) );
    393402
    394403                return mon;
     
    402411
    403412                stmt->push_back( new IfStmt(
     413                        noLabels,
    404414                        safeCond( clause.condition ),
    405415                        new CompoundStmt({
     
    437447                );
    438448
    439                 stmt->push_back( new DeclStmt( timeout ) );
     449                stmt->push_back( new DeclStmt( noLabels, timeout ) );
    440450
    441451                if( time ) {
    442452                        stmt->push_back( new IfStmt(
     453                                noLabels,
    443454                                safeCond( time_cond ),
    444455                                new CompoundStmt({
    445456                                        new ExprStmt(
     457                                                noLabels,
    446458                                                makeOpAssign(
    447459                                                        new VariableExpr( timeout ),
     
    459471                if( has_else ) {
    460472                        stmt->push_back( new IfStmt(
     473                                noLabels,
    461474                                safeCond( else_cond ),
    462475                                new CompoundStmt({
    463476                                        new ExprStmt(
     477                                                noLabels,
    464478                                                makeOpAssign(
    465479                                                        new VariableExpr( timeout ),
     
    497511                );
    498512
    499                 stmt->push_back( new DeclStmt( index ) );
     513                stmt->push_back( new DeclStmt( noLabels, index ) );
    500514
    501515                ObjectDecl * mask = ObjectDecl::newObject(
     
    512526                );
    513527
    514                 stmt->push_back( new DeclStmt( mask ) );
     528                stmt->push_back( new DeclStmt( noLabels, mask ) );
    515529
    516530                stmt->push_back( new ExprStmt(
     531                        noLabels,
    517532                        new ApplicationExpr(
    518533                                VariableExpr::functionPointer( decl_waitfor ),
     
    542557        ) {
    543558                SwitchStmt * swtch = new SwitchStmt(
     559                        noLabels,
    544560                        result,
    545561                        std::list<Statement *>()
     
    550566                        swtch->statements.push_back(
    551567                                new CaseStmt(
     568                                        noLabels,
    552569                                        new ConstantExpr( Constant::from_ulong( i++ ) ),
    553570                                        {
    554571                                                clause.statement,
    555572                                                new BranchStmt(
     573                                                        noLabels,
    556574                                                        "",
    557575                                                        BranchStmt::Break
     
    565583                        swtch->statements.push_back(
    566584                                new CaseStmt(
     585                                        noLabels,
    567586                                        new ConstantExpr( Constant::from_int( -2 ) ),
    568587                                        {
    569588                                                waitfor->timeout.statement,
    570589                                                new BranchStmt(
     590                                                        noLabels,
    571591                                                        "",
    572592                                                        BranchStmt::Break
     
    580600                        swtch->statements.push_back(
    581601                                new CaseStmt(
     602                                        noLabels,
    582603                                        new ConstantExpr( Constant::from_int( -1 ) ),
    583604                                        {
    584605                                                waitfor->orelse.statement,
    585606                                                new BranchStmt(
     607                                                        noLabels,
    586608                                                        "",
    587609                                                        BranchStmt::Break
  • src/ControlStruct/ExceptTranslate.cc

    r5da9d6a r3d560060  
    3030#include "SynTree/Expression.h"       // for UntypedExpr, ConstantExpr, Name...
    3131#include "SynTree/Initializer.h"      // for SingleInit, ListInit
    32 #include "SynTree/Label.h"            // for Label
     32#include "SynTree/Label.h"            // for Label, noLabels
    3333#include "SynTree/Mutator.h"          // for mutateAll
    3434#include "SynTree/Statement.h"        // for CompoundStmt, CatchStmt, ThrowStmt
     
    5757
    5858        void appendDeclStmt( CompoundStmt * block, Declaration * item ) {
    59                 block->push_back(new DeclStmt(item));
     59                block->push_back(new DeclStmt(noLabels, item));
    6060        }
    6161
     
    205205                throwStmt->set_expr( nullptr );
    206206                delete throwStmt;
    207                 return new ExprStmt( call );
     207                return new ExprStmt( noLabels, call );
    208208        }
    209209
     
    220220                assert( handler_except_decl );
    221221
    222                 CompoundStmt * result = new CompoundStmt();
    223                 result->labels =  throwStmt->labels;
    224                 result->push_back( new ExprStmt( UntypedExpr::createAssign(
     222                CompoundStmt * result = new CompoundStmt( throwStmt->get_labels() );
     223                result->push_back( new ExprStmt( noLabels, UntypedExpr::createAssign(
    225224                        nameOf( handler_except_decl ),
    226225                        new ConstantExpr( Constant::null(
     
    232231                        ) ) );
    233232                result->push_back( new ExprStmt(
     233                        noLabels,
    234234                        new UntypedExpr( new NameExpr( "__cfaabi_ehm__rethrow_terminate" ) )
    235235                        ) );
     
    248248                // return false;
    249249                Statement * result = new ReturnStmt(
     250                        throwStmt->get_labels(),
    250251                        new ConstantExpr( Constant::from_bool( false ) )
    251252                        );
    252                 result->labels = throwStmt->labels;
    253253                delete throwStmt;
    254254                return result;
     
    291291                        // }
    292292                        // return;
    293                         CompoundStmt * block = new CompoundStmt();
     293                        CompoundStmt * block = new CompoundStmt( noLabels );
    294294
    295295                        // Just copy the exception value. (Post Validation)
     
    304304                                        ) })
    305305                                );
    306                         block->push_back( new DeclStmt( local_except ) );
     306                        block->push_back( new DeclStmt( noLabels, local_except ) );
    307307
    308308                        // Add the cleanup attribute.
     
    324324
    325325                        std::list<Statement *> caseBody
    326                                         { block, new ReturnStmt( nullptr ) };
     326                                        { block, new ReturnStmt( noLabels, nullptr ) };
    327327                        handler_wrappers.push_back( new CaseStmt(
     328                                noLabels,
    328329                                new ConstantExpr( Constant::from_int( index ) ),
    329330                                caseBody
     
    339340
    340341                SwitchStmt * handler_lookup = new SwitchStmt(
     342                        noLabels,
    341343                        nameOf( index_obj ),
    342344                        stmt_handlers
    343345                        );
    344                 CompoundStmt * body = new CompoundStmt();
     346                CompoundStmt * body = new CompoundStmt( noLabels );
    345347                body->push_back( handler_lookup );
    346348
     
    361363                // }
    362364
    363                 CompoundStmt * block = new CompoundStmt();
     365                CompoundStmt * block = new CompoundStmt( noLabels );
    364366
    365367                // Local Declaration
     
    367369                        dynamic_cast<ObjectDecl *>( modded_handler->get_decl() );
    368370                assert( local_except );
    369                 block->push_back( new DeclStmt( local_except ) );
     371                block->push_back( new DeclStmt( noLabels, local_except ) );
    370372
    371373                // Check for type match.
     
    379381                }
    380382                // Construct the match condition.
    381                 block->push_back( new IfStmt(
     383                block->push_back( new IfStmt( noLabels,
    382384                        cond, modded_handler->get_body(), nullptr ) );
    383385
     
    395397                // }
    396398
    397                 CompoundStmt * body = new CompoundStmt();
     399                CompoundStmt * body = new CompoundStmt( noLabels );
    398400
    399401                FunctionType * func_type = match_func_t.clone();
     
    411413
    412414                        // Create new body.
    413                         handler->set_body( new ReturnStmt(
     415                        handler->set_body( new ReturnStmt( noLabels,
    414416                                new ConstantExpr( Constant::from_int( index ) ) ) );
    415417
     
    419421                }
    420422
    421                 body->push_back( new ReturnStmt(
     423                body->push_back( new ReturnStmt( noLabels,
    422424                        new ConstantExpr( Constant::from_int( 0 ) ) ) );
    423425
     
    439441                args.push_back( nameOf( terminate_match ) );
    440442
    441                 CompoundStmt * callStmt = new CompoundStmt();
    442                 callStmt->push_back( new ExprStmt( caller ) );
     443                CompoundStmt * callStmt = new CompoundStmt( noLabels );
     444                callStmt->push_back( new ExprStmt( noLabels, caller ) );
    443445                return callStmt;
    444446        }
     
    449451                //     HANDLER WRAPPERS { `hander->body`; return true; }
    450452                // }
    451                 CompoundStmt * body = new CompoundStmt();
     453                CompoundStmt * body = new CompoundStmt( noLabels );
    452454
    453455                FunctionType * func_type = handle_func_t.clone();
     
    462464                                dynamic_cast<CompoundStmt*>( handler->get_body() );
    463465                        if ( ! handling_code ) {
    464                                 handling_code = new CompoundStmt();
     466                                handling_code = new CompoundStmt( noLabels );
    465467                                handling_code->push_back( handler->get_body() );
    466468                        }
    467                         handling_code->push_back( new ReturnStmt(
     469                        handling_code->push_back( new ReturnStmt( noLabels,
    468470                                new ConstantExpr( Constant::from_bool( true ) ) ) );
    469471                        handler->set_body( handling_code );
     
    474476                }
    475477
    476                 body->push_back( new ReturnStmt(
     478                body->push_back( new ReturnStmt( noLabels,
    477479                        new ConstantExpr( Constant::from_bool( false ) ) ) );
    478480
     
    484486                        Statement * wraps,
    485487                        FunctionDecl * resume_handler ) {
    486                 CompoundStmt * body = new CompoundStmt();
     488                CompoundStmt * body = new CompoundStmt( noLabels );
    487489
    488490                // struct __try_resume_node __resume_node
     
    519521                setup->get_args().push_back( nameOf( resume_handler ) );
    520522
    521                 body->push_back( new ExprStmt( setup ) );
     523                body->push_back( new ExprStmt( noLabels, setup ) );
    522524
    523525                body->push_back( wraps );
     
    644646                // Generate a prefix for the function names?
    645647
    646                 CompoundStmt * block = new CompoundStmt();
     648                CompoundStmt * block = new CompoundStmt( noLabels );
    647649                CompoundStmt * inner = take_try_block( tryStmt );
    648650
  • src/ControlStruct/ForExprMutator.cc

    r5da9d6a r3d560060  
    2929                // Create compound statement, move initializers outside,
    3030                // the resut of the original stays as is.
    31                 CompoundStmt *block = new CompoundStmt();
     31                CompoundStmt *block = new CompoundStmt( std::list< Label >() );
    3232                std::list<Statement *> &stmts = block->get_kids();
    3333                stmts.splice( stmts.end(), init );
  • src/ControlStruct/LabelFixer.cc

    r5da9d6a r3d560060  
    3737        }
    3838
    39         void LabelFixer::previsit( FunctionDecl * ) {
     39        void LabelFixer::visit( FunctionDecl *functionDecl ) {
    4040                // need to go into a nested function in a fresh state
    41                 GuardValue( labelTable );
     41                std::map < Label, Entry *> oldLabelTable = labelTable;
    4242                labelTable.clear();
    43         }
    4443
    45         void LabelFixer::postvisit( FunctionDecl * functionDecl ) {
     44                maybeAccept( functionDecl->get_statements(), *this );
     45
    4646                MLEMutator mlemut( resolveJumps(), generator );
    4747                functionDecl->acceptMutator( mlemut );
     48
     49                // and remember the outer function's labels when
     50                // returning to it
     51                labelTable = oldLabelTable;
    4852        }
    4953
    5054        // prune to at most one label definition for each statement
    51         void LabelFixer::previsit( Statement *stmt ) {
     55        void LabelFixer::visit( Statement *stmt ) {
    5256                std::list< Label > &labels = stmt->get_labels();
    5357
     
    5862        }
    5963
    60         void LabelFixer::previsit( BranchStmt *branchStmt ) {
    61                 previsit( ( Statement *)branchStmt );
     64        void LabelFixer::visit( BranchStmt *branchStmt ) {
     65                visit ( ( Statement * )branchStmt );
    6266
    6367                // for labeled branches, add an entry to the label table
     
    6872        }
    6973
    70         void LabelFixer::previsit( LabelAddressExpr * addrExpr ) {
    71                 Label & target = addrExpr->arg;
    72                 assert( target != "" );
    73                 setLabelsUsg( target, addrExpr );
     74        void LabelFixer::visit( UntypedExpr *untyped ) {
     75                if ( NameExpr * func = dynamic_cast< NameExpr * >( untyped->get_function() ) ) {
     76                        if ( func->get_name() == "&&" ) {
     77                                NameExpr * arg = dynamic_cast< NameExpr * >( untyped->get_args().front() );
     78                                Label target = arg->get_name();
     79                                assert( target != "" );
     80                                setLabelsUsg( target, untyped );
     81                        } else {
     82                                Visitor::visit( untyped );
     83                        }
     84                }
    7485        }
    7586
  • src/ControlStruct/LabelFixer.h

    r5da9d6a r3d560060  
    1919#include <map>                     // for map
    2020
    21 #include "Common/PassVisitor.h"
    2221#include "Common/SemanticError.h"  // for SemanticError
    2322#include "SynTree/Label.h"         // for Label
     
    2726namespace ControlStruct {
    2827        /// normalizes label definitions and generates multi-level exit labels
    29         class LabelGenerator;
     28class LabelGenerator;
    3029
    31         class LabelFixer final : public WithGuards {
     30        class LabelFixer final : public Visitor {
     31                typedef Visitor Parent;
    3232          public:
    3333                LabelFixer( LabelGenerator *gen = 0 );
     
    3535                std::map < Label, Statement * > *resolveJumps() throw ( SemanticError );
    3636
     37                using Visitor::visit;
     38
    3739                // Declarations
    38                 void previsit( FunctionDecl *functionDecl );
    39                 void postvisit( FunctionDecl *functionDecl );
     40                virtual void visit( FunctionDecl *functionDecl ) override;
    4041
    4142                // Statements
    42                 void previsit( Statement *stmt );
    43                 void previsit( BranchStmt *branchStmt );
     43                void visit( Statement *stmt );
    4444
    45                 // Expressions
    46                 void previsit( LabelAddressExpr *addrExpr );
     45                virtual void visit( CompoundStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     46                virtual void visit( NullStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     47                virtual void visit( ExprStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     48                virtual void visit( IfStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     49                virtual void visit( WhileStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     50                virtual void visit( ForStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     51                virtual void visit( SwitchStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     52                virtual void visit( CaseStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     53                virtual void visit( ReturnStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     54                virtual void visit( TryStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     55                virtual void visit( CatchStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     56                virtual void visit( DeclStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     57                virtual void visit( BranchStmt *branchStmt ) override;
     58                virtual void visit( UntypedExpr *untyped ) override;
    4759
    4860                Label setLabelsDef( std::list< Label > &, Statement *definition );
  • src/ControlStruct/MLEMutator.cc

    r5da9d6a r3d560060  
    149149
    150150                        if ( CaseStmt * c = dynamic_cast< CaseStmt * >( statements.back() ) ) {
    151                                 Statement * stmt = new BranchStmt( Label("brkLabel"), BranchStmt::Break );
    152                                 stmt->labels.push_back( brkLabel );
    153                                 c->get_statements().push_back( stmt );
     151                                std::list<Label> temp; temp.push_back( brkLabel );
     152                                c->get_statements().push_back( new BranchStmt( temp, Label("brkLabel"), BranchStmt::Break ) );
    154153                        } else assert(0); // as of this point, all statements of a switch are still CaseStmts
    155154                } // if
     
    233232                // transform break/continue statements into goto to simplify later handling of branches
    234233                delete branchStmt;
    235                 return new BranchStmt( exitLabel, BranchStmt::Goto );
     234                return new BranchStmt( std::list<Label>(), exitLabel, BranchStmt::Goto );
    236235        }
    237236
     
    240239                CompoundStmt *newBody;
    241240                if ( ! (newBody = dynamic_cast<CompoundStmt *>( bodyLoop )) ) {
    242                         newBody = new CompoundStmt();
     241                        newBody = new CompoundStmt( std::list< Label >() );
    243242                        newBody->get_kids().push_back( bodyLoop );
    244243                } // if
  • src/ControlStruct/Mutate.cc

    r5da9d6a r3d560060  
    2424#include "SynTree/Declaration.h"   // for Declaration
    2525#include "SynTree/Mutator.h"       // for mutateAll
     26//#include "ExceptMutator.h"
    2627
    2728#include "Common/PassVisitor.h"    // for PassVisitor
     
    3637
    3738                // normalizes label definitions and generates multi-level exit labels
    38                 PassVisitor<LabelFixer> lfix;
     39                LabelFixer lfix;
     40
     41                //ExceptMutator exc;
    3942
    4043                mutateAll( translationUnit, formut );
    4144                acceptAll( translationUnit, lfix );
     45                //mutateAll( translationUnit, exc );
    4246        }
    4347} // namespace CodeGen
  • src/GenPoly/Box.cc

    r5da9d6a r3d560060  
    4949#include "SynTree/Expression.h"          // for ApplicationExpr, UntypedExpr
    5050#include "SynTree/Initializer.h"         // for SingleInit, Initializer, Lis...
    51 #include "SynTree/Label.h"               // for Label
     51#include "SynTree/Label.h"               // for Label, noLabels
    5252#include "SynTree/Mutator.h"             // for maybeMutate, Mutator, mutateAll
    5353#include "SynTree/Statement.h"           // for ExprStmt, DeclStmt, ReturnStmt
     
    293293                FunctionDecl *layoutDecl = new FunctionDecl( layoutofName( typeDecl ),
    294294                                                                                                         functionNesting > 0 ? Type::StorageClasses() : Type::StorageClasses( Type::Static ),
    295                                                                                                          LinkageSpec::AutoGen, layoutFnType, new CompoundStmt(),
     295                                                                                                         LinkageSpec::AutoGen, layoutFnType, new CompoundStmt( noLabels ),
    296296                                                                                                         std::list< Attribute * >(), Type::FuncSpecifiers( Type::Inline ) );
    297297                layoutDecl->fixUniqueId();
     
    321321        /// makes an if-statement with a single-expression if-block and no then block
    322322        Statement *makeCond( Expression *cond, Expression *ifPart ) {
    323                 return new IfStmt( cond, new ExprStmt( ifPart ), 0 );
     323                return new IfStmt( noLabels, cond, new ExprStmt( noLabels, ifPart ), 0 );
    324324        }
    325325
     
    340340        /// adds an expression to a compound statement
    341341        void addExpr( CompoundStmt *stmts, Expression *expr ) {
    342                 stmts->get_kids().push_back( new ExprStmt( expr ) );
     342                stmts->get_kids().push_back( new ExprStmt( noLabels, expr ) );
    343343        }
    344344
     
    629629                ObjectDecl *Pass1::makeTemporary( Type *type ) {
    630630                        ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), Type::StorageClasses(), LinkageSpec::C, 0, type, 0 );
    631                         stmtsToAddBefore.push_back( new DeclStmt( newObj ) );
     631                        stmtsToAddBefore.push_back( new DeclStmt( noLabels, newObj ) );
    632632                        return newObj;
    633633                }
     
    740740                                ObjectDecl *newObj = ObjectDecl::newObject( tempNamer.newName(), newType, nullptr );
    741741                                newObj->get_type()->get_qualifiers() = Type::Qualifiers(); // TODO: is this right???
    742                                 stmtsToAddBefore.push_back( new DeclStmt( newObj ) );
     742                                stmtsToAddBefore.push_back( new DeclStmt( noLabels, newObj ) );
    743743                                UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); // TODO: why doesn't this just use initialization syntax?
    744744                                assign->get_args().push_back( new VariableExpr( newObj ) );
    745745                                assign->get_args().push_back( arg );
    746                                 stmtsToAddBefore.push_back( new ExprStmt( assign ) );
     746                                stmtsToAddBefore.push_back( new ExprStmt( noLabels, assign ) );
    747747                                arg = new AddressExpr( new VariableExpr( newObj ) );
    748748                        } // if
     
    888888                                // void return
    889889                                addAdapterParams( adapteeApp, arg, param, adapterType->get_parameters().end(), realParam, tyVars );
    890                                 bodyStmt = new ExprStmt( adapteeApp );
     890                                bodyStmt = new ExprStmt( noLabels, adapteeApp );
    891891                        } else if ( isDynType( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
    892892                                // return type T
     
    900900                                addAdapterParams( adapteeApp, arg, param, adapterType->get_parameters().end(), realParam, tyVars );
    901901                                assign->get_args().push_back( adapteeApp );
    902                                 bodyStmt = new ExprStmt( assign );
     902                                bodyStmt = new ExprStmt( noLabels, assign );
    903903                        } else {
    904904                                // adapter for a function that returns a monomorphic value
    905905                                addAdapterParams( adapteeApp, arg, param, adapterType->get_parameters().end(), realParam, tyVars );
    906                                 bodyStmt = new ReturnStmt( adapteeApp );
     906                                bodyStmt = new ReturnStmt( noLabels, adapteeApp );
    907907                        } // if
    908                         CompoundStmt *adapterBody = new CompoundStmt();
     908                        CompoundStmt *adapterBody = new CompoundStmt( noLabels );
    909909                        adapterBody->get_kids().push_back( bodyStmt );
    910910                        std::string adapterName = makeAdapterName( mangleName );
     
    952952                                                std::pair< AdapterIter, bool > answer = adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, newAdapter ) );
    953953                                                adapter = answer.first;
    954                                                 stmtsToAddBefore.push_back( new DeclStmt( newAdapter ) );
     954                                                stmtsToAddBefore.push_back( new DeclStmt( noLabels, newAdapter ) );
    955955                                        } // if
    956956                                        assert( adapter != adapters.end() );
     
    12791279                                                retval->set_name( "_retval" );
    12801280                                        }
    1281                                         functionDecl->get_statements()->get_kids().push_front( new DeclStmt( retval ) );
     1281                                        functionDecl->get_statements()->get_kids().push_front( new DeclStmt( noLabels, retval ) );
    12821282                                        DeclarationWithType * newRet = retval->clone(); // for ownership purposes
    12831283                                        ftype->get_returnVals().front() = newRet;
     
    15191519                                        // (alloca was previously used, but can't be safely used in loops)
    15201520                                        ObjectDecl *newBuf = ObjectDecl::newObject( bufNamer.newName(), polyToMonoType( objectDecl->type ), nullptr );
    1521                                         stmtsToAddBefore.push_back( new DeclStmt( newBuf ) );
     1521                                        stmtsToAddBefore.push_back( new DeclStmt( noLabels, newBuf ) );
    15221522
    15231523                                        delete objectDecl->get_init();
     
    15981598                ObjectDecl *PolyGenericCalculator::makeVar( const std::string &name, Type *type, Initializer *init ) {
    15991599                        ObjectDecl *newObj = new ObjectDecl( name, Type::StorageClasses(), LinkageSpec::C, 0, type, init );
    1600                         stmtsToAddBefore.push_back( new DeclStmt( newObj ) );
     1600                        stmtsToAddBefore.push_back( new DeclStmt( noLabels, newObj ) );
    16011601                        return newObj;
    16021602                }
     
    16771677                                        addOtypeParamsToLayoutCall( layoutCall, otypeParams );
    16781678
    1679                                         stmtsToAddBefore.push_back( new ExprStmt( layoutCall ) );
     1679                                        stmtsToAddBefore.push_back( new ExprStmt( noLabels, layoutCall ) );
    16801680                                }
    16811681
     
    17031703                                addOtypeParamsToLayoutCall( layoutCall, otypeParams );
    17041704
    1705                                 stmtsToAddBefore.push_back( new ExprStmt( layoutCall ) );
     1705                                stmtsToAddBefore.push_back( new ExprStmt( noLabels, layoutCall ) );
    17061706
    17071707                                return true;
  • src/GenPoly/InstantiateGeneric.cc

    r5da9d6a r3d560060  
    526526                                        Expression * init = new CastExpr( new AddressExpr( memberExpr ), new PointerType( Type::Qualifiers(), concType->clone() ) );
    527527                                        ObjectDecl * tmp = ObjectDecl::newObject( tmpNamer.newName(), new ReferenceType( Type::Qualifiers(), concType ), new SingleInit( init ) );
    528                                         stmtsToAddBefore.push_back( new DeclStmt( tmp ) );
     528                                        stmtsToAddBefore.push_back( new DeclStmt( noLabels, tmp ) );
    529529                                        return new VariableExpr( tmp );
    530530                                } else {
  • src/GenPoly/Specialize.cc

    r5da9d6a r3d560060  
    3535#include "SynTree/Declaration.h"         // for FunctionDecl, DeclarationWit...
    3636#include "SynTree/Expression.h"          // for ApplicationExpr, Expression
    37 #include "SynTree/Label.h"               // for Label
     37#include "SynTree/Label.h"               // for Label, noLabels
    3838#include "SynTree/Mutator.h"             // for mutateAll
    3939#include "SynTree/Statement.h"           // for CompoundStmt, DeclStmt, Expr...
     
    234234                } // if
    235235                // create new thunk with same signature as formal type (C linkage, empty body)
    236                 FunctionDecl *thunkFunc = new FunctionDecl( thunkNamer.newName(), Type::StorageClasses(), LinkageSpec::C, newType, new CompoundStmt() );
     236                FunctionDecl *thunkFunc = new FunctionDecl( thunkNamer.newName(), Type::StorageClasses(), LinkageSpec::C, newType, new CompoundStmt( noLabels ) );
    237237                thunkFunc->fixUniqueId();
    238238
     
    287287                Statement *appStmt;
    288288                if ( funType->returnVals.empty() ) {
    289                         appStmt = new ExprStmt( appExpr );
    290                 } else {
    291                         appStmt = new ReturnStmt( appExpr );
     289                        appStmt = new ExprStmt( noLabels, appExpr );
     290                } else {
     291                        appStmt = new ReturnStmt( noLabels, appExpr );
    292292                } // if
    293293                thunkFunc->statements->kids.push_back( appStmt );
    294294
    295295                // add thunk definition to queue of statements to add
    296                 stmtsToAddBefore.push_back( new DeclStmt( thunkFunc ) );
     296                stmtsToAddBefore.push_back( new DeclStmt( noLabels, thunkFunc ) );
    297297                // return address of thunk function as replacement expression
    298298                return new AddressExpr( new VariableExpr( thunkFunc ) );
  • src/InitTweak/FixGlobalInit.cc

    r5da9d6a r3d560060  
    2020#include <algorithm>               // for replace_if
    2121
    22 #include "Common/PassVisitor.h"
    2322#include "Common/SemanticError.h"  // for SemanticError
    2423#include "Common/UniqueName.h"     // for UniqueName
     
    3029#include "SynTree/Expression.h"    // for ConstantExpr, Expression (ptr only)
    3130#include "SynTree/Initializer.h"   // for ConstructorInit, Initializer
    32 #include "SynTree/Label.h"         // for Label
     31#include "SynTree/Label.h"         // for Label, noLabels
    3332#include "SynTree/Statement.h"     // for CompoundStmt, Statement (ptr only)
    3433#include "SynTree/Type.h"          // for Type, Type::StorageClasses, Functi...
     
    3635
    3736namespace InitTweak {
    38         class GlobalFixer : public WithShortCircuiting {
     37        class GlobalFixer : public Visitor {
    3938          public:
    4039                GlobalFixer( const std::string & name, bool inLibrary );
    4140
    42                 void previsit( ObjectDecl *objDecl );
    43                 void previsit( FunctionDecl *functionDecl );
    44                 void previsit( StructDecl *aggregateDecl );
    45                 void previsit( UnionDecl *aggregateDecl );
    46                 void previsit( EnumDecl *aggregateDecl );
    47                 void previsit( TraitDecl *aggregateDecl );
    48                 void previsit( TypeDecl *typeDecl );
     41                virtual void visit( ObjectDecl *objDecl );
     42                virtual void visit( FunctionDecl *functionDecl );
     43                virtual void visit( StructDecl *aggregateDecl );
     44                virtual void visit( UnionDecl *aggregateDecl );
     45                virtual void visit( EnumDecl *aggregateDecl );
     46                virtual void visit( TraitDecl *aggregateDecl );
     47                virtual void visit( TypeDecl *typeDecl );
    4948
    5049                UniqueName tempNamer;
     
    5453
    5554        void fixGlobalInit( std::list< Declaration * > & translationUnit, const std::string & name, bool inLibrary ) {
    56                 PassVisitor<GlobalFixer> visitor( name, inLibrary );
    57                 acceptAll( translationUnit, visitor );
    58                 GlobalFixer & fixer = visitor.pass;
     55                GlobalFixer fixer( name, inLibrary );
     56                acceptAll( translationUnit, fixer );
    5957                // don't need to include function if it's empty
    6058                if ( fixer.initFunction->get_statements()->get_kids().empty() ) {
     
    9492                        dtorParameters.push_back( new ConstantExpr( Constant::from_int( 102 ) ) );
    9593                }
    96                 initFunction = new FunctionDecl( "_init_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() );
     94                initFunction = new FunctionDecl( "_init_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ) );
    9795                initFunction->get_attributes().push_back( new Attribute( "constructor", ctorParameters ) );
    98                 destroyFunction = new FunctionDecl( "_destroy_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() );
     96                destroyFunction = new FunctionDecl( "_destroy_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ) );
    9997                destroyFunction->get_attributes().push_back( new Attribute( "destructor", dtorParameters ) );
    10098        }
    10199
    102         void GlobalFixer::previsit( ObjectDecl *objDecl ) {
     100        void GlobalFixer::visit( ObjectDecl *objDecl ) {
    103101                std::list< Statement * > & initStatements = initFunction->get_statements()->get_kids();
    104102                std::list< Statement * > & destroyStatements = destroyFunction->get_statements()->get_kids();
     
    136134
    137135        // only modify global variables
    138         void GlobalFixer::previsit( FunctionDecl * ) { visit_children = false; }
    139         void GlobalFixer::previsit( StructDecl * ) { visit_children = false; }
    140         void GlobalFixer::previsit( UnionDecl * ) { visit_children = false; }
    141         void GlobalFixer::previsit( EnumDecl * ) { visit_children = false; }
    142         void GlobalFixer::previsit( TraitDecl * ) { visit_children = false; }
    143         void GlobalFixer::previsit( TypeDecl * ) { visit_children = false; }
     136        void GlobalFixer::visit( __attribute__((unused)) FunctionDecl *functionDecl ) {}
     137        void GlobalFixer::visit( __attribute__((unused)) StructDecl *aggregateDecl ) {}
     138        void GlobalFixer::visit( __attribute__((unused)) UnionDecl *aggregateDecl ) {}
     139        void GlobalFixer::visit( __attribute__((unused)) EnumDecl *aggregateDecl ) {}
     140        void GlobalFixer::visit( __attribute__((unused)) TraitDecl *aggregateDecl ) {}
     141        void GlobalFixer::visit( __attribute__((unused)) TypeDecl *typeDecl ) {}
    144142
    145143} // namespace InitTweak
  • src/InitTweak/FixInit.cc

    r5da9d6a r3d560060  
    4949#include "SynTree/Expression.h"        // for UniqueExpr, VariableExpr, Unty...
    5050#include "SynTree/Initializer.h"       // for ConstructorInit, SingleInit
    51 #include "SynTree/Label.h"             // for Label, operator<
     51#include "SynTree/Label.h"             // for Label, noLabels, operator<
    5252#include "SynTree/Mutator.h"           // for mutateAll, Mutator, maybeMutate
    5353#include "SynTree/Statement.h"         // for ExprStmt, CompoundStmt, Branch...
     
    544544                        // add all temporary declarations and their constructors
    545545                        for ( ObjectDecl * obj : tempDecls ) {
    546                                 stmtsToAddBefore.push_back( new DeclStmt( obj ) );
     546                                stmtsToAddBefore.push_back( new DeclStmt( noLabels, obj ) );
    547547                        } // for
    548548                        for ( ObjectDecl * obj : returnDecls ) {
    549                                 stmtsToAddBefore.push_back( new DeclStmt( obj ) );
     549                                stmtsToAddBefore.push_back( new DeclStmt( noLabels, obj ) );
    550550                        } // for
    551551
    552552                        // add destructors after current statement
    553553                        for ( Expression * dtor : dtors ) {
    554                                 stmtsToAddAfter.push_back( new ExprStmt( dtor ) );
     554                                stmtsToAddAfter.push_back( new ExprStmt( noLabels, dtor ) );
    555555                        } // for
    556556
     
    598598                        if ( ! result->isVoid() ) {
    599599                                for ( ObjectDecl * obj : stmtExpr->get_returnDecls() ) {
    600                                         stmtsToAddBefore.push_back( new DeclStmt( obj ) );
     600                                        stmtsToAddBefore.push_back( new DeclStmt( noLabels, obj ) );
    601601                                } // for
    602602                                // add destructors after current statement
    603603                                for ( Expression * dtor : stmtExpr->get_dtors() ) {
    604                                         stmtsToAddAfter.push_back( new ExprStmt( dtor ) );
     604                                        stmtsToAddAfter.push_back( new ExprStmt( noLabels, dtor ) );
    605605                                } // for
    606606                                // must have a non-empty body, otherwise it wouldn't have a result
    607607                                assert( ! stmts.empty() );
    608608                                assert( ! stmtExpr->get_returnDecls().empty() );
    609                                 stmts.push_back( new ExprStmt( new VariableExpr( stmtExpr->get_returnDecls().front() ) ) );
     609                                stmts.push_back( new ExprStmt( noLabels, new VariableExpr( stmtExpr->get_returnDecls().front() ) ) );
    610610                                stmtExpr->get_returnDecls().clear();
    611611                                stmtExpr->get_dtors().clear();
     
    685685
    686686                                                // generate body of if
    687                                                 CompoundStmt * initStmts = new CompoundStmt();
     687                                                CompoundStmt * initStmts = new CompoundStmt( noLabels );
    688688                                                std::list< Statement * > & body = initStmts->get_kids();
    689689                                                body.push_back( ctor );
    690                                                 body.push_back( new ExprStmt( setTrue ) );
     690                                                body.push_back( new ExprStmt( noLabels, setTrue ) );
    691691
    692692                                                // put it all together
    693                                                 IfStmt * ifStmt = new IfStmt( new VariableExpr( isUninitializedVar ), initStmts, 0 );
    694                                                 stmtsToAddAfter.push_back( new DeclStmt( isUninitializedVar ) );
     693                                                IfStmt * ifStmt = new IfStmt( noLabels, new VariableExpr( isUninitializedVar ), initStmts, 0 );
     694                                                stmtsToAddAfter.push_back( new DeclStmt( noLabels, isUninitializedVar ) );
    695695                                                stmtsToAddAfter.push_back( ifStmt );
    696696
     
    707707
    708708                                                        // void __objName_dtor_atexitN(...) {...}
    709                                                         FunctionDecl * dtorCaller = new FunctionDecl( objDecl->get_mangleName() + dtorCallerNamer.newName(), Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() );
     709                                                        FunctionDecl * dtorCaller = new FunctionDecl( objDecl->get_mangleName() + dtorCallerNamer.newName(), Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ) );
    710710                                                        dtorCaller->fixUniqueId();
    711711                                                        dtorCaller->get_statements()->push_back( dtorStmt );
     
    715715                                                        callAtexit->get_args().push_back( new VariableExpr( dtorCaller ) );
    716716
    717                                                         body.push_back( new ExprStmt( callAtexit ) );
     717                                                        body.push_back( new ExprStmt( noLabels, callAtexit ) );
    718718
    719719                                                        // hoist variable and dtor caller decls to list of decls that will be added into global scope
  • src/InitTweak/InitTweak.cc

    r5da9d6a r3d560060  
    55#include <memory>                  // for __shared_ptr
    66
    7 #include "Common/PassVisitor.h"
    87#include "Common/SemanticError.h"  // for SemanticError
    98#include "Common/UniqueName.h"     // for UniqueName
     
    2019#include "SynTree/Expression.h"    // for Expression, UntypedExpr, Applicati...
    2120#include "SynTree/Initializer.h"   // for Initializer, ListInit, Designation
    22 #include "SynTree/Label.h"         // for Label
     21#include "SynTree/Label.h"         // for Label, noLabels
    2322#include "SynTree/Statement.h"     // for CompoundStmt, ExprStmt, BranchStmt
    2423#include "SynTree/Type.h"          // for FunctionType, ArrayType, PointerType
     
    3029namespace InitTweak {
    3130        namespace {
    32                 struct HasDesignations : public WithShortCircuiting {
     31                class HasDesignations : public Visitor {
     32                public:
    3333                        bool hasDesignations = false;
    34 
    35                         void previsit( BaseSyntaxNode * ) {
    36                                 // short circuit if we already know there are designations
    37                                 if ( hasDesignations ) visit_children = false;
    38                         }
    39 
    40                         void previsit( Designation * des ) {
    41                                 // short circuit if we already know there are designations
    42                                 if ( hasDesignations ) visit_children = false;
    43                                 else if ( ! des->get_designators().empty() ) {
    44                                         hasDesignations = true;
    45                                         visit_children = false;
    46                                 }
     34                        virtual void visit( Designation * des ) {
     35                                if ( ! des->get_designators().empty() ) hasDesignations = true;
     36                                else Visitor::visit( des );
    4737                        }
    4838                };
    4939
    50                 struct InitDepthChecker : public WithGuards {
     40                class InitDepthChecker : public Visitor {
     41                public:
    5142                        bool depthOkay = true;
    5243                        Type * type;
     
    6051                                maxDepth++;
    6152                        }
    62                         void previsit( ListInit * ) {
     53                        virtual void visit( ListInit * listInit ) {
    6354                                curDepth++;
    64                                 GuardAction( [this]() { curDepth--; } );
    6555                                if ( curDepth > maxDepth ) depthOkay = false;
     56                                Visitor::visit( listInit );
     57                                curDepth--;
    6658                        }
    6759                };
    6860
    69                 struct InitFlattener : public WithShortCircuiting {
    70                         void previsit( SingleInit * singleInit ) {
    71                                 visit_children = false;
    72                                 argList.push_back( singleInit->value->clone() );
    73                         }
     61                class InitFlattener : public Visitor {
     62                        public:
     63                        virtual void visit( SingleInit * singleInit );
     64                        virtual void visit( ListInit * listInit );
    7465                        std::list< Expression * > argList;
    7566                };
    7667
     68                void InitFlattener::visit( SingleInit * singleInit ) {
     69                        argList.push_back( singleInit->get_value()->clone() );
     70                }
     71
     72                void InitFlattener::visit( ListInit * listInit ) {
     73                        // flatten nested list inits
     74                        std::list<Initializer*>::iterator it = listInit->begin();
     75                        for ( ; it != listInit->end(); ++it ) {
     76                                (*it)->accept( *this );
     77                        }
     78                }
    7779        }
    7880
    7981        std::list< Expression * > makeInitList( Initializer * init ) {
    80                 PassVisitor<InitFlattener> flattener;
     82                InitFlattener flattener;
    8183                maybeAccept( init, flattener );
    82                 return flattener.pass.argList;
     84                return flattener.argList;
    8385        }
    8486
    8587        bool isDesignated( Initializer * init ) {
    86                 PassVisitor<HasDesignations> finder;
     88                HasDesignations finder;
    8789                maybeAccept( init, finder );
    88                 return finder.pass.hasDesignations;
     90                return finder.hasDesignations;
    8991        }
    9092
    9193        bool checkInitDepth( ObjectDecl * objDecl ) {
    92                 PassVisitor<InitDepthChecker> checker( objDecl->type );
    93                 maybeAccept( objDecl->init, checker );
    94                 return checker.pass.depthOkay;
     94                InitDepthChecker checker( objDecl->get_type() );
     95                maybeAccept( objDecl->get_init(), checker );
     96                return checker.depthOkay;
    9597        }
    9698
     
    193195                        callExpr->get_args().splice( callExpr->get_args().end(), args );
    194196
    195                         *out++ = new IfStmt( cond, new ExprStmt( callExpr ), nullptr );
     197                        *out++ = new IfStmt( noLabels, cond, new ExprStmt( noLabels, callExpr ), nullptr );
    196198
    197199                        UntypedExpr * increment = new UntypedExpr( new NameExpr( "++?" ) );
    198200                        increment->get_args().push_back( index->clone() );
    199                         *out++ = new ExprStmt( increment );
     201                        *out++ = new ExprStmt( noLabels, increment );
    200202                }
    201203
     
    242244                                        std::list< Statement * > stmts;
    243245                                        build( callExpr, idx, idxEnd, init, back_inserter( stmts ) );
    244                                         stmts.push_back( new BranchStmt( switchLabel, BranchStmt::Break ) );
    245                                         CaseStmt * caseStmt = new CaseStmt( condition, stmts );
     246                                        stmts.push_back( new BranchStmt( noLabels, switchLabel, BranchStmt::Break ) );
     247                                        CaseStmt * caseStmt = new CaseStmt( noLabels, condition, stmts );
    246248                                        branches.push_back( caseStmt );
    247249                                }
    248                                 *out++ = new SwitchStmt( index->clone(), branches );
    249                                 *out++ = new NullStmt( { switchLabel } );
     250                                *out++ = new SwitchStmt( noLabels, index->clone(), branches );
     251                                *out++ = new NullStmt( std::list<Label>{ switchLabel } );
    250252                        }
    251253                }
     
    260262        Statement * InitImpl::buildListInit( UntypedExpr * dst, std::list< Expression * > & indices ) {
    261263                if ( ! init ) return nullptr;
    262                 CompoundStmt * block = new CompoundStmt();
     264                CompoundStmt * block = new CompoundStmt( noLabels );
    263265                build( dst, indices.begin(), indices.end(), init, back_inserter( block->get_kids() ) );
    264266                if ( block->get_kids().empty() ) {
     
    307309        }
    308310
    309         struct CallFinder {
     311        class CallFinder : public Visitor {
     312        public:
     313                typedef Visitor Parent;
    310314                CallFinder( const std::list< std::string > & names ) : names( names ) {}
    311315
    312                 void postvisit( ApplicationExpr * appExpr ) {
     316                virtual void visit( ApplicationExpr * appExpr ) {
    313317                        handleCallExpr( appExpr );
    314318                }
    315319
    316                 void postvisit( UntypedExpr * untypedExpr ) {
     320                virtual void visit( UntypedExpr * untypedExpr ) {
    317321                        handleCallExpr( untypedExpr );
    318322                }
     
    324328                template< typename CallExpr >
    325329                void handleCallExpr( CallExpr * expr ) {
     330                        Parent::visit( expr );
    326331                        std::string fname = getFunctionName( expr );
    327332                        if ( std::find( names.begin(), names.end(), fname ) != names.end() ) {
     
    332337
    333338        void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches ) {
    334                 static PassVisitor<CallFinder> finder( std::list< std::string >{ "?{}", "^?{}" } );
    335                 finder.pass.matches = &matches;
     339                static CallFinder finder( std::list< std::string >{ "?{}", "^?{}" } );
     340                finder.matches = &matches;
    336341                maybeAccept( stmt, finder );
    337342        }
     
    539544        }
    540545
    541         struct ConstExprChecker : public WithShortCircuiting {
    542                 // most expressions are not const expr
    543                 void previsit( Expression * ) { isConstExpr = false; visit_children = false; }
    544 
    545                 void previsit( AddressExpr *addressExpr ) {
    546                         visit_children = false;
    547 
     546        class ConstExprChecker : public Visitor {
     547        public:
     548                ConstExprChecker() : isConstExpr( true ) {}
     549
     550                using Visitor::visit;
     551
     552                virtual void visit( ApplicationExpr * ) { isConstExpr = false; }
     553                virtual void visit( UntypedExpr * ) { isConstExpr = false; }
     554                virtual void visit( NameExpr * ) { isConstExpr = false; }
     555                // virtual void visit( CastExpr *castExpr ) { isConstExpr = false; }
     556                virtual void visit( AddressExpr *addressExpr ) {
    548557                        // address of a variable or member expression is constexpr
    549558                        Expression * arg = addressExpr->get_arg();
    550559                        if ( ! dynamic_cast< NameExpr * >( arg) && ! dynamic_cast< VariableExpr * >( arg ) && ! dynamic_cast< MemberExpr * >( arg ) && ! dynamic_cast< UntypedMemberExpr * >( arg ) ) isConstExpr = false;
    551560                }
    552 
    553                 // these expressions may be const expr, depending on their children
    554                 void previsit( SizeofExpr * ) {}
    555                 void previsit( AlignofExpr * ) {}
    556                 void previsit( UntypedOffsetofExpr * ) {}
    557                 void previsit( OffsetofExpr * ) {}
    558                 void previsit( OffsetPackExpr * ) {}
    559                 void previsit( AttrExpr * ) {}
    560                 void previsit( CommaExpr * ) {}
    561                 void previsit( LogicalExpr * ) {}
    562                 void previsit( ConditionalExpr * ) {}
    563                 void previsit( CastExpr * ) {}
    564                 void previsit( ConstantExpr * ) {}
    565 
    566                 bool isConstExpr = true;
     561                virtual void visit( UntypedMemberExpr * ) { isConstExpr = false; }
     562                virtual void visit( MemberExpr * ) { isConstExpr = false; }
     563                virtual void visit( VariableExpr * ) { isConstExpr = false; }
     564                // these might be okay?
     565                // virtual void visit( SizeofExpr *sizeofExpr );
     566                // virtual void visit( AlignofExpr *alignofExpr );
     567                // virtual void visit( UntypedOffsetofExpr *offsetofExpr );
     568                // virtual void visit( OffsetofExpr *offsetofExpr );
     569                // virtual void visit( OffsetPackExpr *offsetPackExpr );
     570                // virtual void visit( AttrExpr *attrExpr );
     571                // virtual void visit( CommaExpr *commaExpr );
     572                // virtual void visit( LogicalExpr *logicalExpr );
     573                // virtual void visit( ConditionalExpr *conditionalExpr );
     574                virtual void visit( TypeExpr * ) { isConstExpr = false; }
     575                virtual void visit( AsmExpr * ) { isConstExpr = false; }
     576                virtual void visit( UntypedValofExpr * ) { isConstExpr = false; }
     577                virtual void visit( CompoundLiteralExpr * ) { isConstExpr = false; }
     578                virtual void visit( UntypedTupleExpr * ) { isConstExpr = false; }
     579                virtual void visit( TupleExpr * ) { isConstExpr = false; }
     580                virtual void visit( TupleAssignExpr * ) { isConstExpr = false; }
     581
     582                bool isConstExpr;
    567583        };
    568584
    569585        bool isConstExpr( Expression * expr ) {
    570586                if ( expr ) {
    571                         PassVisitor<ConstExprChecker> checker;
     587                        ConstExprChecker checker;
    572588                        expr->accept( checker );
    573                         return checker.pass.isConstExpr;
     589                        return checker.isConstExpr;
    574590                }
    575591                return true;
     
    578594        bool isConstExpr( Initializer * init ) {
    579595                if ( init ) {
    580                         PassVisitor<ConstExprChecker> checker;
     596                        ConstExprChecker checker;
    581597                        init->accept( checker );
    582                         return checker.pass.isConstExpr;
     598                        return checker.isConstExpr;
    583599                } // if
    584600                // for all intents and purposes, no initializer means const expr
  • src/MakeLibCfa.cc

    r5da9d6a r3d560060  
    116116                        } // for
    117117
    118                         funcDecl->set_statements( new CompoundStmt() );
     118                        funcDecl->set_statements( new CompoundStmt( std::list< Label >() ) );
    119119                        newDecls.push_back( funcDecl );
    120120
     
    130130                          case CodeGen::OT_INFIXASSIGN:
    131131                                        // return the recursive call
    132                                         stmt = new ReturnStmt( newExpr );
     132                                        stmt = new ReturnStmt( noLabels, newExpr );
    133133                                        break;
    134134                          case CodeGen::OT_CTOR:
    135135                          case CodeGen::OT_DTOR:
    136136                                        // execute the recursive call
    137                                         stmt = new ExprStmt( newExpr );
     137                                        stmt = new ExprStmt( noLabels, newExpr );
    138138                                        break;
    139139                          case CodeGen::OT_CONSTANT:
  • src/Makefile.in

    r5da9d6a r3d560060  
    215215        SymTab/driver_cfa_cpp-Validate.$(OBJEXT) \
    216216        SymTab/driver_cfa_cpp-FixFunction.$(OBJEXT) \
     217        SymTab/driver_cfa_cpp-ImplementationType.$(OBJEXT) \
     218        SymTab/driver_cfa_cpp-TypeEquality.$(OBJEXT) \
    217219        SymTab/driver_cfa_cpp-Autogen.$(OBJEXT) \
    218220        SynTree/driver_cfa_cpp-Type.$(OBJEXT) \
     
    512514        ResolvExpr/CurrentObject.cc ResolvExpr/ExplodedActual.cc \
    513515        SymTab/Indexer.cc SymTab/Mangler.cc SymTab/Validate.cc \
    514         SymTab/FixFunction.cc SymTab/Autogen.cc SynTree/Type.cc \
     516        SymTab/FixFunction.cc SymTab/ImplementationType.cc \
     517        SymTab/TypeEquality.cc SymTab/Autogen.cc SynTree/Type.cc \
    515518        SynTree/VoidType.cc SynTree/BasicType.cc \
    516519        SynTree/PointerType.cc SynTree/ArrayType.cc \
     
    841844SymTab/driver_cfa_cpp-FixFunction.$(OBJEXT): SymTab/$(am__dirstamp) \
    842845        SymTab/$(DEPDIR)/$(am__dirstamp)
     846SymTab/driver_cfa_cpp-ImplementationType.$(OBJEXT):  \
     847        SymTab/$(am__dirstamp) SymTab/$(DEPDIR)/$(am__dirstamp)
     848SymTab/driver_cfa_cpp-TypeEquality.$(OBJEXT): SymTab/$(am__dirstamp) \
     849        SymTab/$(DEPDIR)/$(am__dirstamp)
    843850SymTab/driver_cfa_cpp-Autogen.$(OBJEXT): SymTab/$(am__dirstamp) \
    844851        SymTab/$(DEPDIR)/$(am__dirstamp)
     
    10331040@AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-Autogen.Po@am__quote@
    10341041@AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-FixFunction.Po@am__quote@
     1042@AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-ImplementationType.Po@am__quote@
    10351043@AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-Indexer.Po@am__quote@
    10361044@AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-Mangler.Po@am__quote@
     1045@AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-TypeEquality.Po@am__quote@
    10371046@AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-Validate.Po@am__quote@
    10381047@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-AddressExpr.Po@am__quote@
     
    20302039@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    20312040@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SymTab/driver_cfa_cpp-FixFunction.obj `if test -f 'SymTab/FixFunction.cc'; then $(CYGPATH_W) 'SymTab/FixFunction.cc'; else $(CYGPATH_W) '$(srcdir)/SymTab/FixFunction.cc'; fi`
     2041
     2042SymTab/driver_cfa_cpp-ImplementationType.o: SymTab/ImplementationType.cc
     2043@am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SymTab/driver_cfa_cpp-ImplementationType.o -MD -MP -MF SymTab/$(DEPDIR)/driver_cfa_cpp-ImplementationType.Tpo -c -o SymTab/driver_cfa_cpp-ImplementationType.o `test -f 'SymTab/ImplementationType.cc' || echo '$(srcdir)/'`SymTab/ImplementationType.cc
     2044@am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) SymTab/$(DEPDIR)/driver_cfa_cpp-ImplementationType.Tpo SymTab/$(DEPDIR)/driver_cfa_cpp-ImplementationType.Po
     2045@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='SymTab/ImplementationType.cc' object='SymTab/driver_cfa_cpp-ImplementationType.o' libtool=no @AMDEPBACKSLASH@
     2046@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     2047@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SymTab/driver_cfa_cpp-ImplementationType.o `test -f 'SymTab/ImplementationType.cc' || echo '$(srcdir)/'`SymTab/ImplementationType.cc
     2048
     2049SymTab/driver_cfa_cpp-ImplementationType.obj: SymTab/ImplementationType.cc
     2050@am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SymTab/driver_cfa_cpp-ImplementationType.obj -MD -MP -MF SymTab/$(DEPDIR)/driver_cfa_cpp-ImplementationType.Tpo -c -o SymTab/driver_cfa_cpp-ImplementationType.obj `if test -f 'SymTab/ImplementationType.cc'; then $(CYGPATH_W) 'SymTab/ImplementationType.cc'; else $(CYGPATH_W) '$(srcdir)/SymTab/ImplementationType.cc'; fi`
     2051@am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) SymTab/$(DEPDIR)/driver_cfa_cpp-ImplementationType.Tpo SymTab/$(DEPDIR)/driver_cfa_cpp-ImplementationType.Po
     2052@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='SymTab/ImplementationType.cc' object='SymTab/driver_cfa_cpp-ImplementationType.obj' libtool=no @AMDEPBACKSLASH@
     2053@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     2054@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SymTab/driver_cfa_cpp-ImplementationType.obj `if test -f 'SymTab/ImplementationType.cc'; then $(CYGPATH_W) 'SymTab/ImplementationType.cc'; else $(CYGPATH_W) '$(srcdir)/SymTab/ImplementationType.cc'; fi`
     2055
     2056SymTab/driver_cfa_cpp-TypeEquality.o: SymTab/TypeEquality.cc
     2057@am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SymTab/driver_cfa_cpp-TypeEquality.o -MD -MP -MF SymTab/$(DEPDIR)/driver_cfa_cpp-TypeEquality.Tpo -c -o SymTab/driver_cfa_cpp-TypeEquality.o `test -f 'SymTab/TypeEquality.cc' || echo '$(srcdir)/'`SymTab/TypeEquality.cc
     2058@am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) SymTab/$(DEPDIR)/driver_cfa_cpp-TypeEquality.Tpo SymTab/$(DEPDIR)/driver_cfa_cpp-TypeEquality.Po
     2059@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='SymTab/TypeEquality.cc' object='SymTab/driver_cfa_cpp-TypeEquality.o' libtool=no @AMDEPBACKSLASH@
     2060@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     2061@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SymTab/driver_cfa_cpp-TypeEquality.o `test -f 'SymTab/TypeEquality.cc' || echo '$(srcdir)/'`SymTab/TypeEquality.cc
     2062
     2063SymTab/driver_cfa_cpp-TypeEquality.obj: SymTab/TypeEquality.cc
     2064@am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SymTab/driver_cfa_cpp-TypeEquality.obj -MD -MP -MF SymTab/$(DEPDIR)/driver_cfa_cpp-TypeEquality.Tpo -c -o SymTab/driver_cfa_cpp-TypeEquality.obj `if test -f 'SymTab/TypeEquality.cc'; then $(CYGPATH_W) 'SymTab/TypeEquality.cc'; else $(CYGPATH_W) '$(srcdir)/SymTab/TypeEquality.cc'; fi`
     2065@am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) SymTab/$(DEPDIR)/driver_cfa_cpp-TypeEquality.Tpo SymTab/$(DEPDIR)/driver_cfa_cpp-TypeEquality.Po
     2066@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='SymTab/TypeEquality.cc' object='SymTab/driver_cfa_cpp-TypeEquality.obj' libtool=no @AMDEPBACKSLASH@
     2067@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     2068@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SymTab/driver_cfa_cpp-TypeEquality.obj `if test -f 'SymTab/TypeEquality.cc'; then $(CYGPATH_W) 'SymTab/TypeEquality.cc'; else $(CYGPATH_W) '$(srcdir)/SymTab/TypeEquality.cc'; fi`
    20322069
    20332070SymTab/driver_cfa_cpp-Autogen.o: SymTab/Autogen.cc
  • src/Parser/StatementNode.cc

    r5da9d6a r3d560060  
    3737        DeclarationNode *agg = decl->extractAggregate();
    3838        if ( agg ) {
    39                 StatementNode *nextStmt = new StatementNode( new DeclStmt( maybeBuild< Declaration >( decl ) ) );
     39                StatementNode *nextStmt = new StatementNode( new DeclStmt( noLabels, maybeBuild< Declaration >( decl ) ) );
    4040                set_next( nextStmt );
    4141                if ( decl->get_next() ) {
     
    5050                agg = decl;
    5151        } // if
    52         stmt.reset( new DeclStmt( maybeMoveBuild< Declaration >(agg) ) );
     52        stmt.reset( new DeclStmt( noLabels, maybeMoveBuild< Declaration >(agg) ) );
    5353} // StatementNode::StatementNode
    5454
     
    7575
    7676        if ( e )
    77                 return new ExprStmt( e );
     77                return new ExprStmt( noLabels, e );
    7878        else
    79                 return new NullStmt();
     79                return new NullStmt( noLabels );
    8080}
    8181
     
    113113        }
    114114        delete ctl;
    115         return new IfStmt( cond, thenb, elseb, init );
     115        return new IfStmt( noLabels, cond, thenb, elseb, init );
    116116}
    117117
     
    120120        buildMoveList< Statement, StatementNode >( stmt, branches );
    121121        // branches.size() == 0 for switch (...) {}, i.e., no declaration or statements
    122         return new SwitchStmt( maybeMoveBuild< Expression >(ctl), branches );
     122        return new SwitchStmt( noLabels, maybeMoveBuild< Expression >(ctl), branches );
    123123}
    124124Statement *build_case( ExpressionNode *ctl ) {
    125125        std::list< Statement * > branches;
    126         return new CaseStmt( maybeMoveBuild< Expression >(ctl), branches );
     126        return new CaseStmt( noLabels, maybeMoveBuild< Expression >(ctl), branches );
    127127}
    128128Statement *build_default() {
    129129        std::list< Statement * > branches;
    130         return new CaseStmt( nullptr, branches, true );
     130        return new CaseStmt( noLabels, nullptr, branches, true );
    131131}
    132132
     
    135135        buildMoveList< Statement, StatementNode >( stmt, branches );
    136136        assert( branches.size() == 1 );
    137         return new WhileStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), kind );
     137        return new WhileStmt( noLabels, notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), kind );
    138138}
    139139
     
    157157
    158158        delete forctl;
    159         return new ForStmt( init, cond, incr, branches.front() );
     159        return new ForStmt( noLabels, init, cond, incr, branches.front() );
    160160}
    161161
    162162Statement *build_branch( BranchStmt::Type kind ) {
    163         Statement * ret = new BranchStmt( "", kind );
     163        Statement * ret = new BranchStmt( noLabels, "", kind );
    164164        return ret;
    165165}
    166166Statement *build_branch( std::string *identifier, BranchStmt::Type kind ) {
    167         Statement * ret = new BranchStmt( *identifier, kind );
     167        Statement * ret = new BranchStmt( noLabels, *identifier, kind );
    168168        delete identifier;                                                                      // allocated by lexer
    169169        return ret;
    170170}
    171171Statement *build_computedgoto( ExpressionNode *ctl ) {
    172         return new BranchStmt( maybeMoveBuild< Expression >(ctl), BranchStmt::Goto );
     172        return new BranchStmt( noLabels, maybeMoveBuild< Expression >(ctl), BranchStmt::Goto );
    173173}
    174174
     
    176176        std::list< Expression * > exps;
    177177        buildMoveList( ctl, exps );
    178         return new ReturnStmt( exps.size() > 0 ? exps.back() : nullptr );
     178        return new ReturnStmt( noLabels, exps.size() > 0 ? exps.back() : nullptr );
    179179}
    180180
     
    183183        buildMoveList( ctl, exps );
    184184        assertf( exps.size() < 2, "This means we are leaking memory");
    185         return new ThrowStmt( ThrowStmt::Terminate, !exps.empty() ? exps.back() : nullptr );
     185        return new ThrowStmt( noLabels, ThrowStmt::Terminate, !exps.empty() ? exps.back() : nullptr );
    186186}
    187187
     
    190190        buildMoveList( ctl, exps );
    191191        assertf( exps.size() < 2, "This means we are leaking memory");
    192         return new ThrowStmt( ThrowStmt::Resume, !exps.empty() ? exps.back() : nullptr );
     192        return new ThrowStmt( noLabels, ThrowStmt::Resume, !exps.empty() ? exps.back() : nullptr );
    193193}
    194194
     
    204204        CompoundStmt *tryBlock = strict_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_stmt));
    205205        FinallyStmt *finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) );
    206         return new TryStmt( tryBlock, branches, finallyBlock );
     206        return new TryStmt( noLabels, tryBlock, branches, finallyBlock );
    207207}
    208208Statement *build_catch( CatchStmt::Kind kind, DeclarationNode *decl, ExpressionNode *cond, StatementNode *body ) {
     
    210210        buildMoveList< Statement, StatementNode >( body, branches );
    211211        assert( branches.size() == 1 );
    212         return new CatchStmt( kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), branches.front() );
     212        return new CatchStmt( noLabels, kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), branches.front() );
    213213}
    214214Statement *build_finally( StatementNode *stmt ) {
     
    216216        buildMoveList< Statement, StatementNode >( stmt, branches );
    217217        assert( branches.size() == 1 );
    218         return new FinallyStmt( dynamic_cast< CompoundStmt * >( branches.front() ) );
     218        return new FinallyStmt( noLabels, dynamic_cast< CompoundStmt * >( branches.front() ) );
    219219}
    220220
     
    289289
    290290Statement *build_compound( StatementNode *first ) {
    291         CompoundStmt *cs = new CompoundStmt();
     291        CompoundStmt *cs = new CompoundStmt( noLabels );
    292292        buildMoveList( first, cs->get_kids() );
    293293        return cs;
     
    301301        buildMoveList( input, in );
    302302        buildMoveList( clobber, clob );
    303         return new AsmStmt( voltile, instruction, out, in, clob, gotolabels ? gotolabels->labels : noLabels );
     303        return new AsmStmt( noLabels, voltile, instruction, out, in, clob, gotolabels ? gotolabels->labels : noLabels );
    304304}
    305305
  • src/SymTab/AddVisit.h

    r5da9d6a r3d560060  
    2424                        // add any new declarations after the previous statement
    2525                        for ( std::list< Declaration* >::iterator decl = visitor.declsToAddAfter.begin(); decl != visitor.declsToAddAfter.end(); ++decl ) {
    26                                 DeclStmt *declStmt = new DeclStmt( *decl );
     26                                DeclStmt *declStmt = new DeclStmt( noLabels, *decl );
    2727                                stmts.insert( stmt, declStmt );
    2828                        }
     
    3636                        // add any new declarations before the statement
    3737                        for ( std::list< Declaration* >::iterator decl = visitor.declsToAdd.begin(); decl != visitor.declsToAdd.end(); ++decl ) {
    38                                 DeclStmt *declStmt = new DeclStmt( *decl );
     38                                DeclStmt *declStmt = new DeclStmt( noLabels, *decl );
    3939                                stmts.insert( stmt, declStmt );
    4040                        }
  • src/SymTab/Autogen.cc

    r5da9d6a r3d560060  
    264264                Type::StorageClasses scs = functionNesting > 0 ? Type::StorageClasses() : Type::StorageClasses( Type::Static );
    265265                LinkageSpec::Spec spec = isIntrinsic ? LinkageSpec::Intrinsic : LinkageSpec::AutoGen;
    266                 FunctionDecl * decl = new FunctionDecl( fname, scs, spec, ftype, new CompoundStmt(),
     266                FunctionDecl * decl = new FunctionDecl( fname, scs, spec, ftype, new CompoundStmt( noLabels ),
    267267                                                                                                std::list< Attribute * >(), Type::FuncSpecifiers( Type::Inline ) );
    268268                decl->fixUniqueId();
     
    299299                                assert( assignType->returnVals.size() == 1 );
    300300                                ObjectDecl * dstParam = strict_dynamic_cast< ObjectDecl * >( assignType->parameters.front() );
    301                                 dcl->statements->push_back( new ReturnStmt( new VariableExpr( dstParam ) ) );
     301                                dcl->statements->push_back( new ReturnStmt( noLabels, new VariableExpr( dstParam ) ) );
    302302                        }
    303303                        resolve( dcl );
     
    468468                copy->args.push_back( new AddressExpr( new VariableExpr( srcParam ) ) );
    469469                copy->args.push_back( new SizeofExpr( srcParam->get_type()->clone() ) );
    470                 *out++ = new ExprStmt( copy );
     470                *out++ = new ExprStmt( noLabels, copy );
    471471        }
    472472
     
    544544                        callExpr->get_args().push_back( new VariableExpr( dstParam ) );
    545545                        callExpr->get_args().push_back( new VariableExpr( srcParam ) );
    546                         funcDecl->statements->push_back( new ExprStmt( callExpr ) );
     546                        funcDecl->statements->push_back( new ExprStmt( noLabels, callExpr ) );
    547547                } else {
    548548                        // default ctor/dtor body is empty - add unused attribute to parameter to silence warnings
     
    569569                expr->args.push_back( new CastExpr( new VariableExpr( dst ), new ReferenceType( Type::Qualifiers(), typeDecl->base->clone() ) ) );
    570570                if ( src ) expr->args.push_back( new CastExpr( new VariableExpr( src ), typeDecl->base->clone() ) );
    571                 dcl->statements->kids.push_back( new ExprStmt( expr ) );
     571                dcl->statements->kids.push_back( new ExprStmt( noLabels, expr ) );
    572572        };
    573573
     
    664664                        untyped->get_args().push_back( new VariableExpr( ftype->get_parameters().back() ) );
    665665                }
    666                 function->get_statements()->get_kids().push_back( new ExprStmt( untyped ) );
    667                 function->get_statements()->get_kids().push_back( new ReturnStmt( UntypedExpr::createDeref( new VariableExpr( ftype->get_parameters().front() ) ) ) );
     666                function->get_statements()->get_kids().push_back( new ExprStmt( noLabels, untyped ) );
     667                function->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, UntypedExpr::createDeref( new VariableExpr( ftype->get_parameters().front() ) ) ) );
    668668        }
    669669
  • src/SymTab/Autogen.h

    r5da9d6a r3d560060  
    104104                fExpr->args.splice( fExpr->args.end(), args );
    105105
    106                 *out++ = new ExprStmt( fExpr );
     106                *out++ = new ExprStmt( noLabels, fExpr );
    107107
    108108                srcParam.clearArrayIndices();
     
    162162
    163163                // for stmt's body, eventually containing call
    164                 CompoundStmt * body = new CompoundStmt();
     164                CompoundStmt * body = new CompoundStmt( noLabels );
    165165                Statement * listInit = genCall( srcParam, dstParam, fname, back_inserter( body->kids ), array->base, addCast, forward );
    166166
    167167                // block containing for stmt and index variable
    168168                std::list<Statement *> initList;
    169                 CompoundStmt * block = new CompoundStmt();
    170                 block->push_back( new DeclStmt( index ) );
     169                CompoundStmt * block = new CompoundStmt( noLabels );
     170                block->push_back( new DeclStmt( noLabels, index ) );
    171171                if ( listInit ) block->get_kids().push_back( listInit );
    172                 block->push_back( new ForStmt( initList, cond, inc, body ) );
     172                block->push_back( new ForStmt( noLabels, initList, cond, inc, body ) );
    173173
    174174                *out++ = block;
  • src/SymTab/Validate.cc

    r5da9d6a r3d560060  
    8181
    8282namespace SymTab {
    83         struct HoistStruct final : public WithDeclsToAdd, public WithGuards {
     83        class HoistStruct final : public Visitor {
     84                template< typename Visitor >
     85                friend void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor );
     86            template< typename Visitor >
     87            friend void addVisitStatementList( std::list< Statement* > &stmts, Visitor &visitor );
     88          public:
    8489                /// Flattens nested struct types
    8590                static void hoistStruct( std::list< Declaration * > &translationUnit );
    8691
    87                 void previsit( EnumInstType * enumInstType );
    88                 void previsit( StructInstType * structInstType );
    89                 void previsit( UnionInstType * unionInstType );
    90                 void previsit( StructDecl * aggregateDecl );
    91                 void previsit( UnionDecl * aggregateDecl );
    92 
     92                std::list< Declaration * > &get_declsToAdd() { return declsToAdd; }
     93
     94                virtual void visit( EnumInstType *enumInstType );
     95                virtual void visit( StructInstType *structInstType );
     96                virtual void visit( UnionInstType *unionInstType );
     97                virtual void visit( StructDecl *aggregateDecl );
     98                virtual void visit( UnionDecl *aggregateDecl );
     99
     100                virtual void visit( CompoundStmt *compoundStmt );
     101                virtual void visit( SwitchStmt *switchStmt );
    93102          private:
     103                HoistStruct();
     104
    94105                template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl );
    95106
    96                 bool inStruct = false;
     107                std::list< Declaration * > declsToAdd, declsToAddAfter;
     108                bool inStruct;
    97109        };
    98110
     
    293305
    294306        void HoistStruct::hoistStruct( std::list< Declaration * > &translationUnit ) {
    295                 PassVisitor<HoistStruct> hoister;
    296                 acceptAll( translationUnit, hoister );
     307                HoistStruct hoister;
     308                acceptAndAdd( translationUnit, hoister );
     309        }
     310
     311        HoistStruct::HoistStruct() : inStruct( false ) {
    297312        }
    298313
     
    305320                if ( inStruct ) {
    306321                        // Add elements in stack order corresponding to nesting structure.
    307                         declsToAddBefore.push_front( aggregateDecl );
     322                        declsToAdd.push_front( aggregateDecl );
     323                        Visitor::visit( aggregateDecl );
    308324                } else {
    309                         GuardValue( inStruct );
    310325                        inStruct = true;
     326                        Visitor::visit( aggregateDecl );
     327                        inStruct = false;
    311328                } // if
    312329                // Always remove the hoisted aggregate from the inner structure.
    313                 GuardAction( [this, aggregateDecl]() { filter( aggregateDecl->members, isStructOrUnion, false ); } );
    314         }
    315 
    316         void HoistStruct::previsit( EnumInstType * inst ) {
    317                 if ( inst->baseEnum ) {
    318                         declsToAddBefore.push_front( inst->baseEnum );
    319                 }
    320         }
    321 
    322         void HoistStruct::previsit( StructInstType * inst ) {
    323                 if ( inst->baseStruct ) {
    324                         declsToAddBefore.push_front( inst->baseStruct );
    325                 }
    326         }
    327 
    328         void HoistStruct::previsit( UnionInstType * inst ) {
    329                 if ( inst->baseUnion ) {
    330                         declsToAddBefore.push_front( inst->baseUnion );
    331                 }
    332         }
    333 
    334         void HoistStruct::previsit( StructDecl * aggregateDecl ) {
     330                filter( aggregateDecl->get_members(), isStructOrUnion, false );
     331        }
     332
     333        void HoistStruct::visit( EnumInstType *structInstType ) {
     334                if ( structInstType->get_baseEnum() ) {
     335                        declsToAdd.push_front( structInstType->get_baseEnum() );
     336                }
     337        }
     338
     339        void HoistStruct::visit( StructInstType *structInstType ) {
     340                if ( structInstType->get_baseStruct() ) {
     341                        declsToAdd.push_front( structInstType->get_baseStruct() );
     342                }
     343        }
     344
     345        void HoistStruct::visit( UnionInstType *structInstType ) {
     346                if ( structInstType->get_baseUnion() ) {
     347                        declsToAdd.push_front( structInstType->get_baseUnion() );
     348                }
     349        }
     350
     351        void HoistStruct::visit( StructDecl *aggregateDecl ) {
    335352                handleAggregate( aggregateDecl );
    336353        }
    337354
    338         void HoistStruct::previsit( UnionDecl * aggregateDecl ) {
     355        void HoistStruct::visit( UnionDecl *aggregateDecl ) {
    339356                handleAggregate( aggregateDecl );
     357        }
     358
     359        void HoistStruct::visit( CompoundStmt *compoundStmt ) {
     360                addVisit( compoundStmt, *this );
     361        }
     362
     363        void HoistStruct::visit( SwitchStmt *switchStmt ) {
     364                addVisit( switchStmt, *this );
    340365        }
    341366
  • src/SymTab/module.mk

    r5da9d6a r3d560060  
    1919       SymTab/Validate.cc \
    2020       SymTab/FixFunction.cc \
     21       SymTab/ImplementationType.cc \
     22       SymTab/TypeEquality.cc \
    2123       SymTab/Autogen.cc
  • src/SynTree/CompoundStmt.cc

    r5da9d6a r3d560060  
    2828using std::endl;
    2929
    30 CompoundStmt::CompoundStmt() : Statement() {
     30CompoundStmt::CompoundStmt( std::list<Label> labels ) : Statement( labels ) {
    3131}
    3232
    33 CompoundStmt::CompoundStmt( std::list<Statement *> stmts ) : Statement(), kids( stmts ) {
     33CompoundStmt::CompoundStmt( std::list<Statement *> stmts ) : Statement( noLabels ), kids( stmts ) {
    3434}
    3535
  • src/SynTree/DeclStmt.cc

    r5da9d6a r3d560060  
    2323#include "SynTree/Label.h"   // for Label
    2424
    25 DeclStmt::DeclStmt( Declaration *decl ) : Statement(), decl( decl ) {
     25DeclStmt::DeclStmt( std::list<Label> labels, Declaration *decl ) : Statement( labels ), decl( decl ) {
    2626}
    2727
  • src/SynTree/Statement.cc

    r5da9d6a r3d560060  
    3232using std::endl;
    3333
    34 Statement::Statement( const std::list<Label> & labels ) : labels( labels ) {}
     34Statement::Statement( std::list<Label> labels ) : labels( labels ) {}
    3535
    3636void Statement::print( std::ostream & os, Indenter ) const {
     
    4646Statement::~Statement() {}
    4747
    48 ExprStmt::ExprStmt( Expression *expr ) : Statement(), expr( expr ) {}
     48ExprStmt::ExprStmt( std::list<Label> labels, Expression *expr ) : Statement( labels ), expr( expr ) {}
    4949
    5050ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
     
    6060
    6161
    62 AsmStmt::AsmStmt( bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement(), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {}
     62AsmStmt::AsmStmt( std::list<Label> labels, bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement( labels ), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {}
    6363
    6464AsmStmt::AsmStmt( const AsmStmt & other ) : Statement( other ), voltile( other.voltile ), instruction( maybeClone( other.instruction ) ), gotolabels( other.gotolabels ) {
     
    9696const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" };
    9797
    98 BranchStmt::BranchStmt( Label target, Type type ) throw ( SemanticError ) :
    99         Statement(), originalTarget( target ), target( target ), computedTarget( nullptr ), type( type ) {
     98BranchStmt::BranchStmt( std::list<Label> labels, Label target, Type type ) throw ( SemanticError ) :
     99        Statement( labels ), originalTarget( target ), target( target ), computedTarget( nullptr ), type( type ) {
    100100        //actually this is a syntactic error signaled by the parser
    101101        if ( type == BranchStmt::Goto && target.empty() ) {
     
    104104}
    105105
    106 BranchStmt::BranchStmt( Expression *computedTarget, Type type ) throw ( SemanticError ) :
    107         Statement(), computedTarget( computedTarget ), type( type ) {
     106BranchStmt::BranchStmt( std::list<Label> labels, Expression *computedTarget, Type type ) throw ( SemanticError ) :
     107        Statement( labels ), computedTarget( computedTarget ), type( type ) {
    108108        if ( type != BranchStmt::Goto || computedTarget == nullptr ) {
    109109                throw SemanticError("Computed target not valid in branch statement");
     
    118118}
    119119
    120 ReturnStmt::ReturnStmt( Expression *expr ) : Statement(), expr( expr ) {}
     120ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *expr ) : Statement( labels ), expr( expr ) {}
    121121
    122122ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
     
    135135}
    136136
    137 IfStmt::IfStmt( Expression *condition, Statement *thenPart, Statement *elsePart, std::list<Statement *> initialization ):
    138         Statement(), condition( condition ), thenPart( thenPart ), elsePart( elsePart ), initialization( initialization ) {}
     137IfStmt::IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart, std::list<Statement *> initialization ):
     138        Statement( labels ), condition( condition ), thenPart( thenPart ), elsePart( elsePart ), initialization( initialization ) {}
    139139
    140140IfStmt::IfStmt( const IfStmt & other ) :
     
    176176}
    177177
    178 SwitchStmt::SwitchStmt( Expression * condition, const std::list<Statement *> &statements ):
    179         Statement(), condition( condition ), statements( statements ) {
     178SwitchStmt::SwitchStmt( std::list<Label> labels, Expression * condition, const std::list<Statement *> &statements ):
     179        Statement( labels ), condition( condition ), statements( statements ) {
    180180}
    181181
     
    201201}
    202202
    203 CaseStmt::CaseStmt( Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) :
    204         Statement(), condition( condition ), stmts( statements ), _isDefault( deflt ) {
     203CaseStmt::CaseStmt( std::list<Label> labels, Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) :
     204        Statement( labels ), condition( condition ), stmts( statements ), _isDefault( deflt ) {
    205205        if ( isDefault() && condition != 0 ) throw SemanticError("default case with condition: ", condition);
    206206}
     
    216216}
    217217
    218 CaseStmt * CaseStmt::makeDefault( const std::list<Label> & labels, std::list<Statement *> stmts ) {
    219         CaseStmt * stmt = new CaseStmt( nullptr, stmts, true );
    220         stmt->labels = labels;
    221         return stmt;
     218CaseStmt * CaseStmt::makeDefault( std::list<Label> labels, std::list<Statement *> stmts ) {
     219        return new CaseStmt( labels, 0, stmts, true );
    222220}
    223221
     
    235233}
    236234
    237 WhileStmt::WhileStmt( Expression *condition, Statement *body, bool isDoWhile ):
    238         Statement(), condition( condition), body( body), isDoWhile( isDoWhile) {
     235WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition, Statement *body, bool isDoWhile ):
     236        Statement( labels ), condition( condition), body( body), isDoWhile( isDoWhile) {
    239237}
    240238
     
    257255}
    258256
    259 ForStmt::ForStmt( std::list<Statement *> initialization, Expression *condition, Expression *increment, Statement *body ):
    260         Statement(), initialization( initialization ), condition( condition ), increment( increment ), body( body ) {
     257ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization, Expression *condition, Expression *increment, Statement *body ):
     258        Statement( labels ), initialization( initialization ), condition( condition ), increment( increment ), body( body ) {
    261259}
    262260
     
    304302}
    305303
    306 ThrowStmt::ThrowStmt( Kind kind, Expression * expr, Expression * target ) :
    307                 Statement(), kind(kind), expr(expr), target(target)     {
     304ThrowStmt::ThrowStmt( std::list<Label> labels, Kind kind, Expression * expr, Expression * target ) :
     305                Statement( labels ), kind(kind), expr(expr), target(target)     {
    308306        assertf(Resume == kind || nullptr == target, "Non-local termination throw is not accepted." );
    309307}
     
    328326}
    329327
    330 TryStmt::TryStmt( CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock ) :
    331         Statement(), block( tryBlock ),  handlers( handlers ), finallyBlock( finallyBlock ) {
     328TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock ) :
     329        Statement( labels ), block( tryBlock ),  handlers( handlers ), finallyBlock( finallyBlock ) {
    332330}
    333331
     
    361359}
    362360
    363 CatchStmt::CatchStmt( Kind kind, Declaration *decl, Expression *cond, Statement *body ) :
    364         Statement(), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) {
     361CatchStmt::CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl, Expression *cond, Statement *body ) :
     362        Statement( labels ), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) {
    365363                assertf( decl, "Catch clause must have a declaration." );
    366364}
     
    393391
    394392
    395 FinallyStmt::FinallyStmt( CompoundStmt *block ) : Statement(), block( block ) {
     393FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *block ) : Statement( labels ), block( block ) {
     394        assert( labels.empty() ); // finally statement cannot be labeled
    396395}
    397396
     
    409408}
    410409
    411 WaitForStmt::WaitForStmt() : Statement() {
     410WaitForStmt::WaitForStmt( std::list<Label> labels ) : Statement( labels ) {
    412411        timeout.time      = nullptr;
    413412        timeout.statement = nullptr;
     
    456455}
    457456
    458 NullStmt::NullStmt( const std::list<Label> & labels ) : Statement( labels ) {
    459 }
     457NullStmt::NullStmt( std::list<Label> labels ) : Statement( labels ) {}
     458NullStmt::NullStmt() : Statement( std::list<Label>() ) {}
    460459
    461460void NullStmt::print( std::ostream &os, Indenter ) const {
     
    463462}
    464463
    465 ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( Statement * callStmt ) : Statement(), callStmt( callStmt ) {
     464ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( Statement * callStmt ) : Statement( std::list<Label>() ), callStmt( callStmt ) {
    466465        assert( callStmt );
    467466}
  • src/SynTree/Statement.h

    r5da9d6a r3d560060  
    3737        std::list<Label> labels;
    3838
    39         Statement( const std::list<Label> & labels = {} );
     39        Statement( std::list<Label> labels );
    4040        virtual ~Statement();
    4141
     
    5353        std::list<Statement*> kids;
    5454
    55         CompoundStmt();
     55        CompoundStmt( std::list<Label> labels );
    5656        CompoundStmt( std::list<Statement *> stmts );
    5757        CompoundStmt( const CompoundStmt &other );
     
    7070class NullStmt : public Statement {
    7171  public:
    72         NullStmt( const std::list<Label> & labels = {} );
     72        NullStmt();
     73        NullStmt( std::list<Label> labels );
    7374
    7475        virtual NullStmt *clone() const override { return new NullStmt( *this ); }
     
    8283        Expression *expr;
    8384
    84         ExprStmt( Expression *expr );
     85        ExprStmt( std::list<Label> labels, Expression *expr );
    8586        ExprStmt( const ExprStmt &other );
    8687        virtual ~ExprStmt();
     
    103104        std::list<Label> gotolabels;
    104105
    105         AsmStmt( bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );
     106        AsmStmt( std::list<Label> labels, bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );
    106107        AsmStmt( const AsmStmt &other );
    107108        virtual ~AsmStmt();
     
    133134        std::list<Statement *> initialization;
    134135
    135         IfStmt( Expression *condition, Statement *thenPart, Statement *elsePart,
     136        IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart,
    136137                        std::list<Statement *> initialization = std::list<Statement *>() );
    137138        IfStmt( const IfStmt &other );
     
    157158        std::list<Statement *> statements;
    158159
    159         SwitchStmt( Expression *condition, const std::list<Statement *> &statements );
     160        SwitchStmt( std::list<Label> labels, Expression *condition, const std::list<Statement *> &statements );
    160161        SwitchStmt( const SwitchStmt &other );
    161162        virtual ~SwitchStmt();
     
    179180        std::list<Statement *> stmts;
    180181
    181         CaseStmt( Expression *conditions, const std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError);
     182        CaseStmt( std::list<Label> labels, Expression *conditions, const std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError);
    182183        CaseStmt( const CaseStmt &other );
    183184        virtual ~CaseStmt();
    184185
    185         static CaseStmt * makeDefault( const std::list<Label> & labels = {}, std::list<Statement *> stmts = std::list<Statement *>() );
     186        static CaseStmt * makeDefault( std::list<Label> labels = std::list<Label>(), std::list<Statement *> stmts = std::list<Statement *>() );
    186187
    187188        bool isDefault() const { return _isDefault; }
     
    209210        bool isDoWhile;
    210211
    211         WhileStmt( Expression *condition,
     212        WhileStmt( std::list<Label> labels, Expression *condition,
    212213               Statement *body, bool isDoWhile = false );
    213214        WhileStmt( const WhileStmt &other );
     
    234235        Statement *body;
    235236
    236         ForStmt( std::list<Statement *> initialization,
     237        ForStmt( std::list<Label> labels, std::list<Statement *> initialization,
    237238             Expression *condition = 0, Expression *increment = 0, Statement *body = 0 );
    238239        ForStmt( const ForStmt &other );
     
    263264        Type type;
    264265
    265         BranchStmt( Label target, Type ) throw (SemanticError);
    266         BranchStmt( Expression *computedTarget, Type ) throw (SemanticError);
     266        BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError);
     267        BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError);
    267268
    268269        Label get_originalTarget() { return originalTarget; }
     
    288289        Expression *expr;
    289290
    290         ReturnStmt( Expression *expr );
     291        ReturnStmt( std::list<Label> labels, Expression *expr );
    291292        ReturnStmt( const ReturnStmt &other );
    292293        virtual ~ReturnStmt();
     
    309310        Expression * target;
    310311
    311         ThrowStmt( Kind kind, Expression * expr, Expression * target = nullptr );
     312        ThrowStmt( std::list<Label> labels, Kind kind, Expression * expr, Expression * target = nullptr );
    312313        ThrowStmt( const ThrowStmt &other );
    313314        virtual ~ThrowStmt();
     
    331332        FinallyStmt * finallyBlock;
    332333
    333         TryStmt( CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 );
     334        TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 );
    334335        TryStmt( const TryStmt &other );
    335336        virtual ~TryStmt();
     
    357358        Statement *body;
    358359
    359         CatchStmt( Kind kind, Declaration *decl,
     360        CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl,
    360361                   Expression *cond, Statement *body );
    361362        CatchStmt( const CatchStmt &other );
     
    380381        CompoundStmt *block;
    381382
    382         FinallyStmt( CompoundStmt *block );
     383        FinallyStmt( std::list<Label> labels, CompoundStmt *block );
    383384        FinallyStmt( const FinallyStmt &other );
    384385        virtual ~FinallyStmt();
     
    407408        };
    408409
    409         WaitForStmt();
     410        WaitForStmt( std::list<Label> labels = noLabels );
    410411        WaitForStmt( const WaitForStmt & );
    411412        virtual ~WaitForStmt();
     
    437438        Declaration *decl;
    438439
    439         DeclStmt( Declaration *decl );
     440        DeclStmt( std::list<Label> labels, Declaration *decl );
    440441        DeclStmt( const DeclStmt &other );
    441442        virtual ~DeclStmt();
  • src/SynTree/TupleExpr.cc

    r5da9d6a r3d560060  
    2323#include "Declaration.h"        // for ObjectDecl
    2424#include "Expression.h"         // for Expression, TupleExpr, TupleIndexExpr
    25 #include "SynTree/Label.h"      // for Label
     25#include "SynTree/Label.h"      // for Label, noLabels
    2626#include "SynTree/Statement.h"  // for CompoundStmt, DeclStmt, ExprStmt, Sta...
    2727#include "Tuples/Tuples.h"      // for makeTupleType
     
    8989        // convert internally into a StmtExpr which contains the declarations and produces the tuple of the assignments
    9090        set_result( Tuples::makeTupleType( assigns ) );
    91         CompoundStmt * compoundStmt = new CompoundStmt();
     91        CompoundStmt * compoundStmt = new CompoundStmt( noLabels );
    9292        std::list< Statement * > & stmts = compoundStmt->get_kids();
    9393        for ( ObjectDecl * obj : tempDecls ) {
    94                 stmts.push_back( new DeclStmt( obj ) );
     94                stmts.push_back( new DeclStmt( noLabels, obj ) );
    9595        }
    9696        TupleExpr * tupleExpr = new TupleExpr( assigns );
    9797        assert( tupleExpr->get_result() );
    98         stmts.push_back( new ExprStmt( tupleExpr ) );
     98        stmts.push_back( new ExprStmt( noLabels, tupleExpr ) );
    9999        stmtExpr = new StmtExpr( compoundStmt );
    100100}
  • src/Tuples/TupleAssignment.cc

    r5da9d6a r3d560060  
    2323
    2424#include "CodeGen/OperatorTable.h"
    25 #include "Common/PassVisitor.h"
    2625#include "Common/UniqueName.h"             // for UniqueName
    2726#include "Common/utility.h"                // for zipWith
     
    6261                struct Matcher {
    6362                  public:
    64                         Matcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, const
     63                        Matcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, const 
    6564                                ResolvExpr::AltList& rhs );
    6665                        virtual ~Matcher() {}
     
    7675                struct MassAssignMatcher : public Matcher {
    7776                  public:
    78                         MassAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs,
     77                        MassAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, 
    7978                                const ResolvExpr::AltList& rhs ) : Matcher(spotter, lhs, rhs) {}
    8079                        virtual void match( std::list< Expression * > &out );
     
    8382                struct MultipleAssignMatcher : public Matcher {
    8483                  public:
    85                         MultipleAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs,
     84                        MultipleAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, 
    8685                                const ResolvExpr::AltList& rhs ) : Matcher(spotter, lhs, rhs) {}
    8786                        virtual void match( std::list< Expression * > &out );
     
    120119        }
    121120
    122         void handleTupleAssignment( ResolvExpr::AlternativeFinder & currentFinder, UntypedExpr * expr,
     121        void handleTupleAssignment( ResolvExpr::AlternativeFinder & currentFinder, UntypedExpr * expr, 
    123122                                std::vector<ResolvExpr::AlternativeFinder> &args ) {
    124123                TupleAssignSpotter spotter( currentFinder );
     
    129128                : currentFinder(f) {}
    130129
    131         void TupleAssignSpotter::spot( UntypedExpr * expr,
     130        void TupleAssignSpotter::spot( UntypedExpr * expr, 
    132131                        std::vector<ResolvExpr::AlternativeFinder> &args ) {
    133132                if (  NameExpr *op = dynamic_cast< NameExpr * >(expr->get_function()) ) {
     
    138137                                if ( args.size() == 0 ) return;
    139138
    140                                 // if an assignment only takes 1 argument, that's odd, but maybe someone wrote
     139                                // if an assignment only takes 1 argument, that's odd, but maybe someone wrote 
    141140                                // the function, in which case AlternativeFinder will handle it normally
    142141                                if ( args.size() == 1 && CodeGen::isAssignment( fname ) ) return;
     
    147146                                        if ( ! refToTuple(lhsAlt.expr) ) continue;
    148147
    149                                         // explode is aware of casts - ensure every LHS expression is sent into explode
     148                                        // explode is aware of casts - ensure every LHS expression is sent into explode 
    150149                                        // with a reference cast
    151                                         // xxx - this seems to change the alternatives before the normal
     150                                        // xxx - this seems to change the alternatives before the normal 
    152151                                        //  AlternativeFinder flow; maybe this is desired?
    153152                                        if ( ! dynamic_cast<CastExpr*>( lhsAlt.expr ) ) {
    154                                                 lhsAlt.expr = new CastExpr( lhsAlt.expr,
    155                                                                 new ReferenceType( Type::Qualifiers(),
     153                                                lhsAlt.expr = new CastExpr( lhsAlt.expr, 
     154                                                                new ReferenceType( Type::Qualifiers(), 
    156155                                                                        lhsAlt.expr->get_result()->clone() ) );
    157156                                        }
     
    161160                                        explode( lhsAlt, currentFinder.get_indexer(), back_inserter(lhs), true );
    162161                                        for ( ResolvExpr::Alternative& alt : lhs ) {
    163                                                 // each LHS value must be a reference - some come in with a cast expression,
     162                                                // each LHS value must be a reference - some come in with a cast expression, 
    164163                                                // if not just cast to reference here
    165164                                                if ( ! dynamic_cast<ReferenceType*>( alt.expr->get_result() ) ) {
    166                                                         alt.expr = new CastExpr( alt.expr,
    167                                                                 new ReferenceType( Type::Qualifiers(),
     165                                                        alt.expr = new CastExpr( alt.expr, 
     166                                                                new ReferenceType( Type::Qualifiers(), 
    168167                                                                        alt.expr->get_result()->clone() ) );
    169168                                                }
     
    179178                                                // TODO build iterative version of this instead of using combos
    180179                                                std::vector< ResolvExpr::AltList > rhsAlts;
    181                                                 combos( std::next(args.begin(), 1), args.end(),
     180                                                combos( std::next(args.begin(), 1), args.end(), 
    182181                                                        std::back_inserter( rhsAlts ) );
    183182                                                for ( const ResolvExpr::AltList& rhsAlt : rhsAlts ) {
    184183                                                        // multiple assignment
    185184                                                        ResolvExpr::AltList rhs;
    186                                                         explode( rhsAlt, currentFinder.get_indexer(),
     185                                                        explode( rhsAlt, currentFinder.get_indexer(), 
    187186                                                                std::back_inserter(rhs), true );
    188187                                                        matcher.reset( new MultipleAssignMatcher( *this, lhs, rhs ) );
     
    194193                                                        if ( isTuple(rhsAlt.expr) ) {
    195194                                                                // multiple assignment
    196                                                                 explode( rhsAlt, currentFinder.get_indexer(),
     195                                                                explode( rhsAlt, currentFinder.get_indexer(), 
    197196                                                                        std::back_inserter(rhs), true );
    198197                                                                matcher.reset( new MultipleAssignMatcher( *this, lhs, rhs ) );
     
    223222                ResolvExpr::AltList current;
    224223                // now resolve new assignments
    225                 for ( std::list< Expression * >::iterator i = new_assigns.begin();
     224                for ( std::list< Expression * >::iterator i = new_assigns.begin(); 
    226225                                i != new_assigns.end(); ++i ) {
    227226                        PRINT(
     
    230229                        )
    231230
    232                         ResolvExpr::AlternativeFinder finder{ currentFinder.get_indexer(),
     231                        ResolvExpr::AlternativeFinder finder{ currentFinder.get_indexer(), 
    233232                                currentFinder.get_environ() };
    234233                        try {
     
    254253                // xxx -- was push_front
    255254                currentFinder.get_alternatives().push_back( ResolvExpr::Alternative(
    256                         new TupleAssignExpr(solved_assigns, matcher->tmpDecls), matcher->compositeEnv,
     255                        new TupleAssignExpr(solved_assigns, matcher->tmpDecls), matcher->compositeEnv, 
    257256                        ResolvExpr::sumCost( current ) + matcher->baseCost ) );
    258257        }
    259258
    260         TupleAssignSpotter::Matcher::Matcher( TupleAssignSpotter &spotter,
    261                 const ResolvExpr::AltList &lhs, const ResolvExpr::AltList &rhs )
    262         : lhs(lhs), rhs(rhs), spotter(spotter),
     259        TupleAssignSpotter::Matcher::Matcher( TupleAssignSpotter &spotter, 
     260                const ResolvExpr::AltList &lhs, const ResolvExpr::AltList &rhs ) 
     261        : lhs(lhs), rhs(rhs), spotter(spotter), 
    263262          baseCost( ResolvExpr::sumCost( lhs ) + ResolvExpr::sumCost( rhs ) ) {
    264263                simpleCombineEnvironments( lhs.begin(), lhs.end(), compositeEnv );
     
    278277        // xxx - maybe this should happen in alternative finder for every StmtExpr?
    279278        // xxx - it's possible that these environments could contain some useful information. Maybe the right thing to do is aggregate the environments and pass the aggregate back to be added into the compositeEnv
    280         struct EnvRemover {
    281                 void previsit( ExprStmt * stmt ) {
    282                         delete stmt->expr->env;
    283                         stmt->expr->env = nullptr;
     279        struct EnvRemover : public Visitor {
     280                virtual void visit( ExprStmt * stmt ) {
     281                        delete stmt->get_expr()->get_env();
     282                        stmt->get_expr()->set_env( nullptr );
     283                        Visitor::visit( stmt );
    284284                }
    285285        };
     
    293293                        ret->set_init( ctorInit );
    294294                        ResolvExpr::resolveCtorInit( ctorInit, spotter.currentFinder.get_indexer() ); // resolve ctor/dtors for the new object
    295                         PassVisitor<EnvRemover> rm; // remove environments from subexpressions of StmtExprs
     295                        EnvRemover rm; // remove environments from subexpressions of StmtExprs
    296296                        ctorInit->accept( rm );
    297297                }
  • src/Tuples/TupleExpansion.cc

    r5da9d6a r3d560060  
    315315        namespace {
    316316                /// determines if impurity (read: side-effects) may exist in a piece of code. Currently gives a very crude approximation, wherein any function call expression means the code may be impure
    317                 struct ImpurityDetector : public WithShortCircuiting {
     317                class ImpurityDetector : public Visitor {
     318                public:
    318319                        ImpurityDetector( bool ignoreUnique ) : ignoreUnique( ignoreUnique ) {}
    319320
    320                         void previsit( ApplicationExpr * appExpr ) {
    321                                 visit_children = false;
     321                        typedef Visitor Parent;
     322                        virtual void visit( ApplicationExpr * appExpr ) {
    322323                                if ( DeclarationWithType * function = InitTweak::getFunction( appExpr ) ) {
    323324                                        if ( function->get_linkage() == LinkageSpec::Intrinsic ) {
    324325                                                if ( function->get_name() == "*?" || function->get_name() == "?[?]" ) {
    325326                                                        // intrinsic dereference, subscript are pure, but need to recursively look for impurity
    326                                                         visit_children = true;
     327                                                        Parent::visit( appExpr );
    327328                                                        return;
    328329                                                }
     
    331332                                maybeImpure = true;
    332333                        }
    333                         void previsit( UntypedExpr * ) { maybeImpure = true; visit_children = false; }
    334                         void previsit( UniqueExpr * ) {
     334                        virtual void visit( UntypedExpr * ) { maybeImpure = true; }
     335                        virtual void visit( UniqueExpr * unq ) {
    335336                                if ( ignoreUnique ) {
    336337                                        // bottom out at unique expression.
    337338                                        // The existence of a unique expression doesn't change the purity of an expression.
    338339                                        // That is, even if the wrapped expression is impure, the wrapper protects the rest of the expression.
    339                                         visit_children = false;
    340340                                        return;
    341341                                }
     342                                maybeAccept( unq->expr, *this );
    342343                        }
    343344
     
    348349
    349350        bool maybeImpure( Expression * expr ) {
    350                 PassVisitor<ImpurityDetector> detector( false );
     351                ImpurityDetector detector( false );
    351352                expr->accept( detector );
    352                 return detector.pass.maybeImpure;
     353                return detector.maybeImpure;
    353354        }
    354355
    355356        bool maybeImpureIgnoreUnique( Expression * expr ) {
    356                 PassVisitor<ImpurityDetector> detector( true );
     357                ImpurityDetector detector( true );
    357358                expr->accept( detector );
    358                 return detector.pass.maybeImpure;
     359                return detector.maybeImpure;
    359360        }
    360361} // namespace Tuples
  • src/tests/except-mac.h

    r5da9d6a r3d560060  
    3030        size_t size; \
    3131        void (*copy)(except_name *this, except_name * other); \
    32         void (*free)(except_name &this); \
     32        void (*free)(except_name *this); \
    3333        const char * (*msg)(except_name *this); \
    3434        __VA_ARGS__ \
     
    4242// In each constructor the vtable must be initialized.
    4343#define VTABLE_INIT(this_name,except_name) \
    44 this_name.virtual_table = &INSTANCE(except_name)
     44this_name->virtual_table = &INSTANCE(except_name)
    4545
    4646// Declare the vtable instance. This should end an exception declaration.
     
    7373    this->virtual_table = other->virtual_table; \
    7474} \
    75 void ?{}(name & this) { \
     75void ?{}(name * this) { \
    7676        VTABLE_INIT(this,name); \
    7777} \
Note: See TracChangeset for help on using the changeset viewer.