Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Resolver.cc

    r5b2f5bb r3cfe27f  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Resolver.cc --
     7// Resolver.cc -- 
    88//
    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 Mar 30 15:47:19 2016
    13 // Update Count     : 203
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Mar 24 16:43:11 2016
     13// Update Count     : 181
    1414//
    1515
     
    3333          public:
    3434                Resolver() : SymTab::Indexer( false ), switchType( 0 ) {}
    35 
     35 
    3636                virtual void visit( FunctionDecl *functionDecl );
    3737                virtual void visit( ObjectDecl *functionDecl );
     
    5454                virtual void visit( SingleInit *singleInit );
    5555                virtual void visit( ListInit *listInit );
    56                 virtual void visit( ConstructorInit *ctorInit );
    5756          private:
    5857        typedef std::list< Initializer * >::iterator InitIterator;
     
    6059          void resolveAggrInit( AggregateDecl *, InitIterator &, InitIterator & );
    6160          void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator & );
    62           void fallbackInit( ConstructorInit * ctorInit );
    6361
    6462                std::list< Type * > functionReturn;
     
    9795                        return newExpr;
    9896                }
    99 
     97 
    10098                Expression *findSingleExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
    10199                        TypeEnvironment env;
     
    128126                        } // if
    129127                }
    130 
     128 
    131129                Expression *findIntegralExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
    132130                        TypeEnvironment env;
     
    161159                        return newExpr;
    162160                }
    163 
    164         }
    165 
     161 
     162        }
     163 
    166164        void Resolver::visit( ObjectDecl *objectDecl ) {
    167165                Type *new_type = resolveTypeof( objectDecl->get_type(), *this );
    168166                objectDecl->set_type( new_type );
     167                // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that class-variable
     168                // initContext is changed multiple time because the LHS is analysed twice. The second analysis changes
     169                // initContext because of a function type can contain object declarations in the return and parameter types. So
     170                // each value of initContext is retained, so the type on the first analysis is preserved and used for selecting
     171                // the RHS.
     172                Type *temp = initContext;
    169173                initContext = new_type;
    170174                SymTab::Indexer::visit( objectDecl );
     175                initContext = temp;
    171176        }
    172177
     
    253258                        forStmt->set_condition( newExpr );
    254259                } // if
    255 
     260               
    256261                if ( forStmt->get_increment() ) {
    257262                        Expression * newExpr = findVoidExpression( forStmt->get_increment(), *this );
     
    267272                delete switchStmt->get_condition();
    268273                switchStmt->set_condition( newExpr );
    269 
     274 
    270275                visitor.Visitor::visit( switchStmt );
    271276        }
     
    309314        bool isCharType( T t ) {
    310315                if ( BasicType * bt = dynamic_cast< BasicType * >( t ) ) {
    311                         return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar ||
     316                        return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 
    312317                                bt->get_kind() == BasicType::UnsignedChar;
    313318                }
     
    321326                                string n = ne->get_name();
    322327                                if (n == "0") {
    323                                         initContext = new BasicType(Type::Qualifiers(),
     328                                        initContext = new BasicType(Type::Qualifiers(), 
    324329                                                                                                BasicType::SignedInt);
    325330                                } else {
     
    327332                                        initContext = decl->get_type();
    328333                                }
    329                         } else if (ConstantExpr * e =
     334                        } else if (ConstantExpr * e = 
    330335                                           dynamic_cast<ConstantExpr*>(singleInit->get_value())) {
    331336                                Constant *c = e->get_constant();
     
    350355                                                        singleInit->set_value( ce->get_arg() );
    351356                                                        ce->set_arg( NULL );
    352                                                         delete ce;
     357                                                        delete ce;                                                                     
    353358                                                }
    354359                                        }
     
    466471#endif
    467472        }
    468 
    469         // ConstructorInit - fall back on C-style initializer
    470         void Resolver::fallbackInit( ConstructorInit * ctorInit ) {
    471                 // could not find valid constructor, or found an intrinsic constructor
    472                 // fall back on C-style initializer
    473                 delete ctorInit->get_ctor();
    474                 ctorInit->set_ctor( NULL );
    475                 maybeAccept( ctorInit->get_init(), *this );
    476         }
    477 
    478         void Resolver::visit( ConstructorInit *ctorInit ) {
    479                 TypeEnvironment env;
    480                 try {
    481                         maybeAccept( ctorInit->get_ctor(), *this );
    482                         maybeAccept( ctorInit->get_dtor(), *this );
    483                 } catch ( SemanticError ) {
    484                         // no alternatives for the constructor initializer - fallback on C-style initializer
    485                         // xxx- not sure if this makes a ton of sense - should maybe never be able to have this situation?
    486                         fallbackInit( ctorInit );
    487                         return;
    488                 }
    489 
    490                 if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * > ( ctorInit->get_ctor() ) ) {
    491                         ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( exprStmt->get_expr() );
    492                         assert( appExpr );
    493                         VariableExpr * function = dynamic_cast< VariableExpr * > ( appExpr->get_function() );
    494                         assert( function );
    495                         if ( LinkageSpec::isOverridable( function->get_var()->get_linkage() ) ) {
    496                                 // if the constructor that was found is intrinsic or autogenerated, reset to C-style
    497                                 // initializer so that code generation is easy to handle
    498                                 fallbackInit( ctorInit );
    499                                 return;
    500                         }
    501                 }
    502                 // found a constructor - can get rid of C-style initializer
    503                 delete ctorInit->get_init();
    504                 ctorInit->set_init( NULL );
    505         }
    506473} // namespace ResolvExpr
    507474
Note: See TracChangeset for help on using the changeset viewer.