Changeset c10ee66
- Timestamp:
- May 9, 2017, 1:56:16 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:
- 298581c
- Parents:
- 4f9636f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r4f9636f rc10ee66 765 765 arg = new AddressExpr( arg ); 766 766 } 767 if ( ! ResolvExpr::typesCompatible( param, arg->get_result(), SymTab::Indexer() ) ) { 768 // silence warnings by casting boxed parameters when the actual type does not match up with the formal type. 769 arg = new CastExpr( arg, param->clone() ); 770 } 767 771 } else { 768 772 // use type computed in unification to declare boxed variables … … 902 906 } // if 903 907 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); 904 UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) ); 905 deref->get_args().push_back( new CastExpr( new VariableExpr( *param++ ), new PointerType( Type::Qualifiers(), realType->get_returnVals().front()->get_type()->clone() ) ) ); 908 UntypedExpr *deref = UntypedExpr::createDeref( new CastExpr( new VariableExpr( *param++ ), new PointerType( Type::Qualifiers(), realType->get_returnVals().front()->get_type()->clone() ) ) ); 906 909 assign->get_args().push_back( deref ); 907 910 addAdapterParams( adapteeApp, arg, param, adapterType->get_parameters().end(), realParam, tyVars ); … … 1217 1220 1218 1221 Statement * Pass1::mutate( ReturnStmt *returnStmt ) { 1219 // maybe need access to the env when mutating the expr1220 if ( Expression * expr = returnStmt->get_expr() ) {1221 if ( expr->get_env() ) {1222 env = expr->get_env();1223 }1224 }1225 1226 1222 if ( retval && returnStmt->get_expr() ) { 1227 1223 assert( returnStmt->get_expr()->has_result() && ! returnStmt->get_expr()->get_result()->isVoid() ); … … 1539 1535 Type *declType = objectDecl->get_type(); 1540 1536 std::string bufName = bufNamer.newName(); 1541 ObjectDecl *newBuf = new ObjectDecl( bufName, Type::StorageClasses(), LinkageSpec::C, 0, 1542 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::Kind::Char), new NameExpr( sizeofName( mangleType(declType) ) ), 1537 ObjectDecl *newBuf = new ObjectDecl( bufName, Type::StorageClasses(), LinkageSpec::C, 0, 1538 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::Kind::Char), new NameExpr( sizeofName( mangleType(declType) ) ), 1543 1539 true, false, std::list<Attribute*>{ new Attribute( std::string{"aligned"}, std::list<Expression*>{ new ConstantExpr( Constant::from_int(8) ) } ) } ), 0 ); 1544 1540 stmtsToAdd.push_back( new DeclStmt( noLabels, newBuf ) ); … … 1578 1574 } 1579 1575 1580 /// Returns an expression dereferenced n times1581 Expression *makeDerefdVar( Expression *derefdVar, long n ) {1582 for ( int i = 1; i < n; ++i ) {1583 UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) );1584 derefExpr->get_args().push_back( derefdVar );1585 // xxx - should set results on derefExpr1586 derefdVar = derefExpr;1587 }1588 return derefdVar;1589 }1590 1591 1576 Expression *PolyGenericCalculator::mutate( MemberExpr *memberExpr ) { 1592 1577 // mutate, exiting early if no longer MemberExpr … … 1595 1580 if ( ! memberExpr ) return expr; 1596 1581 1597 // get declaration for base struct, exiting early if not found1598 int varDepth;1599 VariableExpr *varExpr = getBaseVar( memberExpr->get_aggregate(), &varDepth );1600 if ( ! varExpr ) return memberExpr;1601 ObjectDecl *objectDecl = dynamic_cast< ObjectDecl* >( varExpr->get_var() );1602 if ( ! objectDecl ) return memberExpr;1603 1604 1582 // only mutate member expressions for polymorphic types 1605 1583 int tyDepth; 1606 Type *objectType = hasPolyBase( objectDecl->get_type(), scopeTyVars, &tyDepth );1584 Type *objectType = hasPolyBase( memberExpr->get_aggregate()->get_result(), scopeTyVars, &tyDepth ); 1607 1585 if ( ! objectType ) return memberExpr; 1608 1586 findGeneric( objectType ); // ensure layout for this type is available … … 1622 1600 fieldLoc->get_args().push_back( aggr ); 1623 1601 fieldLoc->get_args().push_back( makeOffsetIndex( objectType, i ) ); 1602 fieldLoc->set_result( memberExpr->get_result()->clone() ); 1624 1603 newMemberExpr = fieldLoc; 1625 1604 } else if ( dynamic_cast< UnionInstType* >( objectType ) ) { 1626 // union members are all at offset zero, so build appropriately-dereferenced variable 1627 newMemberExpr = makeDerefdVar( varExpr->clone(), varDepth ); 1605 // union members are all at offset zero, so just use the aggregate expr 1606 Expression * aggr = memberExpr->get_aggregate()->clone(); 1607 delete aggr->get_env(); // xxx - there's a problem with keeping the env for some reason, so for now just get rid of it 1608 aggr->set_env( nullptr ); 1609 newMemberExpr = aggr; 1610 newMemberExpr->set_result( memberExpr->get_result()->clone() ); 1628 1611 } else return memberExpr; 1629 1612 assert( newMemberExpr ); … … 1633 1616 // Not all members of a polymorphic type are themselves of polymorphic type; in this case the member expression should be wrapped and dereferenced to form an lvalue 1634 1617 CastExpr *ptrCastExpr = new CastExpr( newMemberExpr, new PointerType( Type::Qualifiers(), memberType->clone() ) ); 1635 UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) ); 1636 derefExpr->get_args().push_back( ptrCastExpr ); 1618 UntypedExpr *derefExpr = UntypedExpr::createDeref( ptrCastExpr ); 1637 1619 newMemberExpr = derefExpr; 1638 1620 }
Note: See TracChangeset
for help on using the changeset viewer.