Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/TupleExpansion.cc

    r9939dc3 r07de76b  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tue May 17 15:02:00 2022
    13 // Update Count     : 25
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Dec 13 23:45:51 2019
     13// Update Count     : 24
    1414//
    1515
     
    323323                std::vector<ast::ptr<ast::Type>> types;
    324324                ast::CV::Qualifiers quals{
    325                         ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict |
     325                        ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict | ast::CV::Lvalue |
    326326                        ast::CV::Atomic | ast::CV::Mutex };
    327327
     
    366366                }
    367367                return nullptr;
     368        }
     369
     370        namespace {
     371                /// 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
     372                struct ImpurityDetector : public WithShortCircuiting {
     373                        ImpurityDetector( bool ignoreUnique ) : ignoreUnique( ignoreUnique ) {}
     374
     375                        void previsit( const ApplicationExpr * appExpr ) {
     376                                visit_children = false;
     377                                if ( const DeclarationWithType * function = InitTweak::getFunction( appExpr ) ) {
     378                                        if ( function->linkage == LinkageSpec::Intrinsic ) {
     379                                                if ( function->name == "*?" || function->name == "?[?]" ) {
     380                                                        // intrinsic dereference, subscript are pure, but need to recursively look for impurity
     381                                                        visit_children = true;
     382                                                        return;
     383                                                }
     384                                        }
     385                                }
     386                                maybeImpure = true;
     387                        }
     388                        void previsit( const UntypedExpr * ) { maybeImpure = true; visit_children = false; }
     389                        void previsit( const UniqueExpr * ) {
     390                                if ( ignoreUnique ) {
     391                                        // bottom out at unique expression.
     392                                        // The existence of a unique expression doesn't change the purity of an expression.
     393                                        // That is, even if the wrapped expression is impure, the wrapper protects the rest of the expression.
     394                                        visit_children = false;
     395                                        return;
     396                                }
     397                        }
     398
     399                        bool maybeImpure = false;
     400                        bool ignoreUnique;
     401                };
     402        } // namespace
     403
     404        bool maybeImpure( const Expression * expr ) {
     405                PassVisitor<ImpurityDetector> detector( false );
     406                expr->accept( detector );
     407                return detector.pass.maybeImpure;
     408        }
     409
     410        bool maybeImpureIgnoreUnique( const Expression * expr ) {
     411                PassVisitor<ImpurityDetector> detector( true );
     412                expr->accept( detector );
     413                return detector.pass.maybeImpure;
    368414        }
    369415} // namespace Tuples
Note: See TracChangeset for help on using the changeset viewer.