Changeset f30b2610


Ignore:
Timestamp:
Oct 19, 2017, 11:15:36 AM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
e41306d
Parents:
1a5ad8c
git-author:
Rob Schluntz <rschlunt@…> (10/19/17 11:00:48)
git-committer:
Rob Schluntz <rschlunt@…> (10/19/17 11:15:36)
Message:

Refactor forall parameter cloning for autogen into genDefaultType

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.cc

    r1a5ad8c rf30b2610  
    213213
    214214        bool isUnnamedBitfield( ObjectDecl * obj ) {
    215                 return obj != nullptr && obj->get_name() == "" && obj->get_bitfieldWidth() != nullptr;
     215                return obj != nullptr && obj->name == "" && obj->bitfieldWidth != nullptr;
    216216        }
    217217
     
    219219        void addForwardDecl( FunctionDecl * functionDecl, std::list< Declaration * > & declsToAdd ) {
    220220                FunctionDecl * decl = functionDecl->clone();
    221                 delete decl->get_statements();
    222                 decl->set_statements( nullptr );
     221                delete decl->statements;
     222                decl->statements = nullptr;
    223223                declsToAdd.push_back( decl );
    224224                decl->fixUniqueId();
    225225        }
    226226
     227        const std::list< TypeDecl * > getGenericParams( Type * t ) {
     228                std::list< TypeDecl * > * ret = nullptr;
     229                if ( StructInstType * inst = dynamic_cast< StructInstType * > ( t ) ) {
     230                        ret = inst->get_baseParameters();
     231                } else if ( UnionInstType * inst = dynamic_cast< UnionInstType * >( t ) ) {
     232                        ret = inst->get_baseParameters();
     233                }
     234                return ret ? *ret : std::list< TypeDecl * >();
     235        }
     236
    227237        /// given type T, generate type of default ctor/dtor, i.e. function type void (*) (T *)
    228238        FunctionType * genDefaultType( Type * paramType ) {
     239                const auto & typeParams = getGenericParams( paramType );
    229240                FunctionType *ftype = new FunctionType( Type::Qualifiers(), false );
     241                cloneAll( typeParams, ftype->forall );
    230242                ObjectDecl *dstParam = new ObjectDecl( "_dst", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new ReferenceType( Type::Qualifiers(), paramType->clone() ), nullptr );
    231                 ftype->get_parameters().push_back( dstParam );
     243                ftype->parameters.push_back( dstParam );
    232244                return ftype;
    233245        }
     
    237249                FunctionType *ftype = genDefaultType( paramType );
    238250                ObjectDecl *srcParam = new ObjectDecl( "_src", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, paramType->clone(), nullptr );
    239                 ftype->get_parameters().push_back( srcParam );
     251                ftype->parameters.push_back( srcParam );
    240252                return ftype;
    241253        }
     
    245257                FunctionType *ftype = genCopyType( paramType );
    246258                ObjectDecl *returnVal = new ObjectDecl( "_ret", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, paramType->clone(), nullptr );
    247                 ftype->get_returnVals().push_back( returnVal );
     259                ftype->returnVals.push_back( returnVal );
    248260                return ftype;
    249261        }
     
    276288        }
    277289
    278         const std::list< TypeDecl * > getGenericParams( Type * t ) {
    279                 std::list< TypeDecl * > * ret = nullptr;
    280                 if ( StructInstType * inst = dynamic_cast< StructInstType * > ( t ) ) {
    281                         ret = inst->get_baseParameters();
    282                 } else if ( UnionInstType * inst = dynamic_cast< UnionInstType * >( t ) ) {
    283                         ret = inst->get_baseParameters();
    284                 }
    285                 return ret ? *ret : std::list< TypeDecl * >();
    286         }
    287 
    288290        //=============================================================================================
    289291        // FuncGenerator member definitions
     
    318320                        }
    319321
    320                         // Make function polymorphic in same parameters as generic struct, if applicable
    321                         std::list< TypeDecl * > typeParams = getGenericParams( type ); // List of type variables to be placed on the generated functions
    322                         cloneAll( typeParams, ftype->forall );
    323 
    324322                        newFuncs.push_back( genFunc( data.fname, ftype, functionNesting ) );
    325323                }
     
    353351                // generate appropriate calls to member ctor, assignment
    354352                // destructor needs to do everything in reverse, so pass "forward" based on whether the function is a destructor
    355                 if ( ! CodeGen::isDestructor( dcl->get_name() ) ) {
     353                if ( ! CodeGen::isDestructor( dcl->name ) ) {
    356354                        makeFunctionBody( aggregateDecl->members.begin(), aggregateDecl->members.end(), dcl );
    357355                } else {
     
    362360        void StructFuncGenerator::genFieldCtors() {
    363361                // field ctors are only generated if default constructor and copy constructor are both generated
    364                 unsigned numCtors = std::count_if( definitions.begin(), definitions.end(), [](Declaration * dcl) { return CodeGen::isConstructor( dcl->get_name() ); } );
     362                unsigned numCtors = std::count_if( definitions.begin(), definitions.end(), [](Declaration * dcl) { return CodeGen::isConstructor( dcl->name ); } );
    365363
    366364                // Field constructors are only generated if default and copy constructor
     
    371369                // for example, for struct A { int x, y; }; generate
    372370                //   void ?{}(A *, int) and void ?{}(A *, int, int)
    373                 const auto & typeParams = aggregateDecl->parameters;
    374371                FunctionType * memCtorType = genDefaultType( type );
    375                 cloneAll( typeParams, memCtorType->forall );
    376372                for ( Declaration * member : aggregateDecl->members ) {
    377373                        DeclarationWithType * field = strict_dynamic_cast<DeclarationWithType *>( member );
     
    392388
    393389                // assign to destination
    394                 Expression *dstselect = new MemberExpr( field, new CastExpr( new VariableExpr( dstParam ), strict_dynamic_cast< ReferenceType* >( dstParam->get_type() )->get_base()->clone() ) );
    395                 genImplicitCall( srcParam, dstselect, func->get_name(), back_inserter( func->get_statements()->get_kids() ), field, forward );
     390                Expression *dstselect = new MemberExpr( field, new CastExpr( new VariableExpr( dstParam ), strict_dynamic_cast< ReferenceType* >( dstParam->get_type() )->base->clone() ) );
     391                genImplicitCall( srcParam, dstselect, func->name, back_inserter( func->statements->kids ), field, forward );
    396392        }
    397393
     
    504500                // void ?{}(A *, int)
    505501                // This is to mimic C's behaviour which initializes the first member of the union.
    506                 const auto & typeParams = aggregateDecl->parameters;
    507502                FunctionType * memCtorType = genDefaultType( type );
    508                 cloneAll( typeParams, memCtorType->forall );
    509503                for ( Declaration * member : aggregateDecl->members ) {
    510504                        DeclarationWithType * field = strict_dynamic_cast<DeclarationWithType *>( member );
Note: See TracChangeset for help on using the changeset viewer.