Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    re16294d r2efe4b8  
    184184                        /// change the type of generic aggregate members to char[]
    185185                        void mutateMembers( AggregateDecl * aggrDecl );
    186                         /// returns the calculated sizeof expression for ty, or nullptr for use C sizeof()
    187                         Expression* genSizeof( Type* ty );
    188186
    189187                        /// Enters a new scope for type-variables, adding the type variables from ty
     
    281279        /// Adds parameters for otype layout to a function type
    282280        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( &paramType );
    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 ) );
    290289                }
    291290        }
     
    384383                unsigned long n_members = 0;
    385384                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 );
    388387                        assert( dwt );
    389388                        Type *memberType = dwt->get_type();
     
    742741                                Type * newType = param->clone();
    743742                                if ( env ) env->apply( newType );
    744                                 ObjectDecl *newObj = ObjectDecl::newObject( tempNamer.newName(), newType, nullptr );
     743                                ObjectDecl *newObj = ObjectDecl::newObject(
     744                                        tempNamer.newName(), newType, nullptr );
    745745                                newObj->get_type()->get_qualifiers() = Type::Qualifiers(); // TODO: is this right???
    746746                                stmtsToAddBefore.push_back( new DeclStmt( newObj ) );
     
    862862                        // do not carry over attributes to real type parameters/return values
    863863                        for ( DeclarationWithType * dwt : realType->parameters ) {
    864                                 deleteAll( dwt->get_type()->attributes );
    865864                                dwt->get_type()->attributes.clear();
    866865                        }
    867866                        for ( DeclarationWithType * dwt : realType->returnVals ) {
    868                                 deleteAll( dwt->get_type()->attributes );
    869867                                dwt->get_type()->attributes.clear();
    870868                        }
     
    987985                        } // if
    988986                        appExpr->get_args().clear();
    989                         delete appExpr;
    990987                        return addAssign;
    991988                }
     
    10181015                                                } // if
    10191016                                                if ( baseType1 || baseType2 ) {
    1020                                                         delete ret->get_result();
    10211017                                                        ret->set_result( appExpr->get_result()->clone() );
    10221018                                                        if ( appExpr->get_env() ) {
     
    10251021                                                        } // if
    10261022                                                        appExpr->get_args().clear();
    1027                                                         delete appExpr;
    10281023                                                        return ret;
    10291024                                                } // if
     
    10351030                                                        Expression *ret = appExpr->get_args().front();
    10361031                                                        // fix expr type to remove pointer
    1037                                                         delete ret->get_result();
    10381032                                                        ret->set_result( appExpr->get_result()->clone() );
    10391033                                                        if ( appExpr->get_env() ) {
     
    10421036                                                        } // if
    10431037                                                        appExpr->get_args().clear();
    1044                                                         delete appExpr;
    10451038                                                        return ret;
    10461039                                                } // if
     
    11821175                                                Expression *ret = expr->args.front();
    11831176                                                expr->args.clear();
    1184                                                 delete expr;
    11851177                                                return ret;
    11861178                                        } // if
     
    12161208                        if ( polytype || needs ) {
    12171209                                Expression *ret = addrExpr->arg;
    1218                                 delete ret->result;
    12191210                                ret->result = addrExpr->result->clone();
    12201211                                addrExpr->arg = nullptr;
    1221                                 delete addrExpr;
    12221212                                return ret;
    12231213                        } else {
     
    12291219                        if ( retval && returnStmt->expr ) {
    12301220                                assert( returnStmt->expr->result && ! returnStmt->expr->result->isVoid() );
    1231                                 delete returnStmt->expr;
    12321221                                returnStmt->expr = nullptr;
    12331222                        } // if
     
    12721261                                }
    12731262                        }
    1274 //  deleteAll( functions );
    12751263                }
    12761264
     
    12921280                        for ( Declaration * param : functionDecl->type->parameters ) {
    12931281                                if ( ObjectDecl * obj = dynamic_cast< ObjectDecl * >( param ) ) {
    1294                                         delete obj->init;
    12951282                                        obj->init = nullptr;
    12961283                                }
     
    13401327                        std::list< DeclarationWithType *> inferredParams;
    13411328                        // 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 ) {
    13471339                                ObjectDecl *sizeParm, *alignParm;
    13481340                                // add all size and alignment parameters to parameter list
    13491341                                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();
    13541347                                        sizeParm->set_name( sizeofName( parmName ) );
    13551348                                        last = funcType->get_parameters().insert( last, sizeParm );
    13561349                                        ++last;
    13571350
    1358                                         alignParm = newObj.clone();
     1351                                        alignParm = newObj->clone();
    13591352                                        alignParm->set_name( alignofName( parmName ) );
    13601353                                        last = funcType->get_parameters().insert( last, alignParm );
     
    13791372
    13801373                                        ObjectDecl *sizeParm, *alignParm, *offsetParm;
    1381                                         sizeParm = newObj.clone();
     1374                                        sizeParm = newObj->clone();
    13821375                                        sizeParm->set_name( sizeofName( typeName ) );
    13831376                                        last = funcType->get_parameters().insert( last, sizeParm );
    13841377                                        ++last;
    13851378
    1386                                         alignParm = newObj.clone();
     1379                                        alignParm = newObj->clone();
    13871380                                        alignParm->set_name( alignofName( typeName ) );
    13881381                                        last = funcType->get_parameters().insert( last, alignParm );
     
    13921385                                                // NOTE zero-length arrays are illegal in C, so empty structs have no offset array
    13931386                                                if ( ! polyBaseStruct->get_baseStruct()->get_members().empty() ) {
    1394                                                         offsetParm = newPtr.clone();
     1387                                                        offsetParm = newPtr->clone();
    13951388                                                        offsetParm->set_name( offsetofName( typeName ) );
    13961389                                                        last = funcType->get_parameters().insert( last, offsetParm );
     
    14431436                        if ( Type * base = typeDecl->base ) {
    14441437                                // 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 );
    14471440                                Type *layoutType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
    14481441
     
    15011494                                                        // polymorphic aggregate members should be converted into monomorphic members.
    15021495                                                        // 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 );
    15061497                                                }
    15071498                                        }
     
    15261517                                        stmtsToAddBefore.push_back( new DeclStmt( newBuf ) );
    15271518
    1528                                         delete objectDecl->get_init();
    15291519                                        objectDecl->set_init( new SingleInit( new VariableExpr( newBuf ) ) );
    15301520                                }
     
    16051595                        }
    16061596
    1607                         delete memberType;
    1608                         delete memberExpr;
    16091597                        return newMemberExpr;
    16101598                }
     
    16261614                                                addrExpr->arg = nullptr;
    16271615                                                std::swap( addrExpr->env, ret->env );
    1628                                                 delete addrExpr;
    16291616                                                return ret;
    16301617                                        }
     
    16351622
    16361623                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 );
    16381626                        stmtsToAddBefore.push_back( new DeclStmt( newObj ) );
    16391627                        return newObj;
     
    17491737                }
    17501738
    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 ) ) {
    17611742                                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;
    17741745                }
    17751746
     
    17771748                        Type *ty = alignofExpr->get_isType() ? alignofExpr->get_type() : alignofExpr->get_expr()->get_result();
    17781749                        if ( findGeneric( ty ) ) {
    1779                                 Expression *ret = new NameExpr( alignofName( mangleType( ty ) ) );
    1780                                 delete alignofExpr;
    1781                                 return ret;
     1750                                return new NameExpr( alignofName( mangleType( ty ) ) );
    17821751                        }
    17831752                        return alignofExpr;
     
    17941763                                if ( i == -1 ) return offsetofExpr;
    17951764
    1796                                 Expression *offsetInd = makeOffsetIndex( ty, i );
    1797                                 delete offsetofExpr;
    1798                                 return offsetInd;
     1765                                return makeOffsetIndex( ty, i );
    17991766                        } else if ( dynamic_cast< UnionInstType* >( ty ) ) {
    18001767                                // all union members are at offset zero
    1801                                 delete offsetofExpr;
    18021768                                return new ConstantExpr( Constant::from_ulong( 0 ) );
    18031769                        } else return offsetofExpr;
     
    18391805                        }
    18401806
    1841                         delete offsetPackExpr;
    18421807                        return ret;
    18431808                }
Note: See TracChangeset for help on using the changeset viewer.