source: src/SynTree/TupleExpr.cc @ 3c13c03

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 3c13c03 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
RevLine 
[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//
[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"
[51b7345]21
[3c13c03]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        }
[51b7345]28}
29
[0dd3a2f]30TupleExpr::TupleExpr( const TupleExpr &other ) : Expression( other ) {
31        cloneAll( other.exprs, exprs );
[51b7345]32}
33
[0dd3a2f]34TupleExpr::~TupleExpr() {
35        deleteAll( exprs );
[51b7345]36}
37
[0dd3a2f]38void TupleExpr::print( std::ostream &os, int indent ) const {
[aa8f9df]39        os << "Tuple:" << std::endl;
[0dd3a2f]40        printAll( exprs, os, indent+2 );
41        Expression::print( os, indent );
[51b7345]42}
43
[3c13c03]44TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) : tuple( tuple ), index( index )  {
[aa8f9df]45        TupleType * type = safe_dynamic_cast< TupleType * >( tuple->get_result() );
[3c13c03]46        assert( type->size() > index );
47        set_result( (*std::next( type->get_types().begin(), index ))->clone() );
[3b58d91]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 {
[aa8f9df]58        os << "Tuple Index Expression, with tuple:" << std::endl;
[3c13c03]59        os << std::string( indent+2, ' ' );
[3b58d91]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 ) {
[aa8f9df]66        set_result( maybeClone( member->get_result() ) ); // xxx - ???
[3b58d91]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 {
[aa8f9df]78        os << "Member Tuple Expression, with aggregate:" << std::endl;
[3c13c03]79        os << std::string( indent+2, ' ' );
[3b58d91]80        aggregate->print( os, indent+2 );
81        os << std::string( indent+2, ' ' ) << "with member: " << std::endl;
[3c13c03]82        os << std::string( indent+2, ' ' );
[3b58d91]83        member->print( os, indent+2 );
84        Expression::print( os, indent );
85}
86
87
[6eb8948]88TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname ) : Expression( _aname ), assigns( assigns ), tempDecls( tempDecls ) {
[aa8f9df]89        TupleType * type = new TupleType( Type::Qualifiers() );
[6eb8948]90        for ( Expression * expr : assigns ) {
[aa8f9df]91                assert( expr->has_result() );
92                type->get_types().push_back( expr->get_result()->clone() );
[6eb8948]93        }
[aa8f9df]94        set_result( type );
[6eb8948]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 {
[3c13c03]108        os << "Tuple Assignment Expression, with temporaries:" << std::endl;
[6eb8948]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
[0dd3a2f]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.