Changeset e6cee92 for src/Tuples
- Timestamp:
- Jul 17, 2017, 3:25:58 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, resolv-new, with_gc
- Children:
- 795d450
- Parents:
- 7ebaa56
- Location:
- src/Tuples
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Tuples/Explode.h
r7ebaa56 re6cee92 27 27 28 28 namespace Tuples { 29 /// helper function used by explode to properly distribute30 /// '&' across a tuple expression31 Expression * distributeAddr( Expression * expr );32 33 29 /// helper function used by explode 34 30 template< typename OutputIterator > 35 31 void explodeUnique( Expression * expr, const ResolvExpr::Alternative & alt, const SymTab::Indexer & indexer, OutputIterator out, bool isTupleAssign ) { 36 if ( isTupleAssign ) {37 // tuple assignment needs AddressExprs to be recursively exploded to easily get at all of the components38 if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( expr ) ) {39 ResolvExpr::AltList alts;40 explodeUnique( addrExpr->get_arg(), alt, indexer, back_inserter( alts ), isTupleAssign );41 for ( ResolvExpr::Alternative & alt : alts ) {42 // distribute '&' over all components43 alt.expr = distributeAddr( alt.expr );44 *out++ = alt;45 }46 // in tuple assignment, still need to handle the other cases, but only if not already handled here (don't want to output too many alternatives)47 return;48 }49 }50 32 Type * res = expr->get_result(); 51 33 if ( TupleType * tupleType = dynamic_cast< TupleType * > ( res ) ) { -
src/Tuples/TupleAssignment.cc
r7ebaa56 re6cee92 77 77 if ( ! expr ) return false; 78 78 assert( expr->has_result() ); 79 return dynamic_cast< TupleType * >( expr->get_result() );79 return dynamic_cast< TupleType * >( expr->get_result()->stripReferences() ); 80 80 } 81 81 … … 89 89 } 90 90 91 bool pointsToTuple( Expression *expr ) { 91 bool refToTuple( Expression *expr ) { 92 assert( expr->get_result() ); 92 93 // also check for function returning tuple of reference types 93 94 if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { 94 return pointsToTuple( castExpr->get_arg() );95 } else if ( AddressExpr *addr = dynamic_cast< AddressExpr * >( expr) ){96 return isTuple( addr->get_arg());95 return refToTuple( castExpr->get_arg() ); 96 } else { 97 return isTuple( expr ); 97 98 } 98 99 return false; … … 122 123 const ResolvExpr::Alternative & alt1 = ali->front(); 123 124 auto begin = std::next(ali->begin(), 1), end = ali->end(); 124 if ( pointsToTuple(alt1.expr) ) {125 if ( refToTuple(alt1.expr) ) { 125 126 if ( isMultAssign( begin, end ) ) { 126 127 matcher.reset( new MultipleAssignMatcher( *this, *ali ) ); … … 196 197 for ( ResolvExpr::Alternative & alt : lhs ) { 197 198 Expression *& expr = alt.expr; 198 Type * castType = expr->get_result()->clone(); 199 Type * type = InitTweak::getPointerBase( castType ); 200 assert( type ); 199 Type * type = expr->get_result()->clone(); 201 200 type->get_qualifiers() -= Type::Qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Atomic ); 202 type->set_lvalue( true ); // xxx - might not need this 203 expr = new CastExpr( expr, castType ); 201 expr = new CastExpr( expr, new ReferenceType( Type::Qualifiers(), type ) ); 204 202 } 205 203 } … … 221 219 assert( left ); 222 220 std::list< Expression * > args; 223 args.push_back( new AddressExpr( UntypedExpr::createDeref( new VariableExpr( left ) )) );221 args.push_back( new VariableExpr( left ) ); 224 222 // args.push_back( new AddressExpr( new VariableExpr( left ) ) ); 225 223 if ( right ) args.push_back( new VariableExpr( right ) ); … … 241 239 assert( expr->has_result() && ! expr->get_result()->isVoid() ); 242 240 ObjectDecl * ret = new ObjectDecl( namer.newName(), Type::StorageClasses(), LinkageSpec::Cforall, nullptr, expr->get_result()->clone(), new SingleInit( expr->clone() ) ); 243 ConstructorInit * ctorInit = InitTweak::genCtorInit( ret ); 244 ret->set_init( ctorInit ); 245 ResolvExpr::resolveCtorInit( ctorInit, spotter.currentFinder.get_indexer() ); // resolve ctor/dtors for the new object 246 EnvRemover rm; // remove environments from subexpressions of StmtExprs 247 ctorInit->accept( rm ); 241 // if expression type is a reference, don't need to construct anything, a simple initializer is sufficient. 242 if ( ! dynamic_cast< ReferenceType * >( expr->get_result() ) ) { 243 ConstructorInit * ctorInit = InitTweak::genCtorInit( ret ); 244 ret->set_init( ctorInit ); 245 ResolvExpr::resolveCtorInit( ctorInit, spotter.currentFinder.get_indexer() ); // resolve ctor/dtors for the new object 246 EnvRemover rm; // remove environments from subexpressions of StmtExprs 247 ctorInit->accept( rm ); 248 } 248 249 return ret; 249 250 }
Note: See TracChangeset
for help on using the changeset viewer.