source: src/Tuples/Explode.h @ d104b02

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since d104b02 was 9236060, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Merge branch 'master' into references

  • Property mode set to 100644
File size: 3.3 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// Explode.h --
8//
9// Author           : Rob Schluntz
10// Created On       : Wed Nov 9 13:12:24 2016
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Sat Jul 22 09:55:16 2017
13// Update Count     : 3
14//
15
16#pragma once
17
18#include "ResolvExpr/AlternativeFinder.h"
19#include "ResolvExpr/Resolver.h"
20
21#include "SynTree/Expression.h"
22#include "SynTree/Declaration.h"
23#include "SynTree/Type.h"
24
25#include "Tuples.h"
26
27namespace Tuples {
28        /// helper function used by explode
29        template< typename OutputIterator >
30        void explodeUnique( Expression * expr, const ResolvExpr::Alternative & alt, const SymTab::Indexer & indexer, OutputIterator out, bool isTupleAssign ) {
31                Type * res = expr->get_result()->stripReferences();
32                if ( TupleType * tupleType = dynamic_cast< TupleType * > ( res ) ) {
33                        if ( TupleExpr * tupleExpr = dynamic_cast< TupleExpr * >( expr ) ) {
34                                // can open tuple expr and dump its exploded components
35                                for ( Expression * expr : tupleExpr->get_exprs() ) {
36                                        explodeUnique( expr, alt, indexer, out, isTupleAssign );
37                                }
38                        } else {
39                                // tuple type, but not tuple expr - recursively index into its components.
40                                // if expr type is reference, convert to value type
41                                Expression * arg = expr->clone();
42
43                                if ( dynamic_cast<ReferenceType *>( arg->get_result() ) ) {
44                                        // TODO: does this go here (inside uniqueexpr) or outside uniqueexpr? I'm guessing probably should go after...
45                                        arg = new CastExpr( arg, tupleType->clone() );
46                                }
47                                if ( Tuples::maybeImpure( arg ) && ! dynamic_cast< UniqueExpr * >( arg ) ) {
48                                        // expressions which may contain side effects require a single unique instance of the expression.
49                                        arg = new UniqueExpr( arg );
50                                }
51                                for ( unsigned int i = 0; i < tupleType->size(); i++ ) {
52                                        TupleIndexExpr * idx = new TupleIndexExpr( arg->clone(), i );
53                                        explodeUnique( idx, alt, indexer, out, isTupleAssign );
54                                        delete idx;
55                                }
56                                delete arg;
57                        }
58                } else {
59                        // atomic (non-tuple) type - output a clone of the expression in a new alternative
60                        *out++ = ResolvExpr::Alternative( expr->clone(), alt.env, alt.cost, alt.cvtCost );
61                }
62        }
63
64        /// expands a tuple-valued alternative into multiple alternatives, each with a non-tuple-type
65        template< typename OutputIterator >
66        void explode( const ResolvExpr::Alternative &alt, const SymTab::Indexer & indexer, OutputIterator out, bool isTupleAssign = false ) {
67                explodeUnique( alt.expr, alt, indexer, out, isTupleAssign );
68        }
69
70        // explode list of alternatives
71        template< typename AltIterator, typename OutputIterator >
72        void explode( AltIterator altBegin, AltIterator altEnd, const SymTab::Indexer & indexer, OutputIterator out, bool isTupleAssign = false ) {
73                for ( ; altBegin != altEnd; ++altBegin ) {
74                        explode( *altBegin, indexer, out, isTupleAssign );
75                }
76        }
77
78        template< typename OutputIterator >
79        void explode( const ResolvExpr::AltList & alts, const SymTab::Indexer & indexer, OutputIterator out, bool isTupleAssign = false ) {
80                explode( alts.begin(), alts.end(), indexer, out, isTupleAssign );
81        }
82} // namespace Tuples
83
84// Local Variables: //
85// tab-width: 4 //
86// mode: c++ //
87// compile-command: "make install" //
88// End: //
Note: See TracBrowser for help on using the repository browser.