Changeset 71f4e4f for src/ResolvExpr


Ignore:
Timestamp:
Jan 13, 2016, 5:19:47 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
f1e012b
Parents:
02c7d04
Message:

added ConstructorInit?, simple constructors and destructors work correctly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Resolver.cc

    r02c7d04 r71f4e4f  
    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 : Fri Jul 24 17:33:54 2015
    13 // Update Count     : 178
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Jan 13 16:23:51 2016
     13// Update Count     : 186
    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;
     
    9596                        return newExpr;
    9697                }
    97  
     98
    9899                Expression *findSingleExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
    99100                        TypeEnvironment env;
     
    126127                        } // if
    127128                }
    128  
     129
    129130                Expression *findIntegralExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
    130131                        TypeEnvironment env;
     
    159160                        return newExpr;
    160161                }
    161  
    162         }
    163  
     162
     163        }
     164
    164165        void Resolver::visit( ObjectDecl *objectDecl ) {
    165166                Type *new_type = resolveTypeof( objectDecl->get_type(), *this );
     
    251252                        forStmt->set_condition( newExpr );
    252253                } // if
    253                
     254
    254255                if ( forStmt->get_increment() ) {
    255256                        Expression * newExpr = findVoidExpression( forStmt->get_increment(), *this );
     
    265266                delete switchStmt->get_condition();
    266267                switchStmt->set_condition( newExpr );
    267  
     268
    268269                visitor.Visitor::visit( switchStmt );
    269270        }
     
    307308        bool isCharType( T t ) {
    308309                if ( BasicType * bt = dynamic_cast< BasicType * >( t ) ) {
    309                         return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 
     310                        return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar ||
    310311                                bt->get_kind() == BasicType::UnsignedChar;
    311312                }
     
    319320                                string n = ne->get_name();
    320321                                if (n == "0") {
    321                                         initContext = new BasicType(Type::Qualifiers(), 
     322                                        initContext = new BasicType(Type::Qualifiers(),
    322323                                                                                                BasicType::SignedInt);
    323324                                } else {
     
    325326                                        initContext = decl->get_type();
    326327                                }
    327                         } else if (ConstantExpr * e = 
     328                        } else if (ConstantExpr * e =
    328329                                           dynamic_cast<ConstantExpr*>(singleInit->get_value())) {
    329330                                Constant *c = e->get_constant();
     
    349350                                                        singleInit->set_value( ce->get_arg() );
    350351                                                        ce->set_arg( NULL );
    351                                                         delete ce;                                                                     
     352                                                        delete ce;
    352353                                                }
    353354                                        }
     
    465466#endif
    466467        }
     468
     469        void Resolver::visit( ConstructorInit *ctorInit ) {
     470                TypeEnvironment env;
     471                AlternativeFinder finder( *this, env );
     472                finder.find( ctorInit->get_ctor() );
     473                if ( finder.get_alternatives().size() == 0 ) {
     474                        // could not find valid constructor
     475                        delete ctorInit->get_ctor();
     476                        ctorInit->set_ctor( NULL );
     477
     478                        maybeAccept( ctorInit->get_init(), *this );
     479                } else if ( finder.get_alternatives().size() == 1 ) {
     480                        // found a constructor - can get rid of C-style initializer
     481                        Alternative &choice = finder.get_alternatives().front();
     482                        Expression *newExpr = choice.expr->clone();
     483                        finishExpr( newExpr, choice.env );
     484                        ctorInit->set_ctor( newExpr );
     485                        delete ctorInit->get_init();
     486                        ctorInit->set_init( NULL );
     487                } else {
     488                        // too many constructors found
     489                        assert(false);
     490                }
     491        }
    467492} // namespace ResolvExpr
    468493
Note: See TracChangeset for help on using the changeset viewer.