source: src/SynTree/TupleExpr.cc@ 90ce35aa

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 90ce35aa was 849720f, checked in by Andrew Beach <ajbeach@…>, 6 years ago

lvalue should now always come directly from the expression.

  • Property mode set to 100644
File size: 4.5 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
[14388c1]11// Last Modified By : Andrew Beach
[3c7f01b]12// Last Modified On : Wed Aug 14 14:34:00 2019
13// Update Count : 5
[0dd3a2f]14//
[51b73452]15
[e3e16bc]16#include <cassert> // for assert, strict_dynamic_cast, assertf
[ea6332d]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
[ba3706f]25#include "SynTree/Label.h" // for Label
[ea6332d]26#include "SynTree/Statement.h" // for CompoundStmt, DeclStmt, ExprStmt, Sta...
27#include "Tuples/Tuples.h" // for makeTupleType
28#include "Type.h" // for TupleType, Type
[51b73452]29
[bf4b4cf]30UntypedTupleExpr::UntypedTupleExpr( const std::list< Expression * > & exprs ) : Expression(), exprs( exprs ) {
[907eccb]31}
32
33UntypedTupleExpr::UntypedTupleExpr( const UntypedTupleExpr &other ) : Expression( other ) {
34 cloneAll( other.exprs, exprs );
35}
36
37UntypedTupleExpr::~UntypedTupleExpr() {
38 deleteAll( exprs );
39}
40
[50377a4]41void UntypedTupleExpr::print( std::ostream &os, Indenter indent ) const {
[907eccb]42 os << "Untyped Tuple:" << std::endl;
[50377a4]43 printAll( exprs, os, indent+1 );
[907eccb]44 Expression::print( os, indent );
45}
46
[bf4b4cf]47TupleExpr::TupleExpr( const std::list< Expression * > & exprs ) : Expression(), exprs( exprs ) {
[907eccb]48 set_result( Tuples::makeTupleType( exprs ) );
[51b73452]49}
50
[0dd3a2f]51TupleExpr::TupleExpr( const TupleExpr &other ) : Expression( other ) {
52 cloneAll( other.exprs, exprs );
[51b73452]53}
54
[0dd3a2f]55TupleExpr::~TupleExpr() {
56 deleteAll( exprs );
[51b73452]57}
58
[3c7f01b]59bool TupleExpr::get_lvalue() const {
[849720f]60 return false;
[3c7f01b]61}
62
[50377a4]63void TupleExpr::print( std::ostream &os, Indenter indent ) const {
[aa8f9df]64 os << "Tuple:" << std::endl;
[50377a4]65 printAll( exprs, os, indent+1 );
[0dd3a2f]66 Expression::print( os, indent );
[51b73452]67}
68
[3c13c03]69TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) : tuple( tuple ), index( index ) {
[e3e16bc]70 TupleType * type = strict_dynamic_cast< TupleType * >( tuple->get_result() );
[6c3a988f]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() );
[3c13c03]72 set_result( (*std::next( type->get_types().begin(), index ))->clone() );
[5ccb10d]73 // like MemberExpr, TupleIndexExpr is always an lvalue
74 get_result()->set_lvalue( true );
[3b58d91]75}
76
77TupleIndexExpr::TupleIndexExpr( const TupleIndexExpr &other ) : Expression( other ), tuple( other.tuple->clone() ), index( other.index ) {
78}
79
80TupleIndexExpr::~TupleIndexExpr() {
81 delete tuple;
82}
83
[14388c1]84bool TupleIndexExpr::get_lvalue() const {
[849720f]85 return tuple->get_lvalue();
[14388c1]86}
87
[50377a4]88void TupleIndexExpr::print( std::ostream &os, Indenter indent ) const {
[aa8f9df]89 os << "Tuple Index Expression, with tuple:" << std::endl;
[50377a4]90 os << indent+1;
91 tuple->print( os, indent+1 );
92 os << indent+1 << "with index: " << index << std::endl;
[3b58d91]93 Expression::print( os, indent );
94}
95
[bf4b4cf]96TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls ) : Expression() {
[d5556a3]97 // convert internally into a StmtExpr which contains the declarations and produces the tuple of the assignments
[65660bd]98 set_result( Tuples::makeTupleType( assigns ) );
[ba3706f]99 CompoundStmt * compoundStmt = new CompoundStmt();
[d5556a3]100 std::list< Statement * > & stmts = compoundStmt->get_kids();
101 for ( ObjectDecl * obj : tempDecls ) {
[ba3706f]102 stmts.push_back( new DeclStmt( obj ) );
[d5556a3]103 }
104 TupleExpr * tupleExpr = new TupleExpr( assigns );
105 assert( tupleExpr->get_result() );
[ba3706f]106 stmts.push_back( new ExprStmt( tupleExpr ) );
[d5556a3]107 stmtExpr = new StmtExpr( compoundStmt );
[6eb8948]108}
109
[23bb1b9]110TupleAssignExpr::TupleAssignExpr( const TupleAssignExpr &other ) : Expression( other ) {
[d5556a3]111 assert( other.stmtExpr );
112 stmtExpr = other.stmtExpr->clone();
[6eb8948]113}
114
[20de6fb]115TupleAssignExpr::TupleAssignExpr(
116 StmtExpr * s )
117: Expression(), stmtExpr(s) {
118}
119
120
[6eb8948]121TupleAssignExpr::~TupleAssignExpr() {
[d5556a3]122 delete stmtExpr;
[6eb8948]123}
124
[50377a4]125void TupleAssignExpr::print( std::ostream &os, Indenter indent ) const {
[d5556a3]126 os << "Tuple Assignment Expression, with stmt expr:" << std::endl;
[50377a4]127 os << indent+1;
128 stmtExpr->print( os, indent+1 );
[6eb8948]129 Expression::print( os, indent );
130}
131
132
133
[0dd3a2f]134// Local Variables: //
135// tab-width: 4 //
136// mode: c++ //
137// compile-command: "make install" //
138// End: //
Note: See TracBrowser for help on using the repository browser.