source: src/SynTree/TupleExpr.cc @ ea6332d

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since ea6332d was ea6332d, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Big header cleaning pass - commit 3

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