Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Resolver.cc

    r3cfe27f rdb4ecc5  
    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 : Thu Mar 24 16:43:11 2016
    13 // Update Count     : 181
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Thu Apr 14 11:18:12 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 & );
    61 
     62          void fallbackInit( ConstructorInit * ctorInit );
    6263                std::list< Type * > functionReturn;
    6364                Type *initContext;
     
    8283        }
    8384
     85
    8486        namespace {
    8587                void finishExpr( Expression *expr, const TypeEnvironment &env ) {
     
    8789                        env.makeSubstitution( *expr->get_env() );
    8890                }
    89 
    90                 Expression *findVoidExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
    91                         global_renamer.reset();
    92                         TypeEnvironment env;
    93                         Expression *newExpr = resolveInVoidContext( untyped, indexer, env );
    94                         finishExpr( newExpr, env );
    95                         return newExpr;
    96                 }
    97  
     91        } // namespace
     92
     93        Expression *findVoidExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
     94                global_renamer.reset();
     95                TypeEnvironment env;
     96                Expression *newExpr = resolveInVoidContext( untyped, indexer, env );
     97                finishExpr( newExpr, env );
     98                return newExpr;
     99        }
     100
     101        namespace {
    98102                Expression *findSingleExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
    99103                        TypeEnvironment env;
     
    126130                        } // if
    127131                }
    128  
     132
    129133                Expression *findIntegralExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
    130134                        TypeEnvironment env;
     
    159163                        return newExpr;
    160164                }
    161  
    162         }
    163  
     165
     166        }
     167
    164168        void Resolver::visit( ObjectDecl *objectDecl ) {
    165169                Type *new_type = resolveTypeof( objectDecl->get_type(), *this );
     
    258262                        forStmt->set_condition( newExpr );
    259263                } // if
    260                
     264
    261265                if ( forStmt->get_increment() ) {
    262266                        Expression * newExpr = findVoidExpression( forStmt->get_increment(), *this );
     
    272276                delete switchStmt->get_condition();
    273277                switchStmt->set_condition( newExpr );
    274  
     278
    275279                visitor.Visitor::visit( switchStmt );
    276280        }
     
    314318        bool isCharType( T t ) {
    315319                if ( BasicType * bt = dynamic_cast< BasicType * >( t ) ) {
    316                         return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 
     320                        return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar ||
    317321                                bt->get_kind() == BasicType::UnsignedChar;
    318322                }
     
    326330                                string n = ne->get_name();
    327331                                if (n == "0") {
    328                                         initContext = new BasicType(Type::Qualifiers(), 
     332                                        initContext = new BasicType(Type::Qualifiers(),
    329333                                                                                                BasicType::SignedInt);
    330334                                } else {
     
    332336                                        initContext = decl->get_type();
    333337                                }
    334                         } else if (ConstantExpr * e = 
     338                        } else if (ConstantExpr * e =
    335339                                           dynamic_cast<ConstantExpr*>(singleInit->get_value())) {
    336340                                Constant *c = e->get_constant();
     
    355359                                                        singleInit->set_value( ce->get_arg() );
    356360                                                        ce->set_arg( NULL );
    357                                                         delete ce;                                                                     
     361                                                        delete ce;
    358362                                                }
    359363                                        }
     
    471475#endif
    472476        }
     477
     478        // ConstructorInit - fall back on C-style initializer
     479        void Resolver::fallbackInit( ConstructorInit * ctorInit ) {
     480                // could not find valid constructor, or found an intrinsic constructor
     481                // fall back on C-style initializer
     482                delete ctorInit->get_ctor();
     483                ctorInit->set_ctor( NULL );
     484                maybeAccept( ctorInit->get_init(), *this );
     485        }
     486
     487        void Resolver::visit( ConstructorInit *ctorInit ) {
     488                try {
     489                        maybeAccept( ctorInit->get_ctor(), *this );
     490                        maybeAccept( ctorInit->get_dtor(), *this );
     491                } catch ( SemanticError ) {
     492                        // no alternatives for the constructor initializer - fallback on C-style initializer
     493                        // xxx- not sure if this makes a ton of sense - should maybe never be able to have this situation?
     494                        fallbackInit( ctorInit );
     495                        return;
     496                }
     497
     498                if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * > ( ctorInit->get_ctor() ) ) {
     499                        ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( exprStmt->get_expr() );
     500                        assert( appExpr );
     501                        VariableExpr * function = dynamic_cast< VariableExpr * > ( appExpr->get_function() );
     502                        assert( function );
     503                        if ( LinkageSpec::isOverridable( function->get_var()->get_linkage() ) ) {
     504                                // if the constructor that was found is intrinsic or autogenerated, reset to C-style
     505                                // initializer so that code generation is easy to handle
     506                                fallbackInit( ctorInit );
     507                                return;
     508                        }
     509                }
     510                // found a constructor - can get rid of C-style initializer
     511                delete ctorInit->get_init();
     512                ctorInit->set_init( NULL );
     513        }
    473514} // namespace ResolvExpr
    474515
Note: See TracChangeset for help on using the changeset viewer.