Changeset 0ce063b for src


Ignore:
Timestamp:
Jun 5, 2019, 4:28:53 PM (5 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:
54d4c0e
Parents:
4864a73
Message:

DeclReplacer? now returns number of node changed

Location:
src/SynTree
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/DeclReplacer.cc

    r4864a73 r0ce063b  
    3030                        bool debug;
    3131                public:
     32                        size_t replaced;
     33
     34                public:
    3235                        DeclReplacer( const DeclMap & declMap, const TypeMap & typeMap, bool debug = false );
    3336
     
    4548                        bool debug;
    4649                public:
     50                        size_t replaced;
     51
     52                public:
    4753                        ExprDeclReplacer( const ExprMap & exprMap, bool debug = false );
    4854
     
    5258        }
    5359
    54         void replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug ) {
     60        size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug ) {
    5561                PassVisitor<DeclReplacer> replacer( declMap, typeMap, debug );
    5662                maybeAccept( node, replacer );
     63                return replacer.pass.replaced;
    5764        }
    5865
    59         void replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug ) {
     66        size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug ) {
    6067                TypeMap typeMap;
    61                 replace( node, declMap, typeMap, debug );
     68                return replace( node, declMap, typeMap, debug );
    6269        }
    6370
    64         void replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug ) {
     71        size_t replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug ) {
    6572                DeclMap declMap;
    66                 replace( node, declMap, typeMap, debug );
     73                return replace( node, declMap, typeMap, debug );
    6774        }
    6875
    69         void replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug ) {
     76        size_t replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug ) {
    7077                PassVisitor<ExprDeclReplacer> replacer( exprMap, debug );
    7178                node = maybeMutate( node, replacer );
     79                return replacer.pass.replaced;
    7280        }
    7381
    7482        namespace {
    75                 DeclReplacer::DeclReplacer( const DeclMap & declMap, const TypeMap & typeMap, bool debug ) : declMap( declMap ), typeMap( typeMap ) , debug( debug ) {}
     83                DeclReplacer::DeclReplacer( const DeclMap & declMap, const TypeMap & typeMap, bool debug ) : declMap( declMap ), typeMap( typeMap ) , debug( debug ), replaced( 0 ) {}
    7684
    7785                // replace variable with new node from decl map
     
    7987                        // xxx - assertions and parameters aren't accounted for in this... (i.e. they aren't inserted into the map when it's made, only DeclStmts are)
    8088                        if ( declMap.count( varExpr->var ) ) {
     89                                replaced++;
    8190                                auto replacement = declMap.at( varExpr->var );
    8291                                if ( debug ) {
     
    8998                void DeclReplacer::previsit( TypeInstType * inst ) {
    9099                        if ( typeMap.count( inst->baseType ) ) {
     100                                replaced++;
    91101                                auto replacement = typeMap.at( inst->baseType );
    92102                                if ( debug ) {
     
    97107                }
    98108
    99                 ExprDeclReplacer::ExprDeclReplacer( const ExprMap & exprMap, bool debug ) : exprMap( exprMap ), debug( debug ) {}
     109                ExprDeclReplacer::ExprDeclReplacer( const ExprMap & exprMap, bool debug ) : exprMap( exprMap ), debug( debug ), replaced( 0 ) {}
    100110
    101111                Expression * ExprDeclReplacer::postmutate( VariableExpr * varExpr ) {
    102112                        if ( exprMap.count( varExpr->var ) ) {
     113                                replaced++;
    103114                                Expression * replacement = exprMap.at( varExpr->var )->clone();
    104115                                if ( debug ) {
  • src/SynTree/DeclReplacer.h

    r4864a73 r0ce063b  
    2828        typedef std::map< DeclarationWithType *, Expression * > ExprMap;
    2929
    30         void replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug = false );
    31         void replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug = false );
    32         void replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false );
     30        size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug = false );
     31        size_t replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug = false );
     32        size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false );
    3333
    34         void replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug = false);
     34        size_t replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug = false);
    3535        template<typename T>
    3636                void replace( T *& node, const ExprMap & exprMap, bool debug = false ) {
Note: See TracChangeset for help on using the changeset viewer.