Changeset 845cedc for src/InitTweak/FixInit.cc
- Timestamp:
- Apr 25, 2016, 2:49:55 PM (9 years ago)
- 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:
- add371c
- Parents:
- 67b1180
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
r67b1180 r845cedc 10 10 // Created On : Wed Jan 13 16:29:30 2016 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Apr 14 17:29:21 201612 // Last Modified On : Mon Apr 25 14:44:21 2016 13 13 // Update Count : 30 14 14 // … … 18 18 #include "RemoveInit.h" 19 19 #include "ResolvExpr/Resolver.h" 20 #include "ResolvExpr/typeops.h" 20 21 #include "SynTree/Declaration.h" 21 22 #include "SynTree/Type.h" … … 27 28 #include "GenPoly/PolyMutator.h" 28 29 30 bool ctordtorp = false; 31 #define PRINT( text ) if ( ctordtorp ) { text } 32 29 33 namespace InitTweak { 30 34 namespace { … … 115 119 116 120 Expression * InsertImplicitCalls::mutate( ApplicationExpr * appExpr ) { 121 appExpr = dynamic_cast< ApplicationExpr * >( Mutator::mutate( appExpr ) ); 122 assert( appExpr ); 123 117 124 if ( VariableExpr * function = dynamic_cast< VariableExpr * > ( appExpr->get_function() ) ) { 118 125 if ( function->get_var()->get_linkage() == LinkageSpec::Intrinsic ) { 119 126 // optimization: don't need to copy construct in order to call intrinsic functions 120 127 return appExpr; 121 } else if ( FunctionDecl * func = dynamic_cast< FunctionDecl * > ( function->get_var() ) ) { 122 // if ( ) 123 // // optimization: don't need to copy construct in order to call a copy constructor 124 // return appExpr; 128 } else if ( FunctionDecl * funcDecl = dynamic_cast< FunctionDecl * > ( function->get_var() ) ) { 129 FunctionType * ftype = funcDecl->get_functionType(); 130 if ( (funcDecl->get_name() == "?{}" || funcDecl->get_name() == "?=?") && ftype->get_parameters().size() == 2 ) { 131 Type * t1 = ftype->get_parameters().front()->get_type(); 132 Type * t2 = ftype->get_parameters().back()->get_type(); 133 PointerType * ptrType = dynamic_cast< PointerType * > ( t1 ); 134 assert( ptrType ); 135 if ( ResolvExpr::typesCompatible( ptrType->get_base(), t2, SymTab::Indexer() ) ) { 136 // optimization: don't need to copy construct in order to call a copy constructor or 137 // assignment operator 138 return appExpr; 139 } 140 } else if ( funcDecl->get_name() == "^?{}" ) { 141 // correctness: never copy construct arguments to a destructor 142 return appExpr; 143 } 125 144 } 126 145 } 146 PRINT( std::cerr << "InsertImplicitCalls: adding a wrapper " << appExpr << std::endl; ) 147 127 148 // wrap each function call so that it is easy to identify nodes that have to be copy constructed 128 appExpr = dynamic_cast< ApplicationExpr * >( Mutator::mutate( appExpr ) );129 assert( appExpr );130 149 return new ImplicitCopyCtorExpr( appExpr ); 131 150 } … … 140 159 // should only be one alternative for copy ctor and dtor expressions, since 141 160 // all arguments are fixed (VariableExpr and already resolved expression) 161 PRINT( std::cerr << "ResolvingCtorDtor " << untyped << std::endl; ) 142 162 ApplicationExpr * resolved = dynamic_cast< ApplicationExpr * >( ResolvExpr::findVoidExpression( untyped, *this ) ); 143 163 … … 151 171 static UniqueName retNamer("_tmp_cp_ret"); 152 172 153 // resolve function call 154 ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( ResolvExpr::findVoidExpression( impCpCtorExpr->get_callExpr(), *this ) ); 155 assert( appExpr ); 156 delete impCpCtorExpr->get_callExpr(); 157 impCpCtorExpr->set_callExpr( appExpr ); 158 159 // Visitor::visit( impCpCtorExpr ); 173 PRINT( std::cerr << "ResolveCopyCtors: " << impCpCtorExpr << std::endl; ) 174 Visitor::visit( impCpCtorExpr ); 175 176 ApplicationExpr * appExpr = impCpCtorExpr->get_callExpr(); 160 177 161 178 // take each argument and attempt to copy construct it. … … 167 184 168 185 // create and resolve copy constructor 186 PRINT( std::cerr << "makeCtorDtor for an argument" << std::endl; ) 169 187 ApplicationExpr * cpCtor = makeCtorDtor( "?{}", tmp, arg ); 170 188 … … 186 204 // later 187 205 // xxx - handle multiple return values 206 ApplicationExpr * callExpr = impCpCtorExpr->get_callExpr(); 188 207 for ( Type * result : appExpr->get_results() ) { 189 ObjectDecl * ret = new ObjectDecl( retNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, result->clone(), new SingleInit( impCpCtorExpr->get_callExpr()) );208 ObjectDecl * ret = new ObjectDecl( retNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, result->clone(), new SingleInit( callExpr ) ); 190 209 ret->get_type()->set_isConst( false ); 191 210 impCpCtorExpr->get_returnDecls().push_back( ret ); 211 PRINT( std::cerr << "makeCtorDtor for a return" << std::endl; ) 192 212 impCpCtorExpr->get_dtors().push_front( makeCtorDtor( "^?{}", ret ) ); 193 213 } 214 PRINT( std::cerr << "after Resolving: " << impCpCtorExpr << std::endl; ) 194 215 } 195 216 196 217 197 218 Expression * FixCopyCtors::mutate( ImplicitCopyCtorExpr * impCpCtorExpr ) { 219 PRINT( std::cerr << "FixCopyCtors: " << impCpCtorExpr << std::endl; ) 220 221 // assert( impCpCtorExpr->get_callExpr()->get_env() ); 198 222 impCpCtorExpr = dynamic_cast< ImplicitCopyCtorExpr * >( Mutator::mutate( impCpCtorExpr ) ); 199 223 assert( impCpCtorExpr ); … … 219 243 // xxx - update to work with multiple return values 220 244 ObjectDecl * returnDecl = returnDecls.empty() ? NULL : returnDecls.front(); 245 Expression * callExpr = impCpCtorExpr->get_callExpr(); 246 247 PRINT( std::cerr << "Coming out the back..." << impCpCtorExpr << std::endl; ) 221 248 222 249 // xxx - some of these aren't necessary, and can be removed once this is stable … … 225 252 tempDecls.clear(); 226 253 returnDecls.clear(); 254 impCpCtorExpr->set_callExpr( NULL ); 255 delete impCpCtorExpr; 227 256 228 257 if ( returnDecl ) { … … 232 261 } else { 233 262 // add call expression - if no return values, can call directly 234 return impCpCtorExpr->get_callExpr(); 263 assert( callExpr ); 264 return callExpr; 235 265 } 236 266 }
Note: See TracChangeset
for help on using the changeset viewer.