Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Resolver.cc

    r3cfe27f rec79847  
    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 : Mon May 09 12:10:19 2016
     13// Update Count     : 203
    1414//
    1515
     
    2525#include "SymTab/Indexer.h"
    2626#include "Common/utility.h"
     27#include "InitTweak/FixInit.h"
    2728
    2829#include <iostream>
     
    3334          public:
    3435                Resolver() : SymTab::Indexer( false ), switchType( 0 ) {}
    35  
     36
    3637                virtual void visit( FunctionDecl *functionDecl );
    3738                virtual void visit( ObjectDecl *functionDecl );
     
    5455                virtual void visit( SingleInit *singleInit );
    5556                virtual void visit( ListInit *listInit );
     57                virtual void visit( ConstructorInit *ctorInit );
    5658          private:
    5759        typedef std::list< Initializer * >::iterator InitIterator;
     
    5961          void resolveAggrInit( AggregateDecl *, InitIterator &, InitIterator & );
    6062          void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator & );
    61 
     63          void fallbackInit( ConstructorInit * ctorInit );
    6264                std::list< Type * > functionReturn;
    6365                Type *initContext;
     
    8284        }
    8385
     86
    8487        namespace {
    8588                void finishExpr( Expression *expr, const TypeEnvironment &env ) {
     
    8790                        env.makeSubstitution( *expr->get_env() );
    8891                }
    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  
     92        } // namespace
     93
     94        Expression *findVoidExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
     95                global_renamer.reset();
     96                TypeEnvironment env;
     97                Expression *newExpr = resolveInVoidContext( untyped, indexer, env );
     98                finishExpr( newExpr, env );
     99                return newExpr;
     100        }
     101
     102        namespace {
    98103                Expression *findSingleExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
    99104                        TypeEnvironment env;
     
    126131                        } // if
    127132                }
    128  
     133
    129134                Expression *findIntegralExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
    130135                        TypeEnvironment env;
     
    159164                        return newExpr;
    160165                }
    161  
    162         }
    163  
     166
     167        }
     168
    164169        void Resolver::visit( ObjectDecl *objectDecl ) {
    165170                Type *new_type = resolveTypeof( objectDecl->get_type(), *this );
     
    258263                        forStmt->set_condition( newExpr );
    259264                } // if
    260                
     265
    261266                if ( forStmt->get_increment() ) {
    262267                        Expression * newExpr = findVoidExpression( forStmt->get_increment(), *this );
     
    272277                delete switchStmt->get_condition();
    273278                switchStmt->set_condition( newExpr );
    274  
     279
    275280                visitor.Visitor::visit( switchStmt );
    276281        }
     
    314319        bool isCharType( T t ) {
    315320                if ( BasicType * bt = dynamic_cast< BasicType * >( t ) ) {
    316                         return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 
     321                        return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar ||
    317322                                bt->get_kind() == BasicType::UnsignedChar;
    318323                }
     
    326331                                string n = ne->get_name();
    327332                                if (n == "0") {
    328                                         initContext = new BasicType(Type::Qualifiers(), 
     333                                        initContext = new BasicType(Type::Qualifiers(),
    329334                                                                                                BasicType::SignedInt);
    330335                                } else {
     
    332337                                        initContext = decl->get_type();
    333338                                }
    334                         } else if (ConstantExpr * e = 
     339                        } else if (ConstantExpr * e =
    335340                                           dynamic_cast<ConstantExpr*>(singleInit->get_value())) {
    336341                                Constant *c = e->get_constant();
     
    355360                                                        singleInit->set_value( ce->get_arg() );
    356361                                                        ce->set_arg( NULL );
    357                                                         delete ce;                                                                     
     362                                                        delete ce;
    358363                                                }
    359364                                        }
     
    471476#endif
    472477        }
     478
     479        // ConstructorInit - fall back on C-style initializer
     480        void Resolver::fallbackInit( ConstructorInit * ctorInit ) {
     481                // could not find valid constructor, or found an intrinsic constructor
     482                // fall back on C-style initializer
     483                delete ctorInit->get_ctor();
     484                ctorInit->set_ctor( NULL );
     485                maybeAccept( ctorInit->get_init(), *this );
     486        }
     487
     488        void Resolver::visit( ConstructorInit *ctorInit ) {
     489                try {
     490                        maybeAccept( ctorInit->get_ctor(), *this );
     491                        maybeAccept( ctorInit->get_dtor(), *this );
     492                } catch ( SemanticError ) {
     493                        // no alternatives for the constructor initializer - fallback on C-style initializer
     494                        // xxx- not sure if this makes a ton of sense - should maybe never be able to have this situation?
     495                        fallbackInit( ctorInit );
     496                        return;
     497                }
     498
     499                // found a constructor - can get rid of C-style initializer
     500                delete ctorInit->get_init();
     501                ctorInit->set_init( NULL );
     502
     503                // intrinsic single parameter constructors and destructors do nothing. Since this was
     504                // implicitly generated, there's no way for it to have side effects, so get rid of it
     505                // to clean up generated code.
     506                if ( InitTweak::isInstrinsicSingleArgCallStmt( ctorInit->get_ctor() ) ) {
     507                        delete ctorInit->get_ctor();
     508                        ctorInit->set_ctor( NULL );
     509                }
     510                if ( InitTweak::isInstrinsicSingleArgCallStmt( ctorInit->get_ctor() ) ) {
     511                        delete ctorInit->get_dtor();
     512                        ctorInit->set_dtor( NULL );
     513                }
     514        }
    473515} // namespace ResolvExpr
    474516
Note: See TracChangeset for help on using the changeset viewer.