Changes in / [a8541d9:cda48b6]


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Resolver.cc

    ra8541d9 rcda48b6  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 12:17:01 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jun 10 16:11:19 2015
    13 // Update Count     : 77
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Jun  7 21:50:37 2015
     13// Update Count     : 23
    1414//
    1515
     
    3737                virtual void visit( ObjectDecl *functionDecl );
    3838                virtual void visit( TypeDecl *typeDecl );
    39                 virtual void visit( ArrayType * at );
    4039
    4140                virtual void visit( ExprStmt *exprStmt );
     
    158157                initContext = new_type;
    159158                SymTab::Indexer::visit( objectDecl );
    160         }
    161 
    162         void Resolver::visit( ArrayType * at ) {
    163                 if ( at->get_dimension() ) {
    164                         BasicType arrayLenType = BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
    165                         CastExpr *castExpr = new CastExpr( at->get_dimension(), arrayLenType.clone() );
    166                         Expression *newExpr = findSingleExpression( castExpr, *this );
    167                         delete at->get_dimension();
    168                         at->set_dimension( newExpr );
    169 
    170                 }
    171                 Visitor::visit( at );
     159
     160                if ( ArrayType * at = dynamic_cast< ArrayType * >( new_type ) ){
     161                        if ( at->get_dimension() ) {
     162                                BasicType arrayLenType = BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
     163                                CastExpr *castExpr = new CastExpr( at->get_dimension(), arrayLenType.clone() );
     164                                Expression *newExpr = findSingleExpression( castExpr, *this );
     165                                delete at->get_dimension();
     166                                at->set_dimension( newExpr );
     167                        }
     168                }
    172169        }
    173170 
     
    273270                        returnStmt->set_expr( newExpr );
    274271                } // if
    275         }
    276 
    277         template< typename T >
    278         bool isCharType( T t ) {
    279                 if ( BasicType * bt = dynamic_cast< BasicType * >( t ) ) {
    280                         return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar ||
    281                                 bt->get_kind() == BasicType::UnsignedChar;
    282                 }
    283                 return false;
    284272        }
    285273
     
    308296                        delete castExpr;
    309297                        singleInit->set_value( newExpr );
    310 
    311                         // check if initializing type is char[]
    312                         if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) {
    313                                 if ( isCharType( at->get_base() ) ) {
    314                                         // check if the resolved type is char *
    315                                         if ( PointerType * pt = dynamic_cast< PointerType *>( newExpr->get_results().front() ) ) {
    316                                                 if ( isCharType( pt->get_base() ) ) {
    317                                                         // strip cast if we're initializing a char[] with a char *, e.g.
    318                                                         // char x[] = "hello";
    319                                                         CastExpr *ce = dynamic_cast< CastExpr * >( newExpr );
    320                                                         singleInit->set_value( ce->get_arg() );
    321                                                         ce->set_arg( NULL );
    322                                                         delete ce;                                                                     
    323                                                 }
    324                                         }
    325                                 }
    326                         }
    327298                } // if
    328299//      singleInit->get_value()->accept( *this );
     
    330301
    331302        void Resolver::visit( ListInit *listInit ) {
    332                 if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) {
    333                         std::list< Initializer * >::iterator iter( listInit->begin_initializers() );
    334                         for ( ; iter != listInit->end_initializers(); ++iter ) {
    335                                 initContext = at->get_base();
    336                                 (*iter)->accept( *this );
    337                         } // for
    338                 } else if ( UnionInstType *st = dynamic_cast< UnionInstType * >( initContext ) ) {
    339                         DeclarationWithType *dt = dynamic_cast< DeclarationWithType * >( *st->get_baseUnion()->get_members().begin() );
    340                         initContext = dt->get_type();
    341                         (*listInit->begin_initializers())->accept( *this );
    342                 } else {
    343                         // basic types are handled here
    344                         Visitor::visit( listInit );
    345                 }
    346 
     303                Visitor::visit(listInit);
    347304#if 0
    348305                if ( ArrayType *at = dynamic_cast<ArrayType*>(initContext) ) {
Note: See TracChangeset for help on using the changeset viewer.