Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Resolver.cc

    r52f85e0 ra9a259c  
    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 : Peter A. Buhr
    12 // Last Modified On : Tue Feb  9 21:57:52 2016
    13 // Update Count     : 179
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Thu Jan 14 16:45:32 2016
     13// Update Count     : 203
    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 );
    5657          private:
    5758        typedef std::list< Initializer * >::iterator InitIterator;
     
    5960          void resolveAggrInit( AggregateDecl *, InitIterator &, InitIterator & );
    6061          void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator & );
     62          void fallbackInit( ConstructorInit * ctorInit );
    6163
    6264                std::list< Type * > functionReturn;
     
    9597                        return newExpr;
    9698                }
    97  
     99
    98100                Expression *findSingleExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
    99101                        TypeEnvironment env;
     
    126128                        } // if
    127129                }
    128  
     130
    129131                Expression *findIntegralExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
    130132                        TypeEnvironment env;
     
    159161                        return newExpr;
    160162                }
    161  
    162         }
    163  
     163
     164        }
     165
    164166        void Resolver::visit( ObjectDecl *objectDecl ) {
    165167                Type *new_type = resolveTypeof( objectDecl->get_type(), *this );
     
    251253                        forStmt->set_condition( newExpr );
    252254                } // if
    253                
     255
    254256                if ( forStmt->get_increment() ) {
    255257                        Expression * newExpr = findVoidExpression( forStmt->get_increment(), *this );
     
    265267                delete switchStmt->get_condition();
    266268                switchStmt->set_condition( newExpr );
    267  
     269
    268270                visitor.Visitor::visit( switchStmt );
    269271        }
     
    307309        bool isCharType( T t ) {
    308310                if ( BasicType * bt = dynamic_cast< BasicType * >( t ) ) {
    309                         return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 
     311                        return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar ||
    310312                                bt->get_kind() == BasicType::UnsignedChar;
    311313                }
     
    319321                                string n = ne->get_name();
    320322                                if (n == "0") {
    321                                         initContext = new BasicType(Type::Qualifiers(), 
     323                                        initContext = new BasicType(Type::Qualifiers(),
    322324                                                                                                BasicType::SignedInt);
    323325                                } else {
     
    325327                                        initContext = decl->get_type();
    326328                                }
    327                         } else if (ConstantExpr * e = 
     329                        } else if (ConstantExpr * e =
    328330                                           dynamic_cast<ConstantExpr*>(singleInit->get_value())) {
    329331                                Constant *c = e->get_constant();
     
    348350                                                        singleInit->set_value( ce->get_arg() );
    349351                                                        ce->set_arg( NULL );
    350                                                         delete ce;                                                                     
     352                                                        delete ce;
    351353                                                }
    352354                                        }
     
    464466#endif
    465467        }
     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                AlternativeFinder finder( *this, env );
     481                finder.find( ctorInit->get_ctor() );
     482
     483                if ( finder.get_alternatives().size() == 0 ) {
     484                        fallbackInit( ctorInit );
     485                } else if ( finder.get_alternatives().size() == 1 ) {
     486                        Alternative &choice = finder.get_alternatives().front();
     487                        if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( choice.expr ) ) {
     488                                if ( VariableExpr * function = dynamic_cast< VariableExpr * > ( appExpr->get_function() ) ) {
     489                                        if ( LinkageSpec::isOverridable( function->get_var()->get_linkage() ) ) {
     490                                                // if the constructor that was found is intrinsic or autogenerated, reset to C-style
     491                                                // initializer so that code generation is easy to handle
     492                                                fallbackInit( ctorInit );
     493                                                return;
     494                                        }
     495                                }
     496                        }
     497                        // found a constructor - can get rid of C-style initializer
     498                        Expression *newExpr = choice.expr->clone();
     499                        finishExpr( newExpr, choice.env );
     500                        ctorInit->set_ctor( newExpr );
     501                        delete ctorInit->get_init();
     502                        ctorInit->set_init( NULL );
     503                } else {
     504                        // too many constructors found
     505                        assert(false);
     506                }
     507        }
    466508} // namespace ResolvExpr
    467509
Note: See TracChangeset for help on using the changeset viewer.