Changeset a4d188f for src/GenPoly
- Timestamp:
- Mar 19, 2018, 2:13:04 PM (7 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, with_gc
- Children:
- 55c7577
- Parents:
- 453b586
- git-author:
- Rob Schluntz <rschlunt@…> (03/19/18 14:12:48)
- git-committer:
- Rob Schluntz <rschlunt@…> (03/19/18 14:13:04)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Lvalue.cc
r453b586 ra4d188f 279 279 // pointer casts in the right places. 280 280 281 // need to reorganize this so that depth difference is the determining factor in what code is run, rather than whether something is reference type or not. 281 // Note: reference depth difference is the determining factor in what code is run, rather than whether something is 282 // reference type or not, since conversion still needs to occur when both types are references that differ in depth. 282 283 283 284 Type * destType = castExpr->result; … … 303 304 PRINT( std::cerr << "made temp: " << temp << std::endl; ) 304 305 stmtsToAddBefore.push_back( new DeclStmt( temp ) ); 305 for ( int i = 0; i < depth1-1; i++ ) { 306 for ( int i = 0; i < depth1-1; i++ ) { // xxx - maybe this should be diff-1? check how this works with reference type for srcType 306 307 ObjectDecl * newTemp = ObjectDecl::newObject( tempNamer.newName(), new ReferenceType( Type::Qualifiers(), temp->type->clone() ), new SingleInit( new AddressExpr( new VariableExpr( temp ) ) ) ); 307 308 PRINT( std::cerr << "made temp" << i << ": " << newTemp << std::endl; ) … … 318 319 } 319 320 321 // handle conversion between different depths 320 322 PRINT ( 321 323 if ( depth1 || depth2 ) { … … 369 371 return castExpr; 370 372 } 371 372 // // conversion to reference type373 // if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( castExpr->result ) ) {374 // (void)refType;375 // if ( ReferenceType * otherRef = dynamic_cast< ReferenceType * >( castExpr->arg->result ) ) {376 // // nothing to do if casting from reference to reference.377 // (void)otherRef;378 // PRINT( std::cerr << "convert reference to reference -- nop" << std::endl; )379 // if ( isIntrinsicReference( castExpr->arg ) ) {380 // Expression * callExpr = castExpr->arg;381 // PRINT(382 // std::cerr << "but arg is deref -- &" << std::endl;383 // std::cerr << callExpr << std::endl;384 // )385 // callExpr = new AddressExpr( callExpr ); // this doesn't work properly for multiple casts386 // delete callExpr->result;387 // callExpr->set_result( refType->clone() );388 // // move environment out to new top-level389 // callExpr->env = castExpr->env;390 // castExpr->arg = nullptr;391 // castExpr->env = nullptr;392 // delete castExpr;393 // return callExpr;394 // }395 // int depth1 = refType->referenceDepth();396 // int depth2 = otherRef->referenceDepth();397 // int diff = depth1-depth2;398 // if ( diff == 0 ) {399 // // conversion between references of the same depth400 // assertf( depth1 == depth2, "non-intrinsic reference with cast of reference to reference not yet supported: %d %d %s", depth1, depth2, toString( castExpr ).c_str() );401 // PRINT( std::cerr << castExpr << std::endl; )402 // return castExpr;403 // } else if ( diff < 0 ) {404 // // conversion from reference to reference with less depth (e.g. int && -> int &): add dereferences405 // Expression * ret = castExpr->arg;406 // for ( int i = 0; i < diff; ++i ) {407 // ret = mkDeref( ret );408 // }409 // ret->env = castExpr->env;410 // delete ret->result;411 // ret->result = castExpr->result;412 // ret->result->set_lvalue( true ); // ensure result is lvalue413 // castExpr->env = nullptr;414 // castExpr->arg = nullptr;415 // castExpr->result = nullptr;416 // delete castExpr;417 // return ret;418 // } else if ( diff > 0 ) {419 // // conversion from reference to reference with more depth (e.g. int & -> int &&): add address-of420 // Expression * ret = castExpr->arg;421 // for ( int i = 0; i < diff; ++i ) {422 // ret = new AddressExpr( ret );423 // }424 // ret->env = castExpr->env;425 // delete ret->result;426 // ret->result = castExpr->result;427 // castExpr->env = nullptr;428 // castExpr->arg = nullptr;429 // castExpr->result = nullptr;430 // delete castExpr;431 // return ret;432 // }433 434 // assertf( depth1 == depth2, "non-intrinsic reference with cast of reference to reference not yet supported: %d %d %s", depth1, depth2, toString( castExpr ).c_str() );435 // PRINT( std::cerr << castExpr << std::endl; )436 // return castExpr;437 // } else if ( castExpr->arg->result->get_lvalue() ) {438 // // conversion from lvalue to reference439 // // xxx - keep cast, but turn into pointer cast??440 // // xxx - memory441 // PRINT(442 // std::cerr << "convert lvalue to reference -- &" << std::endl;443 // std::cerr << castExpr->arg << std::endl;444 // )445 // AddressExpr * ret = new AddressExpr( castExpr->arg );446 // if ( refType->base->get_qualifiers() != castExpr->arg->result->get_qualifiers() ) {447 // // must keep cast if cast-to type is different from the actual type448 // castExpr->arg = ret;449 // return castExpr;450 // }451 // ret->env = castExpr->env;452 // delete ret->result;453 // ret->result = castExpr->result;454 // castExpr->env = nullptr;455 // castExpr->arg = nullptr;456 // castExpr->result = nullptr;457 // delete castExpr;458 // return ret;459 // } else {460 // // rvalue to reference conversion -- introduce temporary461 // // know that reference depth of cast argument is 0, need to introduce n temporaries for reference depth of n, e.g.462 // // (int &&&)3;463 // // becomes464 // // int __ref_tmp_0 = 3;465 // // int & __ref_tmp_1 = _&_ref_tmp_0;466 // // int && __ref_tmp_2 = &__ref_tmp_1;467 // // &__ref_tmp_2;468 469 // static UniqueName tempNamer( "__ref_tmp_" );470 // ObjectDecl * temp = ObjectDecl::newObject( tempNamer.newName(), castExpr->arg->result->clone(), new SingleInit( castExpr->arg ) );471 // stmtsToAddBefore.push_back( new DeclStmt( temp ) );472 // auto depth = castExpr->result->referenceDepth();473 // for ( int i = 0; i < depth-1; i++ ) {474 // ObjectDecl * newTemp = ObjectDecl::newObject( tempNamer.newName(), new ReferenceType( Type::Qualifiers(), temp->type->clone() ), new SingleInit( new AddressExpr( new VariableExpr( temp ) ) ) );475 // stmtsToAddBefore.push_back( new DeclStmt( newTemp ) );476 // temp = newTemp;477 // }478 // Expression * ret = new AddressExpr( new VariableExpr( temp ) );479 // // for ( int i = 0; i < depth; ++i ) {480 // // ret = mkDeref( ret );481 // // }482 // ret->result = castExpr->result;483 // ret->result->set_lvalue( true ); // ensure result is lvalue484 // ret->env = castExpr->env;485 // castExpr->arg = nullptr;486 // castExpr->env = nullptr;487 // castExpr->result = nullptr;488 // delete castExpr;489 // return ret;490 // }491 // } else if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( castExpr->arg->result ) ) {492 // (void)refType;493 // // conversion from reference to rvalue494 // PRINT(495 // std::cerr << "convert reference to rvalue -- *" << std::endl;496 // std::cerr << "was = " << castExpr << std::endl;497 // )498 // Expression * ret = castExpr->arg;499 // TypeSubstitution * env = castExpr->env;500 // castExpr->set_env( nullptr );501 // if ( ! isIntrinsicReference( ret ) ) {502 // // dereference if not already dereferenced503 // ret = mkDeref( ret );504 // }505 // if ( ResolvExpr::typesCompatibleIgnoreQualifiers( castExpr->result, castExpr->arg->result->stripReferences(), SymTab::Indexer() ) ) {506 // // can remove cast if types are compatible, changing expression type to value type507 // ret->result = castExpr->result->clone();508 // ret->result->set_lvalue( true ); // ensure result is lvalue509 // castExpr->arg = nullptr;510 // delete castExpr;511 // } else {512 // // must keep cast if types are different513 // castExpr->arg = ret;514 // ret = castExpr;515 // }516 // ret->set_env( env );517 // PRINT( std::cerr << "now: " << ret << std::endl; )518 // return ret;519 // }520 // return castExpr;521 373 } 522 374
Note: See TracChangeset
for help on using the changeset viewer.