Changeset f57dd25 for src/SynTree


Ignore:
Timestamp:
May 29, 2019, 3:45:00 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
0aedb01
Parents:
157a816 (diff), ebc0a85 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'cleanup-dtors'

Location:
src/SynTree
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/DeclReplacer.cc

    r157a816 rf57dd25  
    3838                        void previsit( TypeInstType * inst );
    3939                };
     40
     41                /// Mutator that replaces uses of declarations with arbitrary expressions, according to the supplied mapping
     42                struct ExprDeclReplacer {
     43                private:
     44                        const ExprMap & exprMap;
     45                        bool debug;
     46                public:
     47                        ExprDeclReplacer( const ExprMap & exprMap, bool debug = false );
     48
     49                        // replace variable with new node from expr map
     50                        Expression * postmutate( VariableExpr * varExpr );
     51                };
    4052        }
    4153
     
    5365                DeclMap declMap;
    5466                replace( node, declMap, typeMap, debug );
     67        }
     68
     69        void replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug ) {
     70                PassVisitor<ExprDeclReplacer> replacer( exprMap, debug );
     71                node = maybeMutate( node, replacer );
    5572        }
    5673
     
    7996                        }
    8097                }
     98
     99                ExprDeclReplacer::ExprDeclReplacer( const ExprMap & exprMap, bool debug ) : exprMap( exprMap ), debug( debug ) {}
     100
     101                Expression * ExprDeclReplacer::postmutate( VariableExpr * varExpr ) {
     102                        if ( exprMap.count( varExpr->var ) ) {
     103                                Expression * replacement = exprMap.at( varExpr->var )->clone();
     104                                if ( debug ) {
     105                                        std::cerr << "replacing variable reference: " << (void*)varExpr->var << " " << varExpr->var << " with " << (void*)replacement << " " << replacement << std::endl;
     106                                }
     107                                std::swap( varExpr->env, replacement->env );
     108                                delete varExpr;
     109                                return replacement;
     110                        }
     111                        return varExpr;
     112                }
    81113        }
    82114} // namespace VarExprReplacer
  • src/SynTree/DeclReplacer.h

    r157a816 rf57dd25  
    2626        typedef std::map< DeclarationWithType *, DeclarationWithType * > DeclMap;
    2727        typedef std::map< TypeDecl *, TypeDecl * > TypeMap;
     28        typedef std::map< DeclarationWithType *, Expression * > ExprMap;
    2829
    2930        void replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug = false );
    3031        void replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug = false );
    3132        void replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false );
     33
     34        void replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug = false);
     35        template<typename T>
     36                void replace( T *& node, const ExprMap & exprMap, bool debug = false ) {
     37                if ( ! node ) return;
     38                BaseSyntaxNode * arg = node;
     39                replace( arg, exprMap, debug );
     40                node = dynamic_cast<T *>( arg );
     41                assertf( node, "DeclReplacer fundamentally changed the type of its argument." );
     42        }
    3243}
    3344
  • src/SynTree/Expression.cc

    r157a816 rf57dd25  
    538538        assert( callExpr );
    539539        assert( callExpr->result );
    540         set_result( callExpr->get_result()->clone() );
     540        set_result( callExpr->result->clone() );
    541541}
    542542
    543543ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
    544         cloneAll( other.tempDecls, tempDecls );
    545         cloneAll( other.returnDecls, returnDecls );
    546         cloneAll( other.dtors, dtors );
    547544}
    548545
     
    550547        set_env( nullptr ); // ImplicitCopyCtorExpr does not take ownership of an environment
    551548        delete callExpr;
    552         deleteAll( tempDecls );
    553         deleteAll( returnDecls );
    554         deleteAll( dtors );
    555549}
    556550
     
    558552        os <<  "Implicit Copy Constructor Expression: " << std::endl << indent+1;
    559553        callExpr->print( os, indent+1 );
    560         os << std::endl << indent << "... with temporaries:" << std::endl;
    561         printAll( tempDecls, os, indent+1 );
    562         os << std::endl << indent << "... with return temporaries:" << std::endl;
    563         printAll( returnDecls, os, indent+1 );
    564         Expression::print( os, indent );
    565554}
    566555
  • src/SynTree/Expression.h

    r157a816 rf57dd25  
    593593class ImplicitCopyCtorExpr : public Expression {
    594594public:
    595         ApplicationExpr * callExpr;
    596         std::list< ObjectDecl * > tempDecls;
    597         std::list< ObjectDecl * > returnDecls;
    598         std::list< Expression * > dtors;
     595        ApplicationExpr * callExpr = nullptr;
    599596
    600597        ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
    601598        ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
    602599        virtual ~ImplicitCopyCtorExpr();
    603 
    604         ApplicationExpr * get_callExpr() const { return callExpr; }
    605         void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }
    606 
    607         std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
    608         std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
    609         std::list< Expression * > & get_dtors() { return dtors; }
    610600
    611601        virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }
Note: See TracChangeset for help on using the changeset viewer.