| [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" | 
|---|
| [51b73452] | 21 |  | 
|---|
| [3c13c03] | 22 | TupleExpr::TupleExpr( const std::list< Expression * > & exprs, Expression *_aname ) : Expression( _aname ), exprs( exprs ) { | 
|---|
|  | 23 | if ( ! exprs.empty() ) { | 
|---|
|  | 24 | if ( std::all_of( exprs.begin(), exprs.end(), [](Expression * expr) { return expr->get_result(); } ) ) { | 
|---|
|  | 25 | set_result( Tuples::makeTupleType( exprs ) ); | 
|---|
|  | 26 | } | 
|---|
|  | 27 | } | 
|---|
| [51b73452] | 28 | } | 
|---|
|  | 29 |  | 
|---|
| [0dd3a2f] | 30 | TupleExpr::TupleExpr( const TupleExpr &other ) : Expression( other ) { | 
|---|
|  | 31 | cloneAll( other.exprs, exprs ); | 
|---|
| [51b73452] | 32 | } | 
|---|
|  | 33 |  | 
|---|
| [0dd3a2f] | 34 | TupleExpr::~TupleExpr() { | 
|---|
|  | 35 | deleteAll( exprs ); | 
|---|
| [51b73452] | 36 | } | 
|---|
|  | 37 |  | 
|---|
| [0dd3a2f] | 38 | void TupleExpr::print( std::ostream &os, int indent ) const { | 
|---|
| [aa8f9df] | 39 | os << "Tuple:" << std::endl; | 
|---|
| [0dd3a2f] | 40 | printAll( exprs, os, indent+2 ); | 
|---|
|  | 41 | Expression::print( os, indent ); | 
|---|
| [51b73452] | 42 | } | 
|---|
|  | 43 |  | 
|---|
| [3c13c03] | 44 | TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) : tuple( tuple ), index( index )  { | 
|---|
| [aa8f9df] | 45 | TupleType * type = safe_dynamic_cast< TupleType * >( tuple->get_result() ); | 
|---|
| [3c13c03] | 46 | assert( type->size() > index ); | 
|---|
|  | 47 | set_result( (*std::next( type->get_types().begin(), index ))->clone() ); | 
|---|
| [1132b62] | 48 | get_result()->set_isLvalue( type->get_isLvalue() ); | 
|---|
| [3b58d91] | 49 | } | 
|---|
|  | 50 |  | 
|---|
|  | 51 | TupleIndexExpr::TupleIndexExpr( const TupleIndexExpr &other ) : Expression( other ), tuple( other.tuple->clone() ), index( other.index ) { | 
|---|
|  | 52 | } | 
|---|
|  | 53 |  | 
|---|
|  | 54 | TupleIndexExpr::~TupleIndexExpr() { | 
|---|
|  | 55 | delete tuple; | 
|---|
|  | 56 | } | 
|---|
|  | 57 |  | 
|---|
|  | 58 | void TupleIndexExpr::print( std::ostream &os, int indent ) const { | 
|---|
| [aa8f9df] | 59 | os << "Tuple Index Expression, with tuple:" << std::endl; | 
|---|
| [3c13c03] | 60 | os << std::string( indent+2, ' ' ); | 
|---|
| [3b58d91] | 61 | tuple->print( os, indent+2 ); | 
|---|
|  | 62 | os << std::string( indent+2, ' ' ) << "with index: " << index << std::endl; | 
|---|
|  | 63 | Expression::print( os, indent ); | 
|---|
|  | 64 | } | 
|---|
|  | 65 |  | 
|---|
|  | 66 | MemberTupleExpr::MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname ) : Expression( _aname ) { | 
|---|
| [aa8f9df] | 67 | set_result( maybeClone( member->get_result() ) ); // xxx - ??? | 
|---|
| [3b58d91] | 68 | } | 
|---|
|  | 69 |  | 
|---|
|  | 70 | MemberTupleExpr::MemberTupleExpr( const MemberTupleExpr &other ) : Expression( other ), member( other.member->clone() ), aggregate( other.aggregate->clone() ) { | 
|---|
|  | 71 | } | 
|---|
|  | 72 |  | 
|---|
|  | 73 | MemberTupleExpr::~MemberTupleExpr() { | 
|---|
|  | 74 | delete member; | 
|---|
|  | 75 | delete aggregate; | 
|---|
|  | 76 | } | 
|---|
|  | 77 |  | 
|---|
|  | 78 | void MemberTupleExpr::print( std::ostream &os, int indent ) const { | 
|---|
| [aa8f9df] | 79 | os << "Member Tuple Expression, with aggregate:" << std::endl; | 
|---|
| [3c13c03] | 80 | os << std::string( indent+2, ' ' ); | 
|---|
| [3b58d91] | 81 | aggregate->print( os, indent+2 ); | 
|---|
|  | 82 | os << std::string( indent+2, ' ' ) << "with member: " << std::endl; | 
|---|
| [3c13c03] | 83 | os << std::string( indent+2, ' ' ); | 
|---|
| [3b58d91] | 84 | member->print( os, indent+2 ); | 
|---|
|  | 85 | Expression::print( os, indent ); | 
|---|
|  | 86 | } | 
|---|
|  | 87 |  | 
|---|
|  | 88 |  | 
|---|
| [6eb8948] | 89 | TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname ) : Expression( _aname ), assigns( assigns ), tempDecls( tempDecls ) { | 
|---|
| [65660bd] | 90 | set_result( Tuples::makeTupleType( assigns ) ); | 
|---|
| [6eb8948] | 91 | } | 
|---|
|  | 92 |  | 
|---|
|  | 93 | TupleAssignExpr::TupleAssignExpr( const TupleAssignExpr &other ) : Expression( other ), tempDecls( other.tempDecls ) /* temporary */ { | 
|---|
|  | 94 | cloneAll( other.assigns, assigns ); | 
|---|
|  | 95 | // xxx - clone needs to go into assigns and replace tempDecls | 
|---|
|  | 96 | } | 
|---|
|  | 97 |  | 
|---|
|  | 98 | TupleAssignExpr::~TupleAssignExpr() { | 
|---|
|  | 99 | deleteAll( assigns ); | 
|---|
|  | 100 | // deleteAll( tempDecls ); | 
|---|
|  | 101 | } | 
|---|
|  | 102 |  | 
|---|
|  | 103 | void TupleAssignExpr::print( std::ostream &os, int indent ) const { | 
|---|
| [3c13c03] | 104 | os << "Tuple Assignment Expression, with temporaries:" << std::endl; | 
|---|
| [6eb8948] | 105 | printAll( tempDecls, os, indent+4 ); | 
|---|
|  | 106 | os << std::string( indent+2, ' ' ) << "with assignments: " << std::endl; | 
|---|
|  | 107 | printAll( assigns, os, indent+4 ); | 
|---|
|  | 108 | Expression::print( os, indent ); | 
|---|
|  | 109 | } | 
|---|
|  | 110 |  | 
|---|
|  | 111 |  | 
|---|
|  | 112 |  | 
|---|
| [0dd3a2f] | 113 | // Local Variables: // | 
|---|
|  | 114 | // tab-width: 4 // | 
|---|
|  | 115 | // mode: c++ // | 
|---|
|  | 116 | // compile-command: "make install" // | 
|---|
|  | 117 | // End: // | 
|---|