Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Resolver.cc

    rec79847 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 : Mon May 09 12:10:19 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
     
    2525#include "SymTab/Indexer.h"
    2626#include "Common/utility.h"
    27 #include "InitTweak/FixInit.h"
    2827
    2928#include <iostream>
     
    3433          public:
    3534                Resolver() : SymTab::Indexer( false ), switchType( 0 ) {}
    36 
     35 
    3736                virtual void visit( FunctionDecl *functionDecl );
    3837                virtual void visit( ObjectDecl *functionDecl );
     
    5554                virtual void visit( SingleInit *singleInit );
    5655                virtual void visit( ListInit *listInit );
    57                 virtual void visit( ConstructorInit *ctorInit );
    5856          private:
    5957        typedef std::list< Initializer * >::iterator InitIterator;
     
    6159          void resolveAggrInit( AggregateDecl *, InitIterator &, InitIterator & );
    6260          void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator & );
    63           void fallbackInit( ConstructorInit * ctorInit );
     61
    6462                std::list< Type * > functionReturn;
    6563                Type *initContext;
     
    8482        }
    8583
    86 
    8784        namespace {
    8885                void finishExpr( Expression *expr, const TypeEnvironment &env ) {
     
    9087                        env.makeSubstitution( *expr->get_env() );
    9188                }
    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 {
     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 
    10398                Expression *findSingleExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
    10499                        TypeEnvironment env;
     
    131126                        } // if
    132127                }
    133 
     128 
    134129                Expression *findIntegralExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
    135130                        TypeEnvironment env;
     
    164159                        return newExpr;
    165160                }
    166 
    167         }
    168 
     161 
     162        }
     163 
    169164        void Resolver::visit( ObjectDecl *objectDecl ) {
    170165                Type *new_type = resolveTypeof( objectDecl->get_type(), *this );
     
    263258                        forStmt->set_condition( newExpr );
    264259                } // if
    265 
     260               
    266261                if ( forStmt->get_increment() ) {
    267262                        Expression * newExpr = findVoidExpression( forStmt->get_increment(), *this );
     
    277272                delete switchStmt->get_condition();
    278273                switchStmt->set_condition( newExpr );
    279 
     274 
    280275                visitor.Visitor::visit( switchStmt );
    281276        }
     
    319314        bool isCharType( T t ) {
    320315                if ( BasicType * bt = dynamic_cast< BasicType * >( t ) ) {
    321                         return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar ||
     316                        return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 
    322317                                bt->get_kind() == BasicType::UnsignedChar;
    323318                }
     
    331326                                string n = ne->get_name();
    332327                                if (n == "0") {
    333                                         initContext = new BasicType(Type::Qualifiers(),
     328                                        initContext = new BasicType(Type::Qualifiers(), 
    334329                                                                                                BasicType::SignedInt);
    335330                                } else {
     
    337332                                        initContext = decl->get_type();
    338333                                }
    339                         } else if (ConstantExpr * e =
     334                        } else if (ConstantExpr * e = 
    340335                                           dynamic_cast<ConstantExpr*>(singleInit->get_value())) {
    341336                                Constant *c = e->get_constant();
     
    360355                                                        singleInit->set_value( ce->get_arg() );
    361356                                                        ce->set_arg( NULL );
    362                                                         delete ce;
     357                                                        delete ce;                                                                     
    363358                                                }
    364359                                        }
     
    476471#endif
    477472        }
    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         }
    515473} // namespace ResolvExpr
    516474
Note: See TracChangeset for help on using the changeset viewer.