source: src/SynTree/TupleExpr.cc @ 029cbc0

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 029cbc0 was b4f8808, checked in by Andrew Beach <ajbeach@…>, 5 years ago

Removed lvalue from types in the old ast.

  • 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 : Andrew Beach
12// Last Modified On : Wed Aug 14 14:34:00 2019
13// Update Count     : 5
14//
15
16#include <cassert>              // for assert, strict_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
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(), 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, Indenter indent ) const {
42        os << "Untyped Tuple:" << std::endl;
43        printAll( exprs, os, indent+1 );
44        Expression::print( os, indent );
45}
46
47TupleExpr::TupleExpr( const std::list< Expression * > & exprs ) : Expression(), 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
59bool TupleExpr::get_lvalue() const {
60        return false;
61}
62
63void TupleExpr::print( std::ostream &os, Indenter indent ) const {
64        os << "Tuple:" << std::endl;
65        printAll( exprs, os, indent+1 );
66        Expression::print( os, indent );
67}
68
69TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) : tuple( tuple ), index( index )  {
70        TupleType * type = strict_dynamic_cast< TupleType * >( tuple->get_result() );
71        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() );
72        set_result( (*std::next( type->get_types().begin(), index ))->clone() );
73}
74
75TupleIndexExpr::TupleIndexExpr( const TupleIndexExpr &other ) : Expression( other ), tuple( other.tuple->clone() ), index( other.index ) {
76}
77
78TupleIndexExpr::~TupleIndexExpr() {
79        delete tuple;
80}
81
82bool TupleIndexExpr::get_lvalue() const {
83        return tuple->get_lvalue();
84}
85
86void TupleIndexExpr::print( std::ostream &os, Indenter indent ) const {
87        os << "Tuple Index Expression, with tuple:" << std::endl;
88        os << indent+1;
89        tuple->print( os, indent+1 );
90        os << indent+1 << "with index: " << index << std::endl;
91        Expression::print( os, indent );
92}
93
94TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls ) : Expression() {
95        // convert internally into a StmtExpr which contains the declarations and produces the tuple of the assignments
96        set_result( Tuples::makeTupleType( assigns ) );
97        CompoundStmt * compoundStmt = new CompoundStmt();
98        std::list< Statement * > & stmts = compoundStmt->get_kids();
99        for ( ObjectDecl * obj : tempDecls ) {
100                stmts.push_back( new DeclStmt( obj ) );
101        }
102        TupleExpr * tupleExpr = new TupleExpr( assigns );
103        assert( tupleExpr->get_result() );
104        stmts.push_back( new ExprStmt( tupleExpr ) );
105        stmtExpr = new StmtExpr( compoundStmt );
106}
107
108TupleAssignExpr::TupleAssignExpr( const TupleAssignExpr &other ) : Expression( other ) {
109        assert( other.stmtExpr );
110        stmtExpr = other.stmtExpr->clone();
111}
112
113TupleAssignExpr::TupleAssignExpr( 
114        StmtExpr * s )
115: Expression(), stmtExpr(s) {
116}
117
118
119TupleAssignExpr::~TupleAssignExpr() {
120        delete stmtExpr;
121}
122
123void TupleAssignExpr::print( std::ostream &os, Indenter indent ) const {
124        os << "Tuple Assignment Expression, with stmt expr:" << std::endl;
125        os << indent+1;
126        stmtExpr->print( os, indent+1 );
127        Expression::print( os, indent );
128}
129
130
131
132// Local Variables: //
133// tab-width: 4 //
134// mode: c++ //
135// compile-command: "make install" //
136// End: //
Note: See TracBrowser for help on using the repository browser.