source: src/SynTree/TupleExpr.cc @ d5556a3

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since d5556a3 was d5556a3, checked in by Rob Schluntz <rschlunt@…>, 5 years ago

change rework TupleAssignExpr? and StmtExpr?

  • Property mode set to 100644
File size: 4.1 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#include "VarExprReplacer.h"
22
23TupleExpr::TupleExpr( const std::list< Expression * > & exprs, Expression *_aname ) : Expression( _aname ), exprs( exprs ) {
24        if ( ! exprs.empty() ) {
25                if ( std::all_of( exprs.begin(), exprs.end(), [](Expression * expr) { return expr->get_result(); } ) ) {
26                        set_result( Tuples::makeTupleType( exprs ) );
27                }
28        }
29}
30
31TupleExpr::TupleExpr( const TupleExpr &other ) : Expression( other ) {
32        cloneAll( other.exprs, exprs );
33}
34
35TupleExpr::~TupleExpr() {
36        deleteAll( exprs );
37}
38
39void TupleExpr::print( std::ostream &os, int indent ) const {
40        os << "Tuple:" << std::endl;
41        printAll( exprs, os, indent+2 );
42        Expression::print( os, indent );
43}
44
45TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) : tuple( tuple ), index( index )  {
46        TupleType * type = safe_dynamic_cast< TupleType * >( tuple->get_result() );
47        assert( type->size() > index );
48        set_result( (*std::next( type->get_types().begin(), index ))->clone() );
49        get_result()->set_isLvalue( type->get_isLvalue() );
50}
51
52TupleIndexExpr::TupleIndexExpr( const TupleIndexExpr &other ) : Expression( other ), tuple( other.tuple->clone() ), index( other.index ) {
53}
54
55TupleIndexExpr::~TupleIndexExpr() {
56        delete tuple;
57}
58
59void TupleIndexExpr::print( std::ostream &os, int indent ) const {
60        os << "Tuple Index Expression, with tuple:" << std::endl;
61        os << std::string( indent+2, ' ' );
62        tuple->print( os, indent+2 );
63        os << std::string( indent+2, ' ' ) << "with index: " << index << std::endl;
64        Expression::print( os, indent );
65}
66
67MemberTupleExpr::MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname ) : Expression( _aname ) {
68        set_result( maybeClone( member->get_result() ) ); // xxx - ???
69}
70
71MemberTupleExpr::MemberTupleExpr( const MemberTupleExpr &other ) : Expression( other ), member( other.member->clone() ), aggregate( other.aggregate->clone() ) {
72}
73
74MemberTupleExpr::~MemberTupleExpr() {
75        delete member;
76        delete aggregate;
77}
78
79void MemberTupleExpr::print( std::ostream &os, int indent ) const {
80        os << "Member Tuple Expression, with aggregate:" << std::endl;
81        os << std::string( indent+2, ' ' );
82        aggregate->print( os, indent+2 );
83        os << std::string( indent+2, ' ' ) << "with member: " << std::endl;
84        os << std::string( indent+2, ' ' );
85        member->print( os, indent+2 );
86        Expression::print( os, indent );
87}
88
89TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname ) : Expression( _aname ) {
90        // convert internally into a StmtExpr which contains the declarations and produces the tuple of the assignments
91        set_result( Tuples::makeTupleType( assigns ) );
92        CompoundStmt * compoundStmt = new CompoundStmt( noLabels );
93        std::list< Statement * > & stmts = compoundStmt->get_kids();
94        for ( ObjectDecl * obj : tempDecls ) {
95                stmts.push_back( new DeclStmt( noLabels, obj ) );
96        }
97        TupleExpr * tupleExpr = new TupleExpr( assigns );
98        assert( tupleExpr->get_result() );
99        stmts.push_back( new ExprStmt( noLabels, tupleExpr ) );
100        stmtExpr = new StmtExpr( compoundStmt );
101}
102
103TupleAssignExpr::TupleAssignExpr( const TupleAssignExpr &other ) : Expression( other ) {
104        assert( other.stmtExpr );
105        stmtExpr = other.stmtExpr->clone();
106}
107
108TupleAssignExpr::~TupleAssignExpr() {
109        delete stmtExpr;
110}
111
112void TupleAssignExpr::print( std::ostream &os, int indent ) const {
113        os << "Tuple Assignment Expression, with stmt expr:" << std::endl;
114        os << std::string( indent+2, ' ' );
115        stmtExpr->print( os, indent+4 );
116        Expression::print( os, indent );
117}
118
119
120
121// Local Variables: //
122// tab-width: 4 //
123// mode: c++ //
124// compile-command: "make install" //
125// End: //
Note: See TracBrowser for help on using the repository browser.