source: src/Tuples/Tuples.cc@ fd642d2

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 fd642d2 was bc92bee, checked in by Andrew Beach <ajbeach@…>, 6 years ago

Implemented Tuples::maybeImpure while it was fresh in my mind.

  • 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 : 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
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 }
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
58bool maybeImpure( const ast::Expr * expr ) {
59 return detectImpurity<ImpurityDetector>( expr );
60}
61
62bool 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: //
Note: See TracBrowser for help on using the repository browser.