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 |
---|
12 | // Last Modified On : Tue Jun 18 9:31:00 2019 |
---|
13 | // Update Count : 1 |
---|
14 | // |
---|
15 | |
---|
16 | #include "Tuples.h" |
---|
17 | |
---|
18 | #include "AST/Pass.hpp" |
---|
19 | #include "AST/LinkageSpec.hpp" |
---|
20 | #include "InitTweak/InitTweak.h" |
---|
21 | |
---|
22 | namespace Tuples { |
---|
23 | |
---|
24 | namespace { |
---|
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 | } |
---|
38 | maybeImpure = true; visit_children = false; |
---|
39 | } |
---|
40 | void previsit( ast::UntypedExpr const * ) { |
---|
41 | maybeImpure = true; visit_children = false; |
---|
42 | } |
---|
43 | }; |
---|
44 | struct ImpurityDetectorIgnoreUnique : public ImpurityDetector { |
---|
45 | void previsit( ast::UniqueExpr const * ) { |
---|
46 | visit_children = false; |
---|
47 | } |
---|
48 | }; |
---|
49 | |
---|
50 | template<typename Detector> |
---|
51 | bool detectImpurity( const ast::Expr * expr ) { |
---|
52 | ast::Pass<Detector> detector; |
---|
53 | expr->accept( detector ); |
---|
54 | return detector.pass.maybeImpure; |
---|
55 | } |
---|
56 | } // namespace |
---|
57 | |
---|
58 | bool maybeImpure( const ast::Expr * expr ) { |
---|
59 | return detectImpurity<ImpurityDetector>( expr ); |
---|
60 | } |
---|
61 | |
---|
62 | bool maybeImpureIgnoreUnique( const ast::Expr * expr ) { |
---|
63 | return detectImpurity<ImpurityDetectorIgnoreUnique>( expr ); |
---|
64 | } |
---|
65 | |
---|
66 | } // namespace Tuples |
---|
67 | |
---|
68 | // Local Variables: // |
---|
69 | // tab-width: 4 // |
---|
70 | // mode: c++ // |
---|
71 | // compile-command: "make install" // |
---|
72 | // End: // |
---|