Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/Tuples.cc

    rbc92bee rb910d15  
    1010// Created On       : Mon Jun 17 14:41:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Jun 18  9:31:00 2019
    13 // Update Count     : 1
     12// Last Modified On : Wed Jun 12 15:43:00 2019
     13// Update Count     : 0
    1414//
    1515
     
    2727        /// impure.
    2828    struct ImpurityDetector : public ast::WithShortCircuiting {
     29                ImpurityDetector( bool ignoreUnique ) : ignoreUnique( ignoreUnique ) {}
    2930                bool maybeImpure = false;
     31                bool ignoreUnique;
    3032
    3133                void previsit( ast::ApplicationExpr const * appExpr ) {
     34                        visit_children = false;
    3235                        if ( ast::DeclWithType const * function = InitTweak::getFunction( appExpr ) ) {
    3336                                if ( function->linkage == ast::Linkage::Intrinsic
    3437                                                && ( function->name == "*?" || function->name == "?[?]" ) ) {
     38                                        visit_children = true;
    3539                                        return;
    3640                                }
    3741                        }
    38                         maybeImpure = true; visit_children = false;
     42                        maybeImpure = true;
    3943                }
    4044                void previsit( ast::UntypedExpr const * ) {
    4145                        maybeImpure = true; visit_children = false;
    4246                }
    43         };
    44         struct ImpurityDetectorIgnoreUnique : public ImpurityDetector {
    4547                void previsit( ast::UniqueExpr const * ) {
    46                         visit_children = false;
     48                        if ( ignoreUnique ) {
     49                                visit_children = false;
     50                        }
    4751                }
    4852        };
    4953
    50         template<typename Detector>
    51         bool detectImpurity( const ast::Expr * expr ) {
    52                 ast::Pass<Detector> detector;
     54        bool detectImpurity( const ast::Expr * expr, bool ignoreUnique ) {
     55                ast::Pass<ImpurityDetector> detector( ignoreUnique );
    5356                expr->accept( detector );
    5457                return detector.pass.maybeImpure;
     
    5659} // namespace
    5760
    58 bool maybeImpure( const ast::Expr * expr ) {
    59         return detectImpurity<ImpurityDetector>( expr );
    60 }
    61 
    6261bool maybeImpureIgnoreUnique( const ast::Expr * expr ) {
    63         return detectImpurity<ImpurityDetectorIgnoreUnique>( expr );
     62        return detectImpurity( expr, true );
    6463}
    6564
Note: See TracChangeset for help on using the changeset viewer.