Changeset 6eb8948 for src/SynTree


Ignore:
Timestamp:
Sep 12, 2016, 6:32:46 PM (9 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:
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/SynTree
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified 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 );
  • TabularUnified 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
  • TabularUnified 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
  • TabularUnified 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 );
  • TabularUnified 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;
  • TabularUnified 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 //
  • TabularUnified 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
  • TabularUnified 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();
  • TabularUnified 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
  • TabularUnified 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 );
Note: See TracChangeset for help on using the changeset viewer.