source: src/Tuples/Tuples.cc@ aad677d

stuck-waitfor-destruct
Last change on this file since aad677d was c6b4432, checked in by Andrew Beach <ajbeach@…>, 2 years ago

Remove BaseSyntaxNode and clean-up.

  • 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//
[11df881]7// Tuples.cc -- 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
16#include "Tuples.h"
17
18#include "AST/Pass.hpp"
[e01eb4a]19#include "AST/Inspect.hpp"
[b910d15]20#include "AST/LinkageSpec.hpp"
21#include "InitTweak/InitTweak.h"
22
23namespace Tuples {
24
25namespace {
[9939dc3]26
[b910d15]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 {
[9939dc3]31 bool result = false;
[b910d15]32
33 void previsit( ast::ApplicationExpr const * appExpr ) {
[e01eb4a]34 if ( ast::DeclWithType const * function = ast::getFunction( appExpr ) ) {
[b910d15]35 if ( function->linkage == ast::Linkage::Intrinsic
36 && ( function->name == "*?" || function->name == "?[?]" ) ) {
37 return;
38 }
39 }
[9939dc3]40 result = true; visit_children = false;
[b910d15]41 }
42 void previsit( ast::UntypedExpr const * ) {
[9939dc3]43 result = true; visit_children = false;
[b910d15]44 }
[bc92bee]45 };
[9939dc3]46
[bc92bee]47 struct ImpurityDetectorIgnoreUnique : public ImpurityDetector {
[ba662b9]48 using ImpurityDetector::previsit;
[b910d15]49 void previsit( ast::UniqueExpr const * ) {
[bc92bee]50 visit_children = false;
[b910d15]51 }
52 };
53} // namespace
54
[bc92bee]55bool maybeImpure( const ast::Expr * expr ) {
[9939dc3]56 return ast::Pass<ImpurityDetector>::read( expr );
[bc92bee]57}
58
[b910d15]59bool maybeImpureIgnoreUnique( const ast::Expr * expr ) {
[9939dc3]60 return ast::Pass<ImpurityDetectorIgnoreUnique>::read( expr );
61}
62
[b910d15]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.