source: src/ResolvExpr/Alternative.h@ 23b6643f

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 23b6643f was aefcc3b, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

major change to instantiateFunction to match arguments against the formal parameter's structure rather than the reverse

  • Property mode set to 100644
File size: 2.9 KB
RevLine 
[a32b204]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//
[3c13c03]7// Alternative.h --
[a32b204]8//
9// Author : Richard C. Bilson
10// Created On : Sat May 16 23:45:43 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Sat May 16 23:54:39 2015
13// Update Count : 2
[3c13c03]14//
[a32b204]15
16#ifndef ALTERNATIVE_H
17#define ALTERNATIVE_H
[51b73452]18
19#include <list>
20#include "SynTree/SynTree.h"
21#include "Cost.h"
22#include "TypeEnvironment.h"
23
24namespace ResolvExpr {
[a32b204]25 struct Alternative;
26 typedef std::list< Alternative > AltList;
[d9a0e76]27
[a32b204]28 struct Alternative {
29 Alternative();
30 Alternative( Expression *expr, const TypeEnvironment &env, const Cost &cost );
31 Alternative( Expression *expr, const TypeEnvironment &env, const Cost &cost, const Cost &cvtCost );
32 Alternative( const Alternative &other );
33 Alternative &operator=( const Alternative &other );
[aefcc3b]34 Alternative( Alternative && other );
35 Alternative &operator=( Alternative && other );
[a32b204]36 ~Alternative();
[3c13c03]37
[a32b204]38 void initialize( const Alternative &src, Alternative &dest );
[3c13c03]39
[a32b204]40 void print( std::ostream &os, int indent = 0 ) const;
[3c13c03]41
[a32b204]42 Cost cost;
43 Cost cvtCost;
44 Expression *expr;
45 TypeEnvironment env;
46 };
[3c13c03]47
48 /// helper function used by explode
49 template< typename OutputIterator >
50 void explodeUnique( Expression * expr, const Alternative & alt, OutputIterator out ) {
51 Type * res = expr->get_result();
52 if ( TupleType * tupleType = dynamic_cast< TupleType * > ( res ) ) {
[aefcc3b]53 if ( TupleExpr * tupleExpr = dynamic_cast< TupleExpr * >( expr ) ) {
54 // can open tuple expr and dump its exploded components
[3c13c03]55 for ( Expression * expr : tupleExpr->get_exprs() ) {
56 explodeUnique( expr, alt, out );
57 }
58 } else {
[aefcc3b]59 // tuple type, but not tuple expr - need to refer to single instance of the argument
60 // expression and index into its components
[3c13c03]61 UniqueExpr * unq = new UniqueExpr( expr->clone() );
62 for ( unsigned int i = 0; i < tupleType->size(); i++ ) {
63 TupleIndexExpr * idx = new TupleIndexExpr( unq->clone(), i );
64 explodeUnique( idx, alt, out );
65 delete idx;
66 }
67 delete unq;
68 }
69 } else {
[aefcc3b]70 // atomic (non-tuple) type - output a clone of the expression in a new alternative
[3c13c03]71 *out++ = Alternative( expr->clone(), alt.env, alt.cost, alt.cvtCost );
72 }
73 }
74
75 /// expands a tuple-valued alternative into multiple alternatives, each with a non-tuple-type
76 template< typename OutputIterator >
[aefcc3b]77 void explode( const Alternative &alt, OutputIterator out ) {
[3c13c03]78 explodeUnique( alt.expr, alt, out );
79 }
80
81 // explode list of alternatives
82 template< typename OutputIterator >
[aefcc3b]83 void explode( const AltList & alts, OutputIterator out ) {
84 for ( const Alternative & alt : alts ) {
[3c13c03]85 explode( alt, out );
86 }
87 }
[51b73452]88} // namespace ResolvExpr
89
[a32b204]90#endif // ALTERNATIVE_H
91
92// Local Variables: //
93// tab-width: 4 //
94// mode: c++ //
95// compile-command: "make install" //
96// End: //
Note: See TracBrowser for help on using the repository browser.