Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Resolver.cc

    r21ae786 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 : Tue Apr 26 16:08:21 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 );
     61
    6362                std::list< Type * > functionReturn;
    6463                Type *initContext;
     
    8382        }
    8483
    85 
    8684        namespace {
    8785                void finishExpr( Expression *expr, const TypeEnvironment &env ) {
     
    8987                        env.makeSubstitution( *expr->get_env() );
    9088                }
    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 {
     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 
    10298                Expression *findSingleExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
    10399                        TypeEnvironment env;
     
    130126                        } // if
    131127                }
    132 
     128 
    133129                Expression *findIntegralExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
    134130                        TypeEnvironment env;
     
    163159                        return newExpr;
    164160                }
    165 
    166         }
    167 
     161 
     162        }
     163 
    168164        void Resolver::visit( ObjectDecl *objectDecl ) {
    169165                Type *new_type = resolveTypeof( objectDecl->get_type(), *this );
     
    262258                        forStmt->set_condition( newExpr );
    263259                } // if
    264 
     260               
    265261                if ( forStmt->get_increment() ) {
    266262                        Expression * newExpr = findVoidExpression( forStmt->get_increment(), *this );
     
    276272                delete switchStmt->get_condition();
    277273                switchStmt->set_condition( newExpr );
    278 
     274 
    279275                visitor.Visitor::visit( switchStmt );
    280276        }
     
    318314        bool isCharType( T t ) {
    319315                if ( BasicType * bt = dynamic_cast< BasicType * >( t ) ) {
    320                         return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar ||
     316                        return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 
    321317                                bt->get_kind() == BasicType::UnsignedChar;
    322318                }
     
    330326                                string n = ne->get_name();
    331327                                if (n == "0") {
    332                                         initContext = new BasicType(Type::Qualifiers(),
     328                                        initContext = new BasicType(Type::Qualifiers(), 
    333329                                                                                                BasicType::SignedInt);
    334330                                } else {
     
    336332                                        initContext = decl->get_type();
    337333                                }
    338                         } else if (ConstantExpr * e =
     334                        } else if (ConstantExpr * e = 
    339335                                           dynamic_cast<ConstantExpr*>(singleInit->get_value())) {
    340336                                Constant *c = e->get_constant();
     
    359355                                                        singleInit->set_value( ce->get_arg() );
    360356                                                        ce->set_arg( NULL );
    361                                                         delete ce;
     357                                                        delete ce;                                                                     
    362358                                                }
    363359                                        }
     
    475471#endif
    476472        }
    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                 // found a constructor - can get rid of C-style initializer
    499                 delete ctorInit->get_init();
    500                 ctorInit->set_init( NULL );
    501         }
    502473} // namespace ResolvExpr
    503474
Note: See TracChangeset for help on using the changeset viewer.