Changeset d5baf0c


Ignore:
Timestamp:
Jul 2, 2020, 6:05:10 PM (15 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast, new-ast-unique-expr
Children:
74cfafb2
Parents:
5877b3e
Message:

Specialization now produces Declarations instead of Statements so it can be added at the top level.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Specialize.cc

    r5877b3e rd5baf0c  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Dec 13 23:40:49 2019
    13 // Update Count     : 32
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr Jul  2 17:42:00 2020
     13// Update Count     : 33
    1414//
    1515
     
    4242
    4343namespace GenPoly {
    44         struct Specialize final : public WithConstTypeSubstitution, public WithStmtsToAdd, public WithVisitorRef<Specialize> {
     44        struct Specialize final : public WithConstTypeSubstitution,
     45                        public WithDeclsToAdd, public WithVisitorRef<Specialize> {
    4546                Expression * postmutate( ApplicationExpr *applicationExpr );
    4647                Expression * postmutate( CastExpr *castExpr );
     
    248249                } // if
    249250
    250                 // handle any specializations that may still be present
    251                 std::string oldParamPrefix = paramPrefix;
    252                 paramPrefix += "p";
    253                 // save stmtsToAddBefore in oldStmts
    254                 std::list< Statement* > oldStmts;
    255                 oldStmts.splice( oldStmts.end(), stmtsToAddBefore );
    256                 appExpr->acceptMutator( *visitor );
    257                 paramPrefix = oldParamPrefix;
    258                 // write any statements added for recursive specializations into the thunk body
    259                 thunkFunc->statements->kids.splice( thunkFunc->statements->kids.end(), stmtsToAddBefore );
    260                 // restore oldStmts into stmtsToAddBefore
    261                 stmtsToAddBefore.splice( stmtsToAddBefore.end(), oldStmts );
     251                // Handle any specializations that may still be present.
     252                {
     253                        std::string oldParamPrefix = paramPrefix;
     254                        paramPrefix += "p";
     255                        std::list< Declaration * > oldDecls;
     256                        oldDecls.splice( oldDecls.end(), declsToAddBefore );
     257
     258                        appExpr->acceptMutator( *visitor );
     259                        // Write recursive specializations into the thunk body.
     260                        for ( Declaration * decl : declsToAddBefore ) {
     261                                thunkFunc->statements->kids.push_back( new DeclStmt( decl ) );
     262                        }
     263
     264                        declsToAddBefore = std::move( oldDecls );
     265                        paramPrefix = oldParamPrefix;
     266                }
    262267
    263268                // add return (or valueless expression) to the thunk
     
    270275                thunkFunc->statements->kids.push_back( appStmt );
    271276
    272                 // add thunk definition to queue of statements to add
    273                 stmtsToAddBefore.push_back( new DeclStmt( thunkFunc ) );
     277                // Add the thunk definition (converted to DeclStmt if appproprate).
     278                declsToAddBefore.push_back( thunkFunc );
    274279                // return address of thunk function as replacement expression
    275280                return new AddressExpr( new VariableExpr( thunkFunc ) );
Note: See TracChangeset for help on using the changeset viewer.