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