source: src/SynTree/TupleExpr.cc @ fc56cdbf

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 fc56cdbf was 5ccb10d, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Set reference size to base size, clean up debug code, remove more old-style NULLs from prelude

  • 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 : Fri Mar 17 09:42:29 2017
13// Update Count     : 3
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
23UntypedTupleExpr::UntypedTupleExpr( const std::list< Expression * > & exprs, Expression *_aname ) : Expression( _aname ), exprs( exprs ) {
24}
25
26UntypedTupleExpr::UntypedTupleExpr( const UntypedTupleExpr &other ) : Expression( other ) {
27        cloneAll( other.exprs, exprs );
28}
29
30UntypedTupleExpr::~UntypedTupleExpr() {
31        deleteAll( exprs );
32}
33
34void UntypedTupleExpr::print( std::ostream &os, int indent ) const {
35        os << "Untyped Tuple:" << std::endl;
36        printAll( exprs, os, indent+2 );
37        Expression::print( os, indent );
38}
39
40TupleExpr::TupleExpr( const std::list< Expression * > & exprs, Expression *_aname ) : Expression( _aname ), exprs( exprs ) {
41        set_result( Tuples::makeTupleType( exprs ) );
42}
43
44TupleExpr::TupleExpr( const TupleExpr &other ) : Expression( other ) {
45        cloneAll( other.exprs, exprs );
46}
47
48TupleExpr::~TupleExpr() {
49        deleteAll( exprs );
50}
51
52void TupleExpr::print( std::ostream &os, int indent ) const {
53        os << "Tuple:" << std::endl;
54        printAll( exprs, os, indent+2 );
55        Expression::print( os, indent );
56}
57
58TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) : tuple( tuple ), index( index )  {
59        TupleType * type = safe_dynamic_cast< TupleType * >( tuple->get_result() );
60        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() );
61        set_result( (*std::next( type->get_types().begin(), index ))->clone() );
62        // like MemberExpr, TupleIndexExpr is always an lvalue
63        get_result()->set_lvalue( true );
64}
65
66TupleIndexExpr::TupleIndexExpr( const TupleIndexExpr &other ) : Expression( other ), tuple( other.tuple->clone() ), index( other.index ) {
67}
68
69TupleIndexExpr::~TupleIndexExpr() {
70        delete tuple;
71}
72
73void TupleIndexExpr::print( std::ostream &os, int indent ) const {
74        os << "Tuple Index Expression, with tuple:" << std::endl;
75        os << std::string( indent+2, ' ' );
76        tuple->print( os, indent+2 );
77        os << std::string( indent+2, ' ' ) << "with index: " << index << std::endl;
78        Expression::print( os, indent );
79}
80
81TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname ) : Expression( _aname ) {
82        // convert internally into a StmtExpr which contains the declarations and produces the tuple of the assignments
83        set_result( Tuples::makeTupleType( assigns ) );
84        CompoundStmt * compoundStmt = new CompoundStmt( noLabels );
85        std::list< Statement * > & stmts = compoundStmt->get_kids();
86        for ( ObjectDecl * obj : tempDecls ) {
87                stmts.push_back( new DeclStmt( noLabels, obj ) );
88        }
89        TupleExpr * tupleExpr = new TupleExpr( assigns );
90        assert( tupleExpr->get_result() );
91        stmts.push_back( new ExprStmt( noLabels, tupleExpr ) );
92        stmtExpr = new StmtExpr( compoundStmt );
93}
94
95TupleAssignExpr::TupleAssignExpr( const TupleAssignExpr &other ) : Expression( other ) {
96        assert( other.stmtExpr );
97        stmtExpr = other.stmtExpr->clone();
98}
99
100TupleAssignExpr::~TupleAssignExpr() {
101        delete stmtExpr;
102}
103
104void TupleAssignExpr::print( std::ostream &os, int indent ) const {
105        os << "Tuple Assignment Expression, with stmt expr:" << std::endl;
106        os << std::string( indent+2, ' ' );
107        stmtExpr->print( 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.