Changeset f232977 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:
b93a3de
Parents:
150ec33
git-author:
Rob Schluntz <rschlunt@…> (10/13/17 16:05:16)
git-committer:
Rob Schluntz <rschlunt@…> (10/19/17 11:15:35)
Message:

Refactor assignment return autogen code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.cc

    r150ec33 rf232977  
    295295                for ( FunctionDecl * dcl : newFuncs ) {
    296296                        genFuncBody( dcl );
     297                        if ( CodeGen::isAssignment( dcl->name ) ) {
     298                                // assignment needs to return a value
     299                                FunctionType * assignType = dcl->type;
     300                                assert( assignType->parameters.size() == 2 );
     301                                assert( assignType->returnVals.size() == 1 );
     302                                ObjectDecl * dstParam = strict_dynamic_cast< ObjectDecl * >( assignType->parameters.front() );
     303                                dcl->statements->push_back( new ReturnStmt( noLabels, new VariableExpr( dstParam ) ) );
     304                        }
    297305                        resolve( dcl );
    298306                }
     
    349357                } else {
    350358                        makeFunctionBody( aggregateDecl->members.rbegin(), aggregateDecl->members.rend(), dcl, false );
    351                 }
    352                 if ( CodeGen::isAssignment( dcl->name ) ) {
    353                         // assignment needs to return a value
    354                         FunctionType * assignType = dcl->type;
    355                         assert( assignType->parameters.size() == 2 );
    356                         assert( assignType->returnVals.size() == 1 );
    357                         ObjectDecl * srcParam = strict_dynamic_cast< ObjectDecl * >( assignType->parameters.back() );
    358                         ObjectDecl * retParam = strict_dynamic_cast< ObjectDecl * >( assignType->returnVals.front() );
    359 
    360                         dcl->statements->push_back( new ExprStmt( noLabels, new UntypedExpr( new NameExpr("?{}"), { new VariableExpr( retParam ), new VariableExpr( srcParam ) } ) ) );
    361                         dcl->statements->push_back( new ReturnStmt( noLabels, new VariableExpr( retParam ) ) );
    362359                }
    363360        }
     
    483480                        ObjectDecl * dstParam = strict_dynamic_cast< ObjectDecl * >( ftype->parameters.front() );
    484481                        ObjectDecl * srcParam = strict_dynamic_cast< ObjectDecl * >( ftype->parameters.back() );
    485 
    486482                        makeMemberOp( srcParam, dstParam, back_inserter( funcDecl->statements->kids ) );
    487                         if ( CodeGen::isAssignment( funcDecl->name ) ) {
    488                                 // also generate return statement in assignment
    489                                 funcDecl->statements->push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
    490                         }
    491483                } else {
    492484                        // default ctor/dtor body is empty - add unused attribute to parameter to silence warnings
     
    551543                        callExpr->get_args().push_back( new VariableExpr( srcParam ) );
    552544                        funcDecl->statements->push_back( new ExprStmt( noLabels, callExpr ) );
    553                         if ( CodeGen::isAssignment( funcDecl->name ) ) {
    554                                 // also generate return statement in assignment
    555                                 funcDecl->statements->push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
    556                         }
    557545                } else {
    558546                        // default ctor/dtor body is empty - add unused attribute to parameter to silence warnings
     
    580568                if ( src ) expr->args.push_back( new CastExpr( new VariableExpr( src ), typeDecl->base->clone() ) );
    581569                dcl->statements->kids.push_back( new ExprStmt( noLabels, expr ) );
    582                 if ( CodeGen::isAssignment( dcl->get_name() ) ) {
    583                         // assignment needs to return a value
    584                         FunctionType * assignType = dcl->type;
    585                         assert( assignType->parameters.size() == 2 );
    586                         ObjectDecl * srcParam = strict_dynamic_cast< ObjectDecl * >( assignType->parameters.back() );
    587                         dcl->statements->kids.push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
    588                 }
    589570        };
    590571
Note: See TracChangeset for help on using the changeset viewer.