[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 | //
|
---|
[51b73452] | 15 |
|
---|
[e3e16bc] | 16 | #include <cassert> // for assert, strict_dynamic_cast, assertf
|
---|
[ea6332d] | 17 | #include <iterator> // for next
|
---|
| 18 | #include <list> // for list, _List_iterator
|
---|
| 19 | #include <ostream> // for ostream, operator<<, basic_ostream, endl
|
---|
| 20 | #include <string> // for operator<<, string, char_traits
|
---|
| 21 |
|
---|
| 22 | #include "Common/utility.h" // for cloneAll, deleteAll, printAll, toString
|
---|
| 23 | #include "Declaration.h" // for ObjectDecl
|
---|
| 24 | #include "Expression.h" // for Expression, TupleExpr, TupleIndexExpr
|
---|
[ba3706f] | 25 | #include "SynTree/Label.h" // for Label
|
---|
[ea6332d] | 26 | #include "SynTree/Statement.h" // for CompoundStmt, DeclStmt, ExprStmt, Sta...
|
---|
| 27 | #include "Tuples/Tuples.h" // for makeTupleType
|
---|
| 28 | #include "Type.h" // for TupleType, Type
|
---|
[51b73452] | 29 |
|
---|
[bf4b4cf] | 30 | UntypedTupleExpr::UntypedTupleExpr( const std::list< Expression * > & exprs ) : Expression(), exprs( exprs ) {
|
---|
[907eccb] | 31 | }
|
---|
| 32 |
|
---|
| 33 | UntypedTupleExpr::UntypedTupleExpr( const UntypedTupleExpr &other ) : Expression( other ) {
|
---|
| 34 | cloneAll( other.exprs, exprs );
|
---|
| 35 | }
|
---|
| 36 |
|
---|
[50377a4] | 37 | void UntypedTupleExpr::print( std::ostream &os, Indenter indent ) const {
|
---|
[907eccb] | 38 | os << "Untyped Tuple:" << std::endl;
|
---|
[50377a4] | 39 | printAll( exprs, os, indent+1 );
|
---|
[907eccb] | 40 | Expression::print( os, indent );
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[bf4b4cf] | 43 | TupleExpr::TupleExpr( const std::list< Expression * > & exprs ) : Expression(), exprs( exprs ) {
|
---|
[907eccb] | 44 | set_result( Tuples::makeTupleType( exprs ) );
|
---|
[51b73452] | 45 | }
|
---|
| 46 |
|
---|
[0dd3a2f] | 47 | TupleExpr::TupleExpr( const TupleExpr &other ) : Expression( other ) {
|
---|
| 48 | cloneAll( other.exprs, exprs );
|
---|
[51b73452] | 49 | }
|
---|
| 50 |
|
---|
[50377a4] | 51 | void TupleExpr::print( std::ostream &os, Indenter indent ) const {
|
---|
[aa8f9df] | 52 | os << "Tuple:" << std::endl;
|
---|
[50377a4] | 53 | printAll( exprs, os, indent+1 );
|
---|
[0dd3a2f] | 54 | Expression::print( os, indent );
|
---|
[51b73452] | 55 | }
|
---|
| 56 |
|
---|
[3c13c03] | 57 | TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) : tuple( tuple ), index( index ) {
|
---|
[e3e16bc] | 58 | TupleType * type = strict_dynamic_cast< TupleType * >( tuple->get_result() );
|
---|
[6c3a988f] | 59 | 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] | 60 | set_result( (*std::next( type->get_types().begin(), index ))->clone() );
|
---|
[5ccb10d] | 61 | // like MemberExpr, TupleIndexExpr is always an lvalue
|
---|
| 62 | get_result()->set_lvalue( true );
|
---|
[3b58d91] | 63 | }
|
---|
| 64 |
|
---|
| 65 | TupleIndexExpr::TupleIndexExpr( const TupleIndexExpr &other ) : Expression( other ), tuple( other.tuple->clone() ), index( other.index ) {
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[50377a4] | 68 | void TupleIndexExpr::print( std::ostream &os, Indenter indent ) const {
|
---|
[aa8f9df] | 69 | os << "Tuple Index Expression, with tuple:" << std::endl;
|
---|
[50377a4] | 70 | os << indent+1;
|
---|
| 71 | tuple->print( os, indent+1 );
|
---|
| 72 | os << indent+1 << "with index: " << index << std::endl;
|
---|
[3b58d91] | 73 | Expression::print( os, indent );
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[bf4b4cf] | 76 | TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls ) : Expression() {
|
---|
[d5556a3] | 77 | // convert internally into a StmtExpr which contains the declarations and produces the tuple of the assignments
|
---|
[65660bd] | 78 | set_result( Tuples::makeTupleType( assigns ) );
|
---|
[ba3706f] | 79 | CompoundStmt * compoundStmt = new CompoundStmt();
|
---|
[d5556a3] | 80 | std::list< Statement * > & stmts = compoundStmt->get_kids();
|
---|
| 81 | for ( ObjectDecl * obj : tempDecls ) {
|
---|
[ba3706f] | 82 | stmts.push_back( new DeclStmt( obj ) );
|
---|
[d5556a3] | 83 | }
|
---|
| 84 | TupleExpr * tupleExpr = new TupleExpr( assigns );
|
---|
| 85 | assert( tupleExpr->get_result() );
|
---|
[ba3706f] | 86 | stmts.push_back( new ExprStmt( tupleExpr ) );
|
---|
[d5556a3] | 87 | stmtExpr = new StmtExpr( compoundStmt );
|
---|
[6eb8948] | 88 | }
|
---|
| 89 |
|
---|
[23bb1b9] | 90 | TupleAssignExpr::TupleAssignExpr( const TupleAssignExpr &other ) : Expression( other ) {
|
---|
[d5556a3] | 91 | assert( other.stmtExpr );
|
---|
| 92 | stmtExpr = other.stmtExpr->clone();
|
---|
[6eb8948] | 93 | }
|
---|
| 94 |
|
---|
[50377a4] | 95 | void TupleAssignExpr::print( std::ostream &os, Indenter indent ) const {
|
---|
[d5556a3] | 96 | os << "Tuple Assignment Expression, with stmt expr:" << std::endl;
|
---|
[50377a4] | 97 | os << indent+1;
|
---|
| 98 | stmtExpr->print( os, indent+1 );
|
---|
[6eb8948] | 99 | Expression::print( os, indent );
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 |
|
---|
[0dd3a2f] | 104 | // Local Variables: //
|
---|
| 105 | // tab-width: 4 //
|
---|
| 106 | // mode: c++ //
|
---|
| 107 | // compile-command: "make install" //
|
---|
| 108 | // End: //
|
---|