Changeset 6eb8948


Ignore:
Timestamp:
Sep 12, 2016, 6:32:46 PM (5 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
f006f01
Parents:
8f7cea1
git-author:
Rob Schluntz <rschlunt@…> (09/12/16 18:24:34)
git-committer:
Rob Schluntz <rschlunt@…> (09/12/16 18:32:46)
Message:

make TupleAssignment? generate temporaries, add StmtExpr? for GCC statement expressions, expand tuple assignment expressions, collapse SolvedTupleExpr?, MassAssignExpr?, and MultipleAssignExpr? into TupleAssignExpr?

Location:
src
Files:
1 added
20 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r8f7cea1 r6eb8948  
    656656        }
    657657
     658        void CodeGenerator::visit( StmtExpr * stmtExpr ) {
     659                output << "(";
     660                stmtExpr->get_statements()->accept( *this );
     661                output << ")";
     662        }
     663
    658664        //*** Statements
    659665        void CodeGenerator::visit( CompoundStmt * compoundStmt ) {
  • src/CodeGen/CodeGenerator.h

    r8f7cea1 r6eb8948  
    7373                virtual void visit( TypeExpr *typeExpr );
    7474                virtual void visit( AsmExpr * );
     75                virtual void visit( StmtExpr * );
    7576
    7677                //*** Statements
  • src/InitTweak/InitTweak.cc

    r8f7cea1 r6eb8948  
    449449                // virtual void visit( LogicalExpr *logicalExpr );
    450450                // virtual void visit( ConditionalExpr *conditionalExpr );
    451                 virtual void visit( TupleExpr *tupleExpr ) { isConstExpr = false; }
    452                 virtual void visit( SolvedTupleExpr *tupleExpr ) { isConstExpr = false; }
    453451                virtual void visit( TypeExpr *typeExpr ) { isConstExpr = false; }
    454452                virtual void visit( AsmExpr *asmExpr ) { isConstExpr = false; }
    455453                virtual void visit( UntypedValofExpr *valofExpr ) { isConstExpr = false; }
    456454                virtual void visit( CompoundLiteralExpr *compLitExpr ) { isConstExpr = false; }
     455                virtual void visit( TupleExpr *tupleExpr ) { isConstExpr = false; }
     456                virtual void visit( TupleAssignExpr *tupleExpr ) { isConstExpr = false; }
    457457
    458458                bool isConstExpr;
  • src/Makefile.in

    r8f7cea1 r6eb8948  
    188188        SynTree/driver_cfa_cpp-TypeSubstitution.$(OBJEXT) \
    189189        SynTree/driver_cfa_cpp-Attribute.$(OBJEXT) \
    190         Tuples/driver_cfa_cpp-TupleAssignment.$(OBJEXT)
     190        Tuples/driver_cfa_cpp-TupleAssignment.$(OBJEXT) \
     191        Tuples/driver_cfa_cpp-TupleExpansion.$(OBJEXT)
    191192am_driver_cfa_cpp_OBJECTS = $(am__objects_1)
    192193driver_cfa_cpp_OBJECTS = $(am_driver_cfa_cpp_OBJECTS)
     
    400401        SynTree/Initializer.cc SynTree/Visitor.cc SynTree/Mutator.cc \
    401402        SynTree/AddStmtVisitor.cc SynTree/TypeSubstitution.cc \
    402         SynTree/Attribute.cc Tuples/TupleAssignment.cc
     403        SynTree/Attribute.cc Tuples/TupleAssignment.cc \
     404        Tuples/TupleExpansion.cc
    403405MAINTAINERCLEANFILES = Parser/parser.output ${libdir}/${notdir \
    404406        ${cfa_cpplib_PROGRAMS}}
     
    767769Tuples/driver_cfa_cpp-TupleAssignment.$(OBJEXT):  \
    768770        Tuples/$(am__dirstamp) Tuples/$(DEPDIR)/$(am__dirstamp)
     771Tuples/driver_cfa_cpp-TupleExpansion.$(OBJEXT):  \
     772        Tuples/$(am__dirstamp) Tuples/$(DEPDIR)/$(am__dirstamp)
    769773driver/$(am__dirstamp):
    770774        @$(MKDIR_P) driver
     
    874878        -rm -f SynTree/driver_cfa_cpp-VoidType.$(OBJEXT)
    875879        -rm -f Tuples/driver_cfa_cpp-TupleAssignment.$(OBJEXT)
     880        -rm -f Tuples/driver_cfa_cpp-TupleExpansion.$(OBJEXT)
    876881
    877882distclean-compile:
     
    978983@AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-VoidType.Po@am__quote@
    979984@AMDEP_TRUE@@am__include@ @am__quote@Tuples/$(DEPDIR)/driver_cfa_cpp-TupleAssignment.Po@am__quote@
     985@AMDEP_TRUE@@am__include@ @am__quote@Tuples/$(DEPDIR)/driver_cfa_cpp-TupleExpansion.Po@am__quote@
    980986
    981987.cc.o:
     
    23942400@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    23952401@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o Tuples/driver_cfa_cpp-TupleAssignment.obj `if test -f 'Tuples/TupleAssignment.cc'; then $(CYGPATH_W) 'Tuples/TupleAssignment.cc'; else $(CYGPATH_W) '$(srcdir)/Tuples/TupleAssignment.cc'; fi`
     2402
     2403Tuples/driver_cfa_cpp-TupleExpansion.o: Tuples/TupleExpansion.cc
     2404@am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT Tuples/driver_cfa_cpp-TupleExpansion.o -MD -MP -MF Tuples/$(DEPDIR)/driver_cfa_cpp-TupleExpansion.Tpo -c -o Tuples/driver_cfa_cpp-TupleExpansion.o `test -f 'Tuples/TupleExpansion.cc' || echo '$(srcdir)/'`Tuples/TupleExpansion.cc
     2405@am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) Tuples/$(DEPDIR)/driver_cfa_cpp-TupleExpansion.Tpo Tuples/$(DEPDIR)/driver_cfa_cpp-TupleExpansion.Po
     2406@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='Tuples/TupleExpansion.cc' object='Tuples/driver_cfa_cpp-TupleExpansion.o' libtool=no @AMDEPBACKSLASH@
     2407@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     2408@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o Tuples/driver_cfa_cpp-TupleExpansion.o `test -f 'Tuples/TupleExpansion.cc' || echo '$(srcdir)/'`Tuples/TupleExpansion.cc
     2409
     2410Tuples/driver_cfa_cpp-TupleExpansion.obj: Tuples/TupleExpansion.cc
     2411@am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT Tuples/driver_cfa_cpp-TupleExpansion.obj -MD -MP -MF Tuples/$(DEPDIR)/driver_cfa_cpp-TupleExpansion.Tpo -c -o Tuples/driver_cfa_cpp-TupleExpansion.obj `if test -f 'Tuples/TupleExpansion.cc'; then $(CYGPATH_W) 'Tuples/TupleExpansion.cc'; else $(CYGPATH_W) '$(srcdir)/Tuples/TupleExpansion.cc'; fi`
     2412@am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) Tuples/$(DEPDIR)/driver_cfa_cpp-TupleExpansion.Tpo Tuples/$(DEPDIR)/driver_cfa_cpp-TupleExpansion.Po
     2413@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='Tuples/TupleExpansion.cc' object='Tuples/driver_cfa_cpp-TupleExpansion.obj' libtool=no @AMDEPBACKSLASH@
     2414@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     2415@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o Tuples/driver_cfa_cpp-TupleExpansion.obj `if test -f 'Tuples/TupleExpansion.cc'; then $(CYGPATH_W) 'Tuples/TupleExpansion.cc'; else $(CYGPATH_W) '$(srcdir)/Tuples/TupleExpansion.cc'; fi`
    23962416
    23972417.ll.cc:
  • src/ResolvExpr/AlternativeFinder.cc

    r8f7cea1 r6eb8948  
    3838#include "SynTree/TypeSubstitution.h"
    3939#include "SymTab/Validate.h"
    40 #include "Tuples/TupleAssignment.h"
     40#include "Tuples/Tuples.h"
    4141#include "Common/utility.h"
    4242#include "InitTweak/InitTweak.h"
  • src/SymTab/Indexer.cc

    r8f7cea1 r6eb8948  
    452452        }
    453453
    454         void Indexer::visit( SolvedTupleExpr *tupleExpr ) {
     454        void Indexer::visit( TupleAssignExpr *tupleExpr ) {
    455455                acceptAllNewScope( tupleExpr->get_results(), *this );
    456                 acceptAll( tupleExpr->get_exprs(), *this );
     456                enterScope();
     457                acceptAll( tupleExpr->get_tempDecls(), *this );
     458                acceptAll( tupleExpr->get_assigns(), *this );
     459                leaveScope();
    457460        }
    458461
  • src/SymTab/Indexer.h

    r8f7cea1 r6eb8948  
    6464                virtual void visit( ConditionalExpr *conditionalExpr );
    6565                virtual void visit( CommaExpr *commaExpr );
    66                 virtual void visit( TupleExpr *tupleExpr );
    67                 virtual void visit( SolvedTupleExpr *tupleExpr );
    6866                virtual void visit( TypeExpr *typeExpr );
    6967                virtual void visit( AsmExpr *asmExpr );
    7068                virtual void visit( UntypedValofExpr *valofExpr );
     69                virtual void visit( TupleExpr *tupleExpr );
     70                virtual void visit( TupleAssignExpr *tupleExpr );
    7171
    7272                virtual void visit( TraitInstType *contextInst );
  • src/SynTree/Expression.cc

    r8f7cea1 r6eb8948  
    375375}
    376376
    377 
    378 UntypedExpr::UntypedExpr( Expression *_function, Expression *_aname ) : Expression( _aname ), function( _function ) {}
     377UntypedExpr::UntypedExpr( Expression *_function, const std::list<Expression *> &_args, Expression *_aname ) :
     378                Expression( _aname ), function(_function), args(_args) {}
    379379
    380380UntypedExpr::UntypedExpr( const UntypedExpr &other ) :
     
    382382        cloneAll( other.args, args );
    383383}
    384 
    385 UntypedExpr::UntypedExpr( Expression *_function, std::list<Expression *> &_args, Expression *_aname ) :
    386                 Expression( _aname ), function(_function), args(_args) {}
    387384
    388385UntypedExpr::~UntypedExpr() {
     
    568565}
    569566
     567StmtExpr::StmtExpr( CompoundStmt *statements ) : statements( statements ) {
     568        assert( statements );
     569        std::list< Statement * > & body = statements->get_kids();
     570        if ( ! body.empty() ) {
     571                if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) {
     572                        cloneAll( exprStmt->get_expr()->get_results(), get_results() );
     573                }
     574        }
     575}
     576StmtExpr::StmtExpr( const StmtExpr &other ) : statements( other.statements->clone() ) {}
     577StmtExpr::~StmtExpr() {
     578        delete statements;
     579}
     580void StmtExpr::print( std::ostream &os, int indent ) const {
     581        os << std::string( indent, ' ' ) << "Statement Expression: " << std::endl;
     582        statements->print( os, indent+2 );
     583}
     584
    570585std::ostream & operator<<( std::ostream & out, const Expression * expr ) {
    571586        expr->print( out );
  • src/SynTree/Expression.h

    r8f7cea1 r6eb8948  
    9898class UntypedExpr : public Expression {
    9999  public:
    100         UntypedExpr( Expression *function, Expression *_aname = nullptr );
     100        UntypedExpr( Expression *function, const std::list<Expression *> &args = std::list< Expression * >(), Expression *_aname = nullptr );
    101101        UntypedExpr( const UntypedExpr &other );
    102         UntypedExpr( Expression *function, std::list<Expression *> &args, Expression *_aname = nullptr );
    103102        virtual ~UntypedExpr();
    104103
     
    483482};
    484483
    485 /// TupleExpr represents a tuple expression ( [a, b, c] )
    486 class TupleExpr : public Expression {
    487   public:
    488         TupleExpr( Expression *_aname = nullptr );
    489         TupleExpr( const TupleExpr &other );
    490         virtual ~TupleExpr();
    491 
    492         void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; }
    493         std::list<Expression*>& get_exprs() { return exprs; }
    494 
    495         virtual TupleExpr *clone() const { return new TupleExpr( *this ); }
    496         virtual void accept( Visitor &v ) { v.visit( this ); }
    497         virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    498         virtual void print( std::ostream &os, int indent = 0 ) const;
    499   private:
    500         std::list<Expression*> exprs;
    501 };
    502 
    503 /// SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on
    504 class SolvedTupleExpr : public Expression {
    505   public:
    506         SolvedTupleExpr( Expression *_aname = nullptr ) : Expression( _aname ) {}
    507         SolvedTupleExpr( std::list<Expression *> &, Expression *_aname = nullptr );
    508         SolvedTupleExpr( const SolvedTupleExpr &other );
    509         virtual ~SolvedTupleExpr() {}
    510 
    511         std::list<Expression*> &get_exprs() { return exprs; }
    512 
    513         virtual SolvedTupleExpr *clone() const { return new SolvedTupleExpr( *this ); }
    514         virtual void accept( Visitor &v ) { v.visit( this ); }
    515         virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    516         virtual void print( std::ostream &os, int indent = 0 ) const;
    517   private:
    518         std::list<Expression*> exprs;
    519 };
    520 
    521484/// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
    522485class TypeExpr : public Expression {
     
    672635};
    673636
     637/// TupleExpr represents a tuple expression ( [a, b, c] )
     638class TupleExpr : public Expression {
     639  public:
     640        TupleExpr( Expression *_aname = nullptr );
     641        TupleExpr( const TupleExpr &other );
     642        virtual ~TupleExpr();
     643
     644        void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; }
     645        std::list<Expression*>& get_exprs() { return exprs; }
     646
     647        virtual TupleExpr *clone() const { return new TupleExpr( *this ); }
     648        virtual void accept( Visitor &v ) { v.visit( this ); }
     649        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     650        virtual void print( std::ostream &os, int indent = 0 ) const;
     651  private:
     652        std::list<Expression*> exprs;
     653};
     654
    674655/// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer
    675656class TupleIndexExpr : public Expression {
     
    714695};
    715696
    716 /// MultipleAssignExpr represents a multiple assignment operation, where both sides of the assignment have tuple type, e.g. [a, b, c] = [d, e, f];
    717 class MultipleAssignExpr : public Expression {
    718   public:
    719         MultipleAssignExpr( Expression * lhs, Expression * rhs );
    720         MultipleAssignExpr( const MultipleAssignExpr &other );
    721         virtual ~MultipleAssignExpr();
    722 
    723         Expression * get_lhs() const { return lhs; }
    724         Expression * get_rhs() const { return rhs; }
    725         MultipleAssignExpr * set_lhs( Expression *newValue ) { lhs = newValue; return this; }
    726         MultipleAssignExpr * set_rhs( Expression *newValue ) { rhs = newValue; return this; }
    727 
    728         virtual MultipleAssignExpr *clone() const { return new MultipleAssignExpr( *this ); }
    729         virtual void accept( Visitor &v ) { v.visit( this ); }
    730         virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    731         virtual void print( std::ostream &os, int indent = 0 ) const;
    732   private:
    733         Expression * lhs;
    734         Expression * rhs;
    735 };
    736 
    737 /// MassAssignExpr represents a mass assignment operations, where the left hand side has tuple type and the right hand side does not, e.g. [a, b, c] = 5.0;
    738 class MassAssignExpr : public Expression {
    739   public:
    740         MassAssignExpr( Expression * tuple, int field );
    741         MassAssignExpr( const MassAssignExpr &other );
    742         virtual ~MassAssignExpr();
    743 
    744         Expression * get_lhs() const { return lhs; }
    745         Expression * get_rhs() const { return rhs; }
    746         MassAssignExpr * set_lhs( Expression *newValue ) { lhs = newValue; return this; }
    747         MassAssignExpr * set_rhs( Expression *newValue ) { rhs = newValue; return this; }
    748 
    749         virtual MassAssignExpr *clone() const { return new MassAssignExpr( *this ); }
    750         virtual void accept( Visitor &v ) { v.visit( this ); }
    751         virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    752         virtual void print( std::ostream &os, int indent = 0 ) const;
    753   private:
    754         Expression * lhs; // multiple exprs
    755         Expression * rhs; // single expr
     697/// TupleAssignExpr represents a multiple assignment operation, where both sides of the assignment have tuple type, e.g. [a, b, c] = [d, e, f];, or a mass assignment operation, where the left hand side has tuple type and the right hand side does not, e.g. [a, b, c] = 5.0;
     698class TupleAssignExpr : public Expression {
     699  public:
     700        TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr );
     701        TupleAssignExpr( const TupleAssignExpr &other );
     702        virtual ~TupleAssignExpr();
     703
     704        std::list< Expression * > & get_assigns() { return assigns; }
     705        std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
     706
     707        virtual TupleAssignExpr *clone() const { return new TupleAssignExpr( *this ); }
     708        virtual void accept( Visitor &v ) { v.visit( this ); }
     709        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     710        virtual void print( std::ostream &os, int indent = 0 ) const;
     711  private:
     712        std::list< Expression * > assigns; // assignment expressions that use tempDecls
     713        std::list< ObjectDecl * > tempDecls; // temporaries for address of lhs exprs
     714};
     715
     716/// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; })
     717class StmtExpr : public Expression {
     718public:
     719        StmtExpr( CompoundStmt *statements );
     720        StmtExpr( const StmtExpr & other );
     721        virtual ~StmtExpr();
     722
     723        CompoundStmt * get_statements() const { return statements; }
     724        StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
     725
     726        virtual StmtExpr *clone() const { return new StmtExpr( *this ); }
     727        virtual void accept( Visitor &v ) { v.visit( this ); }
     728        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     729        virtual void print( std::ostream &os, int indent = 0 ) const;
     730private:
     731        CompoundStmt * statements;
    756732};
    757733
  • src/SynTree/Mutator.cc

    r8f7cea1 r6eb8948  
    308308}
    309309
    310 Expression *Mutator::mutate( TupleExpr *tupleExpr ) {
    311         mutateAll( tupleExpr->get_results(), *this );
    312         mutateAll( tupleExpr->get_exprs(), *this );
    313         return tupleExpr;
    314 }
    315 
    316 Expression *Mutator::mutate( SolvedTupleExpr *tupleExpr ) {
    317         mutateAll( tupleExpr->get_results(), *this );
    318         mutateAll( tupleExpr->get_exprs(), *this );
    319         return tupleExpr;
    320 }
    321 
    322310Expression *Mutator::mutate( TypeExpr *typeExpr ) {
    323311        mutateAll( typeExpr->get_results(), *this );
     
    364352}
    365353
     354Expression *Mutator::mutate( TupleExpr *tupleExpr ) {
     355        mutateAll( tupleExpr->get_results(), *this );
     356        mutateAll( tupleExpr->get_exprs(), *this );
     357        return tupleExpr;
     358}
     359
    366360Expression *Mutator::mutate( TupleIndexExpr *tupleExpr ) {
    367361        mutateAll( tupleExpr->get_results(), *this );
     
    377371}
    378372
    379 Expression *Mutator::mutate( MultipleAssignExpr *assignExpr ) {
     373Expression *Mutator::mutate( TupleAssignExpr *assignExpr ) {
    380374        mutateAll( assignExpr->get_results(), *this );
    381         assignExpr->set_lhs( maybeMutate( assignExpr->get_lhs(), *this ) );
    382         assignExpr->set_rhs( maybeMutate( assignExpr->get_rhs(), *this ) );
     375        mutateAll( assignExpr->get_tempDecls(), *this );
     376        mutateAll( assignExpr->get_assigns(), *this );
    383377        return assignExpr;
    384378}
    385379
    386 Expression *Mutator::mutate( MassAssignExpr *assignExpr ) {
    387         mutateAll( assignExpr->get_results(), *this );
    388         assignExpr->set_lhs( maybeMutate( assignExpr->get_lhs(), *this ) );
    389         assignExpr->set_rhs( maybeMutate( assignExpr->get_rhs(), *this ) );
    390         return assignExpr;
     380Expression *Mutator::mutate( StmtExpr *stmtExpr ) {
     381        mutateAll( stmtExpr->get_results(), *this );
     382        stmtExpr->set_statements( maybeMutate( stmtExpr->get_statements(), *this ) );
     383        return stmtExpr;
    391384}
    392385
  • src/SynTree/Mutator.h

    r8f7cea1 r6eb8948  
    7171        virtual Expression* mutate( ConditionalExpr *conditionalExpr );
    7272        virtual Expression* mutate( CommaExpr *commaExpr );
    73         virtual Expression* mutate( TupleExpr *tupleExpr );
    74         virtual Expression* mutate( SolvedTupleExpr *tupleExpr );
    7573        virtual Expression* mutate( TypeExpr *typeExpr );
    7674        virtual Expression* mutate( AsmExpr *asmExpr );
     
    8078        virtual Expression* mutate( UntypedValofExpr *valofExpr );
    8179        virtual Expression* mutate( RangeExpr *rangeExpr );
     80        virtual Expression* mutate( TupleExpr *tupleExpr );
    8281        virtual Expression* mutate( TupleIndexExpr *tupleExpr );
    8382        virtual Expression* mutate( MemberTupleExpr *tupleExpr );
    84         virtual Expression* mutate( MultipleAssignExpr *assignExpr );
    85         virtual Expression* mutate( MassAssignExpr *assignExpr );
     83        virtual Expression* mutate( TupleAssignExpr *assignExpr );
     84        virtual Expression* mutate( StmtExpr * stmtExpr );
    8685
    8786        virtual Type* mutate( VoidType *basicType );
  • src/SynTree/SynTree.h

    r8f7cea1 r6eb8948  
    7676class ConditionalExpr;
    7777class CommaExpr;
    78 class TupleExpr;
    79 class SolvedTupleExpr;
    8078class TypeExpr;
    8179class AsmExpr;
     
    8583class UntypedValofExpr;
    8684class RangeExpr;
     85class TupleExpr;
    8786class TupleIndexExpr;
    8887class MemberTupleExpr;
    89 class MultipleAssignExpr;
    90 class MassAssignExpr;
     88class TupleAssignExpr;
     89class StmtExpr;
    9190
    9291class Type;
  • src/SynTree/TupleExpr.cc

    r8f7cea1 r6eb8948  
    1717#include "Common/utility.h"
    1818#include "Type.h"
     19#include "Declaration.h"
    1920
    2021TupleExpr::TupleExpr( Expression *_aname ) : Expression( _aname ) {
     
    3132void TupleExpr::print( std::ostream &os, int indent ) const {
    3233        os << std::string( indent, ' ' ) << "Tuple:" << std::endl;
    33         printAll( exprs, os, indent+2 );
    34         Expression::print( os, indent );
    35 }
    36 
    37 SolvedTupleExpr::SolvedTupleExpr( std::list<Expression *> &_exprs, Expression *_aname ) : Expression( _aname ) {
    38         std::copy(_exprs.begin(), _exprs.end(), back_inserter(exprs));
    39 }
    40 
    41 SolvedTupleExpr::SolvedTupleExpr( const SolvedTupleExpr &other ) : Expression( other ) {
    42         cloneAll( other.exprs, exprs );
    43 }
    44 
    45 void SolvedTupleExpr::print( std::ostream &os, int indent ) const {
    46         os << std::string( indent, ' ' ) << "Solved Tuple:" << std::endl;
    4734        printAll( exprs, os, indent+2 );
    4835        Expression::print( os, indent );
     
    9077
    9178
     79TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname ) : Expression( _aname ), assigns( assigns ), tempDecls( tempDecls ) {
     80        for ( Expression * expr : assigns ) {
     81                cloneAll( expr->get_results(), get_results() );
     82        }
     83}
     84
     85TupleAssignExpr::TupleAssignExpr( const TupleAssignExpr &other ) : Expression( other ), tempDecls( other.tempDecls ) /* temporary */ {
     86        cloneAll( other.assigns, assigns );
     87        // xxx - clone needs to go into assigns and replace tempDecls
     88}
     89
     90TupleAssignExpr::~TupleAssignExpr() {
     91        deleteAll( assigns );
     92        // deleteAll( tempDecls );
     93}
     94
     95void TupleAssignExpr::print( std::ostream &os, int indent ) const {
     96        os << std::string( indent, ' ' ) << "Tuple Assignment Expression, with temporaries:" << std::endl;
     97        printAll( tempDecls, os, indent+4 );
     98        os << std::string( indent+2, ' ' ) << "with assignments: " << std::endl;
     99        printAll( assigns, os, indent+4 );
     100        Expression::print( os, indent );
     101}
     102
     103
     104
    92105// Local Variables: //
    93106// tab-width: 4 //
  • src/SynTree/TupleType.cc

    r8f7cea1 r6eb8948  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // TupleType.cc -- 
     7// TupleType.cc --
    88//
    99// Author           : Richard C. Bilson
     
    1717#include "Common/utility.h"
    1818
    19 TupleType::TupleType( const Type::Qualifiers &tq ) : Type( tq ) {
     19TupleType::TupleType( const Type::Qualifiers &tq, const std::list< Type * > & types ) : Type( tq ), types( types ) {
    2020}
    2121
  • src/SynTree/Type.h

    r8f7cea1 r6eb8948  
    348348class TupleType : public Type {
    349349  public:
    350         TupleType( const Type::Qualifiers &tq );
     350        TupleType( const Type::Qualifiers &tq, const std::list< Type * > & types = std::list< Type * >() );
    351351        TupleType( const TupleType& );
    352352        virtual ~TupleType();
  • src/SynTree/Visitor.cc

    r8f7cea1 r6eb8948  
    261261}
    262262
    263 void Visitor::visit( TupleExpr *tupleExpr ) {
    264         acceptAll( tupleExpr->get_results(), *this );
    265         acceptAll( tupleExpr->get_exprs(), *this );
    266 }
    267 
    268 void Visitor::visit( SolvedTupleExpr *tupleExpr ) {
    269         acceptAll( tupleExpr->get_results(), *this );
    270         acceptAll( tupleExpr->get_exprs(), *this );
    271 }
    272 
    273263void Visitor::visit( TypeExpr *typeExpr ) {
    274264        acceptAll( typeExpr->get_results(), *this );
     
    309299}
    310300
     301void Visitor::visit( TupleExpr *tupleExpr ) {
     302        acceptAll( tupleExpr->get_results(), *this );
     303        acceptAll( tupleExpr->get_exprs(), *this );
     304}
     305
    311306void Visitor::visit( TupleIndexExpr *tupleExpr ) {
    312307        acceptAll( tupleExpr->get_results(), *this );
     
    320315}
    321316
    322 void Visitor::visit( MultipleAssignExpr *assignExpr ) {
     317void Visitor::visit( TupleAssignExpr *assignExpr ) {
    323318        acceptAll( assignExpr->get_results(), *this );
    324         maybeAccept( assignExpr->get_lhs(), *this );
    325         maybeAccept( assignExpr->get_rhs(), *this );
    326 }
    327 
    328 void Visitor::visit( MassAssignExpr *assignExpr ) {
    329         acceptAll( assignExpr->get_results(), *this );
    330         maybeAccept( assignExpr->get_lhs(), *this );
    331         maybeAccept( assignExpr->get_rhs(), *this );
     319        acceptAll( assignExpr->get_tempDecls(), *this );
     320        acceptAll( assignExpr->get_assigns(), *this );
     321}
     322
     323void Visitor::visit( StmtExpr *stmtExpr ) {
     324        acceptAll( stmtExpr->get_results(), *this );
     325        maybeAccept( stmtExpr->get_statements(), *this );
    332326}
    333327
  • src/SynTree/Visitor.h

    r8f7cea1 r6eb8948  
    7171        virtual void visit( ConditionalExpr *conditionalExpr );
    7272        virtual void visit( CommaExpr *commaExpr );
    73         virtual void visit( TupleExpr *tupleExpr );
    74         virtual void visit( SolvedTupleExpr *tupleExpr );
    7573        virtual void visit( TypeExpr *typeExpr );
    7674        virtual void visit( AsmExpr *asmExpr );
     
    8078        virtual void visit( UntypedValofExpr *valofExpr );
    8179        virtual void visit( RangeExpr *rangeExpr );
     80        virtual void visit( TupleExpr *tupleExpr );
    8281        virtual void visit( TupleIndexExpr *tupleExpr );
    8382        virtual void visit( MemberTupleExpr *tupleExpr );
    84         virtual void visit( MultipleAssignExpr *assignExpr );
    85         virtual void visit( MassAssignExpr *assignExpr );
     83        virtual void visit( TupleAssignExpr *assignExpr );
     84        virtual void visit( StmtExpr * stmtExpr );
    8685
    8786        virtual void visit( VoidType *basicType );
  • src/Tuples/TupleAssignment.cc

    r8f7cea1 r6eb8948  
    1818#include "ResolvExpr/typeops.h"
    1919#include "SynTree/Expression.h"
    20 #include "TupleAssignment.h"
     20#include "SynTree/Initializer.h"
     21#include "Tuples.h"
    2122#include "Common/SemanticError.h"
    2223
     
    4041                // records for assignment generation
    4142                struct Options {
    42                         std::list< ResolvExpr::AltList > get_best();
    4343                        void print( std::ostream & );
    4444                        int size() const { return options.size(); }
     
    5151                };
    5252
    53                 class Matcher {
     53                struct Matcher {
    5454                  public:
    5555                        Matcher( TupleAssignSpotter &spotter, Expression *_lhs, Expression *_rhs );
    5656                        virtual ~Matcher() {}
    5757                        virtual void match( std::list< Expression * > &out ) = 0;
    58                         virtual void solve() = 0;
    59                         static UntypedExpr *createAssgn( Expression *left, Expression *right );
    60                   protected:
    6158                        std::list< Expression * > lhs, rhs;
    6259                        TupleAssignSpotter &spotter;
    63                 };
    64 
    65                 class MassAssignMatcher : public Matcher {
     60                        std::list< ObjectDecl * > tmpDecls;
     61                };
     62
     63                struct MassAssignMatcher : public Matcher {
    6664                  public:
    6765                        MassAssignMatcher( TupleAssignSpotter &spotter, Expression *lhs, Expression *rhs ) : Matcher( spotter, lhs, rhs ) {
     
    6967                        }
    7068                        virtual void match( std::list< Expression * > &out );
    71                         virtual void solve();
    72                 };
    73 
    74                 class MultipleAssignMatcher : public Matcher {
     69                };
     70
     71                struct MultipleAssignMatcher : public Matcher {
    7572                  public:
    7673                        MultipleAssignMatcher( TupleAssignSpotter &spot, Expression *lhs, Expression *rhs );
    7774                        virtual void match( std::list< Expression * > &out );
    78                         virtual void solve();
    7975                };
    8076
    8177                ResolvExpr::AlternativeFinder &currentFinder;
    82                 Expression *rhs, *lhs;
     78                // Expression *rhs, *lhs;
    8379                Matcher *matcher = nullptr;
    8480                Options options;
     
    149145
    150146                if ( new_assigns.empty() ) return;
    151                 std::list< Expression * > solved_assigns;
    152147                ResolvExpr::AltList current;
    153148                // now resolve new assignments
     
    161156                        current.push_back( alts.front() );
    162157                }
    163                 options.options.push_back( current );
    164 
    165                 matcher->solve();
     158
     159                // extract expressions from the assignment alternatives to produce a list of assignments that
     160                // together form a single alternative
     161                std::list< Expression *> solved_assigns;
     162                for ( ResolvExpr::Alternative & alt : current ) {
     163                        solved_assigns.push_back( alt.expr->clone() );
     164                }
     165                // xxx - need to do this??
     166                // TypeEnvironment compositeEnv;
     167                // simpleCombineEnvironments( i->begin(), i->end(), compositeEnv );
     168                currentFinder.get_alternatives().push_front( ResolvExpr::Alternative(new TupleAssignExpr(solved_assigns, matcher->tmpDecls), currentFinder.get_environ(), ResolvExpr::sumCost( current ) ) );
    166169        }
    167170
     
    179182        }
    180183
    181         UntypedExpr *TupleAssignSpotter::Matcher::createAssgn( Expression *left, Expression *right ) {
     184        UntypedExpr * createAssgn( ObjectDecl *left, ObjectDecl *right ) {
    182185                assert( left && right );
    183186                std::list< Expression * > args;
    184                 args.push_back( new AddressExpr( left->clone() ) );
    185                 args.push_back( right->clone() );
     187                args.push_back( new AddressExpr( new UntypedExpr( new NameExpr("*?"), std::list< Expression * >{ new VariableExpr( left ) } ) ) );
     188                args.push_back( new VariableExpr( right ) );
    186189                return new UntypedExpr( new NameExpr( "?=?" ), args );
    187190        }
    188191
     192        ObjectDecl * newObject( UniqueName & namer, Expression * expr ) {
     193                Type * type;
     194                assert( expr->get_results().size() >= 1 );
     195                if ( expr->get_results().size() > 1 ) {
     196                        TupleType * tt = new TupleType( Type::Qualifiers() );
     197                        cloneAll( expr->get_results(), tt->get_types() );
     198                        type = tt;
     199                } else {
     200                        type = expr->get_results().front()->clone();
     201                }
     202                return new ObjectDecl( namer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, type, new SingleInit( expr->clone() ) );
     203        }
     204
    189205        void TupleAssignSpotter::MassAssignMatcher::match( std::list< Expression * > &out ) {
     206                static UniqueName lhsNamer( "__massassign_L" );
     207                static UniqueName rhsNamer( "__massassign_R" );
    190208                assert ( ! lhs.empty() && rhs.size() == 1);
    191209
     210                ObjectDecl * rtmp = newObject( rhsNamer, rhs.front() );
    192211                for ( Expression * l : lhs ) {
    193                         out.push_back( createAssgn( l, rhs.front() ) );
    194                 }
    195         }
    196 
    197         void TupleAssignSpotter::MassAssignMatcher::solve() {
    198                 assert( ! spotter.options.empty() );
    199                 for ( std::list< ResolvExpr::AltList >::iterator i = spotter.options.begin(); i != spotter.options.end(); ++i ) {
    200                         // extract expressions from the alternatives to produce a list of assignments that
    201                         // together form a single alternative
    202                         std::list< Expression *> solved_assigns;
    203                         for ( ResolvExpr::Alternative & alt : *i ) {
    204                                 solved_assigns.push_back( alt.expr );
    205                         }
    206                         spotter.currentFinder.get_alternatives().push_front( ResolvExpr::Alternative(new SolvedTupleExpr(solved_assigns), spotter.currentFinder.get_environ(), ResolvExpr::sumCost( *i ) ) );
    207                 }
     212                        ObjectDecl * ltmp = newObject( lhsNamer, new AddressExpr( l ) );
     213                        out.push_back( createAssgn( ltmp, rtmp ) );
     214                        tmpDecls.push_back( ltmp );
     215                }
     216                tmpDecls.push_back( rtmp );
    208217        }
    209218
    210219        void TupleAssignSpotter::MultipleAssignMatcher::match( std::list< Expression * > &out ) {
     220                static UniqueName lhsNamer( "__multassign_L" );
     221                static UniqueName rhsNamer( "__multassign_R" );
    211222                // xxx - need more complicated matching?
    212223                if ( lhs.size() == rhs.size() ) {
    213                         zipWith( lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), back_inserter(out), TupleAssignSpotter::Matcher::createAssgn );
    214                 }
    215         }
    216 
    217         void TupleAssignSpotter::MultipleAssignMatcher::solve() {
    218                 // options.print( std::cerr );
    219                 std::list< ResolvExpr::AltList > best = spotter.options.get_best();
    220                 if ( best.size() == 1 ) {
    221                         std::list<Expression *> solved_assigns;
    222                         for ( ResolvExpr::AltList::iterator i = best.front().begin(); i != best.front().end(); ++i ) {
    223                                 solved_assigns.push_back( i->expr );
    224                         }
    225                         /* assigning cost zero? */
    226                         spotter.currentFinder.get_alternatives().push_front( ResolvExpr::Alternative(new SolvedTupleExpr(solved_assigns), spotter.currentFinder.get_environ(), ResolvExpr::Cost() ) );
    227                 }
    228         }
    229 
    230         std::list< ResolvExpr::AltList > TupleAssignSpotter::Options::get_best() {
    231                 std::list< ResolvExpr::AltList > ret;
    232                 std::list< ResolvExpr::AltList > solns;
    233                 for ( ResolvExpr::AltList & i : options ) {
    234                         ResolvExpr::AltList current;
    235                         findMinCost( i.begin(), i.end(), back_inserter(current) );
    236                         solns.push_back( ResolvExpr::AltList(current.begin(), current.end()) );
    237                 }
    238                 // need to combine -- previously "lift_intersection", which
    239                 // did some madness involving, effectively, the intersection of
    240                 // a bunch of AltLists
    241                 std::list<ResolvExpr::AltList> result = solns;
    242                 if ( result.size() != 1 ) {
    243                         throw SemanticError("Ambiguous tuple expression");
    244                 }
    245                 ret.push_back( *result.begin() );
    246                 return ret;
     224                        std::list< ObjectDecl * > ltmp;
     225                        std::list< ObjectDecl * > rtmp;
     226                        std::transform( lhs.begin(), lhs.end(), back_inserter( ltmp ), []( Expression * expr ){
     227                                return newObject( lhsNamer, new AddressExpr( expr ) );
     228                        });
     229                        std::transform( rhs.begin(), rhs.end(), back_inserter( rtmp ), []( Expression * expr ){
     230                                return newObject( rhsNamer, expr );
     231                        });
     232                        zipWith( ltmp.begin(), ltmp.end(), rtmp.begin(), rtmp.end(), back_inserter(out), createAssgn );
     233                        tmpDecls.splice( tmpDecls.end(), ltmp );
     234                        tmpDecls.splice( tmpDecls.end(), rtmp );
     235                }
    247236        }
    248237
  • src/Tuples/Tuples.h

    r8f7cea1 r6eb8948  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // TupleAssignment.h --
     7// Tuples.h --
    88//
    99// Author           : Rodolfo G. Esteves
     
    1414//
    1515
    16 #ifndef _TUPLE_ASSIGNMENT_H_
    17 #define _TUPLE_ASSIGNMENT_H_
     16#ifndef _TUPLES_H_
     17#define _TUPLE_H_
    1818
    1919#include <string>
     
    2626
    2727namespace Tuples {
     28        // TupleAssignment.cc
    2829        void handleTupleAssignment( ResolvExpr::AlternativeFinder & currentFinder, UntypedExpr * assign, std::list<ResolvExpr::AltList> & possibilities );
     30
     31        // TupleExpansion.cc
     32        void expandTuples( std::list< Declaration * > & translationUnit );
    2933} // namespace Tuples
    3034
  • src/Tuples/module.mk

    r8f7cea1 r6eb8948  
    1515###############################################################################
    1616
    17 SRC +=  Tuples/TupleAssignment.cc
     17SRC +=  Tuples/TupleAssignment.cc \
     18        Tuples/TupleExpansion.cc
  • src/main.cc

    r8f7cea1 r6eb8948  
    4242#include "Common/UnimplementedError.h"
    4343#include "../config.h"
     44#include "Tuples/Tuples.h"
    4445
    4546using namespace std;
     
    265266                OPTPRINT( "convertLvalue" )
    266267                GenPoly::convertLvalue( translationUnit );
     268                OPTPRINT( "expandTuples" ); // xxx - is this the right place for this?
     269                Tuples::expandTuples( translationUnit );
    267270
    268271                if ( bboxp ) {
Note: See TracChangeset for help on using the changeset viewer.