Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r08061589 r4d2434a  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By :
    12 // Last Modified On : Sun Jul 31 08:42:18 2016
    13 // Update Count     : 345
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Jul 15 15:53:15 2016
     13// Update Count     : 306
    1414//
    1515
     
    4545        bool wantSpacing( Statement * stmt) {
    4646                return dynamic_cast< IfStmt * >( stmt ) || dynamic_cast< CompoundStmt * >( stmt ) ||
    47                         dynamic_cast< WhileStmt * >( stmt ) || dynamic_cast< ForStmt * >( stmt ) || dynamic_cast< SwitchStmt *>( stmt );
     47                        dynamic_cast< WhileStmt * >( stmt ) || dynamic_cast< ForStmt * > ( stmt ) || dynamic_cast< SwitchStmt *>( stmt );
    4848        }
    4949
     
    8383        }
    8484
    85         CodeGenerator::CodeGenerator( std::ostream &os ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ) {}
     85        CodeGenerator::CodeGenerator( std::ostream &os ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ) { }
    8686
    8787        CodeGenerator::CodeGenerator( std::ostream &os, std::string init, int indentation, bool infunp )
     
    155155                        objectDecl->get_init()->accept( *this );
    156156                } // if
    157 
    158157                if ( objectDecl->get_bitfieldWidth() ) {
    159158                        output << ":";
     
    173172
    174173                        cur_indent += CodeGenerator::tabsize;
    175                         for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) {
     174                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    176175                                output << indent;
    177176                                (*i)->accept( *this );
    178177                                output << ";" << endl;
    179                         } // for
     178                        }
    180179
    181180                        cur_indent -= CodeGenerator::tabsize;
     
    258257                                (*iter)->accept( *this );
    259258                                output << "]";
    260                         } // if
    261                 } // for
     259                        }
     260                }
    262261                output << " = ";
    263262        }
     
    271270                printDesignators( init->get_designators() );
    272271                output << "{ ";
    273                 if ( init->begin_initializers() == init->end_initializers() ) {
     272                if ( init->begin() == init->end() ) {
    274273                        // illegal to leave initializer list empty for scalar initializers, but always legal to have 0
    275274                        output << "0";
    276275                } else {
    277                         genCommaList( init->begin_initializers(), init->end_initializers() );
     276                        genCommaList( init->begin(), init->end() );
    278277                }
    279278                output << " }";
     
    318317                                        // do nothing
    319318                                        ;
    320                                 } // switch
     319                                }
    321320
    322321                                switch ( opInfo.type ) {
     
    386385                                        // there are no intrinsic definitions of 0/1 or label addresses as functions
    387386                                        assert( false );
    388                                 } // switch
     387                                }
    389388                        } else {
    390389                                varExpr->accept( *this );
     
    418417                                  case OT_CALL:
    419418                                        assert( false );
     419
    420420
    421421                                  case OT_CTOR:
     
    437437                                                // no constructors with 0 or more than 2 parameters
    438438                                                assert( false );
    439                                         } // if
     439                                        }
    440440                                        break;
    441441
     
    470470                                        // there are no intrinsic definitions of 0 or 1 as functions
    471471                                        assert( false );
    472                                 } // switch
     472                                }
    473473                        } else {
    474                                 if ( nameExpr->get_name() == "Range" ) { // case V1 ... V2 or case V1~V2
    475                                         assert( untypedExpr->get_args().size() == 2 );
    476                                         (*untypedExpr->get_args().begin())->accept( *this );
    477                                         output << " ... ";
    478                                         (*--untypedExpr->get_args().end())->accept( *this );
    479                                 } else {                                                                // builtin routines
    480                                         nameExpr->accept( *this );
    481                                         output << "(";
    482                                         genCommaList( untypedExpr->get_args().begin(), untypedExpr->get_args().end() );
    483                                         output << ")";
    484                                 } // if
     474                                nameExpr->accept( *this );
     475                                output << "(";
     476                                genCommaList( untypedExpr->get_args().begin(), untypedExpr->get_args().end() );
     477                                output << ")";
    485478                        } // if
    486479                } else {
     
    528521                        // otherwise, the cast is to an lvalue type, so the cast should be dropped, since the result of a cast is
    529522                        // never an lvalue in C
    530                 } // if
     523                }
    531524                castExpr->get_arg()->accept( *this );
    532525                output << ")";
     
    661654                        if ( wantSpacing( *i ) ) {
    662655                                output << endl;
    663                         } // if
     656                        }
    664657                }
    665658                cur_indent -= CodeGenerator::tabsize;
     
    744737                        (*i)->accept( *this );
    745738                        output << endl;
    746                 } // for
     739                }
    747740                cur_indent -= CodeGenerator::tabsize;
    748741        }
     
    766759                        output << "continue";
    767760                        break;
    768                 } // switch
     761                }
    769762                output << ";";
    770763        }
     
    805798                if ( forStmt->get_condition() != 0 ) {
    806799                        forStmt->get_condition()->accept( *this );
    807                 } // if
     800                }
    808801                output << ";";
    809802
     
    812805                        Expression * expr = new CastExpr( forStmt->get_increment() );
    813806                        expr->accept( *this );
    814                 } // if
     807                }
    815808                output << ") ";
    816809
Note: See TracChangeset for help on using the changeset viewer.