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

Last change on this file since 1ccae59 was c6b4432, checked in by Andrew Beach <ajbeach@…>, 23 months ago

Remove BaseSyntaxNode and clean-up.

  • Property mode set to 100644
File size: 1.8 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.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
23namespace Tuples {
24
25namespace {
26
27 /// Determines if impurity (read: side-effects) may exist in a piece of code. Currently gives
28 /// a very crude approximation, wherein any function call expression means the code may be
29 /// 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} // namespace
54
55bool maybeImpure( const ast::Expr * expr ) {
56 return ast::Pass<ImpurityDetector>::read( expr );
57}
58
59bool maybeImpureIgnoreUnique( const ast::Expr * expr ) {
60 return ast::Pass<ImpurityDetectorIgnoreUnique>::read( expr );
61}
62
63} // namespace Tuples
64
65// Local Variables: //
66// tab-width: 4 //
67// mode: c++ //
68// compile-command: "make install" //
69// End: //
Note: See TracBrowser for help on using the repository browser.