[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 |
---|
[615a096] | 12 | // Last Modified On : Fri Mar 17 09:42:29 2017 |
---|
| 13 | // Update Count : 3 |
---|
[0dd3a2f] | 14 | // |
---|
[51b7345] | 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" |
---|
[51b7345] | 22 | |
---|
[907eccb] | 23 | UntypedTupleExpr::UntypedTupleExpr( const std::list< Expression * > & exprs, Expression *_aname ) : Expression( _aname ), exprs( exprs ) { |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | UntypedTupleExpr::UntypedTupleExpr( const UntypedTupleExpr &other ) : Expression( other ) { |
---|
| 27 | cloneAll( other.exprs, exprs ); |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | UntypedTupleExpr::~UntypedTupleExpr() { |
---|
| 31 | deleteAll( exprs ); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | void UntypedTupleExpr::print( std::ostream &os, int indent ) const { |
---|
| 35 | os << "Untyped Tuple:" << std::endl; |
---|
| 36 | printAll( exprs, os, indent+2 ); |
---|
| 37 | Expression::print( os, indent ); |
---|
| 38 | } |
---|
| 39 | |
---|
[3c13c03] | 40 | TupleExpr::TupleExpr( const std::list< Expression * > & exprs, Expression *_aname ) : Expression( _aname ), exprs( exprs ) { |
---|
[907eccb] | 41 | set_result( Tuples::makeTupleType( exprs ) ); |
---|
[51b7345] | 42 | } |
---|
| 43 | |
---|
[0dd3a2f] | 44 | TupleExpr::TupleExpr( const TupleExpr &other ) : Expression( other ) { |
---|
| 45 | cloneAll( other.exprs, exprs ); |
---|
[51b7345] | 46 | } |
---|
| 47 | |
---|
[0dd3a2f] | 48 | TupleExpr::~TupleExpr() { |
---|
| 49 | deleteAll( exprs ); |
---|
[51b7345] | 50 | } |
---|
| 51 | |
---|
[0dd3a2f] | 52 | void TupleExpr::print( std::ostream &os, int indent ) const { |
---|
[aa8f9df] | 53 | os << "Tuple:" << std::endl; |
---|
[0dd3a2f] | 54 | printAll( exprs, os, indent+2 ); |
---|
| 55 | Expression::print( os, indent ); |
---|
[51b7345] | 56 | } |
---|
| 57 | |
---|
[3c13c03] | 58 | TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) : tuple( tuple ), index( index ) { |
---|
[aa8f9df] | 59 | TupleType * type = safe_dynamic_cast< TupleType * >( tuple->get_result() ); |
---|
[6c3a988f] | 60 | assertf( type->size() > index, "TupleIndexExpr index out of bounds: tuple size %d, requested index %d in expr %s", type->size(), index, toString( tuple ).c_str() ); |
---|
[3c13c03] | 61 | set_result( (*std::next( type->get_types().begin(), index ))->clone() ); |
---|
[615a096] | 62 | get_result()->set_lvalue( type->get_lvalue() ); |
---|
[3b58d91] | 63 | } |
---|
| 64 | |
---|
| 65 | TupleIndexExpr::TupleIndexExpr( const TupleIndexExpr &other ) : Expression( other ), tuple( other.tuple->clone() ), index( other.index ) { |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | TupleIndexExpr::~TupleIndexExpr() { |
---|
| 69 | delete tuple; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | void TupleIndexExpr::print( std::ostream &os, int indent ) const { |
---|
[aa8f9df] | 73 | os << "Tuple Index Expression, with tuple:" << std::endl; |
---|
[3c13c03] | 74 | os << std::string( indent+2, ' ' ); |
---|
[3b58d91] | 75 | tuple->print( os, indent+2 ); |
---|
| 76 | os << std::string( indent+2, ' ' ) << "with index: " << index << std::endl; |
---|
| 77 | Expression::print( os, indent ); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | MemberTupleExpr::MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname ) : Expression( _aname ) { |
---|
[aa8f9df] | 81 | set_result( maybeClone( member->get_result() ) ); // xxx - ??? |
---|
[3b58d91] | 82 | } |
---|
| 83 | |
---|
| 84 | MemberTupleExpr::MemberTupleExpr( const MemberTupleExpr &other ) : Expression( other ), member( other.member->clone() ), aggregate( other.aggregate->clone() ) { |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | MemberTupleExpr::~MemberTupleExpr() { |
---|
| 88 | delete member; |
---|
| 89 | delete aggregate; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | void MemberTupleExpr::print( std::ostream &os, int indent ) const { |
---|
[aa8f9df] | 93 | os << "Member Tuple Expression, with aggregate:" << std::endl; |
---|
[3c13c03] | 94 | os << std::string( indent+2, ' ' ); |
---|
[3b58d91] | 95 | aggregate->print( os, indent+2 ); |
---|
| 96 | os << std::string( indent+2, ' ' ) << "with member: " << std::endl; |
---|
[3c13c03] | 97 | os << std::string( indent+2, ' ' ); |
---|
[3b58d91] | 98 | member->print( os, indent+2 ); |
---|
| 99 | Expression::print( os, indent ); |
---|
| 100 | } |
---|
| 101 | |
---|
[d5556a3] | 102 | TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname ) : Expression( _aname ) { |
---|
| 103 | // convert internally into a StmtExpr which contains the declarations and produces the tuple of the assignments |
---|
[65660bd] | 104 | set_result( Tuples::makeTupleType( assigns ) ); |
---|
[d5556a3] | 105 | CompoundStmt * compoundStmt = new CompoundStmt( noLabels ); |
---|
| 106 | std::list< Statement * > & stmts = compoundStmt->get_kids(); |
---|
| 107 | for ( ObjectDecl * obj : tempDecls ) { |
---|
| 108 | stmts.push_back( new DeclStmt( noLabels, obj ) ); |
---|
| 109 | } |
---|
| 110 | TupleExpr * tupleExpr = new TupleExpr( assigns ); |
---|
| 111 | assert( tupleExpr->get_result() ); |
---|
| 112 | stmts.push_back( new ExprStmt( noLabels, tupleExpr ) ); |
---|
| 113 | stmtExpr = new StmtExpr( compoundStmt ); |
---|
[6eb8948] | 114 | } |
---|
| 115 | |
---|
[23bb1b9] | 116 | TupleAssignExpr::TupleAssignExpr( const TupleAssignExpr &other ) : Expression( other ) { |
---|
[d5556a3] | 117 | assert( other.stmtExpr ); |
---|
| 118 | stmtExpr = other.stmtExpr->clone(); |
---|
[6eb8948] | 119 | } |
---|
| 120 | |
---|
| 121 | TupleAssignExpr::~TupleAssignExpr() { |
---|
[d5556a3] | 122 | delete stmtExpr; |
---|
[6eb8948] | 123 | } |
---|
| 124 | |
---|
| 125 | void TupleAssignExpr::print( std::ostream &os, int indent ) const { |
---|
[d5556a3] | 126 | os << "Tuple Assignment Expression, with stmt expr:" << std::endl; |
---|
| 127 | os << std::string( indent+2, ' ' ); |
---|
| 128 | stmtExpr->print( os, indent+4 ); |
---|
[6eb8948] | 129 | Expression::print( os, indent ); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | |
---|
[0dd3a2f] | 134 | // Local Variables: // |
---|
| 135 | // tab-width: 4 // |
---|
| 136 | // mode: c++ // |
---|
| 137 | // compile-command: "make install" // |
---|
| 138 | // End: // |
---|