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.cc -- A collection of tuple operations. |
---|
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 : Mon May 16 16:15:00 2022 |
---|
13 | // Update Count : 2 |
---|
14 | // |
---|
15 | |
---|
16 | #include "Tuples.h" |
---|
17 | |
---|
18 | #include "AST/Pass.hpp" |
---|
19 | #include "AST/Inspect.hpp" |
---|
20 | #include "AST/LinkageSpec.hpp" |
---|
21 | #include "InitTweak/InitTweak.h" |
---|
22 | |
---|
23 | namespace Tuples { |
---|
24 | |
---|
25 | namespace { |
---|
26 | |
---|
27 | /// Determines if impurity (read: side-effects) may exist in a piece of code. |
---|
28 | /// Currently gives a very crude approximation, wherein almost any function |
---|
29 | /// call expression means the code may be impure. |
---|
30 | struct ImpurityDetector : public ast::WithShortCircuiting { |
---|
31 | bool result = false; |
---|
32 | |
---|
33 | void previsit( ast::ApplicationExpr const * appExpr ) { |
---|
34 | if ( ast::DeclWithType const * function = ast::getFunction( appExpr ) ) { |
---|
35 | if ( function->linkage == ast::Linkage::Intrinsic |
---|
36 | && ( function->name == "*?" || function->name == "?[?]" ) ) { |
---|
37 | return; |
---|
38 | } |
---|
39 | } |
---|
40 | result = true; visit_children = false; |
---|
41 | } |
---|
42 | void previsit( ast::UntypedExpr const * ) { |
---|
43 | result = true; visit_children = false; |
---|
44 | } |
---|
45 | }; |
---|
46 | |
---|
47 | struct ImpurityDetectorIgnoreUnique : public ImpurityDetector { |
---|
48 | using ImpurityDetector::previsit; |
---|
49 | void previsit( ast::UniqueExpr const * ) { |
---|
50 | visit_children = false; |
---|
51 | } |
---|
52 | }; |
---|
53 | |
---|
54 | } // namespace |
---|
55 | |
---|
56 | bool maybeImpure( const ast::Expr * expr ) { |
---|
57 | return ast::Pass<ImpurityDetector>::read( expr ); |
---|
58 | } |
---|
59 | |
---|
60 | bool maybeImpureIgnoreUnique( const ast::Expr * expr ) { |
---|
61 | return ast::Pass<ImpurityDetectorIgnoreUnique>::read( expr ); |
---|
62 | } |
---|
63 | |
---|
64 | } // namespace Tuples |
---|
65 | |
---|
66 | // Local Variables: // |
---|
67 | // tab-width: 4 // |
---|
68 | // mode: c++ // |
---|
69 | // compile-command: "make install" // |
---|
70 | // End: // |
---|