Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/GenInit.cc

    rac9ca967 rdcd73d1  
    2929#include "GenPoly/DeclMutator.h"
    3030#include "GenPoly/ScopedSet.h"
    31 #include "ResolvExpr/typeops.h"
    3231
    3332namespace InitTweak {
     
    5150
    5251          protected:
    53                 FunctionType * ftype;
     52                std::list<DeclarationWithType*> returnVals;
    5453                UniqueName tempNamer;
    5554                std::string funcName;
     
    8786
    8887                bool isManaged( ObjectDecl * objDecl ) const ; // determine if object is managed
    89                 bool isManaged( Type * type ) const; // determine if type is managed
    9088                void handleDWT( DeclarationWithType * dwt ); // add type to managed if ctor/dtor
    9189                GenPoly::ScopedSet< std::string > managedTypes;
     
    136134
    137135        Statement *ReturnFixer::mutate( ReturnStmt *returnStmt ) {
    138                 std::list< DeclarationWithType * > & returnVals = ftype->get_returnVals();
     136                // update for multiple return values
    139137                assert( returnVals.size() == 0 || returnVals.size() == 1 );
    140138                // hands off if the function returns an lvalue - we don't want to allocate a temporary if a variable's address
     
    158156
    159157        DeclarationWithType* ReturnFixer::mutate( FunctionDecl *functionDecl ) {
    160                 // xxx - need to handle named return values - this pass may need to happen
    161                 // after resolution? the ordering is tricky because return statements must be
    162                 // constructed - the simplest way to do that (while also handling multiple
    163                 // returns) is to structure the returnVals into a tuple, as done here.
    164                 // however, if the tuple return value is structured before resolution,
    165                 // it's difficult to resolve named return values, since the name is lost
    166                 // in conversion to a tuple. this might be easiest to deal with
    167                 // after reference types are added, as it may then be possible to
    168                 // uniformly move named return values to the parameter list directly
    169                 ValueGuard< FunctionType * > oldFtype( ftype );
     158                ValueGuard< std::list<DeclarationWithType*> > oldReturnVals( returnVals );
    170159                ValueGuard< std::string > oldFuncName( funcName );
    171160
    172                 ftype = functionDecl->get_functionType();
    173                 std::list< DeclarationWithType * > & retVals = ftype->get_returnVals();
    174                 if ( retVals.size() > 1 ) {
    175                         TupleType * tupleType = safe_dynamic_cast< TupleType * >( ResolvExpr::extractResultType( ftype ) );
    176                         ObjectDecl * newRet = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, tupleType, new ListInit( std::list<Initializer*>(), noDesignators, false ) );
    177                         retVals.clear();
    178                         retVals.push_back( newRet );
    179                 }
     161                FunctionType * type = functionDecl->get_functionType();
     162                returnVals = type->get_returnVals();
    180163                funcName = functionDecl->get_name();
    181164                DeclarationWithType * decl = Mutator::mutate( functionDecl );
     
    237220        }
    238221
    239         bool CtorDtor::isManaged( Type * type ) const {
    240                 if ( TupleType * tupleType = dynamic_cast< TupleType * > ( type ) ) {
    241                         // tuple is also managed if any of its components are managed
    242                         if ( std::any_of( tupleType->get_types().begin(), tupleType->get_types().end(), [&](Type * type) { return isManaged( type ); }) ) {
    243                                 return true;
    244                         }
    245                 }
    246                 return managedTypes.find( SymTab::Mangler::mangle( type ) ) != managedTypes.end();
    247         }
    248 
    249222        bool CtorDtor::isManaged( ObjectDecl * objDecl ) const {
    250223                Type * type = objDecl->get_type();
     
    252225                        type = at->get_base();
    253226                }
    254                 return isManaged( type );
     227                return managedTypes.find( SymTab::Mangler::mangle( type ) ) != managedTypes.end();
    255228        }
    256229
     
    315288                managedTypes.beginScope();
    316289                // go through assertions and recursively add seen ctor/dtors
    317                 for ( auto & tyDecl : functionDecl->get_functionType()->get_forall() ) {
     290                for ( TypeDecl * tyDecl : functionDecl->get_functionType()->get_forall() ) {
    318291                        for ( DeclarationWithType *& assertion : tyDecl->get_assertions() ) {
    319292                                assertion = assertion->acceptMutator( *this );
Note: See TracChangeset for help on using the changeset viewer.