Changeset d5556a3 for src/Tuples
- Timestamp:
- Dec 13, 2016, 5:37:15 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 31f379c
- Parents:
- 1d2b64f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Tuples/TupleExpansion.cc
r1d2b64f rd5556a3 194 194 new CommaExpr( new CommaExpr( assignUnq, assignFinished ), var->clone() ) ); 195 195 condExpr->set_result( var->get_result()->clone() ); 196 condExpr->set_env( maybeClone( unqExpr->get_env() ) ); 196 197 decls[id] = condExpr; 197 198 } … … 202 203 Expression * TupleAssignExpander::mutate( TupleAssignExpr * assnExpr ) { 203 204 assnExpr = safe_dynamic_cast< TupleAssignExpr * >( Parent::mutate( assnExpr ) ); 204 CompoundStmt * compoundStmt = new CompoundStmt( noLabels ); 205 std::list< Statement * > & stmts = compoundStmt->get_kids(); 206 for ( ObjectDecl * obj : assnExpr->get_tempDecls() ) { 207 stmts.push_back( new DeclStmt( noLabels, obj ) ); 208 } 209 TupleExpr * tupleExpr = new TupleExpr( assnExpr->get_assigns() ); 210 assert( tupleExpr->get_result() ); 211 stmts.push_back( new ExprStmt( noLabels, tupleExpr ) ); 212 assnExpr->get_tempDecls().clear(); 213 assnExpr->get_assigns().clear(); 205 StmtExpr * ret = assnExpr->get_stmtExpr(); 206 assnExpr->set_stmtExpr( nullptr ); 207 // move env to StmtExpr 208 ret->set_env( assnExpr->get_env() ); 209 assnExpr->set_env( nullptr ); 214 210 delete assnExpr; 215 return new StmtExpr( compoundStmt );211 return ret; 216 212 } 217 213 … … 221 217 if ( ! typeMap.count( mangleName ) ) { 222 218 // generate struct type to replace tuple type 219 // xxx - should fix this to only generate one tuple struct for each number of type parameters 223 220 StructDecl * decl = new StructDecl( "_tuple_type_" + mangleName ); 224 221 decl->set_body( true ); … … 247 244 tupleExpr->set_tuple( nullptr ); 248 245 unsigned int idx = tupleExpr->get_index(); 246 TypeSubstitution * env = tupleExpr->get_env(); 247 tupleExpr->set_env( nullptr ); 249 248 delete tupleExpr; 250 249 … … 253 252 assert( structDecl->get_members().size() > idx ); 254 253 Declaration * member = *std::next(structDecl->get_members().begin(), idx); 255 return new MemberExpr( safe_dynamic_cast< DeclarationWithType * >( member ), tuple ); 256 } 257 258 Expression * replaceTupleExpr( Type * result, const std::list< Expression * > & exprs ) { 254 MemberExpr * memExpr = new MemberExpr( safe_dynamic_cast< DeclarationWithType * >( member ), tuple ); 255 memExpr->set_env( env ); 256 return memExpr; 257 } 258 259 Expression * replaceTupleExpr( Type * result, const std::list< Expression * > & exprs, TypeSubstitution * env ) { 259 260 if ( result->isVoid() ) { 260 261 // void result - don't need to produce a value for cascading - just output a chain of comma exprs 261 262 assert( ! exprs.empty() ); 262 263 std::list< Expression * >::const_iterator iter = exprs.begin(); 263 Expression * expr = *iter++;264 Expression * expr = new CastExpr( *iter++ ); 264 265 for ( ; iter != exprs.end(); ++iter ) { 265 expr = new CommaExpr( expr, *iter ); 266 } 266 expr = new CommaExpr( expr, new CastExpr( *iter ) ); 267 } 268 expr->set_env( env ); 267 269 return expr; 268 270 } else { … … 274 276 inits.push_back( new SingleInit( expr ) ); 275 277 } 276 return new CompoundLiteralExpr( result, new ListInit( inits ) ); 278 Expression * expr = new CompoundLiteralExpr( result, new ListInit( inits ) ); 279 expr->set_env( env ); 280 return expr; 277 281 } 278 282 } … … 284 288 std::list< Expression * > exprs = tupleExpr->get_exprs(); 285 289 assert( result ); 290 TypeSubstitution * env = tupleExpr->get_env(); 286 291 287 292 // remove data from shell and delete it 288 293 tupleExpr->set_result( nullptr ); 289 294 tupleExpr->get_exprs().clear(); 295 tupleExpr->set_env( nullptr ); 290 296 delete tupleExpr; 291 297 292 return replaceTupleExpr( result, exprs );298 return replaceTupleExpr( result, exprs, env ); 293 299 } 294 300
Note: See TracChangeset
for help on using the changeset viewer.