Changeset 2097cd4


Ignore:
Timestamp:
Mar 5, 2018, 3:33:36 PM (6 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:
9bfc9da
Parents:
000ff2c
Message:

Minor code cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r000ff2c r2097cd4  
    11741174                        if ( expr->result && isPolyType( expr->result, scopeTyVars, env ) ) {
    11751175                                if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->function ) ) {
    1176                                         if ( name->get_name() == "*?" ) {
     1176                                        if ( name->name == "*?" ) {
    11771177                                                Expression *ret = expr->args.front();
    11781178                                                expr->args.clear();
     
    11871187                void Pass1::premutate( AddressExpr * ) { visit_children = false; }
    11881188                Expression * Pass1::postmutate( AddressExpr * addrExpr ) {
    1189                         assert( addrExpr->get_arg()->result && ! addrExpr->get_arg()->get_result()->isVoid() );
     1189                        assert( addrExpr->arg->result && ! addrExpr->arg->result->isVoid() );
    11901190
    11911191                        bool needs = false;
    1192                         if ( UntypedExpr *expr = dynamic_cast< UntypedExpr *>( addrExpr->get_arg() ) ) {
    1193                                 if ( expr->result && isPolyType( expr->get_result(), scopeTyVars, env ) ) {
    1194                                         if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) {
    1195                                                 if ( name->get_name() == "*?" ) {
    1196                                                         if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr->get_args().front() ) ) {
    1197                                                                 assert( appExpr->get_function()->result );
    1198                                                                 FunctionType *function = getFunctionType( appExpr->get_function()->get_result() );
     1192                        if ( UntypedExpr *expr = dynamic_cast< UntypedExpr *>( addrExpr->arg ) ) {
     1193                                if ( expr->result && isPolyType( expr->result, scopeTyVars, env ) ) {
     1194                                        if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->function ) ) {
     1195                                                if ( name->name == "*?" ) {
     1196                                                        if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr->args.front() ) ) {
     1197                                                                assert( appExpr->function->result );
     1198                                                                FunctionType *function = getFunctionType( appExpr->function->result );
    11991199                                                                assert( function );
    12001200                                                                needs = needsAdapter( function, scopeTyVars );
     
    12061206                        // isPolyType check needs to happen before mutating addrExpr arg, so pull it forward
    12071207                        // out of the if condition.
    1208                         addrExpr->arg = addrExpr->get_arg()->acceptMutator( *visitor );
     1208                        addrExpr->arg = addrExpr->arg->acceptMutator( *visitor );
    12091209                        // ... but must happen after mutate, since argument might change (e.g. intrinsic *?, ?[?]) - re-evaluate above comment
    1210                         bool polytype = isPolyType( addrExpr->get_arg()->get_result(), scopeTyVars, env );
     1210                        bool polytype = isPolyType( addrExpr->arg->result, scopeTyVars, env );
    12111211                        if ( polytype || needs ) {
    1212                                 Expression *ret = addrExpr->get_arg();
    1213                                 delete ret->get_result();
    1214                                 ret->set_result( addrExpr->get_result()->clone() );
    1215                                 addrExpr->set_arg( 0 );
     1212                                Expression *ret = addrExpr->arg;
     1213                                delete ret->result;
     1214                                ret->result = addrExpr->result->clone();
     1215                                addrExpr->arg = nullptr;
    12161216                                delete addrExpr;
    12171217                                return ret;
     
    12501250
    12511251                void Pass2::addAdapters( FunctionType *functionType ) {
    1252                         std::list< DeclarationWithType *> &paramList = functionType->get_parameters();
     1252                        std::list< DeclarationWithType *> &paramList = functionType->parameters;
    12531253                        std::list< FunctionType *> functions;
    12541254                        for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {
     
    12711271
    12721272                DeclarationWithType * Pass2::postmutate( FunctionDecl *functionDecl ) {
    1273                         FunctionType * ftype = functionDecl->get_functionType();
    1274                         if ( ! ftype->get_returnVals().empty() && functionDecl->get_statements() ) {
    1275                                 if ( ! isPrefix( functionDecl->get_name(), "_thunk" ) && ! isPrefix( functionDecl->get_name(), "_adapter" ) ) { // xxx - remove check for prefix once thunks properly use ctor/dtors
    1276                                         assert( ftype->get_returnVals().size() == 1 );
    1277                                         DeclarationWithType * retval = ftype->get_returnVals().front();
    1278                                         if ( retval->get_name() == "" ) {
    1279                                                 retval->set_name( "_retval" );
     1273                        FunctionType * ftype = functionDecl->type;
     1274                        if ( ! ftype->returnVals.empty() && functionDecl->statements ) {
     1275                                if ( ! isPrefix( functionDecl->name, "_thunk" ) && ! isPrefix( functionDecl->name, "_adapter" ) ) { // xxx - remove check for prefix once thunks properly use ctor/dtors
     1276                                        assert( ftype->returnVals.size() == 1 );
     1277                                        DeclarationWithType * retval = ftype->returnVals.front();
     1278                                        if ( retval->name == "" ) {
     1279                                                retval->name = "_retval";
    12801280                                        }
    1281                                         functionDecl->get_statements()->get_kids().push_front( new DeclStmt( retval ) );
     1281                                        functionDecl->statements->kids.push_front( new DeclStmt( retval ) );
    12821282                                        DeclarationWithType * newRet = retval->clone(); // for ownership purposes
    1283                                         ftype->get_returnVals().front() = newRet;
     1283                                        ftype->returnVals.front() = newRet;
    12841284                                }
    12851285                        }
    12861286                        // errors should have been caught by this point, remove initializers from parameters to allow correct codegen of default arguments
    1287                         for ( Declaration * param : functionDecl->get_functionType()->get_parameters() ) {
     1287                        for ( Declaration * param : functionDecl->type->parameters ) {
    12881288                                if ( ObjectDecl * obj = dynamic_cast< ObjectDecl * >( param ) ) {
    1289                                         delete obj->get_init();
    1290                                         obj->set_init( nullptr );
     1289                                        delete obj->init;
     1290                                        obj->init = nullptr;
    12911291                                }
    12921292                        }
Note: See TracChangeset for help on using the changeset viewer.