source: src/Tuples/Tuples.cc@ 1e5dedc4

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 1e5dedc4 was b910d15, checked in by Andrew Beach <ajbeach@…>, 6 years ago

Implemented new versions of Tuples/Explode.

  • Property mode set to 100644
File size: 1.9 KB
Line 
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 : Wed Jun 12 15:43:00 2019
13// Update Count : 0
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 ImpurityDetector( bool ignoreUnique ) : ignoreUnique( ignoreUnique ) {}
30 bool maybeImpure = false;
31 bool ignoreUnique;
32
33 void previsit( ast::ApplicationExpr const * appExpr ) {
34 visit_children = false;
35 if ( ast::DeclWithType const * function = InitTweak::getFunction( appExpr ) ) {
36 if ( function->linkage == ast::Linkage::Intrinsic
37 && ( function->name == "*?" || function->name == "?[?]" ) ) {
38 visit_children = true;
39 return;
40 }
41 }
42 maybeImpure = true;
43 }
44 void previsit( ast::UntypedExpr const * ) {
45 maybeImpure = true; visit_children = false;
46 }
47 void previsit( ast::UniqueExpr const * ) {
48 if ( ignoreUnique ) {
49 visit_children = false;
50 }
51 }
52 };
53
54 bool detectImpurity( const ast::Expr * expr, bool ignoreUnique ) {
55 ast::Pass<ImpurityDetector> detector( ignoreUnique );
56 expr->accept( detector );
57 return detector.pass.maybeImpure;
58 }
59} // namespace
60
61bool maybeImpureIgnoreUnique( const ast::Expr * expr ) {
62 return detectImpurity( expr, true );
63}
64
65} // namespace Tuples
66
67// Local Variables: //
68// tab-width: 4 //
69// mode: c++ //
70// compile-command: "make install" //
71// End: //
Note: See TracBrowser for help on using the repository browser.