source: src/SynTree/TupleExpr.cc @ 8780e30

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 8780e30 was 65660bd, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

replace multiple-returning functions with tuple-returning functions, implement tuple ctor/dtor, allow N-arg tuple assignment

  • Property mode set to 100644
File size: 3.8 KB
Line 
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//
7// TupleExpr.cc --
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//
15
16#include "Expression.h"
17#include "Common/utility.h"
18#include "Type.h"
19#include "Declaration.h"
20#include "Tuples/Tuples.h"
21
22TupleExpr::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        }
28}
29
30TupleExpr::TupleExpr( const TupleExpr &other ) : Expression( other ) {
31        cloneAll( other.exprs, exprs );
32}
33
34TupleExpr::~TupleExpr() {
35        deleteAll( exprs );
36}
37
38void TupleExpr::print( std::ostream &os, int indent ) const {
39        os << "Tuple:" << std::endl;
40        printAll( exprs, os, indent+2 );
41        Expression::print( os, indent );
42}
43
44TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) : tuple( tuple ), index( index )  {
45        TupleType * type = safe_dynamic_cast< TupleType * >( tuple->get_result() );
46        assert( type->size() > index );
47        set_result( (*std::next( type->get_types().begin(), index ))->clone() );
48        get_result()->set_isLvalue( type->get_isLvalue() );
49}
50
51TupleIndexExpr::TupleIndexExpr( const TupleIndexExpr &other ) : Expression( other ), tuple( other.tuple->clone() ), index( other.index ) {
52}
53
54TupleIndexExpr::~TupleIndexExpr() {
55        delete tuple;
56}
57
58void TupleIndexExpr::print( std::ostream &os, int indent ) const {
59        os << "Tuple Index Expression, with tuple:" << std::endl;
60        os << std::string( indent+2, ' ' );
61        tuple->print( os, indent+2 );
62        os << std::string( indent+2, ' ' ) << "with index: " << index << std::endl;
63        Expression::print( os, indent );
64}
65
66MemberTupleExpr::MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname ) : Expression( _aname ) {
67        set_result( maybeClone( member->get_result() ) ); // xxx - ???
68}
69
70MemberTupleExpr::MemberTupleExpr( const MemberTupleExpr &other ) : Expression( other ), member( other.member->clone() ), aggregate( other.aggregate->clone() ) {
71}
72
73MemberTupleExpr::~MemberTupleExpr() {
74        delete member;
75        delete aggregate;
76}
77
78void MemberTupleExpr::print( std::ostream &os, int indent ) const {
79        os << "Member Tuple Expression, with aggregate:" << std::endl;
80        os << std::string( indent+2, ' ' );
81        aggregate->print( os, indent+2 );
82        os << std::string( indent+2, ' ' ) << "with member: " << std::endl;
83        os << std::string( indent+2, ' ' );
84        member->print( os, indent+2 );
85        Expression::print( os, indent );
86}
87
88
89TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname ) : Expression( _aname ), assigns( assigns ), tempDecls( tempDecls ) {
90        set_result( Tuples::makeTupleType( assigns ) );
91}
92
93TupleAssignExpr::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
98TupleAssignExpr::~TupleAssignExpr() {
99        deleteAll( assigns );
100        // deleteAll( tempDecls );
101}
102
103void TupleAssignExpr::print( std::ostream &os, int indent ) const {
104        os << "Tuple Assignment Expression, with temporaries:" << std::endl;
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
113// Local Variables: //
114// tab-width: 4 //
115// mode: c++ //
116// compile-command: "make install" //
117// End: //
Note: See TracBrowser for help on using the repository browser.