[0dd3a2f] | 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 | //
|
---|
[3b58d91] | 7 | // TupleExpr.cc --
|
---|
[0dd3a2f] | 8 | //
|
---|
| 9 | // Author : Richard C. Bilson
|
---|
| 10 | // Created On : Mon May 18 07:44:20 2015
|
---|
| 11 | // Last Modified By : Peter A. Buhr
|
---|
| 12 | // Last Modified On : Mon May 18 10:59:19 2015
|
---|
| 13 | // Update Count : 1
|
---|
| 14 | //
|
---|
[51b73452] | 15 |
|
---|
| 16 | #include "Expression.h"
|
---|
[d3b7937] | 17 | #include "Common/utility.h"
|
---|
[3b58d91] | 18 | #include "Type.h"
|
---|
[6eb8948] | 19 | #include "Declaration.h"
|
---|
[3c13c03] | 20 | #include "Tuples/Tuples.h"
|
---|
[23bb1b9] | 21 | #include "VarExprReplacer.h"
|
---|
[51b73452] | 22 |
|
---|
[3c13c03] | 23 | TupleExpr::TupleExpr( const std::list< Expression * > & exprs, Expression *_aname ) : Expression( _aname ), exprs( exprs ) {
|
---|
| 24 | if ( ! exprs.empty() ) {
|
---|
| 25 | if ( std::all_of( exprs.begin(), exprs.end(), [](Expression * expr) { return expr->get_result(); } ) ) {
|
---|
| 26 | set_result( Tuples::makeTupleType( exprs ) );
|
---|
| 27 | }
|
---|
| 28 | }
|
---|
[51b73452] | 29 | }
|
---|
| 30 |
|
---|
[0dd3a2f] | 31 | TupleExpr::TupleExpr( const TupleExpr &other ) : Expression( other ) {
|
---|
| 32 | cloneAll( other.exprs, exprs );
|
---|
[51b73452] | 33 | }
|
---|
| 34 |
|
---|
[0dd3a2f] | 35 | TupleExpr::~TupleExpr() {
|
---|
| 36 | deleteAll( exprs );
|
---|
[51b73452] | 37 | }
|
---|
| 38 |
|
---|
[0dd3a2f] | 39 | void TupleExpr::print( std::ostream &os, int indent ) const {
|
---|
[aa8f9df] | 40 | os << "Tuple:" << std::endl;
|
---|
[0dd3a2f] | 41 | printAll( exprs, os, indent+2 );
|
---|
| 42 | Expression::print( os, indent );
|
---|
[51b73452] | 43 | }
|
---|
| 44 |
|
---|
[3c13c03] | 45 | TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) : tuple( tuple ), index( index ) {
|
---|
[aa8f9df] | 46 | TupleType * type = safe_dynamic_cast< TupleType * >( tuple->get_result() );
|
---|
[3c13c03] | 47 | assert( type->size() > index );
|
---|
| 48 | set_result( (*std::next( type->get_types().begin(), index ))->clone() );
|
---|
[1132b62] | 49 | get_result()->set_isLvalue( type->get_isLvalue() );
|
---|
[3b58d91] | 50 | }
|
---|
| 51 |
|
---|
| 52 | TupleIndexExpr::TupleIndexExpr( const TupleIndexExpr &other ) : Expression( other ), tuple( other.tuple->clone() ), index( other.index ) {
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | TupleIndexExpr::~TupleIndexExpr() {
|
---|
| 56 | delete tuple;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | void TupleIndexExpr::print( std::ostream &os, int indent ) const {
|
---|
[aa8f9df] | 60 | os << "Tuple Index Expression, with tuple:" << std::endl;
|
---|
[3c13c03] | 61 | os << std::string( indent+2, ' ' );
|
---|
[3b58d91] | 62 | tuple->print( os, indent+2 );
|
---|
| 63 | os << std::string( indent+2, ' ' ) << "with index: " << index << std::endl;
|
---|
| 64 | Expression::print( os, indent );
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | MemberTupleExpr::MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname ) : Expression( _aname ) {
|
---|
[aa8f9df] | 68 | set_result( maybeClone( member->get_result() ) ); // xxx - ???
|
---|
[3b58d91] | 69 | }
|
---|
| 70 |
|
---|
| 71 | MemberTupleExpr::MemberTupleExpr( const MemberTupleExpr &other ) : Expression( other ), member( other.member->clone() ), aggregate( other.aggregate->clone() ) {
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | MemberTupleExpr::~MemberTupleExpr() {
|
---|
| 75 | delete member;
|
---|
| 76 | delete aggregate;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | void MemberTupleExpr::print( std::ostream &os, int indent ) const {
|
---|
[aa8f9df] | 80 | os << "Member Tuple Expression, with aggregate:" << std::endl;
|
---|
[3c13c03] | 81 | os << std::string( indent+2, ' ' );
|
---|
[3b58d91] | 82 | aggregate->print( os, indent+2 );
|
---|
| 83 | os << std::string( indent+2, ' ' ) << "with member: " << std::endl;
|
---|
[3c13c03] | 84 | os << std::string( indent+2, ' ' );
|
---|
[3b58d91] | 85 | member->print( os, indent+2 );
|
---|
| 86 | Expression::print( os, indent );
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 |
|
---|
[6eb8948] | 90 | TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname ) : Expression( _aname ), assigns( assigns ), tempDecls( tempDecls ) {
|
---|
[65660bd] | 91 | set_result( Tuples::makeTupleType( assigns ) );
|
---|
[6eb8948] | 92 | }
|
---|
| 93 |
|
---|
[23bb1b9] | 94 | TupleAssignExpr::TupleAssignExpr( const TupleAssignExpr &other ) : Expression( other ) {
|
---|
[6eb8948] | 95 | cloneAll( other.assigns, assigns );
|
---|
[23bb1b9] | 96 | cloneAll( other.tempDecls, tempDecls );
|
---|
| 97 |
|
---|
| 98 | // clone needs to go into assigns and replace tempDecls
|
---|
| 99 | VarExprReplacer::DeclMap declMap;
|
---|
| 100 | std::list< ObjectDecl * >::const_iterator origit = other.tempDecls.begin();
|
---|
| 101 | for ( ObjectDecl * temp : tempDecls ) {
|
---|
| 102 | assert( origit != other.tempDecls.end() );
|
---|
| 103 | ObjectDecl * origTemp = *origit++;
|
---|
| 104 | assert( origTemp );
|
---|
| 105 | assert( temp->get_name() == origTemp->get_name() );
|
---|
| 106 | declMap[ origTemp ] = temp;
|
---|
| 107 | }
|
---|
| 108 | if ( ! declMap.empty() ) {
|
---|
| 109 | VarExprReplacer replacer( declMap );
|
---|
| 110 | for ( Expression * assn : assigns ) {
|
---|
| 111 | assn->accept( replacer );
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
[6eb8948] | 114 | }
|
---|
| 115 |
|
---|
| 116 | TupleAssignExpr::~TupleAssignExpr() {
|
---|
| 117 | deleteAll( assigns );
|
---|
| 118 | // deleteAll( tempDecls );
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | void TupleAssignExpr::print( std::ostream &os, int indent ) const {
|
---|
[3c13c03] | 122 | os << "Tuple Assignment Expression, with temporaries:" << std::endl;
|
---|
[6eb8948] | 123 | printAll( tempDecls, os, indent+4 );
|
---|
| 124 | os << std::string( indent+2, ' ' ) << "with assignments: " << std::endl;
|
---|
| 125 | printAll( assigns, os, indent+4 );
|
---|
| 126 | Expression::print( os, indent );
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 |
|
---|
[0dd3a2f] | 131 | // Local Variables: //
|
---|
| 132 | // tab-width: 4 //
|
---|
| 133 | // mode: c++ //
|
---|
| 134 | // compile-command: "make install" //
|
---|
| 135 | // End: //
|
---|