Ignore:
Timestamp:
Jun 29, 2016, 4:47:57 PM (8 years ago)
Author:
Aaron Moss <a3moss@…>
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, with_gc
Children:
a1d7679
Parents:
89b686a (diff), 87b5bf0 (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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r89b686a re64365c  
    4848        }
    4949
    50         ostream & CodeGenerator::Indenter::operator()( ostream & output ) {
     50        ostream & CodeGenerator::Indenter::operator()( ostream & output ) const {
    5151          return output << string( cg.cur_indent, ' ' );
    5252        }
    5353
    54         ostream & operator<<( ostream & output, CodeGenerator::Indenter &indent ) {
     54        ostream & operator<<( ostream & output, const CodeGenerator::Indenter &indent ) {
    5555                return indent( output );
    5656        }
    5757
    58         CodeGenerator::CodeGenerator( std::ostream &os ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ) { }
     58        CodeGenerator::LabelPrinter & CodeGenerator::LabelPrinter::operator()( std::list< Label > & l ) {
     59                labels = &l;
     60                return *this;
     61        }
     62
     63        ostream & operator<<( ostream & output, CodeGenerator::LabelPrinter &printLabels ) {
     64                std::list< Label > & labs = *printLabels.labels;
     65                // l.unique(); // assumes a sorted list. Why not use set? Does order matter?
     66                for ( Label & l : labs ) {
     67                        output << l.get_name() + ": ";
     68                        printLabels.cg.genAttributes( l.get_attributes() );
     69                }
     70                return output;
     71        }
     72
     73        CodeGenerator::CodeGenerator( std::ostream &os ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ) { }
    5974
    6075        CodeGenerator::CodeGenerator( std::ostream &os, std::string init, int indentation, bool infunp )
    61                         : indent( *this), cur_indent( indentation ), insideFunction( infunp ), output( os ) {
     76                        : indent( *this), cur_indent( indentation ), insideFunction( infunp ), output( os ), printLabels( *this ) {
    6277                //output << std::string( init );
    6378        }
    6479
    6580        CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indentation, bool infunp )
    66                         : indent( *this ), cur_indent( indentation ), insideFunction( infunp ), output( os ) {
     81                        : indent( *this ), cur_indent( indentation ), insideFunction( infunp ), output( os ), printLabels( *this ) {
    6782                //output << std::string( init );
    6883        }
     
    735750        void CodeGenerator::visit( ReturnStmt *returnStmt ) {
    736751                output << "return ";
    737 
    738                 // xxx -- check for null expression;
    739                 if ( returnStmt->get_expr() ) {
    740                         returnStmt->get_expr()->accept( *this );
    741                 } // if
     752                maybeAccept( returnStmt->get_expr(), *this );
    742753                output << ";";
    743754        }
     
    799810                        output << ";";
    800811                } // if
    801         }
    802 
    803         std::string CodeGenerator::printLabels( std::list< Label > &l ) {
    804                 std::string str( "" );
    805                 l.unique(); // assumes a sorted list. Why not use set?
    806 
    807                 for ( std::list< Label >::iterator i = l.begin(); i != l.end(); i++ )
    808                         str += *i + ": ";
    809 
    810                 return str;
    811812        }
    812813
Note: See TracChangeset for help on using the changeset viewer.