source: src/Tuples/Tuples.cpp @ eb5dbfd

Last change on this file since eb5dbfd was c92bdcc, checked in by Andrew Beach <ajbeach@…>, 6 months ago

Updated the rest of the names in src/ (except for the generated files).

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[b910d15]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//
[c92bdcc]7// Tuples.cpp -- A collection of tuple operations.
[b910d15]8//
9// Author           : Andrew Beach
10// Created On       : Mon Jun 17 14:41:00 2019
11// Last Modified By : Andrew Beach
[9939dc3]12// Last Modified On : Mon May 16 16:15:00 2022
13// Update Count     : 2
[b910d15]14//
15
[c92bdcc]16#include "Tuples.hpp"
[b910d15]17
18#include "AST/Pass.hpp"
[e01eb4a]19#include "AST/Inspect.hpp"
[b910d15]20#include "AST/LinkageSpec.hpp"
[c92bdcc]21#include "InitTweak/InitTweak.hpp"
[b910d15]22
23namespace Tuples {
24
25namespace {
[9939dc3]26
[e580aa5]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.
30struct ImpurityDetector : public ast::WithShortCircuiting {
31        bool result = false;
[b910d15]32
[e580aa5]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;
[b910d15]38                        }
39                }
[e580aa5]40                result = true; visit_children = false;
41        }
42        void previsit( ast::UntypedExpr const * ) {
43                result = true; visit_children = false;
44        }
45};
46
47struct ImpurityDetectorIgnoreUnique : public ImpurityDetector {
48        using ImpurityDetector::previsit;
49        void previsit( ast::UniqueExpr const * ) {
50                visit_children = false;
51        }
52};
[9939dc3]53
[b910d15]54} // namespace
55
[bc92bee]56bool maybeImpure( const ast::Expr * expr ) {
[9939dc3]57        return ast::Pass<ImpurityDetector>::read( expr );
[bc92bee]58}
59
[b910d15]60bool maybeImpureIgnoreUnique( const ast::Expr * expr ) {
[9939dc3]61        return ast::Pass<ImpurityDetectorIgnoreUnique>::read( expr );
62}
63
[b910d15]64} // namespace Tuples
65
66// Local Variables: //
67// tab-width: 4 //
68// mode: c++ //
69// compile-command: "make install" //
70// End: //
Note: See TracBrowser for help on using the repository browser.