Changeset 3b58d91 for src/SynTree


Ignore:
Timestamp:
Sep 8, 2016, 10:51:07 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:
cd14861
Parents:
4e7f0f1
Message:

add AST nodes TupleIndexExpr?, MemberTupleExpr?, MassAssignExpr?, and MultipleAssignExpr?, modify parser to produce nodes for field tuples, modify UntypedMemberExpr? to contain a list of members

Location:
src/SynTree
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.cc

    r4e7f0f1 r3b58d91  
    310310}
    311311
    312 UntypedMemberExpr::UntypedMemberExpr( std::string _member, Expression *_aggregate, Expression *_aname ) :
     312UntypedMemberExpr::UntypedMemberExpr( Expression * _member, Expression *_aggregate, Expression *_aname ) :
    313313                Expression( _aname ), member(_member), aggregate(_aggregate) {}
    314314
    315315UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) :
    316                 Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
     316                Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) {
    317317}
    318318
    319319UntypedMemberExpr::~UntypedMemberExpr() {
    320320        delete aggregate;
     321        delete member;
    321322}
    322323
    323324void UntypedMemberExpr::print( std::ostream &os, int indent ) const {
    324         os << "Untyped Member Expression, with field: " << get_member();
     325        os << "Untyped Member Expression, with field: " << std::endl;
     326        get_member()->print(os, indent+4);
     327        os << std::string( indent+2, ' ' );
    325328
    326329        Expression *agg = get_aggregate();
    327         os << ", from aggregate: ";
     330        os << "from aggregate: " << std::endl;
    328331        if (agg != 0) {
    329                 os << std::string( indent + 2, ' ' );
    330                 agg->print(os, indent + 2);
     332                os << std::string( indent + 4, ' ' );
     333                agg->print(os, indent + 4);
    331334        }
    332335        os << std::string( indent+2, ' ' );
  • src/SynTree/Expression.h

    r4e7f0f1 r3b58d91  
    200200class UntypedMemberExpr : public Expression {
    201201  public:
    202         UntypedMemberExpr( std::string member, Expression *aggregate, Expression *_aname = nullptr );
     202        UntypedMemberExpr( Expression *member, Expression *aggregate, Expression *_aname = nullptr );
    203203        UntypedMemberExpr( const UntypedMemberExpr &other );
    204204        virtual ~UntypedMemberExpr();
    205205
    206         std::string get_member() const { return member; }
    207         void set_member( const std::string &newValue ) { member = newValue; }
     206        Expression * get_member() const { return member; }
     207        void set_member( Expression * newValue ) { member = newValue; }
    208208        Expression *get_aggregate() const { return aggregate; }
    209209        void set_aggregate( Expression *newValue ) { aggregate = newValue; }
     
    214214        virtual void print( std::ostream &os, int indent = 0 ) const;
    215215  private:
    216         std::string member;
     216        Expression *member;
    217217        Expression *aggregate;
    218218};
     
    618618        CompoundLiteralExpr( Type * type, Initializer * initializer );
    619619        CompoundLiteralExpr( const CompoundLiteralExpr &other );
    620         ~CompoundLiteralExpr();
     620        virtual ~CompoundLiteralExpr();
    621621
    622622        Type * get_type() const { return type; }
     
    651651  private:
    652652        Expression *low, *high;
     653};
     654
     655/// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer
     656class TupleIndexExpr : public Expression {
     657  public:
     658        TupleIndexExpr( Expression * tuple, unsigned int index );
     659        TupleIndexExpr( const TupleIndexExpr &other );
     660        virtual ~TupleIndexExpr();
     661
     662        Expression * get_tuple() const { return tuple; }
     663        int get_index() const { return index; }
     664        TupleIndexExpr * set_tuple( Expression *newValue ) { tuple = newValue; return this; }
     665        TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
     666
     667        virtual TupleIndexExpr *clone() const { return new TupleIndexExpr( *this ); }
     668        virtual void accept( Visitor &v ) { v.visit( this ); }
     669        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     670        virtual void print( std::ostream &os, int indent = 0 ) const;
     671  private:
     672        Expression * tuple;
     673        unsigned int index;
     674};
     675
     676/// MemberTupleExpr represents a tuple member selection operation on a struct type, e.g. s.[a, b, c] after processing by the expression analyzer
     677class MemberTupleExpr : public Expression {
     678  public:
     679        MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname = nullptr );
     680        MemberTupleExpr( const MemberTupleExpr &other );
     681        virtual ~MemberTupleExpr();
     682
     683        Expression * get_member() const { return member; }
     684        Expression * get_aggregate() const { return aggregate; }
     685        MemberTupleExpr * set_member( Expression *newValue ) { member = newValue; return this; }
     686        MemberTupleExpr * set_aggregate( Expression *newValue ) { aggregate = newValue; return this; }
     687
     688        virtual MemberTupleExpr *clone() const { return new MemberTupleExpr( *this ); }
     689        virtual void accept( Visitor &v ) { v.visit( this ); }
     690        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     691        virtual void print( std::ostream &os, int indent = 0 ) const;
     692  private:
     693        Expression * member;
     694        Expression * aggregate;
     695};
     696
     697/// MultipleAssignExpr represents a multiple assignment operation, where both sides of the assignment have tuple type, e.g. [a, b, c] = [d, e, f];
     698class MultipleAssignExpr : public Expression {
     699  public:
     700        MultipleAssignExpr( Expression * lhs, Expression * rhs );
     701        MultipleAssignExpr( const MultipleAssignExpr &other );
     702        virtual ~MultipleAssignExpr();
     703
     704        Expression * get_lhs() const { return lhs; }
     705        Expression * get_rhs() const { return rhs; }
     706        MultipleAssignExpr * set_lhs( Expression *newValue ) { lhs = newValue; return this; }
     707        MultipleAssignExpr * set_rhs( Expression *newValue ) { rhs = newValue; return this; }
     708
     709        virtual MultipleAssignExpr *clone() const { return new MultipleAssignExpr( *this ); }
     710        virtual void accept( Visitor &v ) { v.visit( this ); }
     711        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     712        virtual void print( std::ostream &os, int indent = 0 ) const;
     713  private:
     714        Expression * lhs;
     715        Expression * rhs;
     716};
     717
     718/// 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;
     719class MassAssignExpr : public Expression {
     720  public:
     721        MassAssignExpr( Expression * tuple, int field );
     722        MassAssignExpr( const MassAssignExpr &other );
     723        virtual ~MassAssignExpr();
     724
     725        Expression * get_lhs() const { return lhs; }
     726        Expression * get_rhs() const { return rhs; }
     727        MassAssignExpr * set_lhs( Expression *newValue ) { lhs = newValue; return this; }
     728        MassAssignExpr * set_rhs( Expression *newValue ) { rhs = newValue; return this; }
     729
     730        virtual MassAssignExpr *clone() const { return new MassAssignExpr( *this ); }
     731        virtual void accept( Visitor &v ) { v.visit( this ); }
     732        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     733        virtual void print( std::ostream &os, int indent = 0 ) const;
     734  private:
     735        Expression * lhs; // multiple exprs
     736        Expression * rhs; // single expr
    653737};
    654738
  • src/SynTree/Mutator.cc

    r4e7f0f1 r3b58d91  
    216216        mutateAll( memberExpr->get_results(), *this );
    217217        memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
     218        memberExpr->set_member( maybeMutate( memberExpr->get_member(), *this ) );
    218219        return memberExpr;
    219220}
     
    355356        rangeExpr->set_high( maybeMutate( rangeExpr->get_high(), *this ) );
    356357        return rangeExpr;
     358}
     359
     360Expression *Mutator::mutate( TupleIndexExpr *tupleExpr ) {
     361        mutateAll( tupleExpr->get_results(), *this );
     362        tupleExpr->set_tuple( maybeMutate( tupleExpr->get_tuple(), *this ) );
     363        return tupleExpr;
     364}
     365
     366Expression *Mutator::mutate( MemberTupleExpr *tupleExpr ) {
     367        mutateAll( tupleExpr->get_results(), *this );
     368        tupleExpr->set_member( maybeMutate( tupleExpr->get_member(), *this ) );
     369        tupleExpr->set_aggregate( maybeMutate( tupleExpr->get_aggregate(), *this ) );
     370        return tupleExpr;
     371}
     372
     373Expression *Mutator::mutate( MultipleAssignExpr *assignExpr ) {
     374        mutateAll( assignExpr->get_results(), *this );
     375        assignExpr->set_lhs( maybeMutate( assignExpr->get_lhs(), *this ) );
     376        assignExpr->set_rhs( maybeMutate( assignExpr->get_rhs(), *this ) );
     377        return assignExpr;
     378}
     379
     380Expression *Mutator::mutate( MassAssignExpr *assignExpr ) {
     381        mutateAll( assignExpr->get_results(), *this );
     382        assignExpr->set_lhs( maybeMutate( assignExpr->get_lhs(), *this ) );
     383        assignExpr->set_rhs( maybeMutate( assignExpr->get_rhs(), *this ) );
     384        return assignExpr;
    357385}
    358386
  • src/SynTree/Mutator.h

    r4e7f0f1 r3b58d91  
    7979        virtual Expression* mutate( CompoundLiteralExpr *compLitExpr );
    8080        virtual Expression* mutate( RangeExpr *rangeExpr );
     81        virtual Expression* mutate( TupleIndexExpr *tupleExpr );
     82        virtual Expression* mutate( MemberTupleExpr *tupleExpr );
     83        virtual Expression* mutate( MultipleAssignExpr *assignExpr );
     84        virtual Expression* mutate( MassAssignExpr *assignExpr );
    8185
    8286        virtual Type* mutate( VoidType *basicType );
  • src/SynTree/SynTree.h

    r4e7f0f1 r3b58d91  
    8484class CompoundLiteralExpr;
    8585class RangeExpr;
     86class TupleIndexExpr;
     87class MemberTupleExpr;
     88class MultipleAssignExpr;
     89class MassAssignExpr;
    8690
    8791class Type;
  • src/SynTree/TupleExpr.cc

    r4e7f0f1 r3b58d91  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // TupleExpr.cc -- 
     7// TupleExpr.cc --
    88//
    99// Author           : Richard C. Bilson
     
    1616#include "Expression.h"
    1717#include "Common/utility.h"
     18#include "Type.h"
    1819
    1920TupleExpr::TupleExpr( Expression *_aname ) : Expression( _aname ) {
     
    4849}
    4950
     51TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) {
     52        // TupleType * type = safe_dynamic_cast< TypeType * >( tuple->get_ )
     53        assert( tuple->get_results().size() >= index );
     54        add_result( *std::next( tuple->get_results().begin(), index ) );
     55}
     56
     57TupleIndexExpr::TupleIndexExpr( const TupleIndexExpr &other ) : Expression( other ), tuple( other.tuple->clone() ), index( other.index ) {
     58}
     59
     60TupleIndexExpr::~TupleIndexExpr() {
     61        delete tuple;
     62}
     63
     64void TupleIndexExpr::print( std::ostream &os, int indent ) const {
     65        os << std::string( indent, ' ' ) << "Tuple Index Expression, with tuple:" << std::endl;
     66        tuple->print( os, indent+2 );
     67        os << std::string( indent+2, ' ' ) << "with index: " << index << std::endl;
     68        Expression::print( os, indent );
     69}
     70
     71MemberTupleExpr::MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname ) : Expression( _aname ) {
     72        cloneAll( member->get_results(), get_results() ); // xxx - ???
     73}
     74
     75MemberTupleExpr::MemberTupleExpr( const MemberTupleExpr &other ) : Expression( other ), member( other.member->clone() ), aggregate( other.aggregate->clone() ) {
     76}
     77
     78MemberTupleExpr::~MemberTupleExpr() {
     79        delete member;
     80        delete aggregate;
     81}
     82
     83void MemberTupleExpr::print( std::ostream &os, int indent ) const {
     84        os << std::string( indent, ' ' ) << "Member Tuple Expression, with aggregate:" << std::endl;
     85        aggregate->print( os, indent+2 );
     86        os << std::string( indent+2, ' ' ) << "with member: " << std::endl;
     87        member->print( os, indent+2 );
     88        Expression::print( os, indent );
     89}
     90
     91
    5092// Local Variables: //
    5193// tab-width: 4 //
  • src/SynTree/Visitor.cc

    r4e7f0f1 r3b58d91  
    182182        acceptAll( memberExpr->get_results(), *this );
    183183        maybeAccept( memberExpr->get_aggregate(), *this );
     184        maybeAccept( memberExpr->get_member(), *this );
    184185}
    185186
     
    301302        maybeAccept( rangeExpr->get_low(), *this );
    302303        maybeAccept( rangeExpr->get_high(), *this );
     304}
     305
     306void Visitor::visit( TupleIndexExpr *tupleExpr ) {
     307        acceptAll( tupleExpr->get_results(), *this );
     308        maybeAccept( tupleExpr->get_tuple(), *this );
     309}
     310
     311void Visitor::visit( MemberTupleExpr *tupleExpr ) {
     312        acceptAll( tupleExpr->get_results(), *this );
     313        maybeAccept( tupleExpr->get_member(), *this );
     314        maybeAccept( tupleExpr->get_aggregate(), *this );
     315}
     316
     317void Visitor::visit( MultipleAssignExpr *assignExpr ) {
     318        acceptAll( assignExpr->get_results(), *this );
     319        maybeAccept( assignExpr->get_lhs(), *this );
     320        maybeAccept( assignExpr->get_rhs(), *this );
     321}
     322
     323void Visitor::visit( MassAssignExpr *assignExpr ) {
     324        acceptAll( assignExpr->get_results(), *this );
     325        maybeAccept( assignExpr->get_lhs(), *this );
     326        maybeAccept( assignExpr->get_rhs(), *this );
    303327}
    304328
  • src/SynTree/Visitor.h

    r4e7f0f1 r3b58d91  
    7979        virtual void visit( CompoundLiteralExpr *compLitExpr );
    8080        virtual void visit( RangeExpr *rangeExpr );
     81        virtual void visit( TupleIndexExpr *tupleExpr );
     82        virtual void visit( MemberTupleExpr *tupleExpr );
     83        virtual void visit( MultipleAssignExpr *assignExpr );
     84        virtual void visit( MassAssignExpr *assignExpr );
    8185
    8286        virtual void visit( VoidType *basicType );
Note: See TracChangeset for help on using the changeset viewer.