Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r4d2434a r08061589  
    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 Jul 15 15:53:15 2016
    13 // Update Count     : 306
     11// Last Modified By :
     12// Last Modified On : Sun Jul 31 08:42:18 2016
     13// Update Count     : 345
    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
    157158                if ( objectDecl->get_bitfieldWidth() ) {
    158159                        output << ":";
     
    172173
    173174                        cur_indent += CodeGenerator::tabsize;
    174                         for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
     175                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) {
    175176                                output << indent;
    176177                                (*i)->accept( *this );
    177178                                output << ";" << endl;
    178                         }
     179                        } // for
    179180
    180181                        cur_indent -= CodeGenerator::tabsize;
     
    257258                                (*iter)->accept( *this );
    258259                                output << "]";
    259                         }
    260                 }
     260                        } // if
     261                } // for
    261262                output << " = ";
    262263        }
     
    270271                printDesignators( init->get_designators() );
    271272                output << "{ ";
    272                 if ( init->begin() == init->end() ) {
     273                if ( init->begin_initializers() == init->end_initializers() ) {
    273274                        // illegal to leave initializer list empty for scalar initializers, but always legal to have 0
    274275                        output << "0";
    275276                } else {
    276                         genCommaList( init->begin(), init->end() );
     277                        genCommaList( init->begin_initializers(), init->end_initializers() );
    277278                }
    278279                output << " }";
     
    317318                                        // do nothing
    318319                                        ;
    319                                 }
     320                                } // switch
    320321
    321322                                switch ( opInfo.type ) {
     
    385386                                        // there are no intrinsic definitions of 0/1 or label addresses as functions
    386387                                        assert( false );
    387                                 }
     388                                } // switch
    388389                        } else {
    389390                                varExpr->accept( *this );
     
    417418                                  case OT_CALL:
    418419                                        assert( false );
    419 
    420420
    421421                                  case OT_CTOR:
     
    437437                                                // no constructors with 0 or more than 2 parameters
    438438                                                assert( false );
    439                                         }
     439                                        } // if
    440440                                        break;
    441441
     
    470470                                        // there are no intrinsic definitions of 0 or 1 as functions
    471471                                        assert( false );
    472                                 }
     472                                } // switch
    473473                        } else {
    474                                 nameExpr->accept( *this );
    475                                 output << "(";
    476                                 genCommaList( untypedExpr->get_args().begin(), untypedExpr->get_args().end() );
    477                                 output << ")";
     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
    478485                        } // if
    479486                } else {
     
    521528                        // otherwise, the cast is to an lvalue type, so the cast should be dropped, since the result of a cast is
    522529                        // never an lvalue in C
    523                 }
     530                } // if
    524531                castExpr->get_arg()->accept( *this );
    525532                output << ")";
     
    654661                        if ( wantSpacing( *i ) ) {
    655662                                output << endl;
    656                         }
     663                        } // if
    657664                }
    658665                cur_indent -= CodeGenerator::tabsize;
     
    737744                        (*i)->accept( *this );
    738745                        output << endl;
    739                 }
     746                } // for
    740747                cur_indent -= CodeGenerator::tabsize;
    741748        }
     
    759766                        output << "continue";
    760767                        break;
    761                 }
     768                } // switch
    762769                output << ";";
    763770        }
     
    798805                if ( forStmt->get_condition() != 0 ) {
    799806                        forStmt->get_condition()->accept( *this );
    800                 }
     807                } // if
    801808                output << ";";
    802809
     
    805812                        Expression * expr = new CastExpr( forStmt->get_increment() );
    806813                        expr->accept( *this );
    807                 }
     814                } // if
    808815                output << ") ";
    809816
Note: See TracChangeset for help on using the changeset viewer.