source: src/SynTree/TupleExpr.cc @ 8c49c0e

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 8c49c0e was 3c13c03, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

expand TupleExpr? and TupleIndexExpr?, add UniqueExpr?

  • Property mode set to 100644
File size: 3.9 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}
49
50TupleIndexExpr::TupleIndexExpr( const TupleIndexExpr &other ) : Expression( other ), tuple( other.tuple->clone() ), index( other.index ) {
51}
52
53TupleIndexExpr::~TupleIndexExpr() {
54        delete tuple;
55}
56
57void TupleIndexExpr::print( std::ostream &os, int indent ) const {
58        os << "Tuple Index Expression, with tuple:" << std::endl;
59        os << std::string( indent+2, ' ' );
60        tuple->print( os, indent+2 );
61        os << std::string( indent+2, ' ' ) << "with index: " << index << std::endl;
62        Expression::print( os, indent );
63}
64
65MemberTupleExpr::MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname ) : Expression( _aname ) {
66        set_result( maybeClone( member->get_result() ) ); // xxx - ???
67}
68
69MemberTupleExpr::MemberTupleExpr( const MemberTupleExpr &other ) : Expression( other ), member( other.member->clone() ), aggregate( other.aggregate->clone() ) {
70}
71
72MemberTupleExpr::~MemberTupleExpr() {
73        delete member;
74        delete aggregate;
75}
76
77void MemberTupleExpr::print( std::ostream &os, int indent ) const {
78        os << "Member Tuple Expression, with aggregate:" << std::endl;
79        os << std::string( indent+2, ' ' );
80        aggregate->print( os, indent+2 );
81        os << std::string( indent+2, ' ' ) << "with member: " << std::endl;
82        os << std::string( indent+2, ' ' );
83        member->print( os, indent+2 );
84        Expression::print( os, indent );
85}
86
87
88TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname ) : Expression( _aname ), assigns( assigns ), tempDecls( tempDecls ) {
89        TupleType * type = new TupleType( Type::Qualifiers() );
90        for ( Expression * expr : assigns ) {
91                assert( expr->has_result() );
92                type->get_types().push_back( expr->get_result()->clone() );
93        }
94        set_result( type );
95}
96
97TupleAssignExpr::TupleAssignExpr( const TupleAssignExpr &other ) : Expression( other ), tempDecls( other.tempDecls ) /* temporary */ {
98        cloneAll( other.assigns, assigns );
99        // xxx - clone needs to go into assigns and replace tempDecls
100}
101
102TupleAssignExpr::~TupleAssignExpr() {
103        deleteAll( assigns );
104        // deleteAll( tempDecls );
105}
106
107void TupleAssignExpr::print( std::ostream &os, int indent ) const {
108        os << "Tuple Assignment Expression, with temporaries:" << std::endl;
109        printAll( tempDecls, os, indent+4 );
110        os << std::string( indent+2, ' ' ) << "with assignments: " << std::endl;
111        printAll( assigns, os, indent+4 );
112        Expression::print( os, indent );
113}
114
115
116
117// Local Variables: //
118// tab-width: 4 //
119// mode: c++ //
120// compile-command: "make install" //
121// End: //
Note: See TracBrowser for help on using the repository browser.