source: src/Tuples/Explode.h@ 17f22e78

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 17f22e78 was e6cee92, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Fix TupleAssignment code for references

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