Changeset 582ee28 for src


Ignore:
Timestamp:
Oct 19, 2017, 11:15:35 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:
9dbf7c8
Parents:
ab4bff5
git-author:
Rob Schluntz <rschlunt@…> (10/17/17 12:09:24)
git-committer:
Rob Schluntz <rschlunt@…> (10/19/17 11:15:35)
Message:

Fix unique id for union field constructor parameter, small cleanup in CopyParams?

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/CopyParams.cc

    rab4bff5 r582ee28  
    5353
    5454        void CopyParams::visit( FunctionDecl *funcDecl ) {
    55                 if ( funcDecl->get_statements() ) {
    56                         funcDecl->get_statements()->accept( *this );
     55                if ( funcDecl->statements ) {
     56                        funcDecl->statements->accept( *this );
    5757
    5858                        if ( ! modVars.empty() ) {
     
    6060                                // xxx - this needs to use constructors, not assignment operators
    6161                                // assume the assignment operator is the first assert param after any "type" parameter
    62                                 for ( Type::ForallList::const_iterator tyVar = funcDecl->get_functionType()->get_forall().begin(); tyVar != funcDecl->get_functionType()->get_forall().end(); ++tyVar ) {
     62                                for ( Type::ForallList::const_iterator tyVar = funcDecl->type->forall.begin(); tyVar != funcDecl->type->forall.end(); ++tyVar ) {
    6363                                        if ( (*tyVar)->get_kind() == TypeDecl::Any ) {
    64                                                 assert( !(*tyVar)->get_assertions().empty() );
    65                                                 assert( (*tyVar)->get_assertions().front()->get_name() == "?=?" );
    66                                                 assignOps[ (*tyVar)->get_name() ] = (*tyVar)->get_assertions().front();
     64                                                assert( !(*tyVar)->assertions.empty() );
     65                                                assert( (*tyVar)->assertions.front()->name == "?=?" );
     66                                                assignOps[ (*tyVar)->name ] = (*tyVar)->assertions.front();
    6767                                        } // if
    6868                                } // for
    69                                 for ( std::list< DeclarationWithType* >::iterator param = funcDecl->get_functionType()->get_parameters().begin(); param != funcDecl->get_functionType()->get_parameters().end(); ++param ) {
     69                                for ( std::list< DeclarationWithType* >::iterator param = funcDecl->type->parameters.begin(); param != funcDecl->type->parameters.end(); ++param ) {
    7070                                        std::set< UniqueId >::const_iterator var = modVars.find( (*param)->get_uniqueId() );
    7171                                        if ( var != modVars.end() ) {
    7272                                                TypeInstType *typeInst = dynamic_cast< TypeInstType* >( (*param)->get_type() );
    73                                                 assert( typeInst );
    74                                                 std::map< std::string, DeclarationWithType* >::const_iterator assignOp = assignOps.find( typeInst->get_name() );
     73                                                assertf( typeInst, "Found in modVars for function %s: unique id: %u, %s", funcDecl->name.c_str(), (*param)->get_uniqueId(), toString( *param ).c_str() );
     74                                                std::map< std::string, DeclarationWithType* >::const_iterator assignOp = assignOps.find( typeInst->name );
    7575                                                if ( assignOp != assignOps.end() ) {
    7676                                                        DeclarationWithType *oldParam = *param;
     
    7878                                                        (*param)->set_mangleName( namer.newName( (*param)->get_mangleName() ) );
    7979                                                        ApplicationExpr *assign = new ApplicationExpr( new VariableExpr( assignOp->second ) );
    80                                                         assign->get_args().push_back( new VariableExpr( oldParam ) );
    81                                                         assign->get_args().push_back( new VariableExpr( *param ) );
    82                                                         funcDecl->get_statements()->get_kids().push_front( new ExprStmt( noLabels, assign ) );
    83                                                         funcDecl->get_statements()->get_kids().push_front( new DeclStmt( noLabels, oldParam ) );
     80                                                        assign->args.push_back( new VariableExpr( oldParam ) );
     81                                                        assign->args.push_back( new VariableExpr( *param ) );
     82                                                        funcDecl->statements->push_front( new ExprStmt( noLabels, assign ) );
     83                                                        funcDecl->statements->push_front( new DeclStmt( noLabels, oldParam ) );
    8484                                                } // if
    8585                                                modVars.erase( var );
     
    9797        // every parameter of TypeInstType* when visiting the FunctionDecl.
    9898        void CopyParams::visit( AddressExpr *addrExpr ) {
    99                 if ( VariableExpr *varExpr = dynamic_cast< VariableExpr* >( addrExpr->get_arg() ) ) {
    100                         if ( dynamic_cast< TypeInstType* >( varExpr->get_var()->get_type() ) ) {
    101                                 modVars.insert( varExpr->get_var()->get_uniqueId() );
     99                if ( VariableExpr *varExpr = dynamic_cast< VariableExpr* >( addrExpr->arg ) ) {
     100                        if ( dynamic_cast< TypeInstType* >( varExpr->var->get_type() ) ) {
     101                                assertf( varExpr->var->get_uniqueId(), "Address-taken variable does not have a unique ID: %s", toString( varExpr->var ).c_str() );
     102                                modVars.insert( varExpr->var->get_uniqueId() );
     103                                std::cerr << "added unique id: " << varExpr->var->get_uniqueId() << " var: " << varExpr->var << std::endl;
    102104                        } // if
    103105                } // if
  • src/SymTab/Autogen.cc

    rab4bff5 r582ee28  
    523523                        FunctionDecl * ctor = genFunc( "?{}", memCtorType->clone(), functionNesting );
    524524                        ObjectDecl * srcParam = strict_dynamic_cast<ObjectDecl *>( ctor->type->parameters.back() );
     525                        srcParam->fixUniqueId();
    525526                        ObjectDecl * dstParam = InitTweak::getParamThis( ctor->type );
    526527                        makeMemberOp( srcParam, dstParam, back_inserter( ctor->statements->kids ) );
  • src/SynTree/Declaration.cc

    rab4bff5 r582ee28  
    4242
    4343void Declaration::fixUniqueId() {
     44        // don't need to set unique ID twice
     45        if ( uniqueId ) return;
    4446        uniqueId = ++lastUniqueId;
    4547        idMap[ uniqueId ] = this;
Note: See TracChangeset for help on using the changeset viewer.