Changes in src/GenPoly/Box.cc [e16294d:2efe4b8]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
re16294d r2efe4b8 184 184 /// change the type of generic aggregate members to char[] 185 185 void mutateMembers( AggregateDecl * aggrDecl ); 186 /// returns the calculated sizeof expression for ty, or nullptr for use C sizeof()187 Expression* genSizeof( Type* ty );188 186 189 187 /// Enters a new scope for type-variables, adding the type variables from ty … … 281 279 /// Adds parameters for otype layout to a function type 282 280 void addOtypeParams( FunctionType *layoutFnType, std::list< TypeDecl* > &otypeParams ) { 283 BasicType sizeAlignType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 284 285 for ( std::list< TypeDecl* >::const_iterator param = otypeParams.begin(); param != otypeParams.end(); ++param ) { 286 TypeInstType paramType( Type::Qualifiers(), (*param)->get_name(), *param ); 287 std::string paramName = mangleType( ¶mType ); 288 layoutFnType->get_parameters().push_back( new ObjectDecl( sizeofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) ); 289 layoutFnType->get_parameters().push_back( new ObjectDecl( alignofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) ); 281 auto sizeAlignType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 282 283 for ( std::list< TypeDecl* >::const_iterator param = otypeParams.begin(); 284 param != otypeParams.end(); ++param ) { 285 auto paramType = new TypeInstType( Type::Qualifiers(), (*param)->get_name(), *param ); 286 std::string paramName = mangleType( paramType ); 287 layoutFnType->get_parameters().push_back( new ObjectDecl( sizeofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType->clone(), 0 ) ); 288 layoutFnType->get_parameters().push_back( new ObjectDecl( alignofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType->clone(), 0 ) ); 290 289 } 291 290 } … … 384 383 unsigned long n_members = 0; 385 384 bool firstMember = true; 386 for ( Declaration* member : structDecl->get_members()) {387 DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( member );385 for ( std::list< Declaration* >::const_iterator member = structDecl->get_members().begin(); member != structDecl->get_members().end(); ++member ) { 386 DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *member ); 388 387 assert( dwt ); 389 388 Type *memberType = dwt->get_type(); … … 742 741 Type * newType = param->clone(); 743 742 if ( env ) env->apply( newType ); 744 ObjectDecl *newObj = ObjectDecl::newObject( tempNamer.newName(), newType, nullptr ); 743 ObjectDecl *newObj = ObjectDecl::newObject( 744 tempNamer.newName(), newType, nullptr ); 745 745 newObj->get_type()->get_qualifiers() = Type::Qualifiers(); // TODO: is this right??? 746 746 stmtsToAddBefore.push_back( new DeclStmt( newObj ) ); … … 862 862 // do not carry over attributes to real type parameters/return values 863 863 for ( DeclarationWithType * dwt : realType->parameters ) { 864 deleteAll( dwt->get_type()->attributes );865 864 dwt->get_type()->attributes.clear(); 866 865 } 867 866 for ( DeclarationWithType * dwt : realType->returnVals ) { 868 deleteAll( dwt->get_type()->attributes );869 867 dwt->get_type()->attributes.clear(); 870 868 } … … 987 985 } // if 988 986 appExpr->get_args().clear(); 989 delete appExpr;990 987 return addAssign; 991 988 } … … 1018 1015 } // if 1019 1016 if ( baseType1 || baseType2 ) { 1020 delete ret->get_result();1021 1017 ret->set_result( appExpr->get_result()->clone() ); 1022 1018 if ( appExpr->get_env() ) { … … 1025 1021 } // if 1026 1022 appExpr->get_args().clear(); 1027 delete appExpr;1028 1023 return ret; 1029 1024 } // if … … 1035 1030 Expression *ret = appExpr->get_args().front(); 1036 1031 // fix expr type to remove pointer 1037 delete ret->get_result();1038 1032 ret->set_result( appExpr->get_result()->clone() ); 1039 1033 if ( appExpr->get_env() ) { … … 1042 1036 } // if 1043 1037 appExpr->get_args().clear(); 1044 delete appExpr;1045 1038 return ret; 1046 1039 } // if … … 1182 1175 Expression *ret = expr->args.front(); 1183 1176 expr->args.clear(); 1184 delete expr;1185 1177 return ret; 1186 1178 } // if … … 1216 1208 if ( polytype || needs ) { 1217 1209 Expression *ret = addrExpr->arg; 1218 delete ret->result;1219 1210 ret->result = addrExpr->result->clone(); 1220 1211 addrExpr->arg = nullptr; 1221 delete addrExpr;1222 1212 return ret; 1223 1213 } else { … … 1229 1219 if ( retval && returnStmt->expr ) { 1230 1220 assert( returnStmt->expr->result && ! returnStmt->expr->result->isVoid() ); 1231 delete returnStmt->expr;1232 1221 returnStmt->expr = nullptr; 1233 1222 } // if … … 1272 1261 } 1273 1262 } 1274 // deleteAll( functions );1275 1263 } 1276 1264 … … 1292 1280 for ( Declaration * param : functionDecl->type->parameters ) { 1293 1281 if ( ObjectDecl * obj = dynamic_cast< ObjectDecl * >( param ) ) { 1294 delete obj->init;1295 1282 obj->init = nullptr; 1296 1283 } … … 1340 1327 std::list< DeclarationWithType *> inferredParams; 1341 1328 // size/align/offset parameters may not be used in body, pass along with unused attribute. 1342 ObjectDecl newObj( "", Type::StorageClasses(), LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, 1343 { new Attribute( "unused" ) } ); 1344 ObjectDecl newPtr( "", Type::StorageClasses(), LinkageSpec::C, 0, 1345 new PointerType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ), 0 ); 1346 for ( Type::ForallList::const_iterator tyParm = funcType->get_forall().begin(); tyParm != funcType->get_forall().end(); ++tyParm ) { 1329 auto newObj = new ObjectDecl( 1330 "", Type::StorageClasses(), LinkageSpec::C, 0, 1331 new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, 1332 { new Attribute( "unused" ) } ); 1333 auto newPtr = new ObjectDecl( 1334 "", Type::StorageClasses(), LinkageSpec::C, 0, 1335 new PointerType( Type::Qualifiers(), 1336 new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ), 0 ); 1337 for ( Type::ForallList::const_iterator tyParm = funcType->get_forall().begin(); 1338 tyParm != funcType->get_forall().end(); ++tyParm ) { 1347 1339 ObjectDecl *sizeParm, *alignParm; 1348 1340 // add all size and alignment parameters to parameter list 1349 1341 if ( (*tyParm)->isComplete() ) { 1350 TypeInstType parmType( Type::Qualifiers(), (*tyParm)->get_name(), *tyParm ); 1351 std::string parmName = mangleType( &parmType ); 1352 1353 sizeParm = newObj.clone(); 1342 auto parmType = new TypeInstType( 1343 Type::Qualifiers(), (*tyParm)->get_name(), *tyParm ); 1344 std::string parmName = mangleType( parmType ); 1345 1346 sizeParm = newObj->clone(); 1354 1347 sizeParm->set_name( sizeofName( parmName ) ); 1355 1348 last = funcType->get_parameters().insert( last, sizeParm ); 1356 1349 ++last; 1357 1350 1358 alignParm = newObj .clone();1351 alignParm = newObj->clone(); 1359 1352 alignParm->set_name( alignofName( parmName ) ); 1360 1353 last = funcType->get_parameters().insert( last, alignParm ); … … 1379 1372 1380 1373 ObjectDecl *sizeParm, *alignParm, *offsetParm; 1381 sizeParm = newObj .clone();1374 sizeParm = newObj->clone(); 1382 1375 sizeParm->set_name( sizeofName( typeName ) ); 1383 1376 last = funcType->get_parameters().insert( last, sizeParm ); 1384 1377 ++last; 1385 1378 1386 alignParm = newObj .clone();1379 alignParm = newObj->clone(); 1387 1380 alignParm->set_name( alignofName( typeName ) ); 1388 1381 last = funcType->get_parameters().insert( last, alignParm ); … … 1392 1385 // NOTE zero-length arrays are illegal in C, so empty structs have no offset array 1393 1386 if ( ! polyBaseStruct->get_baseStruct()->get_members().empty() ) { 1394 offsetParm = newPtr .clone();1387 offsetParm = newPtr->clone(); 1395 1388 offsetParm->set_name( offsetofName( typeName ) ); 1396 1389 last = funcType->get_parameters().insert( last, offsetParm ); … … 1443 1436 if ( Type * base = typeDecl->base ) { 1444 1437 // add size/align variables for opaque type declarations 1445 TypeInstType inst( Type::Qualifiers(), typeDecl->name, typeDecl );1446 std::string typeName = mangleType( &inst );1438 auto inst = new TypeInstType( Type::Qualifiers(), typeDecl->name, typeDecl ); 1439 std::string typeName = mangleType( inst ); 1447 1440 Type *layoutType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 1448 1441 … … 1501 1494 // polymorphic aggregate members should be converted into monomorphic members. 1502 1495 // Using char[size_T] here respects the expected sizing rules of an aggregate type. 1503 Type * newType = polyToMonoType( field->type ); 1504 delete field->type; 1505 field->type = newType; 1496 field->type = polyToMonoType( field->type ); 1506 1497 } 1507 1498 } … … 1526 1517 stmtsToAddBefore.push_back( new DeclStmt( newBuf ) ); 1527 1518 1528 delete objectDecl->get_init();1529 1519 objectDecl->set_init( new SingleInit( new VariableExpr( newBuf ) ) ); 1530 1520 } … … 1605 1595 } 1606 1596 1607 delete memberType;1608 delete memberExpr;1609 1597 return newMemberExpr; 1610 1598 } … … 1626 1614 addrExpr->arg = nullptr; 1627 1615 std::swap( addrExpr->env, ret->env ); 1628 delete addrExpr;1629 1616 return ret; 1630 1617 } … … 1635 1622 1636 1623 ObjectDecl *PolyGenericCalculator::makeVar( const std::string &name, Type *type, Initializer *init ) { 1637 ObjectDecl *newObj = new ObjectDecl( name, Type::StorageClasses(), LinkageSpec::C, nullptr, type, init ); 1624 ObjectDecl *newObj = new ObjectDecl( 1625 name, Type::StorageClasses(), LinkageSpec::C, nullptr, type, init ); 1638 1626 stmtsToAddBefore.push_back( new DeclStmt( newObj ) ); 1639 1627 return newObj; … … 1749 1737 } 1750 1738 1751 Expression * PolyGenericCalculator::genSizeof( Type* ty ) { 1752 if ( ArrayType * aty = dynamic_cast<ArrayType *>(ty) ) { 1753 // generate calculated size for possibly generic array 1754 Expression * sizeofBase = genSizeof( aty->get_base() ); 1755 if ( ! sizeofBase ) return nullptr; 1756 Expression * dim = aty->get_dimension(); 1757 aty->set_dimension( nullptr ); 1758 return makeOp( "?*?", sizeofBase, dim ); 1759 } else if ( findGeneric( ty ) ) { 1760 // generate calculated size for generic type 1739 Expression *PolyGenericCalculator::postmutate( SizeofExpr *sizeofExpr ) { 1740 Type *ty = sizeofExpr->get_isType() ? sizeofExpr->get_type() : sizeofExpr->get_expr()->get_result(); 1741 if ( findGeneric( ty ) ) { 1761 1742 return new NameExpr( sizeofName( mangleType( ty ) ) ); 1762 } else return nullptr; 1763 } 1764 1765 Expression *PolyGenericCalculator::postmutate( SizeofExpr *sizeofExpr ) { 1766 Type *ty = sizeofExpr->get_isType() ? 1767 sizeofExpr->get_type() : sizeofExpr->get_expr()->get_result(); 1768 1769 Expression * gen = genSizeof( ty ); 1770 if ( gen ) { 1771 delete sizeofExpr; 1772 return gen; 1773 } else return sizeofExpr; 1743 } 1744 return sizeofExpr; 1774 1745 } 1775 1746 … … 1777 1748 Type *ty = alignofExpr->get_isType() ? alignofExpr->get_type() : alignofExpr->get_expr()->get_result(); 1778 1749 if ( findGeneric( ty ) ) { 1779 Expression *ret = new NameExpr( alignofName( mangleType( ty ) ) ); 1780 delete alignofExpr; 1781 return ret; 1750 return new NameExpr( alignofName( mangleType( ty ) ) ); 1782 1751 } 1783 1752 return alignofExpr; … … 1794 1763 if ( i == -1 ) return offsetofExpr; 1795 1764 1796 Expression *offsetInd = makeOffsetIndex( ty, i ); 1797 delete offsetofExpr; 1798 return offsetInd; 1765 return makeOffsetIndex( ty, i ); 1799 1766 } else if ( dynamic_cast< UnionInstType* >( ty ) ) { 1800 1767 // all union members are at offset zero 1801 delete offsetofExpr;1802 1768 return new ConstantExpr( Constant::from_ulong( 0 ) ); 1803 1769 } else return offsetofExpr; … … 1839 1805 } 1840 1806 1841 delete offsetPackExpr;1842 1807 return ret; 1843 1808 }
Note: See TracChangeset
for help on using the changeset viewer.