Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r2efe4b8 r982f95d  
    3838#include "Lvalue.h"                      // for generalizedLvalue
    3939#include "Parser/LinkageSpec.h"          // for C, Spec, Cforall, Intrinsic
    40 #include "ResolvExpr/TypeEnvironment.h"  // for EqvClass
    4140#include "ResolvExpr/typeops.h"          // for typesCompatible
    4241#include "ScopedSet.h"                   // for ScopedSet, ScopedSet<>::iter...
     
    184183                        /// change the type of generic aggregate members to char[]
    185184                        void mutateMembers( AggregateDecl * aggrDecl );
     185                        /// returns the calculated sizeof expression for ty, or nullptr for use C sizeof()
     186                        Expression* genSizeof( Type* ty );
    186187
    187188                        /// Enters a new scope for type-variables, adding the type variables from ty
     
    383384                unsigned long n_members = 0;
    384385                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 );
    387388                        assert( dwt );
    388389                        Type *memberType = dwt->get_type();
     
    590591                        // pass size/align for type variables
    591592                        for ( TyVarMap::const_iterator tyParm = exprTyVars.begin(); tyParm != exprTyVars.end(); ++tyParm ) {
    592                                 ResolvExpr::EqvClass eqvClass;
    593593                                assert( env );
    594594                                if ( tyParm->second.isComplete ) {
     
    17371737                }
    17381738
     1739                Expression * PolyGenericCalculator::genSizeof( Type* ty ) {
     1740                        if ( ArrayType * aty = dynamic_cast<ArrayType *>(ty) ) {
     1741                                // generate calculated size for possibly generic array
     1742                                Expression * sizeofBase = genSizeof( aty->get_base() );
     1743                                if ( ! sizeofBase ) return nullptr;
     1744                                Expression * dim = aty->get_dimension();
     1745                                aty->set_dimension( nullptr );
     1746                                return makeOp( "?*?", sizeofBase, dim );
     1747                        } else if ( findGeneric( ty ) ) {
     1748                                // generate calculated size for generic type
     1749                                return new NameExpr( sizeofName( mangleType( ty ) ) );
     1750                        } else return nullptr;
     1751                }
     1752
    17391753                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;
     1754                        Type *ty = sizeofExpr->get_isType() ?
     1755                                sizeofExpr->get_type() : sizeofExpr->get_expr()->get_result();
     1756                       
     1757                        Expression * gen = genSizeof( ty );
     1758                        return gen ? gen : sizeofExpr;
    17451759                }
    17461760
Note: See TracChangeset for help on using the changeset viewer.