source: src/Tuples/Tuples.cc @ 7f66cec

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 7f66cec was ba662b9, checked in by Fangren Yu <f37yu@…>, 4 years ago

actually run impurity check

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[b910d15]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// Tuples.h --
8//
9// Author           : Andrew Beach
10// Created On       : Mon Jun 17 14:41:00 2019
11// Last Modified By : Andrew Beach
[bc92bee]12// Last Modified On : Tue Jun 18  9:31:00 2019
13// Update Count     : 1
[b910d15]14//
15
16#include "Tuples.h"
17
18#include "AST/Pass.hpp"
19#include "AST/LinkageSpec.hpp"
20#include "InitTweak/InitTweak.h"
21
22namespace Tuples {
23
24namespace {
25        /// Determines if impurity (read: side-effects) may exist in a piece of code. Currently gives
26        /// a very crude approximation, wherein any function call expression means the code may be
27        /// impure.
28    struct ImpurityDetector : public ast::WithShortCircuiting {
29                bool maybeImpure = false;
30
31                void previsit( ast::ApplicationExpr const * appExpr ) {
32                        if ( ast::DeclWithType const * function = InitTweak::getFunction( appExpr ) ) {
33                                if ( function->linkage == ast::Linkage::Intrinsic
34                                                && ( function->name == "*?" || function->name == "?[?]" ) ) {
35                                        return;
36                                }
37                        }
[bc92bee]38                        maybeImpure = true; visit_children = false;
[b910d15]39                }
40                void previsit( ast::UntypedExpr const * ) {
41                        maybeImpure = true; visit_children = false;
42                }
[bc92bee]43        };
44        struct ImpurityDetectorIgnoreUnique : public ImpurityDetector {
[ba662b9]45                using ImpurityDetector::previsit;
[b910d15]46                void previsit( ast::UniqueExpr const * ) {
[bc92bee]47                        visit_children = false;
[b910d15]48                }
49        };
50
[bc92bee]51        template<typename Detector>
52        bool detectImpurity( const ast::Expr * expr ) {
53                ast::Pass<Detector> detector;
[b910d15]54                expr->accept( detector );
55                return detector.pass.maybeImpure;
56        }
57} // namespace
58
[bc92bee]59bool maybeImpure( const ast::Expr * expr ) {
60        return detectImpurity<ImpurityDetector>( expr );
61}
62
[b910d15]63bool maybeImpureIgnoreUnique( const ast::Expr * expr ) {
[bc92bee]64        return detectImpurity<ImpurityDetectorIgnoreUnique>( expr );
[b910d15]65}
66
67} // namespace Tuples
68
69// Local Variables: //
70// tab-width: 4 //
71// mode: c++ //
72// compile-command: "make install" //
73// End: //
Note: See TracBrowser for help on using the repository browser.