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