Changeset 86ad276 for src/ControlStruct


Ignore:
Timestamp:
Dec 5, 2017, 1:36:23 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
12d2dc8
Parents:
f3b9efc (diff), 5da9d6a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/ControlStruct
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/ExceptTranslate.cc

    rf3b9efc r86ad276  
    3030#include "SynTree/Expression.h"       // for UntypedExpr, ConstantExpr, Name...
    3131#include "SynTree/Initializer.h"      // for SingleInit, ListInit
    32 #include "SynTree/Label.h"            // for Label, noLabels
     32#include "SynTree/Label.h"            // for Label
    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(noLabels, item));
     59                block->push_back(new DeclStmt(item));
    6060        }
    6161
     
    205205                throwStmt->set_expr( nullptr );
    206206                delete throwStmt;
    207                 return new ExprStmt( noLabels, call );
     207                return new ExprStmt( call );
    208208        }
    209209
     
    220220                assert( handler_except_decl );
    221221
    222                 CompoundStmt * result = new CompoundStmt( throwStmt->get_labels() );
    223                 result->push_back( new ExprStmt( noLabels, UntypedExpr::createAssign(
     222                CompoundStmt * result = new CompoundStmt();
     223                result->labels =  throwStmt->labels;
     224                result->push_back( new ExprStmt( UntypedExpr::createAssign(
    224225                        nameOf( handler_except_decl ),
    225226                        new ConstantExpr( Constant::null(
     
    231232                        ) ) );
    232233                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(),
    251250                        new ConstantExpr( Constant::from_bool( false ) )
    252251                        );
     252                result->labels = throwStmt->labels;
    253253                delete throwStmt;
    254254                return result;
     
    291291                        // }
    292292                        // return;
    293                         CompoundStmt * block = new CompoundStmt( noLabels );
     293                        CompoundStmt * block = new CompoundStmt();
    294294
    295295                        // Just copy the exception value. (Post Validation)
     
    304304                                        ) })
    305305                                );
    306                         block->push_back( new DeclStmt( noLabels, local_except ) );
     306                        block->push_back( new DeclStmt( local_except ) );
    307307
    308308                        // Add the cleanup attribute.
     
    324324
    325325                        std::list<Statement *> caseBody
    326                                         { block, new ReturnStmt( noLabels, nullptr ) };
     326                                        { block, new ReturnStmt( nullptr ) };
    327327                        handler_wrappers.push_back( new CaseStmt(
    328                                 noLabels,
    329328                                new ConstantExpr( Constant::from_int( index ) ),
    330329                                caseBody
     
    340339
    341340                SwitchStmt * handler_lookup = new SwitchStmt(
    342                         noLabels,
    343341                        nameOf( index_obj ),
    344342                        stmt_handlers
    345343                        );
    346                 CompoundStmt * body = new CompoundStmt( noLabels );
     344                CompoundStmt * body = new CompoundStmt();
    347345                body->push_back( handler_lookup );
    348346
     
    363361                // }
    364362
    365                 CompoundStmt * block = new CompoundStmt( noLabels );
     363                CompoundStmt * block = new CompoundStmt();
    366364
    367365                // Local Declaration
     
    369367                        dynamic_cast<ObjectDecl *>( modded_handler->get_decl() );
    370368                assert( local_except );
    371                 block->push_back( new DeclStmt( noLabels, local_except ) );
     369                block->push_back( new DeclStmt( local_except ) );
    372370
    373371                // Check for type match.
     
    381379                }
    382380                // Construct the match condition.
    383                 block->push_back( new IfStmt( noLabels,
     381                block->push_back( new IfStmt(
    384382                        cond, modded_handler->get_body(), nullptr ) );
    385383
     
    397395                // }
    398396
    399                 CompoundStmt * body = new CompoundStmt( noLabels );
     397                CompoundStmt * body = new CompoundStmt();
    400398
    401399                FunctionType * func_type = match_func_t.clone();
     
    413411
    414412                        // Create new body.
    415                         handler->set_body( new ReturnStmt( noLabels,
     413                        handler->set_body( new ReturnStmt(
    416414                                new ConstantExpr( Constant::from_int( index ) ) ) );
    417415
     
    421419                }
    422420
    423                 body->push_back( new ReturnStmt( noLabels,
     421                body->push_back( new ReturnStmt(
    424422                        new ConstantExpr( Constant::from_int( 0 ) ) ) );
    425423
     
    441439                args.push_back( nameOf( terminate_match ) );
    442440
    443                 CompoundStmt * callStmt = new CompoundStmt( noLabels );
    444                 callStmt->push_back( new ExprStmt( noLabels, caller ) );
     441                CompoundStmt * callStmt = new CompoundStmt();
     442                callStmt->push_back( new ExprStmt( caller ) );
    445443                return callStmt;
    446444        }
     
    451449                //     HANDLER WRAPPERS { `hander->body`; return true; }
    452450                // }
    453                 CompoundStmt * body = new CompoundStmt( noLabels );
     451                CompoundStmt * body = new CompoundStmt();
    454452
    455453                FunctionType * func_type = handle_func_t.clone();
     
    464462                                dynamic_cast<CompoundStmt*>( handler->get_body() );
    465463                        if ( ! handling_code ) {
    466                                 handling_code = new CompoundStmt( noLabels );
     464                                handling_code = new CompoundStmt();
    467465                                handling_code->push_back( handler->get_body() );
    468466                        }
    469                         handling_code->push_back( new ReturnStmt( noLabels,
     467                        handling_code->push_back( new ReturnStmt(
    470468                                new ConstantExpr( Constant::from_bool( true ) ) ) );
    471469                        handler->set_body( handling_code );
     
    476474                }
    477475
    478                 body->push_back( new ReturnStmt( noLabels,
     476                body->push_back( new ReturnStmt(
    479477                        new ConstantExpr( Constant::from_bool( false ) ) ) );
    480478
     
    486484                        Statement * wraps,
    487485                        FunctionDecl * resume_handler ) {
    488                 CompoundStmt * body = new CompoundStmt( noLabels );
     486                CompoundStmt * body = new CompoundStmt();
    489487
    490488                // struct __try_resume_node __resume_node
     
    521519                setup->get_args().push_back( nameOf( resume_handler ) );
    522520
    523                 body->push_back( new ExprStmt( noLabels, setup ) );
     521                body->push_back( new ExprStmt( setup ) );
    524522
    525523                body->push_back( wraps );
     
    646644                // Generate a prefix for the function names?
    647645
    648                 CompoundStmt * block = new CompoundStmt( noLabels );
     646                CompoundStmt * block = new CompoundStmt();
    649647                CompoundStmt * inner = take_try_block( tryStmt );
    650648
  • src/ControlStruct/ForExprMutator.cc

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

    rf3b9efc r86ad276  
    3737        }
    3838
    39         void LabelFixer::visit( FunctionDecl *functionDecl ) {
     39        void LabelFixer::previsit( FunctionDecl * ) {
    4040                // need to go into a nested function in a fresh state
    41                 std::map < Label, Entry *> oldLabelTable = labelTable;
     41                GuardValue( labelTable );
    4242                labelTable.clear();
     43        }
    4344
    44                 maybeAccept( functionDecl->get_statements(), *this );
    45 
     45        void LabelFixer::postvisit( FunctionDecl * functionDecl ) {
    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;
    5248        }
    5349
    5450        // prune to at most one label definition for each statement
    55         void LabelFixer::visit( Statement *stmt ) {
     51        void LabelFixer::previsit( Statement *stmt ) {
    5652                std::list< Label > &labels = stmt->get_labels();
    5753
     
    6258        }
    6359
    64         void LabelFixer::visit( BranchStmt *branchStmt ) {
    65                 visit ( ( Statement * )branchStmt );
     60        void LabelFixer::previsit( BranchStmt *branchStmt ) {
     61                previsit( ( Statement *)branchStmt );
    6662
    6763                // for labeled branches, add an entry to the label table
     
    7268        }
    7369
    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                 }
     70        void LabelFixer::previsit( LabelAddressExpr * addrExpr ) {
     71                Label & target = addrExpr->arg;
     72                assert( target != "" );
     73                setLabelsUsg( target, addrExpr );
    8574        }
    8675
  • src/ControlStruct/LabelFixer.h

    rf3b9efc r86ad276  
    1919#include <map>                     // for map
    2020
     21#include "Common/PassVisitor.h"
    2122#include "Common/SemanticError.h"  // for SemanticError
    2223#include "SynTree/Label.h"         // for Label
     
    2627namespace ControlStruct {
    2728        /// normalizes label definitions and generates multi-level exit labels
    28 class LabelGenerator;
     29        class LabelGenerator;
    2930
    30         class LabelFixer final : public Visitor {
    31                 typedef Visitor Parent;
     31        class LabelFixer final : public WithGuards {
    3232          public:
    3333                LabelFixer( LabelGenerator *gen = 0 );
     
    3535                std::map < Label, Statement * > *resolveJumps() throw ( SemanticError );
    3636
    37                 using Visitor::visit;
    38 
    3937                // Declarations
    40                 virtual void visit( FunctionDecl *functionDecl ) override;
     38                void previsit( FunctionDecl *functionDecl );
     39                void postvisit( FunctionDecl *functionDecl );
    4140
    4241                // Statements
    43                 void visit( Statement *stmt );
     42                void previsit( Statement *stmt );
     43                void previsit( BranchStmt *branchStmt );
    4444
    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;
     45                // Expressions
     46                void previsit( LabelAddressExpr *addrExpr );
    5947
    6048                Label setLabelsDef( std::list< Label > &, Statement *definition );
  • src/ControlStruct/MLEMutator.cc

    rf3b9efc r86ad276  
    149149
    150150                        if ( CaseStmt * c = dynamic_cast< CaseStmt * >( statements.back() ) ) {
    151                                 std::list<Label> temp; temp.push_back( brkLabel );
    152                                 c->get_statements().push_back( new BranchStmt( temp, Label("brkLabel"), BranchStmt::Break ) );
     151                                Statement * stmt = new BranchStmt( Label("brkLabel"), BranchStmt::Break );
     152                                stmt->labels.push_back( brkLabel );
     153                                c->get_statements().push_back( stmt );
    153154                        } else assert(0); // as of this point, all statements of a switch are still CaseStmts
    154155                } // if
     
    232233                // transform break/continue statements into goto to simplify later handling of branches
    233234                delete branchStmt;
    234                 return new BranchStmt( std::list<Label>(), exitLabel, BranchStmt::Goto );
     235                return new BranchStmt( exitLabel, BranchStmt::Goto );
    235236        }
    236237
     
    239240                CompoundStmt *newBody;
    240241                if ( ! (newBody = dynamic_cast<CompoundStmt *>( bodyLoop )) ) {
    241                         newBody = new CompoundStmt( std::list< Label >() );
     242                        newBody = new CompoundStmt();
    242243                        newBody->get_kids().push_back( bodyLoop );
    243244                } // if
  • src/ControlStruct/Mutate.cc

    rf3b9efc r86ad276  
    2424#include "SynTree/Declaration.h"   // for Declaration
    2525#include "SynTree/Mutator.h"       // for mutateAll
    26 //#include "ExceptMutator.h"
    2726
    2827#include "Common/PassVisitor.h"    // for PassVisitor
     
    3736
    3837                // normalizes label definitions and generates multi-level exit labels
    39                 LabelFixer lfix;
    40 
    41                 //ExceptMutator exc;
     38                PassVisitor<LabelFixer> lfix;
    4239
    4340                mutateAll( translationUnit, formut );
    4441                acceptAll( translationUnit, lfix );
    45                 //mutateAll( translationUnit, exc );
    4642        }
    4743} // namespace CodeGen
Note: See TracChangeset for help on using the changeset viewer.