Changes in / [df2be83:e55ca05]


Ignore:
Location:
src/GenPoly
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    rdf2be83 re55ca05  
    205205                        ObjectDecl *makeTemporary( Type *type );
    206206
    207                         ScopedMap< std::string, DeclarationWithType *> assignOps;    ///< Currently known type variable assignment operators
     207                        std::map< std::string, DeclarationWithType *> assignOps;     ///< Currently known type variable assignment operators
    208208                        ResolvExpr::TypeMap< DeclarationWithType > scopedAssignOps;  ///< Currently known assignment operators
    209209                        ScopedMap< std::string, DeclarationWithType* > adapters;     ///< Set of adapter functions in the current scope
     
    385385                for ( std::list< TypeDecl* >::const_iterator param = otypeParams.begin(); param != otypeParams.end(); ++param ) {
    386386                        TypeInstType paramType( Type::Qualifiers(), (*param)->get_name(), *param );
    387                         std::string paramName = mangleType( &paramType );
    388                         layoutFnType->get_parameters().push_back( new ObjectDecl( sizeofName( paramName ), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) );
    389                         layoutFnType->get_parameters().push_back( new ObjectDecl( alignofName( paramName ), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) );
     387                        layoutFnType->get_parameters().push_back( new ObjectDecl( sizeofName( &paramType ), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) );
     388                        layoutFnType->get_parameters().push_back( new ObjectDecl( alignofName( &paramType ), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) );
    390389                }
    391390        }
    392391
    393392        /// Builds a layout function declaration
    394         FunctionDecl *buildLayoutFunctionDecl( AggregateDecl *typeDecl, unsigned int functionNesting, FunctionType *layoutFnType ) {
     393        FunctionDecl *buildLayoutFunctionDecl( const std::string &typeName, unsigned int functionNesting, FunctionType *layoutFnType ) {
    395394                // Routines at global scope marked "static" to prevent multiple definitions is separate translation units
    396395                // because each unit generates copies of the default routines for each aggregate.
    397396                FunctionDecl *layoutDecl = new FunctionDecl(
    398                         layoutofName( typeDecl ), functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, layoutFnType, new CompoundStmt( noLabels ), true, false );
     397                        "__layoutof_" + typeName, functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, layoutFnType, new CompoundStmt( noLabels ), true, false );
    399398                layoutDecl->fixUniqueId();
    400399                return layoutDecl;
     
    463462                PointerType *sizeAlignOutType = new PointerType( Type::Qualifiers(), sizeAlignType );
    464463               
    465                 ObjectDecl *sizeParam = new ObjectDecl( sizeofName( structDecl->get_name() ), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType, 0 );
     464                ObjectDecl *sizeParam = new ObjectDecl( "__sizeof_" + structDecl->get_name(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType, 0 );
    466465                layoutFnType->get_parameters().push_back( sizeParam );
    467                 ObjectDecl *alignParam = new ObjectDecl( alignofName( structDecl->get_name() ), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 );
     466                ObjectDecl *alignParam = new ObjectDecl( "__alignof_" + structDecl->get_name(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 );
    468467                layoutFnType->get_parameters().push_back( alignParam );
    469                 ObjectDecl *offsetParam = new ObjectDecl( offsetofName( structDecl->get_name() ), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 );
     468                ObjectDecl *offsetParam = new ObjectDecl( "__offsetof_" + structDecl->get_name(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 );
    470469                layoutFnType->get_parameters().push_back( offsetParam );
    471470                addOtypeParams( layoutFnType, otypeParams );
    472471
    473472                // build function decl
    474                 FunctionDecl *layoutDecl = buildLayoutFunctionDecl( structDecl, functionNesting, layoutFnType );
     473                FunctionDecl *layoutDecl = buildLayoutFunctionDecl( structDecl->get_name(), functionNesting, layoutFnType );
    475474
    476475                // calculate struct layout in function body
     
    524523                PointerType *sizeAlignOutType = new PointerType( Type::Qualifiers(), sizeAlignType );
    525524               
    526                 ObjectDecl *sizeParam = new ObjectDecl( sizeofName( unionDecl->get_name() ), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType, 0 );
     525                ObjectDecl *sizeParam = new ObjectDecl( "__sizeof_" + unionDecl->get_name(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType, 0 );
    527526                layoutFnType->get_parameters().push_back( sizeParam );
    528                 ObjectDecl *alignParam = new ObjectDecl( alignofName( unionDecl->get_name() ), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 );
     527                ObjectDecl *alignParam = new ObjectDecl( "__alignof_" + unionDecl->get_name(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 );
    529528                layoutFnType->get_parameters().push_back( alignParam );
    530529                addOtypeParams( layoutFnType, otypeParams );
    531530
    532531                // build function decl
    533                 FunctionDecl *layoutDecl = buildLayoutFunctionDecl( unionDecl, functionNesting, layoutFnType );
     532                FunctionDecl *layoutDecl = buildLayoutFunctionDecl( unionDecl->get_name(), functionNesting, layoutFnType );
    534533
    535534                // calculate union layout in function body
     
    664663                        if ( functionDecl->get_statements() ) {         // empty routine body ?
    665664                                doBeginScope();
    666                                 scopeTyVars.beginScope();;
    667                                 assignOps.beginScope();
     665                                TyVarMap oldtyVars = scopeTyVars;
     666                                std::map< std::string, DeclarationWithType *> oldassignOps = assignOps;
    668667                                DeclarationWithType *oldRetval = retval;
    669668                                bool oldUseRetval = useRetval;
     
    706705                                functionDecl->set_statements( functionDecl->get_statements()->acceptMutator( *this ) );
    707706
    708                                 scopeTyVars.endScope();
    709                                 assignOps.endScope();
     707                                scopeTyVars = oldtyVars;
     708                                assignOps = oldassignOps;
     709                                // std::cerr << "end FunctionDecl: ";
     710                                // for ( TyVarMap::iterator i = scopeTyVars.begin(); i != scopeTyVars.end(); ++i ) {
     711                                //      std::cerr << i->first << " ";
     712                                // }
     713                                // std::cerr << "\n";
    710714                                retval = oldRetval;
    711715                                useRetval = oldUseRetval;
     
    743747                        Type *polyBase = hasPolyBase( parmType, exprTyVars );
    744748                        if ( polyBase && ! dynamic_cast< TypeInstType* >( polyBase ) ) {
    745                                 std::string typeName = mangleType( polyBase );
    746                                 if ( seenTypes.count( typeName ) ) return;
     749                                std::string sizeName = sizeofName( polyBase );
     750                                if ( seenTypes.count( sizeName ) ) return;
    747751
    748752                                arg = appExpr->get_args().insert( arg, new SizeofExpr( argBaseType->clone() ) );
     
    762766                                }
    763767
    764                                 seenTypes.insert( typeName );
     768                                seenTypes.insert( sizeName );
    765769                        }
    766770                }
     
    11201124                                addAssign->get_args().push_back( appExpr->get_args().front() );
    11211125                        } // if
    1122                         addAssign->get_args().push_back( new NameExpr( sizeofName( mangleType( polyType ) ) ) );
     1126                        addAssign->get_args().push_back( new NameExpr( sizeofName( polyType ) ) );
    11231127                        addAssign->get_results().front() = appExpr->get_results().front()->clone();
    11241128                        if ( appExpr->get_env() ) {
     
    11471151                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    11481152                                                        multiply->get_args().push_back( appExpr->get_args().back() );
    1149                                                         multiply->get_args().push_back( new SizeofExpr( baseType1->clone() ) );
     1153                                                        multiply->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) );
    11501154                                                        ret->get_args().push_back( appExpr->get_args().front() );
    11511155                                                        ret->get_args().push_back( multiply );
     
    11531157                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    11541158                                                        multiply->get_args().push_back( appExpr->get_args().front() );
    1155                                                         multiply->get_args().push_back( new SizeofExpr( baseType2->clone() ) );
     1159                                                        multiply->get_args().push_back( new NameExpr( sizeofName( baseType2 ) ) );
    11561160                                                        ret->get_args().push_back( multiply );
    11571161                                                        ret->get_args().push_back( appExpr->get_args().back() );
     
    12161220                                                        UntypedExpr *divide = new UntypedExpr( new NameExpr( "?/?" ) );
    12171221                                                        divide->get_args().push_back( appExpr );
    1218                                                         divide->get_args().push_back( new SizeofExpr( baseType1->clone() ) );
     1222                                                        divide->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) );
    12191223                                                        divide->get_results().push_front( appExpr->get_results().front()->clone() );
    12201224                                                        if ( appExpr->get_env() ) {
     
    12261230                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    12271231                                                        multiply->get_args().push_back( appExpr->get_args().back() );
    1228                                                         multiply->get_args().push_back( new SizeofExpr( baseType1->clone() ) );
     1232                                                        multiply->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) );
    12291233                                                        appExpr->get_args().back() = multiply;
    12301234                                                } else if ( baseType2 ) {
    12311235                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    12321236                                                        multiply->get_args().push_back( appExpr->get_args().front() );
    1233                                                         multiply->get_args().push_back( new SizeofExpr( baseType2->clone() ) );
     1237                                                        multiply->get_args().push_back( new NameExpr( sizeofName( baseType2 ) ) );
    12341238                                                        appExpr->get_args().front() = multiply;
    12351239                                                } // if
     
    12411245                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    12421246                                                        multiply->get_args().push_back( appExpr->get_args().back() );
    1243                                                         multiply->get_args().push_back( new SizeofExpr( baseType->clone() ) );
     1247                                                        multiply->get_args().push_back( new NameExpr( sizeofName( baseType ) ) );
    12441248                                                        appExpr->get_args().back() = multiply;
    12451249                                                } // if
     
    12781282                        std::list< Expression *>::iterator paramBegin = appExpr->get_args().begin();
    12791283
    1280                         TyVarMap exprTyVars( (TypeDecl::Kind)-1 );
     1284                        TyVarMap exprTyVars;
    12811285                        makeTyVarMap( function, exprTyVars );
    12821286                        ReferenceToType *polyRetType = isPolyRet( function );
     
    13811385                                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( retval->get_type() ) ) {
    13821386                                        // find assignment operator for type variable
    1383                                         ScopedMap< std::string, DeclarationWithType *>::const_iterator assignIter = assignOps.find( typeInst->get_name() );
     1387                                        std::map< std::string, DeclarationWithType *>::const_iterator assignIter = assignOps.find( typeInst->get_name() );
    13841388                                        if ( assignIter == assignOps.end() ) {
    13851389                                                throw SemanticError( "Attempt to return dtype or ftype object in ", returnStmt->get_expr() );
     
    14151419                                                DeclarationWithType *assertAssign = 0;
    14161420                                                if ( TypeInstType *formalTypeInstType = dynamic_cast< TypeInstType* >( formalType ) ) {
    1417                                                         ScopedMap< std::string, DeclarationWithType *>::const_iterator assertAssignIt = assignOps.find( formalTypeInstType->get_name() );
     1421                                                        std::map< std::string, DeclarationWithType *>::const_iterator assertAssignIt = assignOps.find( formalTypeInstType->get_name() );
    14181422                                                        if ( assertAssignIt == assignOps.end() ) {
    14191423                                                                throw SemanticError( "No assignment operation found for ", formalTypeInstType );
     
    14561460
    14571461                Type * Pass1::mutate( PointerType *pointerType ) {
    1458                         scopeTyVars.beginScope();
     1462                        TyVarMap oldtyVars = scopeTyVars;
    14591463                        makeTyVarMap( pointerType, scopeTyVars );
    14601464
    14611465                        Type *ret = Mutator::mutate( pointerType );
    14621466
    1463                         scopeTyVars.endScope();
     1467                        scopeTyVars = oldtyVars;
    14641468                        return ret;
    14651469                }
    14661470
    14671471                Type * Pass1::mutate( FunctionType *functionType ) {
    1468                         scopeTyVars.beginScope();
     1472                        TyVarMap oldtyVars = scopeTyVars;
    14691473                        makeTyVarMap( functionType, scopeTyVars );
    14701474
    14711475                        Type *ret = Mutator::mutate( functionType );
    14721476
    1473                         scopeTyVars.endScope();
     1477                        scopeTyVars = oldtyVars;
    14741478                        return ret;
    14751479                }
     
    15361540
    15371541                Type * Pass2::mutate( PointerType *pointerType ) {
    1538                         scopeTyVars.beginScope();
     1542                        TyVarMap oldtyVars = scopeTyVars;
    15391543                        makeTyVarMap( pointerType, scopeTyVars );
    15401544
    15411545                        Type *ret = Mutator::mutate( pointerType );
    15421546
    1543                         scopeTyVars.endScope();
     1547                        scopeTyVars = oldtyVars;
    15441548                        return ret;
    15451549                }
    15461550
    15471551                Type *Pass2::mutate( FunctionType *funcType ) {
    1548                         scopeTyVars.beginScope();
     1552                        TyVarMap oldtyVars = scopeTyVars;
    15491553                        makeTyVarMap( funcType, scopeTyVars );
    15501554
     
    15681572                                if ( (*tyParm)->get_kind() == TypeDecl::Any ) {
    15691573                                        TypeInstType parmType( Type::Qualifiers(), (*tyParm)->get_name(), *tyParm );
    1570                                         std::string parmName = mangleType( &parmType );
    15711574
    15721575                                        sizeParm = newObj.clone();
    1573                                         sizeParm->set_name( sizeofName( parmName ) );
     1576                                        sizeParm->set_name( sizeofName( &parmType ) );
    15741577                                        last = funcType->get_parameters().insert( last, sizeParm );
    15751578                                        ++last;
    15761579
    15771580                                        alignParm = newObj.clone();
    1578                                         alignParm->set_name( alignofName( parmName ) );
     1581                                        alignParm->set_name( alignofName( &parmType ) );
    15791582                                        last = funcType->get_parameters().insert( last, alignParm );
    15801583                                        ++last;
     
    15931596                                Type *polyBase = hasPolyBase( (*fnParm)->get_type(), scopeTyVars );
    15941597                                if ( polyBase && ! dynamic_cast< TypeInstType* >( polyBase ) ) {
    1595                                         std::string typeName = mangleType( polyBase );
    1596                                         if ( seenTypes.count( typeName ) ) continue;
     1598                                        std::string sizeName = sizeofName( polyBase );
     1599                                        if ( seenTypes.count( sizeName ) ) continue;
    15971600
    15981601                                        ObjectDecl *sizeParm, *alignParm, *offsetParm;
    15991602                                        sizeParm = newObj.clone();
    1600                                         sizeParm->set_name( sizeofName( typeName ) );
     1603                                        sizeParm->set_name( sizeName );
    16011604                                        last = funcType->get_parameters().insert( last, sizeParm );
    16021605                                        ++last;
    16031606
    16041607                                        alignParm = newObj.clone();
    1605                                         alignParm->set_name( alignofName( typeName ) );
     1608                                        alignParm->set_name( alignofName( polyBase ) );
    16061609                                        last = funcType->get_parameters().insert( last, alignParm );
    16071610                                        ++last;
     
    16111614                                                if ( ! polyBaseStruct->get_baseStruct()->get_members().empty() ) {
    16121615                                                        offsetParm = newPtr.clone();
    1613                                                         offsetParm->set_name( offsetofName( typeName ) );
     1616                                                        offsetParm->set_name( offsetofName( polyBase ) );
    16141617                                                        last = funcType->get_parameters().insert( last, offsetParm );
    16151618                                                        ++last;
     
    16171620                                        }
    16181621
    1619                                         seenTypes.insert( typeName );
     1622                                        seenTypes.insert( sizeName );
    16201623                                }
    16211624                        }
     
    16271630                        mutateAll( funcType->get_parameters(), *this );
    16281631
    1629                         scopeTyVars.endScope();
     1632                        scopeTyVars = oldtyVars;
    16301633                        return funcType;
    16311634                }
     
    18241827                template< typename DeclClass >
    18251828                DeclClass * PolyGenericCalculator::handleDecl( DeclClass *decl, Type *type ) {
    1826                         scopeTyVars.beginScope();
     1829                        TyVarMap oldtyVars = scopeTyVars;
    18271830                        makeTyVarMap( type, scopeTyVars );
    18281831
    18291832                        DeclClass *ret = static_cast< DeclClass *>( Mutator::mutate( decl ) );
    18301833
    1831                         scopeTyVars.endScope();
     1834                        scopeTyVars = oldtyVars;
    18321835                        return ret;
    18331836                }
     
    18511854
    18521855                Type * PolyGenericCalculator::mutate( PointerType *pointerType ) {
    1853                         scopeTyVars.beginScope();
     1856                        TyVarMap oldtyVars = scopeTyVars;
    18541857                        makeTyVarMap( pointerType, scopeTyVars );
    18551858
    18561859                        Type *ret = Mutator::mutate( pointerType );
    18571860
    1858                         scopeTyVars.endScope();
     1861                        scopeTyVars = oldtyVars;
    18591862                        return ret;
    18601863                }
    18611864
    18621865                Type * PolyGenericCalculator::mutate( FunctionType *funcType ) {
    1863                         scopeTyVars.beginScope();
     1866                        TyVarMap oldtyVars = scopeTyVars;
    18641867                        makeTyVarMap( funcType, scopeTyVars );
    18651868
     
    18691872                                Type *polyBase = hasPolyBase( (*fnParm)->get_type(), scopeTyVars );
    18701873                                if ( polyBase && ! dynamic_cast< TypeInstType* >( polyBase ) ) {
    1871                                         knownLayouts.insert( mangleType( polyBase ) );
     1874                                        knownLayouts.insert( sizeofName( polyBase ) );
    18721875                                }
    18731876                        }
     
    18751878                        Type *ret = Mutator::mutate( funcType );
    18761879
    1877                         scopeTyVars.endScope();
     1880                        scopeTyVars = oldtyVars;
    18781881                        return ret;
    18791882                }
     
    18861889                                        Type *declType = objectDecl->get_type();
    18871890                                        UntypedExpr *alloc = new UntypedExpr( new NameExpr( "__builtin_alloca" ) );
    1888                                         alloc->get_args().push_back( new NameExpr( sizeofName( mangleType( declType ) ) ) );
     1891                                        alloc->get_args().push_back( new NameExpr( sizeofName( declType ) ) );
    18891892
    18901893                                        delete objectDecl->get_init();
     
    19181921                        ConstantExpr *fieldIndex = new ConstantExpr( Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), offset_namer.str() ) );
    19191922                        UntypedExpr *fieldOffset = new UntypedExpr( new NameExpr( "?[?]" ) );
    1920                         fieldOffset->get_args().push_back( new NameExpr( offsetofName( mangleType( objectType ) ) ) );
     1923                        fieldOffset->get_args().push_back( new NameExpr( offsetofName( objectType ) ) );
    19211924                        fieldOffset->get_args().push_back( fieldIndex );
    19221925                        return fieldOffset;
     
    19921995                                if ( findGeneric( *param ) ) {
    19931996                                        // push size/align vars for a generic parameter back
    1994                                         std::string paramName = mangleType( *param );
    1995                                         layoutCall->get_args().push_back( new NameExpr( sizeofName( paramName ) ) );
    1996                                         layoutCall->get_args().push_back( new NameExpr( alignofName( paramName ) ) );
     1997                                        layoutCall->get_args().push_back( new NameExpr( sizeofName( *param ) ) );
     1998                                        layoutCall->get_args().push_back( new NameExpr( alignofName( *param ) ) );
    19971999                                } else {
    19982000                                        layoutCall->get_args().push_back( new SizeofExpr( (*param)->clone() ) );
     
    20382040                        } else if ( StructInstType *structTy = dynamic_cast< StructInstType* >( ty ) ) {
    20392041                                // check if this type already has a layout generated for it
    2040                                 std::string typeName = mangleType( ty );
    2041                                 if ( knownLayouts.find( typeName ) != knownLayouts.end() ) return true;
     2042                                std::string sizeName = sizeofName( ty );
     2043                                if ( knownLayouts.find( sizeName ) != knownLayouts.end() ) return true;
    20422044
    20432045                                // check if any of the type parameters have dynamic layout; if none do, this type is (or will be) monomorphized
     
    20462048
    20472049                                // insert local variables for layout and generate call to layout function
    2048                                 knownLayouts.insert( typeName );  // done early so as not to interfere with the later addition of parameters to the layout call
     2050                                knownLayouts.insert( sizeName );  // done early so as not to interfere with the later addition of parameters to the layout call
    20492051                                Type *layoutType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
    20502052
     
    20522054                                if ( n_members == 0 ) {
    20532055                                        // all empty structs have the same layout - size 1, align 1
    2054                                         makeVar( sizeofName( typeName ), layoutType, new SingleInit( new ConstantExpr( Constant::from( (unsigned long)1 ) ) ) );
    2055                                         makeVar( alignofName( typeName ), layoutType->clone(), new SingleInit( new ConstantExpr( Constant::from( (unsigned long)1 ) ) ) );
     2056                                        makeVar( sizeName, layoutType, new SingleInit( new ConstantExpr( Constant::from( (unsigned long)1 ) ) ) );
     2057                                        makeVar( alignofName( ty ), layoutType->clone(), new SingleInit( new ConstantExpr( Constant::from( (unsigned long)1 ) ) ) );
    20562058                                        // NOTE zero-length arrays are forbidden in C, so empty structs have no offsetof array
    20572059                                } else {
    2058                                         ObjectDecl *sizeVar = makeVar( sizeofName( typeName ), layoutType );
    2059                                         ObjectDecl *alignVar = makeVar( alignofName( typeName ), layoutType->clone() );
    2060                                         ObjectDecl *offsetVar = makeVar( offsetofName( typeName ), new ArrayType( Type::Qualifiers(), layoutType->clone(), new ConstantExpr( Constant::from( n_members ) ), false, false ) );
     2060                                        ObjectDecl *sizeVar = makeVar( sizeName, layoutType );
     2061                                        ObjectDecl *alignVar = makeVar( alignofName( ty ), layoutType->clone() );
     2062                                        ObjectDecl *offsetVar = makeVar( offsetofName( ty ), new ArrayType( Type::Qualifiers(), layoutType->clone(), new ConstantExpr( Constant::from( n_members ) ), false, false ) );
    20612063
    20622064                                        // generate call to layout function
    2063                                         UntypedExpr *layoutCall = new UntypedExpr( new NameExpr( layoutofName( structTy->get_baseStruct() ) ) );
     2065                                        UntypedExpr *layoutCall = new UntypedExpr( new NameExpr( "__layoutof_" + structTy->get_baseStruct()->get_name() ) );
    20642066                                        layoutCall->get_args().push_back( new AddressExpr( new VariableExpr( sizeVar ) ) );
    20652067                                        layoutCall->get_args().push_back( new AddressExpr( new VariableExpr( alignVar ) ) );
     
    20732075                        } else if ( UnionInstType *unionTy = dynamic_cast< UnionInstType* >( ty ) ) {
    20742076                                // check if this type already has a layout generated for it
    2075                                 std::string typeName = mangleType( ty );
    2076                                 if ( knownLayouts.find( typeName ) != knownLayouts.end() ) return true;
     2077                                std::string sizeName = sizeofName( ty );
     2078                                if ( knownLayouts.find( sizeName ) != knownLayouts.end() ) return true;
    20772079
    20782080                                // check if any of the type parameters have dynamic layout; if none do, this type is (or will be) monomorphized
     
    20812083
    20822084                                // insert local variables for layout and generate call to layout function
    2083                                 knownLayouts.insert( typeName );  // done early so as not to interfere with the later addition of parameters to the layout call
     2085                                knownLayouts.insert( sizeName );  // done early so as not to interfere with the later addition of parameters to the layout call
    20842086                                Type *layoutType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
    20852087
    2086                                 ObjectDecl *sizeVar = makeVar( sizeofName( typeName ), layoutType );
    2087                                 ObjectDecl *alignVar = makeVar( alignofName( typeName ), layoutType->clone() );
     2088                                ObjectDecl *sizeVar = makeVar( sizeName, layoutType );
     2089                                ObjectDecl *alignVar = makeVar( alignofName( ty ), layoutType->clone() );
    20882090
    20892091                                // generate call to layout function
    2090                                 UntypedExpr *layoutCall = new UntypedExpr( new NameExpr( layoutofName( unionTy->get_baseUnion() ) ) );
     2092                                UntypedExpr *layoutCall = new UntypedExpr( new NameExpr( "__layoutof_" + unionTy->get_baseUnion()->get_name() ) );
    20912093                                layoutCall->get_args().push_back( new AddressExpr( new VariableExpr( sizeVar ) ) );
    20922094                                layoutCall->get_args().push_back( new AddressExpr( new VariableExpr( alignVar ) ) );
     
    21042106                        Type *ty = sizeofExpr->get_type();
    21052107                        if ( findGeneric( ty ) ) {
    2106                                 Expression *ret = new NameExpr( sizeofName( mangleType( ty ) ) );
     2108                                Expression *ret = new NameExpr( sizeofName( ty ) );
    21072109                                delete sizeofExpr;
    21082110                                return ret;
     
    21142116                        Type *ty = alignofExpr->get_type();
    21152117                        if ( findGeneric( ty ) ) {
    2116                                 Expression *ret = new NameExpr( alignofName( mangleType( ty ) ) );
     2118                                Expression *ret = new NameExpr( alignofName( ty ) );
    21172119                                delete alignofExpr;
    21182120                                return ret;
     
    21522154                        if ( findGeneric( ty ) ) {
    21532155                                // pull offset back from generated type information
    2154                                 ret = new NameExpr( offsetofName( mangleType( ty ) ) );
     2156                                ret = new NameExpr( offsetofName( ty ) );
    21552157                        } else {
    2156                                 std::string offsetName = offsetofName( mangleType( ty ) );
     2158                                std::string offsetName = offsetofName( ty );
    21572159                                if ( knownOffsets.find( offsetName ) != knownOffsets.end() ) {
    21582160                                        // use the already-generated offsets for this type
     
    21942196                void PolyGenericCalculator::doEndScope() {
    21952197                        knownLayouts.endScope();
    2196                         knownOffsets.endScope();
     2198                        knownOffsets.beginScope();
    21972199                }
    21982200
     
    22012203                template< typename DeclClass >
    22022204                DeclClass * Pass3::handleDecl( DeclClass *decl, Type *type ) {
    2203                         scopeTyVars.beginScope();
     2205                        TyVarMap oldtyVars = scopeTyVars;
    22042206                        makeTyVarMap( type, scopeTyVars );
    22052207
     
    22072209                        ScrubTyVars::scrub( decl, scopeTyVars );
    22082210
    2209                         scopeTyVars.endScope();
     2211                        scopeTyVars = oldtyVars;
    22102212                        return ret;
    22112213                }
     
    22372239
    22382240                Type * Pass3::mutate( PointerType *pointerType ) {
    2239                         scopeTyVars.beginScope();
     2241                        TyVarMap oldtyVars = scopeTyVars;
    22402242                        makeTyVarMap( pointerType, scopeTyVars );
    22412243
    22422244                        Type *ret = Mutator::mutate( pointerType );
    22432245
    2244                         scopeTyVars.endScope();
     2246                        scopeTyVars = oldtyVars;
    22452247                        return ret;
    22462248                }
    22472249
    22482250                Type * Pass3::mutate( FunctionType *functionType ) {
    2249                         scopeTyVars.beginScope();
     2251                        TyVarMap oldtyVars = scopeTyVars;
    22502252                        makeTyVarMap( functionType, scopeTyVars );
    22512253
    22522254                        Type *ret = Mutator::mutate( functionType );
    22532255
    2254                         scopeTyVars.endScope();
     2256                        scopeTyVars = oldtyVars;
    22552257                        return ret;
    22562258                }
  • src/GenPoly/FindFunction.cc

    rdf2be83 re55ca05  
    5555                        TyVarMap::iterator var = tyVars.find( (*i)->get_name() );
    5656                        if ( var != tyVars.end() ) {
    57                                 tyVars.erase( var->first );
     57                                tyVars.erase( var );
    5858                        } // if
    5959                } // for
     
    6161
    6262        Type * FindFunction::mutate( FunctionType *functionType ) {
    63                 tyVars.beginScope();
     63                TyVarMap oldTyVars = tyVars;
    6464                handleForall( functionType->get_forall() );
    6565                mutateAll( functionType->get_returnVals(), *this );
     
    7272                        } // if
    7373                } // if
    74                 tyVars.endScope();
     74                tyVars = oldTyVars;
    7575                return ret;
    7676        }
    7777
    7878        Type * FindFunction::mutate( PointerType *pointerType ) {
    79                 tyVars.beginScope();
     79                TyVarMap oldTyVars = tyVars;
    8080                handleForall( pointerType->get_forall() );
    8181                Type *ret = Mutator::mutate( pointerType );
    82                 tyVars.endScope();
     82                tyVars = oldTyVars;
    8383                return ret;
    8484        }
  • src/GenPoly/GenPoly.cc

    rdf2be83 re55ca05  
    1616#include "GenPoly.h"
    1717
     18#include "SymTab/Mangler.h"
    1819#include "SynTree/Expression.h"
    1920#include "SynTree/Type.h"
     
    3738        ReferenceToType *isPolyRet( FunctionType *function ) {
    3839                if ( ! function->get_returnVals().empty() ) {
    39                         TyVarMap forallTypes( (TypeDecl::Kind)-1 );
     40                        TyVarMap forallTypes;
    4041                        makeTyVarMap( function, forallTypes );
    4142                        return (ReferenceToType*)isPolyType( function->get_returnVals().front()->get_type(), forallTypes );
     
    217218        }
    218219
     220        std::string sizeofName( Type *ty ) {
     221                return std::string( "_sizeof_" ) + SymTab::Mangler::mangleType( ty );
     222        }
     223
     224        std::string alignofName( Type *ty ) {
     225                return std::string( "_alignof_" ) + SymTab::Mangler::mangleType( ty );
     226        }
     227
     228        std::string offsetofName( Type* ty ) {
     229                return std::string( "_offsetof_" ) + SymTab::Mangler::mangleType( ty );
     230        }
     231
    219232} // namespace GenPoly
    220233
  • src/GenPoly/GenPoly.h

    rdf2be83 re55ca05  
    1717#define GENPOLY_H
    1818
     19#include <map>
    1920#include <string>
    2021#include <iostream>
    2122#include <utility>
    22 
    23 #include "ErasableScopedMap.h"
    24 
    25 #include "SymTab/Mangler.h"
    2623
    2724#include "SynTree/Declaration.h"
     
    3027
    3128namespace GenPoly {
    32         typedef ErasableScopedMap< std::string, TypeDecl::Kind > TyVarMap;
     29        typedef std::map< std::string, TypeDecl::Kind > TyVarMap;
    3330
    3431        /// A function needs an adapter if it returns a polymorphic value or if any of its
     
    7269        void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap );
    7370
    74         /// Gets the mangled name of this type; alias for SymTab::Mangler::mangleType().
    75         inline std::string mangleType( Type *ty ) { return SymTab::Mangler::mangleType( ty ); }
    76        
    77         /// Gets the name of the sizeof parameter for the type, given its mangled name
    78         inline std::string sizeofName( const std::string &name ) { return std::string( "_sizeof_" ) + name; }
     71        /// Gets the name of the sizeof parameter for the type
     72        std::string sizeofName( Type *ty );
    7973
    80         /// Gets the name of the alignof parameter for the type, given its mangled name
    81         inline std::string alignofName( const std::string &name ) { return std::string( "_alignof_" ) + name; }
     74        /// Gets the name of the alignof parameter for the type
     75        std::string alignofName( Type *ty );
    8276
    83         /// Gets the name of the offsetof parameter for the type, given its mangled name
    84         inline std::string offsetofName( const std::string &name ) { return std::string( "_offsetof_" ) + name; }
    85 
    86         /// Gets the name of the layout function for a given aggregate type, given its declaration
    87         inline std::string layoutofName( AggregateDecl *decl ) { return std::string( "_layoutof_" ) + decl->get_name(); }
    88        
     77        /// Gets the name of the offsetof parameter for the type
     78        std::string offsetofName( Type *ty );
    8979} // namespace GenPoly
    9080
  • src/GenPoly/PolyMutator.cc

    rdf2be83 re55ca05  
    2727        }
    2828
    29         PolyMutator::PolyMutator() : scopeTyVars( (TypeDecl::Kind)-1 ), env( 0 ) {}
     29        PolyMutator::PolyMutator() : env( 0 ) {
     30        }
    3031
    3132        void PolyMutator::mutateStatementList( std::list< Statement* > &statements ) {
  • src/GenPoly/ScopedMap.h

    rdf2be83 re55ca05  
    5151                        typedef typename scope_list::size_type size_type;
    5252
    53                         /// Checks if this iterator points to a valid item
    54                         bool is_valid() const {
    55                                 return it != (*scopes)[i].end();
    56                         }
    57 
    58                         /// Increments on invalid
    59                         iterator& next_valid() {
    60                                 if ( ! is_valid() ) { ++(*this); }
    61                                 return *this;
    62                         }
    63 
    64                         /// Decrements on invalid
    65                         iterator& prev_valid() {
    66                                 if ( ! is_valid() ) { --(*this); }
    67                                 return *this;
    68                         }
    69 
    7053                        iterator(scope_list const &_scopes, const wrapped_iterator &_it, size_type _i)
    7154                                : scopes(&_scopes), it(_it), i(_i) {}
     
    8568                                        --i;
    8669                                        it = (*scopes)[i].begin();
    87                                 } else {
    88                                         ++it;
    89                                 }
    90                                 return next_valid();
     70                                        return *this;
     71                                }
     72                                ++it;
     73                                return *this;
    9174                        }
    9275                        iterator& operator++ (int) { iterator tmp = *this; ++(*this); return tmp; }
     
    9982                                }
    10083                                --it;
    101                                 return prev_valid();
     84                                return *this;
    10285                        }
    10386                        iterator& operator-- (int) { iterator tmp = *this; --(*this); return tmp; }
     
    122105                        typedef typename scope_list::size_type size_type;
    123106
    124                         /// Checks if this iterator points to a valid item
    125                         bool is_valid() const {
    126                                 return it != (*scopes)[i].end();
    127                         }
    128 
    129                         /// Increments on invalid
    130                         const_iterator& next_valid() {
    131                                 if ( ! is_valid() ) { ++(*this); }
    132                                 return *this;
    133                         }
    134 
    135                         /// Decrements on invalid
    136                         const_iterator& prev_valid() {
    137                                 if ( ! is_valid() ) { --(*this); }
    138                                 return *this;
    139                         }
    140 
    141107                        const_iterator(scope_list const &_scopes, const wrapped_const_iterator &_it, size_type _i)
    142108                                : scopes(&_scopes), it(_it), i(_i) {}
     
    161127                                        --i;
    162128                                        it = (*scopes)[i].begin();
    163                                 } else {
    164                                         ++it;
    165                                 }
    166                                 return next_valid();
     129                                        return *this;
     130                                }
     131                                ++it;
     132                                return *this;
    167133                        }
    168134                        const_iterator& operator++ (int) { const_iterator tmp = *this; ++(*this); return tmp; }
     
    175141                                }
    176142                                --it;
    177                                 return prev_valid();
     143                                return *this;
    178144                        }
    179145                        const_iterator& operator-- (int) { const_iterator tmp = *this; --(*this); return tmp; }
     
    205171                ScopedMap() { beginScope(); }
    206172
    207                 iterator begin() { return iterator(scopes, scopes.back().begin(), scopes.size()-1).next_valid(); }
    208                 const_iterator begin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1).next_valid(); }
    209                 const_iterator cbegin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1).next_valid(); }
     173                iterator begin() { return iterator(scopes, scopes.back().begin(), scopes.size()-1); }
     174                const_iterator begin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1); }
     175                const_iterator cbegin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1); }
    210176                iterator end() { return iterator(scopes, scopes[0].end(), 0); }
    211177                const_iterator end() const { return const_iterator(scopes, scopes[0].end(), 0); }
  • src/GenPoly/ScopedSet.h

    rdf2be83 re55ca05  
    4848                        typedef typename scope_list::size_type size_type;
    4949
    50                         /// Checks if this iterator points to a valid item
    51                         bool is_valid() const {
    52                                 return it != (*scopes)[i].end();
    53                         }
    54 
    55                         /// Increments on invalid
    56                         iterator& next_valid() {
    57                                 if ( ! is_valid() ) { ++(*this); }
    58                                 return *this;
    59                         }
    60 
    61                         /// Decrements on invalid
    62                         iterator& prev_valid() {
    63                                 if ( ! is_valid() ) { --(*this); }
    64                                 return *this;
    65                         }
    66 
    6750                        iterator(scope_list const &_scopes, const wrapped_iterator &_it, size_type _i)
    6851                                : scopes(&_scopes), it(_it), i(_i) {}
     
    8265                                        --i;
    8366                                        it = (*scopes)[i].begin();
    84                                 } else {
    85                                         ++it;
    86                                 }
    87                                 return next_valid();
     67                                        return *this;
     68                                }
     69                                ++it;
     70                                return *this;
    8871                        }
    8972                        iterator& operator++ (int) { iterator tmp = *this; ++(*this); return tmp; }
     
    9679                                }
    9780                                --it;
    98                                 return prev_valid();
     81                                return *this;
    9982                        }
    10083                        iterator& operator-- (int) { iterator tmp = *this; --(*this); return tmp; }
     
    119102                        typedef typename scope_list::size_type size_type;
    120103
    121                         /// Checks if this iterator points to a valid item
    122                         bool is_valid() const {
    123                                 return it != (*scopes)[i].end();
    124                         }
    125 
    126                         /// Increments on invalid
    127                         const_iterator& next_valid() {
    128                                 if ( ! is_valid() ) { ++(*this); }
    129                                 return *this;
    130                         }
    131 
    132                         /// Decrements on invalid
    133                         const_iterator& prev_valid() {
    134                                 if ( ! is_valid() ) { --(*this); }
    135                                 return *this;
    136                         }
    137 
    138104                        const_iterator(scope_list const &_scopes, const wrapped_const_iterator &_it, size_type _i)
    139105                                : scopes(&_scopes), it(_it), i(_i) {}
     
    158124                                        --i;
    159125                                        it = (*scopes)[i].begin();
    160                                 } else {
    161                                         ++it;
    162                                 }
    163                                 return next_valid();
     126                                        return *this;
     127                                }
     128                                ++it;
     129                                return *this;
    164130                        }
    165131                        const_iterator& operator++ (int) { const_iterator tmp = *this; ++(*this); return tmp; }
     
    172138                                }
    173139                                --it;
    174                                 return prev_valid();
     140                                return *this;
    175141                        }
    176142                        const_iterator& operator-- (int) { const_iterator tmp = *this; --(*this); return tmp; }
     
    201167                ScopedSet() { beginScope(); }
    202168
    203                 iterator begin() { return iterator(scopes, scopes.back().begin(), scopes.size()-1).next_valid(); }
    204                 const_iterator begin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1).next_valid(); }
    205                 const_iterator cbegin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1).next_valid(); }
     169                iterator begin() { return iterator(scopes, scopes.back().begin(), scopes.size()-1); }
     170                const_iterator begin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1); }
     171                const_iterator cbegin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1); }
    206172                iterator end() { return iterator(scopes, scopes[0].end(), 0); }
    207173                const_iterator end() const { return const_iterator(scopes, scopes[0].end(), 0); }
  • src/GenPoly/ScrubTyVars.cc

    rdf2be83 re55ca05  
    6464                // sizeof( T ) => _sizeof_T parameter, which is the size of T
    6565                if ( Type *polyType = isPolyType( szeof->get_type() ) ) {
    66                         Expression *expr = new NameExpr( sizeofName( mangleType( polyType ) ) );
     66                        Expression *expr = new NameExpr( sizeofName( polyType ) );
    6767                        return expr;
    6868                } else {
     
    7474                // alignof( T ) => _alignof_T parameter, which is the alignment of T
    7575                if ( Type *polyType = isPolyType( algnof->get_type() ) ) {
    76                         Expression *expr = new NameExpr( alignofName( mangleType( polyType ) ) );
     76                        Expression *expr = new NameExpr( alignofName( polyType ) );
    7777                        return expr;
    7878                } else {
Note: See TracChangeset for help on using the changeset viewer.