Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/TupleExpansion.cc

    rf0ecf9b r027c496  
    315315        namespace {
    316316                /// determines if impurity (read: side-effects) may exist in a piece of code. Currently gives a very crude approximation, wherein any function call expression means the code may be impure
    317                 class ImpurityDetector : public Visitor {
    318                 public:
     317                struct ImpurityDetector : public WithShortCircuiting {
    319318                        ImpurityDetector( bool ignoreUnique ) : ignoreUnique( ignoreUnique ) {}
    320319
    321                         typedef Visitor Parent;
    322                         virtual void visit( ApplicationExpr * appExpr ) {
     320                        void previsit( ApplicationExpr * appExpr ) {
     321                                visit_children = false;
    323322                                if ( DeclarationWithType * function = InitTweak::getFunction( appExpr ) ) {
    324323                                        if ( function->get_linkage() == LinkageSpec::Intrinsic ) {
    325324                                                if ( function->get_name() == "*?" || function->get_name() == "?[?]" ) {
    326325                                                        // intrinsic dereference, subscript are pure, but need to recursively look for impurity
    327                                                         Parent::visit( appExpr );
     326                                                        visit_children = true;
    328327                                                        return;
    329328                                                }
     
    332331                                maybeImpure = true;
    333332                        }
    334                         virtual void visit( UntypedExpr * ) { maybeImpure = true; }
    335                         virtual void visit( UniqueExpr * unq ) {
     333                        void previsit( UntypedExpr * ) { maybeImpure = true; visit_children = false; }
     334                        void previsit( UniqueExpr * ) {
    336335                                if ( ignoreUnique ) {
    337336                                        // bottom out at unique expression.
    338337                                        // The existence of a unique expression doesn't change the purity of an expression.
    339338                                        // That is, even if the wrapped expression is impure, the wrapper protects the rest of the expression.
     339                                        visit_children = false;
    340340                                        return;
    341341                                }
    342                                 maybeAccept( unq->expr, *this );
    343342                        }
    344343
     
    349348
    350349        bool maybeImpure( Expression * expr ) {
    351                 ImpurityDetector detector( false );
     350                PassVisitor<ImpurityDetector> detector( false );
    352351                expr->accept( detector );
    353                 return detector.maybeImpure;
     352                return detector.pass.maybeImpure;
    354353        }
    355354
    356355        bool maybeImpureIgnoreUnique( Expression * expr ) {
    357                 ImpurityDetector detector( true );
     356                PassVisitor<ImpurityDetector> detector( true );
    358357                expr->accept( detector );
    359                 return detector.maybeImpure;
     358                return detector.pass.maybeImpure;
    360359        }
    361360} // namespace Tuples
Note: See TracChangeset for help on using the changeset viewer.