Changeset 724c2b6


Ignore:
Timestamp:
Jul 15, 2015, 4:47:48 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
1db21619
Parents:
9163b9c (diff), 1ab4ce2 (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 'resolver'

Location:
src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r9163b9c r724c2b6  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jun 26 16:52:58 2015
    13 // Update Count     : 144
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Jul 15 14:47:42 2015
     13// Update Count     : 177
    1414//
    1515
     
    3838        int CodeGenerator::tabsize = 4;
    3939
    40         // the kinds of statements that would ideally be separated by more whitespace
     40        // the kinds of statements that would ideally be followed by whitespace
    4141        bool wantSpacing( Statement * stmt) {
    4242                return dynamic_cast< IfStmt * >( stmt ) || dynamic_cast< CompoundStmt * >( stmt ) ||
     
    588588
    589589        void CodeGenerator::visit( ForStmt *forStmt ) {
    590                 output << "for (";
    591 
    592                 if ( forStmt->get_initialization() != 0 )
    593                         forStmt->get_initialization()->accept( *this );
    594                 else
    595                         output << ";";
    596                
     590                // initialization is always hoisted, so don't
     591                // bother doing anything with that
     592                output << "for (;";
     593
    597594                if ( forStmt->get_condition() != 0 )
    598595                        forStmt->get_condition()->accept( *this );
  • src/ControlStruct/ForExprMutator.cc

    r9163b9c r724c2b6  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 19 15:31:47 2015
    13 // Update Count     : 2
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Jul 14 12:14:44 2015
     13// Update Count     : 10
    1414//
    1515
     
    2222                // recurse down all nest for loops to hoist any initializer declarations to make them C89 (rather than C99)
    2323                forStmt->set_body( forStmt->get_body()->acceptMutator( *this ) );
    24                 if ( DeclStmt *decl = dynamic_cast< DeclStmt * > ( forStmt->get_initialization() ) ) {
    25                         // create compound statement, move initializer declaration outside, leave _for_ as-is
    26                         CompoundStmt *block = new CompoundStmt( std::list< Label >() );
    27                         std::list<Statement *> &stmts = block->get_kids();
    2824
    29                         stmts.push_back( decl );
    30                         forStmt->set_initialization( 0 );
    31                         stmts.push_back( forStmt );
     25                std::list<Statement *> &init = forStmt->get_initialization();
     26                if ( init.size() == 0 ) {
     27                        return forStmt;
     28                } // if
    3229
    33                         return block;
    34                 } // if
     30                // create compound statement, move initializers outside, leave _for_ as-is
     31                CompoundStmt *block = new CompoundStmt( std::list< Label >() );
     32                std::list<Statement *> &stmts = block->get_kids();
     33                for ( std::list<Statement *>::iterator it = init.begin(); it != init.end(); ++it ) {
     34                        stmts.push_back( *it );
     35                }       // for
     36
     37                // add for to the new block
     38                stmts.push_back( forStmt );
     39                forStmt->set_initialization( std::list<Statement *>() );
     40                return block;
    3541
    3642                return forStmt;
  • src/ControlStruct/Mutate.cc

    r9163b9c r724c2b6  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jun 03 23:08:43 2015
    13 // Update Count     : 5
     12// Last Modified On : Wed Jul 15 14:50:04 2015
     13// Update Count     : 7
    1414//
    1515
     
    3636namespace ControlStruct {
    3737        void mutate( std::list< Declaration * > translationUnit ) {
    38                 // ForExprMutator formut;
     38                // hoist initialization out of for statements
     39                ForExprMutator formut;
    3940
    4041                // normalizes label definitions and generates multi-level
     
    5152                // LabelTypeChecker lbl;
    5253
    53                 // mutateAll( translationUnit, formut );
     54                mutateAll( translationUnit, formut );
    5455                acceptAll( translationUnit, lfix );
    5556                mutateAll( translationUnit, chmut );
  • src/GenPoly/PolyMutator.cc

    r9163b9c r724c2b6  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 19 07:45:50 2015
    13 // Update Count     : 1
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Jul 15 14:50:58 2015
     13// Update Count     : 3
    1414//
    1515
     
    9292        Statement * PolyMutator::mutate(ForStmt *forStmt) {
    9393                forStmt->set_body(  mutateStatement( forStmt->get_body() ) );
    94                 forStmt->set_initialization(  maybeMutate( forStmt->get_initialization(), *this ) );
     94                mutateAll( forStmt->get_initialization(), *this );
    9595                forStmt->set_condition(  mutateExpression( forStmt->get_condition() ) );
    9696                forStmt->set_increment(  mutateExpression( forStmt->get_increment() ) );
  • src/Parser/StatementNode.cc

    r9163b9c r724c2b6  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 14:59:41 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jun  6 23:25:41 2015
    13 // Update Count     : 19
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Jul 14 12:20:44 2015
     13// Update Count     : 21
    1414//
    1515
     
    271271                        assert( ctl != 0 );
    272272
    273                         Statement *stmt = 0;
    274                         if ( ctl->get_init() != 0 )
    275                                 stmt = ctl->get_init()->build();
     273                        std::list<Statement *> init;
     274                        if ( ctl->get_init() != 0 ) {
     275                                buildList( ctl->get_init(), init );
     276                        }
    276277
    277278                        Expression *cond = 0;
     
    283284                                incr = ctl->get_change()->build();
    284285
    285                         return new ForStmt( labs, stmt, cond, incr, branches.front() );
     286                        return new ForStmt( labs, init, cond, incr, branches.front() );
    286287                }
    287288          case Switch:
  • src/ResolvExpr/Resolver.cc

    r9163b9c r724c2b6  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 12:17:01 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul  3 16:18:20 2015
    13 // Update Count     : 159
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Jul 15 14:54:04 2015
     13// Update Count     : 167
    1414//
    1515
     
    226226
    227227        void Resolver::visit( ForStmt *forStmt ) {
    228             // SymTab::Indexer::visit( forStmt );
    229                 Expression *newExpr;
    230             // for statements introduce a level of scope
    231             enterScope();
    232             maybeAccept( forStmt->get_initialization(), *this );
     228                SymTab::Indexer::visit( forStmt );
     229
    233230                if ( forStmt->get_condition() ) {
    234                         newExpr = findSingleExpression( forStmt->get_condition(), *this );
     231                        Expression * newExpr = findSingleExpression( forStmt->get_condition(), *this );
    235232                        delete forStmt->get_condition();
    236233                        forStmt->set_condition( newExpr );
    237234                } // if
    238  
     235               
    239236                if ( forStmt->get_increment() ) {
    240                         newExpr = findVoidExpression( forStmt->get_increment(), *this );
     237                        Expression * newExpr = findVoidExpression( forStmt->get_increment(), *this );
    241238                        delete forStmt->get_increment();
    242239                        forStmt->set_increment( newExpr );
    243240                } // if
    244 
    245             maybeAccept( forStmt->get_condition(), *this );
    246             maybeAccept( forStmt->get_increment(), *this );
    247             maybeAccept( forStmt->get_body(), *this );
    248             leaveScope();
    249241        }
    250242
  • src/SymTab/AddVisit.h

    r9163b9c r724c2b6  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 16:14:32 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 17 16:16:38 2015
    13 // Update Count     : 3
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Jul 14 12:26:17 2015
     13// Update Count     : 4
    1414//
    1515
     
    5757        inline void addVisit(ForStmt *forStmt, Visitor &visitor) {
    5858                addVisitStatement( forStmt->get_body(), visitor );
    59                 maybeAccept( forStmt->get_initialization(), visitor );
     59                acceptAll( forStmt->get_initialization(), visitor );
    6060                maybeAccept( forStmt->get_condition(), visitor );
    6161                maybeAccept( forStmt->get_increment(), visitor );
  • src/SymTab/Validate.cc

    r9163b9c r724c2b6  
    1010// Created On       : Sun May 17 21:50:04 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Mon Jul 13 14:38:19 2015
    13 // Update Count     : 184
     12// Last Modified On : Tue Jul 14 12:27:54 2015
     13// Update Count     : 186
    1414//
    1515
     
    535535                init->get_args().push_back( new NameExpr( "0" ) );
    536536                Statement *initStmt = new ExprStmt( noLabels, init );
    537  
     537                std::list<Statement *> initList;
     538                initList.push_back( initStmt );
     539
    538540                UntypedExpr *cond = new UntypedExpr( new NameExpr( "?<?" ) );
    539541                cond->get_args().push_back( new VariableExpr( index ) );
     
    560562                assignExpr->get_args().push_back( srcIndex );
    561563 
    562                 *out++ = new ForStmt( noLabels, initStmt, cond, inc, new ExprStmt( noLabels, assignExpr ) );
     564                *out++ = new ForStmt( noLabels, initList, cond, inc, new ExprStmt( noLabels, assignExpr ) );
    563565        }
    564566
  • src/SynTree/Mutator.cc

    r9163b9c r724c2b6  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 18 10:10:46 2015
    13 // Update Count     : 1
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Jul 14 12:31:39 2015
     13// Update Count     : 2
    1414//
    1515
     
    109109
    110110Statement *Mutator::mutate( ForStmt *forStmt ) {
    111         forStmt->set_initialization( maybeMutate( forStmt->get_initialization(), *this ) );
     111        mutateAll( forStmt->get_initialization(), *this );
    112112        forStmt->set_condition( maybeMutate( forStmt->get_condition(), *this ) );
    113113        forStmt->set_increment( maybeMutate( forStmt->get_increment(), *this ) );
  • src/SynTree/Statement.cc

    r9163b9c r724c2b6  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jun 29 17:37:10 2015
    13 // Update Count     : 22
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Jul 15 14:57:40 2015
     13// Update Count     : 27
    1414//
    1515
     
    192192}
    193193
    194 ForStmt::ForStmt( std::list<Label> labels, Statement *initialization_, Expression *condition_, Expression *increment_, Statement *body_ ):
     194ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization_, Expression *condition_, Expression *increment_, Statement *body_ ):
    195195        Statement( labels ), initialization( initialization_ ), condition( condition_ ), increment( increment_ ), body( body_ ) {
    196196}
    197197
    198198ForStmt::~ForStmt() {
    199         delete initialization;
     199        deleteAll( initialization );
    200200        delete condition;
    201201        delete increment;
     
    213213
    214214        os << string( indent + 2, ' ' ) << "initialization: \n";
    215         if ( initialization != 0 )
    216                 initialization->print( os, indent + 4 );
     215        for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) {
     216                (*it)->print( os, indent + 4 );
     217        }
    217218
    218219        os << "\n" << string( indent + 2, ' ' ) << "condition: \n";
  • src/SynTree/Statement.h

    r9163b9c r724c2b6  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jun 23 11:44:27 2015
    13 // Update Count     : 20
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Jul 14 12:14:54 2015
     13// Update Count     : 24
    1414//
    1515
     
    199199class ForStmt : public Statement {
    200200  public:
    201         ForStmt( std::list<Label> labels, Statement *initialization = 0,
     201        ForStmt( std::list<Label> labels, std::list<Statement *> initialization,
    202202             Expression *condition = 0, Expression *increment = 0, Statement *body = 0 );
    203203        virtual ~ForStmt();
    204204
    205         Statement *get_initialization() { return initialization; }
    206         void set_initialization( Statement *newValue ) { initialization = newValue; }
     205        std::list<Statement *> &get_initialization() { return initialization; }
     206        void set_initialization( std::list<Statement *> newValue ) { initialization = newValue; }
    207207        Expression *get_condition() { return condition; }
    208208        void set_condition( Expression *newValue ) { condition = newValue; }
     
    217217        virtual void print( std::ostream &os, int indent = 0 ) const;
    218218  private:
    219         Statement *initialization;
     219        std::list<Statement *> initialization;
    220220        Expression *condition;
    221221        Expression *increment;
  • src/SynTree/Visitor.cc

    r9163b9c r724c2b6  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 18 11:14:51 2015
    13 // Update Count     : 2
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Jul 14 12:31:03 2015
     13// Update Count     : 3
    1414//
    1515
     
    9494
    9595void Visitor::visit( ForStmt *forStmt ) {
    96         // ForStmt still needs to be fixed
    97         maybeAccept( forStmt->get_initialization(), *this );
     96        acceptAll( forStmt->get_initialization(), *this );
    9897        maybeAccept( forStmt->get_condition(), *this );
    9998        maybeAccept( forStmt->get_increment(), *this );
  • src/main.cc

    r9163b9c r724c2b6  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Mon Jul 06 15:01:26 2015
    13 // Update Count     : 79
     12// Last Modified On : Wed Jul 15 16:45:24 2015
     13// Update Count     : 145
    1414//
    1515
     
    5454        if ( errorp ) std::cerr << x << std::endl;
    5555
    56 void parse( FILE * input, LinkageSpec::Type t, bool shouldExit = false );
     56static void parse( FILE * input, LinkageSpec::Type t, bool shouldExit = false );
     57static void dump( std::list< Declaration * > & translationUnit );
    5758
    5859bool
     
    6465        libcfap = false,
    6566        nopreludep = false,
    66         protop = false,
     67        noprotop = false,
    6768        parsep = false,
    6869        resolvep = false,                                                                       // used in AlternativeFinder
     
    8182        { "grammar", no_argument, 0, Grammar },
    8283        { "libcfa", no_argument, 0, LibCFA },
    83         { "nopreamble", no_argument, 0, Nopreamble },
     84        { "no-preamble", no_argument, 0, Nopreamble },
    8485        { "parse", no_argument, 0, Parse },
    85         { "prototypes", no_argument, 0, Prototypes },
     86        { "no-prototypes", no_argument, 0, Prototypes },
    8687        { "resolver", no_argument, 0, Resolver },
    8788        { "symbol", no_argument, 0, Symbol },
     
    131132                  case Prototypes:
    132133                  case 'p':                                                                             // generate prototypes for preamble functions
    133                         protop = true;
     134                        noprotop = true;
    134135                        break;
    135136                  case Parse:
     
    221222                Parser::get_parser().freeTree();
    222223                if ( astp ) {
    223                         printAll( translationUnit, std::cout );
     224                        dump( translationUnit );
    224225                        return 0;
    225226                } // if
     
    242243
    243244                if ( validp ) {
    244                         printAll( translationUnit, std::cout );
     245                        dump( translationUnit );
    245246                        return 0;
    246247                } // if
     
    252253
    253254                if ( libcfap ) {
    254                         protop = true;
    255255                        // generate the bodies of cfa library functions
    256256                        LibCfa::makeLibCfa( translationUnit );
     
    258258
    259259                if ( bresolvep ) {
    260                         printAll( translationUnit, std::cout );
     260                        dump( translationUnit );
    261261                        return 0;
    262262                } // if
     
    265265                ResolvExpr::resolve( translationUnit );
    266266                if ( exprp ) {
    267                         printAll( translationUnit, std::cout );
     267                        dump( translationUnit );
    268268                }
    269269
     
    279279                // print tree right before code generation
    280280                if ( codegenp ) {
    281                         printAll( translationUnit, std::cout );
    282                         return 0;
    283                 } // if
    284 
    285                 CodeGen::generate( translationUnit, *output, true ); //protop );
     281                        dump( translationUnit );
     282                        return 0;
     283                } // if
     284
     285                CodeGen::generate( translationUnit, *output, ! noprotop );
    286286
    287287                if ( output != &std::cout ) {
     
    290290        } catch ( SemanticError &e ) {
    291291                if ( errorp ) {
    292                         printAll( translationUnit, std::cerr );
     292                        dump( translationUnit );
    293293                }
    294294                e.print( std::cerr );
     
    315315} // main
    316316
    317 void parse( FILE * input, LinkageSpec::Type linkage, bool shouldExit ) {
     317static void parse( FILE * input, LinkageSpec::Type linkage, bool shouldExit ) {
    318318        Parser::get_parser().set_linkage( linkage );
    319319        Parser::get_parser().parse( input );
     
    325325}
    326326
     327static bool notPrelude( Declaration * decl ) {
     328        return ! LinkageSpec::isBuiltin( decl->get_linkage() );
     329}
     330
     331static void dump( std::list< Declaration * > & translationUnit ) {
     332        std::list< Declaration * > decls;
     333        if ( noprotop ) {
     334                filter( translationUnit.begin(), translationUnit.end(),
     335                                std::back_inserter( decls ), notPrelude );
     336        } else {
     337                decls = translationUnit;
     338        }
     339
     340        printAll( decls, std::cout );
     341}
     342
     343
    327344// Local Variables: //
    328345// tab-width: 4 //
Note: See TracChangeset for help on using the changeset viewer.