Ignore:
Timestamp:
Sep 17, 2016, 8:27:51 AM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
8c49c0e
Parents:
12bc63a
Message:

expand TupleExpr? and TupleIndexExpr?, add UniqueExpr?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/TupleExpr.cc

    r12bc63a r3c13c03  
    1818#include "Type.h"
    1919#include "Declaration.h"
     20#include "Tuples/Tuples.h"
    2021
    21 TupleExpr::TupleExpr( Expression *_aname ) : Expression( _aname ) {
     22TupleExpr::TupleExpr( const std::list< Expression * > & exprs, Expression *_aname ) : Expression( _aname ), exprs( exprs ) {
     23        if ( ! exprs.empty() ) {
     24                if ( std::all_of( exprs.begin(), exprs.end(), [](Expression * expr) { return expr->get_result(); } ) ) {
     25                        set_result( Tuples::makeTupleType( exprs ) );
     26                }
     27        }
    2228}
    2329
     
    3642}
    3743
    38 TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) {
     44TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) : tuple( tuple ), index( index )  {
    3945        TupleType * type = safe_dynamic_cast< TupleType * >( tuple->get_result() );
    40         assert( type->size() >= index );
    41         set_result( *std::next( type->get_types().begin(), index ) );
     46        assert( type->size() > index );
     47        set_result( (*std::next( type->get_types().begin(), index ))->clone() );
    4248}
    4349
     
    5157void TupleIndexExpr::print( std::ostream &os, int indent ) const {
    5258        os << "Tuple Index Expression, with tuple:" << std::endl;
     59        os << std::string( indent+2, ' ' );
    5360        tuple->print( os, indent+2 );
    5461        os << std::string( indent+2, ' ' ) << "with index: " << index << std::endl;
     
    7077void MemberTupleExpr::print( std::ostream &os, int indent ) const {
    7178        os << "Member Tuple Expression, with aggregate:" << std::endl;
     79        os << std::string( indent+2, ' ' );
    7280        aggregate->print( os, indent+2 );
    7381        os << std::string( indent+2, ' ' ) << "with member: " << std::endl;
     82        os << std::string( indent+2, ' ' );
    7483        member->print( os, indent+2 );
    7584        Expression::print( os, indent );
     
    97106
    98107void TupleAssignExpr::print( std::ostream &os, int indent ) const {
    99         os << std::string( indent, ' ' ) << "Tuple Assignment Expression, with temporaries:" << std::endl;
     108        os << "Tuple Assignment Expression, with temporaries:" << std::endl;
    100109        printAll( tempDecls, os, indent+4 );
    101110        os << std::string( indent+2, ' ' ) << "with assignments: " << std::endl;
Note: See TracChangeset for help on using the changeset viewer.